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