use of org.finra.herd.model.api.xml.JobUpdateRequest in project herd by FINRAOS.
the class JobRestControllerTest method testUpdateJob.
@Test
public void testUpdateJob() throws Exception {
// Create a job update request.
JobUpdateRequest jobUpdateRequest = new JobUpdateRequest(JobActionEnum.RESUME);
// Create a job.
Job job = new Job();
job.setId(JOB_ID);
// Mock the external calls.
when(jobService.updateJob(JOB_ID, jobUpdateRequest)).thenReturn(job);
// Call the method under test.
Job result = jobRestController.updateJob(JOB_ID, jobUpdateRequest);
// Verify the external calls.
verify(jobService).updateJob(JOB_ID, jobUpdateRequest);
verifyNoMoreInteractionsHelper();
// Validate the results.
assertEquals(job, result);
}
use of org.finra.herd.model.api.xml.JobUpdateRequest in project herd by FINRAOS.
the class JobServiceTest method testGetJobsValidateJobStatusFilter.
@Test
public void testGetJobsValidateJobStatusFilter() throws Exception {
// Create and persist a job definition.
jobDefinitionServiceTestHelper.createJobDefinition(ACTIVITI_XML_TEST_USER_TASK_WITH_CLASSPATH);
// Create and start two Activiti jobs.
List<Job> jobs = Arrays.asList(jobService.createAndStartJob(jobServiceTestHelper.createJobCreateRequest(TEST_ACTIVITI_NAMESPACE_CD, TEST_ACTIVITI_JOB_NAME)), jobService.createAndStartJob(jobServiceTestHelper.createJobCreateRequest(TEST_ACTIVITI_NAMESPACE_CD, TEST_ACTIVITI_JOB_NAME)));
// Jobs should be waiting at relative User tasks.
// Allow READ and EXECUTE access for the current user to the job definition namespace.
jobServiceTestHelper.setCurrentUserNamespaceAuthorizations(TEST_ACTIVITI_NAMESPACE_CD, Arrays.asList(NamespacePermissionEnum.READ, NamespacePermissionEnum.EXECUTE));
JobSummaries resultJobSummaries;
Map<String, JobStatusEnum> expectedJobStatuses;
List<Task> tasks;
// Get all jobs for the relative job definition and expected job status.
resultJobSummaries = jobService.getJobs(TEST_ACTIVITI_NAMESPACE_CD, TEST_ACTIVITI_JOB_NAME, JobStatusEnum.RUNNING, NO_START_TIME, NO_END_TIME);
// Validate the result job summaries.
expectedJobStatuses = new HashMap<String, JobStatusEnum>() {
{
put(jobs.get(0).getId(), JobStatusEnum.RUNNING);
put(jobs.get(1).getId(), JobStatusEnum.RUNNING);
}
};
validateJobSummaries(expectedJobStatuses, resultJobSummaries);
// Suspend the first job.
jobService.updateJob(jobs.get(0).getId(), new JobUpdateRequest(JobActionEnum.SUSPEND));
// The second job is still RUNNING.
// Get RUNNING jobs.
resultJobSummaries = jobService.getJobs(TEST_ACTIVITI_NAMESPACE_CD, TEST_ACTIVITI_JOB_NAME, JobStatusEnum.RUNNING, NO_START_TIME, NO_END_TIME);
// Validate the result job summaries.
expectedJobStatuses = new HashMap<String, JobStatusEnum>() {
{
put(jobs.get(1).getId(), JobStatusEnum.RUNNING);
}
};
validateJobSummaries(expectedJobStatuses, resultJobSummaries);
// Get SUSPENDED jobs.
resultJobSummaries = jobService.getJobs(TEST_ACTIVITI_NAMESPACE_CD, TEST_ACTIVITI_JOB_NAME, JobStatusEnum.SUSPENDED, NO_START_TIME, NO_END_TIME);
// Validate the result job summaries.
expectedJobStatuses = new HashMap<String, JobStatusEnum>() {
{
put(jobs.get(0).getId(), JobStatusEnum.SUSPENDED);
}
};
validateJobSummaries(expectedJobStatuses, resultJobSummaries);
// Resume the first job.
jobService.updateJob(jobs.get(0).getId(), new JobUpdateRequest(JobActionEnum.RESUME));
// Complete the first job.
tasks = activitiTaskService.createTaskQuery().processInstanceId(jobs.get(0).getId()).list();
activitiTaskService.complete(tasks.get(0).getId());
// Get COMPLETED jobs.
resultJobSummaries = jobService.getJobs(TEST_ACTIVITI_NAMESPACE_CD, TEST_ACTIVITI_JOB_NAME, JobStatusEnum.COMPLETED, NO_START_TIME, NO_END_TIME);
// Validate the result job summaries.
expectedJobStatuses = new HashMap<String, JobStatusEnum>() {
{
put(jobs.get(0).getId(), JobStatusEnum.COMPLETED);
}
};
validateJobSummaries(expectedJobStatuses, resultJobSummaries);
// Complete the second job.
tasks = activitiTaskService.createTaskQuery().processInstanceId(jobs.get(1).getId()).list();
activitiTaskService.complete(tasks.get(0).getId());
// All jobs now should have been completed.
// Try to get RUNNING jobs.
resultJobSummaries = jobService.getJobs(TEST_ACTIVITI_NAMESPACE_CD, TEST_ACTIVITI_JOB_NAME, JobStatusEnum.RUNNING, NO_START_TIME, NO_END_TIME);
assertEquals(0, resultJobSummaries.getJobSummaries().size());
// Try to get SUSPENDED jobs.
resultJobSummaries = jobService.getJobs(TEST_ACTIVITI_NAMESPACE_CD, TEST_ACTIVITI_JOB_NAME, JobStatusEnum.SUSPENDED, NO_START_TIME, NO_END_TIME);
assertEquals(0, resultJobSummaries.getJobSummaries().size());
// Get COMPLETED jobs.
resultJobSummaries = jobService.getJobs(TEST_ACTIVITI_NAMESPACE_CD, TEST_ACTIVITI_JOB_NAME, JobStatusEnum.COMPLETED, NO_START_TIME, NO_END_TIME);
// Validate the result job summaries.
expectedJobStatuses = new HashMap<String, JobStatusEnum>() {
{
put(jobs.get(0).getId(), JobStatusEnum.COMPLETED);
put(jobs.get(1).getId(), JobStatusEnum.COMPLETED);
}
};
validateJobSummaries(expectedJobStatuses, resultJobSummaries);
}
use of org.finra.herd.model.api.xml.JobUpdateRequest in project herd by FINRAOS.
the class JobServiceTest method testDeleteJobSuspendedJobWithMultipleSubProcesses.
@Test
@Transactional(propagation = Propagation.NOT_SUPPORTED)
public void testDeleteJobSuspendedJobWithMultipleSubProcesses() throws Exception {
// Create and persist a test job definition.
executeJdbcTestHelper.prepareHerdDatabaseForExecuteJdbcWithReceiveTaskTest(TEST_ACTIVITI_NAMESPACE_CD, TEST_ACTIVITI_JOB_NAME, ACTIVITI_XML_TEST_MULTIPLE_SUB_PROCESSES);
try {
// Get the job definition entity and ensure it exists.
JobDefinitionEntity jobDefinitionEntity = jobDefinitionDao.getJobDefinitionByAltKey(TEST_ACTIVITI_NAMESPACE_CD, TEST_ACTIVITI_JOB_NAME);
assertNotNull(jobDefinitionEntity);
// Get the process definition id.
String processDefinitionId = jobDefinitionEntity.getActivitiId();
// Build the parameters map.
Map<String, Object> parameters = new HashMap<>();
parameters.put("counter", 0);
// Start the job.
ProcessInstance processInstance = activitiService.startProcessInstanceByProcessDefinitionId(processDefinitionId, parameters);
assertNotNull(processInstance);
// Get the process instance id for this job.
String processInstanceId = processInstance.getProcessInstanceId();
// Wait for all processes to become active - we expect to have the main process along with 800 sub-processes.
waitUntilActiveProcessesThreshold(processDefinitionId, 801);
// Get the job and validate that it is RUNNING.
Job getJobResponse = jobService.getJob(processInstanceId, true);
assertNotNull(getJobResponse);
assertEquals(JobStatusEnum.RUNNING, getJobResponse.getStatus());
// Suspend the job.
jobService.updateJob(processInstanceId, new JobUpdateRequest(JobActionEnum.SUSPEND));
// Get the job again and validate that it is now SUSPENDED.
getJobResponse = jobService.getJob(processInstanceId, true);
assertNotNull(getJobResponse);
assertEquals(JobStatusEnum.SUSPENDED, getJobResponse.getStatus());
// Delete the job in suspended state and validate the response.
Job deleteJobResponse = jobService.deleteJob(processInstanceId, new JobDeleteRequest(ACTIVITI_JOB_DELETE_REASON));
assertEquals(JobStatusEnum.COMPLETED, deleteJobResponse.getStatus());
assertEquals(ACTIVITI_JOB_DELETE_REASON, deleteJobResponse.getDeleteReason());
// Validate the historic process instance.
HistoricProcessInstance historicProcessInstance = activitiHistoryService.createHistoricProcessInstanceQuery().processInstanceId(processInstanceId).singleResult();
assertNotNull(historicProcessInstance);
assertEquals(ACTIVITI_JOB_DELETE_REASON, historicProcessInstance.getDeleteReason());
} finally {
// Clean up the Herd database.
executeJdbcTestHelper.cleanUpHerdDatabaseAfterExecuteJdbcWithReceiveTaskTest(TEST_ACTIVITI_NAMESPACE_CD, TEST_ACTIVITI_JOB_NAME);
// Clean up the Activiti.
deleteActivitiDeployments();
}
}
use of org.finra.herd.model.api.xml.JobUpdateRequest in project herd by FINRAOS.
the class JobServiceTest method testUpdateJobInvalidParameters.
@Test
public void testUpdateJobInvalidParameters() throws Exception {
// Create a test job definition.
jobDefinitionServiceTestHelper.createJobDefinition(ACTIVITI_XML_TEST_USER_TASK_WITH_CLASSPATH);
// Create and start the job.
Job job = jobService.createAndStartJob(jobServiceTestHelper.createJobCreateRequest(TEST_ACTIVITI_NAMESPACE_CD, TEST_ACTIVITI_JOB_NAME));
// Job should be waiting at User task.
// Get the running job with non verbose.
Job jobGet = jobService.getJob(job.getId(), false);
assertEquals(JobStatusEnum.RUNNING, jobGet.getStatus());
assertNull(jobGet.getActivitiJobXml());
assertTrue(CollectionUtils.isEmpty(jobGet.getCompletedWorkflowSteps()));
assertEquals("usertask1", jobGet.getCurrentWorkflowStep().getId());
// Try to update a job using invalid job id.
try {
jobService.updateJob("I_DO_NOT_EXIST", new JobUpdateRequest(JobActionEnum.SUSPEND));
fail();
} catch (ObjectNotFoundException e) {
assertEquals("Job with ID \"I_DO_NOT_EXIST\" does not exist or is already completed.", e.getMessage());
}
// Try to resume an already running job.
try {
jobService.updateJob(job.getId(), new JobUpdateRequest(JobActionEnum.RESUME));
fail();
} catch (IllegalArgumentException e) {
assertEquals(String.format("Job with ID \"%s\" is already in an active state.", job.getId()), e.getMessage());
}
// Suspend the job.
jobService.updateJob(job.getId(), new JobUpdateRequest(JobActionEnum.SUSPEND));
// Validate that the job is suspended.
jobGet = jobService.getJob(job.getId(), false);
assertEquals(JobStatusEnum.SUSPENDED, jobGet.getStatus());
assertNull(jobGet.getActivitiJobXml());
assertTrue(CollectionUtils.isEmpty(jobGet.getCompletedWorkflowSteps()));
assertEquals("usertask1", jobGet.getCurrentWorkflowStep().getId());
// Try to suspend an already suspended job.
try {
jobService.updateJob(job.getId(), new JobUpdateRequest(JobActionEnum.SUSPEND));
fail();
} catch (IllegalArgumentException e) {
assertEquals(String.format("Job with ID \"%s\" is already in a suspended state.", job.getId()), e.getMessage());
}
// Resume the job.
jobService.updateJob(job.getId(), new JobUpdateRequest(JobActionEnum.RESUME));
// Validate that the job is running.
jobGet = jobService.getJob(job.getId(), false);
assertEquals(JobStatusEnum.RUNNING, jobGet.getStatus());
assertNull(jobGet.getActivitiJobXml());
assertTrue(CollectionUtils.isEmpty(jobGet.getCompletedWorkflowSteps()));
assertEquals("usertask1", jobGet.getCurrentWorkflowStep().getId());
// Query the pending task and complete it
List<Task> tasks = activitiTaskService.createTaskQuery().processInstanceId(job.getId()).list();
activitiTaskService.complete(tasks.get(0).getId());
// Job should have been completed.
// Get the completed job with non verbose.
jobGet = jobService.getJob(job.getId(), false);
assertEquals(JobStatusEnum.COMPLETED, jobGet.getStatus());
assertNotNull(jobGet.getStartTime());
assertNotNull(jobGet.getEndTime());
assertNull(jobGet.getActivitiJobXml());
assertTrue(CollectionUtils.isEmpty(jobGet.getCompletedWorkflowSteps()));
assertNull(jobGet.getCurrentWorkflowStep());
// Try to update a completed job.
try {
jobService.updateJob(job.getId(), new JobUpdateRequest(JobActionEnum.SUSPEND));
fail();
} catch (ObjectNotFoundException e) {
assertEquals(String.format("Job with ID \"%s\" does not exist or is already completed.", job.getId()), e.getMessage());
}
}
use of org.finra.herd.model.api.xml.JobUpdateRequest in project herd by FINRAOS.
the class JobServiceTest method testUpdateJob.
@Test
public void testUpdateJob() throws Exception {
// Create a test job definition.
jobDefinitionServiceTestHelper.createJobDefinition(ACTIVITI_XML_TEST_USER_TASK_WITH_CLASSPATH);
// Create and start the job.
Job job = jobService.createAndStartJob(jobServiceTestHelper.createJobCreateRequest(TEST_ACTIVITI_NAMESPACE_CD, TEST_ACTIVITI_JOB_NAME));
// Job should be waiting at User task.
// Get the running job with non verbose.
Job jobGet = jobService.getJob(job.getId(), false);
assertEquals(JobStatusEnum.RUNNING, jobGet.getStatus());
assertNull(jobGet.getActivitiJobXml());
assertTrue(CollectionUtils.isEmpty(jobGet.getCompletedWorkflowSteps()));
assertEquals("usertask1", jobGet.getCurrentWorkflowStep().getId());
// Suspend the job.
jobService.updateJob(job.getId(), new JobUpdateRequest(JobActionEnum.SUSPEND));
// Validate that the job is suspended.
jobGet = jobService.getJob(job.getId(), false);
assertEquals(JobStatusEnum.SUSPENDED, jobGet.getStatus());
assertNull(jobGet.getActivitiJobXml());
assertTrue(CollectionUtils.isEmpty(jobGet.getCompletedWorkflowSteps()));
assertEquals("usertask1", jobGet.getCurrentWorkflowStep().getId());
// Resume the job.
jobService.updateJob(job.getId(), new JobUpdateRequest(JobActionEnum.RESUME));
// Validate that the job is running.
jobGet = jobService.getJob(job.getId(), false);
assertEquals(JobStatusEnum.RUNNING, jobGet.getStatus());
assertNull(jobGet.getActivitiJobXml());
assertTrue(CollectionUtils.isEmpty(jobGet.getCompletedWorkflowSteps()));
assertEquals("usertask1", jobGet.getCurrentWorkflowStep().getId());
// Query the pending task and complete it
List<Task> tasks = activitiTaskService.createTaskQuery().processInstanceId(job.getId()).list();
activitiTaskService.complete(tasks.get(0).getId());
// Job should have been completed.
// Get the completed job with non verbose.
jobGet = jobService.getJob(job.getId(), false);
assertEquals(JobStatusEnum.COMPLETED, jobGet.getStatus());
assertNotNull(jobGet.getStartTime());
assertNotNull(jobGet.getEndTime());
assertNull(jobGet.getActivitiJobXml());
assertTrue(CollectionUtils.isEmpty(jobGet.getCompletedWorkflowSteps()));
assertNull(jobGet.getCurrentWorkflowStep());
}
Aggregations