Search in sources :

Example 1 with TransactionPolicy

use of io.cdap.cdap.api.annotation.TransactionPolicy in project cdap by caskdata.

the class Transactions method getTransactionControl.

private static TransactionControl getTransactionControl(Class<?> cls, String methodName, Class<?>[] params) {
    try {
        Method method = cls.getDeclaredMethod(methodName, params);
        TransactionPolicy annotation = method.getAnnotation(TransactionPolicy.class);
        if (annotation != null) {
            return annotation.value();
        }
    } catch (NoSuchMethodException e) {
    // this class does not have the method, that is ok
    }
    return null;
}
Also used : TransactionPolicy(io.cdap.cdap.api.annotation.TransactionPolicy) Method(java.lang.reflect.Method)

Example 2 with TransactionPolicy

use of io.cdap.cdap.api.annotation.TransactionPolicy 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 3 with TransactionPolicy

use of io.cdap.cdap.api.annotation.TransactionPolicy in project cdap by caskdata.

the class ConnectionHandler method deleteConnection.

/**
 * Delete a connection in the given namespace
 */
@DELETE
@TransactionPolicy(value = TransactionControl.EXPLICIT)
@Path(API_VERSION + "/contexts/{context}/connections/{connection}")
public void deleteConnection(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, "Deleting connection in system namespace is currently not supported");
            return;
        }
        ConnectionId connectionId = new ConnectionId(namespaceSummary, connection);
        contextAccessEnforcer.enforce(new ConnectionEntityId(namespace, connectionId.getConnectionId()), StandardPermission.DELETE);
        Connection oldConnection = store.getConnection(connectionId);
        store.deleteConnection(connectionId);
        Metrics child = metrics.child(ImmutableMap.of(Constants.Metrics.Tag.APP_ENTITY_TYPE, Constants.CONNECTION_SERVICE_NAME, Constants.Metrics.Tag.APP_ENTITY_TYPE_NAME, oldConnection.getConnectionType()));
        child.count(Constants.Metrics.Connection.CONNECTION_DELETED_COUNT, 1);
        responder.sendStatus(HttpURLConnection.HTTP_OK);
    });
}
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) ConnectionEntityId(io.cdap.cdap.proto.id.ConnectionEntityId) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) TransactionPolicy(io.cdap.cdap.api.annotation.TransactionPolicy)

Example 4 with TransactionPolicy

use of io.cdap.cdap.api.annotation.TransactionPolicy in project cdap by caskdata.

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);
    });
}
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) ConnectionEntityId(io.cdap.cdap.proto.id.ConnectionEntityId) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET) TransactionPolicy(io.cdap.cdap.api.annotation.TransactionPolicy)

Example 5 with TransactionPolicy

use of io.cdap.cdap.api.annotation.TransactionPolicy 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)

Aggregations

TransactionPolicy (io.cdap.cdap.api.annotation.TransactionPolicy)13 Path (javax.ws.rs.Path)8 Metrics (io.cdap.cdap.api.metrics.Metrics)6 Connection (io.cdap.cdap.etl.proto.connection.Connection)6 ConnectionId (io.cdap.cdap.etl.proto.connection.ConnectionId)6 HttpURLConnection (java.net.HttpURLConnection)6 ConnectionEntityId (io.cdap.cdap.proto.id.ConnectionEntityId)5 POST (javax.ws.rs.POST)4 HashMap (java.util.HashMap)3 Map (java.util.Map)3 MacroEvaluator (io.cdap.cdap.api.macro.MacroEvaluator)2 SparkClientContext (io.cdap.cdap.api.spark.SparkClientContext)2 BatchPhaseSpec (io.cdap.cdap.etl.batch.BatchPhaseSpec)2 DefaultMacroEvaluator (io.cdap.cdap.etl.common.DefaultMacroEvaluator)2 PipelineRuntime (io.cdap.cdap.etl.common.PipelineRuntime)2 CompositeFinisher (io.cdap.cdap.etl.common.submit.CompositeFinisher)2 Finisher (io.cdap.cdap.etl.common.submit.Finisher)2 ConnectionCreationRequest (io.cdap.cdap.etl.proto.connection.ConnectionCreationRequest)2 StageSpec (io.cdap.cdap.etl.proto.v2.spec.StageSpec)2 GET (javax.ws.rs.GET)2