Search in sources :

Example 21 with JobDefinitionCreateRequest

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

the class JobDefinitionServiceTestHelper method createJobDefinition.

/**
 * Creates a job definition based on the specified Activiti XML classpath resource location.
 *
 * @param activitiXmlClasspathResourceName the Activiti XML classpath resource location.
 *
 * @return the job definition.
 * @throws Exception if any errors were encountered.
 */
public JobDefinition createJobDefinition(String activitiXmlClasspathResourceName) throws Exception {
    // Create the namespace entity.
    namespaceDaoTestHelper.createNamespaceEntity(AbstractServiceTest.TEST_ACTIVITI_NAMESPACE_CD);
    // Create and persist a valid job definition.
    JobDefinitionCreateRequest jobDefinitionCreateRequest = createJobDefinitionCreateRequest(activitiXmlClasspathResourceName);
    JobDefinition jobDefinition = jobDefinitionService.createJobDefinition(jobDefinitionCreateRequest, false);
    // Validate the returned object against the input.
    assertEquals(new JobDefinition(jobDefinition.getId(), jobDefinitionCreateRequest.getNamespace(), jobDefinitionCreateRequest.getJobName(), jobDefinitionCreateRequest.getDescription(), jobDefinitionCreateRequest.getActivitiJobXml(), jobDefinitionCreateRequest.getParameters(), jobDefinitionCreateRequest.getS3PropertiesLocation(), HerdDaoSecurityHelper.SYSTEM_USER), jobDefinition);
    return jobDefinition;
}
Also used : JobDefinitionCreateRequest(org.finra.herd.model.api.xml.JobDefinitionCreateRequest) JobDefinition(org.finra.herd.model.api.xml.JobDefinition)

Example 22 with JobDefinitionCreateRequest

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

the class JobServiceTest method createJobWithParameters.

/**
 * Creates a new job definition, and a job using the default values and given parameters configurations.
 *
 * @param jobDefinitionS3PropertiesLocation the S3 properties location for the job definition
 * @param jobDefinitionParameters the job definition parameters
 * @param jobCreateRequestS3PropertiesLocation the S3 properties location for the job create request
 * @param jobCreateRequestParameters the job create request parameters
 *
 * @return the job
 * @throws Exception
 */
private Job createJobWithParameters(S3PropertiesLocation jobDefinitionS3PropertiesLocation, List<Parameter> jobDefinitionParameters, S3PropertiesLocation jobCreateRequestS3PropertiesLocation, List<Parameter> jobCreateRequestParameters) 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.setParameters(jobDefinitionParameters);
    jobDefinitionCreateRequest.setS3PropertiesLocation(jobDefinitionS3PropertiesLocation);
    // Create the job definition.
    jobDefinitionService.createJobDefinition(jobDefinitionCreateRequest, false);
    // Create a job create request using hard coded test values.
    JobCreateRequest jobCreateRequest = jobServiceTestHelper.createJobCreateRequest(TEST_ACTIVITI_NAMESPACE_CD, TEST_ACTIVITI_JOB_NAME);
    jobCreateRequest.setParameters(jobCreateRequestParameters);
    jobCreateRequest.setS3PropertiesLocation(jobCreateRequestS3PropertiesLocation);
    // Create the job.
    return jobService.createAndStartJob(jobCreateRequest);
}
Also used : JobDefinitionCreateRequest(org.finra.herd.model.api.xml.JobDefinitionCreateRequest) JobCreateRequest(org.finra.herd.model.api.xml.JobCreateRequest)

Example 23 with JobDefinitionCreateRequest

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

the class JobDefinitionServiceTest method createJobDefinition.

/**
 * Creates a new standard job definition.
 *
 * @return the created job definition.
 * @throws Exception if any problems were encountered.
 */
private JobDefinition createJobDefinition() throws Exception {
    // Create the namespace entity.
    namespaceDaoTestHelper.createNamespaceEntity(TEST_ACTIVITI_NAMESPACE_CD);
    // Create job definition create request using hard coded test values.
    JobDefinitionCreateRequest request = jobDefinitionServiceTestHelper.createJobDefinitionCreateRequest();
    // Create the job definition in the database.
    JobDefinition jobDefinition = jobDefinitionService.createJobDefinition(request, false);
    // Validate the created job definition.
    validateJobDefinition(jobDefinition);
    return jobDefinition;
}
Also used : JobDefinitionCreateRequest(org.finra.herd.model.api.xml.JobDefinitionCreateRequest) JobDefinition(org.finra.herd.model.api.xml.JobDefinition)

Example 24 with JobDefinitionCreateRequest

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

the class JobDefinitionServiceTest method testUpdateJobDefinition.

@Test
public void testUpdateJobDefinition() throws Exception {
    // Create job definition create request using hard coded test values.
    JobDefinitionCreateRequest createRequest = jobDefinitionServiceTestHelper.createJobDefinitionCreateRequest();
    // Set 2 distinct parameters.
    List<Parameter> parameters = new ArrayList<>();
    createRequest.setParameters(parameters);
    Parameter parameter = new Parameter(ATTRIBUTE_NAME_1_MIXED_CASE, ATTRIBUTE_VALUE_1);
    parameters.add(parameter);
    parameter = new Parameter(ATTRIBUTE_NAME_2_MIXED_CASE, ATTRIBUTE_VALUE_2);
    parameters.add(parameter);
    // Create the namespace entity.
    namespaceDaoTestHelper.createNamespaceEntity(TEST_ACTIVITI_NAMESPACE_CD);
    // 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);
    // Validate the updated job definition.
    assertEquals(new JobDefinition(jobDefinition.getId(), jobDefinition.getNamespace(), jobDefinition.getJobName(), updateRequest.getDescription(), updateRequest.getActivitiJobXml(), updateRequest.getParameters(), jobDefinition.getS3PropertiesLocation(), HerdDaoSecurityHelper.SYSTEM_USER), updatedJobDefinition);
}
Also used : JobDefinitionCreateRequest(org.finra.herd.model.api.xml.JobDefinitionCreateRequest) ArrayList(java.util.ArrayList) Parameter(org.finra.herd.model.api.xml.Parameter) JobDefinition(org.finra.herd.model.api.xml.JobDefinition) JobDefinitionUpdateRequest(org.finra.herd.model.api.xml.JobDefinitionUpdateRequest) Test(org.junit.Test)

Example 25 with JobDefinitionCreateRequest

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

the class JobDefinitionServiceTest method testCreateJobDefinitionAssertThrowErrorWhenFirstTaskNotAsync.

/**
 * Asserts that create job definition proceeds throws an exception when the first task is not async
 *
 * @throws Exception
 */
@Test
public void testCreateJobDefinitionAssertThrowErrorWhenFirstTaskNotAsync() throws Exception {
    String namespace = NAMESPACE;
    String jobName = JOB_NAME;
    BpmnModel bpmnModel = new BpmnModel();
    Process process = new Process();
    process.setId(namespace + '.' + jobName);
    {
        StartEvent element = new StartEvent();
        element.setId("start");
        process.addFlowElement(element);
    }
    {
        ScriptTask element = new ScriptTask();
        element.setId("script");
        element.setScriptFormat("js");
        element.setScript("// do nothing");
        process.addFlowElement(element);
    }
    {
        EndEvent element = new EndEvent();
        element.setId("end");
        process.addFlowElement(element);
    }
    process.addFlowElement(new SequenceFlow("start", "script"));
    process.addFlowElement(new SequenceFlow("script", "end"));
    bpmnModel.addProcess(process);
    String activitiJobXml = getActivitiXmlFromBpmnModel(bpmnModel);
    namespaceDaoTestHelper.createNamespaceEntity(namespace);
    try {
        jobDefinitionService.createJobDefinition(new JobDefinitionCreateRequest(namespace, jobName, null, activitiJobXml, null, null), true);
        fail();
    } catch (Exception e) {
        assertEquals(IllegalArgumentException.class, e.getClass());
        assertEquals("Element with id \"script\" must be set to activiti:async=true. All tasks which start the workflow must be asynchronous to prevent " + "certain undesired transactional behavior, such as records of workflow not being saved on errors. Please refer to Activiti and herd " + "documentations for details.", e.getMessage());
    }
}
Also used : ScriptTask(org.activiti.bpmn.model.ScriptTask) SequenceFlow(org.activiti.bpmn.model.SequenceFlow) StartEvent(org.activiti.bpmn.model.StartEvent) JobDefinitionCreateRequest(org.finra.herd.model.api.xml.JobDefinitionCreateRequest) EndEvent(org.activiti.bpmn.model.EndEvent) Process(org.activiti.bpmn.model.Process) ObjectNotFoundException(org.finra.herd.model.ObjectNotFoundException) AlreadyExistsException(org.finra.herd.model.AlreadyExistsException) BpmnModel(org.activiti.bpmn.model.BpmnModel) Test(org.junit.Test)

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