use of org.gridlab.gat.URI in project compss by bsc-wdc.
the class ResourceBrokerJavaJobExample method start.
public void start(String brokerURI) {
ResourceBroker broker = null;
try {
broker = GAT.createResourceBroker(new URI(brokerURI));
} catch (GATObjectCreationException e) {
System.err.println("Failed to create resource broker at location '" + brokerURI + "': " + e);
return;
} catch (URISyntaxException e) {
System.err.println("Wrong uri '" + brokerURI + "': " + e);
return;
}
JavaSoftwareDescription sd = new JavaSoftwareDescription();
sd.setExecutable("/usr/bin/java");
sd.setJavaMain("my.package.HelloWorld");
sd.setJavaArguments("hello", "world");
sd.setJavaClassPath("myJar1:myDir");
sd.setJavaOptions("-version");
sd.addJavaSystemProperty("key", "value");
try {
sd.setStdout(GAT.createFile("javajob.txt"));
} catch (GATObjectCreationException e) {
System.err.println("Failed to create the stdout file 'javajob.txt': " + e);
return;
}
JobDescription jd = new JobDescription(sd);
Job job = null;
try {
job = broker.submitJob(jd);
} catch (GATInvocationException e) {
System.err.println("Failed to submit the job: " + e);
return;
}
while (job.getState() != JobState.STOPPED) {
System.out.println("job is in state: " + job.getState());
try {
Thread.sleep(200);
} catch (InterruptedException e) {
// ignore
}
}
}
use of org.gridlab.gat.URI in project compss by bsc-wdc.
the class TestSubmitGlobus method test.
public void test(final String host) throws Exception {
final SoftwareDescription sd = new SoftwareDescription();
sd.setExecutable("/bin/sleep");
sd.setArguments("10");
final JobDescription jd = new JobDescription(sd);
Preferences prefs = new Preferences();
prefs.put("resourcebroker.adaptor.name", "wsgt4new");
prefs.put("file.adaptor.name", "local,gridftp");
CertificateSecurityContext ctxt = new CertificateSecurityContext(new URI(System.getProperty("user.home") + "/.globus/userkey.pem"), new URI(System.getProperty("user.home") + "/.globus/usercert.pem"), getPassphrase());
final GATContext context = new GATContext();
context.addPreferences(prefs);
context.addSecurityContext(ctxt);
File[] files = new File[NFILES];
for (int i = 0; i < files.length; i++) {
files[i] = GAT.createFile(context, "file" + i);
files[i].createNewFile();
}
for (File f : files) {
sd.addPreStagedFile(f);
sd.addPostStagedFile(f);
}
final ResourceBroker broker = GAT.createResourceBroker(context, new URI(host));
for (int j = 0; j < NBATCHES; j++) {
logger.info("Starting a batch of " + NJOBS + " jobs");
for (int i = 0; i < NJOBS; i++) {
Thread t = new Thread() {
public void run() {
try {
broker.submitJob(jd, TestSubmitGlobus.this, "job.status");
} catch (Throwable e) {
System.out.println("Submit failed");
e.printStackTrace();
synchronized (TestSubmitGlobus.this) {
finished++;
TestSubmitGlobus.this.notifyAll();
}
}
}
};
t.start();
}
synchronized (this) {
while (finished < NJOBS * (j - BACK)) {
logger.info("Waiting until at least " + (NJOBS * (j - BACK)) + " jobs are finished");
try {
wait();
} catch (Throwable e) {
// ignore
}
}
}
}
synchronized (this) {
while (finished != NJOBS * NBATCHES) {
try {
wait();
} catch (Throwable e) {
// ignore
}
}
}
}
use of org.gridlab.gat.URI in project compss by bsc-wdc.
the class RemoteCat method main.
public static void main(String[] args) throws Exception {
FileInputStream in = GAT.createFileInputStream(new URI(args[0]));
java.io.InputStreamReader reader = new java.io.InputStreamReader(in);
java.io.BufferedReader buf = new java.io.BufferedReader(reader);
while (true) {
String result = buf.readLine();
if (result == null) {
break;
}
System.out.println(result);
}
in.close();
GAT.end();
}
use of org.gridlab.gat.URI in project compss by bsc-wdc.
the class SubmitJobCallback method start.
public void start(String brokerURI) throws GATObjectCreationException, URISyntaxException, GATInvocationException {
SoftwareDescription sd = new SoftwareDescription();
sd.setExecutable("/bin/hostname");
File stdout = GAT.createFile("hostname.txt");
sd.setStdout(stdout);
JobDescription jd = new JobDescription(sd);
ResourceBroker broker = GAT.createResourceBroker(new URI(brokerURI));
broker.submitJob(jd, this, "job.status");
synchronized (this) {
try {
wait();
} catch (InterruptedException e) {
// ignore
}
}
}
use of org.gridlab.gat.URI in project compss by bsc-wdc.
the class SecurityExample method main.
/**
* This example shows the use of the SecurityContext objects in JavaGAT.
*
* This example will attach various security contexts to a GATContext. Then
* it will try to create the same file with and without this GATContext.
* Note that you've to replace the arguments of the methods with values that
* are suitable for your environment. Please don't put passwords and
* passphrases directly in the source code, but try to retrieve by having
* the user to type it.
*
* @param args
* a String representation of a valid JavaGAT uri that points
* to a file
*/
public static void main(String[] args) {
GATContext context = new GATContext();
try {
// create a certificate security context
CertificateSecurityContext globusSecurityContext = new CertificateSecurityContext(new URI("userkey.pem"), new URI("usercert.pem"), "grid-proxy-init passphrase");
// add a note to this security context; it's only to be used for the
// globus and wsgt4new adaptors
globusSecurityContext.addNote("adaptors", "globus,wsgt4new");
context.addSecurityContext(globusSecurityContext);
} catch (URISyntaxException e) {
// ignore
}
// create a password security context
PasswordSecurityContext ftpSecurityContext = new PasswordSecurityContext(System.getProperty("user.name"), "ftp password");
// add a note to this security context; it's only to be used for ftp and
// only for two hosts, host1 and host2:21
ftpSecurityContext.addNote("adaptors", "ftp");
ftpSecurityContext.addNote("hosts", "host1,host2:21");
context.addSecurityContext(ftpSecurityContext);
PasswordSecurityContext sshSecurityContext = new PasswordSecurityContext(System.getProperty("user.name"), "ssh password");
// add a note to this security context; it's only to be used for
// sshtrilead and commandlinessh and only for one host, host3
sshSecurityContext.addNote("adaptors", "sshtrilead,commandlinessh");
sshSecurityContext.addNote("hosts", "host3");
context.addSecurityContext(sshSecurityContext);
// contexts attached
try {
File file = GAT.createFile(context, new URI(args[0]));
System.out.println(args[0] + " exists: " + file.exists());
} catch (Exception e) {
System.err.println("Failed to check whether '" + args[0] + "' exists: " + e);
}
// contexts.
try {
File file2 = GAT.createFile(new URI(args[0]));
System.out.println(args[0] + " exists: " + file2.exists());
} catch (Exception e) {
System.err.println("Failed to check whether '" + args[0] + "' exists: " + e);
}
}
Aggregations