use of com.netflix.conductor.client.exceptions.ConductorClientException in project conductor by Netflix.
the class TaskClient method evaluateAndUploadLargePayload.
public void evaluateAndUploadLargePayload(TaskResult taskResult, String taskType) {
Preconditions.checkNotNull(taskResult, "Task result cannot be null");
Preconditions.checkArgument(StringUtils.isBlank(taskResult.getExternalOutputPayloadStoragePath()), "External Storage Path must not be set");
try (ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream()) {
objectMapper.writeValue(byteArrayOutputStream, taskResult.getOutputData());
byte[] taskOutputBytes = byteArrayOutputStream.toByteArray();
long taskResultSize = taskOutputBytes.length;
MetricsContainer.recordTaskResultPayloadSize(taskType, taskResultSize);
long payloadSizeThreshold = conductorClientConfiguration.getTaskOutputPayloadThresholdKB() * 1024;
if (taskResultSize > payloadSizeThreshold) {
if (!conductorClientConfiguration.isExternalPayloadStorageEnabled() || taskResultSize > conductorClientConfiguration.getTaskOutputMaxPayloadThresholdKB() * 1024) {
taskResult.setReasonForIncompletion(String.format("The TaskResult payload size: %d is greater than the permissible %d MB", taskResultSize, payloadSizeThreshold));
taskResult.setStatus(TaskResult.Status.FAILED_WITH_TERMINAL_ERROR);
taskResult.setOutputData(null);
} else {
MetricsContainer.incrementExternalPayloadUsedCount(taskType, ExternalPayloadStorage.Operation.WRITE.name(), ExternalPayloadStorage.PayloadType.TASK_OUTPUT.name());
String externalStoragePath = uploadToExternalPayloadStorage(ExternalPayloadStorage.PayloadType.TASK_OUTPUT, taskOutputBytes, taskResultSize);
taskResult.setExternalOutputPayloadStoragePath(externalStoragePath);
taskResult.setOutputData(null);
}
}
} catch (IOException e) {
String errorMsg = String.format("Unable to update task: %s with task result", taskResult.getTaskId());
logger.error(errorMsg, e);
throw new ConductorClientException(errorMsg, e);
}
}
use of com.netflix.conductor.client.exceptions.ConductorClientException in project conductor by Netflix.
the class TaskPollExecutorTest method testLargePayloadCanFailUpdateWithRetry.
@Test
public void testLargePayloadCanFailUpdateWithRetry() {
Task task = testTask();
Worker worker = mock(Worker.class);
when(worker.getPollingInterval()).thenReturn(3000);
when(worker.getTaskDefName()).thenReturn(TEST_TASK_DEF_NAME);
when(worker.execute(any())).thenReturn(new TaskResult(task));
TaskClient taskClient = Mockito.mock(TaskClient.class);
when(taskClient.pollTask(any(), any(), any())).thenReturn(task);
when(taskClient.ack(any(), any())).thenReturn(true);
doAnswer(invocation -> {
Object[] args = invocation.getArguments();
TaskResult result = (TaskResult) args[0];
assertNull(result.getReasonForIncompletion());
result.setReasonForIncompletion("some_reason");
throw new ConductorClientException();
}).when(taskClient).evaluateAndUploadLargePayload(any(TaskResult.class), any());
TaskPollExecutor taskPollExecutor = new TaskPollExecutor(null, taskClient, 1, 3, new HashMap<>(), "test-worker-");
CountDownLatch latch = new CountDownLatch(1);
doAnswer(invocation -> {
latch.countDown();
return null;
}).when(worker).onErrorUpdate(any());
Executors.newSingleThreadScheduledExecutor().scheduleAtFixedRate(() -> taskPollExecutor.pollAndExecute(worker), 0, 1, TimeUnit.SECONDS);
Uninterruptibles.awaitUninterruptibly(latch);
// When evaluateAndUploadLargePayload fails indefinitely, task update shouldn't be called.
verify(taskClient, times(0)).updateTask(any());
}
use of com.netflix.conductor.client.exceptions.ConductorClientException in project conductor by Netflix.
the class ClientBase method handleUniformInterfaceException.
private void handleUniformInterfaceException(UniformInterfaceException exception, URI uri) {
ClientResponse clientResponse = exception.getResponse();
if (clientResponse == null) {
throw new ConductorClientException(String.format("Unable to invoke Conductor API with uri: %s", uri));
}
try {
if (clientResponse.getStatus() < 300) {
return;
}
String errorMessage = clientResponse.getEntity(String.class);
logger.error("Unable to invoke Conductor API with uri: {}, unexpected response from server: statusCode={}, responseBody='{}'.", uri, clientResponse.getStatus(), errorMessage);
ErrorResponse errorResponse;
try {
errorResponse = objectMapper.readValue(errorMessage, ErrorResponse.class);
} catch (IOException e) {
throw new ConductorClientException(clientResponse.getStatus(), errorMessage);
}
throw new ConductorClientException(clientResponse.getStatus(), errorResponse);
} catch (ConductorClientException e) {
throw e;
} catch (ClientHandlerException e) {
handleClientHandlerException(e, uri);
} catch (RuntimeException e) {
handleRuntimeException(e, uri);
} finally {
clientResponse.close();
}
}
use of com.netflix.conductor.client.exceptions.ConductorClientException in project conductor by Netflix.
the class PayloadStorage method download.
/**
* Downloads the payload from the given uri.
*
* @param uri the location from where the object is to be downloaded
* @return an inputstream of the payload in the external storage
* @throws ConductorClientException if the download fails due to an invalid path or an error from external storage
*/
@Override
public InputStream download(String uri) {
HttpURLConnection connection = null;
String errorMsg;
try {
URL url = new URI(uri).toURL();
connection = (HttpURLConnection) url.openConnection();
connection.setDoOutput(false);
// Check the HTTP response code
int responseCode = connection.getResponseCode();
if (responseCode == HttpURLConnection.HTTP_OK) {
logger.debug("Download completed with HTTP response code: {}", connection.getResponseCode());
return org.apache.commons.io.IOUtils.toBufferedInputStream(connection.getInputStream());
}
errorMsg = String.format("Unable to download. Response code: %d", responseCode);
logger.error(errorMsg);
throw new ConductorClientException(errorMsg);
} catch (URISyntaxException | MalformedURLException e) {
errorMsg = String.format("Invalid uri specified: %s", uri);
logger.error(errorMsg, e);
throw new ConductorClientException(errorMsg, e);
} catch (IOException e) {
errorMsg = String.format("Error downloading from uri: %s", uri);
logger.error(errorMsg, e);
throw new ConductorClientException(errorMsg, e);
} finally {
if (connection != null) {
connection.disconnect();
}
}
}
Aggregations