Job job = new Job(); job.setId(processInstanceId); job.setNamespace(namespaceCd); job.setJobName(jobName); job.setParameters(jobParameters); for (Map.Entry<String, Object> entry : mergedParameters.entrySet())
public Object copyTo(ObjectLocator locator, Object target, CopyStrategy2 strategy) { final Object draftCopy = ((target == null)?createNewInstance():target); if (draftCopy instanceof Job) { final Job copy = ((Job) draftCopy); if (idShouldBeCopiedAndSet == Boolean.TRUE) { String sourceId; sourceId = this.getId(); String copyId = ((String) strategy.copy(LocatorUtils.property(locator, "id", sourceId), sourceId, (this.id!= null))); copy.setId(copyId); } else { if (idShouldBeCopiedAndSet == Boolean.FALSE) { if (statusShouldBeCopiedAndSet == Boolean.TRUE) { JobStatusEnum sourceStatus; sourceStatus = this.getStatus(); JobStatusEnum copyStatus = ((JobStatusEnum) strategy.copy(LocatorUtils.property(locator, "status", sourceStatus), sourceStatus, (this.status!= null))); copy.setStatus(copyStatus); } else { if (statusShouldBeCopiedAndSet == Boolean.FALSE) { if (namespaceShouldBeCopiedAndSet == Boolean.TRUE) { String sourceNamespace; sourceNamespace = this.getNamespace(); String copyNamespace = ((String) strategy.copy(LocatorUtils.property(locator, "namespace", sourceNamespace), sourceNamespace, (this.namespace!= null))); copy.setNamespace(copyNamespace); } else { if (namespaceShouldBeCopiedAndSet == Boolean.FALSE) { if (jobNameShouldBeCopiedAndSet == Boolean.TRUE) {
theId = this.getId(); strategy.appendField(locator, this, "id", buffer, theId, (this.id!= null)); theStatus = this.getStatus(); strategy.appendField(locator, this, "status", buffer, theStatus, (this.status!= null)); theNamespace = this.getNamespace(); strategy.appendField(locator, this, "namespace", buffer, theNamespace, (this.namespace!= null)); theJobName = this.getJobName(); strategy.appendField(locator, this, "jobName", buffer, theJobName, (this.jobName!= null)); theStartTime = this.getStartTime(); strategy.appendField(locator, this, "startTime", buffer, theStartTime, (this.startTime!= null)); theEndTime = this.getEndTime(); strategy.appendField(locator, this, "endTime", buffer, theEndTime, (this.endTime!= null)); theCurrentWorkflowStep = this.getCurrentWorkflowStep(); strategy.appendField(locator, this, "currentWorkflowStep", buffer, theCurrentWorkflowStep, (this.currentWorkflowStep!= null)); theCompletedWorkflowSteps = ((this.completedWorkflowSteps!= null)?this.getCompletedWorkflowSteps():null); strategy.appendField(locator, this, "completedWorkflowSteps", buffer, theCompletedWorkflowSteps, (this.completedWorkflowSteps!= null)); theParameters = ((this.parameters!= null)?this.getParameters():null); strategy.appendField(locator, this, "parameters", buffer, theParameters, (this.parameters!= null)); theActivitiJobXml = this.getActivitiJobXml(); strategy.appendField(locator, this, "activitiJobXml", buffer, theActivitiJobXml, (this.activitiJobXml!= null));
Job jobGet = jobService.getJob(job.getId(), true); assertEquals(JobStatusEnum.RUNNING, jobGet.getStatus()); assertNotNull(jobGet.getActivitiJobXml()); assertEquals(activitiXml, jobGet.getActivitiJobXml()); assertTrue(jobGet.getCompletedWorkflowSteps().size() > 0); assertEquals("usertask1", jobGet.getCurrentWorkflowStep().getId()); jobGet = jobService.getJob(job.getId(), false); assertEquals(JobStatusEnum.RUNNING, jobGet.getStatus()); assertNull(jobGet.getActivitiJobXml()); assertTrue(CollectionUtils.isEmpty(jobGet.getCompletedWorkflowSteps())); assertEquals("usertask1", jobGet.getCurrentWorkflowStep().getId()); List<Task> tasks = activitiTaskService.createTaskQuery().processInstanceId(job.getId()).list(); jobGet = jobService.getJob(job.getId(), true); assertEquals(JobStatusEnum.COMPLETED, jobGet.getStatus()); assertNotNull(jobGet.getStartTime()); assertNotNull(jobGet.getEndTime()); assertNotNull(jobGet.getActivitiJobXml()); assertEquals(activitiXml, jobGet.getActivitiJobXml()); assertTrue(jobGet.getCompletedWorkflowSteps().size() > 0); assertNull(jobGet.getCurrentWorkflowStep()); jobGet = jobService.getJob(job.getId(), false); assertEquals(JobStatusEnum.COMPLETED, jobGet.getStatus()); assertNotNull(jobGet.getStartTime()); assertNotNull(jobGet.getEndTime()); assertNull(jobGet.getActivitiJobXml());
Job job = new Job(); job.setId(jobIdLocal); job.setStatus(processInstance.isSuspended() ? JobStatusEnum.SUSPENDED : JobStatusEnum.RUNNING); workflowErrors.add(workflowError); job.setWorkflowErrors(workflowErrors); job.setCurrentWorkflowStep(currentStep); job.setStatus(JobStatusEnum.COMPLETED); job.setDeleteReason(historicProcessInstance.getDeleteReason()); job.setStartTime(HerdDateUtils.getXMLGregorianCalendarValue(historicProcessInstance.getStartTime())); job.setEndTime(HerdDateUtils.getXMLGregorianCalendarValue(historicProcessInstance.getEndTime()));
@Test public void testGetJobIntermediateTimer() throws Exception { jobDefinitionServiceTestHelper.createJobDefinition(ACTIVITI_XML_HERD_INTERMEDIATE_TIMER_WITH_CLASSPATH); Job job = jobService.createAndStartJob(jobServiceTestHelper.createJobCreateRequest(TEST_ACTIVITI_NAMESPACE_CD, TEST_ACTIVITI_JOB_NAME)); String activitiXml = IOUtils.toString(resourceLoader.getResource(ACTIVITI_XML_HERD_INTERMEDIATE_TIMER_WITH_CLASSPATH).getInputStream()); // Job should be waiting at User task. // Get job status Job jobGet = jobService.getJob(job.getId(), true); assertEquals(JobStatusEnum.RUNNING, jobGet.getStatus()); assertNotNull(jobGet.getActivitiJobXml()); assertEquals(activitiXml, jobGet.getActivitiJobXml()); assertTrue(jobGet.getCompletedWorkflowSteps().size() > 0); // Current workflow step will be null assertNull(jobGet.getCurrentWorkflowStep()); org.activiti.engine.runtime.Job timer = activitiManagementService.createJobQuery().processInstanceId(job.getId()).timers().singleResult(); if (timer != null) { activitiManagementService.executeJob(timer.getId()); } // Get the job status again. job should have completed now. jobGet = jobService.getJob(job.getId(), false); assertEquals(JobStatusEnum.COMPLETED, jobGet.getStatus()); assertNull(jobGet.getCurrentWorkflowStep()); }
@Test public void testGetJob() throws Exception { // Create a job. Job job = new Job(); job.setId(JOB_ID); // Mock the external calls. when(jobService.getJob(JOB_ID, VERBOSE)).thenReturn(job); // Call the method under test. Job result = jobRestController.getJob(JOB_ID, VERBOSE); // Verify the external calls. verify(jobService).getJob(JOB_ID, VERBOSE); verifyNoMoreInteractionsHelper(); // Validate the results. assertEquals(job, result); }
/** * Asserts that the deleteJob call will move the job to completion, and add a record in the history instance with the specified delete reason. * * @throws Exception */ @Test public void testDeleteJob() throws Exception { // Start a job that will wait in a receive task jobDefinitionServiceTestHelper.createJobDefinition(ACTIVITI_XML_TEST_RECEIVE_TASK_WITH_CLASSPATH); Job job = jobService.createAndStartJob(jobServiceTestHelper.createJobCreateRequest(TEST_ACTIVITI_NAMESPACE_CD, TEST_ACTIVITI_JOB_NAME)); // Create a job delete request JobDeleteRequest jobDeleteRequest = new JobDeleteRequest(); jobDeleteRequest.setDeleteReason("test delete reason"); Job deleteJobResponse = jobService.deleteJob(job.getId(), jobDeleteRequest); // Assert delete job response assertEquals(job.getId(), deleteJobResponse.getId()); assertNull(deleteJobResponse.getNamespace()); assertNull(deleteJobResponse.getJobName()); assertEquals(JobStatusEnum.COMPLETED, deleteJobResponse.getStatus()); assertEquals(jobDeleteRequest.getDeleteReason(), deleteJobResponse.getDeleteReason()); // Assert historic process instance HistoricProcessInstance historicProcessInstance = activitiHistoryService.createHistoricProcessInstanceQuery().processInstanceId(job.getId()).singleResult(); assertNotNull(historicProcessInstance); assertEquals(jobDeleteRequest.getDeleteReason(), historicProcessInstance.getDeleteReason()); }
@Test public void testSignalJob() throws Exception { jobDefinitionServiceTestHelper.createJobDefinition(ACTIVITI_XML_TEST_RECEIVE_TASK_WITH_CLASSPATH); // Start the job. Job job = jobService.createAndStartJob(jobServiceTestHelper.createJobCreateRequest(TEST_ACTIVITI_NAMESPACE_CD, TEST_ACTIVITI_JOB_NAME)); // Job should be waiting at Receive task. Job jobGet = jobService.getJob(job.getId(), false); assertEquals(JobStatusEnum.RUNNING, jobGet.getStatus()); assertEquals("receivetask1", jobGet.getCurrentWorkflowStep().getId()); // Signal job to continue. List<Parameter> signalParameters = new ArrayList<>(); Parameter signalPameter1 = new Parameter("UT_SIGNAL_PARAM_1", "UT_SIGNAL_VALUE_1"); signalParameters.add(signalPameter1); JobSignalRequest jobSignalRequest = new JobSignalRequest(job.getId(), "receivetask1", signalParameters, null); Job signalJob = jobService.signalJob(jobSignalRequest); assertEquals(JobStatusEnum.RUNNING, signalJob.getStatus()); assertEquals("receivetask1", signalJob.getCurrentWorkflowStep().getId()); assertTrue(signalJob.getParameters().contains(signalPameter1)); // Job should have been completed. jobGet = jobService.getJob(job.getId(), true); assertEquals(JobStatusEnum.COMPLETED, jobGet.getStatus()); assertTrue(jobGet.getParameters().contains(signalPameter1)); }
@Test public void testCreateJobNoParams() throws Exception { // Create the namespace entity. namespaceDaoTestHelper.createNamespaceEntity(TEST_ACTIVITI_NAMESPACE_CD); // Create a job definition create request using hard coded test values. JobDefinitionCreateRequest jobDefinitionCreateRequest = jobDefinitionServiceTestHelper.createJobDefinitionCreateRequest(); jobDefinitionCreateRequest.setParameters(null); // Create the job definition. jobDefinitionService.createJobDefinition(jobDefinitionCreateRequest, false); // Create a job create request using hard coded test values. JobCreateRequest jobCreateRequest = jobServiceTestHelper.createJobCreateRequest(TEST_ACTIVITI_NAMESPACE_CD, TEST_ACTIVITI_JOB_NAME); jobCreateRequest.setParameters(null); // Create the job. Job resultJob = jobService.createAndStartJob(jobCreateRequest); //expected default parameter List<Parameter> expectedParameters = Arrays.asList(new Parameter(HERD_WORKFLOW_ENVIRONMENT, configurationHelper.getProperty(ConfigurationValue.HERD_ENVIRONMENT))); // Validate the results. assertNotNull(resultJob); assertNotNull(resultJob.getId()); assertTrue(!resultJob.getId().isEmpty()); assertEquals(TEST_ACTIVITI_NAMESPACE_CD, resultJob.getNamespace()); assertEquals(TEST_ACTIVITI_JOB_NAME, resultJob.getJobName()); assertTrue(resultJob.getParameters().size() == 1); assertTrue(expectedParameters.containsAll(resultJob.getParameters())); }
private Map<String, Object> createJob(String clusterName, String dryRun, String contentType, String emrClusterDefinitionOverride) throws Exception { List<Parameter> parameters = new ArrayList<>(); parameters.add(new Parameter("clusterName", clusterName)); parameters.add(new Parameter("dryRun", dryRun)); parameters.add(new Parameter("contentType", contentType)); parameters.add(new Parameter("emrClusterDefinitionOverride", emrClusterDefinitionOverride)); // Run a job with Activiti XML that will start cluster. Job job = jobServiceTestHelper.createJobForCreateCluster(ACTIVITI_XML_CREATE_CLUSTER_WITH_CLASSPATH, parameters); assertNotNull(job); HistoricProcessInstance hisInstance = activitiHistoryService.createHistoricProcessInstanceQuery().processInstanceId(job.getId()).includeProcessVariables().singleResult(); return hisInstance.getProcessVariables(); }
assertEquals(TEST_ACTIVITI_NAMESPACE_CD, job.getNamespace()); assertEquals(TEST_ACTIVITI_JOB_NAME, job.getJobName()); for (Parameter param : job.getParameters())
assertEquals(new Job(job.getId(), null, TEST_ACTIVITI_NAMESPACE_CD, TEST_ACTIVITI_JOB_NAME, null, null, null, null, Arrays .asList(new Parameter("notification_businessObjectDefinitionName", BDEF_NAME), new Parameter("notification_partitionValues", PARTITION_VALUE + "|" + StringUtils.join(SUBPARTITION_VALUES, "|")),
@Test public void testSignalJobNoParameters() throws Exception { jobDefinitionServiceTestHelper.createJobDefinition(ACTIVITI_XML_TEST_RECEIVE_TASK_WITH_CLASSPATH); // Start the job. Job job = jobService.createAndStartJob(jobServiceTestHelper.createJobCreateRequest(TEST_ACTIVITI_NAMESPACE_CD, TEST_ACTIVITI_JOB_NAME)); // Job should be waiting at Receive task. Job jobGet = jobService.getJob(job.getId(), false); assertEquals(JobStatusEnum.RUNNING, jobGet.getStatus()); assertEquals("receivetask1", jobGet.getCurrentWorkflowStep().getId()); // Signal job to continue. JobSignalRequest jobSignalRequest = new JobSignalRequest(job.getId(), "receivetask1", null, null); Job signalJob = jobService.signalJob(jobSignalRequest); assertEquals(JobStatusEnum.RUNNING, signalJob.getStatus()); assertEquals("receivetask1", signalJob.getCurrentWorkflowStep().getId()); // Job should have been completed. jobGet = jobService.getJob(job.getId(), true); assertEquals(JobStatusEnum.COMPLETED, jobGet.getStatus()); }
/** * Create an instance of {@link Job } * */ public Job createJob() { return new Job(); }
Job jobGetResponse = jobService.getJob(jobStartResponse.getId(), true); assertEquals(JobStatusEnum.COMPLETED, jobGetResponse.getStatus()); assertTrue(jobGetResponse.getParameters().contains(new Parameter("service_taskStatus", "SUCCESS"))); expectedJdbcExecutionResponse.setStatements(Arrays.asList(expectedJdbcStatement)); Parameter expectedJdbcExecutionResponseParameter = new Parameter("service_jsonResponse", jsonHelper.objectToJson(expectedJdbcExecutionResponse)); assertTrue(jobGetResponse.getParameters().contains(expectedJdbcExecutionResponseParameter));
@Override public Job signalJob(JobSignalRequest request) throws Exception { // Perform the validation. validateJobSignalRequest(request); Execution execution = activitiService.getExecutionByProcessInstanceIdAndActivitiId(request.getId(), request.getReceiveTaskId()); if (execution == null) { throw new ObjectNotFoundException( String.format("No job found for matching job id: \"%s\" and receive task id: \"%s\".", request.getId(), request.getReceiveTaskId())); } String processDefinitionKey = activitiService.getProcessInstanceById(execution.getProcessInstanceId()).getProcessDefinitionKey(); checkPermissions(processDefinitionKey, new NamespacePermissionEnum[] {NamespacePermissionEnum.EXECUTE}); // Retrieve the job before signaling. Job job = getJob(request.getId(), false, false); // Build the parameters map Map<String, Object> signalParameters = getParameters(request); // Signal the workflow. activitiService.signal(execution.getId(), signalParameters); // Build the parameters map merged with job and signal parameters. Map<String, Object> mergedParameters = new HashMap<>(); for (Parameter jobParam : job.getParameters()) { mergedParameters.put(jobParam.getName(), jobParam.getValue()); } mergedParameters.putAll(signalParameters); // Update the parameters in job populateWorkflowParameters(job, mergedParameters); return job; }
/** * Signals job with S3 properties set. Parameters should be populated from the properties. * * @throws Exception */ @Test public void testSignalJobWithS3Properties() throws Exception { jobDefinitionServiceTestHelper.createJobDefinition(ACTIVITI_XML_TEST_RECEIVE_TASK_WITH_CLASSPATH); Parameter parameter = new Parameter("testName", "testValue"); S3PropertiesLocation s3PropertiesLocation = getS3PropertiesLocation("s3BucketName", "s3ObjectKey", parameter); // Start the job. Job job = jobService.createAndStartJob(jobServiceTestHelper.createJobCreateRequest(TEST_ACTIVITI_NAMESPACE_CD, TEST_ACTIVITI_JOB_NAME)); JobSignalRequest jobSignalRequest = new JobSignalRequest(job.getId(), "receivetask1", null, null); jobSignalRequest.setS3PropertiesLocation(s3PropertiesLocation); Job signalJob = jobService.signalJob(jobSignalRequest); assertParameterEquals(parameter, signalJob.getParameters()); }
assertEquals(JobStatusEnum.RUNNING, getJobResponse.getStatus()); assertEquals(JobStatusEnum.SUSPENDED, getJobResponse.getStatus()); assertEquals(JobStatusEnum.COMPLETED, deleteJobResponse.getStatus()); assertEquals(ACTIVITI_JOB_DELETE_REASON, deleteJobResponse.getDeleteReason());
theId = this.getId(); strategy.appendField(locator, this, "id", buffer, theId, (this.id!= null)); theStatus = this.getStatus(); strategy.appendField(locator, this, "status", buffer, theStatus, (this.status!= null)); theNamespace = this.getNamespace(); strategy.appendField(locator, this, "namespace", buffer, theNamespace, (this.namespace!= null)); theJobName = this.getJobName(); strategy.appendField(locator, this, "jobName", buffer, theJobName, (this.jobName!= null)); theStartTime = this.getStartTime(); strategy.appendField(locator, this, "startTime", buffer, theStartTime, (this.startTime!= null)); theEndTime = this.getEndTime(); strategy.appendField(locator, this, "endTime", buffer, theEndTime, (this.endTime!= null)); theCurrentWorkflowStep = this.getCurrentWorkflowStep(); strategy.appendField(locator, this, "currentWorkflowStep", buffer, theCurrentWorkflowStep, (this.currentWorkflowStep!= null)); theCompletedWorkflowSteps = ((this.completedWorkflowSteps!= null)?this.getCompletedWorkflowSteps():null); strategy.appendField(locator, this, "completedWorkflowSteps", buffer, theCompletedWorkflowSteps, (this.completedWorkflowSteps!= null)); theParameters = ((this.parameters!= null)?this.getParameters():null); strategy.appendField(locator, this, "parameters", buffer, theParameters, (this.parameters!= null)); theActivitiJobXml = this.getActivitiJobXml(); strategy.appendField(locator, this, "activitiJobXml", buffer, theActivitiJobXml, (this.activitiJobXml!= null));