Issue with ServiceGroup in EDRA 1.1

EDRA (Shadowfax) has a cool feature called ServiceGroup. This allows you to group services in a logical group and has a pipeline defined that uses the Service Group. An example of usage would be creating a service group for transactional service actions and another service group for non-transactional ones (example of Wake Jens from Volvo IT).

This nice feature has an issue in EDRA 1.1 so I decided to go deep into it. I found that there was a problem in the Configuration Validation which didn't take into account this service's group. To make the long story short, as we have the source code of EDRA here are the methods I've changed (in bold) on the file ConfigValidator.cs to make the ServiceGroups work (download ConfigValidator.zip (61.44 KB)):

1. ValidateBusinessActionNames

private bool ValidateBusinessActionNames(StringBuilder report)
{
    string serviceActionName = null;
    string pipelineName = null;
    bool baServiceActionFound;
    bool result = true;

    IDictionaryEnumerator businessActionEnumerator = _businessActDefSettings.BusinessActions.GetEnumerator();
    while ( businessActionEnumerator.MoveNext() )
    {
        BusinessActionSettings baSettings = (BusinessActionSettings)businessActionEnumerator.Value;
            
        // Checking if the current business action specified in the configuration
        // is a compenstae business action or not. The checks for service interface
        // service implementation pipeline should be done only if the the business
        // action is not specified as compensate business action for any of the existing
        // business actions.
        if (IsCompensateBusinessAction(baSettings.Name))
        {
            continue;
        }

        IDictionaryEnumerator pipelineEnumerator = _pipelineDefSettings.ServiceInterfacePipelines.GetEnumerator();
        baServiceActionFound = false;
        while ( pipelineEnumerator.MoveNext() )
        {
            ServiceInterfacePipelineConfig pipelineCfg = (ServiceInterfacePipelineConfig)pipelineEnumerator.Value;
            serviceActionName = pipelineCfg.ServiceName;
            pipelineName = pipelineCfg.Name;

            bool isInServiceGroup = false;
            if ( pipelineCfg.ServiceGroup != null && pipelineCfg.ServiceGroup != String.Empty )
            {
                // get the service group for the current pipeline config and check that the service group contains the business action
                ServiceGroupConfig serviceGroup = (ServiceGroupConfig)PipelinesConfig.Config.ServiceGroups[ pipelineCfg.ServiceGroup ];
                isInServiceGroup = serviceGroup.Services.Contains( baSettings.Name.Trim() );
            }
            
            if( (String.Compare(baSettings.Name.Trim(), serviceActionName.Trim(), true) == 0 ) || ( serviceActionName == "*" ) || ( isInServiceGroup ) )
            {
                baServiceActionFound = true;
                break;
            }
        }
        if ( baServiceActionFound == false )
        {
            result &= false;
            report.Append(Resource.ResourceManager.FormatMessage(Resource.MessageKey.ServiceInterfacePipelineMissingForBAErrMsg, baSettings.Name));
            break;
        }


        pipelineEnumerator = _pipelineDefSettings.ServiceImplementationPipelines.GetEnumerator();
        baServiceActionFound = false;
        while ( pipelineEnumerator.MoveNext() )
        {
            ServiceImplementationPipelineConfig pipelineCfg = (ServiceImplementationPipelineConfig)pipelineEnumerator.Value;
            serviceActionName = pipelineCfg.ServiceName;
            pipelineName = pipelineCfg.Name;

            bool isInServiceGroup = false;
            if ( pipelineCfg.ServiceGroup != null && pipelineCfg.ServiceGroup != String.Empty )
            {
                ServiceGroupConfig serviceGroup = (ServiceGroupConfig)PipelinesConfig.Config.ServiceGroups[ pipelineCfg.ServiceGroup ];
                isInServiceGroup = serviceGroup.Services.Contains( baSettings.Name.Trim() );
            }

            if( (String.Compare(baSettings.Name.Trim(), serviceActionName.Trim(), true) == 0 ) || ( serviceActionName == "*" ) || ( isInServiceGroup ) )
            {
                baServiceActionFound = true;
            }
        }
        if ( baServiceActionFound == false )
        {
            result &= false;
            report.Append(Resource.ResourceManager.FormatMessage(Resource.MessageKey.ServiceImplPipelineMissingForBAErrMsg, baSettings.Name));
            break;
        }
    }
    return(result);
}

2. ValidateImplPipelines

private bool ValidateImplPipelines(StringBuilder report, string serviceActionName)
{
    bool result = true;
    BusinessActionSettingCollection baSettingCollection = _businessActDefSettings.BusinessActions;

    foreach(DictionaryEntry entry in _pipelineDefSettings.ServiceImplementationPipelines )
    {
        ServiceImplementationPipelineConfig config = (ServiceImplementationPipelineConfig)entry.Value;
        if ( ( String.Compare(config.ServiceName.Trim(), serviceActionName.Trim(), true) == 0 ) || (config.ServiceName.Trim() == "*") )
        {
            result &= ValidateHandlers(report, config, JoinPoint.ServiceImplementation);
            
            // Checking if the service implementation pipeline is default
            if ( config.ServiceName.Trim() != "*" )
            {
                // if a service group was configured, check that each service action on the servicegroup has a corresponding BA
                if ( config.ServiceGroup.Trim() != String.Empty )
                {
                    ServiceGroupConfig serviceGroup = (ServiceGroupConfig)PipelinesConfig.Config.ServiceGroups[ config.ServiceGroup ];
                    foreach( string service in serviceGroup.Services )
                    {
                        BusinessActionSettings baSettings = baSettingCollection[ service ];
                        result &= ValidateAssemblyInfo(report, baSettings.TypeName, "business action");
                        result &= ValidateBusinessActionInvocationModes(report, baSettings);
                    }
                }
                else
                {
                    BusinessActionSettings baSettings = baSettingCollection[config.ServiceName];
                    result &= ValidateAssemblyInfo(report, baSettings.TypeName, "business action");
                    result &= ValidateBusinessActionInvocationModes(report, baSettings);
                }                        
            }
            break;
        }
    }
    return(result);
}

Published: February 14 2005

blog comments powered by Disqus