Search in sources :

Example 1 with RestCallDetails

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));
}
Also used : StructuredRestCallEvent(com.sequenceiq.cloudbreak.structuredevent.event.StructuredRestCallEvent) RestCallDetails(com.sequenceiq.cloudbreak.structuredevent.event.rest.RestCallDetails)

Example 2 with RestCallDetails

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);
    }
}
Also used : RestCallDetails(com.sequenceiq.cloudbreak.structuredevent.event.rest.RestCallDetails) CDPStructuredRestCallEvent(com.sequenceiq.cloudbreak.structuredevent.event.cdp.CDPStructuredRestCallEvent) CDPOperationDetails(com.sequenceiq.cloudbreak.structuredevent.event.cdp.CDPOperationDetails) IOException(java.io.IOException)

Example 3 with RestCallDetails

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

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

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

Aggregations

RestCallDetails (com.sequenceiq.cloudbreak.structuredevent.event.rest.RestCallDetails)24 RestRequestDetails (com.sequenceiq.cloudbreak.structuredevent.event.rest.RestRequestDetails)20 Test (org.junit.jupiter.api.Test)19 HashMap (java.util.HashMap)18 RestResponseDetails (com.sequenceiq.cloudbreak.structuredevent.event.rest.RestResponseDetails)14 Json (com.sequenceiq.cloudbreak.common.json.Json)11 StructuredRestCallEvent (com.sequenceiq.cloudbreak.structuredevent.event.StructuredRestCallEvent)11 OperationDetails (com.sequenceiq.cloudbreak.structuredevent.event.legacy.OperationDetails)8 CDPOperationDetails (com.sequenceiq.cloudbreak.structuredevent.event.cdp.CDPOperationDetails)4 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)2 ThreadBasedUserCrnProvider (com.sequenceiq.cloudbreak.auth.ThreadBasedUserCrnProvider)1 AccountAwareResource (com.sequenceiq.cloudbreak.common.dal.model.AccountAwareResource)1 CloudbreakUser (com.sequenceiq.cloudbreak.common.user.CloudbreakUser)1 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 CDPStructuredRestCallEvent (com.sequenceiq.cloudbreak.structuredevent.event.cdp.CDPStructuredRestCallEvent)1 CustomCrnOrNameProvider (com.sequenceiq.cloudbreak.structuredevent.rest.CustomCrnOrNameProvider)1 RESOURCE_ID (com.sequenceiq.cloudbreak.structuredevent.rest.urlparser.CDPRestUrlParser.RESOURCE_ID)1 Stack (com.sequenceiq.freeipa.entity.Stack)1