Search in sources :

Example 6 with ValidationFailure

use of io.cdap.cdap.etl.api.validation.ValidationFailure in project cdap by caskdata.

the class DataPipelineServiceTest method testValidateMultiInputInvalidInputField.

@Test
public void testValidateMultiInputInvalidInputField() throws Exception {
    // StringValueFilterTransform will be configured to filter records where field x has value 'y'
    // it will be invalid because the type of field x will be an int instead of the required string
    String stageName = "tx";
    Map<String, String> properties = new HashMap<>();
    properties.put("field", "x");
    properties.put("value", "y");
    ETLStage stage = new ETLStage(stageName, new ETLPlugin(StringValueFilterTransform.NAME, Transform.PLUGIN_TYPE, properties));
    Schema inputSchema = Schema.recordOf("x", Schema.Field.of("x", Schema.of(Schema.Type.INT)));
    StageValidationRequest requestBody = new StageValidationRequest(stage, ImmutableList.of(new StageSchema("input1", inputSchema), new StageSchema("input2", inputSchema)), false);
    StageValidationResponse actual = sendRequest(requestBody);
    List<String> expectedInputs = ImmutableList.of("input1", "input2");
    Assert.assertNull(actual.getSpec());
    Assert.assertEquals(1, actual.getFailures().size());
    ValidationFailure failure = actual.getFailures().iterator().next();
    // the stage will add 3 causes. Two are related to input field and one is related to config property.
    Assert.assertEquals(3, failure.getCauses().size());
    Assert.assertEquals("field", failure.getCauses().get(0).getAttribute(CauseAttributes.STAGE_CONFIG));
    Assert.assertEquals(stageName, failure.getCauses().get(0).getAttribute(STAGE));
    Assert.assertEquals(stageName, failure.getCauses().get(1).getAttribute(STAGE));
    Assert.assertEquals(stageName, failure.getCauses().get(2).getAttribute(STAGE));
    Assert.assertTrue(expectedInputs.contains(failure.getCauses().get(1).getAttribute(CauseAttributes.INPUT_STAGE)));
    Assert.assertTrue(expectedInputs.contains(failure.getCauses().get(2).getAttribute(CauseAttributes.INPUT_STAGE)));
}
Also used : StageSchema(io.cdap.cdap.etl.proto.v2.validation.StageSchema) StageValidationRequest(io.cdap.cdap.etl.proto.v2.validation.StageValidationRequest) HashMap(java.util.HashMap) ETLStage(io.cdap.cdap.etl.proto.v2.ETLStage) StageSchema(io.cdap.cdap.etl.proto.v2.validation.StageSchema) Schema(io.cdap.cdap.api.data.schema.Schema) ETLPlugin(io.cdap.cdap.etl.proto.v2.ETLPlugin) StageValidationResponse(io.cdap.cdap.etl.proto.v2.validation.StageValidationResponse) ValidationFailure(io.cdap.cdap.etl.api.validation.ValidationFailure) Test(org.junit.Test)

Example 7 with ValidationFailure

use of io.cdap.cdap.etl.api.validation.ValidationFailure in project cdap by caskdata.

the class DefaultFailureCollector method addFailure.

@Override
public ValidationFailure addFailure(String message, @Nullable String correctiveAction) {
    ValidationFailure failure = new ValidationFailure(message, correctiveAction, stageName, inputSchemas);
    failures.add(failure);
    return failure;
}
Also used : ValidationFailure(io.cdap.cdap.etl.api.validation.ValidationFailure)

Example 8 with ValidationFailure

use of io.cdap.cdap.etl.api.validation.ValidationFailure in project cdap by caskdata.

the class LoggingFailureCollector method getOrThrowException.

@Override
public ValidationException getOrThrowException() throws ValidationException {
    ValidationException validationException;
    try {
        validationException = super.getOrThrowException();
    } catch (ValidationException e) {
        validationException = e;
    }
    if (validationException.getFailures().isEmpty()) {
        return validationException;
    }
    List<ValidationFailure> failures = validationException.getFailures();
    LOG.error("Encountered '{}' validation failures: {}{}", failures.size(), System.lineSeparator(), IntStream.range(0, failures.size()).mapToObj(index -> String.format("%d. %s", index + 1, failures.get(index).getFullMessage())).collect(Collectors.joining(System.lineSeparator())));
    throw validationException;
}
Also used : ValidationException(io.cdap.cdap.etl.api.validation.ValidationException) ValidationFailure(io.cdap.cdap.etl.api.validation.ValidationFailure)

Example 9 with ValidationFailure

use of io.cdap.cdap.etl.api.validation.ValidationFailure in project cdap by caskdata.

the class MockFailureCollector method addFailure.

@Override
public ValidationFailure addFailure(String message, @Nullable String correctiveAction) {
    ValidationFailure failure = new ValidationFailure(message, stageName, correctiveAction, Collections.emptyMap());
    failures.add(failure);
    return failure;
}
Also used : ValidationFailure(io.cdap.cdap.etl.api.validation.ValidationFailure)

Example 10 with ValidationFailure

use of io.cdap.cdap.etl.api.validation.ValidationFailure in project cdap by caskdata.

the class SimpleFailureCollector method addFailure.

@Override
public ValidationFailure addFailure(String message, @Nullable String correctiveAction) {
    ValidationFailure failure = new ValidationFailure(message, correctiveAction);
    failures.add(failure);
    return failure;
}
Also used : ValidationFailure(io.cdap.cdap.etl.api.validation.ValidationFailure)

Aggregations

ValidationFailure (io.cdap.cdap.etl.api.validation.ValidationFailure)13 ETLStage (io.cdap.cdap.etl.proto.v2.ETLStage)9 StageValidationRequest (io.cdap.cdap.etl.proto.v2.validation.StageValidationRequest)9 StageValidationResponse (io.cdap.cdap.etl.proto.v2.validation.StageValidationResponse)9 Test (org.junit.Test)9 ETLPlugin (io.cdap.cdap.etl.proto.v2.ETLPlugin)6 StageSchema (io.cdap.cdap.etl.proto.v2.validation.StageSchema)5 Schema (io.cdap.cdap.api.data.schema.Schema)4 HashMap (java.util.HashMap)4 ValidationException (io.cdap.cdap.etl.api.validation.ValidationException)1 ArtifactSelectorConfig (io.cdap.cdap.etl.proto.ArtifactSelectorConfig)1