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