use of org.finra.herd.model.jpa.JobDefinitionEntity in project herd by FINRAOS.
the class JobServiceGetJobsTest method testGetJobsWhenJobStatusNullQueryIgnoreStatus.
@SuppressWarnings("unchecked")
@Test
public void testGetJobsWhenJobStatusNullQueryIgnoreStatus() throws Exception {
String namespace = "namespace";
String jobName = "jobName";
JobStatusEnum jobStatus = null;
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);
when(activitiService.getProcessDefinitionsByIds(any())).thenReturn(asList());
jobServiceImpl.getJobs(namespace, jobName, jobStatus, NO_START_TIME, NO_END_TIME);
// Assert neither status filter was called on the query
verify(activitiService).getHistoricProcessInstancesCountByStatusAndProcessDefinitionKeys(isNull(JobStatusEnum.class), any(), any(), any());
verify(activitiService).getHistoricProcessInstancesByStatusAndProcessDefinitionKeys(isNull(JobStatusEnum.class), any(), any(), any());
}
use of org.finra.herd.model.jpa.JobDefinitionEntity in project herd by FINRAOS.
the class JobServiceTest method testCreateJobWithS3PropertiesJobDefinitionWrongDatafixSafety.
/**
* Tests an edge case where the job definition was persisted with some S3 properties location, but due to some datafix, the S3 properties location's object
* key was removed, but not the bucket name. The service should still work, it would simply ignore the definition's S3 properties location.
*
* @throws Exception
*/
@Test
public void testCreateJobWithS3PropertiesJobDefinitionWrongDatafixSafety() throws Exception {
// Create the namespace entity.
namespaceDaoTestHelper.createNamespaceEntity(TEST_ACTIVITI_NAMESPACE_CD);
// Create a job definition create request using hard coded test values.
JobDefinitionCreateRequest jobDefinitionCreateRequest = jobDefinitionServiceTestHelper.createJobDefinitionCreateRequest();
jobDefinitionCreateRequest.setS3PropertiesLocation(getS3PropertiesLocation("testBucketName", "testObjectKey", new Parameter("testName", "testValue")));
jobDefinitionCreateRequest.setParameters(null);
// Create the job definition.
JobDefinition jobDefinition = jobDefinitionService.createJobDefinition(jobDefinitionCreateRequest, false);
Integer jobDefinitionId = jobDefinition.getId();
JobDefinitionEntity jobDefinitionEntity = herdDao.findById(JobDefinitionEntity.class, jobDefinitionId);
jobDefinitionEntity.setS3ObjectKey(null);
// Create a job create request using hard coded test values.
JobCreateRequest jobCreateRequest = jobServiceTestHelper.createJobCreateRequest(TEST_ACTIVITI_NAMESPACE_CD, TEST_ACTIVITI_JOB_NAME);
jobCreateRequest.setParameters(null);
// Create the job.
Job resultJob = jobService.createAndStartJob(jobCreateRequest);
Assert.assertNotNull("resultJob parameters", resultJob.getParameters());
}
use of org.finra.herd.model.jpa.JobDefinitionEntity in project herd by FINRAOS.
the class JobServiceTest method testDeleteJobSuspendedJobWithMultipleSubProcesses.
@Test
@Transactional(propagation = Propagation.NOT_SUPPORTED)
public void testDeleteJobSuspendedJobWithMultipleSubProcesses() 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());
// Suspend the job.
jobService.updateJob(processInstanceId, new JobUpdateRequest(JobActionEnum.SUSPEND));
// Get the job again and validate that it is now SUSPENDED.
getJobResponse = jobService.getJob(processInstanceId, true);
assertNotNull(getJobResponse);
assertEquals(JobStatusEnum.SUSPENDED, getJobResponse.getStatus());
// Delete the job in suspended state 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();
}
}
use of org.finra.herd.model.jpa.JobDefinitionEntity 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();
}
}
use of org.finra.herd.model.jpa.JobDefinitionEntity in project herd by FINRAOS.
the class JobDefinitionDaoImpl method getJobDefinitionByProcessDefinitionId.
@Override
public JobDefinitionEntity getJobDefinitionByProcessDefinitionId(String processDefinitionId) {
// 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> jobDefinition = criteria.from(JobDefinitionEntity.class);
// Create the standard restrictions (i.e. the standard where clauses).
Predicate namespaceRestriction = builder.equal(jobDefinition.get(JobDefinitionEntity_.activitiId), processDefinitionId);
criteria.select(jobDefinition).where(builder.and(namespaceRestriction, namespaceRestriction));
return executeSingleResultQuery(criteria, String.format("Found more than one Activiti job definition with processDefinitionId = \"%s\".", processDefinitionId));
}
Aggregations