use of com.sequenceiq.cloudbreak.structuredevent.event.cdp.CDPStructuredRestCallEvent 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);
}
}
use of com.sequenceiq.cloudbreak.structuredevent.event.cdp.CDPStructuredRestCallEvent in project cloudbreak by hortonworks.
the class CDPStructuredEventDBServiceTest method testCreateWhenResourceCrnIsNotEmpty.
@Test
public void testCreateWhenResourceCrnIsNotEmpty() {
CDPStructuredEvent event = new CDPStructuredRestCallEvent();
CDPOperationDetails operation = new CDPOperationDetails();
operation.setResourceCrn("crn:cdp:cloudbreak:us-west-1:someone:stack:12345");
event.setOperation(operation);
CDPStructuredEventEntity entity = new CDPStructuredEventEntity();
when(cdpStructuredEventToCDPStructuredEventEntityConverter.convert(event)).thenReturn(entity);
underTest.create(event);
verify(cdpStructuredEventToCDPStructuredEventEntityConverter, Mockito.times(1)).convert(event);
verify(structuredEventRepository, Mockito.times(1)).save(entity);
}
use of com.sequenceiq.cloudbreak.structuredevent.event.cdp.CDPStructuredRestCallEvent in project cloudbreak by hortonworks.
the class CDPStructuredEventDBServiceTest method testCreateWhenResourceCrnIsEmpty.
@Test
public void testCreateWhenResourceCrnIsEmpty() {
CDPStructuredEvent event = new CDPStructuredRestCallEvent();
CDPOperationDetails operation = new CDPOperationDetails();
operation.setResourceCrn("");
event.setOperation(operation);
underTest.create(event);
verify(cdpStructuredEventToCDPStructuredEventEntityConverter, never()).convert(event);
}
use of com.sequenceiq.cloudbreak.structuredevent.event.cdp.CDPStructuredRestCallEvent in project cloudbreak by hortonworks.
the class CDPStructuredEventDBServiceTest method testCreateWhenResourceCrnIsNull.
@Test
public void testCreateWhenResourceCrnIsNull() {
CDPStructuredEvent event = new CDPStructuredRestCallEvent();
CDPOperationDetails operation = new CDPOperationDetails();
operation.setResourceCrn(null);
event.setOperation(operation);
underTest.create(event);
verify(cdpStructuredEventToCDPStructuredEventEntityConverter, never()).convert(event);
}
use of com.sequenceiq.cloudbreak.structuredevent.event.cdp.CDPStructuredRestCallEvent in project cloudbreak by hortonworks.
the class RestCDPEventDataExtractor method shouldAudit.
@Override
public boolean shouldAudit(CDPStructuredEvent structuredEvent) {
CDPStructuredRestCallEvent event = (CDPStructuredRestCallEvent) structuredEvent;
String resourceType = event.getOperation().getResourceType();
if (resourceType != null) {
CDPRestResourceAuditEventConverter restResourceAuditEventConverter = getConverter(resourceType);
return restResourceAuditEventConverter != null && restResourceAuditEventConverter.shouldAudit(event);
}
return false;
}
Aggregations