Search in sources :

Example 1 with S3PropertiesLocation

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

the class JobDefinitionServiceImpl method createJobDefinitionFromEntity.

/**
 * Creates the job definition from the persisted entity.
 *
 * @param jobDefinitionEntity the newly persisted job definition entity.
 *
 * @return the job definition.
 */
private JobDefinition createJobDefinitionFromEntity(JobDefinitionEntity jobDefinitionEntity) throws IOException {
    // Create the business object definition information.
    JobDefinition jobDefinition = new JobDefinition();
    jobDefinition.setId(jobDefinitionEntity.getId());
    jobDefinition.setNamespace(jobDefinitionEntity.getNamespace().getCode());
    jobDefinition.setJobName(jobDefinitionEntity.getName());
    jobDefinition.setDescription(jobDefinitionEntity.getDescription());
    String s3BucketName = jobDefinitionEntity.getS3BucketName();
    String s3ObjectKey = jobDefinitionEntity.getS3ObjectKey();
    if (s3BucketName != null && s3ObjectKey != null) {
        S3PropertiesLocation s3PropertiesLocation = new S3PropertiesLocation();
        s3PropertiesLocation.setBucketName(s3BucketName);
        s3PropertiesLocation.setKey(s3ObjectKey);
        jobDefinition.setS3PropertiesLocation(s3PropertiesLocation);
    }
    // Retrieve Activiti XML from activiti.
    ProcessDefinition processDefinition = activitiRepositoryService.createProcessDefinitionQuery().processDefinitionId(jobDefinitionEntity.getActivitiId()).singleResult();
    InputStream xmlStream = activitiRepositoryService.getResourceAsStream(processDefinition.getDeploymentId(), processDefinition.getResourceName());
    jobDefinition.setActivitiJobXml(IOUtils.toString(xmlStream));
    // Add in the parameters.
    List<Parameter> parameters = new ArrayList<>();
    jobDefinition.setParameters(parameters);
    for (JobDefinitionParameterEntity parameterEntity : jobDefinitionEntity.getParameters()) {
        Parameter parameter = new Parameter(parameterEntity.getName(), parameterEntity.getValue());
        jobDefinitionHelper.maskPassword(parameter);
        parameters.add(parameter);
    }
    // Populate the "last updated by" user ID.
    jobDefinition.setLastUpdatedByUserId(jobDefinitionEntity.getUpdatedBy());
    return jobDefinition;
}
Also used : S3PropertiesLocation(org.finra.herd.model.api.xml.S3PropertiesLocation) InputStream(java.io.InputStream) JobDefinitionParameterEntity(org.finra.herd.model.jpa.JobDefinitionParameterEntity) ArrayList(java.util.ArrayList) Parameter(org.finra.herd.model.api.xml.Parameter) ProcessDefinition(org.activiti.engine.repository.ProcessDefinition) JobDefinition(org.finra.herd.model.api.xml.JobDefinition)

Example 2 with S3PropertiesLocation

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

the class JdbcServiceImpl method executeJdbcImpl.

/**
 * This implementation uses a {@link DriverManagerDataSource}. Uses existing Spring ORM transaction.
 *
 * @param jdbcExecutionRequest JDBC execution request
 *
 * @return {@link JdbcExecutionResponse}
 */
protected JdbcExecutionResponse executeJdbcImpl(JdbcExecutionRequest jdbcExecutionRequest) {
    validateJdbcExecutionRequest(jdbcExecutionRequest);
    // Optionally, get properties from S3
    S3PropertiesLocation s3PropertiesLocation = jdbcExecutionRequest.getS3PropertiesLocation();
    Map<String, Object> variables = getVariablesFromS3(s3PropertiesLocation);
    // Create data source
    DataSource dataSource = createDataSource(jdbcExecutionRequest.getConnection(), variables);
    // Execute the requested statements
    List<JdbcStatement> requestJdbcStatements = jdbcExecutionRequest.getStatements();
    List<JdbcStatement> responseJdbcStatements = executeStatements(requestJdbcStatements, dataSource, variables);
    // Create and return the execution result
    return new JdbcExecutionResponse(null, responseJdbcStatements);
}
Also used : S3PropertiesLocation(org.finra.herd.model.api.xml.S3PropertiesLocation) JdbcStatement(org.finra.herd.model.api.xml.JdbcStatement) JdbcExecutionResponse(org.finra.herd.model.api.xml.JdbcExecutionResponse) DataSource(javax.sql.DataSource) DriverManagerDataSource(org.springframework.jdbc.datasource.DriverManagerDataSource)

Example 3 with S3PropertiesLocation

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

the class JobDefinitionServiceTest method getS3PropertiesLocation.

private S3PropertiesLocation getS3PropertiesLocation() {
    S3PropertiesLocation s3PropertiesLocation = new S3PropertiesLocation();
    s3PropertiesLocation.setBucketName("testBucketName");
    s3PropertiesLocation.setKey("testKey");
    return s3PropertiesLocation;
}
Also used : S3PropertiesLocation(org.finra.herd.model.api.xml.S3PropertiesLocation)

Example 4 with S3PropertiesLocation

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

the class JobDefinitionServiceTest method testUpdateJobDefinitionWithS3Properties.

@Test
public void testUpdateJobDefinitionWithS3Properties() 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();
    // 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);
    updateRequest.setS3PropertiesLocation(s3PropertiesLocation);
    // 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(), s3PropertiesLocation, HerdDaoSecurityHelper.SYSTEM_USER), updatedJobDefinition);
    // Validate the updated job definition entity.
    Assert.assertEquals("updatedJobDefinitionEntity s3BucketName", s3PropertiesLocation.getBucketName(), updatedJobDefinitionEntity.getS3BucketName());
    Assert.assertEquals("updatedJobDefinitionEntity s3ObjectKey", s3PropertiesLocation.getKey(), 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 5 with S3PropertiesLocation

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

the class JobServiceTest method testCreateJobWithS3PropertiesWithInvalidUnicodeThrows.

/**
 * A Java Properties file is invalid when there is an invalid unicode reference. The service should throw a friendly error message when such case happens.
 *
 * @throws Exception
 */
@Test
public void testCreateJobWithS3PropertiesWithInvalidUnicodeThrows() throws Exception {
    Parameter jobCreateRequestS3Parameter = new Parameter("name2", "value2\\uxxxx");
    String s3BucketName = "s3BucketName";
    S3PropertiesLocation jobCreateRequestS3PropertiesLocation = getS3PropertiesLocation(s3BucketName, "jobCreationObjectKey", jobCreateRequestS3Parameter);
    String bucketName = jobCreateRequestS3PropertiesLocation.getBucketName();
    String key = jobCreateRequestS3PropertiesLocation.getKey();
    try {
        createJobWithParameters(null, null, jobCreateRequestS3PropertiesLocation, null);
        Assert.fail("expected IllegalArgumentException, but no exception was thrown");
    } catch (Exception e) {
        Assert.assertEquals("thrown exception type", IllegalArgumentException.class, e.getClass());
        Assert.assertEquals("thrown exception message", "The properties file in S3 bucket '" + bucketName + "' and key '" + key + "' is invalid.", e.getMessage());
    }
}
Also used : S3PropertiesLocation(org.finra.herd.model.api.xml.S3PropertiesLocation) Parameter(org.finra.herd.model.api.xml.Parameter) ObjectNotFoundException(org.finra.herd.model.ObjectNotFoundException) AccessDeniedException(org.springframework.security.access.AccessDeniedException) Test(org.junit.Test)

Aggregations

S3PropertiesLocation (org.finra.herd.model.api.xml.S3PropertiesLocation)33 Test (org.junit.Test)26 Parameter (org.finra.herd.model.api.xml.Parameter)13 Job (org.finra.herd.model.api.xml.Job)7 JdbcExecutionRequest (org.finra.herd.model.api.xml.JdbcExecutionRequest)6 ObjectNotFoundException (org.finra.herd.model.ObjectNotFoundException)5 AccessDeniedException (org.springframework.security.access.AccessDeniedException)5 JobDefinition (org.finra.herd.model.api.xml.JobDefinition)4 JdbcExecutionResponse (org.finra.herd.model.api.xml.JdbcExecutionResponse)3 JobDefinitionCreateRequest (org.finra.herd.model.api.xml.JobDefinitionCreateRequest)3 JobSignalRequest (org.finra.herd.model.api.xml.JobSignalRequest)3 JobDefinitionEntity (org.finra.herd.model.jpa.JobDefinitionEntity)3 AbstractServiceTest (org.finra.herd.service.AbstractServiceTest)3 HashMap (java.util.HashMap)2 JdbcStatement (org.finra.herd.model.api.xml.JdbcStatement)2 JobDefinitionUpdateRequest (org.finra.herd.model.api.xml.JobDefinitionUpdateRequest)2 JobDefinitionParameterEntity (org.finra.herd.model.jpa.JobDefinitionParameterEntity)2 InputStream (java.io.InputStream)1 ArrayList (java.util.ArrayList)1 DataSource (javax.sql.DataSource)1