Search in sources :

Example 6 with RestRequestDetails

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);
}
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 7 with RestRequestDetails

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);
}
Also used : RestCallDetails(com.sequenceiq.cloudbreak.structuredevent.event.rest.RestCallDetails) HashMap(java.util.HashMap) RestRequestDetails(com.sequenceiq.cloudbreak.structuredevent.event.rest.RestRequestDetails) CDPOperationDetails(com.sequenceiq.cloudbreak.structuredevent.event.cdp.CDPOperationDetails) RestResponseDetails(com.sequenceiq.cloudbreak.structuredevent.event.rest.RestResponseDetails) Test(org.junit.jupiter.api.Test)

Example 8 with RestRequestDetails

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);
}
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) CDPOperationDetails(com.sequenceiq.cloudbreak.structuredevent.event.cdp.CDPOperationDetails) RestResponseDetails(com.sequenceiq.cloudbreak.structuredevent.event.rest.RestResponseDetails) Test(org.junit.jupiter.api.Test)

Example 9 with RestRequestDetails

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());
}
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 10 with RestRequestDetails

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();
}
Also used : HashMap(java.util.HashMap) RestRequestDetails(com.sequenceiq.cloudbreak.structuredevent.event.rest.RestRequestDetails) Json(com.sequenceiq.cloudbreak.common.json.Json) CDPRestResourceAuditEventConverter(com.sequenceiq.cloudbreak.structuredevent.service.audit.auditeventname.rest.CDPRestResourceAuditEventConverter)

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