Search in sources :

Example 46 with Job

use of org.finra.herd.model.api.xml.Job in project herd by FINRAOS.

the class JobServiceTest method testGetJobs.

@Test
public void testGetJobs() throws Exception {
    // Create and persist a job definition.
    jobDefinitionServiceTestHelper.createJobDefinition(ACTIVITI_XML_TEST_USER_TASK_WITH_CLASSPATH);
    // Create and start three 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)), jobService.createAndStartJob(jobServiceTestHelper.createJobCreateRequest(TEST_ACTIVITI_NAMESPACE_CD, TEST_ACTIVITI_JOB_NAME)));
    // Jobs should be waiting at relative User tasks.
    // Allow READ access for the current user to the job definition namespace.
    jobServiceTestHelper.setCurrentUserNamespaceAuthorizations(TEST_ACTIVITI_NAMESPACE_CD, Arrays.asList(NamespacePermissionEnum.READ));
    JobSummaries resultJobSummaries;
    Map<String, JobStatusEnum> expectedJobStatuses;
    DateTime startTime = new DateTime().minusHours(1);
    DateTime endTime = new DateTime().plusHours(1);
    // 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, startTime, 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);
            put(jobs.get(2).getId(), JobStatusEnum.RUNNING);
        }
    };
    validateJobSummaries(expectedJobStatuses, resultJobSummaries);
    // Query the pending tasks and complete them.
    for (Job job : jobs) {
        List<Task> tasks = activitiTaskService.createTaskQuery().processInstanceId(job.getId()).list();
        activitiTaskService.complete(tasks.get(0).getId());
    }
    // Jobs should have been completed.
    // Get all jobs for the relative job definition and expected job status.
    resultJobSummaries = jobService.getJobs(TEST_ACTIVITI_NAMESPACE_CD, TEST_ACTIVITI_JOB_NAME, JobStatusEnum.COMPLETED, startTime, endTime);
    // Validate the result job summaries.
    expectedJobStatuses = new HashMap<String, JobStatusEnum>() {

        {
            put(jobs.get(0).getId(), JobStatusEnum.COMPLETED);
            put(jobs.get(1).getId(), JobStatusEnum.COMPLETED);
            put(jobs.get(2).getId(), JobStatusEnum.COMPLETED);
        }
    };
    validateJobSummaries(expectedJobStatuses, resultJobSummaries);
}
Also used : Task(org.activiti.engine.task.Task) JobStatusEnum(org.finra.herd.model.api.xml.JobStatusEnum) JobSummaries(org.finra.herd.model.api.xml.JobSummaries) Job(org.finra.herd.model.api.xml.Job) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Example 47 with Job

use of org.finra.herd.model.api.xml.Job 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());
}
Also used : JobUpdateRequest(org.finra.herd.model.api.xml.JobUpdateRequest) Task(org.activiti.engine.task.Task) Job(org.finra.herd.model.api.xml.Job) Test(org.junit.Test)

Example 48 with Job

use of org.finra.herd.model.api.xml.Job in project herd by FINRAOS.

the class JobServiceTest method testUpdateJobTrimParameters.

@Test
public void testUpdateJobTrimParameters() 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 using input parameters with leading and trailing empty spaces.
    jobService.updateJob(addWhitespace(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 using input parameters with leading and trailing empty spaces.
    jobService.updateJob(addWhitespace(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());
}
Also used : JobUpdateRequest(org.finra.herd.model.api.xml.JobUpdateRequest) Task(org.activiti.engine.task.Task) Job(org.finra.herd.model.api.xml.Job) Test(org.junit.Test)

Example 49 with Job

use of org.finra.herd.model.api.xml.Job in project herd by FINRAOS.

the class JobServiceTest method testGetJobIntermediateTimer.

@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());
}
Also used : Job(org.finra.herd.model.api.xml.Job) Test(org.junit.Test)

Example 50 with Job

use of org.finra.herd.model.api.xml.Job in project herd by FINRAOS.

the class JobServiceTest method testSignalJobWithS3PropertiesPrecedenceRequestParamsOverridesS3.

/**
 * Signals job with both S3 properties and request parameters set. If there are name clashes, the request parameter should take precedence.
 *
 * @throws Exception
 */
@Test
public void testSignalJobWithS3PropertiesPrecedenceRequestParamsOverridesS3() throws Exception {
    jobDefinitionServiceTestHelper.createJobDefinition(ACTIVITI_XML_TEST_RECEIVE_TASK_WITH_CLASSPATH);
    Parameter s3Parameter = new Parameter("testName", "testValue");
    Parameter requestParameter = new Parameter("testName", "expectedValue");
    S3PropertiesLocation s3PropertiesLocation = getS3PropertiesLocation("s3BucketName", "s3ObjectKey", s3Parameter);
    // 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);
    jobSignalRequest.setParameters(Arrays.asList(requestParameter));
    Job signalJob = jobService.signalJob(jobSignalRequest);
    assertParameterEquals(requestParameter, signalJob.getParameters());
}
Also used : S3PropertiesLocation(org.finra.herd.model.api.xml.S3PropertiesLocation) Parameter(org.finra.herd.model.api.xml.Parameter) JobSignalRequest(org.finra.herd.model.api.xml.JobSignalRequest) Job(org.finra.herd.model.api.xml.Job) Test(org.junit.Test)

Aggregations

Job (org.finra.herd.model.api.xml.Job)71 Test (org.junit.Test)60 Parameter (org.finra.herd.model.api.xml.Parameter)30 HistoricProcessInstance (org.activiti.engine.history.HistoricProcessInstance)21 ArrayList (java.util.ArrayList)20 FieldExtension (org.activiti.bpmn.model.FieldExtension)11 AbstractServiceTest (org.finra.herd.service.AbstractServiceTest)11 Task (org.activiti.engine.task.Task)9 BusinessObjectDataKey (org.finra.herd.model.api.xml.BusinessObjectDataKey)9 ObjectNotFoundException (org.finra.herd.model.ObjectNotFoundException)8 JobDefinition (org.finra.herd.model.api.xml.JobDefinition)7 JobDeleteRequest (org.finra.herd.model.api.xml.JobDeleteRequest)7 JobSignalRequest (org.finra.herd.model.api.xml.JobSignalRequest)7 S3PropertiesLocation (org.finra.herd.model.api.xml.S3PropertiesLocation)7 AccessDeniedException (org.springframework.security.access.AccessDeniedException)7 JobAction (org.finra.herd.model.api.xml.JobAction)6 JobUpdateRequest (org.finra.herd.model.api.xml.JobUpdateRequest)6 NotificationRegistrationKey (org.finra.herd.model.api.xml.NotificationRegistrationKey)6 ApplicationUser (org.finra.herd.model.dto.ApplicationUser)6 SecurityUserWrapper (org.finra.herd.model.dto.SecurityUserWrapper)6