Search in sources :

Example 6 with ConnectionCreationRequest

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);
        }
    });
}
Also used : ConnectionCreationRequest(io.cdap.cdap.etl.proto.connection.ConnectionCreationRequest) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) TransactionPolicy(io.cdap.cdap.api.annotation.TransactionPolicy)

Example 7 with ConnectionCreationRequest

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);
    });
}
Also used : ConnectionBadRequestException(io.cdap.cdap.etl.proto.connection.ConnectionBadRequestException) 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) ConnectionCreationRequest(io.cdap.cdap.etl.proto.connection.ConnectionCreationRequest) Path(javax.ws.rs.Path) TransactionPolicy(io.cdap.cdap.api.annotation.TransactionPolicy) PUT(javax.ws.rs.PUT)

Example 8 with ConnectionCreationRequest

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);
        }
    });
}
Also used : ConnectionCreationRequest(io.cdap.cdap.etl.proto.connection.ConnectionCreationRequest) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) TransactionPolicy(io.cdap.cdap.api.annotation.TransactionPolicy)

Example 9 with ConnectionCreationRequest

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);
    });
}
Also used : ConnectionBadRequestException(io.cdap.cdap.etl.proto.connection.ConnectionBadRequestException) 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) ConnectionCreationRequest(io.cdap.cdap.etl.proto.connection.ConnectionCreationRequest) Path(javax.ws.rs.Path) TransactionPolicy(io.cdap.cdap.api.annotation.TransactionPolicy) PUT(javax.ws.rs.PUT)

Example 10 with ConnectionCreationRequest

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);
}
Also used : ArtifactSelectorConfig(io.cdap.cdap.etl.proto.ArtifactSelectorConfig) ConnectionCreationRequest(io.cdap.cdap.etl.proto.connection.ConnectionCreationRequest) PluginInfo(io.cdap.cdap.etl.proto.connection.PluginInfo) ConnectorDetail(io.cdap.cdap.etl.proto.connection.ConnectorDetail) File(java.io.File) Test(org.junit.Test)

Aggregations

ConnectionCreationRequest (io.cdap.cdap.etl.proto.connection.ConnectionCreationRequest)20 ArtifactSelectorConfig (io.cdap.cdap.etl.proto.ArtifactSelectorConfig)14 PluginInfo (io.cdap.cdap.etl.proto.connection.PluginInfo)14 Test (org.junit.Test)10 File (java.io.File)8 StructuredRecord (io.cdap.cdap.api.data.format.StructuredRecord)6 Schema (io.cdap.cdap.api.data.schema.Schema)6 BrowseEntity (io.cdap.cdap.etl.api.connector.BrowseEntity)6 ETLStage (io.cdap.cdap.etl.proto.v2.ETLStage)6 TransactionPolicy (io.cdap.cdap.api.annotation.TransactionPolicy)4 Table (io.cdap.cdap.api.dataset.table.Table)4 PreviewManager (io.cdap.cdap.app.preview.PreviewManager)4 PreviewStatus (io.cdap.cdap.app.preview.PreviewStatus)4 ConnectorDetail (io.cdap.cdap.etl.proto.connection.ConnectorDetail)4 ETLBatchConfig (io.cdap.cdap.etl.proto.v2.ETLBatchConfig)4 ProgramRunStatus (io.cdap.cdap.proto.ProgramRunStatus)4 Path (javax.ws.rs.Path)4 AppRequest (io.cdap.cdap.proto.artifact.AppRequest)3 PreviewConfig (io.cdap.cdap.proto.artifact.preview.PreviewConfig)3 ApplicationId (io.cdap.cdap.proto.id.ApplicationId)3