Search in sources :

Example 1 with JobSummaries

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

the class JobServiceGetJobsTest method testGetJobsGivenOneRunningJobAssertReturnCompletedJob.

@SuppressWarnings("unchecked")
@Test
public void testGetJobsGivenOneRunningJobAssertReturnCompletedJob() throws Exception {
    String namespace = "namespace";
    String jobName = "jobName";
    JobStatusEnum jobStatus = JobStatusEnum.RUNNING;
    long expectedNumberOfExceptions = 1234l;
    Set<String> authorizedNamespaces = new HashSet<>(Arrays.asList(namespace));
    when(namespaceSecurityHelper.getAuthorizedNamespaces(any())).thenReturn(authorizedNamespaces);
    NamespaceEntity namespaceEntity = new NamespaceEntity();
    namespaceEntity.setCode(namespace);
    when(namespaceDao.getNamespaceByCd(any())).thenReturn(namespaceEntity);
    List<JobDefinitionEntity> jobDefinitionEntities = new ArrayList<>();
    JobDefinitionEntity jobDefinitionEntity1 = new JobDefinitionEntity();
    jobDefinitionEntity1.setActivitiId(namespace + "." + jobName + ":1" + ":1");
    jobDefinitionEntities.add(jobDefinitionEntity1);
    when(jobDefinitionDao.getJobDefinitionsByFilter(any(Collection.class), any())).thenReturn(jobDefinitionEntities);
    ProcessDefinition processDefinition = mock(ProcessDefinition.class);
    when(processDefinition.getId()).thenReturn("a.b:1:1");
    when(processDefinition.getKey()).thenReturn("a.b");
    when(activitiService.getProcessDefinitionsByIds(any())).thenReturn(asList(processDefinition));
    when(activitiService.getHistoricProcessInstancesCountByStatusAndProcessDefinitionKeys(any(), any(), any(), any())).thenReturn(1l);
    List<HistoricProcessInstance> historicProcessInstances = new ArrayList<>();
    HistoricProcessInstanceEntity historicProcessInstanceEntity1 = new HistoricProcessInstanceEntity();
    historicProcessInstanceEntity1.setId("historicProcessInstanceEntity1.id");
    historicProcessInstanceEntity1.setProcessDefinitionId("a.b:1:1");
    historicProcessInstanceEntity1.setStartTime(new Date(1234));
    historicProcessInstances.add(historicProcessInstanceEntity1);
    when(activitiService.getHistoricProcessInstancesByStatusAndProcessDefinitionKeys(any(), any(), any(), any())).thenReturn(historicProcessInstances);
    when(activitiService.getJobsWithExceptionCountByProcessInstanceId(any())).thenReturn(expectedNumberOfExceptions);
    JobSummaries getJobsResult = jobServiceImpl.getJobs(namespace, jobName, jobStatus, NO_START_TIME, NO_END_TIME);
    List<JobSummary> jobSummaries = getJobsResult.getJobSummaries();
    assertEquals(1, jobSummaries.size());
    JobSummary jobSummary = jobSummaries.get(0);
    assertEquals(historicProcessInstanceEntity1.getId(), jobSummary.getId());
    assertEquals("a", jobSummary.getNamespace());
    assertEquals("b", jobSummary.getJobName());
    assertEquals(JobStatusEnum.RUNNING, jobSummary.getStatus());
    assertEquals(historicProcessInstanceEntity1.getStartTime().getTime(), jobSummary.getStartTime().toGregorianCalendar().getTimeInMillis());
    assertNull(jobSummary.getEndTime());
    assertEquals(expectedNumberOfExceptions, jobSummary.getTotalExceptions());
    verify(activitiService).getJobsWithExceptionCountByProcessInstanceId(historicProcessInstanceEntity1.getId());
    verify(activitiService).getHistoricProcessInstancesCountByStatusAndProcessDefinitionKeys(eq(JobStatusEnum.RUNNING), any(), any(), any());
    verify(activitiService).getHistoricProcessInstancesByStatusAndProcessDefinitionKeys(eq(JobStatusEnum.RUNNING), any(), any(), any());
}
Also used : NamespaceEntity(org.finra.herd.model.jpa.NamespaceEntity) HistoricProcessInstance(org.activiti.engine.history.HistoricProcessInstance) ArrayList(java.util.ArrayList) ProcessDefinition(org.activiti.engine.repository.ProcessDefinition) JobSummaries(org.finra.herd.model.api.xml.JobSummaries) Date(java.util.Date) JobSummary(org.finra.herd.model.api.xml.JobSummary) JobDefinitionEntity(org.finra.herd.model.jpa.JobDefinitionEntity) JobStatusEnum(org.finra.herd.model.api.xml.JobStatusEnum) Collection(java.util.Collection) HistoricProcessInstanceEntity(org.activiti.engine.impl.persistence.entity.HistoricProcessInstanceEntity) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 2 with JobSummaries

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

the class JobServiceGetJobsTest method testGetJobsWhenJobDaoReturnEmptyAssertReturnEmpty.

@SuppressWarnings("unchecked")
@Test
public void testGetJobsWhenJobDaoReturnEmptyAssertReturnEmpty() throws Exception {
    String namespace = "namespace";
    String jobName = "jobName";
    JobStatusEnum jobStatus = JobStatusEnum.COMPLETED;
    Set<String> authorizedNamespaces = new HashSet<>(Arrays.asList(namespace));
    when(namespaceSecurityHelper.getAuthorizedNamespaces(any())).thenReturn(authorizedNamespaces);
    NamespaceEntity namespaceEntity = new NamespaceEntity();
    namespaceEntity.setCode(namespace);
    when(namespaceDao.getNamespaceByCd(any())).thenReturn(namespaceEntity);
    when(jobDefinitionDao.getJobDefinitionsByFilter(any(Collection.class), any())).thenReturn(new ArrayList<>());
    JobSummaries getJobsResult = jobServiceImpl.getJobs(namespace, jobName, jobStatus, NO_START_TIME, NO_END_TIME);
    List<JobSummary> jobSummaries = getJobsResult.getJobSummaries();
    assertEquals(0, jobSummaries.size());
}
Also used : JobSummary(org.finra.herd.model.api.xml.JobSummary) NamespaceEntity(org.finra.herd.model.jpa.NamespaceEntity) JobStatusEnum(org.finra.herd.model.api.xml.JobStatusEnum) Collection(java.util.Collection) JobSummaries(org.finra.herd.model.api.xml.JobSummaries) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 3 with JobSummaries

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

Example 4 with JobSummaries

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

the class JobServiceTest method testGetJobsInvalidParameters.

@Test
public void testGetJobsInvalidParameters() 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;
    // 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);
            put(jobs.get(2).getId(), JobStatusEnum.RUNNING);
        }
    };
    validateJobSummaries(expectedJobStatuses, resultJobSummaries);
    // Try to get jobs using invalid job definition namespace.
    resultJobSummaries = jobService.getJobs("I_DO_NOT_EXIST", TEST_ACTIVITI_JOB_NAME, JobStatusEnum.RUNNING, NO_START_TIME, NO_END_TIME);
    assertEquals(0, resultJobSummaries.getJobSummaries().size());
    // Try to get jobs using invalid job definition name.
    resultJobSummaries = jobService.getJobs(TEST_ACTIVITI_NAMESPACE_CD, "I_DO_NOT_EXIST", JobStatusEnum.RUNNING, NO_START_TIME, NO_END_TIME);
    assertEquals(0, resultJobSummaries.getJobSummaries().size());
    // Try to get jobs using SUSPENDED job status.
    resultJobSummaries = jobService.getJobs(TEST_ACTIVITI_NAMESPACE_CD, TEST_ACTIVITI_JOB_NAME, JobStatusEnum.SUSPENDED, NO_START_TIME, NO_END_TIME);
    assertEquals(0, resultJobSummaries.getJobSummaries().size());
    // Try to get jobs using COMPLETED job status.
    resultJobSummaries = jobService.getJobs(TEST_ACTIVITI_NAMESPACE_CD, TEST_ACTIVITI_JOB_NAME, JobStatusEnum.COMPLETED, NO_START_TIME, NO_END_TIME);
    assertEquals(0, resultJobSummaries.getJobSummaries().size());
    // Try to get jobs using invalid start time (current time plus one hour).
    DateTime invalidStartTime = new DateTime().plusHours(1);
    resultJobSummaries = jobService.getJobs(TEST_ACTIVITI_NAMESPACE_CD, TEST_ACTIVITI_JOB_NAME, JobStatusEnum.RUNNING, invalidStartTime, NO_END_TIME);
    assertEquals(0, resultJobSummaries.getJobSummaries().size());
    // 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, 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);
            put(jobs.get(2).getId(), JobStatusEnum.COMPLETED);
        }
    };
    validateJobSummaries(expectedJobStatuses, resultJobSummaries);
    // Try to get jobs using invalid end time (current time minus one hour).
    DateTime invalidEndTime = new DateTime().minusHours(1);
    resultJobSummaries = jobService.getJobs(TEST_ACTIVITI_NAMESPACE_CD, TEST_ACTIVITI_JOB_NAME, JobStatusEnum.COMPLETED, NO_START_TIME, invalidEndTime);
    assertEquals(0, resultJobSummaries.getJobSummaries().size());
}
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 5 with JobSummaries

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

the class JobServiceTest method testGetJobsMissingOptionalParameters.

@Test
public void testGetJobsMissingOptionalParameters() 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;
    // Get all jobs without specifying any of the optional parameters.
    resultJobSummaries = jobService.getJobs(NO_NAMESPACE, NO_ACTIVITI_JOB_NAME, NO_ACTIVITI_JOB_STATUS, 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);
            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 without specifying any of the optional parameters.
    resultJobSummaries = jobService.getJobs(NO_NAMESPACE, NO_ACTIVITI_JOB_NAME, NO_ACTIVITI_JOB_STATUS, 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);
            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) Test(org.junit.Test)

Aggregations

JobSummaries (org.finra.herd.model.api.xml.JobSummaries)12 Test (org.junit.Test)11 JobStatusEnum (org.finra.herd.model.api.xml.JobStatusEnum)10 JobSummary (org.finra.herd.model.api.xml.JobSummary)7 HashSet (java.util.HashSet)6 Task (org.activiti.engine.task.Task)5 Job (org.finra.herd.model.api.xml.Job)5 NamespaceEntity (org.finra.herd.model.jpa.NamespaceEntity)5 Collection (java.util.Collection)4 HistoricProcessInstance (org.activiti.engine.history.HistoricProcessInstance)4 ProcessDefinition (org.activiti.engine.repository.ProcessDefinition)4 JobDefinitionEntity (org.finra.herd.model.jpa.JobDefinitionEntity)4 DateTime (org.joda.time.DateTime)4 ArrayList (java.util.ArrayList)3 Date (java.util.Date)3 HistoricProcessInstanceEntity (org.activiti.engine.impl.persistence.entity.HistoricProcessInstanceEntity)3 HashMap (java.util.HashMap)1 Pattern (java.util.regex.Pattern)1 JobUpdateRequest (org.finra.herd.model.api.xml.JobUpdateRequest)1 JobDefinitionAlternateKeyDto (org.finra.herd.model.dto.JobDefinitionAlternateKeyDto)1