Search in sources :

Example 36 with RestRequestDetails

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

the class CDPRestCommonServiceTest method testWhenNameAndResourceCrnComeFromTheResponse.

@Test
public void testWhenNameAndResourceCrnComeFromTheResponse() {
    RestCallDetails restCallDetails = new RestCallDetails();
    RestRequestDetails request = new RestRequestDetails();
    RestResponseDetails response = new RestResponseDetails();
    response.setBody(new Json(Map.of("name", "name3", "resourceCrn", "crn3")).getValue());
    restCallDetails.setRestRequest(request);
    restCallDetails.setRestResponse(response);
    Map<String, Object> expected = new HashMap<>();
    expected.put(CLUSTER_NAME, "name3");
    expected.put(CLUSTER_CRN, "crn3");
    Map<String, String> actual = underTest.collectCrnAndNameIfPresent(restCallDetails, null, Collections.emptyMap(), 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 37 with RestRequestDetails

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

the class StructuredEventFilterUtilTest method testSendStructuredEventWhenRestParamsAreOkThenParamsAreValid.

@Test
public void testSendStructuredEventWhenRestParamsAreOkThenParamsAreValid() {
    RestRequestDetails restRequestDetails = new RestRequestDetails();
    RestResponseDetails restResponseDetails = new RestResponseDetails();
    Map<String, String> restParams = new HashMap<>();
    restParams.put("key", "val");
    underTest.sendStructuredEvent(restRequestDetails, restResponseDetails, restParams, 0L, null);
    verify(structuredEventClient).sendStructuredEvent(any());
}
Also used : HashMap(java.util.HashMap) RestRequestDetails(com.sequenceiq.cloudbreak.structuredevent.event.rest.RestRequestDetails) RestResponseDetails(com.sequenceiq.cloudbreak.structuredevent.event.rest.RestResponseDetails) Test(org.junit.jupiter.api.Test)

Example 38 with RestRequestDetails

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

the class StructuredEventFilterUtilTest method testSendStructuredEventWhenRestParamIsEmptyMapThenParamsAreInvalid.

@Test
public void testSendStructuredEventWhenRestParamIsEmptyMapThenParamsAreInvalid() {
    RestRequestDetails restRequestDetails = new RestRequestDetails();
    RestResponseDetails restResponseDetails = new RestResponseDetails();
    underTest.sendStructuredEvent(restRequestDetails, restResponseDetails, Collections.emptyMap(), 0L, null);
    verify(structuredEventClient, never()).sendStructuredEvent(any());
}
Also used : RestRequestDetails(com.sequenceiq.cloudbreak.structuredevent.event.rest.RestRequestDetails) RestResponseDetails(com.sequenceiq.cloudbreak.structuredevent.event.rest.RestResponseDetails) Test(org.junit.jupiter.api.Test)

Example 39 with RestRequestDetails

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

the class CDPKafkaStructuredEventHandler method sanitizeSensitiveRestData.

protected void sanitizeSensitiveRestData(CDPStructuredEvent event) {
    if ("StructuredRestCallEvent".equals(event.getType())) {
        CDPStructuredRestCallEvent restEvent = (CDPStructuredRestCallEvent) event;
        RestRequestDetails restRequestDetails = restEvent.getRestCall().getRestRequest();
        restRequestDetails.setBody(REPLACEMENT);
        restRequestDetails.setHeaders(new HashMap());
        RestResponseDetails restResponseDetails = restEvent.getRestCall().getRestResponse();
        restResponseDetails.setBody(REPLACEMENT);
        restResponseDetails.setHeaders(new HashMap<>());
    }
}
Also used : CDPStructuredRestCallEvent(com.sequenceiq.cloudbreak.structuredevent.event.cdp.CDPStructuredRestCallEvent) HashMap(java.util.HashMap) RestRequestDetails(com.sequenceiq.cloudbreak.structuredevent.event.rest.RestRequestDetails) RestResponseDetails(com.sequenceiq.cloudbreak.structuredevent.event.rest.RestResponseDetails)

Example 40 with RestRequestDetails

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

the class CDPStructuredEventFilter method filter.

/**
 * On response, attaches a logging stream to the request context, or sends a structured event.
 * <p>
 * The filter essentially helps send a structured event or sends it itself.
 * <ul>
 *     <li>When there is a response entity, {@code LoggingStream} is attached and used in {@code aroundWriteTo} to send a structured event.</li>
 *     <li>When there isn't a response entity, send a structured event directly.</li>
 * </ul>
 */
@Override
public void filter(ContainerRequestContext requestContext, ContainerResponseContext responseContext) {
    if (BooleanUtils.isTrue((Boolean) requestContext.getProperty(LOGGING_ENABLED_PROPERTY))) {
        RestResponseDetails restResponse = restEventFilterRelatedObjectFactory.createResponseDetails(responseContext);
        if (responseContext.hasEntity()) {
            OutputStream stream = new LoggingStream(responseContext.getEntityStream(), contentLogging);
            responseContext.setEntityStream(stream);
            requestContext.setProperty(LOGGINGSTREAM_PROPERTY, stream);
            requestContext.setProperty(RESPONSE_DETAILS, restResponse);
        } else {
            Long requestTime = (Long) requestContext.getProperty(REQUEST_TIME);
            RestRequestDetails restRequest = (RestRequestDetails) requestContext.getProperty(REQUEST_DETAILS);
            Map<String, String> restParams = (Map<String, String>) requestContext.getProperty(REST_PARAMS);
            structuredEventFilterUtil.sendStructuredEvent(restRequest, restResponse, restParams, requestTime, "");
        }
    }
}
Also used : OutputStream(java.io.OutputStream) RestRequestDetails(com.sequenceiq.cloudbreak.structuredevent.event.rest.RestRequestDetails) HashMap(java.util.HashMap) Map(java.util.Map) RestResponseDetails(com.sequenceiq.cloudbreak.structuredevent.event.rest.RestResponseDetails)

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