Search in sources :

Example 6 with CDPOperationDetails

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);
}
Also used : RestCallDetails(com.sequenceiq.cloudbreak.structuredevent.event.rest.RestCallDetails) HashMap(java.util.HashMap) RestRequestDetails(com.sequenceiq.cloudbreak.structuredevent.event.rest.RestRequestDetails) Json(com.sequenceiq.cloudbreak.common.json.Json) CDPOperationDetails(com.sequenceiq.cloudbreak.structuredevent.event.cdp.CDPOperationDetails) RestResponseDetails(com.sequenceiq.cloudbreak.structuredevent.event.rest.RestResponseDetails) Test(org.junit.jupiter.api.Test)

Example 7 with CDPOperationDetails

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;
}
Also used : CDPStructuredEvent(com.sequenceiq.cloudbreak.structuredevent.event.cdp.CDPStructuredEvent) CDPOperationDetails(com.sequenceiq.cloudbreak.structuredevent.event.cdp.CDPOperationDetails)

Example 8 with CDPOperationDetails

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);
}
Also used : CDPStructuredFlowEvent(com.sequenceiq.cloudbreak.structuredevent.event.cdp.CDPStructuredFlowEvent) CDPFlowResourceAuditEventConverter(com.sequenceiq.cloudbreak.structuredevent.service.audit.auditeventname.flow.CDPFlowResourceAuditEventConverter) CDPOperationDetails(com.sequenceiq.cloudbreak.structuredevent.event.cdp.CDPOperationDetails)

Example 9 with CDPOperationDetails

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);
    }
}
Also used : AuditEvent(com.sequenceiq.cloudbreak.audit.model.AuditEvent) CDPOperationDetails(com.sequenceiq.cloudbreak.structuredevent.event.cdp.CDPOperationDetails)

Example 10 with CDPOperationDetails

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;
}
Also used : CDPEnvironmentStructuredFlowEvent(com.sequenceiq.cloudbreak.structuredevent.event.cdp.environment.CDPEnvironmentStructuredFlowEvent) EnvironmentDetails(com.sequenceiq.cloudbreak.structuredevent.event.cdp.environment.EnvironmentDetails) Environment(com.sequenceiq.environment.environment.domain.Environment) CDPOperationDetails(com.sequenceiq.cloudbreak.structuredevent.event.cdp.CDPOperationDetails)

Aggregations

CDPOperationDetails (com.sequenceiq.cloudbreak.structuredevent.event.cdp.CDPOperationDetails)31 Test (org.junit.jupiter.api.Test)8 CDPStructuredFlowEvent (com.sequenceiq.cloudbreak.structuredevent.event.cdp.CDPStructuredFlowEvent)7 CDPStructuredNotificationEvent (com.sequenceiq.cloudbreak.structuredevent.event.cdp.CDPStructuredNotificationEvent)6 CDPStructuredEvent (com.sequenceiq.cloudbreak.structuredevent.event.cdp.CDPStructuredEvent)5 FlowDetails (com.sequenceiq.cloudbreak.structuredevent.event.FlowDetails)4 CDPStructuredRestCallEvent (com.sequenceiq.cloudbreak.structuredevent.event.cdp.CDPStructuredRestCallEvent)4 Json (com.sequenceiq.cloudbreak.common.json.Json)3 CDPStructuredEventEntity (com.sequenceiq.cloudbreak.structuredevent.domain.CDPStructuredEventEntity)3 CDPStructuredNotificationDetails (com.sequenceiq.cloudbreak.structuredevent.event.cdp.CDPStructuredNotificationDetails)3 CDPEnvironmentStructuredFlowEvent (com.sequenceiq.cloudbreak.structuredevent.event.cdp.environment.CDPEnvironmentStructuredFlowEvent)3 EnvironmentDetails (com.sequenceiq.cloudbreak.structuredevent.event.cdp.environment.EnvironmentDetails)3 RestCallDetails (com.sequenceiq.cloudbreak.structuredevent.event.rest.RestCallDetails)3 UsageProto (com.cloudera.thunderhead.service.common.usage.UsageProto)2 CDPFreeIpaStructuredFlowEvent (com.sequenceiq.cloudbreak.structuredevent.event.cdp.freeipa.CDPFreeIpaStructuredFlowEvent)2 RestRequestDetails (com.sequenceiq.cloudbreak.structuredevent.event.rest.RestRequestDetails)2 RestResponseDetails (com.sequenceiq.cloudbreak.structuredevent.event.rest.RestResponseDetails)2 SdxCluster (com.sequenceiq.datalake.entity.SdxCluster)2 SdxStatusEntity (com.sequenceiq.datalake.entity.SdxStatusEntity)2 Environment (com.sequenceiq.environment.environment.domain.Environment)2