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);
}
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());
}
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());
}
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<>());
}
}
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, "");
}
}
}
Aggregations