Search in sources :

Example 1 with RemoteExecutionException

use of io.cdap.cdap.api.service.worker.RemoteExecutionException in project cdap by caskdata.

the class ValidationHandler method validateRemotely.

private void validateRemotely(HttpServiceRequest request, HttpServiceResponder responder, String namespace) throws IOException {
    String validationRequestString = StandardCharsets.UTF_8.decode(request.getContent()).toString();
    RemoteValidationRequest remoteValidationRequest = new RemoteValidationRequest(namespace, validationRequestString);
    RunnableTaskRequest runnableTaskRequest = RunnableTaskRequest.getBuilder(RemoteValidationTask.class.getName()).withParam(GSON.toJson(remoteValidationRequest)).build();
    try {
        byte[] bytes = getContext().runTask(runnableTaskRequest);
        responder.sendString(Bytes.toString(bytes));
    } catch (RemoteExecutionException e) {
        RemoteTaskException remoteTaskException = e.getCause();
        responder.sendError(getExceptionCode(remoteTaskException.getRemoteExceptionClassName(), remoteTaskException.getMessage(), namespace), remoteTaskException.getMessage());
    } catch (Exception e) {
        responder.sendError(HttpURLConnection.HTTP_INTERNAL_ERROR, e.getMessage());
    }
}
Also used : RemoteExecutionException(io.cdap.cdap.api.service.worker.RemoteExecutionException) RemoteTaskException(io.cdap.cdap.api.service.worker.RemoteTaskException) RunnableTaskRequest(io.cdap.cdap.api.service.worker.RunnableTaskRequest) RemoteExecutionException(io.cdap.cdap.api.service.worker.RemoteExecutionException) AccessException(io.cdap.cdap.api.security.AccessException) RemoteTaskException(io.cdap.cdap.api.service.worker.RemoteTaskException) JsonSyntaxException(com.google.gson.JsonSyntaxException) IOException(java.io.IOException)

Example 2 with RemoteExecutionException

use of io.cdap.cdap.api.service.worker.RemoteExecutionException in project cdap by caskdata.

the class ConnectionHandler method executeRemotely.

/**
 * Common method for all remote executions.
 * Remote request is created, executed and response is added to {@link HttpServiceResponder}
 * @param namespace namespace string
 * @param request Serialized request string
 * @param connection {@link Connection} details if present
 * @param remoteExecutionTaskClass Remote execution task class
 * @param responder {@link HttpServiceResponder} for the http request.
 */
private void executeRemotely(String namespace, String request, @Nullable Connection connection, Class<? extends RemoteConnectionTaskBase> remoteExecutionTaskClass, HttpServiceResponder responder) {
    RemoteConnectionRequest remoteRequest = new RemoteConnectionRequest(namespace, request, connection);
    RunnableTaskRequest runnableTaskRequest = RunnableTaskRequest.getBuilder(remoteExecutionTaskClass.getName()).withParam(GSON.toJson(remoteRequest)).build();
    try {
        byte[] bytes = getContext().runTask(runnableTaskRequest);
        responder.sendString(new String(bytes, StandardCharsets.UTF_8));
    } catch (RemoteExecutionException e) {
        // TODO CDAP-18787 - Handle other exceptions
        RemoteTaskException remoteTaskException = e.getCause();
        responder.sendError(getExceptionCode(remoteTaskException.getRemoteExceptionClassName(), remoteTaskException.getMessage(), namespace), remoteTaskException.getMessage());
    } catch (Exception e) {
        responder.sendError(HttpURLConnection.HTTP_INTERNAL_ERROR, e.getMessage());
    }
}
Also used : RemoteExecutionException(io.cdap.cdap.api.service.worker.RemoteExecutionException) RemoteTaskException(io.cdap.cdap.api.service.worker.RemoteTaskException) RunnableTaskRequest(io.cdap.cdap.api.service.worker.RunnableTaskRequest) RemoteTaskException(io.cdap.cdap.api.service.worker.RemoteTaskException) ConnectionNotFoundException(io.cdap.cdap.etl.proto.connection.ConnectionNotFoundException) RemoteExecutionException(io.cdap.cdap.api.service.worker.RemoteExecutionException) ValidationException(io.cdap.cdap.etl.api.validation.ValidationException) IOException(java.io.IOException) ConnectionBadRequestException(io.cdap.cdap.etl.proto.connection.ConnectionBadRequestException)

Aggregations

RemoteExecutionException (io.cdap.cdap.api.service.worker.RemoteExecutionException)2 RemoteTaskException (io.cdap.cdap.api.service.worker.RemoteTaskException)2 RunnableTaskRequest (io.cdap.cdap.api.service.worker.RunnableTaskRequest)2 IOException (java.io.IOException)2 JsonSyntaxException (com.google.gson.JsonSyntaxException)1 AccessException (io.cdap.cdap.api.security.AccessException)1 ValidationException (io.cdap.cdap.etl.api.validation.ValidationException)1 ConnectionBadRequestException (io.cdap.cdap.etl.proto.connection.ConnectionBadRequestException)1 ConnectionNotFoundException (io.cdap.cdap.etl.proto.connection.ConnectionNotFoundException)1