Search in sources :

Example 16 with JobDefinitionCreateRequest

use of org.finra.herd.model.api.xml.JobDefinitionCreateRequest 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());
}
Also used : JobDefinitionEntity(org.finra.herd.model.jpa.JobDefinitionEntity) JobDefinitionCreateRequest(org.finra.herd.model.api.xml.JobDefinitionCreateRequest) Parameter(org.finra.herd.model.api.xml.Parameter) Job(org.finra.herd.model.api.xml.Job) JobDefinition(org.finra.herd.model.api.xml.JobDefinition) JobCreateRequest(org.finra.herd.model.api.xml.JobCreateRequest) Test(org.junit.Test)

Example 17 with JobDefinitionCreateRequest

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

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

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

the class JobDefinitionServiceTest method testCreateJobDefinitionInvalidActivitiElement.

/**
 * This method tests the scenario in which an invalid Java class name is given. This must throw IllegalArgumentException from the Activiti layer.
 */
@Test(expected = IllegalArgumentException.class)
public void testCreateJobDefinitionInvalidActivitiElement() throws Exception {
    // Create the namespace entity.
    namespaceDaoTestHelper.createNamespaceEntity(TEST_ACTIVITI_NAMESPACE_CD);
    // Create and persist a valid job definition.
    JobDefinitionCreateRequest request = jobDefinitionServiceTestHelper.createJobDefinitionCreateRequest();
    // Read the Activiti XML file so that an error can be injected.
    InputStream xmlStream = resourceLoader.getResource(ACTIVITI_XML_HERD_WORKFLOW_WITH_CLASSPATH).getInputStream();
    // Inject an error by having an invalid Activiti element name in the XML file.
    // Note that XML file structure is correct as per the XML schema. However, there is an invalid Activiti element in the XML file.
    // The line below will be affected in the XML file as per this error injection.
    // <serviceTask id="servicetask1" name="Test Service Step" activiti:class="org.activiti.engine.impl.test.NoOpServiceTask">
    request.setActivitiJobXml(IOUtils.toString(xmlStream).replaceAll("serviceTask", "invalidActivitiTask"));
    // Try creating the job definition and the Activiti layer mush throw an exception.
    jobDefinitionService.createJobDefinition(request, false);
}
Also used : InputStream(java.io.InputStream) JobDefinitionCreateRequest(org.finra.herd.model.api.xml.JobDefinitionCreateRequest) Test(org.junit.Test)

Example 20 with JobDefinitionCreateRequest

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

the class JobDefinitionServiceTestHelper method createJobDefinitionCreateRequest.

/**
 * Creates a new job definition create request based on user specified parameters.
 *
 * @param namespaceCd the namespace code.
 * @param jobName the job name.
 * @param jobDescription the job description.
 * @param activitiXml the Activiti XML.
 * @param parameters the parameters.
 *
 * @return the job definition create request.
 */
public JobDefinitionCreateRequest createJobDefinitionCreateRequest(String namespaceCd, String jobName, String jobDescription, String activitiXml, List<Parameter> parameters) {
    // Create and return a new job definition create request.
    JobDefinitionCreateRequest request = new JobDefinitionCreateRequest();
    request.setNamespace(namespaceCd);
    request.setJobName(jobName);
    request.setDescription(jobDescription);
    request.setActivitiJobXml(activitiXml);
    request.setParameters(parameters);
    return request;
}
Also used : JobDefinitionCreateRequest(org.finra.herd.model.api.xml.JobDefinitionCreateRequest)

Aggregations

JobDefinitionCreateRequest (org.finra.herd.model.api.xml.JobDefinitionCreateRequest)26 Test (org.junit.Test)19 JobDefinition (org.finra.herd.model.api.xml.JobDefinition)9 Parameter (org.finra.herd.model.api.xml.Parameter)5 BpmnModel (org.activiti.bpmn.model.BpmnModel)4 EndEvent (org.activiti.bpmn.model.EndEvent)4 Process (org.activiti.bpmn.model.Process)4 SequenceFlow (org.activiti.bpmn.model.SequenceFlow)4 StartEvent (org.activiti.bpmn.model.StartEvent)4 JobCreateRequest (org.finra.herd.model.api.xml.JobCreateRequest)4 JobDefinitionUpdateRequest (org.finra.herd.model.api.xml.JobDefinitionUpdateRequest)4 JobDefinitionEntity (org.finra.herd.model.jpa.JobDefinitionEntity)4 ArrayList (java.util.ArrayList)3 ScriptTask (org.activiti.bpmn.model.ScriptTask)3 Job (org.finra.herd.model.api.xml.Job)3 S3PropertiesLocation (org.finra.herd.model.api.xml.S3PropertiesLocation)3 InputStream (java.io.InputStream)2 AlreadyExistsException (org.finra.herd.model.AlreadyExistsException)2 ObjectNotFoundException (org.finra.herd.model.ObjectNotFoundException)2 Transactional (org.springframework.transaction.annotation.Transactional)1