use of com.sequenceiq.cloudbreak.structuredevent.event.rest.RestCallDetails in project cloudbreak by hortonworks.
the class StructuredEventFilter method sendStructuredEvent.
private void sendStructuredEvent(RestRequestDetails restRequest, RestResponseDetails restResponse, Map<String, String> restParams, Long requestTime, String responseBody) {
restResponse.setBody(responseBody);
RestCallDetails restCall = new RestCallDetails();
restCall.setRestRequest(restRequest);
restCall.setRestResponse(restResponse);
restCall.setDuration(System.currentTimeMillis() - requestTime);
structuredEventClient.sendStructuredEvent(new StructuredRestCallEvent(createOperationDetails(restParams, requestTime), restCall));
}
use of com.sequenceiq.cloudbreak.structuredevent.event.rest.RestCallDetails in project cloudbreak by hortonworks.
the class StructuredEventFilterUtil method sendStructuredEvent.
public void sendStructuredEvent(RestRequestDetails restRequest, RestResponseDetails restResponse, Map<String, String> restParams, Long requestTime, String responseBody) {
boolean valid = checkRestParams(restParams);
try {
if (!valid) {
LOGGER.debug("Cannot create structured event, because rest params are invalid.");
return;
}
restResponse.setBody(responseBody);
RestCallDetails restCall = new RestCallDetails();
restCall.setRestRequest(restRequest);
restCall.setRestResponse(restResponse);
restCall.setDuration(System.currentTimeMillis() - requestTime);
Map<String, String> params = restCommonService.collectCrnAndNameIfPresent(restCall, null, restParams, RESOURCE_NAME, RESOURCE_CRN);
dataCollector.fetchDataFromDbIfNeed(params);
restParams.putAll(params);
CDPOperationDetails cdpOperationDetails = restEventFilterRelatedObjectFactory.createCDPOperationDetails(restParams, requestTime);
CDPStructuredRestCallEvent structuredEvent = new CDPStructuredRestCallEvent(cdpOperationDetails, restCall, null, null);
structuredEventClient.sendStructuredEvent(structuredEvent);
} catch (UnsupportedOperationException e) {
LOGGER.debug("Audit log is unnecessary: {}", e.getMessage());
} catch (Exception ex) {
LOGGER.warn("Failed to send structured event: " + ex.getMessage(), ex);
}
}
use of com.sequenceiq.cloudbreak.structuredevent.event.rest.RestCallDetails in project cloudbreak by hortonworks.
the class CDPRestCommonServiceTest method testWhenNameAndResourceCrnComeFromTheMapParameterButExistInRequestAndResponse.
@Test
public void testWhenNameAndResourceCrnComeFromTheMapParameterButExistInRequestAndResponse() {
Map<String, String> restParams = Map.of(CLUSTER_NAME, "name1", CLUSTER_CRN, "crn1");
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);
Map<String, String> expected = new HashMap<>();
expected.put(CLUSTER_NAME, "name1");
expected.put(CLUSTER_CRN, "crn1");
Map<String, String> actual = underTest.collectCrnAndNameIfPresent(restCallDetails, null, restParams, CLUSTER_NAME, CLUSTER_CRN);
assertEquals(expected, actual);
}
use of com.sequenceiq.cloudbreak.structuredevent.event.rest.RestCallDetails in project cloudbreak by hortonworks.
the class CDPRestCommonServiceTest method testWhenNameAndResourceCrnComeFromTheNameOrCrnProvider.
@Test
public void testWhenNameAndResourceCrnComeFromTheNameOrCrnProvider() {
RestCallDetails restCallDetails = new RestCallDetails();
RestRequestDetails request = new RestRequestDetails();
RestResponseDetails response = new RestResponseDetails();
CDPOperationDetails operationDetails = new CDPOperationDetails();
restCallDetails.setRestRequest(request);
restCallDetails.setRestResponse(response);
Map<String, String> restParams = new HashMap<>();
restParams.put(RESOURCE_TYPE, "mock");
CustomCrnOrNameProvider customCrnOrNameProvider = mock(CustomCrnOrNameProvider.class);
customCrnOrNameProviders.put("mockCustomCrnOrNameProvider", customCrnOrNameProvider);
when(customCrnOrNameProvider.provide(restCallDetails, operationDetails, restParams, "names", "crns")).thenReturn(Map.of("crns", "pCrn", "names", "pName"));
Map<String, Object> expected = new HashMap<>();
expected.put("names", "pName");
expected.put("crns", "pCrn");
Map<String, String> actual = underTest.collectCrnAndNameIfPresent(restCallDetails, operationDetails, restParams, "names", "crns");
assertEquals(expected, actual);
}
use of com.sequenceiq.cloudbreak.structuredevent.event.rest.RestCallDetails in project cloudbreak by hortonworks.
the class CDPRestCommonServiceTest method testWhenNameAndResourceCrnComeFromTheOperationDetails.
@Test
public void testWhenNameAndResourceCrnComeFromTheOperationDetails() {
RestCallDetails restCallDetails = new RestCallDetails();
RestRequestDetails request = new RestRequestDetails();
RestResponseDetails response = new RestResponseDetails();
response.setBody(new Json(Map.of("responses", List.of(Map.of("name", "name1", "crn", "crn1"), Map.of("name", "name2", "crn", "crn2")))).getValue());
CDPOperationDetails operationDetails = new CDPOperationDetails();
operationDetails.setResourceCrn("opCrn");
operationDetails.setResourceName("opName");
restCallDetails.setRestRequest(request);
restCallDetails.setRestResponse(response);
Map<String, Object> expected = new HashMap<>();
expected.put("names", "opName");
expected.put("crns", "opCrn");
Map<String, String> actual = underTest.collectCrnAndNameIfPresent(restCallDetails, operationDetails, Collections.emptyMap(), "names", "crns");
assertEquals(expected, actual);
}
Aggregations