public class ResourceProcessor {
public static void generateResourceElements(JobDefinitionType value, JobExecutionContext context) throws Exception{
HpcApplicationDeploymentType appDepType = (HpcApplicationDeploymentType) context
.getApplicationContext().getApplicationDeploymentDescription()
.getType();
createMemory(value, appDepType);
ContextHeaderDocument.ContextHeader currentContextHeader = context.getContextHeader();
if(currentContextHeader != null){
if (currentContextHeader.getWorkflowSchedulingContext() != null) {
if (currentContextHeader != null &&
currentContextHeader.getWorkflowSchedulingContext().getApplicationSchedulingContextArray() != null &&
currentContextHeader.getWorkflowSchedulingContext().getApplicationSchedulingContextArray().length > 0) {
try {
int cpuCount = currentContextHeader.getWorkflowSchedulingContext().getApplicationSchedulingContextArray()[0].getCpuCount();
if(cpuCount>0){
// appDepType.setCpuCount(cpuCount);
NumberOfProcessesType num = NumberOfProcessesType.Factory.newInstance();
String processers = Integer.toString(cpuCount);
num.setStringValue(processers);
JSDLUtils.getOrCreateSPMDApplication(value).setNumberOfProcesses(num);
}
} catch (NullPointerException e) {
new GFacProviderException("No Value sent in WorkflowContextHeader for Node Count, value in the Deployment Descriptor will be used",e);
}
try {
int nodeCount = currentContextHeader.getWorkflowSchedulingContext().getApplicationSchedulingContextArray()[0].getNodeCount();
if(nodeCount>0){
appDepType.setNodeCount(nodeCount);
}
} catch (NullPointerException e) {
new GFacProviderException("No Value sent in WorkflowContextHeader for Node Count, value in the Deployment Descriptor will be used",e);
}
try {
String queueName = currentContextHeader.getWorkflowSchedulingContext().getApplicationSchedulingContextArray()[0].getQueueName();
if (queueName != null) {
if(appDepType.getQueue() == null){
QueueType queueType = appDepType.addNewQueue();
queueType.setQueueName(queueName);
}else{
appDepType.getQueue().setQueueName(queueName);
}
}
} catch (NullPointerException e) {
new GFacProviderException("No Value sent in WorkflowContextHeader for Node Count, value in the Deployment Descriptor will be used",e);
}
try {
int maxwallTime = currentContextHeader.getWorkflowSchedulingContext().getApplicationSchedulingContextArray()[0].getMaxWallTime();
if(maxwallTime>0){
appDepType.setMaxWallTime(maxwallTime);
}
} catch (NullPointerException e) {
new GFacProviderException("No Value sent in WorkflowContextHeader for Node Count, value in the Deployment Descriptor will be used",e);
}
}
}
}
if (appDepType.getCpuCount() > 0) {
RangeValueType rangeType = new RangeValueType();
rangeType.setLowerBound(Double.NaN);
rangeType.setUpperBound(Double.NaN);
rangeType.setExact(appDepType.getCpuCount());
JSDLUtils.setTotalCPUCountRequirements(value, rangeType);
}
if (appDepType.getProcessorsPerNode() > 0) {
RangeValueType rangeType = new RangeValueType();
rangeType.setLowerBound(Double.NaN);
rangeType.setUpperBound(Double.NaN);
rangeType.setExact(appDepType.getProcessorsPerNode());
JSDLUtils.setIndividualCPUCountRequirements(value, rangeType);
}
if (appDepType.getNodeCount() > 0) {
RangeValueType rangeType = new RangeValueType();
rangeType.setLowerBound(Double.NaN);
rangeType.setUpperBound(Double.NaN);
rangeType.setExact(appDepType.getNodeCount());
JSDLUtils.setTotalResourceCountRequirements(value, rangeType);
}
if(appDepType.getMaxWallTime() > 0) {
RangeValueType cpuTime = new RangeValueType();
cpuTime.setLowerBound(Double.NaN);
cpuTime.setUpperBound(Double.NaN);
long wallTime = appDepType.getMaxWallTime() * 60;
cpuTime.setExact(wallTime);
JSDLUtils.setIndividualCPUTimeRequirements(value, cpuTime);
}
}