Run multiple services in an application

Goal

In your application, different sessions may need different services to perform computations.

You want to be able to specify that an application can run several services.

Assumptions

For the procedures in this document, it is assumed you want your application to use two different services, ServiceA, and ServiceB. The application is registered under the consumer /SampleApplications/SOASamples.

Package and deploy your services

Different services can use separate service packages or the same service package. Ensure each service definition in an application profile has a unique service name. Note that only one of your services can be set as the default service.

This example assumes you will create a separate package for each service used by your application.

For example, to use ServiceA and ServiceB in your application:

  • Create ServiceApkg.gz and include all related binaries for ServiceA in this package.

  • Create ServiceBpkg.gz and include all related binaries for ServiceB in this package.

  1. Go to the directory that contains your service binaries and compress the service binaries into two files: ServiceApkg.gz, and ServiceBpkg.gz.
  2. Deploy the service packages in the consumer with the soamdeploy command. (If you prefer, you may use the Wizard for this task.)
    soamdeploy add ServiceApkg -p ServiceApkg.gz -c /SampleApplications/SOASamples
    soamdeploy add ServiceBpkg -p ServiceBpkg.gz -c /SampleApplications/SOASamples

    The service packages are deployed.

  3. Check the list of deployed services with the soamdeploy view command.

    For example:

    soamdeploy view -c /SampleApplications/SOASamples

    You should be able to see your service packages deployed. Notice that the Application field has a dash (-), indicating that there are no applications associated with the package you deployed.

Associate your application with the service packages

To associate your application with the different service packages, edit your application profile.

Important:

By configuring more than one service in your application, a host blocked because of an error in one of the services is also blocked for all other services of the same application.

  1. Open your application profile.
  2. In the session type definition, under SessionTypes, specify the session type name and add the serviceName parameter.

    The serviceName parameter can be any name you want. It is used to link the session type definition with the service definition. If serviceName is not defined, the session uses the default service.

    For example:

    ...
    <SessionTypes>
            <Type name="MysessiontypeA" serviceName="ServiceA" priority="1" 
    recoverable="false" sessionRetryLimit="3" taskRetryLimit="3" 
    abortSessionIfTaskFail="false" suspendGracePeriod="100"  
    taskCleanupPeriod="100"persistSessionHistory="all" persistTaskHistory="all"/>
           <Type name="MysessiontypeB" priority="1" recoverable="false"      
    serviceName="ServiceB" sessionRetryLimit="3" taskRetryLimit="3"  
    abortSessionIfTaskFail="false" suspendGracePeriod="100"  taskCleanupPeriod="100" 
    persistSessionHistory="all" persistTaskHistory="all"/>
    </SessionTypes>
  3. In the service definition, under Service, specify the service name, service package name, and start command for the service. All services specified in SessionTypes should be configured in the Service section.
    1. For Service name, specify the same value that you specified for serviceName in the session type.
    2. Specify the packageName parameter and specify the name of the package you deployed.

      You can find out the package name with the command soamdeploy view.

    1. Change startCmd to point to your service executable.

      Leave the ${SOAM_DEPLOY_DIR} in your path as this is the deployment directory in the system. If your service is located under a subdirectory, indicate the subdirectory after ${SOAM_DEPLOY_DIR} in the path.

      On Windows:

      <Service name="ServiceA" description="My Sample Service A"
      packageName="ServiceApkg" deploymentTimeout="300">
              <osTypes>
                  <osType name="all" startCmd="${SOAM_DEPLOY_DIR}\ServiceA.exe">
                  </osType>
              </osTypes>
          </Service>

      On Linux:

      <Service name="ServiceB" description="My Sample Service B"
      packageName="ServiceBpkg" deploymentTimeout="300">
              <osTypes>
                  <osType name="all" startCmd="${SOAM_DEPLOY_DIR}/ServiceB">
                  </osType>
              </osTypes>
          </Service>
  4. Repeat steps 2-3 for every service that you want to refer to in your application.
  5. Add a default attribute for the service that you want to designate as the default so that it is started when the service instance manager starts.

    When specifying multiple services, you must designate one service as the default.

    For example, for ServiceA and ServiceB, your application profile should look similar to the following. Note that in this example, ServiceA is the default service.

    <?xml version="1.0" encoding="UTF-8"?>
    <Profile xmlns="http://www.platform.com/Symphony/Profile/Application" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="">    
    <Consumer applicationName="SampleApplicationCPP" 
    consumerId="/SampleApplications/SOASamples" policy="R_Proportion" 
    taskHighWaterMark="1.0" taskLowWaterMark="1.0" resourceBalanceInterval="5" 
    sessionSchedulingInterval="500" resourceGroupName="ComputeHosts"/>
    ...
    <SessionTypes>
            <Type name="MysessiontypeA" priority="1" recoverable="false" 
    serviceName="ServiceA" sessionRetryLimit="3" taskRetryLimit="3"  
    abortSessionIfTaskFail="false" suspendGracePeriod="100"  taskCleanupPeriod="100" 
    persistSessionHistory="all" persistTaskHistory="all"/>
            <Type name="MysessiontypeB" priority="1" recoverable="false"      
    serviceName="ServiceB" sessionRetryLimit="3" taskRetryLimit="3"  
    abortSessionIfTaskFail="false" suspendGracePeriod="100"  taskCleanupPeriod="100" 
    persistSessionHistory="all" persistTaskHistory="all"/>
    </SessionTypes>
        
    <Service name="ServiceA" description="The Sample Service A" 
    packageName="ServiceApkg" default="true" deploymentTimeout="300">
            <osTypes>
                <osType name="NTX86" startCmd="${SOAM_DEPLOY_DIR}\ServiceA.exe"> 
            </osType>
            </osTypes>
        </Service>
             
    <Service name="ServiceB" description="The Sample Service B" 
    packageName="ServiceBpkg" deploymentTimeout="300">
                <osTypes>
                    <osType name="LINUX86"startCmd="${SOAM_DEPLOY_DIR}/ServiceB">
                    </osType>
                </osTypes>
            </Service>
    </Profile>
  6. Register the application profile with the soamreg command. (If you prefer, you may use the Wizard for this task.)

    For example:

    soamreg SampleApp.xml

    The application is registered and enabled.

  7. Check that the application is associated with the package with the soamdeploy view command.

    soamdeploy view -c /SampleApplications/SOASamples

    You should be able to see package names and the associated application names.

Check your client application code and run your client

Check your client application code to ensure:

  • The application name specified when connecting to the application is the same as that specified in the application profile

  • The session types you specified to create the session must exist in your application profile unless you specified " " for the session types, which means to use the default session type.

    If you want to specify the service name directly to override the service configured in the session type, the service must be configured in your application profile.

  1. Check client code to ensure the application name specified in connect( ) is the same as that specified in the application profile.

    For example, if, in your application profile you have applicationName="SampleAppCPP",

    your client code must also contain SampleAppCPP:
    ...
    // set up application specific information to be supplied to the System        
    ConnectionPtr conPtr = SoamFactory::connect("SampleAppCPP",&securityCB);
    ...
  2. Check client code to ensure the session type name specified when creating the session is configured in your application profile.
    For example, create sessions with the session types for ServiceA and ServiceB:
    ...
    // Set up session creation attributes for ServiceA        
    SessionCreationAttributes attributesA;       
    attributesA.setSessionName("mySessionA");
    attributesA.setSessionType("MysessiontypeA");   
    attributesA.setSessionFlags(SF_RECEIVE_SYNC); 
    // Set up session creation attributes for ServiceBSessionCreationAttributes
    attributesB;attributesB.setSessionName("mySessionB");
    attributesB.setSessionType("MysessiontypeB");
    attributesB.setSessionFlags(SF_RECEIVE_SYNC);
    // Create synchronous sessions        
    SessionPtr sesPtrA = conPtr->createSession(attributesA);
    SessionPtr sesPtrB = conPtr->createSession(attributesB);
    ...
  3. Save your client code and recompile.
  4. Run your client to submit work to your application.