use of org.gridlab.gat.GATContext in project compss by bsc-wdc.
the class LogicalFileAdaptorTest method test.
public AdaptorTestResult test(String adaptor, String[] hosts) throws URISyntaxException {
if (hosts.length != 4) {
System.out.println("please provide 4 hosts (comma separated, no spaces)");
System.exit(1);
}
AdaptorTestResult adaptorTestResult = new AdaptorTestResult(adaptor, hosts[0]);
GATContext gatContext = new GATContext();
Preferences preferences = new Preferences();
preferences.put("logicalfile.adaptor.name", adaptor);
LogicalFile logicalFile = null;
try {
logicalFile = GAT.createLogicalFile(gatContext, preferences, "test-logical-file", LogicalFile.CREATE);
} catch (GATObjectCreationException e) {
e.printStackTrace();
GAT.end();
System.exit(1);
}
adaptorTestResult.put("replicate [0]", replicateTest(gatContext, preferences, logicalFile, new URI("any://" + hosts[0] + "/JavaGAT-test-logical-file"), false));
adaptorTestResult.put("add [0]", addTest(gatContext, preferences, logicalFile, new URI("any://" + hosts[0] + "/JavaGAT-test-logical-file"), true));
adaptorTestResult.put("add false [1]", addTest(gatContext, preferences, logicalFile, new URI("any://" + hosts[1] + "/JavaGAT-test-logical-file"), false));
adaptorTestResult.put("replicate [1]", replicateTest(gatContext, preferences, logicalFile, new URI("any://" + hosts[1] + "/JavaGAT-test-logical-file"), true));
adaptorTestResult.put("remove [1]", removeTest(gatContext, preferences, logicalFile, new URI("any://" + hosts[1] + "/JavaGAT-test-logical-file"), true));
adaptorTestResult.put("add true [1]", addTest(gatContext, preferences, logicalFile, new URI("any://" + hosts[1] + "/JavaGAT-test-logical-file"), true));
adaptorTestResult.put("replicate2[1]", replicateTest(gatContext, preferences, logicalFile, new URI("any://" + hosts[1] + "/JavaGAT-test-logical-file"), false));
adaptorTestResult.put("replicate [2]", replicateTest(gatContext, preferences, logicalFile, new URI("any://" + hosts[2] + "/JavaGAT-test-logical-file"), true));
adaptorTestResult.put("closest [3]", closestTest(gatContext, preferences, logicalFile, new URI("any://" + hosts[3] + "/JavaGAT-test-logical-file"), true));
return adaptorTestResult;
}
use of org.gridlab.gat.GATContext 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.GATContext 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);
}
}
use of org.gridlab.gat.GATContext in project compss by bsc-wdc.
the class GATAdaptor method init.
public void init() {
// Create request queues
copyQueue = new RequestQueue<DataOperation>();
safeQueue = new RequestQueue<DataOperation>();
String adaptor = System.getProperty(COMPSsConstants.GAT_FILE_ADAPTOR);
if (debug) {
logger.debug("Initializing GAT");
}
pool = new ThreadPool(GAT_POOL_SIZE, POOL_NAME, new Dispatcher(copyQueue));
try {
pool.startThreads();
} catch (Exception e) {
ErrorManager.error(THREAD_POOL_ERR, e);
}
safePool = new ThreadPool(SAFE_POOL_SIZE, SAFE_POOL_NAME, new Dispatcher(safeQueue));
try {
safePool.startThreads();
} catch (Exception e) {
ErrorManager.error(THREAD_POOL_ERR, e);
}
// GAT adaptor path
if (debug) {
logger.debug("Initializing GAT Tranfer Context");
}
transferContext = new GATContext();
/*
* We need to try the local adaptor when both source and target hosts are local, because ssh file adaptor cannot
* perform local operations
*/
transferContext.addPreference("File.adaptor.name", adaptor + ", srcToLocalToDestCopy, local");
}
use of org.gridlab.gat.GATContext in project compss by bsc-wdc.
the class AdvertJob method main.
public static void main(String[] args) throws Exception {
try {
GATContext c = new GATContext();
Preferences prefs = new Preferences();
prefs.put("File.adaptor.name", "local,commandlinessh");
prefs.put("job.stop.on.exit", "false");
c.addPreferences(prefs);
SoftwareDescription sd = new SoftwareDescription();
sd.setExecutable("/bin/sleep");
sd.setArguments("100");
// stdout & stderr
File stdout = GAT.createFile(c, "std.out");
File stderr = GAT.createFile(c, "std.err");
sd.setStderr(stderr);
sd.setStdout(stdout);
ResourceDescription rd = new HardwareResourceDescription();
JobDescription jd = new JobDescription(sd, rd);
ResourceBroker broker = GAT.createResourceBroker(c, new URI("sshsge://fs0.das3.cs.vu.nl"));
Job job = broker.submitJob(jd);
AdvertService a = GAT.createAdvertService(c);
MetaData m = new MetaData();
m.put("name", "testJob");
a.add(job, m, "/rob/testJob");
a.exportDataBase(new URI("file:///mydb"));
GAT.end();
System.exit(0);
} catch (Throwable e) {
e.printStackTrace();
}
}
Aggregations