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