Search in sources :

Example 11 with StructuredRestCallEvent

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

the class DatahubRestResourceAuditEventConverterTest method testRequestParametersWhenStackFoundAndScaling.

@Test
public void testRequestParametersWhenStackFoundAndScaling() {
    StructuredRestCallEvent event = new StructuredRestCallEvent();
    OperationDetails operation = new OperationDetails();
    operation.setResourceName("name");
    operation.setWorkspaceId(123L);
    operation.setResourceEvent("scaling");
    event.setOperation(operation);
    RestCallDetails restCall = new RestCallDetails();
    event.setRestCall(restCall);
    RestRequestDetails restRequest = new RestRequestDetails();
    restRequest.setMethod("PUT");
    restRequest.setBody(new Json(Map.of("group", "gr", "desiredCount", 2)).getValue());
    restCall.setRestRequest(restRequest);
    Stack stack = new Stack();
    Cluster cluster = new Cluster();
    cluster.setId(345L);
    stack.setCluster(cluster);
    HostGroup hostGroup = new HostGroup();
    InstanceGroup instanceGroup = new InstanceGroup();
    hostGroup.setInstanceGroup(instanceGroup);
    Map<String, Object> params = new HashMap<>();
    when(legacyRestCommonService.addClusterCrnAndNameIfPresent(event)).thenReturn(params);
    when(stackService.findStackByNameAndWorkspaceId(operation.getResourceName(), operation.getWorkspaceId())).thenReturn(Optional.of(stack));
    when(hostGroupService.getByClusterIdAndNameWithRecipes(345L, "gr")).thenReturn(hostGroup);
    Map<String, Object> actual = underTest.requestParameters(event);
    Assertions.assertEquals(3, actual.size());
    Assertions.assertEquals(2, actual.get("desiredCount"));
    Assertions.assertEquals(0, actual.get("originalCount"));
    Assertions.assertEquals("gr", actual.get("hostGroup"));
}
Also used : HashMap(java.util.HashMap) RestRequestDetails(com.sequenceiq.cloudbreak.structuredevent.event.rest.RestRequestDetails) Cluster(com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster) HostGroup(com.sequenceiq.cloudbreak.domain.stack.cluster.host.HostGroup) Json(com.sequenceiq.cloudbreak.common.json.Json) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) InstanceGroup(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup) StructuredRestCallEvent(com.sequenceiq.cloudbreak.structuredevent.event.StructuredRestCallEvent) OperationDetails(com.sequenceiq.cloudbreak.structuredevent.event.legacy.OperationDetails) RestCallDetails(com.sequenceiq.cloudbreak.structuredevent.event.rest.RestCallDetails) Test(org.junit.jupiter.api.Test)

Example 12 with StructuredRestCallEvent

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

the class StructuredEventFilterTest method filterWithResponse.

@Test
void filterWithResponse() throws IOException {
    MultivaluedMap<String, String> headersMap = createRequestHeader();
    ContainerRequest requestContext = createRequestContext(headersMap);
    underTest.filter(requestContext);
    requestContext.setProperty("cdp.structuredevent.loggingEnabled", Boolean.TRUE);
    ArgumentCaptor<StructuredRestCallEvent> structuredEventCaptor = ArgumentCaptor.forClass(StructuredRestCallEvent.class);
    doNothing().when(legacyStructuredEventClient).sendStructuredEvent(structuredEventCaptor.capture());
    ContainerResponseContext responseContext = new ContainerResponse(requestContext, Response.accepted().build());
    underTest.filter(requestContext, responseContext);
    StructuredRestCallEvent captorValue = structuredEventCaptor.getValue();
    headersMap.forEach((key, value) -> assertEquals(value.get(0), captorValue.getRestCall().getRestRequest().getHeaders().get(key)));
}
Also used : StructuredRestCallEvent(com.sequenceiq.cloudbreak.structuredevent.event.StructuredRestCallEvent) ContainerResponse(org.glassfish.jersey.server.ContainerResponse) ContainerResponseContext(javax.ws.rs.container.ContainerResponseContext) ContainerRequest(org.glassfish.jersey.server.ContainerRequest) Test(org.junit.jupiter.api.Test)

Example 13 with StructuredRestCallEvent

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

the class KafkaStructuredEventHandlerTest method createDummyStructuredRestEvent.

private StructuredRestCallEvent createDummyStructuredRestEvent() {
    RestRequestDetails requestDetails = new RestRequestDetails();
    requestDetails.setBody("RequestBodyContent");
    requestDetails.setRequestUri("/v3/clusters");
    RestResponseDetails restResponseDetails = new RestResponseDetails();
    restResponseDetails.setStatusCode(200);
    restResponseDetails.setBody("BodyContent");
    restResponseDetails.setHeaders(ImmutableMap.of("content-length", "89"));
    RestCallDetails restCallDetails = new RestCallDetails();
    restCallDetails.setRestRequest(requestDetails);
    restCallDetails.setRestResponse(restResponseDetails);
    StructuredRestCallEvent restEvent = new StructuredRestCallEvent();
    restEvent.setRestCall(restCallDetails);
    restEvent.setType("StructuredRestCallEvent");
    return restEvent;
}
Also used : StructuredRestCallEvent(com.sequenceiq.cloudbreak.structuredevent.event.StructuredRestCallEvent) RestCallDetails(com.sequenceiq.cloudbreak.structuredevent.event.rest.RestCallDetails) RestRequestDetails(com.sequenceiq.cloudbreak.structuredevent.event.rest.RestRequestDetails) RestResponseDetails(com.sequenceiq.cloudbreak.structuredevent.event.rest.RestResponseDetails)

Example 14 with StructuredRestCallEvent

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

the class KafkaStructuredEventHandlerTest method checkIfPropertiesGetFilteredWithCustomMapper.

@Test
public void checkIfPropertiesGetFilteredWithCustomMapper() {
    StructuredRestCallEvent restEvent = createDummyStructuredRestEvent();
    classIntest.sanitizeSensitiveRestData(restEvent);
    RestRequestDetails requestDetails = restEvent.getRestCall().getRestRequest();
    assertTrue("Should be sanitized from Kafka event", requestDetails.getBody().contains(REPLACEMENT));
    assertTrue("Should be empty because of ", requestDetails.getHeaders().isEmpty());
    assertTrue("Should be left intact", requestDetails.getRequestUri().equals("/v3/clusters"));
}
Also used : StructuredRestCallEvent(com.sequenceiq.cloudbreak.structuredevent.event.StructuredRestCallEvent) RestRequestDetails(com.sequenceiq.cloudbreak.structuredevent.event.rest.RestRequestDetails) Test(org.junit.Test)

Example 15 with StructuredRestCallEvent

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

the class RestLegacyEventDataExtractor method shouldAudit.

@Override
public boolean shouldAudit(StructuredEvent structuredEvent) {
    StructuredRestCallEvent event = (StructuredRestCallEvent) structuredEvent;
    String resourceType = event.getOperation().getResourceType();
    if (resourceType != null) {
        RestResourceAuditEventConverter restResourceAuditEventConverter = getConverter(resourceType);
        return restResourceAuditEventConverter != null && restResourceAuditEventConverter.shouldAudit(event);
    }
    return false;
}
Also used : StructuredRestCallEvent(com.sequenceiq.cloudbreak.structuredevent.event.StructuredRestCallEvent) RestResourceAuditEventConverter(com.sequenceiq.cloudbreak.structuredevent.auditeventname.rest.RestResourceAuditEventConverter)

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