throw new GFacException(e);
}
}
private JobExecutionContext createJEC(String experimentID, String taskID) throws Exception {
JobExecutionContext jobExecutionContext;
TaskDetails taskData = (TaskDetails) registry.get(RegistryModelType.TASK_DETAIL, taskID);
// this is wear our new model and old model is mapping (so serviceName in ExperimentData and service name in ServiceDescriptor
// has to be same.
// 1. Get the Task from the task ID and construct the Job object and save it in to registry
// 2. Add another property to jobExecutionContext and read them inside the provider and use it.
String serviceName = taskData.getApplicationId();
if (serviceName == null) {
throw new GFacException("Error executing the job because there is not Application Name in this Experiment: " + serviceName );
}
ServiceDescription serviceDescription = airavataRegistry2.getServiceDescriptor(serviceName);
if (serviceDescription == null ) {
throw new GFacException("Error executing the job because there is not Application Name in this Experiment: " + serviceName );
}
String hostName;
HostDescription hostDescription = null;
if(taskData.getTaskScheduling().getResourceHostId() != null){
hostName = taskData.getTaskScheduling().getResourceHostId();
hostDescription = airavataRegistry2.getHostDescriptor(hostName);
}else{
List<HostDescription> registeredHosts = new ArrayList<HostDescription>();
Map<String, ApplicationDescription> applicationDescriptors = airavataRegistry2.getApplicationDescriptors(serviceName);
for (String hostDescName : applicationDescriptors.keySet()) {
registeredHosts.add(airavataRegistry2.getHostDescriptor(hostDescName));
}
Class<? extends HostScheduler> aClass = Class.forName(ServerSettings.getHostScheduler()).asSubclass(HostScheduler.class);
HostScheduler hostScheduler = aClass.newInstance();
hostDescription = hostScheduler.schedule(registeredHosts);
hostName = hostDescription.getType().getHostName();
}
if(hostDescription == null){
throw new GFacException("Error executing the job as the host is not registered " + hostName);
}
ApplicationDescription applicationDescription = airavataRegistry2.getApplicationDescriptors(serviceName, hostName);
URL resource = GFacImpl.class.getClassLoader().getResource(org.apache.airavata.common.utils.Constants.GFAC_CONFIG_XML);
Properties configurationProperties = ServerSettings.getProperties();
GFacConfiguration gFacConfiguration = GFacConfiguration.create(new File(resource.getPath()), airavataAPI, configurationProperties);
// start constructing jobexecutioncontext
jobExecutionContext = new JobExecutionContext(gFacConfiguration, serviceName);
// setting experiment/task/workflownode related information
Experiment experiment = (Experiment) registry.get(RegistryModelType.EXPERIMENT, experimentID);
jobExecutionContext.setExperiment(experiment);
jobExecutionContext.setExperimentID(experimentID);
jobExecutionContext.setWorkflowNodeDetails(experiment.getWorkflowNodeDetailsList().get(0));
jobExecutionContext.setTaskData(taskData);
// setting the registry
jobExecutionContext.setRegistry(registry);
ApplicationContext applicationContext = new ApplicationContext();
applicationContext.setApplicationDeploymentDescription(applicationDescription);
applicationContext.setHostDescription(hostDescription);
applicationContext.setServiceDescription(serviceDescription);
jobExecutionContext.setApplicationContext(applicationContext);
List<DataObjectType> experimentInputs = taskData.getApplicationInputs();
jobExecutionContext.setInMessageContext(new MessageContext(GFacUtils.getMessageContext(experimentInputs,
serviceDescription.getType().getInputParametersArray())));
List<DataObjectType> outputData = taskData.getApplicationOutputs();
jobExecutionContext.setOutMessageContext(new MessageContext(GFacUtils.getMessageContext(outputData,
serviceDescription.getType().getOutputParametersArray())));
jobExecutionContext.setProperty(Constants.PROP_TOPIC, experimentID);
return jobExecutionContext;
}