use of com.sequenceiq.cloudbreak.structuredevent.event.cdp.CDPOperationDetails in project cloudbreak by hortonworks.
the class CDPRestCommonServiceTest method testWhenNameAndResourceCrnComeFromTheOperationDetails.
@Test
public void testWhenNameAndResourceCrnComeFromTheOperationDetails() {
RestCallDetails restCallDetails = new RestCallDetails();
RestRequestDetails request = new RestRequestDetails();
RestResponseDetails response = new RestResponseDetails();
response.setBody(new Json(Map.of("responses", List.of(Map.of("name", "name1", "crn", "crn1"), Map.of("name", "name2", "crn", "crn2")))).getValue());
CDPOperationDetails operationDetails = new CDPOperationDetails();
operationDetails.setResourceCrn("opCrn");
operationDetails.setResourceName("opName");
restCallDetails.setRestRequest(request);
restCallDetails.setRestResponse(response);
Map<String, Object> expected = new HashMap<>();
expected.put("names", "opName");
expected.put("crns", "opCrn");
Map<String, String> actual = underTest.collectCrnAndNameIfPresent(restCallDetails, operationDetails, Collections.emptyMap(), "names", "crns");
assertEquals(expected, actual);
}
use of com.sequenceiq.cloudbreak.structuredevent.event.cdp.CDPOperationDetails in project cloudbreak by hortonworks.
the class CDPStructuredEventV1ControllerTest method createTestCDPStructuredEvent.
private CDPStructuredEvent createTestCDPStructuredEvent() {
CDPOperationDetails operationDetails = new CDPOperationDetails();
operationDetails.setResourceCrn("someCrn");
operationDetails.setResourceType("environment");
CDPStructuredEvent cdpStructuredEvent = new CDPStructuredEvent() {
@Override
public String getStatus() {
return SENT;
}
@Override
public Long getDuration() {
return 1L;
}
};
cdpStructuredEvent.setOperation(operationDetails);
return cdpStructuredEvent;
}
use of com.sequenceiq.cloudbreak.structuredevent.event.cdp.CDPOperationDetails in project cloudbreak by hortonworks.
the class FlowCDPEventDataExtractor method shouldAudit.
@Override
public boolean shouldAudit(CDPStructuredEvent structuredEvent) {
CDPOperationDetails operation = structuredEvent.getOperation();
CDPFlowResourceAuditEventConverter flowResourceAuditEventConverter = getConverter(operation.getResourceType());
if (flowResourceAuditEventConverter == null) {
return false;
}
boolean crn = Crn.isCrn(operation.getResourceCrn());
return crn && flowResourceAuditEventConverter.shouldAudit((CDPStructuredFlowEvent) structuredEvent);
}
use of com.sequenceiq.cloudbreak.structuredevent.event.cdp.CDPOperationDetails in project cloudbreak by hortonworks.
the class CDPAuditStructuredEventHandler method accept.
@Override
public void accept(Event<T> structuredEvent) {
try {
T data = structuredEvent.getData();
CDPOperationDetails operation = data.getOperation();
CDPEventDataExtractor<T> extractor = eventDataExtractorMap.get(operation.getEventType().name().toLowerCase() + "CDPEventDataExtractor");
LOGGER.info("Extract audit event as {}", extractor);
AuditEvent event = AuditEvent.builder().withAccountId(operation.getAccountId()).withActor(ActorCrn.builder().withActorCrn(operation.getUserCrn()).build()).withEventData(extractor.eventData(data)).withEventName(extractor.eventName(data)).withEventSource(extractor.eventSource(data)).withSourceIp(extractor.sourceIp(data)).build();
auditClient.createAuditEvent(event);
} catch (UnsupportedOperationException e) {
LOGGER.debug("Audit log is unnecessary: {}", e.getMessage());
} catch (Exception e) {
LOGGER.warn("Cannot perform auditing: {}", e.getMessage(), e);
}
}
use of com.sequenceiq.cloudbreak.structuredevent.event.cdp.CDPOperationDetails in project cloudbreak by hortonworks.
the class EnvironmentStructuredFlowEventFactory method createStructuredFlowEvent.
@Override
public CDPStructuredFlowEvent createStructuredFlowEvent(Long resourceId, FlowDetails flowDetails, Exception exception) {
Environment environment = environmentService.findEnvironmentByIdOrThrow(resourceId);
String resourceType = CloudbreakEventService.ENVIRONMENT_RESOURCE_TYPE;
CDPOperationDetails operationDetails = new CDPOperationDetails(clock.getCurrentTimeMillis(), FLOW, resourceType, environment.getId(), environment.getName(), nodeConfig.getId(), serviceVersion, environment.getAccountId(), environment.getResourceCrn(), environment.getCreator(), environment.getResourceCrn(), null);
EnvironmentDetails environmentDetails = environmentDtoConverter.environmentToDto(environment);
CDPEnvironmentStructuredFlowEvent event = new CDPEnvironmentStructuredFlowEvent(operationDetails, flowDetails, environmentDetails, environment.getStatus().name(), getReason(environment));
if (exception != null) {
event.setException(ExceptionUtils.getStackTrace(exception));
}
return event;
}
Aggregations