User’s Manual Thomas Jefferson National Accelerator Facility


How do I check if my service is up and running?



Download 415.94 Kb.
Page11/17
Date28.01.2017
Size415.94 Kb.
#10668
1   ...   7   8   9   10   11   12   13   14   ...   17

How do I check if my service is up and running?

In the previous chapter we described a set of steps necessary to deploy a service engine as a service in a ClaRA platform. As a proof of the successful deployment we checked the platform console printouts. However, it is likely that you will not have access to the platform console and more importantly, you might want to check if there are already deployed services with identical engines before a new service deployment. For this reason let us see how we can get a list of registered services on a ClaRA cloud that are using the same service engine. Take a look at this code.

public class ServicesByEngineName extends JOrchestrator{
/**

* Constructor

* Connects to the ClaRA platform

*

* @param name of this orchestrator



*/

public ServicesByEngineName(String name) {

super(name);

}
We repeat the standard beginning of the orchestrator class for the sake of completeness of the presented code that can be directly replicated in your test projects.

In the main method of this orchestrator we create an object of this class and request registration information from the registration and discovery services of the platform. Based on the registration information we obtain the list of all registered service canonical names on the cloud that are using the required engine. To get the list of all registered services we use the engine name that was defined when the service developer override getName() ClaRA interface method. Note that an engine name is case sensitive.

public static void main(String[] args) {

String oName = args[0];

String engineName = args[1];


// an instance of this class

ServicesByEngineName rso = new ServicesByEngineName(oName);


// get registration information form the platform normative services

rso.updateRegistration();


// get all registered service canonical names that has a required engine name.

ArrayList serviceNames = rso.getServiceNamesByEngineName(engineName);

if(serviceNames!=null && !serviceNames.isEmpty()){
for(String sn:serviceNames){

// list service information

System.out.println();

rso.listServiceInformation(sn);

}

} else {


System.out.println("No service with the specified engine name = "+engineName+" was found.");

}

rso.exit();



}

}

In the segment of the code above we iterate over all the service names, presenting the requested engine as a service on a cloud. For all found services we print short information, including the author and the version of a service. Below is the snapshot of a terminal that was used to compile and run above the presented orchestrator.



>javac -cp $CLARA_SERVICES/lib/clara.jar:$CLARA_SERVICES/lib/jtools-1.0.jar:$CLARA_SERVICES/lib/cMsg-3.3.jar ServicesByEngineName.java -d $CLARA_SERVICES/
>java -cp "$CLARA_SERVICES/.:$CLARA_SERVICES/lib/*" examples.orchestrator.check.ServicesByEngineName xyz Hello
Description: Hello World service

Version : 1.0

Author : Gyurjyan

How do I request a service?

Now that we have developed and deployed our first service let us request the hello-world service to greet us. As you already guessed we need to write an orchestrator that will communicate with the ClaRA platform registration and discovery services, find the hello-world service and request the service of it. We will name our orchestrator as a ServiceByCanonicalName since in this exercise we are planning to access a service by its canonical name. The listing of the ServiceByCanonicalName.java code is shown below.


public class ServiceByCanonicalName extends JOrchestrator {

/**

* Constructor



* Connects to the ClaRA platform

*

* @param name of this orchestrator



*/

public ServiceByCanonicalName(String name) {

super(name);

}
public static void main(String[] args) {

String oName = args[0];

String serviceName = args[1];


// instance of this class

ServiceByCanonicalName rs = new ServiceByCanonicalName(oName);


// get registration information form the platform registration and discovery services

rs.updateRegistration();


// check the platform registration if the service in question is registered

if(rs.isServiceRunning(serviceName)){


// request the service
// create a request transient data

JioSerial dataRequest = new JioSerial();

dataRequest.setLanguage(CConstants.LANG_JAVA);

dataRequest.setData(oName);

dataRequest.setMimeType(MimeType.STRING);
// send the request

JioSerial dataResponse = rs.syncRunService(serviceName, dataRequest,1000);


// print the response

System.out.println(dataResponse);

} else {

System.out.println("Service was not found");

}

rs.exit();



}

}
// request the service


// create a request transient data

JioSerial dataRequest = new JioSerial();

dataRequest.setLanguage(CConstants.LANG_JAVA);

dataRequest.setData(oName);

dataRequest.setMimeType(MimeType.STRING);
// send the request

JioSerial dataResponse = rs.syncRunService(serviceName, dataRequest,1000);


// print the response

System.out.println(dataResponse);

} else {

System.out.println("Service was not found");

}

rs.exit();



}

}

As usual the first argument to the main method is the name of this orchestrator, required for the proper connection to the ClaRA platform. The second argument is the canonical name of the service that we are planning to access. The first thing we do in the code is to obtain the registration information from the registry and discovery services. Having this information, we proceed to check if the service of interest is registered with the platform registry services. This will indicate that the service is up and running and is ready to accept requests. For the request we create a transient input data object and specify the input data type as a string and specify the programming language of the requester client (i.e. this orchestrator) that created the transient data. Defining the language of the transient data object creator in the coming releases is expected to be deprecated, but for the 2.1.1 release we need this due to the transient data handling differences between Java and C++.



As the input transient data content we send the registration name of the ServiceByCanonicalName orchestrator. Let us compile and run this orchestrator.

>javac -cp $CLARA_SERVICES/lib/clara.jar:$CLARA_SERVICES/lib/jtools-1.0.jar:$CLARA_SERVICES/lib/cMsg-3.3.jar ServiceByCanonicalName.java -d $CLARA_SERVICES/
>java -cp "$CLARA_SERVICES/.:$CLARA_SERVICES/lib/*" examples.orchestrator.request.ServiceByCanonicalName xName 129.57.81.247/xContainer/hello
mimeType = STRING

dataUnit = undefined

dataDescription = response to xName

language = java

version = 0.0

status = Info

control = undefined

exceptionSink = undefined

exceptionSource = undefined

data = 2012/08/07 17:04:40: Hello

After the execution you will get a similar printout (shown above) indicating the hello-world service output data details.





Download 415.94 Kb.

Share with your friends:
1   ...   7   8   9   10   11   12   13   14   ...   17




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

    Main page