}
}
public DuccWorkJob create(CommonConfiguration common, JobRequestProperties jobRequestProperties) {
String methodName = "create";
DuccWorkJob job = new DuccWorkJob();
checkSpec(job, jobRequestProperties);
// id, type
String ddCr = jobRequestProperties.getProperty(JobSpecificationProperties.key_driver_descriptor_CR);
if(ddCr == null) {
job.setDuccType(DuccType.Service);
job.setDuccId(duccIdFactory.next());
}
else {
job.setDuccType(DuccType.Job);
job.setDuccId(duccIdFactory.next());
}
// driver
DuccType duccType = job.getDuccType();
switch(duccType) {
case Job:
createDriver(common, jobRequestProperties, job);
setDebugPorts(common, jobRequestProperties, job);
break;
case Service:
break;
}
// Service Deployment Type
if(jobRequestProperties.containsKey(ServiceRequestProperties.key_service_type_custom)) {
job.setServiceDeploymentType(ServiceDeploymentType.custom);
}
else if(jobRequestProperties.containsKey(ServiceRequestProperties.key_service_type_other)) {
job.setServiceDeploymentType(ServiceDeploymentType.other);
}
else if(jobRequestProperties.containsKey(ServiceRequestProperties.key_service_type_uima)) {
job.setServiceDeploymentType(ServiceDeploymentType.uima);
}
else {
job.setServiceDeploymentType(ServiceDeploymentType.unspecified);
}
// sweep out leftover logging trash
logSweeper(jobRequestProperties.getProperty(JobRequestProperties.key_log_directory), job.getDuccId());
// log
jobRequestProperties.specification(logger);
// classpath
String java_classpath = getDuccClasspath(1); // for job processes & services
String processClasspath = jobRequestProperties.getProperty(JobSpecificationProperties.key_classpath);
logger.debug(methodName, job.getDuccId(), "process CP (spec):"+processClasspath);
logger.debug(methodName, job.getDuccId(), "java CP:"+java_classpath);
if(processClasspath != null) {
if(isClasspathOrderUserBeforeDucc(jobRequestProperties.getProperty(JobSpecificationProperties.key_classpath_order),job.getDuccId())) {
logger.info(methodName, job.getDuccId(), "process:OrderUserBeforeDucc");
processClasspath=processClasspath+File.pathSeparator+java_classpath;
}
else {
logger.info(methodName, job.getDuccId(), "process:OrderDuccBeforeUser");
processClasspath=java_classpath+File.pathSeparator+processClasspath;
}
}
else {
logger.info(methodName, job.getDuccId(), "process:OrderDefault");
processClasspath=java_classpath;
}
logger.debug(methodName, job.getDuccId(), "process CP (combined):"+processClasspath);
// java command
String javaCmd = jobRequestProperties.getProperty(JobSpecificationProperties.key_jvm);
if(javaCmd == null) {
// Agent will set javaCmd for Driver and Processes
}
// standard info
DuccStandardInfo standardInfo = new DuccStandardInfo();
job.setStandardInfo(standardInfo);
standardInfo.setUser(jobRequestProperties.getProperty(JobSpecificationProperties.key_user));
standardInfo.setSubmitter(jobRequestProperties.getProperty(JobSpecificationProperties.key_submitter_pid_at_host));
standardInfo.setDateOfSubmission(TimeStamp.getCurrentMillis());
standardInfo.setDateOfCompletion(null);
standardInfo.setDescription(jobRequestProperties.getProperty(JobSpecificationProperties.key_description));
standardInfo.setLogDirectory(jobRequestProperties.getProperty(JobSpecificationProperties.key_log_directory));
standardInfo.setWorkingDirectory(jobRequestProperties.getProperty(JobSpecificationProperties.key_working_directory));
String notifications = jobRequestProperties.getProperty(JobSpecificationProperties.key_notifications);
if(notifications == null) {
standardInfo.setNotifications(null);
}
else {
String[] notificationsArray = notifications.split(" ,");
for(String notification : notificationsArray) {
notification.trim();
}
standardInfo.setNotifications(notificationsArray);
}
// scheduling info
DuccSchedulingInfo schedulingInfo = new DuccSchedulingInfo();
String ducc_rm_share_quantum = DuccPropertiesResolver.getInstance().getFileProperty(DuccPropertiesResolver.ducc_rm_share_quantum);
if(ducc_rm_share_quantum != null) {
ducc_rm_share_quantum = ducc_rm_share_quantum.trim();
if(ducc_rm_share_quantum.length() > 0) {
schedulingInfo.setShareMemorySize(ducc_rm_share_quantum);
}
}
job.setSchedulingInfo(schedulingInfo);
schedulingInfo.setSchedulingClass(jobRequestProperties.getProperty(JobSpecificationProperties.key_scheduling_class));
schedulingInfo.setSchedulingPriority(jobRequestProperties.getProperty(JobSpecificationProperties.key_scheduling_priority));
schedulingInfo.setSharesMax(jobRequestProperties.getProperty(JobSpecificationProperties.key_process_deployments_max));
schedulingInfo.setSharesMin(jobRequestProperties.getProperty(JobSpecificationProperties.key_process_deployments_min));
schedulingInfo.setThreadsPerShare(jobRequestProperties.getProperty(JobSpecificationProperties.key_process_thread_count));
schedulingInfo.setShareMemorySize(jobRequestProperties.getProperty(JobSpecificationProperties.key_process_memory_size));
schedulingInfo.setShareMemoryUnits(MemoryUnits.GB);
if (job.getDuccType() == DuccType.Job){
checkSchedulingLimits(job, schedulingInfo);
}
// process_initialization_time_max
String pi_time = jobRequestProperties.getProperty(JobRequestProperties.key_process_initialization_time_max);
if(pi_time == null) {
pi_time = DuccPropertiesResolver.getInstance().getFileProperty(DuccPropertiesResolver.ducc_agent_launcher_process_init_timeout);
}
try {
long value = Long.parseLong(pi_time)*60*1000;
standardInfo.setProcessInitializationTimeMax(value);
}
catch(Exception e) {
logger.error(methodName, job.getDuccId(), e);
}
// jp
ServiceDeploymentType serviceDeploymentType = job.getServiceDeploymentType();
if(isJpUima(duccType, serviceDeploymentType)) {
String process_DD = jobRequestProperties.getProperty(JobSpecificationProperties.key_process_DD);
if(process_DD != null) {
// user DD
IDuccUimaDeploymentDescriptor uimaDeploymentDescriptor = new DuccUimaDeploymentDescriptor(process_DD);
job.setUimaDeployableConfiguration(uimaDeploymentDescriptor);
dump(job, uimaDeploymentDescriptor);
}
else {
// UIMA aggregate
String name = common.jdQueuePrefix+job.getDuccId().toString();
String description = job.getStandardInfo().getDescription();
int threadCount = Integer.parseInt(job.getSchedulingInfo().getThreadsPerShare());
String brokerURL = job.getjobBroker();;
String endpoint = job.getjobQueue();
ArrayList<IDuccUimaAggregateComponent> components = new ArrayList<IDuccUimaAggregateComponent>();
String CMDescriptor = jobRequestProperties.getProperty(JobSpecificationProperties.key_process_descriptor_CM);
if(CMDescriptor != null) {
ArrayList<String> CMOverrides = toArrayList(jobRequestProperties.getProperty(JobSpecificationProperties.key_process_descriptor_CM_overrides));
IDuccUimaAggregateComponent componentCM = new DuccUimaAggregateComponent(CMDescriptor, CMOverrides);
components.add(componentCM);
}
String AEDescriptor = jobRequestProperties.getProperty(JobSpecificationProperties.key_process_descriptor_AE);
if(AEDescriptor != null) {
ArrayList<String> AEOverrides = toArrayList(jobRequestProperties.getProperty(JobSpecificationProperties.key_process_descriptor_AE_overrides));
IDuccUimaAggregateComponent componentAE = new DuccUimaAggregateComponent(AEDescriptor, AEOverrides);
components.add(componentAE);
}
String CCDescriptor = jobRequestProperties.getProperty(JobSpecificationProperties.key_process_descriptor_CC);
if(CCDescriptor != null) {
ArrayList<String> CCOverrides = toArrayList(jobRequestProperties.getProperty(JobSpecificationProperties.key_process_descriptor_CC_overrides));
IDuccUimaAggregateComponent componentCC = new DuccUimaAggregateComponent(CCDescriptor, CCOverrides);
components.add(componentCC);
}
IDuccUimaAggregate uimaAggregate = new DuccUimaAggregate(name,description,threadCount,brokerURL,endpoint,components);
job.setUimaDeployableConfiguration(uimaAggregate);
dump(job, uimaAggregate);
}
// pipelines
JavaCommandLine pipelineCommandLine = new JavaCommandLine(javaCmd);
pipelineCommandLine.setClassName("main:provided-by-Process-Manager");
pipelineCommandLine.setClasspath(processClasspath);
String process_jvm_args = jobRequestProperties.getProperty(JobSpecificationProperties.key_process_jvm_args);
ArrayList<String> pTokens = QuotedOptions.tokenizeList(process_jvm_args, true);
for(String token : pTokens) {
pipelineCommandLine.addOption(token);
}
// Add any site-provided JVM args
String siteJvmArgs = DuccPropertiesResolver.get(DuccPropertiesResolver.ducc_process_jvm_args);
pTokens = QuotedOptions.tokenizeList(siteJvmArgs, true); // a null arg is acceptable
for(String token : pTokens) {
pipelineCommandLine.addOption(token);
}
String processEnvironmentVariables = jobRequestProperties.getProperty(JobSpecificationProperties.key_environment);
int envCountProcess = addEnvironment(job, "process", pipelineCommandLine, processEnvironmentVariables);
logger.info(methodName, job.getDuccId(), "process env vars: "+envCountProcess);
logger.debug(methodName, job.getDuccId(), "pipeline: "+pipelineCommandLine.getCommand());
pipelineCommandLine.setLogDirectory(jobRequestProperties.getProperty(JobSpecificationProperties.key_log_directory));
job.setCommandLine(pipelineCommandLine);
}
else {
// ducclet (sometimes known as arbitrary process)
String process_executable = jobRequestProperties.getProperty(JobSpecificationProperties.key_process_executable);
NonJavaCommandLine executableProcessCommandLine = new NonJavaCommandLine(process_executable);
String processEnvironmentVariables = jobRequestProperties.getProperty(JobSpecificationProperties.key_environment);
int envCountProcess = addEnvironment(job, "process", executableProcessCommandLine, processEnvironmentVariables);
logger.info(methodName, job.getDuccId(), "process env vars: "+envCountProcess);
logger.debug(methodName, job.getDuccId(), "ducclet: "+executableProcessCommandLine.getCommandLine());
job.setCommandLine(executableProcessCommandLine);
// Tokenize arguments string and strip any quotes, then add to command line.
// Note: placeholders replaced by CLI so can avoid the add method.
List<String> process_executable_arguments = QuotedOptions.tokenizeList(
jobRequestProperties.getProperty(JobSpecificationProperties.key_process_executable_args), true);
executableProcessCommandLine.getArguments().addAll(process_executable_arguments);
}
// process_initialization_failures_cap
String failures_cap = jobRequestProperties.getProperty(JobSpecificationProperties.key_process_initialization_failures_cap);
try {
long process_failures_cap = Long.parseLong(failures_cap);
if(process_failures_cap > 0) {
job.setProcessInitFailureCap(process_failures_cap);
}
else {
logger.warn(methodName, job.getDuccId(), "invalid "+JobSpecificationProperties.key_process_initialization_failures_cap+": "+failures_cap);
}
}
catch(Exception e) {
logger.warn(methodName, job.getDuccId(), "invalid "+JobSpecificationProperties.key_process_initialization_failures_cap+": "+failures_cap);
}
// process_failures_limit
String failures_limit = jobRequestProperties.getProperty(JobSpecificationProperties.key_process_failures_limit);
try {
long process_failures_limit = Long.parseLong(failures_limit);
if(process_failures_limit > 0) {
job.setProcessFailureLimit(process_failures_limit);
}
else {
logger.warn(methodName, job.getDuccId(), "invalid "+JobSpecificationProperties.key_process_failures_limit+": "+failures_limit);
}
}
catch(Exception e) {
logger.warn(methodName, job.getDuccId(), "invalid "+JobSpecificationProperties.key_process_failures_limit+": "+failures_limit);
}
//
// Set the service dependency, if there is one.
//
String depstr = jobRequestProperties.getProperty(JobSpecificationProperties.key_service_dependency);
if ( depstr == null ) {
logger.debug(methodName, job.getDuccId(), "No service dependencies");
} else {
logger.debug(methodName, job.getDuccId(), "Adding service dependency", depstr);
String[] deps = depstr.split("\\s+");
job.setServiceDependencies(deps);
}
// Service Endpoint
String ep = jobRequestProperties.getProperty(ServiceRequestProperties.key_service_request_endpoint);
if ( ep == null ) {
logger.debug(methodName, job.getDuccId(), "No service endpoint");
} else {
logger.debug(methodName, job.getDuccId(), "Adding service endpoint", ep);
job.setServiceEndpoint(ep);
}
// Cancel On Interrupt
if(jobRequestProperties.containsKey(JobSpecificationProperties.key_cancel_on_interrupt)) {
job.setCancelOnInterrupt();
}
else if(jobRequestProperties.containsKey(ReservationSpecificationProperties.key_cancel_managed_reservation_on_interrupt)) {
job.setCancelOnInterrupt();
}
//TODO be sure to clean-up fpath upon job completion!
return job;
}