Search in sources :

Example 1 with BrowseRequest

use of io.cdap.cdap.etl.api.connector.BrowseRequest 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 2 with BrowseRequest

use of io.cdap.cdap.etl.api.connector.BrowseRequest in project cdap by caskdata.

the class ConnectionHandler method browse.

/**
 * Browse the connection on a given path.
 */
@POST
@TransactionPolicy(value = TransactionControl.EXPLICIT)
@Path(API_VERSION + "/contexts/{context}/connections/{connection}/browse")
public void browse(HttpServiceRequest request, HttpServiceResponder responder, @PathParam("context") String namespace, @PathParam("connection") String connection) {
    respond(namespace, responder, namespaceSummary -> {
        if (namespaceSummary.getName().equalsIgnoreCase(NamespaceId.SYSTEM.getNamespace())) {
            responder.sendError(HttpURLConnection.HTTP_BAD_REQUEST, "Browsing connection in system namespace is currently not supported");
            return;
        }
        contextAccessEnforcer.enforce(new ConnectionEntityId(namespace, ConnectionId.getConnectionId(connection)), StandardPermission.USE);
        String browseRequestString = StandardCharsets.UTF_8.decode(request.getContent()).toString();
        BrowseRequest browseRequest = GSON.fromJson(browseRequestString, BrowseRequest.class);
        if (browseRequest == null) {
            responder.sendError(HttpURLConnection.HTTP_BAD_REQUEST, "The request body is empty");
            return;
        }
        if (browseRequest.getPath() == null) {
            responder.sendError(HttpURLConnection.HTTP_BAD_REQUEST, "Path is not provided in the browse request");
            return;
        }
        Connection conn = store.getConnection(new ConnectionId(namespaceSummary, connection));
        if (getContext().isRemoteTaskEnabled()) {
            executeRemotely(namespace, browseRequestString, conn, RemoteConnectionBrowseTask.class, responder);
        } else {
            browseLocally(namespaceSummary.getName(), browseRequest, conn, responder);
        }
        Metrics child = metrics.child(ImmutableMap.of(Constants.Metrics.Tag.APP_ENTITY_TYPE, Constants.CONNECTION_SERVICE_NAME, Constants.Metrics.Tag.APP_ENTITY_TYPE_NAME, conn.getConnectionType()));
        child.count(Constants.Metrics.Connection.CONNECTION_BROWSE_COUNT, 1);
    });
}
Also used : ConnectionId(io.cdap.cdap.etl.proto.connection.ConnectionId) Metrics(io.cdap.cdap.api.metrics.Metrics) HttpURLConnection(java.net.HttpURLConnection) Connection(io.cdap.cdap.etl.proto.connection.Connection) BrowseRequest(io.cdap.cdap.etl.api.connector.BrowseRequest) ConnectionEntityId(io.cdap.cdap.proto.id.ConnectionEntityId) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) TransactionPolicy(io.cdap.cdap.api.annotation.TransactionPolicy)

Aggregations

BrowseRequest (io.cdap.cdap.etl.api.connector.BrowseRequest)2 Connection (io.cdap.cdap.etl.proto.connection.Connection)2 TransactionPolicy (io.cdap.cdap.api.annotation.TransactionPolicy)1 Metrics (io.cdap.cdap.api.metrics.Metrics)1 ServicePluginConfigurer (io.cdap.cdap.api.service.http.ServicePluginConfigurer)1 DefaultConnectorConfigurer (io.cdap.cdap.datapipeline.connection.DefaultConnectorConfigurer)1 DefaultConnectorContext (io.cdap.cdap.datapipeline.connection.DefaultConnectorContext)1 BrowseDetail (io.cdap.cdap.etl.api.connector.BrowseDetail)1 Connector (io.cdap.cdap.etl.api.connector.Connector)1 ConnectorContext (io.cdap.cdap.etl.api.connector.ConnectorContext)1 ArtifactSelectorProvider (io.cdap.cdap.etl.common.ArtifactSelectorProvider)1 ConnectionId (io.cdap.cdap.etl.proto.connection.ConnectionId)1 SimpleFailureCollector (io.cdap.cdap.etl.proto.validation.SimpleFailureCollector)1 TrackedPluginSelector (io.cdap.cdap.etl.spec.TrackedPluginSelector)1 ConnectionEntityId (io.cdap.cdap.proto.id.ConnectionEntityId)1 HttpURLConnection (java.net.HttpURLConnection)1 POST (javax.ws.rs.POST)1 Path (javax.ws.rs.Path)1