use of io.cdap.cdap.api.service.worker.RemoteTaskException 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());
}
}
use of io.cdap.cdap.api.service.worker.RemoteTaskException 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());
}
}
Aggregations