Search in sources :

Example 26 with Job

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

Example 27 with Job

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

the class JobServiceTest method testDeleteJob.

/**
 * 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());
}
Also used : HistoricProcessInstance(org.activiti.engine.history.HistoricProcessInstance) JobDeleteRequest(org.finra.herd.model.api.xml.JobDeleteRequest) Job(org.finra.herd.model.api.xml.Job) Test(org.junit.Test)

Example 28 with Job

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

the class JobServiceTest method testGetJobAssertNoErrorGivenJobCompletedAndUserDoesHasPermissions.

@Test
public void testGetJobAssertNoErrorGivenJobCompletedAndUserDoesHasPermissions() throws Exception {
    jobDefinitionServiceTestHelper.createJobDefinition(null);
    Job job = jobService.createAndStartJob(jobServiceTestHelper.createJobCreateRequest(TEST_ACTIVITI_NAMESPACE_CD, TEST_ACTIVITI_JOB_NAME));
    String username = "username";
    ApplicationUser applicationUser = new ApplicationUser(getClass());
    applicationUser.setUserId(username);
    applicationUser.setNamespaceAuthorizations(new HashSet<>());
    applicationUser.getNamespaceAuthorizations().add(new NamespaceAuthorization(TEST_ACTIVITI_NAMESPACE_CD, Arrays.asList(NamespacePermissionEnum.READ)));
    SecurityContextHolder.getContext().setAuthentication(new TestingAuthenticationToken(new SecurityUserWrapper(username, "password", false, false, false, false, Collections.emptyList(), applicationUser), null));
    try {
        jobService.getJob(job.getId(), false);
    } catch (AccessDeniedException e) {
        fail();
    }
}
Also used : ApplicationUser(org.finra.herd.model.dto.ApplicationUser) AccessDeniedException(org.springframework.security.access.AccessDeniedException) SecurityUserWrapper(org.finra.herd.model.dto.SecurityUserWrapper) NamespaceAuthorization(org.finra.herd.model.api.xml.NamespaceAuthorization) Job(org.finra.herd.model.api.xml.Job) TestingAuthenticationToken(org.springframework.security.authentication.TestingAuthenticationToken) Test(org.junit.Test)

Example 29 with Job

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

the class JobServiceTest method testDeleteJobActiveJobWithMultipleSubProcesses.

@Test
@Transactional(propagation = Propagation.NOT_SUPPORTED)
public void testDeleteJobActiveJobWithMultipleSubProcesses() 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());
        // Delete the job 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();
    }
}
Also used : JobDefinitionEntity(org.finra.herd.model.jpa.JobDefinitionEntity) HashMap(java.util.HashMap) HistoricProcessInstance(org.activiti.engine.history.HistoricProcessInstance) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) HistoricProcessInstance(org.activiti.engine.history.HistoricProcessInstance) JobDeleteRequest(org.finra.herd.model.api.xml.JobDeleteRequest) Job(org.finra.herd.model.api.xml.Job) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 30 with Job

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

the class JobServiceTest method testGetJob.

@Test
public void testGetJob() throws Exception {
    jobDefinitionServiceTestHelper.createJobDefinition(ACTIVITI_XML_TEST_USER_TASK_WITH_CLASSPATH);
    Job job = jobService.createAndStartJob(jobServiceTestHelper.createJobCreateRequest(TEST_ACTIVITI_NAMESPACE_CD, TEST_ACTIVITI_JOB_NAME));
    String activitiXml = IOUtils.toString(resourceLoader.getResource(ACTIVITI_XML_TEST_USER_TASK_WITH_CLASSPATH).getInputStream());
    // Job should be waiting at User task.
    // Running job with verbose
    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());
    // Running job with non verbose
    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.
    // Completed job with verbose
    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());
    // 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 : Task(org.activiti.engine.task.Task) 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