Search in sources :

Example 6 with StageSchema

use of io.cdap.cdap.etl.proto.v2.validation.StageSchema 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 StageSchema

use of io.cdap.cdap.etl.proto.v2.validation.StageSchema in project cdap by caskdata.

the class ValidationUtilsTest method testValidateException.

@Test
public void testValidateException() {
    Schema testSchema = Schema.recordOf("a", Schema.Field.of("a", Schema.of(Schema.Type.STRING)));
    StageSchema testStageSchema = new StageSchema("source", testSchema);
    ETLStage etlStage = new ETLStage("source", MockSource.getPlugin(null));
    StageValidationRequest validationRequest = new StageValidationRequest(etlStage, Collections.singletonList(testStageSchema), false);
    StageValidationResponse stageValidationResponse = ValidationUtils.validate(NamespaceId.DEFAULT.getNamespace(), validationRequest, getPluginConfigurer(MockSource.PLUGIN_CLASS), properties -> properties, MOCK_FEATURE_FLAGS_PROVIDER);
    Assert.assertEquals(1, stageValidationResponse.getFailures().size());
}
Also used : StageSchema(io.cdap.cdap.etl.proto.v2.validation.StageSchema) StageValidationRequest(io.cdap.cdap.etl.proto.v2.validation.StageValidationRequest) 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) StageValidationResponse(io.cdap.cdap.etl.proto.v2.validation.StageValidationResponse) Test(org.junit.Test)

Example 8 with StageSchema

use of io.cdap.cdap.etl.proto.v2.validation.StageSchema in project cdap by caskdata.

the class ValidationUtilsTest method testMacroSubstitution.

@Test
public void testMacroSubstitution() {
    Schema testSchema = Schema.recordOf("a", Schema.Field.of("a", Schema.of(Schema.Type.STRING)));
    StageSchema testStageSchema = new StageSchema("source", testSchema);
    ETLStage etlStage = new ETLStage("source", MockSource.getPlugin("@{tName}"));
    StageValidationRequest validationRequest = new StageValidationRequest(etlStage, Collections.singletonList(testStageSchema), false);
    String testtable = "testtable";
    StageValidationResponse stageValidationResponse = ValidationUtils.validate(NamespaceId.DEFAULT.getNamespace(), validationRequest, getPluginConfigurer(MockSource.PLUGIN_CLASS), properties -> {
        Map<String, String> propertiesCopy = new HashMap<>(properties);
        if (propertiesCopy.getOrDefault("tableName", "").equals("@{tName}")) {
            propertiesCopy.put("tableName", testtable);
        }
        return propertiesCopy;
    }, MOCK_FEATURE_FLAGS_PROVIDER);
    Assert.assertTrue(stageValidationResponse.getFailures().isEmpty());
    Assert.assertEquals(testtable, stageValidationResponse.getSpec().getPlugin().getProperties().get("tableName"));
}
Also used : StageSchema(io.cdap.cdap.etl.proto.v2.validation.StageSchema) StageValidationRequest(io.cdap.cdap.etl.proto.v2.validation.StageValidationRequest) ETLStage(io.cdap.cdap.etl.proto.v2.ETLStage) HashMap(java.util.HashMap) StageSchema(io.cdap.cdap.etl.proto.v2.validation.StageSchema) Schema(io.cdap.cdap.api.data.schema.Schema) StageValidationResponse(io.cdap.cdap.etl.proto.v2.validation.StageValidationResponse) Test(org.junit.Test)

Example 9 with StageSchema

use of io.cdap.cdap.etl.proto.v2.validation.StageSchema in project cdap by caskdata.

the class DataPipelineServiceTest method testSecureMacroSubstitution.

@Test
public void testSecureMacroSubstitution() throws Exception {
    // StringValueFilterTransform checks that the field exists in the input schema
    String stageName = "tx";
    Map<String, String> properties = new HashMap<>();
    properties.put("field", "${secure(field)}");
    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)));
    // this call happens when no value for 'field' is in the secure store, which should not result in
    // any failures because the macro could not be enabled so the check is skipped
    StageValidationRequest requestBody = new StageValidationRequest(stage, Collections.singletonList(new StageSchema("input", inputSchema)), false);
    StageValidationResponse actual = sendRequest(requestBody);
    Assert.assertTrue(actual.getFailures().isEmpty());
    // now set the value of 'field' to be 'z', which is not in the input schema
    // this call should result in a failure
    getSecureStoreManager().put("default", "field", "z", "desc", Collections.emptyMap());
    actual = sendRequest(requestBody);
    Assert.assertNull(actual.getSpec());
    Assert.assertEquals(1, actual.getFailures().size());
    ValidationFailure failure = actual.getFailures().iterator().next();
    // the stage will add 2 causes for invalid input field failure. One is related to input field and the other is
    // related to config property.
    Assert.assertEquals(1, failure.getCauses().size());
    Assert.assertEquals("field", failure.getCauses().get(0).getAttribute(CauseAttributes.STAGE_CONFIG));
    Assert.assertEquals(stageName, failure.getCauses().get(0).getAttribute(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 10 with StageSchema

use of io.cdap.cdap.etl.proto.v2.validation.StageSchema in project cdap by caskdata.

the class ValidationUtilsTest method testValidateNoException.

@Test
public void testValidateNoException() {
    Schema testSchema = Schema.recordOf("a", Schema.Field.of("a", Schema.of(Schema.Type.STRING)));
    StageSchema testStageSchema = new StageSchema("source", testSchema);
    ETLStage etlStage = new ETLStage("source", MockSource.getPlugin("testtable"));
    StageValidationRequest validationRequest = new StageValidationRequest(etlStage, Collections.singletonList(testStageSchema), false);
    StageValidationResponse stageValidationResponse = ValidationUtils.validate(NamespaceId.DEFAULT.getNamespace(), validationRequest, getPluginConfigurer(MockSource.PLUGIN_CLASS), properties -> properties, MOCK_FEATURE_FLAGS_PROVIDER);
    Assert.assertTrue(stageValidationResponse.getFailures().isEmpty());
}
Also used : StageSchema(io.cdap.cdap.etl.proto.v2.validation.StageSchema) StageValidationRequest(io.cdap.cdap.etl.proto.v2.validation.StageValidationRequest) 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) StageValidationResponse(io.cdap.cdap.etl.proto.v2.validation.StageValidationResponse) Test(org.junit.Test)

Aggregations

ETLStage (io.cdap.cdap.etl.proto.v2.ETLStage)10 StageSchema (io.cdap.cdap.etl.proto.v2.validation.StageSchema)10 StageValidationResponse (io.cdap.cdap.etl.proto.v2.validation.StageValidationResponse)10 StageValidationRequest (io.cdap.cdap.etl.proto.v2.validation.StageValidationRequest)9 Test (org.junit.Test)9 Schema (io.cdap.cdap.api.data.schema.Schema)8 ValidationFailure (io.cdap.cdap.etl.api.validation.ValidationFailure)5 ETLPlugin (io.cdap.cdap.etl.proto.v2.ETLPlugin)5 HashMap (java.util.HashMap)5 ValidationException (io.cdap.cdap.etl.api.validation.ValidationException)1 BatchPipelineSpec (io.cdap.cdap.etl.batch.BatchPipelineSpec)1 BatchPipelineSpecGenerator (io.cdap.cdap.etl.batch.BatchPipelineSpecGenerator)1 DefaultPipelineConfigurer (io.cdap.cdap.etl.common.DefaultPipelineConfigurer)1 DefaultStageConfigurer (io.cdap.cdap.etl.common.DefaultStageConfigurer)1 ETLBatchConfig (io.cdap.cdap.etl.proto.v2.ETLBatchConfig)1 StageSpec (io.cdap.cdap.etl.proto.v2.spec.StageSpec)1 ValidatingConfigurer (io.cdap.cdap.etl.validation.ValidatingConfigurer)1