Search in sources :

Example 6 with StructuredRestCallEvent

use of com.sequenceiq.cloudbreak.structuredevent.event.StructuredRestCallEvent in project cloudbreak by hortonworks.

the class LegacyRestCommonServiceTest method testWhenNameAndResourceCrnComeFromTheResponse.

@Test
public void testWhenNameAndResourceCrnComeFromTheResponse() {
    StructuredRestCallEvent event = new StructuredRestCallEvent();
    OperationDetails operation = new OperationDetails();
    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);
    event.setRestCall(restCallDetails);
    event.setOperation(operation);
    Map<String, Object> expected = new HashMap<>();
    expected.put(CLUSTER_NAME, "name3");
    expected.put(CLUSTER_CRN, "crn3");
    Map<String, Object> actual = legacyRestCommonService.addClusterCrnAndNameIfPresent(event);
    assertEquals(expected, actual);
}
Also used : StructuredRestCallEvent(com.sequenceiq.cloudbreak.structuredevent.event.StructuredRestCallEvent) OperationDetails(com.sequenceiq.cloudbreak.structuredevent.event.legacy.OperationDetails) 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 StructuredRestCallEvent

use of com.sequenceiq.cloudbreak.structuredevent.event.StructuredRestCallEvent in project cloudbreak by hortonworks.

the class LegacyRestCommonServiceTest method testWhenNameAndResourceCrnNotExists.

@Test
public void testWhenNameAndResourceCrnNotExists() {
    StructuredRestCallEvent event = new StructuredRestCallEvent();
    OperationDetails operation = new OperationDetails();
    RestCallDetails restCallDetails = new RestCallDetails();
    RestRequestDetails request = new RestRequestDetails();
    request.setMethod("POST");
    request.setRequestUri("uri");
    RestResponseDetails response = new RestResponseDetails();
    restCallDetails.setRestRequest(request);
    restCallDetails.setRestResponse(response);
    event.setRestCall(restCallDetails);
    event.setOperation(operation);
    UnsupportedOperationException exception = assertThrows(UnsupportedOperationException.class, () -> legacyRestCommonService.addClusterCrnAndNameIfPresent(event));
    assertEquals(exception.getMessage(), "Cannot determine the resource crn or name, so we does not support for auditing for method: " + "POST, uri: uri, body: null");
}
Also used : StructuredRestCallEvent(com.sequenceiq.cloudbreak.structuredevent.event.StructuredRestCallEvent) OperationDetails(com.sequenceiq.cloudbreak.structuredevent.event.legacy.OperationDetails) RestCallDetails(com.sequenceiq.cloudbreak.structuredevent.event.rest.RestCallDetails) RestRequestDetails(com.sequenceiq.cloudbreak.structuredevent.event.rest.RestRequestDetails) RestResponseDetails(com.sequenceiq.cloudbreak.structuredevent.event.rest.RestResponseDetails) Test(org.junit.jupiter.api.Test)

Example 8 with StructuredRestCallEvent

use of com.sequenceiq.cloudbreak.structuredevent.event.StructuredRestCallEvent in project cloudbreak by hortonworks.

the class LegacyRestCommonServiceTest method testWhenNameAndResourceCrnComeFromTheRequestBodyButExistInResponse.

@Test
public void testWhenNameAndResourceCrnComeFromTheRequestBodyButExistInResponse() {
    StructuredRestCallEvent event = new StructuredRestCallEvent();
    OperationDetails operation = new OperationDetails();
    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);
    event.setRestCall(restCallDetails);
    event.setOperation(operation);
    Map<String, Object> expected = new HashMap<>();
    expected.put(CLUSTER_NAME, "name2");
    expected.put(CLUSTER_CRN, "crn2");
    Map<String, Object> actual = legacyRestCommonService.addClusterCrnAndNameIfPresent(event);
    assertEquals(expected, actual);
}
Also used : StructuredRestCallEvent(com.sequenceiq.cloudbreak.structuredevent.event.StructuredRestCallEvent) OperationDetails(com.sequenceiq.cloudbreak.structuredevent.event.legacy.OperationDetails) 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 9 with StructuredRestCallEvent

use of com.sequenceiq.cloudbreak.structuredevent.event.StructuredRestCallEvent in project cloudbreak by hortonworks.

the class LegacyRestCommonServiceTest method testWhenNamesAndCrnAreListAndMethodDelete.

@Test
public void testWhenNamesAndCrnAreListAndMethodDelete() {
    StructuredRestCallEvent event = new StructuredRestCallEvent();
    OperationDetails operation = new OperationDetails();
    RestCallDetails restCallDetails = new RestCallDetails();
    RestRequestDetails request = new RestRequestDetails();
    request.setMethod("DELETE");
    request.setBody(new Json(Map.of("names", List.of("names1", "names2"), "crns", List.of("crns1", "crns2"))).getValue());
    RestResponseDetails response = new RestResponseDetails();
    restCallDetails.setRestRequest(request);
    restCallDetails.setRestResponse(response);
    event.setRestCall(restCallDetails);
    event.setOperation(operation);
    Map<String, Object> expected = new HashMap<>();
    expected.put(CLUSTER_NAME, "names1,names2");
    expected.put(CLUSTER_CRN, "crns1,crns2");
    Map<String, Object> actual = legacyRestCommonService.addClusterCrnAndNameIfPresent(event);
    assertEquals(expected, actual);
}
Also used : StructuredRestCallEvent(com.sequenceiq.cloudbreak.structuredevent.event.StructuredRestCallEvent) OperationDetails(com.sequenceiq.cloudbreak.structuredevent.event.legacy.OperationDetails) 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 10 with StructuredRestCallEvent

use of com.sequenceiq.cloudbreak.structuredevent.event.StructuredRestCallEvent in project cloudbreak by hortonworks.

the class LegacyStructuredEventFilter 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);
    CloudbreakUser cloudbreakUser = cloudbreakRestRequestThreadLocalService.getCloudbreakUser();
    if (cloudbreakUser == null) {
        String serviceId = authenticatedUserService.getServiceAccountId();
        cloudbreakUser = new CloudbreakUser(serviceId, serviceId, serviceId, serviceId, serviceId);
    }
    Long workspaceId = cloudbreakRestRequestThreadLocalService.getRequestedWorkspaceId();
    legacyStructuredEventClient.sendStructuredEvent(new StructuredRestCallEvent(createOperationDetails(restParams, requestTime, workspaceId, cloudbreakUser), restCall));
}
Also used : StructuredRestCallEvent(com.sequenceiq.cloudbreak.structuredevent.event.StructuredRestCallEvent) RestCallDetails(com.sequenceiq.cloudbreak.structuredevent.event.rest.RestCallDetails) CloudbreakUser(com.sequenceiq.cloudbreak.common.user.CloudbreakUser)

Aggregations

StructuredRestCallEvent (com.sequenceiq.cloudbreak.structuredevent.event.StructuredRestCallEvent)16 RestCallDetails (com.sequenceiq.cloudbreak.structuredevent.event.rest.RestCallDetails)11 RestRequestDetails (com.sequenceiq.cloudbreak.structuredevent.event.rest.RestRequestDetails)11 Test (org.junit.jupiter.api.Test)9 OperationDetails (com.sequenceiq.cloudbreak.structuredevent.event.legacy.OperationDetails)8 HashMap (java.util.HashMap)8 RestResponseDetails (com.sequenceiq.cloudbreak.structuredevent.event.rest.RestResponseDetails)7 Json (com.sequenceiq.cloudbreak.common.json.Json)5 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)2 Test (org.junit.Test)2 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 RestResourceAuditEventConverter (com.sequenceiq.cloudbreak.structuredevent.auditeventname.rest.RestResourceAuditEventConverter)1 StructuredEvent (com.sequenceiq.cloudbreak.structuredevent.event.StructuredEvent)1 ContainerResponseContext (javax.ws.rs.container.ContainerResponseContext)1 ContainerRequest (org.glassfish.jersey.server.ContainerRequest)1 ContainerResponse (org.glassfish.jersey.server.ContainerResponse)1 SendResult (org.springframework.kafka.support.SendResult)1