use of com.sequenceiq.cloudbreak.structuredevent.event.StructuredRestCallEvent 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));
}
use of com.sequenceiq.cloudbreak.structuredevent.event.StructuredRestCallEvent in project cloudbreak by hortonworks.
the class KafkaStructuredEventHandlerTest method checkEventTypeBasedTopicDistribution.
@Test
public void checkEventTypeBasedTopicDistribution() throws ExecutionException, InterruptedException {
StructuredRestCallEvent structuredEvent = createDummyStructuredRestEvent();
Event<StructuredEvent> event = new Event<>(structuredEvent);
ListenableFuture<SendResult<String, String>> futures = generateMockFutureWrappers();
when(kafkaTemplate.send(eq("cbStructuredRestCallEvent"), anyString())).thenReturn(futures);
classIntest.accept(event);
verify(kafkaTemplate).send(eq("cbStructuredRestCallEvent"), anyString());
}
use of com.sequenceiq.cloudbreak.structuredevent.event.StructuredRestCallEvent in project cloudbreak by hortonworks.
the class DatahubRestResourceAuditEventConverterTest method testRequestParametersWhenStackNotFound.
@Test
public void testRequestParametersWhenStackNotFound() {
StructuredRestCallEvent event = new StructuredRestCallEvent();
OperationDetails operation = new OperationDetails();
operation.setResourceName("name");
operation.setWorkspaceId(123L);
event.setOperation(operation);
RestCallDetails restCall = new RestCallDetails();
event.setRestCall(restCall);
RestRequestDetails restRequest = new RestRequestDetails();
restCall.setRestRequest(restRequest);
Map<String, Object> params = new HashMap<>();
when(legacyRestCommonService.addClusterCrnAndNameIfPresent(event)).thenReturn(params);
when(stackService.findStackByNameAndWorkspaceId(operation.getResourceName(), operation.getWorkspaceId())).thenReturn(Optional.empty());
Map<String, Object> actual = underTest.requestParameters(event);
Assertions.assertEquals(0, actual.size());
}
use of com.sequenceiq.cloudbreak.structuredevent.event.StructuredRestCallEvent in project cloudbreak by hortonworks.
the class DatahubRestResourceAuditEventConverterTest method testRequestParametersWhenStackFoundButNotScaling.
@Test
public void testRequestParametersWhenStackFoundButNotScaling() {
StructuredRestCallEvent event = new StructuredRestCallEvent();
OperationDetails operation = new OperationDetails();
operation.setResourceName("name");
operation.setWorkspaceId(123L);
event.setOperation(operation);
RestCallDetails restCall = new RestCallDetails();
event.setRestCall(restCall);
RestRequestDetails restRequest = new RestRequestDetails();
restRequest.setMethod("POST");
restCall.setRestRequest(restRequest);
Stack stack = new Stack();
Map<String, Object> params = new HashMap<>();
when(legacyRestCommonService.addClusterCrnAndNameIfPresent(event)).thenReturn(params);
when(stackService.findStackByNameAndWorkspaceId(operation.getResourceName(), operation.getWorkspaceId())).thenReturn(Optional.of(stack));
Map<String, Object> actual = underTest.requestParameters(event);
Assertions.assertEquals(0, actual.size());
}
use of com.sequenceiq.cloudbreak.structuredevent.event.StructuredRestCallEvent in project cloudbreak by hortonworks.
the class LegacyRestCommonServiceTest method testWhenNameAndResourceCrnComeFromTheOperationButExistInRequestAndResponse.
@Test
public void testWhenNameAndResourceCrnComeFromTheOperationButExistInRequestAndResponse() {
StructuredRestCallEvent event = new StructuredRestCallEvent();
OperationDetails operation = new OperationDetails();
operation.setResourceCrn("crn1");
operation.setResourceName("name1");
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, "name1");
expected.put(CLUSTER_CRN, "crn1");
Map<String, Object> actual = legacyRestCommonService.addClusterCrnAndNameIfPresent(event);
assertEquals(expected, actual);
}
Aggregations