use of com.sequenceiq.cloudbreak.structuredevent.event.rest.RestRequestDetails 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.RestRequestDetails 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.RestRequestDetails 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);
}
use of com.sequenceiq.cloudbreak.structuredevent.event.rest.RestRequestDetails in project cloudbreak by hortonworks.
the class StructuredEventFilterUtilTest method testSendStructuredEventWhenRestParamIsNotEmptyMapButValuesAreNullThenParamsAreInvalid.
@Test
public void testSendStructuredEventWhenRestParamIsNotEmptyMapButValuesAreNullThenParamsAreInvalid() {
RestRequestDetails restRequestDetails = new RestRequestDetails();
RestResponseDetails restResponseDetails = new RestResponseDetails();
Map<String, String> restParams = new HashMap<>();
restParams.put("key", null);
underTest.sendStructuredEvent(restRequestDetails, restResponseDetails, restParams, 0L, null);
verify(structuredEventClient, never()).sendStructuredEvent(any());
}
use of com.sequenceiq.cloudbreak.structuredevent.event.rest.RestRequestDetails in project cloudbreak by hortonworks.
the class RestCDPEventDataExtractor method eventData.
@Override
public EventData eventData(CDPStructuredRestCallEvent 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();
CDPRestResourceAuditEventConverter restResourceAuditEventConverter = getConverter(resourceType);
if (restResourceAuditEventConverter != null) {
LOGGER.info("Determine request params with {}", restResourceAuditEventConverter);
Map<String, String> params = restResourceAuditEventConverter.requestParameters(structuredEvent);
requestParameters.putAll(params);
}
return ApiRequestData.builder().withApiVersion(cbVersion).withMutating(mutating).withRequestParameters(new Json(requestParameters).getValue()).withUserAgent(userAgent).build();
}
Aggregations