Search in sources :

Example 6 with ConnectorDetail

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);
}
Also used : HttpRequest(io.cdap.common.http.HttpRequest) HttpResponse(io.cdap.common.http.HttpResponse) ConnectorDetail(io.cdap.cdap.etl.proto.connection.ConnectorDetail) SpecGenerationRequest(io.cdap.cdap.etl.proto.connection.SpecGenerationRequest) URL(java.net.URL)

Example 7 with ConnectorDetail

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);
}
Also used : ArtifactSelectorConfig(io.cdap.cdap.etl.proto.ArtifactSelectorConfig) ConnectionCreationRequest(io.cdap.cdap.etl.proto.connection.ConnectionCreationRequest) PluginInfo(io.cdap.cdap.etl.proto.connection.PluginInfo) ConnectorDetail(io.cdap.cdap.etl.proto.connection.ConnectorDetail) File(java.io.File) Test(org.junit.Test)

Example 8 with ConnectorDetail

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);
    }
}
Also used : Connector(io.cdap.cdap.etl.api.connector.Connector) ArtifactSelectorProvider(io.cdap.cdap.etl.common.ArtifactSelectorProvider) SampleResponse(io.cdap.cdap.etl.proto.connection.SampleResponse) Connection(io.cdap.cdap.etl.proto.connection.Connection) ConnectorDetail(io.cdap.cdap.etl.proto.connection.ConnectorDetail) ConnectorSpec(io.cdap.cdap.etl.api.connector.ConnectorSpec) SampleRequest(io.cdap.cdap.etl.api.connector.SampleRequest) DefaultConnectorConfigurer(io.cdap.cdap.datapipeline.connection.DefaultConnectorConfigurer) TrackedPluginSelector(io.cdap.cdap.etl.spec.TrackedPluginSelector) ConnectorContext(io.cdap.cdap.etl.api.connector.ConnectorContext) ConnectorSpecRequest(io.cdap.cdap.etl.api.connector.ConnectorSpecRequest) ServicePluginConfigurer(io.cdap.cdap.api.service.http.ServicePluginConfigurer)

Example 9 with ConnectorDetail

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);
}
Also used : ArtifactSelectorConfig(io.cdap.cdap.etl.proto.ArtifactSelectorConfig) ConnectionCreationRequest(io.cdap.cdap.etl.proto.connection.ConnectionCreationRequest) PluginInfo(io.cdap.cdap.etl.proto.connection.PluginInfo) ConnectorDetail(io.cdap.cdap.etl.proto.connection.ConnectorDetail) File(java.io.File) Test(org.junit.Test)

Example 10 with ConnectorDetail

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);
}
Also used : HttpRequest(io.cdap.common.http.HttpRequest) HttpResponse(io.cdap.common.http.HttpResponse) ConnectorDetail(io.cdap.cdap.etl.proto.connection.ConnectorDetail) SpecGenerationRequest(io.cdap.cdap.etl.proto.connection.SpecGenerationRequest) URL(java.net.URL)

Aggregations

ConnectorDetail (io.cdap.cdap.etl.proto.connection.ConnectorDetail)12 ArtifactSelectorConfig (io.cdap.cdap.etl.proto.ArtifactSelectorConfig)6 PluginInfo (io.cdap.cdap.etl.proto.connection.PluginInfo)6 SampleResponse (io.cdap.cdap.etl.proto.connection.SampleResponse)6 ServicePluginConfigurer (io.cdap.cdap.api.service.http.ServicePluginConfigurer)4 DefaultConnectorConfigurer (io.cdap.cdap.datapipeline.connection.DefaultConnectorConfigurer)4 Connector (io.cdap.cdap.etl.api.connector.Connector)4 ConnectorContext (io.cdap.cdap.etl.api.connector.ConnectorContext)4 ConnectorSpec (io.cdap.cdap.etl.api.connector.ConnectorSpec)4 ConnectorSpecRequest (io.cdap.cdap.etl.api.connector.ConnectorSpecRequest)4 SampleRequest (io.cdap.cdap.etl.api.connector.SampleRequest)4 ArtifactSelectorProvider (io.cdap.cdap.etl.common.ArtifactSelectorProvider)4 ConnectionCreationRequest (io.cdap.cdap.etl.proto.connection.ConnectionCreationRequest)4 PluginDetail (io.cdap.cdap.etl.proto.connection.PluginDetail)4 TrackedPluginSelector (io.cdap.cdap.etl.spec.TrackedPluginSelector)4 File (java.io.File)4 Test (org.junit.Test)4 StructuredRecord (io.cdap.cdap.api.data.format.StructuredRecord)2 Schema (io.cdap.cdap.api.data.schema.Schema)2 DefaultConnectorContext (io.cdap.cdap.datapipeline.connection.DefaultConnectorContext)2