use of com.sequenceiq.cloudbreak.sigmadbus.model.DatabusRecordProcessingException in project cloudbreak by hortonworks.
the class SigmaDatabusClient method uploadRecordToS3.
private void uploadRecordToS3(String s3Url, DatabusRequest request, String recordId) throws DatabusRecordProcessingException {
String payload = getPayload(request);
try {
HttpClient client = HttpClient.newHttpClient();
HttpRequest httpRequest = HttpRequest.newBuilder().uri(new URI(s3Url)).PUT(HttpRequest.BodyPublishers.ofString(payload)).build();
HttpResponse<String> response = client.send(httpRequest, HttpResponse.BodyHandlers.ofString());
Response.Status.Family statusFamily = Response.Status.Family.familyOf(response.statusCode());
LOGGER.debug("Databus (upload to S3) response status code: {}", response.statusCode());
if (Response.Status.Family.SUCCESSFUL.equals(statusFamily) || Response.Status.Family.REDIRECTION.equals(statusFamily)) {
LOGGER.debug("Databus record with id {} successfully uploaded to s3.", recordId);
} else {
throw new DatabusRecordProcessingException(String.format("S3 upload failed for databus record with id %s", recordId));
}
} catch (URISyntaxException | IOException | InterruptedException e) {
throw new DatabusRecordProcessingException(String.format("Error during uploading record with id %s to s3", recordId), e);
}
}
use of com.sequenceiq.cloudbreak.sigmadbus.model.DatabusRecordProcessingException in project cloudbreak by hortonworks.
the class DatabusRecordWorkerTest method testProcessRecordInputThrowingDatabusRecordException.
@Test
public void testProcessRecordInputThrowingDatabusRecordException() throws DatabusRecordProcessingException {
// GIVEN
underTest = spy(underTest);
doReturn(dataBusClient).when(underTest).getClient();
doThrow(new DatabusRecordProcessingException("error")).when(dataBusClient).putRecord(any(DatabusRequest.class));
doNothing().when(databusRecordProcessor).handleDatabusRecordProcessingException(any(DatabusRequest.class), any(DatabusRecordProcessingException.class));
// WHEN
underTest.processRecordInput(createDatabusRequest());
// THEN
verify(databusRecordProcessor, times(1)).handleDatabusRecordProcessingException(any(DatabusRequest.class), any(DatabusRecordProcessingException.class));
}
use of com.sequenceiq.cloudbreak.sigmadbus.model.DatabusRecordProcessingException in project cloudbreak by hortonworks.
the class SigmaDatabusClient method putRecord.
/**
* Upload data into databus. If the payload is larger than 1 MB, the data will be uploaded to cloudera S3.
* @param request databus record payload input
* @throws DatabusRecordProcessingException error during databus record processing
*/
public void putRecord(DatabusRequest request) throws DatabusRecordProcessingException {
ManagedChannelWrapper channelWrapper = getMessageWrapper();
DbusProto.PutRecordRequest recordRequest = convert(request, databusStreamConfiguration);
String requestId = MDCBuilder.getOrGenerateRequestId();
LOGGER.debug("Creating databus request with request id: {}", requestId);
buildMdcContext(request, requestId);
DbusProto.PutRecordResponse recordResponse = newStub(channelWrapper.getChannel(), requestId, regionAwareInternalCrnGeneratorFactory.iam().getInternalCrnForServiceAsString()).putRecord(recordRequest);
DbusProto.Record.Reply.Status status = recordResponse.getRecord().getStatus();
LOGGER.debug("Returned dbus record status is {}", status);
if (DbusProto.Record.Reply.Status.SENT.equals(status)) {
String recordId = recordResponse.getRecord().getRecordId();
LOGGER.debug("Dbus record sucessfully processed with record id: {}", recordId);
} else if (DbusProto.Record.Reply.Status.PENDING.equals(status)) {
String recordId = recordResponse.getRecord().getRecordId();
String s3BucketUrl = recordResponse.getRecord().getUploadUrl();
LOGGER.debug("Dbus record can be uploaded to s3 [record id: {}], [s3 url: {}]", recordId, s3BucketUrl);
uploadRecordToS3(s3BucketUrl, request, recordId);
} else {
throw new DatabusRecordProcessingException("Cannot process record to Sigma Databus.");
}
}
Aggregations