Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Copyright 2012 International Business Machines Corp.
   * 
   * See the NOTICE file distributed with this work for additional information
   * regarding copyright ownership. Licensed under the Apache License, 
   * Version 2.0 (the "License"); you may not use this file except in compliance
   * with the License. You may obtain a copy of the License at
   * 
   *   http://www.apache.org/licenses/LICENSE-2.0
  * 
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
 package com.ibm.jbatch.container.jobinstance;
 
 
 
 
 public class JobExecutionHelper {
 
 	private final static String CLASSNAME = JobExecutionHelper.class.getName();
 	private final static Logger logger = Logger.getLogger();
 
 	private static ServicesManager servicesManager = ServicesManagerImpl.getInstance();
 
 
 
 
 	private static ModelNavigator<JSLJobgetResolvedJobNavigator(String jobXmlProperties jobParametersboolean parallelExecution) {
 
 		JSLJob jobModel = ModelResolverFactory.createJobResolver().resolveModel(jobXml); 
 		PropertyResolver<JSLJobpropResolver = PropertyResolverFactory.createJobPropertyResolver(parallelExecution);
 		propResolver.substituteProperties(jobModeljobParameters);
 
 		return NavigatorFactory.createJobNavigator(jobModel);
 	}
 
 	private static ModelNavigator<JSLJobgetResolvedJobNavigator(JSLJob jobModelProperties jobParametersboolean parallelExecution) {
 
 		PropertyResolver<JSLJobpropResolver = PropertyResolverFactory.createJobPropertyResolver(parallelExecution);
 		propResolver.substituteProperties(jobModeljobParameters);
 
 		return NavigatorFactory.createJobNavigator(jobModel);
 	}
 
 	private static JobContextImpl getJobContext(ModelNavigator<JSLJobjobNavigator) {
 		JSLProperties jslProperties = new JSLProperties();
 		if(jobNavigator.getRootModelElement() != null) {
 			jslProperties = jobNavigator.getRootModelElement().getProperties();
 		}
 		return new JobContextImpl(jobNavigatorjslProperties); 
 	}
 
 	private static JobInstance getNewJobInstance(String nameString jobXml) {
 		return .createJobInstance(nameapptagjobXml);
 	}
 
 	private static JobInstance getNewSubJobInstance(String name) {
 	}
 
 	private static JobStatus createNewJobStatus(JobInstance jobInstance) {
 		long instanceId = jobInstance.getInstanceId();
		jobStatus.setJobInstance(jobInstance);
		return jobStatus;
	}
	private static void validateRestartableFalseJobsDoNotRestart(JSLJob jobModel)
		if (jobModel.getRestartable() != null && jobModel.getRestartable().equalsIgnoreCase("false")) {
			throw new JobRestartException("Job Restartable attribute is false, Job cannot be restarted.");
		}
	}
	public static RuntimeJobExecution startJob(String jobXMLProperties jobParametersthrows JobStartException {
		.entering("startJob"new Object[]{jobXMLjobParameters==null ? "<null>" : jobParameters});
		JSLJob jobModel = ModelResolverFactory.createJobResolver().resolveModel(jobXML); 
		ModelNavigator<JSLJobjobNavigator = getResolvedJobNavigator(jobModeljobParametersfalse);
		JobContextImpl jobContext = getJobContext(jobNavigator);
		JobInstance jobInstance = getNewJobInstance(jobNavigator.getRootModelElement().getId(), jobXML);
		RuntimeJobExecution executionHelper = 
				.createJobExecution(jobInstancejobParametersjobContext.getBatchStatus());
		executionHelper.prepareForExecution(jobContext);
		JobStatus jobStatus = createNewJobStatus(jobInstance);
		.exiting("startJob"executionHelper);
		return executionHelper;
	}
		.entering("startFlowInSplit"jobModel);
		ModelNavigator<JSLJobjobNavigator = getResolvedJobNavigator(jobModelnulltrue);
		JobContextImpl jobContext = getJobContext(jobNavigator);
		JobInstance jobInstance = getNewSubJobInstance(jobNavigator.getRootModelElement().getId());
		RuntimeFlowInSplitExecution executionHelper = 
		executionHelper.prepareForExecution(jobContext);
		JobStatus jobStatus = createNewJobStatus(jobInstance);
		.exiting("startFlowInSplit"executionHelper);
		return executionHelper;
	}
	public static RuntimeJobExecution startPartition(JSLJob jobModelProperties jobParametersthrows JobStartException{
		.entering("startPartition"new Object[]{jobModeljobParameters ==null ? "<null>" :jobParameters});
		ModelNavigator<JSLJobjobNavigator = getResolvedJobNavigator(jobModeljobParameterstrue);
		JobContextImpl jobContext = getJobContext(jobNavigator);
		JobInstance jobInstance = getNewSubJobInstance(jobNavigator.getRootModelElement().getId());
		RuntimeJobExecution executionHelper = 
				.createJobExecution(jobInstancejobParametersjobContext.getBatchStatus());
		executionHelper.prepareForExecution(jobContext);
		JobStatus jobStatus = createNewJobStatus(jobInstance);
		.exiting("startPartition"executionHelper);
		return executionHelper;
	}
		return restartExecution(executionIdnullnullfalsefalse);
	}
		if (jobStatus.getBatchStatus() == null) {
			String msg = "On restart, we didn't find an earlier batch status.";
			throw new IllegalStateException(msg);
		}
			String msg = "Already completed job instance = " + jobStatus.getJobInstanceId();
else if (jobStatus.getBatchStatus().equals(.)) {
			String msg = "Abandoned job instance = " + jobStatus.getJobInstanceId();
			throw new JobRestartException(msg);
	}
	private static void validateJobExecutionIsMostRecent(long jobInstanceIdlong executionIdthrows JobExecutionNotMostRecentException {
		long mostRecentExecutionId = .getMostRecentExecutionId(jobInstanceId);
		if ( mostRecentExecutionId != executionId ) {
			String message = "ExecutionId: " + executionId + " is not the most recent execution.";
			.warning(message);
		}
	}
	public static RuntimeJobExecution restartPartition(long execIdJSLJob gennedJobModelProperties partitionPropsthrows JobRestartException
		return restartExecution(execIdgennedJobModelpartitionPropstruefalse);	
	}
	public static RuntimeFlowInSplitExecution restartFlowInSplit(long execIdJSLJob gennedJobModelthrows JobRestartException
		return (RuntimeFlowInSplitExecution)restartExecution(execIdgennedJobModelnulltruetrue);	
	}
	public static RuntimeJobExecution restartJob(long executionIdProperties restartJobParametersthrows JobRestartException
		return restartExecution(executionIdnullrestartJobParametersfalsefalse);	
	}
	private static RuntimeJobExecution restartExecution(long executionIdJSLJob gennedJobModelProperties restartJobParametersboolean parallelExecutionboolean flowInSplitthrows JobRestartException
		JobStatus jobStatus = .getJobStatus(jobInstanceId);
			.fine("On restartJob with jobInstance Id = " + jobInstanceId + " , found JobStatus: " + jobStatus + 
					", batchStatus = " + jobStatus.getBatchStatus().name() ); 
		}
		validateJobExecutionIsMostRecent(jobInstanceIdexecutionId);
		JobInstanceImpl jobInstance = jobStatus.getJobInstance();
		ModelNavigator<JSLJobjobNavigator = null;
		// If we are in a parallel job that is genned use the regenned JSL.
		if (gennedJobModel == null) {
			jobNavigator = getResolvedJobNavigator(jobInstance.getJobXML(), restartJobParametersparallelExecution);
else {
			jobNavigator = getResolvedJobNavigator(gennedJobModelrestartJobParametersparallelExecution);
		}
		// JSLJob jobModel = ModelResolverFactory.createJobResolver().resolveModel(jobInstance.getJobXML());
		JobContextImpl jobContext = getJobContext(jobNavigator);
		RuntimeJobExecution executionHelper;
		if (flowInSplit) {
			executionHelper = .createFlowInSplitExecution(jobInstancejobContext.getBatchStatus());
else {
			executionHelper = .createJobExecution(jobInstancerestartJobParametersjobContext.getBatchStatus());
		}
		executionHelper.prepareForExecution(jobContextjobStatus.getRestartOn());
		return executionHelper;
	}    
	public static IJobExecution getPersistedJobOperatorJobExecution(long jobExecutionIdthrows NoSuchJobExecutionException {
	}
	public static JobInstance getJobInstance(long executionId){
		JobInstanceImpl jobInstance = jobStatus.getJobInstance();
		return jobInstance;
	}
New to GrepCode? Check out our FAQ X