throws GFacProviderException {
UnicoreHostType host = (UnicoreHostType) jobExecutionContext.getApplicationContext().getHostDescription().getType();
String factoryUrl = host.getUnicoreBESEndPointArray()[0];
EndpointReferenceType eprt = EndpointReferenceType.Factory.newInstance();
eprt.addNewAddress().setStringValue(factoryUrl);
CreateActivityDocument cad = CreateActivityDocument.Factory
.newInstance();
JobDefinitionType jobDefinition = null;
try {
//FIXME: Replace by a native client
// jobDefinition = JSDLGenerator.buildJSDLInstance(jobExecutionContext).getJobDefinition();
// cad.addNewCreateActivity().addNewActivityDocument().setJobDefinition(jobDefinition);
System.out.println("REMOVE ME");
} catch (Exception e1) {
throw new GFacProviderException("Cannot generate JSDL instance from the JobExecutionContext.",e1);
}
FactoryClient factory = null;
try {
factory = new FactoryClient(eprt, secProperties);
} catch (Exception e) {
throw new GFacProviderException("");
}
CreateActivityResponseDocument response = null;
try {
log.info(String.format("Activity Submitting to %s ... \n", factoryUrl));
response = factory.createActivity(cad);
log.info(String.format("Activity Submitted to %s \n", factoryUrl));
} catch (Exception e) {
e.printStackTrace();
throw new GFacProviderException("Cannot create activity.", e);
}
EndpointReferenceType activityEpr = response
.getCreateActivityResponse().getActivityIdentifier();
log.debug("Activity EPR: "+activityEpr);
log.info("Activity: "+activityEpr.getAddress().getStringValue()+ " Submitted.");
//factory.waitWhileActivityIsDone(activityEpr, 1000);
jobId = WSUtilities.extractResourceID(activityEpr);
if (jobId == null) {
jobId = new Long(Calendar.getInstance().getTimeInMillis())
.toString();
}
saveApplicationJob(jobExecutionContext, jobDefinition);
log.info(formatStatusMessage(activityEpr.getAddress().getStringValue(), factory.getActivityStatus(activityEpr)
.toString()));
//TODO publish the status messages to the message bus
while ((factory.getActivityStatus(activityEpr) != ActivityStateEnumeration.FINISHED) &&
(factory.getActivityStatus(activityEpr) != ActivityStateEnumeration.FAILED)){
ActivityStatusType activityStatus = null;
try {
activityStatus = getStatus(factory, activityEpr);
GFacUtils.updateApplicationJobStatus(jobExecutionContext, jobId, getApplicationJobStatus(activityStatus));
log.info (subStatusAsString(activityStatus));
} catch (UnknownActivityIdentifierFault e) {
throw new GFacProviderException(e.getMessage(), e.getCause());
}
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
}
continue;
}
ActivityStatusType activityStatus = null;
try {
activityStatus = getStatus(factory, activityEpr);
} catch (UnknownActivityIdentifierFault e) {
throw new GFacProviderException(e.getMessage(), e.getCause());
}
log.info(formatStatusMessage(activityEpr.getAddress().getStringValue(), activityStatus.getState().toString()));
if ((activityStatus.getState() == ActivityStateEnumeration.FAILED)) {
log.info(activityStatus.getFault().getFaultcode().getLocalPart()
+ "\n" + activityStatus.getFault().getFaultstring());
log.info("EXITCODE: "+activityStatus.getExitCode());