use of io.cdap.cdap.etl.proto.connection.ConnectorDetail in project cdap by cdapio.
the class DataPipelineConnectionTest method getConnectionSpec.
private ConnectorDetail getConnectionSpec(String connection, String path, @Nullable String pluginName, @Nullable String pluginType) throws IOException {
String url = URLEncoder.encode(String.format("v1/contexts/%s/connections/%s/specification", NamespaceId.DEFAULT.getNamespace(), connection), StandardCharsets.UTF_8.name());
URL validatePipelineURL = serviceURI.resolve(url).toURL();
HttpRequest.Builder request = HttpRequest.builder(HttpMethod.POST, validatePipelineURL).withBody(GSON.toJson(new SpecGenerationRequest(path, Collections.emptyMap(), pluginName, pluginType)));
HttpResponse response = executeRequest(request);
Assert.assertEquals("Wrong answer: " + response.getResponseBodyAsString(), expectedCode, response.getResponseCode());
return expectedCode != HttpURLConnection.HTTP_OK ? null : GSON.fromJson(response.getResponseBodyAsString(), ConnectorDetail.class);
}
use of io.cdap.cdap.etl.proto.connection.ConnectorDetail in project cdap by cdapio.
the class DataPipelineConnectionTest method testConnectionSpec.
@Test
public void testConnectionSpec() throws Exception {
File directory = TEMP_FOLDER.newFolder();
String conn = "test_connection2";
ConnectionCreationRequest creationRequest = new ConnectionCreationRequest("", new PluginInfo(FileConnector.NAME, Connector.PLUGIN_TYPE, null, Collections.emptyMap(), // in set up we add "-mocks" as the suffix for the artifact id
new ArtifactSelectorConfig("system", APP_ARTIFACT_ID.getArtifact() + "-mocks", APP_ARTIFACT_ID.getVersion())));
addConnection(conn, creationRequest);
ConnectorDetail connectorDetail = getConnectionSpec(conn, directory.getCanonicalPath(), null, null);
Assert.assertTrue(connectorDetail.getRelatedPlugins().size() > 1);
connectorDetail = getConnectionSpec(conn, directory.getCanonicalPath(), "dummyPlugin", "batchsource");
Assert.assertEquals(connectorDetail.getRelatedPlugins().size(), 0);
connectorDetail = getConnectionSpec(conn, directory.getCanonicalPath(), "", "batchsource");
Assert.assertEquals(connectorDetail.getRelatedPlugins().size(), 1);
deleteConnection(conn);
}
use of io.cdap.cdap.etl.proto.connection.ConnectorDetail in project cdap by cdapio.
the class RemoteConnectionSampleTask method execute.
@Override
public String execute(SystemAppTaskContext systemAppContext, RemoteConnectionRequest request) throws Exception {
String namespace = request.getNamespace();
Connection connection = request.getConnection();
// Plugin selector and configurer
TrackedPluginSelector pluginSelector = new TrackedPluginSelector(new ArtifactSelectorProvider().getPluginSelector(connection.getPlugin().getArtifact()));
ServicePluginConfigurer pluginConfigurer = systemAppContext.createServicePluginConfigurer(namespace);
ConnectorContext connectorContext = ConnectionUtils.getConnectorContext(pluginConfigurer);
SampleRequest sampleRequest = GSON.fromJson(request.getRequest(), SampleRequest.class);
try (Connector connector = getConnector(systemAppContext, pluginConfigurer, connection.getPlugin(), namespace, pluginSelector)) {
connector.configure(new DefaultConnectorConfigurer(pluginConfigurer));
ConnectorSpecRequest specRequest = ConnectorSpecRequest.builder().setPath(sampleRequest.getPath()).setConnection(connection.getName()).setProperties(sampleRequest.getProperties()).build();
ConnectorSpec spec = connector.generateSpec(connectorContext, specRequest);
ConnectorDetail detail = ConnectionUtils.getConnectorDetail(pluginSelector.getSelectedArtifact(), spec);
SampleResponse sampleResponse = ConnectionUtils.getSampleResponse(connector, connectorContext, sampleRequest, detail, pluginConfigurer);
return GSON.toJson(sampleResponse);
}
}
use of io.cdap.cdap.etl.proto.connection.ConnectorDetail in project cdap by caskdata.
the class DataPipelineConnectionTest method testConnectionSpec.
@Test
public void testConnectionSpec() throws Exception {
File directory = TEMP_FOLDER.newFolder();
String conn = "test_connection2";
ConnectionCreationRequest creationRequest = new ConnectionCreationRequest("", new PluginInfo(FileConnector.NAME, Connector.PLUGIN_TYPE, null, Collections.emptyMap(), // in set up we add "-mocks" as the suffix for the artifact id
new ArtifactSelectorConfig("system", APP_ARTIFACT_ID.getArtifact() + "-mocks", APP_ARTIFACT_ID.getVersion())));
addConnection(conn, creationRequest);
ConnectorDetail connectorDetail = getConnectionSpec(conn, directory.getCanonicalPath(), null, null);
Assert.assertTrue(connectorDetail.getRelatedPlugins().size() > 1);
connectorDetail = getConnectionSpec(conn, directory.getCanonicalPath(), "dummyPlugin", "batchsource");
Assert.assertEquals(connectorDetail.getRelatedPlugins().size(), 0);
connectorDetail = getConnectionSpec(conn, directory.getCanonicalPath(), "", "batchsource");
Assert.assertEquals(connectorDetail.getRelatedPlugins().size(), 1);
deleteConnection(conn);
}
use of io.cdap.cdap.etl.proto.connection.ConnectorDetail in project cdap by caskdata.
the class DataPipelineConnectionTest method getConnectionSpec.
private ConnectorDetail getConnectionSpec(String connection, String path, @Nullable String pluginName, @Nullable String pluginType) throws IOException {
String url = URLEncoder.encode(String.format("v1/contexts/%s/connections/%s/specification", NamespaceId.DEFAULT.getNamespace(), connection), StandardCharsets.UTF_8.name());
URL validatePipelineURL = serviceURI.resolve(url).toURL();
HttpRequest.Builder request = HttpRequest.builder(HttpMethod.POST, validatePipelineURL).withBody(GSON.toJson(new SpecGenerationRequest(path, Collections.emptyMap(), pluginName, pluginType)));
HttpResponse response = executeRequest(request);
Assert.assertEquals("Wrong answer: " + response.getResponseBodyAsString(), expectedCode, response.getResponseCode());
return expectedCode != HttpURLConnection.HTTP_OK ? null : GSON.fromJson(response.getResponseBodyAsString(), ConnectorDetail.class);
}
Aggregations