Search in sources :

Example 1 with RestRequestDetails

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

the class StructuredEventFilter method createRequestDetails.

private RestRequestDetails createRequestDetails(ContainerRequestContext requestContext, String body) {
    RestRequestDetails restRequest = new RestRequestDetails();
    restRequest.setRequestUri(requestContext.getUriInfo().getRequestUri().toString());
    restRequest.setBody(body);
    restRequest.setCookies(requestContext.getCookies().entrySet().stream().collect(Collectors.toMap(Entry::getKey, e -> e.getValue().toString())));
    restRequest.setHeaders(requestContext.getHeaders().entrySet().stream().filter(e -> !skippedHeadersList.contains(e.getKey())).collect(Collectors.toMap(Entry::getKey, e -> StringUtils.join(e.getValue(), ","))));
    MediaType mediaType = requestContext.getMediaType();
    restRequest.setMediaType(mediaType != null ? mediaType.toString() : "");
    restRequest.setMethod(requestContext.getMethod());
    return restRequest;
}
Also used : Entry(java.util.Map.Entry) RestRequestDetails(com.sequenceiq.cloudbreak.structuredevent.event.rest.RestRequestDetails) MediaType(javax.ws.rs.core.MediaType)

Example 2 with RestRequestDetails

use of com.sequenceiq.cloudbreak.structuredevent.event.rest.RestRequestDetails 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 RestRequestDetails

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

the class CDPRestCommonService method collectCrnAndNameIfPresent.

public Map<String, String> collectCrnAndNameIfPresent(RestCallDetails restCallDetails, CDPOperationDetails operationDetails, Map<String, String> restParams, String nameField, String crnField) {
    Map<String, String> params = new HashMap<>();
    RestRequestDetails restRequest = restCallDetails.getRestRequest();
    Json requestJson = getJson(restRequest.getBody());
    Json responseJson = getJson(restCallDetails.getRestResponse().getBody());
    Map<String, String> copyRestParams = new HashMap<>(restParams);
    copyRestParams.putAll(collectFromCrnOrNameProvider(restCallDetails, operationDetails, restParams, nameField, crnField));
    String resourceCrn = getCrn(requestJson, responseJson, operationDetails, copyRestParams, crnField);
    String name = getName(requestJson, responseJson, operationDetails, copyRestParams, nameField);
    checkNameOrCrnProvided(restRequest, resourceCrn, name);
    addNameAndCrnIfNotEmpty(nameField, crnField, params, resourceCrn, name);
    return params;
}
Also used : HashMap(java.util.HashMap) RestRequestDetails(com.sequenceiq.cloudbreak.structuredevent.event.rest.RestRequestDetails) Json(com.sequenceiq.cloudbreak.common.json.Json)

Example 4 with RestRequestDetails

use of com.sequenceiq.cloudbreak.structuredevent.event.rest.RestRequestDetails 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 5 with RestRequestDetails

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

the class RestEventFilterRelatedObjectFactory method createRequestDetails.

public RestRequestDetails createRequestDetails(ContainerRequestContext requestContext, String body) {
    LOGGER.debug("Request body length: {}", body.length());
    RestRequestDetails restRequest = new RestRequestDetails();
    restRequest.setRequestUri(requestContext.getUriInfo().getRequestUri().toString());
    restRequest.setBody(body);
    restRequest.setCookies(convertCookies(requestContext));
    restRequest.setHeaders(convertHeaders(requestContext));
    restRequest.setMediaType(getMediaType(requestContext.getMediaType()));
    restRequest.setMethod(requestContext.getMethod());
    return restRequest;
}
Also used : RestRequestDetails(com.sequenceiq.cloudbreak.structuredevent.event.rest.RestRequestDetails)

Aggregations

RestRequestDetails (com.sequenceiq.cloudbreak.structuredevent.event.rest.RestRequestDetails)40 HashMap (java.util.HashMap)29 RestResponseDetails (com.sequenceiq.cloudbreak.structuredevent.event.rest.RestResponseDetails)25 Test (org.junit.jupiter.api.Test)23 RestCallDetails (com.sequenceiq.cloudbreak.structuredevent.event.rest.RestCallDetails)20 Json (com.sequenceiq.cloudbreak.common.json.Json)15 StructuredRestCallEvent (com.sequenceiq.cloudbreak.structuredevent.event.StructuredRestCallEvent)11 OperationDetails (com.sequenceiq.cloudbreak.structuredevent.event.legacy.OperationDetails)8 Map (java.util.Map)6 OutputStream (java.io.OutputStream)3 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)2 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 Cluster (com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster)1 HostGroup (com.sequenceiq.cloudbreak.domain.stack.cluster.host.HostGroup)1 InstanceGroup (com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup)1 RestResourceAuditEventConverter (com.sequenceiq.cloudbreak.structuredevent.auditeventname.rest.RestResourceAuditEventConverter)1