Search in sources :

Example 21 with JobDefinitionEntity

use of org.finra.herd.model.jpa.JobDefinitionEntity in project herd by FINRAOS.

the class JobDefinitionDaoImpl method getJobDefinitionsByFilter.

@Override
public List<JobDefinitionEntity> getJobDefinitionsByFilter(Collection<String> namespaces, String jobName) {
    // Create the criteria builder and the criteria.
    CriteriaBuilder builder = entityManager.getCriteriaBuilder();
    CriteriaQuery<JobDefinitionEntity> criteria = builder.createQuery(JobDefinitionEntity.class);
    // The criteria root is the job definition.
    Root<JobDefinitionEntity> jobDefinitionEntityRoot = criteria.from(JobDefinitionEntity.class);
    // Join to the other tables we can filter on.
    Join<JobDefinitionEntity, NamespaceEntity> namespaceEntityJoin = jobDefinitionEntityRoot.join(JobDefinitionEntity_.namespace);
    // Create the standard restrictions (i.e. the standard where clauses).
    List<Predicate> predicates = new ArrayList<>();
    if (CollectionUtils.isNotEmpty(namespaces)) {
        predicates.add(namespaceEntityJoin.get(NamespaceEntity_.code).in(namespaces));
    }
    if (StringUtils.isNotBlank(jobName)) {
        predicates.add(builder.equal(builder.upper(jobDefinitionEntityRoot.get(JobDefinitionEntity_.name)), jobName.toUpperCase()));
    }
    // Order the results by namespace and job name.
    List<Order> orderBy = new ArrayList<>();
    orderBy.add(builder.asc(namespaceEntityJoin.get(NamespaceEntity_.code)));
    orderBy.add(builder.asc(jobDefinitionEntityRoot.get(JobDefinitionEntity_.name)));
    // Add the clauses for the query.
    criteria.select(jobDefinitionEntityRoot).where(builder.and(predicates.toArray(new Predicate[predicates.size()]))).orderBy(orderBy);
    // Execute the query and return the result list.
    return entityManager.createQuery(criteria).getResultList();
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) Order(javax.persistence.criteria.Order) JobDefinitionEntity(org.finra.herd.model.jpa.JobDefinitionEntity) NamespaceEntity(org.finra.herd.model.jpa.NamespaceEntity) ArrayList(java.util.ArrayList) Predicate(javax.persistence.criteria.Predicate)

Example 22 with JobDefinitionEntity

use of org.finra.herd.model.jpa.JobDefinitionEntity in project herd by FINRAOS.

the class JobDefinitionServiceTest method testCreateJobDefinitionWithS3PropertiesLocationPersistsEntity.

/**
 * Asserts that when a job definition is created using {@link S3PropertiesLocation}, the S3 location information is persisted.
 *
 * @throws Exception
 */
@Test
public void testCreateJobDefinitionWithS3PropertiesLocationPersistsEntity() throws Exception {
    S3PropertiesLocation s3PropertiesLocation = getS3PropertiesLocation();
    namespaceDaoTestHelper.createNamespaceEntity(TEST_ACTIVITI_NAMESPACE_CD);
    JobDefinitionCreateRequest request = jobDefinitionServiceTestHelper.createJobDefinitionCreateRequest();
    request.setS3PropertiesLocation(s3PropertiesLocation);
    JobDefinition jobDefinition = jobDefinitionService.createJobDefinition(request, false);
    Assert.assertEquals("jobDefinition s3PropertiesLocation", request.getS3PropertiesLocation(), jobDefinition.getS3PropertiesLocation());
    JobDefinitionEntity jobDefinitionEntity = herdDao.findById(JobDefinitionEntity.class, jobDefinition.getId());
    Assert.assertNotNull("jobDefinitionEntity is null", jobDefinitionEntity);
    Assert.assertEquals("jobDefinitionEntity s3BucketName", s3PropertiesLocation.getBucketName(), jobDefinitionEntity.getS3BucketName());
    Assert.assertEquals("jobDefinitionEntity s3ObjectKey", s3PropertiesLocation.getKey(), jobDefinitionEntity.getS3ObjectKey());
}
Also used : JobDefinitionEntity(org.finra.herd.model.jpa.JobDefinitionEntity) S3PropertiesLocation(org.finra.herd.model.api.xml.S3PropertiesLocation) JobDefinitionCreateRequest(org.finra.herd.model.api.xml.JobDefinitionCreateRequest) JobDefinition(org.finra.herd.model.api.xml.JobDefinition) Test(org.junit.Test)

Example 23 with JobDefinitionEntity

use of org.finra.herd.model.jpa.JobDefinitionEntity in project herd by FINRAOS.

the class JobDefinitionServiceTest method testUpdateJobDefinitionWithS3PropertiesClear.

@Test
public void testUpdateJobDefinitionWithS3PropertiesClear() throws Exception {
    S3PropertiesLocation s3PropertiesLocation = getS3PropertiesLocation();
    // Create the namespace entity.
    namespaceDaoTestHelper.createNamespaceEntity(TEST_ACTIVITI_NAMESPACE_CD);
    // Create job definition create request using hard coded test values.
    JobDefinitionCreateRequest createRequest = jobDefinitionServiceTestHelper.createJobDefinitionCreateRequest();
    createRequest.setS3PropertiesLocation(s3PropertiesLocation);
    // Create the job definition in the database.
    JobDefinition jobDefinition = jobDefinitionService.createJobDefinition(createRequest, false);
    // Create an update request with a varied set of data that is based on the same data used in the create request.
    JobDefinitionUpdateRequest updateRequest = createUpdateRequest(createRequest);
    // Update the job definition in the database.
    JobDefinition updatedJobDefinition = jobDefinitionService.updateJobDefinition(createRequest.getNamespace(), createRequest.getJobName(), updateRequest, false);
    JobDefinitionEntity updatedJobDefinitionEntity = herdDao.findById(JobDefinitionEntity.class, updatedJobDefinition.getId());
    // Validate the updated job definition.
    assertEquals(new JobDefinition(jobDefinition.getId(), jobDefinition.getNamespace(), jobDefinition.getJobName(), updateRequest.getDescription(), updateRequest.getActivitiJobXml(), updateRequest.getParameters(), null, HerdDaoSecurityHelper.SYSTEM_USER), updatedJobDefinition);
    // Validate the updated job definition entity.
    Assert.assertNull("updatedJobDefinitionEntity s3BucketName", updatedJobDefinitionEntity.getS3BucketName());
    Assert.assertNull("updatedJobDefinitionEntity s3ObjectKey", updatedJobDefinitionEntity.getS3ObjectKey());
}
Also used : JobDefinitionEntity(org.finra.herd.model.jpa.JobDefinitionEntity) S3PropertiesLocation(org.finra.herd.model.api.xml.S3PropertiesLocation) JobDefinitionCreateRequest(org.finra.herd.model.api.xml.JobDefinitionCreateRequest) JobDefinition(org.finra.herd.model.api.xml.JobDefinition) JobDefinitionUpdateRequest(org.finra.herd.model.api.xml.JobDefinitionUpdateRequest) Test(org.junit.Test)

Example 24 with JobDefinitionEntity

use of org.finra.herd.model.jpa.JobDefinitionEntity in project herd by FINRAOS.

the class JobServiceGetJobsTest method testGetJobsGivenOneCompletedJobAndPassingStartAndEndTimeAssertReturnCompletedJob.

@SuppressWarnings("unchecked")
@Test
public void testGetJobsGivenOneCompletedJobAndPassingStartAndEndTimeAssertReturnCompletedJob() throws Exception {
    String namespace = "namespace";
    String jobName = "jobName";
    DateTime startTime = new DateTime(new Date(0123));
    DateTime endTime = new DateTime(new Date(3456));
    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);
    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));
    historicProcessInstanceEntity1.setEndTime(new Date(2345));
    historicProcessInstances.add(historicProcessInstanceEntity1);
    when(activitiService.getHistoricProcessInstancesByStatusAndProcessDefinitionKeys(any(), any(), any(), any())).thenReturn(historicProcessInstances);
    JobSummaries getJobsResult = jobServiceImpl.getJobs(namespace, jobName, jobStatus, startTime, endTime);
    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.COMPLETED, jobSummary.getStatus());
    assertEquals(historicProcessInstanceEntity1.getStartTime().getTime(), jobSummary.getStartTime().toGregorianCalendar().getTimeInMillis());
    assertEquals(historicProcessInstanceEntity1.getEndTime().getTime(), jobSummary.getEndTime().toGregorianCalendar().getTimeInMillis());
    assertEquals(0, jobSummary.getTotalExceptions());
    verify(activitiService).getHistoricProcessInstancesCountByStatusAndProcessDefinitionKeys(eq(JobStatusEnum.COMPLETED), any(), eq(startTime), eq(endTime));
    verify(activitiService).getHistoricProcessInstancesByStatusAndProcessDefinitionKeys(eq(JobStatusEnum.COMPLETED), any(), eq(startTime), eq(endTime));
}
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) DateTime(org.joda.time.DateTime) 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 25 with JobDefinitionEntity

use of org.finra.herd.model.jpa.JobDefinitionEntity in project herd by FINRAOS.

the class JobServiceGetJobsTest method testGetJobsGivenMultipleHistoricProcessInstanceWithSamKeyJobAssertReturnCompletedJob.

/**
 * Tests case where multiple process instances were created, but the job definition entities were deleted at some point without removing the old historic
 * instances, then a new process instance is created with the same namespace and job name pair. When a ListJobs is called, it should not return the old
 * instance information. <p/> This case was added as a verification to the bug raised by test automation.
 */
@SuppressWarnings("unchecked")
@Test
public void testGetJobsGivenMultipleHistoricProcessInstanceWithSamKeyJobAssertReturnCompletedJob() 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);
    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));
        historicProcessInstanceEntity1.setEndTime(new Date(2345));
        historicProcessInstances.add(historicProcessInstanceEntity1);
    }
    {
        HistoricProcessInstanceEntity historicProcessInstanceEntity1 = new HistoricProcessInstanceEntity();
        historicProcessInstanceEntity1.setId("historicProcessInstanceEntity2.id");
        historicProcessInstanceEntity1.setProcessDefinitionId("a.b:1:2");
        historicProcessInstanceEntity1.setStartTime(new Date(1234));
        historicProcessInstanceEntity1.setEndTime(new Date(2345));
        historicProcessInstances.add(historicProcessInstanceEntity1);
    }
    when(activitiService.getHistoricProcessInstancesByStatusAndProcessDefinitionKeys(any(), any(), any(), any())).thenReturn(historicProcessInstances);
    JobSummaries getJobsResult = jobServiceImpl.getJobs(namespace, jobName, jobStatus, NO_START_TIME, NO_END_TIME);
    List<JobSummary> jobSummaries = getJobsResult.getJobSummaries();
    assertEquals(1, jobSummaries.size());
}
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)

Aggregations

JobDefinitionEntity (org.finra.herd.model.jpa.JobDefinitionEntity)36 NamespaceEntity (org.finra.herd.model.jpa.NamespaceEntity)18 Test (org.junit.Test)17 ArrayList (java.util.ArrayList)12 ProcessDefinition (org.activiti.engine.repository.ProcessDefinition)11 HistoricProcessInstance (org.activiti.engine.history.HistoricProcessInstance)7 Collection (java.util.Collection)6 HashSet (java.util.HashSet)6 JobDefinition (org.finra.herd.model.api.xml.JobDefinition)5 JobStatusEnum (org.finra.herd.model.api.xml.JobStatusEnum)5 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)4 Predicate (javax.persistence.criteria.Predicate)4 NamespacePermission (org.finra.herd.model.annotation.NamespacePermission)4 JobAction (org.finra.herd.model.api.xml.JobAction)4 JobDefinitionCreateRequest (org.finra.herd.model.api.xml.JobDefinitionCreateRequest)4 JobSummaries (org.finra.herd.model.api.xml.JobSummaries)4 JobSummary (org.finra.herd.model.api.xml.JobSummary)4 NotificationActionEntity (org.finra.herd.model.jpa.NotificationActionEntity)4 NotificationJobActionEntity (org.finra.herd.model.jpa.NotificationJobActionEntity)4 Date (java.util.Date)3