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;
}
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);
}
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;
}
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());
}
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());
}
}
Aggregations