Search in sources :

Example 1 with DatabusRecordProcessingException

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);
    }
}
Also used : HttpRequest(java.net.http.HttpRequest) DatabusRecordProcessingException(com.sequenceiq.cloudbreak.sigmadbus.model.DatabusRecordProcessingException) HttpClient(java.net.http.HttpClient) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) URI(java.net.URI)

Example 2 with DatabusRecordProcessingException

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));
}
Also used : DatabusRequest(com.sequenceiq.cloudbreak.sigmadbus.model.DatabusRequest) DatabusRecordProcessingException(com.sequenceiq.cloudbreak.sigmadbus.model.DatabusRecordProcessingException) Test(org.junit.jupiter.api.Test)

Example 3 with DatabusRecordProcessingException

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.");
    }
}
Also used : DatabusRecordProcessingException(com.sequenceiq.cloudbreak.sigmadbus.model.DatabusRecordProcessingException) ManagedChannelWrapper(com.sequenceiq.cloudbreak.grpc.ManagedChannelWrapper) DbusProto(com.cloudera.sigma.service.dbus.DbusProto)

Aggregations

DatabusRecordProcessingException (com.sequenceiq.cloudbreak.sigmadbus.model.DatabusRecordProcessingException)3 DbusProto (com.cloudera.sigma.service.dbus.DbusProto)1 ManagedChannelWrapper (com.sequenceiq.cloudbreak.grpc.ManagedChannelWrapper)1 DatabusRequest (com.sequenceiq.cloudbreak.sigmadbus.model.DatabusRequest)1 IOException (java.io.IOException)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 HttpClient (java.net.http.HttpClient)1 HttpRequest (java.net.http.HttpRequest)1 Test (org.junit.jupiter.api.Test)1