Search in sources :

Example 26 with RestRequestDetails

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

the class FreeIpaCustomCrnOrNameProviderTest method testProviderWhenHasQueryParamsButNotContainsEnvironmentCrn.

@Test
public void testProviderWhenHasQueryParamsButNotContainsEnvironmentCrn() {
    RestCallDetails restCallDetails = new RestCallDetails();
    RestRequestDetails restRequestDetails = new RestRequestDetails();
    restCallDetails.setRestRequest(restRequestDetails);
    restRequestDetails.setRequestUri("http://localhost/any/path?asdda=asdasd");
    Map<String, String> restParams = new HashMap<>();
    underTest.provide(restCallDetails, null, restParams, "name", "crn");
    Assertions.assertFalse(restParams.containsKey("name"));
    Assertions.assertFalse(restParams.containsKey("crn"));
}
Also used : RestCallDetails(com.sequenceiq.cloudbreak.structuredevent.event.rest.RestCallDetails) HashMap(java.util.HashMap) RestRequestDetails(com.sequenceiq.cloudbreak.structuredevent.event.rest.RestRequestDetails) Test(org.junit.jupiter.api.Test)

Example 27 with RestRequestDetails

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

the class LegacyRestCommonService method addClusterCrnAndNameIfPresent.

public Map<String, Object> addClusterCrnAndNameIfPresent(StructuredRestCallEvent structuredEvent) {
    Map<String, Object> params = new HashMap<>();
    RestRequestDetails restRequest = structuredEvent.getRestCall().getRestRequest();
    Json requestJson = getJson(restRequest.getBody());
    Json responseJson = getJson(structuredEvent.getRestCall().getRestResponse().getBody());
    String resourceCrn = getCrn(requestJson, responseJson, restRequest, structuredEvent.getOperation());
    String name = getName(requestJson, responseJson, restRequest, structuredEvent.getOperation());
    checkNameOrCrnProvided(restRequest, resourceCrn, name);
    if (StringUtils.isNotEmpty(name)) {
        params.put(CLUSTER_NAME, name);
    }
    if (StringUtils.isNotEmpty(resourceCrn)) {
        params.put(CLUSTER_CRN, resourceCrn);
    }
    return params;
}
Also used : HashMap(java.util.HashMap) RestRequestDetails(com.sequenceiq.cloudbreak.structuredevent.event.rest.RestRequestDetails) Json(com.sequenceiq.cloudbreak.common.json.Json)

Example 28 with RestRequestDetails

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

the class LegacyStructuredEventFilter method createRequestDetails.

private 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(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 29 with RestRequestDetails

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

the class LegacyStructuredEventFilter 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);
        if (restParams == null) {
            restParams = new HashMap<>();
        }
        extendRestParamsFromResponse(restParams, responseBody);
        sendStructuredEvent(restRequest, restResponse, restParams, requestTime, responseBody);
    }
}
Also used : RestRequestDetails(com.sequenceiq.cloudbreak.structuredevent.event.rest.RestRequestDetails) Map(java.util.Map) HashMap(java.util.HashMap) RestResponseDetails(com.sequenceiq.cloudbreak.structuredevent.event.rest.RestResponseDetails)

Example 30 with RestRequestDetails

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

the class RestLegacyEventDataExtractor method eventData.

@Override
public EventData eventData(StructuredRestCallEvent structuredEvent) {
    RestRequestDetails restRequest = structuredEvent.getRestCall().getRestRequest();
    boolean mutating = Set.of("POST", "PUT", "DELETE").contains(restRequest.getMethod());
    String userAgent = restRequest.getHeaders().get("user-agent");
    Map<String, Object> requestParameters = new HashMap<>();
    requestParameters.put("uri", restRequest.getRequestUri());
    String resourceType = structuredEvent.getOperation().getResourceType();
    RestResourceAuditEventConverter restResourceAuditEventConverter = getConverter(resourceType);
    if (restResourceAuditEventConverter != null) {
        LOGGER.info("Determine request params with {}", restResourceAuditEventConverter);
        Map<String, Object> params = restResourceAuditEventConverter.requestParameters(structuredEvent);
        requestParameters.putAll(params);
    }
    return ApiRequestData.builder().withApiVersion(cbVersion).withMutating(mutating).withRequestParameters(new Json(requestParameters).getValue()).withUserAgent(userAgent).build();
}
Also used : HashMap(java.util.HashMap) RestResourceAuditEventConverter(com.sequenceiq.cloudbreak.structuredevent.auditeventname.rest.RestResourceAuditEventConverter) RestRequestDetails(com.sequenceiq.cloudbreak.structuredevent.event.rest.RestRequestDetails) Json(com.sequenceiq.cloudbreak.common.json.Json)

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