= Binary distribution = Download the QCG-Computing Java SDK from the [http://www.qoscosgrid.org/trac/qcg-computing/downloads downloads] section. You will find all needed jars in the lib directory. = 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 fileList = new ArrayList(); 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 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 }}}