Search in sources :

Example 6 with ValidationException

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

the class ConnectionHandler method testLocally.

private void testLocally(String namespace, ConnectionCreationRequest creationRequest, HttpServiceResponder responder) throws IOException {
    ServicePluginConfigurer pluginConfigurer = getContext().createServicePluginConfigurer(namespace);
    ConnectorConfigurer connectorConfigurer = new DefaultConnectorConfigurer(pluginConfigurer);
    SimpleFailureCollector failureCollector = new SimpleFailureCollector();
    ConnectorContext connectorContext = new DefaultConnectorContext(failureCollector, pluginConfigurer);
    TrackedPluginSelector pluginSelector = new TrackedPluginSelector(new ArtifactSelectorProvider().getPluginSelector(creationRequest.getPlugin().getArtifact()));
    try (Connector connector = getConnector(pluginConfigurer, creationRequest.getPlugin(), namespace, pluginSelector)) {
        connector.configure(connectorConfigurer);
        try {
            connector.test(connectorContext);
            failureCollector.getOrThrowException();
        } catch (ValidationException e) {
            responder.sendJson(e.getFailures());
            return;
        }
    }
    responder.sendStatus(HttpURLConnection.HTTP_OK);
}
Also used : Connector(io.cdap.cdap.etl.api.connector.Connector) SimpleFailureCollector(io.cdap.cdap.etl.proto.validation.SimpleFailureCollector) ArtifactSelectorProvider(io.cdap.cdap.etl.common.ArtifactSelectorProvider) DefaultConnectorContext(io.cdap.cdap.datapipeline.connection.DefaultConnectorContext) TrackedPluginSelector(io.cdap.cdap.etl.spec.TrackedPluginSelector) ValidationException(io.cdap.cdap.etl.api.validation.ValidationException) ConnectorContext(io.cdap.cdap.etl.api.connector.ConnectorContext) DefaultConnectorContext(io.cdap.cdap.datapipeline.connection.DefaultConnectorContext) DefaultConnectorConfigurer(io.cdap.cdap.datapipeline.connection.DefaultConnectorConfigurer) DefaultConnectorConfigurer(io.cdap.cdap.datapipeline.connection.DefaultConnectorConfigurer) ConnectorConfigurer(io.cdap.cdap.etl.api.connector.ConnectorConfigurer) ServicePluginConfigurer(io.cdap.cdap.api.service.http.ServicePluginConfigurer)

Example 7 with ValidationException

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

the class DataStreamsPipelineSpecGenerator method generateSpec.

@Override
public DataStreamsPipelineSpec generateSpec(DataStreamsConfig config) throws ValidationException {
    long batchIntervalMillis;
    try {
        batchIntervalMillis = TimeParser.parseDuration(config.getBatchInterval());
    } catch (Exception e) {
        throw new IllegalArgumentException(String.format("Unable to parse batchInterval '%s'", config.getBatchInterval()));
    }
    String pipelineId = UUID.randomUUID().toString();
    if (runtimeConfigurer != null && runtimeConfigurer.getDeployedApplicationSpec() != null) {
        SparkSpecification sparkSpec = runtimeConfigurer.getDeployedApplicationSpec().getSpark().get(DataStreamsSparkLauncher.NAME);
        DataStreamsPipelineSpec spec = GSON.fromJson(sparkSpec.getProperty(Constants.PIPELINEID), DataStreamsPipelineSpec.class);
        pipelineId = spec.getPipelineId();
    }
    DataStreamsPipelineSpec.Builder specBuilder = DataStreamsPipelineSpec.builder(batchIntervalMillis, pipelineId).setExtraJavaOpts(config.getExtraJavaOpts()).setStopGracefully(config.getStopGracefully()).setIsUnitTest(config.isUnitTest()).setCheckpointsDisabled(config.checkpointsDisabled());
    String checkpointDir = config.getCheckpointDir();
    if (!config.checkpointsDisabled() && checkpointDir != null) {
        try {
            new Path(checkpointDir);
        } catch (Exception e) {
            throw new IllegalArgumentException(String.format("Checkpoint directory '%s' is not a valid Path: %s", checkpointDir, e.getMessage()), e);
        }
        specBuilder.setCheckpointDirectory(checkpointDir);
    }
    configureStages(config, specBuilder);
    return specBuilder.build();
}
Also used : Path(org.apache.hadoop.fs.Path) SparkSpecification(io.cdap.cdap.api.spark.SparkSpecification) ValidationException(io.cdap.cdap.etl.api.validation.ValidationException)

Example 8 with ValidationException

use of io.cdap.cdap.etl.api.validation.ValidationException in project hydrator-plugins by cdapio.

the class ValueMapperTest method testMappingValidation.

@Test
public void testMappingValidation() throws Exception {
    Schema inputSchema = Schema.recordOf("sourceRecord", Schema.Field.of(ID, Schema.of(Schema.Type.STRING)), Schema.Field.of(NAME, Schema.of(Schema.Type.STRING)), Schema.Field.of(SALARY, Schema.of(Schema.Type.STRING)), Schema.Field.of(DESIGNATIONID, Schema.of(Schema.Type.STRING)));
    ValueMapper.Config config = new ValueMapper.Config("designationid:designation_lookup_table", "designationid:DEFAULTID");
    MockPipelineConfigurer configurer = new MockPipelineConfigurer(inputSchema);
    try {
        new ValueMapper(config).configurePipeline(configurer);
        Assert.fail();
    } catch (ValidationException e) {
        Assert.assertEquals(1, e.getFailures().size());
        Assert.assertEquals(1, e.getFailures().get(0).getCauses().size());
        Cause expectedCause = new Cause();
        expectedCause.addAttribute(STAGE, MOCK_STAGE);
        expectedCause.addAttribute(CauseAttributes.STAGE_CONFIG, ValueMapper.Config.MAPPING);
        expectedCause.addAttribute(CauseAttributes.CONFIG_ELEMENT, "designationid:designation_lookup_table");
        Assert.assertEquals(expectedCause, e.getFailures().get(0).getCauses().get(0));
    }
}
Also used : ValidationException(io.cdap.cdap.etl.api.validation.ValidationException) MockPipelineConfigurer(io.cdap.cdap.etl.mock.common.MockPipelineConfigurer) ETLBatchConfig(io.cdap.cdap.etl.proto.v2.ETLBatchConfig) Schema(io.cdap.cdap.api.data.schema.Schema) Cause(io.cdap.cdap.etl.api.validation.ValidationFailure.Cause) Test(org.junit.Test)

Example 9 with ValidationException

use of io.cdap.cdap.etl.api.validation.ValidationException in project hydrator-plugins by cdapio.

the class NormalizeTest method testEmptyFieldMapping.

@Test
public void testEmptyFieldMapping() throws Exception {
    Normalize.NormalizeConfig config = new Normalize.NormalizeConfig(null, validFieldNormalizing, OUTPUT_SCHEMA.toString());
    MockPipelineConfigurer configurer = new MockPipelineConfigurer(INPUT_SCHEMA);
    try {
        new Normalize(config).configurePipeline(configurer);
        Assert.fail();
    } catch (ValidationException e) {
        Assert.assertEquals(1, e.getFailures().size());
        Assert.assertEquals(1, e.getFailures().get(0).getCauses().size());
        ValidationFailure.Cause expectedCause = new ValidationFailure.Cause();
        expectedCause.addAttribute(STAGE, MOCK_STAGE);
        expectedCause.addAttribute(CauseAttributes.STAGE_CONFIG, Normalize.NormalizeConfig.FIELD_MAPPING);
        Assert.assertEquals(expectedCause, e.getFailures().get(0).getCauses().get(0));
    }
}
Also used : ValidationException(io.cdap.cdap.etl.api.validation.ValidationException) MockPipelineConfigurer(io.cdap.cdap.etl.mock.common.MockPipelineConfigurer) ValidationFailure(io.cdap.cdap.etl.api.validation.ValidationFailure) Test(org.junit.Test)

Example 10 with ValidationException

use of io.cdap.cdap.etl.api.validation.ValidationException in project hydrator-plugins by cdapio.

the class NormalizeTest method testEmptyFieldNormalizing.

@Test
public void testEmptyFieldNormalizing() throws Exception {
    Normalize.NormalizeConfig config = new Normalize.NormalizeConfig(validFieldMapping, null, OUTPUT_SCHEMA.toString());
    MockPipelineConfigurer configurer = new MockPipelineConfigurer(INPUT_SCHEMA);
    try {
        new Normalize(config).configurePipeline(configurer);
        Assert.fail();
    } catch (ValidationException e) {
        Assert.assertEquals(1, e.getFailures().size());
        Assert.assertEquals(1, e.getFailures().get(0).getCauses().size());
        ValidationFailure.Cause expectedCause = new ValidationFailure.Cause();
        expectedCause.addAttribute(STAGE, MOCK_STAGE);
        expectedCause.addAttribute(CauseAttributes.STAGE_CONFIG, Normalize.NormalizeConfig.FIELD_NORMALIZING);
        Assert.assertEquals(expectedCause, e.getFailures().get(0).getCauses().get(0));
    }
}
Also used : ValidationException(io.cdap.cdap.etl.api.validation.ValidationException) MockPipelineConfigurer(io.cdap.cdap.etl.mock.common.MockPipelineConfigurer) ValidationFailure(io.cdap.cdap.etl.api.validation.ValidationFailure) Test(org.junit.Test)

Aggregations

ValidationException (io.cdap.cdap.etl.api.validation.ValidationException)49 Test (org.junit.Test)30 Schema (io.cdap.cdap.api.data.schema.Schema)18 Cause (io.cdap.cdap.etl.api.validation.ValidationFailure.Cause)17 MockPipelineConfigurer (io.cdap.cdap.etl.mock.common.MockPipelineConfigurer)17 FailureCollector (io.cdap.cdap.etl.api.FailureCollector)10 ValidationFailure (io.cdap.cdap.etl.api.validation.ValidationFailure)10 MockFailureCollector (io.cdap.cdap.etl.mock.validation.MockFailureCollector)9 ETLBatchConfig (io.cdap.cdap.etl.proto.v2.ETLBatchConfig)8 ArtifactSelectorProvider (io.cdap.cdap.etl.common.ArtifactSelectorProvider)6 StageSpec (io.cdap.cdap.etl.proto.v2.spec.StageSpec)6 HashMap (java.util.HashMap)6 StructuredRecord (io.cdap.cdap.api.data.format.StructuredRecord)5 ConnectorContext (io.cdap.cdap.etl.api.connector.ConnectorContext)5 AutoJoinerContext (io.cdap.cdap.etl.api.join.AutoJoinerContext)5 ServicePluginConfigurer (io.cdap.cdap.api.service.http.ServicePluginConfigurer)4 DefaultConnectorConfigurer (io.cdap.cdap.datapipeline.connection.DefaultConnectorConfigurer)4 DefaultConnectorContext (io.cdap.cdap.datapipeline.connection.DefaultConnectorContext)4 TransformContext (io.cdap.cdap.etl.api.TransformContext)4 Connector (io.cdap.cdap.etl.api.connector.Connector)4