Search in sources :

Example 6 with JobCreateRequest

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

the class JobServiceTest method testCreateJobParameterNameEmpty.

@Test(expected = IllegalArgumentException.class)
public void testCreateJobParameterNameEmpty() throws Exception {
    // Create a job create request using hard coded test values.
    JobCreateRequest jobCreateRequest = jobServiceTestHelper.createJobCreateRequest(TEST_ACTIVITI_NAMESPACE_CD, TEST_ACTIVITI_JOB_NAME);
    // Add a parameter with an empty name.
    Parameter parameter = new Parameter(" ", ATTRIBUTE_VALUE_1);
    jobCreateRequest.getParameters().add(parameter);
    // Try to create a job.
    jobService.createAndStartJob(jobCreateRequest);
}
Also used : Parameter(org.finra.herd.model.api.xml.Parameter) JobCreateRequest(org.finra.herd.model.api.xml.JobCreateRequest) Test(org.junit.Test)

Example 7 with JobCreateRequest

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

the class ExecuteJdbcTest method testExecuteJdbcWithReceiveTask.

/**
 * Asserts that the task executes asynchronously when receiveTaskId is specified.
 * <p/>
 * This is a very special test case which involves multithreading and transactions, therefore we cannot use the standard test methods we have. The
 * transaction MUST BE DISABLED for this test to work correctly - since we have 2 threads which both access the database, if we run transactionally, the
 * threads cannot share information.
 * <p/>
 * TODO this test could be made generic once we have async support for other tasks.
 */
@Test
@Transactional(propagation = Propagation.NOT_SUPPORTED)
public void testExecuteJdbcWithReceiveTask() throws Exception {
    // Create and persist a test job definition.
    executeJdbcTestHelper.prepareHerdDatabaseForExecuteJdbcWithReceiveTaskTest(TEST_ACTIVITI_NAMESPACE_CD, TEST_ACTIVITI_JOB_NAME, "classpath:org/finra/herd/service/testActivitiWorkflowExecuteJdbcTaskWithReceiveTask.bpmn20.xml");
    try {
        // Create a JDBC execution request.
        JdbcExecutionRequest jdbcExecutionRequest = jdbcServiceTestHelper.createDefaultUpdateJdbcExecutionRequest();
        // Create and initialize a list of parameters.
        List<Parameter> parameters = new ArrayList<>();
        parameters.add(new Parameter("contentType", "xml"));
        parameters.add(new Parameter("jdbcExecutionRequest", xmlHelper.objectToXml(jdbcExecutionRequest)));
        // Get a job create request.
        JobCreateRequest jobCreateRequest = jobServiceTestHelper.createJobCreateRequest(TEST_ACTIVITI_NAMESPACE_CD, TEST_ACTIVITI_JOB_NAME);
        jobCreateRequest.setParameters(parameters);
        // Start the job.
        Job jobStartResponse = jobService.createAndStartJob(jobCreateRequest);
        // Wait for the process to finish
        waitUntilAllProcessCompleted();
        // Validate that the job is completed.
        Job jobGetResponse = jobService.getJob(jobStartResponse.getId(), true);
        assertEquals(JobStatusEnum.COMPLETED, jobGetResponse.getStatus());
        // Validate the task status.
        assertTrue(jobGetResponse.getParameters().contains(new Parameter("service_taskStatus", "SUCCESS")));
        // Validate the JDBC execution response.
        JdbcExecutionResponse expectedJdbcExecutionResponse = new JdbcExecutionResponse();
        JdbcStatement originalJdbcStatement = jdbcExecutionRequest.getStatements().get(0);
        JdbcStatement expectedJdbcStatement = new JdbcStatement();
        expectedJdbcStatement.setType(originalJdbcStatement.getType());
        expectedJdbcStatement.setSql(originalJdbcStatement.getSql());
        expectedJdbcStatement.setStatus(JdbcStatementStatus.SUCCESS);
        expectedJdbcStatement.setResult("1");
        expectedJdbcExecutionResponse.setStatements(Arrays.asList(expectedJdbcStatement));
        Parameter expectedJdbcExecutionResponseParameter = new Parameter("service_jsonResponse", jsonHelper.objectToJson(expectedJdbcExecutionResponse));
        assertTrue(jobGetResponse.getParameters().contains(expectedJdbcExecutionResponseParameter));
    } finally {
        // Clean up the Herd database.
        executeJdbcTestHelper.cleanUpHerdDatabaseAfterExecuteJdbcWithReceiveTaskTest(TEST_ACTIVITI_NAMESPACE_CD, TEST_ACTIVITI_JOB_NAME);
        // Clean up the Activiti.
        deleteActivitiDeployments();
    }
}
Also used : JdbcStatement(org.finra.herd.model.api.xml.JdbcStatement) ArrayList(java.util.ArrayList) Parameter(org.finra.herd.model.api.xml.Parameter) Job(org.finra.herd.model.api.xml.Job) JdbcExecutionRequest(org.finra.herd.model.api.xml.JdbcExecutionRequest) JdbcExecutionResponse(org.finra.herd.model.api.xml.JdbcExecutionResponse) JobCreateRequest(org.finra.herd.model.api.xml.JobCreateRequest) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 8 with JobCreateRequest

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

the class JobServiceTest method testCreateJobDuplicateParameterName.

@Test(expected = IllegalArgumentException.class)
public void testCreateJobDuplicateParameterName() throws Exception {
    // Create a job create request using hard coded test values.
    JobCreateRequest jobCreateRequest = jobServiceTestHelper.createJobCreateRequest(TEST_ACTIVITI_NAMESPACE_CD, TEST_ACTIVITI_JOB_NAME);
    // Add a duplicate parameter.
    Parameter parameter = new Parameter();
    parameter.setName(addWhitespace(jobCreateRequest.getParameters().get(0).getName().toUpperCase()));
    parameter.setValue(jobCreateRequest.getParameters().get(0).getValue());
    jobCreateRequest.getParameters().add(parameter);
    // Try to create a job.
    jobService.createAndStartJob(jobCreateRequest);
}
Also used : Parameter(org.finra.herd.model.api.xml.Parameter) JobCreateRequest(org.finra.herd.model.api.xml.JobCreateRequest) Test(org.junit.Test)

Example 9 with JobCreateRequest

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

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

the class BusinessObjectDataNotificationJobActionServiceImpl method performNotificationAction.

@Override
public Object performNotificationAction(NotificationEventParamsDto notificationEventParams) throws Exception {
    if (notificationEventParams instanceof BusinessObjectDataNotificationEventParamsDto) {
        BusinessObjectDataNotificationEventParamsDto businessObjectDataNotificationEventParams = (BusinessObjectDataNotificationEventParamsDto) notificationEventParams;
        JobCreateRequest request = new JobCreateRequest();
        JobDefinitionEntity jobDefinitionEntity = businessObjectDataNotificationEventParams.getNotificationJobAction().getJobDefinition();
        request.setNamespace(jobDefinitionEntity.getNamespace().getCode());
        request.setJobName(jobDefinitionEntity.getName());
        request.setParameters(buildJobParameters(businessObjectDataNotificationEventParams));
        /*
             * Log enough information so we can trace back what notification registration triggered what workflow.
             * This also allows us to reproduce the workflow execution if needed by logging the entire jobCreateRequest in JSON format.
             */
        if (LOGGER.isInfoEnabled()) {
            BusinessObjectDataNotificationRegistrationEntity businessObjectDataNotificationRegistration = businessObjectDataNotificationEventParams.getBusinessObjectDataNotificationRegistration();
            LOGGER.info("Starting a job due to a notification. notificationRegistrationKey={} jobCreateRequest={}", jsonHelper.objectToJson(notificationRegistrationHelper.getNotificationRegistrationKey(businessObjectDataNotificationRegistration)), jsonHelper.objectToJson(request));
        }
        return jobService.createAndStartJob(request);
    } else {
        throw new IllegalStateException("Notification event parameters DTO passed to the method must be an instance of BusinessObjectDataNotificationEventParamsDto.");
    }
}
Also used : JobDefinitionEntity(org.finra.herd.model.jpa.JobDefinitionEntity) BusinessObjectDataNotificationEventParamsDto(org.finra.herd.model.dto.BusinessObjectDataNotificationEventParamsDto) BusinessObjectDataNotificationRegistrationEntity(org.finra.herd.model.jpa.BusinessObjectDataNotificationRegistrationEntity) JobCreateRequest(org.finra.herd.model.api.xml.JobCreateRequest)

Aggregations

JobCreateRequest (org.finra.herd.model.api.xml.JobCreateRequest)11 Test (org.junit.Test)7 Parameter (org.finra.herd.model.api.xml.Parameter)6 Job (org.finra.herd.model.api.xml.Job)5 JobDefinitionCreateRequest (org.finra.herd.model.api.xml.JobDefinitionCreateRequest)4 JobDefinitionEntity (org.finra.herd.model.jpa.JobDefinitionEntity)3 ArrayList (java.util.ArrayList)2 JdbcExecutionRequest (org.finra.herd.model.api.xml.JdbcExecutionRequest)1 JdbcExecutionResponse (org.finra.herd.model.api.xml.JdbcExecutionResponse)1 JdbcStatement (org.finra.herd.model.api.xml.JdbcStatement)1 JobDefinition (org.finra.herd.model.api.xml.JobDefinition)1 BusinessObjectDataNotificationEventParamsDto (org.finra.herd.model.dto.BusinessObjectDataNotificationEventParamsDto)1 StorageUnitNotificationEventParamsDto (org.finra.herd.model.dto.StorageUnitNotificationEventParamsDto)1 BusinessObjectDataNotificationRegistrationEntity (org.finra.herd.model.jpa.BusinessObjectDataNotificationRegistrationEntity)1 StorageUnitNotificationRegistrationEntity (org.finra.herd.model.jpa.StorageUnitNotificationRegistrationEntity)1 Transactional (org.springframework.transaction.annotation.Transactional)1