Search in sources :

Example 16 with Job

use of org.finra.herd.model.api.xml.Job 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 17 with Job

use of org.finra.herd.model.api.xml.Job 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 18 with Job

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

the class JobServiceTest method testGetJobAssertNoErrorGivenJobRunningAndUserDoesHasPermissions.

@Test
public void testGetJobAssertNoErrorGivenJobRunningAndUserDoesHasPermissions() 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 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 19 with Job

use of org.finra.herd.model.api.xml.Job 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)

Example 20 with Job

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

the class JobServiceTest method testCreateJobWithS3Properties.

/**
 * Creates a job where the definition and request has S3 properties. Both parameters should be merged.
 *
 * @throws Exception
 */
@Test
public void testCreateJobWithS3Properties() throws Exception {
    Parameter jobDefinitionS3Parameter = new Parameter("name1", "value1");
    Parameter jobCreateRequestS3Parameter = new Parameter("name2", "value2");
    String s3BucketName = "s3BucketName";
    S3PropertiesLocation jobDefinitionS3PropertiesLocation = getS3PropertiesLocation(s3BucketName, "jobDefinitionObjectKey", jobDefinitionS3Parameter);
    S3PropertiesLocation jobCreateRequestS3PropertiesLocation = getS3PropertiesLocation(s3BucketName, "jobCreationObjectKey", jobCreateRequestS3Parameter);
    Job resultJob = createJobWithParameters(jobDefinitionS3PropertiesLocation, null, jobCreateRequestS3PropertiesLocation, null);
    List<Parameter> actualParameters = resultJob.getParameters();
    assertParameterEquals(jobDefinitionS3Parameter, actualParameters);
    assertParameterEquals(jobCreateRequestS3Parameter, actualParameters);
}
Also used : S3PropertiesLocation(org.finra.herd.model.api.xml.S3PropertiesLocation) Parameter(org.finra.herd.model.api.xml.Parameter) 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