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