Version 16 (modified by mmamonski, 11 years ago) (diff)

--

Binary distribution

Download the QCG-Computing Java SDK from the downloads section. You will find all needed jars in the lib directory.

Compiling from sources

In order to get the newest version of the QCG-Computing SDK we recommend you to compile it using sources checkouted directly from SVN. You will need to perform the following steps (beforehand make sure that  maven is installed in your system)

mkdir sdk
cd sdk
#at first compile and install the QCG-Core SDK (a dependency for QCG-Computing SDK)
svn co https://apps.man.poznan.pl/svn/qcg-core/trunk/java/WSIT/QCGCoreSDK
cd QCGCoreSDK/endorsed
./install-endorsed.sh
...
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------------
[INFO] Total time: < 1 second
[INFO] Finished at: Thu Dec 08 14:38:03 CET 2011
[INFO] Final Memory: 6M/219M
[INFO] ------------------------------------------------------------------------
cd ..
mvn install
[INFO] Installing /home/qcg-dev/sdk/QCGCoreSDK/target/QCGCoreSDK-2.1.1.jar to /home/qcg-dev/.m2/repository/org/qcg/QCGCoreSDK/2.1.1/QCGCoreSDK-2.1.1.jar
[INFO] Installing /home/qcg-dev/sdk/QCGCoreSDK/target/QCGCoreSDK-2.1.1-jar-with-dependencies.jar to /home/qcg-dev/.m2/repository/org/qcg/QCGCoreSDK/2.1.1/QCGCoreSDK-2.1.1-jar-with-dependencies.jar
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 40 seconds
[INFO] Finished at: Thu Dec 08 15:01:36 CET 2011
[INFO] Final Memory: 44M/492M
[INFO] ------------------------------------------------------------------------

cd ..
#finally checkout and build the QCG-Computing SDK
svn co https://apps.man.poznan.pl/svn/qcg-computing/trunk
cd trunk/java/WSIT/QCGComputingSDK
mvn install:install-file -DgroupId=org.metastatic.rsync -DartifactId=JarSync -Dpackaging=jar -Dversion=0.3 -Dfile=lib/jarsync.jar
mvn -Dmaven.test.skip=true package


Example Usage

Job Management and Data Staging

The below example shows how to:

  • stage input file
  • submit a simple job and wait until it finishes
  • list remote directories
  • stage output files

We assume that you have already initialized your security context:

  • user cert and key installed in ~/.globus
  • trusted CAs installed either in ~/.globus/certificates or /etc/grid-security/certificates
		/* 1. Generate proxy from your certificate */
		GSIProxy.generateProxy("my-password");
		
		/* 2. Create service stubs */
		QCGFactory besFactory =  new QCGFactory(QCG_COMPUTING_HOST, QCG_COMPUTING_PORT, new GSIAuthentication());
		QCGStaging staging = new QCGStaging(QCG_COMPUTING_HOST, 19000, new GSIAuthentication(), new SimpleFileStagingHandler());
		
		
		/* 3. Create sandbox directory on remote cluster */
		String jobDir = UUID.randomUUID().toString();
		staging.mkdir(jobDir, "0700", null);
		
		/* 4. Create input file */
		FileWriter fw = new FileWriter("input.txt");
		fw.write("2 + 2\n");
		fw.close();
		
		/* 5. Stage the input file */
		JSDL stageInJSDL = new JSDL("stage-In");
		stageInJSDL.setWorkingDirectory(jobDir);
		stageInJSDL.getDataStaging().add(new JSDLDataStaging("input.txt" /* remote file name */, "input.txt" /* local file name */, null));
		staging.stageInFiles(stageInJSDL);
			
		
		/* 6. create JSDL document for simple job*/
		JSDL simpleJSDL = new JSDL("SimpleCalculation");
		
		simpleJSDL.setWorkingDirectory(jobDir);
		simpleJSDL.setExecutable("/usr/bin/bc");
		simpleJSDL.getArguments().add("-q");
		simpleJSDL.setInput("input.txt");
		simpleJSDL.setOutput("result.txt");
		
		/* 7. submit a job */
		ActivityEndpointReference jobEpr = besFactory.createActivity(simpleJSDL);
		System.out.println("Submitted a job: " + jobEpr.getActivityUUID());
		
		/* 8. wait for termination */
		QCGActivityStatus status = null;
		while (!( status = besFactory.getActivityStatus(jobEpr)).isFinalState()) { 
			Thread.sleep(2000);
			System.out.println("Status: " + status.getBESSubStateName());
		}
		
		/* 9. Print final status */
		if (status.getBESStateName().equals(QCGActivityStatus.QCG_ACTIVITY_STATE_FINISHED)) {
			System.out.println("Job has finished with exit status: " + status.getEndStatus().getExitStatus() );
		} else if (status.getBESStateName().equals(QCGActivityStatus.QCG_ACTIVITY_STATE_FAILED)){
			System.err.println("Job failed");
		} else if (status.getBESStateName().equals(QCGActivityStatus.QCG_ACTIVITY_STATE_CANCELLED)){
			System.err.println("Job was cancelled");
		}
		
		/* 10. Get file list */
		JSDL listJSDL = new JSDL("list-dir");
		listJSDL = staging.listDirectory(jobDir, null);
		List<String> fileList = new ArrayList<String>();
		for (JSDLDataStaging ds : listJSDL.getDataStaging()) {
			fileList.add(jobDir + "/" + ds.getFileName());
		}
		
		FileInfo filesInfo[] = staging.statFile(fileList, null);
		
		System.out.println("Directory listing: ");
		for (int i = 0; i < filesInfo.length; i++) {
			System.out.printf(" %-20s : size = %6d mode = %s\n", 
					listJSDL.getDataStaging().get(i).getFileName(), 
					filesInfo[i].getSize(),
					filesInfo[i].getMode()
					);
		}
		
		/* 11. Stage output file */
		JSDL stageOutJSDL = new JSDL("Stage-Out");
		stageOutJSDL.setWorkingDirectory(jobDir);
		stageOutJSDL.getDataStaging().add(new JSDLDataStaging("result.txt" /*remote file name */, null, "result.txt" /* local file name */));
		staging.stageOutFiles(stageOutJSDL);
		
		/* 12 Read file */
		BufferedReader br = new BufferedReader(new FileReader("result.txt"));
		System.out.println();
		System.out.println("result = " + br.readLine());
		br.close();
		
		/* 13 cleanup remote job directory*/
		for (int i = 0; i < filesInfo.length; i++) {
			if ((filesInfo[i].getMode() & FileInfo.S_IFDIR) == 0) 
				staging.delete(fileList.get(i), null);
		}
		staging.delete(jobDir, null);

Other authentication mechanisms

SSL (https)

/* mutual authentication - PEM files */
SSLAuthentication(String CAFile, String CAPath, String userCertKey, String keyPassphrase, String trustedDN) throws IOException
/* server only authentication - PEM files */
SSLAuthentication(String CAFile, String CAPath, String trustedDN)  throws IOException, GeneralSecurityException
/* mutual authentication - certs loaded from streams */
SSLAuthentication(List<InputStream> caList, InputStream userCertKey, String keyPassphrase, String trustedDN) throws IOException, GeneralSecurityException

GSI (httpg)

GSIAuthentication(String trustedDN) throws IOException

GSIAuthentication(String   userProxy, String trustedDN) throws IOException

GSIAuthentication(InputStream  userProxy, String trustedDN) throws IOException