JARC

From Intrument Element Wiki

Jump to: navigation, search

In this page we will show you how to build a java client that access the Grid infrastructure using ARC middleware. This is an example of Job submission using the ARC APIs. This executable main does:

  • Prepare an HashMap with the information for accessing the Grid User Interface (UI).
  • Initialize the connection with the UI
  • Create a directory in the remote machine where the necessary files will be uploaded.
  • Uploaded the input files, executable and job description into the machine where the UI is running.
  • Verify if the job can be submitted.
  • Submit the job.
  • Monitor the execution of the job.
  • Retrieve the output of the job from the Grid.
  • Download the output from the machine where the UI is running to the local machine.
  • Remove the remote folder that has been created at the beginning.
  • Close the communication with the UI.


Libraries

Download the libraries you need to include in your program:

  • jARC.jar

If you are wondering where you can get them easily, look at our repository at the following link: jARC.jar library

Write the Code

First, we need to Prepare an HashMap with the information for accessing the Grid User Interface (UI). You can refer to the Init method of the ARCFacade class for more information about the parameters

		HashMap<String,String> parameters=new HashMap<String,String>();
		parameters.put("user", "flelli");
		parameters.put("port", "22");

		parameters.put("hostname", "ocikbnor.uzh.ch");
		parameters.put("credential", "/Users/francescolelli/.ssh/id_NoPWDdsa");
		parameters.put("UserOrganization", "unisi.ch");
		parameters.put("SWITCHID", "3004256@lu.unisi.ch");
		parameters.put("SWITCHPWD", "mySexyPassword");
		parameters.put("GridVO", "smscg");
		parameters.put("SecurityRefreshTimeSecond", "2000");

		//File Management
		parameters.put("BaseLocalSpoolPath", "/Users/francescolelli/Documents/workspace-jopera-source/arcAPIs/arc/");
		parameters.put("BaseRemoteSpoolPath", "/home/flelli/joperaArc");
		parameters.put("BaseLocalOutputSpoolPath", "/Users/francescolelli/Documents/workspace-jopera-source/arcAPIs/output");

		//Security File 
		parameters.put("SecurityLocalSpoolPath", "/Users/francescolelli/Documents/workspace-jopera-source/arcAPIs");
		parameters.put("SecurityRemoteSpoolPath", "/home/flelli/Cert");

We now Initialize the connection with the UI refer to the Init method of the ARCFacade class for more information about the parameters

		ARCFacade arc=new ARCFacade();
		String folderWhereExecuteTheJob="";
		arc.init(parameters);


then we Create a directory in the remote machine where the necessary files will be uploaded. Note that the APIs deal with / \ problems

		folderWhereExecuteTheJob=parameters.get("BaseRemoteSpoolPath")+"//\\myTestJobSubmission";
		arc.createDirectory(folderWhereExecuteTheJob);


We can then uploaded the input files, executable and job description into the machine where the UI is running.

		arc.upload(parameters.get("BaseLocalSpoolPath"), folderWhereExecuteTheJob);

Verify if the job can be submitted.

		String validationResult= arc.validateJob(folderWhereExecuteTheJob,"/arc/hallo.xrsl");	
		if (validationResult.contains(Constant.MESSAGE_PROXY_EXPIRED))
		{
			arc.renewCertificates();
		}

Submit the job.

		String jobID=arc.submitJob(folderWhereExecuteTheJob, "/arc/hallo.xrsl");


Monitor the execution of the job.

		String status="";
		while(!iAmInAnEndingState(status)){
			try {
				status = arc.checkJobStatus(jobID);
			} catch (ArcException e) {
				System.out.println("We like ArcException :-)");
				e.printStackTrace(); 
			}
			System.out.println("JobID: "+jobID+"\n Status:"+status); 
		}


	   private static boolean iAmInAnEndingState(String status) {
		if (status.contains(Constant.JOB_STATUS_FINISHED) || status.contains(Constant.JOB_STATUS_FAILED)){
		return true;
		}
		return false;
	}


Download the output from the machine where the UI is running to the local machine.

		String folderWhereStoreTheOutput=folderWhereExecuteTheJob+"/output";
		arc.createDirectory(folderWhereStoreTheOutput);
		arc.retrieveJobOutputFromGrid(jobID, folderWhereStoreTheOutput);

Download the output from the machine where the UI is running to the local machine.

		String localFolderWhereStoreTheOutput=parameters.get("BaseLocalOutputSpoolPath");
		arc.downlaod(folderWhereStoreTheOutput, localFolderWhereStoreTheOutput);

Remove the remote folder that has been created at the beginning.

		arc.remove(folderWhereExecuteTheJob);

Close the communication with the UI.

		arc.destroy();


Testing Your Code

A working example of this code can be found at: Code of this example. Note that you need the the jARC.jar library in order to run the code.

Personal tools