Search in sources :

Example 16 with RestRequestDetails

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

the class LegacyRestCommonServiceTest method testWhenNameAndResourceCrnNotExists.

@Test
public void testWhenNameAndResourceCrnNotExists() {
    StructuredRestCallEvent event = new StructuredRestCallEvent();
    OperationDetails operation = new OperationDetails();
    RestCallDetails restCallDetails = new RestCallDetails();
    RestRequestDetails request = new RestRequestDetails();
    request.setMethod("POST");
    request.setRequestUri("uri");
    RestResponseDetails response = new RestResponseDetails();
    restCallDetails.setRestRequest(request);
    restCallDetails.setRestResponse(response);
    event.setRestCall(restCallDetails);
    event.setOperation(operation);
    UnsupportedOperationException exception = assertThrows(UnsupportedOperationException.class, () -> legacyRestCommonService.addClusterCrnAndNameIfPresent(event));
    assertEquals(exception.getMessage(), "Cannot determine the resource crn or name, so we does not support for auditing for method: " + "POST, uri: uri, body: null");
}
Also used : StructuredRestCallEvent(com.sequenceiq.cloudbreak.structuredevent.event.StructuredRestCallEvent) OperationDetails(com.sequenceiq.cloudbreak.structuredevent.event.legacy.OperationDetails) RestCallDetails(com.sequenceiq.cloudbreak.structuredevent.event.rest.RestCallDetails) RestRequestDetails(com.sequenceiq.cloudbreak.structuredevent.event.rest.RestRequestDetails) RestResponseDetails(com.sequenceiq.cloudbreak.structuredevent.event.rest.RestResponseDetails) Test(org.junit.jupiter.api.Test)

Example 17 with RestRequestDetails

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

the class LegacyRestCommonServiceTest method testWhenNameAndResourceCrnComeFromTheRequestBodyButExistInResponse.

@Test
public void testWhenNameAndResourceCrnComeFromTheRequestBodyButExistInResponse() {
    StructuredRestCallEvent event = new StructuredRestCallEvent();
    OperationDetails operation = new OperationDetails();
    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);
    event.setRestCall(restCallDetails);
    event.setOperation(operation);
    Map<String, Object> expected = new HashMap<>();
    expected.put(CLUSTER_NAME, "name2");
    expected.put(CLUSTER_CRN, "crn2");
    Map<String, Object> actual = legacyRestCommonService.addClusterCrnAndNameIfPresent(event);
    assertEquals(expected, actual);
}
Also used : StructuredRestCallEvent(com.sequenceiq.cloudbreak.structuredevent.event.StructuredRestCallEvent) OperationDetails(com.sequenceiq.cloudbreak.structuredevent.event.legacy.OperationDetails) 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 18 with RestRequestDetails

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

the class LegacyRestCommonServiceTest method testWhenNamesAndCrnAreListAndMethodDelete.

@Test
public void testWhenNamesAndCrnAreListAndMethodDelete() {
    StructuredRestCallEvent event = new StructuredRestCallEvent();
    OperationDetails operation = new OperationDetails();
    RestCallDetails restCallDetails = new RestCallDetails();
    RestRequestDetails request = new RestRequestDetails();
    request.setMethod("DELETE");
    request.setBody(new Json(Map.of("names", List.of("names1", "names2"), "crns", List.of("crns1", "crns2"))).getValue());
    RestResponseDetails response = new RestResponseDetails();
    restCallDetails.setRestRequest(request);
    restCallDetails.setRestResponse(response);
    event.setRestCall(restCallDetails);
    event.setOperation(operation);
    Map<String, Object> expected = new HashMap<>();
    expected.put(CLUSTER_NAME, "names1,names2");
    expected.put(CLUSTER_CRN, "crns1,crns2");
    Map<String, Object> actual = legacyRestCommonService.addClusterCrnAndNameIfPresent(event);
    assertEquals(expected, actual);
}
Also used : StructuredRestCallEvent(com.sequenceiq.cloudbreak.structuredevent.event.StructuredRestCallEvent) OperationDetails(com.sequenceiq.cloudbreak.structuredevent.event.legacy.OperationDetails) 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 19 with RestRequestDetails

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

the class LegacyStructuredEventFilter method filter.

@Override
public void filter(ContainerRequestContext requestContext, ContainerResponseContext responseContext) {
    if (BooleanUtils.isTrue((Boolean) requestContext.getProperty(LOGGING_ENABLED_PROPERTY))) {
        RestResponseDetails restResponse = createResponseDetails(responseContext);
        if (responseContext.hasEntity()) {
            OutputStream stream = new LoggingStream(responseContext.getEntityStream());
            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);
            sendStructuredEvent(restRequest, restResponse, restParams, requestTime, "");
        }
    }
}
Also used : FilterOutputStream(java.io.FilterOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OutputStream(java.io.OutputStream) 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 20 with RestRequestDetails

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

the class StructuredEventFilter method filter.

@Override
public void filter(ContainerRequestContext requestContext, ContainerResponseContext responseContext) {
    if (BooleanUtils.isTrue((Boolean) requestContext.getProperty(LOGGING_ENABLED_PROPERTY))) {
        RestResponseDetails restResponse = createResponseDetails(responseContext);
        if (responseContext.hasEntity()) {
            OutputStream stream = new LoggingStream(responseContext.getEntityStream());
            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);
            sendStructuredEvent(restRequest, restResponse, restParams, requestTime, "");
        }
    }
}
Also used : ByteArrayOutputStream(java.io.ByteArrayOutputStream) OutputStream(java.io.OutputStream) FilterOutputStream(java.io.FilterOutputStream) RestRequestDetails(com.sequenceiq.cloudbreak.structuredevent.event.rest.RestRequestDetails) 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