Search in sources :

Example 26 with S3PropertiesLocation

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

the class JdbcServiceTest method testExecuteJdbcParamValidationS3PropertiesLocationBucketNameBlank.

/**
 * When S3 properties location is specified, bucket name must not be a blank string.
 */
@Test
public void testExecuteJdbcParamValidationS3PropertiesLocationBucketNameBlank() {
    JdbcExecutionRequest jdbcExecutionRequest = jdbcServiceTestHelper.createDefaultUpdateJdbcExecutionRequest();
    jdbcExecutionRequest.setS3PropertiesLocation(new S3PropertiesLocation(BLANK_TEXT, "test_key"));
    try {
        jdbcService.executeJdbc(jdbcExecutionRequest);
        Assert.fail("expected an IllegalArgumentException, but no exception was thrown");
    } catch (Exception e) {
        Assert.assertEquals("thrown exception type", IllegalArgumentException.class, e.getClass());
        Assert.assertEquals("thrown exception message", "S3 properties location bucket name is required", e.getMessage());
    }
}
Also used : S3PropertiesLocation(org.finra.herd.model.api.xml.S3PropertiesLocation) JdbcExecutionRequest(org.finra.herd.model.api.xml.JdbcExecutionRequest) Test(org.junit.Test)

Example 27 with S3PropertiesLocation

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

the class JobRestControllerTest method testSignalJob.

@Test
public void testSignalJob() throws Exception {
    // Create a job signal request.
    JobSignalRequest jobSignalRequest = new JobSignalRequest(JOB_ID, JOB_RECEIVE_TASK_ID, Arrays.asList(new Parameter(ATTRIBUTE_NAME_1_MIXED_CASE, ATTRIBUTE_VALUE_1)), new S3PropertiesLocation(S3_BUCKET_NAME, S3_KEY));
    // Create a job.
    Job job = new Job();
    job.setId(JOB_ID);
    // Mock the external calls.
    when(jobService.signalJob(jobSignalRequest)).thenReturn(job);
    // Call the method under test.
    Job result = jobRestController.signalJob(jobSignalRequest);
    // Verify the external calls.
    verify(jobService).signalJob(jobSignalRequest);
    verifyNoMoreInteractionsHelper();
    // Validate the results.
    assertEquals(job, result);
}
Also used : S3PropertiesLocation(org.finra.herd.model.api.xml.S3PropertiesLocation) JobSignalRequest(org.finra.herd.model.api.xml.JobSignalRequest) Parameter(org.finra.herd.model.api.xml.Parameter) Job(org.finra.herd.model.api.xml.Job) Test(org.junit.Test)

Example 28 with S3PropertiesLocation

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

the class S3PropertiesLocationHelperTest method testValidateNoErrorsAndTrimmed.

/**
 * validate() throws no errors when {@link S3PropertiesLocation} is given with both bucket name and key as a non-blank string.
 * The given object's bucket name and key should be trimmed as a side effect.
 */
@Test
public void testValidateNoErrorsAndTrimmed() {
    S3PropertiesLocation s3PropertiesLocation = getS3PropertiesLocation();
    String expectedBucketName = s3PropertiesLocation.getBucketName();
    String expectedKey = s3PropertiesLocation.getKey();
    s3PropertiesLocation.setBucketName(BLANK_TEXT + s3PropertiesLocation.getBucketName() + BLANK_TEXT);
    s3PropertiesLocation.setKey(BLANK_TEXT + s3PropertiesLocation.getKey() + BLANK_TEXT);
    try {
        s3PropertiesLocationHelper.validate(s3PropertiesLocation);
        Assert.assertEquals("s3PropertiesLocation bucketName", expectedBucketName, s3PropertiesLocation.getBucketName());
        Assert.assertEquals("s3PropertiesLocation key", expectedKey, s3PropertiesLocation.getKey());
    } catch (Exception e) {
        Assert.fail("unexpected exception was thrown. " + e);
    }
}
Also used : S3PropertiesLocation(org.finra.herd.model.api.xml.S3PropertiesLocation) Test(org.junit.Test) AbstractServiceTest(org.finra.herd.service.AbstractServiceTest)

Example 29 with S3PropertiesLocation

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

the class JobServiceImpl method getParameters.

/**
 * Gets the parameters from the given {@link JobDefinitionEntity} and {@link JobCreateRequest} and their respective S3 locations provided. If there are any
 * parameter conflicts, this method will automatically merge them by a predefined precedence, from least to greatest: <ol> <li>Job Definition S3
 * location</li> <li>Job Definition parameters</li> <li>Job Create Request S3 location</li> <li>Job Create Request parameters</li> </ol>
 *
 * @param jobDefinitionEntity {@link JobDefinitionEntity}
 * @param jobCreateRequest {@link JobCreateRequest}
 *
 * @return merged parameters
 */
private Map<String, Object> getParameters(JobDefinitionEntity jobDefinitionEntity, JobCreateRequest jobCreateRequest) {
    Map<String, Object> mergedParameters = new HashMap<>();
    // Get parameters from job definition S3 location
    putParametersFromS3(jobDefinitionEntity.getS3BucketName(), jobDefinitionEntity.getS3ObjectKey(), mergedParameters);
    // Get parameters from job definition parameters
    for (JobDefinitionParameterEntity definitionParam : jobDefinitionEntity.getParameters()) {
        mergedParameters.put(definitionParam.getName(), definitionParam.getValue());
    }
    // Get parameters from job create request S3 location
    S3PropertiesLocation s3PropertiesLocation = jobCreateRequest.getS3PropertiesLocation();
    if (s3PropertiesLocation != null) {
        putParametersFromS3(s3PropertiesLocation.getBucketName(), s3PropertiesLocation.getKey(), mergedParameters);
    }
    // Get parameters from job create request parameters
    mergedParameters.putAll(toMap(jobCreateRequest.getParameters()));
    return mergedParameters;
}
Also used : S3PropertiesLocation(org.finra.herd.model.api.xml.S3PropertiesLocation) HashMap(java.util.HashMap) JobDefinitionParameterEntity(org.finra.herd.model.jpa.JobDefinitionParameterEntity)

Example 30 with S3PropertiesLocation

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

the class JobServiceImpl method getParameters.

/**
 * Gets the parameters from the given {@link JobSignalRequest} and the S3 location provided.
 *
 * @param jobSignalRequest {@link JobSignalRequest}
 *
 * @return parameters
 */
private Map<String, Object> getParameters(JobSignalRequest jobSignalRequest) {
    Map<String, Object> signalParameters = new HashMap<>();
    // Get parameters from S3
    S3PropertiesLocation s3PropertiesLocation = jobSignalRequest.getS3PropertiesLocation();
    if (s3PropertiesLocation != null) {
        putParametersFromS3(s3PropertiesLocation.getBucketName(), s3PropertiesLocation.getKey(), signalParameters);
    }
    // Get parameters from request
    signalParameters.putAll(toMap(jobSignalRequest.getParameters()));
    return signalParameters;
}
Also used : S3PropertiesLocation(org.finra.herd.model.api.xml.S3PropertiesLocation) HashMap(java.util.HashMap)

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