use of io.cdap.cdap.etl.proto.connection.Connection in project cdap by cdapio.
the class ConnectionHandler method sample.
/**
* Retrive sample result for the connection
*/
@POST
@TransactionPolicy(value = TransactionControl.EXPLICIT)
@Path(API_VERSION + "/contexts/{context}/connections/{connection}/sample")
public void sample(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, "Sampling connection in system namespace is currently not supported");
return;
}
contextAccessEnforcer.enforce(new ConnectionEntityId(namespace, ConnectionId.getConnectionId(connection)), StandardPermission.USE);
String sampleRequestString = StandardCharsets.UTF_8.decode(request.getContent()).toString();
SampleRequest sampleRequest = GSON.fromJson(sampleRequestString, SampleRequest.class);
if (sampleRequest == null) {
responder.sendError(HttpURLConnection.HTTP_BAD_REQUEST, "The request body is empty");
return;
}
if (sampleRequest.getPath() == null) {
responder.sendError(HttpURLConnection.HTTP_BAD_REQUEST, "Path is not provided in the sample request");
return;
}
if (sampleRequest.getLimit() <= 0) {
responder.sendError(HttpURLConnection.HTTP_BAD_REQUEST, "Limit should be greater than 0");
return;
}
Connection conn = store.getConnection(new ConnectionId(namespaceSummary, connection));
if (getContext().isRemoteTaskEnabled()) {
executeRemotely(namespace, sampleRequestString, conn, RemoteConnectionSampleTask.class, responder);
} else {
sampleLocally(namespaceSummary.getName(), sampleRequestString, 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_SAMPLE_COUNT, 1);
// sample will also generate the spec, so add the metric for it
child.count(Constants.Metrics.Connection.CONNECTION_SPEC_COUNT, 1);
});
}
use of io.cdap.cdap.etl.proto.connection.Connection in project cdap by cdapio.
the class ConnectionHandler method getConnection.
/**
* Returns the specific connection information in the given namespace
*/
@GET
@TransactionPolicy(value = TransactionControl.EXPLICIT)
@Path(API_VERSION + "/contexts/{context}/connections/{connection}")
public void getConnection(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, "Getting connection in system namespace is currently not supported");
return;
}
contextAccessEnforcer.enforce(new ConnectionEntityId(namespace, ConnectionId.getConnectionId(connection)), StandardPermission.GET);
Connection conn = store.getConnection(new ConnectionId(namespaceSummary, connection));
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_GET_COUNT, 1);
responder.sendJson(conn);
});
}
use of io.cdap.cdap.etl.proto.connection.Connection in project cdap by cdapio.
the class ConnectionHandler method createConnection.
/**
* Creates a connection in the given namespace
*/
@PUT
@TransactionPolicy(value = TransactionControl.EXPLICIT)
@Path(API_VERSION + "/contexts/{context}/connections/{connection}")
public void createConnection(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, "Creating connection in system namespace is currently not supported");
return;
}
ConnectionId connectionId = new ConnectionId(namespaceSummary, connection);
checkPutConnectionPermissions(connectionId);
ConnectionCreationRequest creationRequest = GSON.fromJson(StandardCharsets.UTF_8.decode(request.getContent()).toString(), ConnectionCreationRequest.class);
String connType = creationRequest.getPlugin().getName();
if (disabledTypes.contains(connType)) {
throw new ConnectionBadRequestException(String.format("Connection type %s is disabled, connection cannot be created", connType));
}
long now = System.currentTimeMillis();
Connection connectionInfo = new Connection(connection, connectionId.getConnectionId(), connType, creationRequest.getDescription(), false, false, now, now, creationRequest.getPlugin());
store.saveConnection(connectionId, connectionInfo, creationRequest.overWrite());
Metrics child = metrics.child(ImmutableMap.of(Constants.Metrics.Tag.APP_ENTITY_TYPE, Constants.CONNECTION_SERVICE_NAME, Constants.Metrics.Tag.APP_ENTITY_TYPE_NAME, connectionInfo.getConnectionType()));
child.count(Constants.Metrics.Connection.CONNECTION_COUNT, 1);
responder.sendStatus(HttpURLConnection.HTTP_OK);
});
}
use of io.cdap.cdap.etl.proto.connection.Connection in project cdap by cdapio.
the class ConnectionHandler method spec.
/**
* Retrieve the spec for the connector, which can be used in a source/sink
*/
@POST
@TransactionPolicy(value = TransactionControl.EXPLICIT)
@Path(API_VERSION + "/contexts/{context}/connections/{connection}/specification")
public void spec(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, "Generating connector spec in system namespace is currently not supported");
return;
}
contextAccessEnforcer.enforce(new ConnectionEntityId(namespace, ConnectionId.getConnectionId(connection)), StandardPermission.USE);
String specGenerationRequestString = StandardCharsets.UTF_8.decode(request.getContent()).toString();
SpecGenerationRequest specRequest = GSON.fromJson(specGenerationRequestString, SpecGenerationRequest.class);
if (specRequest == null) {
responder.sendError(HttpURLConnection.HTTP_BAD_REQUEST, "The request body is empty");
return;
}
if (specRequest.getPath() == null) {
responder.sendError(HttpURLConnection.HTTP_BAD_REQUEST, "Path is not provided in the sample request");
return;
}
Connection conn = store.getConnection(new ConnectionId(namespaceSummary, connection));
if (getContext().isRemoteTaskEnabled()) {
executeRemotely(namespace, specGenerationRequestString, conn, RemoteConnectionSpecTask.class, responder);
} else {
specGenerationLocally(namespaceSummary.getName(), specRequest, 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_SPEC_COUNT, 1);
});
}
use of io.cdap.cdap.etl.proto.connection.Connection in project cdap by cdapio.
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