Prepare the service for CoDeS deployment
Preparing the service
First, we need the compiled source code and all its dependencies. It is desirable to separe binaries from libraries in different sources. File dependencies should be placed as they were in the execution environment. No hidden files or file names starting by '.' are supported by CoDeS.
Including CoDeS in the service
CoDeS library must be included in order to deploy a service. Then, an implementation of the Service interface ( codes.services.Service) must be provided. This interface offers two methods to start and stop a service and an additional method to send messages to the service instances. The programmer should implement the start and the stop procedures using Java.
Once the interface is implemented, it should be added to the service binaries. All the files needed to execute these binaries can be placed by relative paths. Remember the libraries (such as CoDeS) must be placed in the libraries directory.
ServiceCEcho.java is an example on how to use this simple interface.
Specifying the service with an XML file
In order to know which is the class the Service is implementing and the CLASSPATH used to find the libraries, an XML file containing this information must be provided. Other files can also be included. We need to specify the following information:
- Service implementation class, defined by the field service, where sPath links to the binaries and sName is the name of the implementation class. Remember the class should be placed in the same directory or explicitly indicated (if the class file is /Service/bin/imp/Service.class and path is /Service/bin/, then the class name must be imp.Service).
- Location of all needed libraries. Each library must be specified separately.
- Prior files needed to be uncompressed.
SpecificationECHO.xml is an example of this kind of configuration file.
Packing the whole service
Once all this steps are fulfilled, is time to pack together in a zip file all the needed pieces. Tis file must include the following:
- Directory with the service binary files.
- Directory with all needed libraries.
- The XML configuration file specEl xml amb l'especificació d'execució
It is a good practice to group all these files under a directory for each service, so it is easier to compile all the needed information.
Registering the service in CoDeS
The CoDeS implementation offers an API that can be used to register new services as active.
Snippet to register a service
For this step, we would need an application that performs the following tasks:
Create an instance in the CoDeS API:
This instance should be of the type CoDeSAPI and can be obtained through the publication API CoDeSAPIPublishing. Basically, we would need the following code:
This would allow us to access CoDeS to register the new service.
Create the service especification
We need to instantiate the CoDeS class ServiceSpecification with four values:
- execSpec: name of the file containing the service and the location of the XML configuration file. Currently, we use the notation nameOfTheFile:XMLLocation to specify this.
- managerSpec: number of service replicas required for its deployment.
- requirements: computing resources requirements for the service (cpu, memory, etc)
- path: boolean
Registering the service
Once we specified the service, it is time to register it using the method registerService(sid, s) de l’API. Then, using the following command, the service is finally deployed on the community and can be consumed:
DHT file upload
Finally, we need to upload the binary files of the service to the DHT, so they can be accessed when creating replicas. The CoDeS API offers the method putFile(String id, String path), which starts the file upload process if the file and an identifier is provided:
RegisterCoDeS.java is an example of service registering. In that file, all the needed steps to deploy the service ECHO are performed.
Service execution and interaction
The CoDeS API offers several methods to execute a service and communicate with it to obtain information about that execution.
Start a service
In order to start a service, we need to know its identifier and then run the following sentence:
Obtain the service location
The CoDeS API enables the developer to obtain a list of the locations (hosts) where the service was finally deployed. The following command performs this action:
The list can be iterated to obtain the addresses of the hosts offering the given service: