How to use the DataMiner Pool Manager

From Gcube Wiki
Revision as of 11:18, 17 May 2017 by Nunzioandreagalante (Talk | contribs) (Architecture)

Jump to: navigation, search

DataMiner Pool Manager

DataMiner Pool Manager service, aka DMPM, is a REST service able to rationalize and automatize the current process for publishing SAI algorithms on DataMiner nodes and keep DataMiner cluster updated.


Architecture

The following main entities will be involved in the process of integration between SAI and the production environment:

  • SAI: such component allows the user to upload the Package related to the algorithm to deploy and to decide on which VRE
  • Dataminer Pool Manager: a Smartgears REST service in charge of managing the installation of algorithms on the infrastructure dataminers
  • The Staging DataMiner: a particular dataminer machine, usable only by the Dataminer Pool Manager, used to test the installation of an algorithm and to its dependencies
  • SVN Dependencies Lists: lists (in files on SVN) of dependencies to must be installed on Dataminer machines. There is one list for type of dependency (system, github, cran) both for RPrototypingLab and for Production. The list should also contain references to algorithms that use each package. E.g.
     <package-name> [alg1, alg2, alg3]
  • The Cron job: runs on every Dataminer and periodically (every minute) aligns the packages installed on the machine with the SVN Dependencies List (both Production and RPrototypingLab)

Requirements

On the host where the Service is deployed, must be possible to execute the ansible-playbook command, in order to allow the installation of the dependencies on the staging dataminer, and to install the algorithm on the target VRE The dependencies in the metadata file inside the algorithm package (coming from SAI then), must respect the following guidelines: R Dependencies must have prefix cran: OS Dependencies must have prefix os: Custom Dependencies must have prefix github: At least for the staging dataminer used in the test phase, the application must have SSH root access; for the installation of the algorithm at production level instead, should have to be enough the gcube priviliges.


Process (From SAI to Production VRE)

The idea is to have just an instance of SAI in RPrototypingLab VRE and allow the user to specify the VRE by providing the token for that VRE. The Installation of the new algorithms by means of SAI involves the following input therefore:

Package containing Metadata and dependencies The target VRE and the token to access it

The process is composed of two main phases:

TEST Phase: installation of an algorithm and its deps in the staging dataminer; it ends with the publishing of an algorithm in the pool of dataminers of the RPrototypingLab VRE; The DMPM contacts the Staging Dataminer and installs the algorithm and the dependencies The output is retrieved. If there are errors in the installation (e.g. a dependency that does not exist) it stops and the log is returned to the user The DMPM updates the SVN RPrototypingLab Dependencies lists Install the algorithm only (not the dependencies) in RPrototypingLab dataminers Publish the new algorithm in RPrototypingLab VRE (the script do this by itself: if an algorithm is already available on the IS in that scope, the script updates the .jar files, but the resource on the IS, the .properties and the wps config do not change)

RELEASE Phase SAI will invoke the service working in RELEASE PHASE in order to install the algorithm in a particular VRE of production (provided by the user); SAI will pass to the DMPM the target VRE name and the token to access to that VRE The DMPM updates the SVN Production Dependencies lists Install the algorithm only (not the dependencies) in the production dataminers Publish the algorithm in the VRE


SAI is deployed in several scopes and the user may deploy the algorithm just in the actual VRE. The idea now is to have just an instance of SAI in RProto and allow the user to specify the VRE by providing the token for that VRE. Ideally both the token and the name of the VRE will be passed to the DMPM service in order to install the algorithm in that VRE.


Functionalities

The DMPM REST Service will expose three main functionalities: TEST PHASE: A method able to test the installation of the algorithm and its dependencies on a staging dataminer first, to update the SVN lists dedicated to RPrototypingLab, and to install the algorithm on the set of dataminers of RPrototypingLab VRE. The parameters to consider are the following: the algorithm (URL to package containing the dependencies and the script to install) the category to which the algorithm belong to the VRE token from which SAI is used (ideally RPrototypingLab)

   An example of Rest call is the following:

http://node2-d-d4s.d4science.org:8080/dataminer-pool-manager-1.0.0-SNAPSHOT/rest/algorithm/stage?gcube-token=708e7eb8-11a7-4e9a-816b-c9ed7e7e99fe-98187548&algorithmPackageURL=http://data.d4science.org/dENQTTMxdjNZcGRpK0NHd2pvU0owMFFzN0VWemw3Zy9HbWJQNStIS0N6Yz0&category=ICHTHYOP_MODEL

RELEASE PHASE: a method invoked from SAI, executed after that the Test phase has successfully finished, able to update the SVN list of production with the dependencies extracted from the package (if new ones), and to install the algorithm on a set of Dataminers/a single one belonging to a particular production VRE provided by the user. Some of the parameters to consider are the following: the algorithm (URL to package containing the dependencies and the script to install) the category to which the algorithm belong to the VRE token from which SAI is used (ideally RPrototypingLab) The target VRE on which install the algorithm The token for the target VRE

An example of Rest call is the following:

       http://node2-d-d4s.d4science.org:8080/dataminer-pool-manager-1.0.0-SNAPSHOT/rest/algorithm/add?gcube-token=708e7eb8-11a7-4e9a-816b-c9ed7e7e99fe-98187548&algorithmPackageURL=http://data.d4science.org/dENQTTMxdjNZcGRpK0NHd2pvU0owMFFzN0VWemw3Zy9HbWJQNStIS0N6Yz0&category=ICHTHYOP_MODEL&targetVREToken=3a23bfa4-4dfe-44fc-988f-194b91071dd2-843339462&targetVRE=/d4science.research-infrastructures.eu/gCubeApps/RPrototypingLab    

The result of the execution will be monitored asynchronously by means of a REST call to a log having as parameter the ID of the operation. This can be done both at TEST and RELEASE phases.

       http://node2-d-d4s.d4science.org:8080/dataminer-pool-manager-1.0.0-SNAPSHOT/rest/log?gcube-token=708e7eb8-11a7-4e9a-816b-c9ed7e7e99fe-98187548&logUrl=426c8e35-a624-4710-b612-c90929c32c27 



Overview

The service may accept an algorithm descriptor, including its dependencies (either OS, R and custom packages), queries the IS for dataminers in the current scope, generates (via templating) ansible playbook, inventory and roles for relevant stuff (algorithm installer, algorithms, dependencies), executes ansible playbook on a DataMiner.

In such sense, the service accepts as input, among the others, the url of an algorithm package (including jar, and metadata), extracts the information needed to installation, installs the script, update the list of dependencies, optionally publishs the new algorithm in the Information System and returns asynchronously the execution outcome to the caller.

Maven coordinates

The first version of the the service will be released in gCube 4.4.0 released. The maven artifact coordinates are:

<dependency>
   <groupId>org.gcube.dataanalysis</groupId>
   <artifactId>dataminer-pool-manager</artifactId>
   <version>2.0.0-SNAPSHOT</version> 
   <packaging>war</packaging>
</dependency>

Configuration and Testing

DMPM is a SmartGears compliant service.

/home/gcube/SmartGears-Bundle/tomcat/webapps/dataminer-pool-manager-2.0.0-SNAPSHOT

In such sense, an instance has already been deployed and configured at Development level.

http://node2-d-d4s.d4science.org:8080/dataminer-pool-manager-2.0.0-SNAPSHOT/rest/

Such environment contains the configurations for ansible playbook, inventory and roles for algorithm installer, scripts, algorithms, dependencies and the logs of the execution.

/home/gcube/tomcat/webapps/dataminer-pool-manager/WEB-INF/classes/static          // static resource inside the WAR containing static roles
/home/gcube/tomcat/webapps/dataminer-pool-manager/WEB-INF/classes/templates      // static resource inside the WAR containing the templates
/home/gcube/tomcat/webapps/dataminer-pool-manager/WEB-INF/classes/custom   // static resource inside the WAR containing the custom roles
/home/gcube/dataminer-pool-manager/dpmConfig/service.properties       // static resource on the filesystem containing configuration data
/home/gcube/dataminer-pool-manager/jobs    //dynamically generated resource concerning the logs of the different job executions
/home/gcube/dataminer-pool-manager/work    //dinamically generated resource concerning the Ansible worker for each job

In order to allow Ansible to work on the pool of DataMiners, is necessary that the SSH key of the VM on which the service run (e.g., node2-d-d4s.d4science.org) must be deployed on the pool of dataminers with root permissions.

Requirements

The dependencies in the metadata file inside the algorithm package, must respect the following guidelines:

  • R Dependencies must have prefix cran:
  • OS Dependencies must have prefix os:
  • Custom Dependencies must have prefix github:

In case no prefix is specified, the service considers such dependencies as OS ones.

Usage and APIs

Currently the service exposes the following REST methods:

  • Adding an Algorithm to a single DataMiner host

Such functionality installs the Algorithm on the specific DataMiner, update the SVN list of dependencies, optionally stores the algorithm in the Information System and returns immediately the log ID useful to monitor the execution. It is possible to use such feature in case the service runs inside a VRE having a single dataminer (e.g., pre-production environment).


addAlgorithmToHost(algorithm, hostname, name, description, category, algorithmType, skipJava, publish, updateSVN);


        @GET
	@Path("/hosts/add")
	@Produces("text/plain")
	public String addAlgorithmToHost(
			@QueryParam("algorithm") String algorithm, 
			@QueryParam("hostname") String hostname,
			@QueryParam("name") String name,
			@QueryParam("description") String description,
			@QueryParam("category") String category,
			@DefaultValue("transducerers") @QueryParam("algorithmType") String algorithmType,
			@DefaultValue("N") @QueryParam("skipJava") String skipJava,
			@DefaultValue("false") @QueryParam("publish") boolean publish,
			@DefaultValue("false") @QueryParam("updateSVN") boolean updateSVN)
			throws IOException, InterruptedException, SVNException {
		Algorithm algo = this.getAlgorithm(algorithm, null, hostname, name, description, category, algorithmType,
				skipJava);
		// publish algo
 
		if (publish) {
			service.addAlgToIs(algo);
		}
		return service.addAlgorithmToHost(algo, hostname, updateSVN);
	}


It is possible to distinguish among mandatories parameters and optional ones:

  • Mandatories:
    • algorithm: URL related the package of the Algorithm; such parameter is mandatory.
    • hostname: the hostname of the DataMiner on which deploy the script; such parameter is mandatory.
  • Optionals (The overall set of parameters, except the mandatory ones. can be extract from the metadata file (where available), or overwritten by the caller):
    • name: the name of the Algorithm (e.g.,ICHTHYOP_MODEL_ONE_BY_ONE )
    • description: the description of the Algorithm
    • category: the category to which the Algorithm belongs to (e.g, ICHTHYOP_MODEL)
    • algorithmType: by default set to "transducerers"
    • skipJava: by default set to "N"
    • publish: by default set to "false"; the registration of the algorithm in the VRE is currently done both by the service and by the install script (addAlgorithm.sh); by the way, if set to true, this parameter forces the registration in the IS of the deployed algorithm at caller scope level. The algorithm will be registered as Generic Resource.
    • updateSVN: by default set to "false"; If the package contains dependencies not present in the SVN list of R/OS/GitHub Packages to be installed, the caller can set such parameter to true and they will be added to such lists in the related files by using the default svn credentials of the caller (~/.subversion folder). The update happens only at the end of the process, when the algorithm has been successfully deployed

An example of the usage is the following:

http://node2-d-d4s.d4science.org:8080/dataminer-pool-manager-1.0.0-SNAPSHOT/rest/hosts/add?gcube-token=VRE_TOKEN_ID&algorithm=URL_TP_ALGORITHM&hostname=TARGET_DATAMINER


  • Adding an Algorithm to the set of DataMiners (or a single one) available in the VRE

Such functionality installs the Algorithm on the set of dataminers of a particular VRE, update the SVN list of dependencies, optionally stores the algorithm in the Information System and returns immediately the log ID useful to monitor the execution. It's possible to automatically retrieve the set of dataminers in a cluster from the HA proxy. In fact, this exposes its status in csv format where we can retrieve the association between clusters and dataminers. (In the future, the cluster and the list of dataminers associated, will be available as properties of the service endpoint related to HAProxy resource in the IS. DMPM will be made compliant with such modification in the gCube release 4.5.0). For this to be effective, the name of the cluster in the HAProxy has been normalized with the name of dataminer/haproxy in the VRE. By relying on this, given a VRE (e.g. RProtoLab), the service will be able to deploy an algorithm to all dataminers belonging to it. In case the HAProxy is a dataminer itself (e.g., pre-production environment), the service is able to install automatically the algorithm just on it.

addAlgorithmToVRE(algorithm, name, description, category, algorithmType, skipJava, publish, updateSVN);


        @GET
	@Path("/scopes/add")
	@Produces("text/plain")
	public String addAlgorithmToVRE(
			@QueryParam("algorithm") String algorithm, 
			@QueryParam("name") String name,
			@QueryParam("description") String description,
			@QueryParam("category") String category,
			@DefaultValue("transducerers") @QueryParam("algorithmType") String algorithmType,
			@DefaultValue("N") @QueryParam("skipJava") String skipJava,
			@DefaultValue("false") @QueryParam("publish") boolean publish,
			@DefaultValue("false") @QueryParam("updateSVN") boolean updateSVN)
			throws IOException, InterruptedException, SVNException {
		Algorithm algo = this.getAlgorithm(algorithm, /*vre*/null, null, name, description, category, algorithmType, skipJava);
 
		// publish algo
		if (publish) {
			service.addAlgToIs(algo);
		}
		return service.addAlgorithmToVRE(algo, ScopeProvider.instance.get(), updateSVN);
	}


It is possible to distinguish among mandatories parameters and optional ones:

  • Mandatories:
    • algorithm: URL related the package of the Algorithm; such parameter is mandatory.
  • Optionals (The overall set of parameters, except the mandatory ones. can be extract from the metadata file (where available), or overwritten by the caller):
    • name: the name of the Algorithm (e.g., ICHTHYOP_MODEL_ONE_BY_ONE )
    • description: the description of the Algorithm
    • category: the category to which the Algorithm belongs to (e.g, ICHTHYOP_MODEL)
    • algorithmType: by default set to "transducerers"
    • skipJava: by default set to "N"
    • publish: by default set to "false"; the registration of the algorithm in the VRE is currently done both by the service and by the install script (addAlgorithm.sh); by the way, if set to true, this parameter forces the registration in the IS of the deployed algorithm at caller scope level. The algorithm will be registered as Generic Resource.
    • updateSVN: by default set to "false"; If the package contains dependencies not present in the SVN list of R/OS/GitHub Packages to be installed, the caller can set such parameter to true and they will be added to such lists in the related files by using the default svn credentials of the caller (~/.subversion folder). The update happens only at the end of the process, when the algorithm has been successfully deployed.

An example of the usage is the following:

http://node2-d-d4s.d4science.org:8080/dataminer-pool-manager-1.0.0-SNAPSHOT/rest/scopes/add?gcube-token=VRE_TOKEN_ID&algorithm=URL_TP_ALGORITHM


  • Monitoring the execution

Such functionality allows the caller to monitor asynchronously the execution by using the log ID obtained when an algorithm is deployed.

getLogById(logID);


   @GET
   @Path("/log")
   @Produces("text/plain")
   public String getLogById(@QueryParam("logUrl") String logUrl) throws IOException {
       // TODO Auto-generated method stub
       LOGGER.debug("Returning Log =" + logUrl);
       return service.getScriptFromURL(service.getURLfromWorkerLog(logUrl));
   }


An example of the usage is the following:

http://node2-d-d4s.d4science.org:8080/dataminer-pool-manager-1.0.0-SNAPSHOT/rest/log?gcube-token=TOKEN_ID&logUrl=LOG_ID