use of io.cdap.cdap.etl.proto.connection.ConnectionCreationRequest in project cdap by caskdata.
the class ConnectionHandler method testConnection.
@POST
@TransactionPolicy(value = TransactionControl.EXPLICIT)
@Path(API_VERSION + "/contexts/{context}/connections/test")
public void testConnection(HttpServiceRequest request, HttpServiceResponder responder, @PathParam("context") String namespace) {
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;
}
String testRequestString = StandardCharsets.UTF_8.decode(request.getContent()).toString();
ConnectionCreationRequest testRequest = GSON.fromJson(testRequestString, ConnectionCreationRequest.class);
if (getContext().isRemoteTaskEnabled()) {
executeRemotely(namespace, testRequestString, null, RemoteConnectionTestTask.class, responder);
} else {
testLocally(namespaceSummary.getName(), testRequest, responder);
}
});
}
use of io.cdap.cdap.etl.proto.connection.ConnectionCreationRequest in project cdap by caskdata.
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.ConnectionCreationRequest in project cdap by cdapio.
the class ConnectionHandler method testConnection.
@POST
@TransactionPolicy(value = TransactionControl.EXPLICIT)
@Path(API_VERSION + "/contexts/{context}/connections/test")
public void testConnection(HttpServiceRequest request, HttpServiceResponder responder, @PathParam("context") String namespace) {
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;
}
String testRequestString = StandardCharsets.UTF_8.decode(request.getContent()).toString();
ConnectionCreationRequest testRequest = GSON.fromJson(testRequestString, ConnectionCreationRequest.class);
if (getContext().isRemoteTaskEnabled()) {
executeRemotely(namespace, testRequestString, null, RemoteConnectionTestTask.class, responder);
} else {
testLocally(namespaceSummary.getName(), testRequest, responder);
}
});
}
use of io.cdap.cdap.etl.proto.connection.ConnectionCreationRequest 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.ConnectionCreationRequest 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);
}
Aggregations