Search in sources :

Example 1 with RestResponseDetails

use of com.sequenceiq.cloudbreak.structuredevent.event.rest.RestResponseDetails in project cloudbreak by hortonworks.

the class StructuredEventFilter method createResponseDetails.

private RestResponseDetails createResponseDetails(ContainerResponseContext responseContext) {
    RestResponseDetails restResponse = new RestResponseDetails();
    restResponse.setStatusCode(responseContext.getStatus());
    restResponse.setCookies(responseContext.getCookies().entrySet().stream().collect(Collectors.toMap(Entry::getKey, e -> e.getValue().toString())));
    restResponse.setHeaders(responseContext.getHeaders().entrySet().stream().filter(e -> !skippedHeadersList.contains(e.getKey())).collect(Collectors.toMap(Entry::getKey, e -> StringUtils.join(e.getValue(), ","))));
    MediaType mediaType = responseContext.getMediaType();
    restResponse.setMediaType(mediaType != null ? mediaType.toString() : "");
    return restResponse;
}
Also used : Entry(java.util.Map.Entry) MediaType(javax.ws.rs.core.MediaType) RestResponseDetails(com.sequenceiq.cloudbreak.structuredevent.event.rest.RestResponseDetails)

Example 2 with RestResponseDetails

use of com.sequenceiq.cloudbreak.structuredevent.event.rest.RestResponseDetails in project cloudbreak by hortonworks.

the class StructuredEventFilter method aroundWriteTo.

@Override
public void aroundWriteTo(WriterInterceptorContext context) throws IOException, WebApplicationException {
    context.proceed();
    if (BooleanUtils.isTrue((Boolean) context.getProperty(LOGGING_ENABLED_PROPERTY))) {
        Long requestTime = (Long) context.getProperty(REQUEST_TIME);
        RestRequestDetails restRequest = (RestRequestDetails) context.getProperty(REQUEST_DETAILS);
        RestResponseDetails restResponse = (RestResponseDetails) context.getProperty(RESPONSE_DETAILS);
        String responseBody = ((LoggingStream) context.getProperty(LOGGINGSTREAM_PROPERTY)).getStringBuilder(MessageUtils.getCharset(context.getMediaType())).toString();
        Map<String, String> restParams = (Map<String, String>) context.getProperty(REST_PARAMS);
        extendRestParamsFromResponse(restParams, responseBody);
        sendStructuredEvent(restRequest, restResponse, restParams, requestTime, responseBody);
    }
}
Also used : RestRequestDetails(com.sequenceiq.cloudbreak.structuredevent.event.rest.RestRequestDetails) Map(java.util.Map) RestResponseDetails(com.sequenceiq.cloudbreak.structuredevent.event.rest.RestResponseDetails)

Example 3 with RestResponseDetails

use of com.sequenceiq.cloudbreak.structuredevent.event.rest.RestResponseDetails in project cloudbreak by hortonworks.

the class CDPStructuredEventFilter method sendStructuredEvent.

private void sendStructuredEvent(WriterInterceptorContext context) {
    Long requestTime = (Long) context.getProperty(REQUEST_TIME);
    RestRequestDetails restRequest = (RestRequestDetails) context.getProperty(REQUEST_DETAILS);
    RestResponseDetails restResponse = (RestResponseDetails) context.getProperty(RESPONSE_DETAILS);
    String responseBody = ((LoggingStream) context.getProperty(LOGGINGSTREAM_PROPERTY)).getStringBuilder(MessageUtils.getCharset(context.getMediaType())).toString();
    Map<String, String> restParams = (Map<String, String>) context.getProperty(REST_PARAMS);
    if (restParams == null) {
        restParams = new HashMap<>();
    }
    structuredEventFilterUtil.sendStructuredEvent(restRequest, restResponse, restParams, requestTime, responseBody);
}
Also used : RestRequestDetails(com.sequenceiq.cloudbreak.structuredevent.event.rest.RestRequestDetails) HashMap(java.util.HashMap) Map(java.util.Map) RestResponseDetails(com.sequenceiq.cloudbreak.structuredevent.event.rest.RestResponseDetails)

Example 4 with RestResponseDetails

use of com.sequenceiq.cloudbreak.structuredevent.event.rest.RestResponseDetails in project cloudbreak by hortonworks.

the class CDPRestCommonServiceTest method testWhenNameAndResourceCrnComeFromTheMapParameterButExistInRequestAndResponse.

@Test
public void testWhenNameAndResourceCrnComeFromTheMapParameterButExistInRequestAndResponse() {
    Map<String, String> restParams = Map.of(CLUSTER_NAME, "name1", CLUSTER_CRN, "crn1");
    RestCallDetails restCallDetails = new RestCallDetails();
    RestRequestDetails request = new RestRequestDetails();
    request.setBody(new Json(Map.of("name", "name2", "resourceCrn", "crn2")).getValue());
    RestResponseDetails response = new RestResponseDetails();
    response.setBody(new Json(Map.of("name", "name3", "resourceCrn", "crn3")).getValue());
    restCallDetails.setRestRequest(request);
    restCallDetails.setRestResponse(response);
    Map<String, String> expected = new HashMap<>();
    expected.put(CLUSTER_NAME, "name1");
    expected.put(CLUSTER_CRN, "crn1");
    Map<String, String> actual = underTest.collectCrnAndNameIfPresent(restCallDetails, null, restParams, CLUSTER_NAME, CLUSTER_CRN);
    assertEquals(expected, actual);
}
Also used : RestCallDetails(com.sequenceiq.cloudbreak.structuredevent.event.rest.RestCallDetails) HashMap(java.util.HashMap) RestRequestDetails(com.sequenceiq.cloudbreak.structuredevent.event.rest.RestRequestDetails) Json(com.sequenceiq.cloudbreak.common.json.Json) RestResponseDetails(com.sequenceiq.cloudbreak.structuredevent.event.rest.RestResponseDetails) Test(org.junit.jupiter.api.Test)

Example 5 with RestResponseDetails

use of com.sequenceiq.cloudbreak.structuredevent.event.rest.RestResponseDetails in project cloudbreak by hortonworks.

the class CDPRestCommonServiceTest method testWhenNameAndResourceCrnComeFromTheNameOrCrnProvider.

@Test
public void testWhenNameAndResourceCrnComeFromTheNameOrCrnProvider() {
    RestCallDetails restCallDetails = new RestCallDetails();
    RestRequestDetails request = new RestRequestDetails();
    RestResponseDetails response = new RestResponseDetails();
    CDPOperationDetails operationDetails = new CDPOperationDetails();
    restCallDetails.setRestRequest(request);
    restCallDetails.setRestResponse(response);
    Map<String, String> restParams = new HashMap<>();
    restParams.put(RESOURCE_TYPE, "mock");
    CustomCrnOrNameProvider customCrnOrNameProvider = mock(CustomCrnOrNameProvider.class);
    customCrnOrNameProviders.put("mockCustomCrnOrNameProvider", customCrnOrNameProvider);
    when(customCrnOrNameProvider.provide(restCallDetails, operationDetails, restParams, "names", "crns")).thenReturn(Map.of("crns", "pCrn", "names", "pName"));
    Map<String, Object> expected = new HashMap<>();
    expected.put("names", "pName");
    expected.put("crns", "pCrn");
    Map<String, String> actual = underTest.collectCrnAndNameIfPresent(restCallDetails, operationDetails, restParams, "names", "crns");
    assertEquals(expected, actual);
}
Also used : RestCallDetails(com.sequenceiq.cloudbreak.structuredevent.event.rest.RestCallDetails) HashMap(java.util.HashMap) RestRequestDetails(com.sequenceiq.cloudbreak.structuredevent.event.rest.RestRequestDetails) CDPOperationDetails(com.sequenceiq.cloudbreak.structuredevent.event.cdp.CDPOperationDetails) RestResponseDetails(com.sequenceiq.cloudbreak.structuredevent.event.rest.RestResponseDetails) Test(org.junit.jupiter.api.Test)

Aggregations

RestResponseDetails (com.sequenceiq.cloudbreak.structuredevent.event.rest.RestResponseDetails)28 RestRequestDetails (com.sequenceiq.cloudbreak.structuredevent.event.rest.RestRequestDetails)25 HashMap (java.util.HashMap)19 Test (org.junit.jupiter.api.Test)16 RestCallDetails (com.sequenceiq.cloudbreak.structuredevent.event.rest.RestCallDetails)14 Json (com.sequenceiq.cloudbreak.common.json.Json)10 StructuredRestCallEvent (com.sequenceiq.cloudbreak.structuredevent.event.StructuredRestCallEvent)7 Map (java.util.Map)6 OperationDetails (com.sequenceiq.cloudbreak.structuredevent.event.legacy.OperationDetails)5 OutputStream (java.io.OutputStream)3 CDPOperationDetails (com.sequenceiq.cloudbreak.structuredevent.event.cdp.CDPOperationDetails)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 FilterOutputStream (java.io.FilterOutputStream)2 Entry (java.util.Map.Entry)2 MediaType (javax.ws.rs.core.MediaType)2 CDPStructuredRestCallEvent (com.sequenceiq.cloudbreak.structuredevent.event.cdp.CDPStructuredRestCallEvent)1