User’s Manual Thomas Jefferson National Accelerator Facility



Download 415.94 Kb.
Page13/17
Date conversion28.01.2017
Size415.94 Kb.
1   ...   9   10   11   12   13   14   15   16   17

Configuring a service

A ClaRA composite service typically consists of a set of entity services running on one or more machines that cooperate to provide a useful facility to an end-user or to another software system. A particularly critical aspect of a PDP application deployment practice is the ability to configure individual services that are part of an application. An example might be an event-service of a charged particle tracking application, which uses an input file as the front-end and has a back-end that stores reconstructed persistent data. In this case we need to configure the event-service and define the required end points in terms of input/output file locations.

In this tutorial we show how one can configure the previously discussed hello-world service. We will slightly modify our hello-world service and make it configurable. For that let us modify the execute method that will greet in a language defined at the service configuration stage. First we implement the configure ClaRA interface method. This method sets the private language indicator variable according to a language request that was obtained through the transient configuration data.

// defines a language using which we say hello

private int language = 0;
@Override

public void configure(JioSerial data) {


// check the input data mime-type

if(data.getMimeType().type().equals(MimeType.STRING.type())){


// get data object

String cd = data.getStringObject();

if(cd.equalsIgnoreCase("Armenian")){

language = 1;

} else if (cd.equalsIgnoreCase("Italian")){

language = 2;

} else if (cd.equalsIgnoreCase("Russian")){

language = 3;

} else if (cd.equalsIgnoreCase("French")){

language = 4;

} else if (cd.equalsIgnoreCase("German")){

language = 5;

} else if (cd.equalsIgnoreCase("Greek")){

language = 6;

} else if (cd.equalsIgnoreCase("Hebrew")){

language = 7;

} else if (cd.equalsIgnoreCase("Japanese")){

language = 8;

} else if (cd.equalsIgnoreCase("Thai")){

language = 9;

}

}

}



Now, let us modify the previously mentioned execute method of the hello-world service that will use a language indicator to construct the greeting message. The switch statement and the case for the service request rejection are shown below.
public JioSerial execute(JioSerial data) {
// output transient data object

JioSerial out = new JioSerial();

out.setLanguage(CConstants.LANG_JAVA);

out.setMimeType(MimeType.STRING);

// check the input data mime-type

if(data.getMimeType().type().equals(MimeType.STRING.type())){


// get the data content

String inputDataObject = data.getStringObject();


// generate the output data

switch(language){

case 0:

out.setData(CUtil.getCurrentTime()+": Hello");



break;

case 1:


out.setData(CUtil.getCurrentTime()+": Barev");

break;


case 2:

out.setData(CUtil.getCurrentTime()+": Salve");

break;

case 3:


out.setData(CUtil.getCurrentTime()+": Zdrastvui");

break;


case 4:

out.setData(CUtil.getCurrentTime()+": Bonjour");

break;

case 5:


out.setData(CUtil.getCurrentTime()+": Guten Tag");

break;


case 6:

out.setData(CUtil.getCurrentTime()+": Gia'sou");

break;

case 7:


out.setData(CUtil.getCurrentTime()+": Shalom");

break;


case 8:

out.setData(CUtil.getCurrentTime()+": Kon-nichiwa");

break;

case 9:


out.setData(CUtil.getCurrentTime()+": Sa-wat-dee");

break;


}

out.setDataDescription("response to " + inputDataObject);

out.setStatus(CConstants.info);

} else {
// Reject with an execution status = error

out.setData(CConstants.REJECT);

out.setDataDescription("I can accept only strings");

out.setStatus(CConstants.error);

}

return out;



}

If you have been following along in this tutorial from the start then you know that for any external communication (including the configuration request) with a service you need to write an orchestrator. An example of a service configuration orchestrator is shown below.

public class ConfigureService extends JOrchestrator {
public ConfigureService(String name) {

super(name);

}

Now let us write the main method of ConfigureService orchestrator. As usual first we get the registration information for the service of interest, making sure the service is properly deployed.


public static void main(String[] args) {

String oName = args[0];

String service = args[1];

String language = args[2];


ConfigureService cs = new ConfigureService(oName);
// get registration information form the platform normative services

cs.updateRegistration();


// check if the service1 is registered

if(!cs.isServiceRunning(service)){

System.out.println("Error: Can not find the registration information for the service = "+service);

System.exit(1);

}
// create configuration data

JioSerial cData = new JioSerial();

cData.setLanguage(CConstants.LANG_JAVA);

cData.setData(language);

cData.setMimeType(MimeType.STRING);
if(!cs.configureService(service,cData)){

System.out.println("Error: Configure failed.");

}

cs.exit();



}

}


To make sure that configuration and following service execution are operationally correct and consistent we need first to compile and deploy the hello-world service (refer the previous paragraphs) and then compile and run the ConfigureService orchestrator. Here is how we compile and run the ConfigureService orchestrator.
>javac -cp $CLARA_SERVICES/lib/clara.jar:$CLARA_SERVICES/lib/jtools-1.0.jar:$CLARA_SERVICES/lib/cMsg-3.3.jar ConfigureService.java -d $CLARA_SERVICES/

Below is the snapshot of the terminal that was used to run the hello-world service configuration orchestrator. Note that this orchestrator uses a service canonical name to locate the requested service to be configured. As a reminder, the canonical name of a service is constructed as host/container-name/engine-name. Note that the name of the deployed service can be seen in the platform console.




>java -cp "$CLARA_SERVICES/.:$CLARA_SERVICES/lib/*" examples.orchestrator.ConfigureService oName 129.57.81.247/xContainer/Hello Armenian
As you can see, our orchestrator is not verbose. So, in order to be convinced that we configured properly the hello-world service, let us request the hello-world service and see it will greet us in a language required at the configuration stage (i.e. Armenian in this particular execution of the ConfigureService orchestrator. See above). In order to request the hello-world service we use ServiceByCanonicalName orchestrator (see “How do I request a service” paragraph).

java -cp "$CLARA_SERVICES/.:$CLARA_SERVICES/lib/*" examples.orchestrator.request.ServiceByCanonicalName xName 129.57.81.247/xContainer/hello
date = 2012/08/15 11:38:44

dataSource = undefined

dataDestination = undefined

dataDescription = response to xName

status = Info

mimeType = STRING

dataUnit = undefined

language = java

version = 0.0

control = undefined

exceptionSource = undefined

exceptionDestination = undefined

data = 2012/08/15 11:38:44: Barev

If you get the word “Barev” in the data content of the transient data envelope from the hello-world service then the configuration of the service was successful.


1   ...   9   10   11   12   13   14   15   16   17


The database is protected by copyright ©ininet.org 2016
send message

    Main page