Search in sources :

Example 6 with DefaultConnectorContext

use of io.cdap.cdap.datapipeline.connection.DefaultConnectorContext in project cdap by cdapio.

the class RemoteConnectionTestTask method execute.

@Override
public String execute(SystemAppTaskContext systemAppContext, RemoteConnectionRequest request) throws Exception {
    String namespace = request.getNamespace();
    ConnectionCreationRequest connectionCreationRequest = GSON.fromJson(request.getRequest(), ConnectionCreationRequest.class);
    ServicePluginConfigurer pluginConfigurer = systemAppContext.createServicePluginConfigurer(namespace);
    ConnectorConfigurer connectorConfigurer = new DefaultConnectorConfigurer(pluginConfigurer);
    SimpleFailureCollector failureCollector = new SimpleFailureCollector();
    ConnectorContext connectorContext = new DefaultConnectorContext(failureCollector, pluginConfigurer);
    TrackedPluginSelector pluginSelector = new TrackedPluginSelector(new ArtifactSelectorProvider().getPluginSelector(connectionCreationRequest.getPlugin().getArtifact()));
    try (Connector connector = getConnector(systemAppContext, pluginConfigurer, connectionCreationRequest.getPlugin(), namespace, pluginSelector)) {
        connector.configure(connectorConfigurer);
        try {
            connector.test(connectorContext);
            failureCollector.getOrThrowException();
            return "";
        } catch (ValidationException e) {
            return GSON.toJson(e.getFailures());
        }
    }
}
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) DefaultConnectorContext(io.cdap.cdap.datapipeline.connection.DefaultConnectorContext) ConnectorContext(io.cdap.cdap.etl.api.connector.ConnectorContext) ConnectionCreationRequest(io.cdap.cdap.etl.proto.connection.ConnectionCreationRequest) 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 DefaultConnectorContext

use of io.cdap.cdap.datapipeline.connection.DefaultConnectorContext in project cdap by caskdata.

the class ConnectionHandler method browseLocally.

private void browseLocally(String namespace, BrowseRequest browseRequest, Connection conn, HttpServiceResponder responder) throws IOException {
    ServicePluginConfigurer pluginConfigurer = getContext().createServicePluginConfigurer(namespace);
    ConnectorConfigurer connectorConfigurer = new DefaultConnectorConfigurer(pluginConfigurer);
    ConnectorContext connectorContext = new DefaultConnectorContext(new SimpleFailureCollector(), pluginConfigurer);
    TrackedPluginSelector pluginSelector = new TrackedPluginSelector(new ArtifactSelectorProvider().getPluginSelector(conn.getPlugin().getArtifact()));
    try (Connector connector = getConnector(pluginConfigurer, conn.getPlugin(), namespace, pluginSelector)) {
        connector.configure(connectorConfigurer);
        responder.sendJson(connector.browse(connectorContext, browseRequest));
    }
}
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) 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 8 with DefaultConnectorContext

use of io.cdap.cdap.datapipeline.connection.DefaultConnectorContext in project cdap by caskdata.

the class RemoteConnectionBrowseTask 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 servicePluginConfigurer = systemAppContext.createServicePluginConfigurer(namespace);
    BrowseRequest browseRequest = GSON.fromJson(request.getRequest(), BrowseRequest.class);
    try (Connector connector = getConnector(systemAppContext, servicePluginConfigurer, connection.getPlugin(), namespace, pluginSelector)) {
        // configure and browse
        connector.configure(new DefaultConnectorConfigurer(servicePluginConfigurer));
        ConnectorContext connectorContext = new DefaultConnectorContext(new SimpleFailureCollector(), servicePluginConfigurer);
        BrowseDetail browseDetail = connector.browse(connectorContext, browseRequest);
        return GSON.toJson(browseDetail);
    }
}
Also used : Connector(io.cdap.cdap.etl.api.connector.Connector) ArtifactSelectorProvider(io.cdap.cdap.etl.common.ArtifactSelectorProvider) SimpleFailureCollector(io.cdap.cdap.etl.proto.validation.SimpleFailureCollector) TrackedPluginSelector(io.cdap.cdap.etl.spec.TrackedPluginSelector) DefaultConnectorContext(io.cdap.cdap.datapipeline.connection.DefaultConnectorContext) Connection(io.cdap.cdap.etl.proto.connection.Connection) ConnectorContext(io.cdap.cdap.etl.api.connector.ConnectorContext) DefaultConnectorContext(io.cdap.cdap.datapipeline.connection.DefaultConnectorContext) BrowseRequest(io.cdap.cdap.etl.api.connector.BrowseRequest) DefaultConnectorConfigurer(io.cdap.cdap.datapipeline.connection.DefaultConnectorConfigurer) BrowseDetail(io.cdap.cdap.etl.api.connector.BrowseDetail) ServicePluginConfigurer(io.cdap.cdap.api.service.http.ServicePluginConfigurer)

Example 9 with DefaultConnectorContext

use of io.cdap.cdap.datapipeline.connection.DefaultConnectorContext in project cdap by cdapio.

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 10 with DefaultConnectorContext

use of io.cdap.cdap.datapipeline.connection.DefaultConnectorContext in project cdap by cdapio.

the class ConnectionHandler method specGenerationLocally.

private void specGenerationLocally(String namespace, SpecGenerationRequest specRequest, Connection conn, HttpServiceResponder responder) throws IOException {
    ServicePluginConfigurer pluginConfigurer = getContext().createServicePluginConfigurer(namespace);
    ConnectorConfigurer connectorConfigurer = new DefaultConnectorConfigurer(pluginConfigurer);
    ConnectorContext connectorContext = new DefaultConnectorContext(new SimpleFailureCollector(), pluginConfigurer);
    // use tracked selector to get exact plugin version that gets selected since the passed version can be null
    TrackedPluginSelector pluginSelector = new TrackedPluginSelector(new ArtifactSelectorProvider().getPluginSelector(conn.getPlugin().getArtifact()));
    try (Connector connector = getConnector(pluginConfigurer, conn.getPlugin(), namespace, pluginSelector)) {
        connector.configure(connectorConfigurer);
        ConnectorSpecRequest connectorSpecRequest = ConnectorSpecRequest.builder().setPath(specRequest.getPath()).setConnection(conn.getName()).setProperties(specRequest.getProperties()).build();
        ConnectorSpec spec = connector.generateSpec(connectorContext, connectorSpecRequest);
        ConnectorSpec newSpec = ConnectionUtils.filterSpecWithPluginNameAndType(spec, specRequest.getPluginName(), specRequest.getPluginType());
        responder.sendString(GSON.toJson(ConnectionUtils.getConnectorDetail(pluginSelector.getSelectedArtifact(), newSpec)));
    }
}
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) ConnectorContext(io.cdap.cdap.etl.api.connector.ConnectorContext) DefaultConnectorContext(io.cdap.cdap.datapipeline.connection.DefaultConnectorContext) ConnectorSpecRequest(io.cdap.cdap.etl.api.connector.ConnectorSpecRequest) ConnectorSpec(io.cdap.cdap.etl.api.connector.ConnectorSpec) 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)

Aggregations

ServicePluginConfigurer (io.cdap.cdap.api.service.http.ServicePluginConfigurer)12 DefaultConnectorConfigurer (io.cdap.cdap.datapipeline.connection.DefaultConnectorConfigurer)12 DefaultConnectorContext (io.cdap.cdap.datapipeline.connection.DefaultConnectorContext)12 Connector (io.cdap.cdap.etl.api.connector.Connector)12 ConnectorContext (io.cdap.cdap.etl.api.connector.ConnectorContext)12 ArtifactSelectorProvider (io.cdap.cdap.etl.common.ArtifactSelectorProvider)12 SimpleFailureCollector (io.cdap.cdap.etl.proto.validation.SimpleFailureCollector)12 TrackedPluginSelector (io.cdap.cdap.etl.spec.TrackedPluginSelector)12 ConnectorConfigurer (io.cdap.cdap.etl.api.connector.ConnectorConfigurer)10 ConnectorSpec (io.cdap.cdap.etl.api.connector.ConnectorSpec)4 ConnectorSpecRequest (io.cdap.cdap.etl.api.connector.ConnectorSpecRequest)4 ValidationException (io.cdap.cdap.etl.api.validation.ValidationException)4 BrowseDetail (io.cdap.cdap.etl.api.connector.BrowseDetail)2 BrowseRequest (io.cdap.cdap.etl.api.connector.BrowseRequest)2 SampleRequest (io.cdap.cdap.etl.api.connector.SampleRequest)2 Connection (io.cdap.cdap.etl.proto.connection.Connection)2 ConnectionBadRequestException (io.cdap.cdap.etl.proto.connection.ConnectionBadRequestException)2 ConnectionCreationRequest (io.cdap.cdap.etl.proto.connection.ConnectionCreationRequest)2 ConnectorDetail (io.cdap.cdap.etl.proto.connection.ConnectorDetail)2 PluginInfo (io.cdap.cdap.etl.proto.connection.PluginInfo)2