Search in sources :

Example 1 with CDPStructuredEvent

use of com.sequenceiq.cloudbreak.structuredevent.event.cdp.CDPStructuredEvent 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 2 with CDPStructuredEvent

use of com.sequenceiq.cloudbreak.structuredevent.event.cdp.CDPStructuredEvent in project cloudbreak by hortonworks.

the class CDPStructuredEventDBService method getPagedEventsOfResources.

@Override
public <T extends CDPStructuredEvent> Page<T> getPagedEventsOfResources(List<StructuredEventType> eventTypes, List<String> resourceCrns, Pageable pageable) {
    LOGGER.debug("Gathering pageable events for types: '{}' and resource CRNs: '{}'", eventTypes, resourceCrns);
    List<StructuredEventType> types = getAllEventTypeIfEmpty(eventTypes);
    try {
        Page<CDPStructuredEventEntity> events = pagingStructuredEventRepository.findByEventTypeInAndResourceCrnIn(types, resourceCrns, pageable);
        return (Page<T>) Optional.ofNullable(events).orElse(Page.empty()).map(event -> cdpStructuredEventEntityToCDPStructuredEventConverter.convert(event));
    } catch (Exception ex) {
        String msg = String.format("Failed get pageable events for types: '%s' and resource CRNs: '%s'", types, resourceCrns);
        LOGGER.warn(msg, ex);
        throw new CloudbreakServiceException(msg, ex);
    }
}
Also used : CDPStructuredEventEntityToCDPStructuredEventConverter(com.sequenceiq.cloudbreak.structuredevent.service.converter.CDPStructuredEventEntityToCDPStructuredEventConverter) CDPStructuredEventService(com.sequenceiq.cloudbreak.structuredevent.service.CDPStructuredEventService) LoggerFactory(org.slf4j.LoggerFactory) JsonUtil(com.sequenceiq.cloudbreak.common.json.JsonUtil) CDPStructuredEvent(com.sequenceiq.cloudbreak.structuredevent.event.cdp.CDPStructuredEvent) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) ValidationResult(com.sequenceiq.cloudbreak.validation.ValidationResult) AccountAwareResourceRepository(com.sequenceiq.cloudbreak.common.dal.repository.AccountAwareResourceRepository) Pageable(org.springframework.data.domain.Pageable) AnonymizerUtil(com.sequenceiq.cloudbreak.common.anonymizer.AnonymizerUtil) CDPStructuredEventRepository(com.sequenceiq.cloudbreak.structuredevent.repository.CDPStructuredEventRepository) Logger(org.slf4j.Logger) CDPPagingStructuredEventRepository(com.sequenceiq.cloudbreak.structuredevent.repository.CDPPagingStructuredEventRepository) Page(org.springframework.data.domain.Page) Crn(com.sequenceiq.cloudbreak.auth.crn.Crn) Collectors(java.util.stream.Collectors) StructuredEventType(com.sequenceiq.cloudbreak.structuredevent.event.StructuredEventType) List(java.util.List) Component(org.springframework.stereotype.Component) CollectionUtils(org.springframework.util.CollectionUtils) CloudbreakServiceException(com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException) Optional(java.util.Optional) CDPStructuredEventToCDPStructuredEventEntityConverter(com.sequenceiq.cloudbreak.structuredevent.service.converter.CDPStructuredEventToCDPStructuredEventEntityConverter) AbstractAccountAwareResourceService(com.sequenceiq.cloudbreak.common.service.account.AbstractAccountAwareResourceService) StringUtils(org.springframework.util.StringUtils) CDPStructuredEventEntity(com.sequenceiq.cloudbreak.structuredevent.domain.CDPStructuredEventEntity) CloudbreakServiceException(com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException) StructuredEventType(com.sequenceiq.cloudbreak.structuredevent.event.StructuredEventType) CDPStructuredEventEntity(com.sequenceiq.cloudbreak.structuredevent.domain.CDPStructuredEventEntity) Page(org.springframework.data.domain.Page) CloudbreakServiceException(com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException)

Example 3 with CDPStructuredEvent

use of com.sequenceiq.cloudbreak.structuredevent.event.cdp.CDPStructuredEvent in project cloudbreak by hortonworks.

the class CDPFlowStructuredEventHandler method buildCdpStructuredEvent.

private CDPStructuredEvent buildCdpStructuredEvent(String fromId, String toId, String eventId, long duration) {
    FlowDetails flowDetails = new FlowDetails(flowChainType, flowType, flowChainId, flowId, fromId, toId, eventId, duration);
    CDPStructuredEvent structuredEvent;
    if (exception == null) {
        structuredEvent = cdpStructuredFlowEventFactory.createStructuredFlowEvent(resourceId, flowDetails);
    } else {
        structuredEvent = cdpStructuredFlowEventFactory.createStructuredFlowEvent(resourceId, flowDetails, exception);
        exception = null;
    }
    return structuredEvent;
}
Also used : FlowDetails(com.sequenceiq.cloudbreak.structuredevent.event.FlowDetails) CDPStructuredEvent(com.sequenceiq.cloudbreak.structuredevent.event.cdp.CDPStructuredEvent)

Example 4 with CDPStructuredEvent

use of com.sequenceiq.cloudbreak.structuredevent.event.cdp.CDPStructuredEvent in project cloudbreak by hortonworks.

the class CDPFlowStructuredEventHandler method stateMachineStopped.

@Override
public void stateMachineStopped(StateMachine<S, E> stateMachine) {
    if (!stateMachine.isComplete()) {
        State<S, E> currentState = stateMachine.getState();
        Long currentTime = System.currentTimeMillis();
        String fromId = currentState != null ? currentState.getId().toString() : "unknown";
        FlowDetails flowDetails = new FlowDetails(flowChainType, flowType, flowChainId, flowId, fromId, "unknown", "FLOW_CANCEL", lastStateChange == null ? 0L : currentTime - lastStateChange);
        CDPStructuredEvent structuredEvent = cdpStructuredFlowEventFactory.createStructuredFlowEvent(resourceId, flowDetails);
        cdpDefaultStructuredEventClient.sendStructuredEvent(structuredEvent);
        lastStateChange = currentTime;
    }
}
Also used : FlowDetails(com.sequenceiq.cloudbreak.structuredevent.event.FlowDetails) CDPStructuredEvent(com.sequenceiq.cloudbreak.structuredevent.event.cdp.CDPStructuredEvent)

Example 5 with CDPStructuredEvent

use of com.sequenceiq.cloudbreak.structuredevent.event.cdp.CDPStructuredEvent in project cloudbreak by hortonworks.

the class CDPFlowStructuredEventHandler method transition.

/**
 * Send a new structured event.
 * @param transition provides information to build the new Structured Event.
 */
@Override
public void transition(Transition<S, E> transition) {
    try {
        String fromId = getFromId(transition);
        String toId = getToId(transition);
        String eventId = getEventId(transition);
        LOGGER.debug("New transition arrived: from: {}, to: {}, eventId: {}, detailed: {}", fromId, toId, eventId, true);
        Long currentTime = System.currentTimeMillis();
        long duration = lastStateChange == null ? 0L : currentTime - lastStateChange;
        LOGGER.debug("Build new CDP structured event");
        CDPStructuredEvent structuredEvent = buildCdpStructuredEvent(fromId, toId, eventId, duration);
        LOGGER.debug("New CDP structured event built, send to all consumers");
        cdpDefaultStructuredEventClient.sendStructuredEvent(structuredEvent);
        LOGGER.debug("CDP structured events sent to all consumers");
        lastStateChange = currentTime;
    } catch (RuntimeException ex) {
        LOGGER.error("Error happened during structured flow event generation! The event won't be stored!", ex);
    }
}
Also used : CDPStructuredEvent(com.sequenceiq.cloudbreak.structuredevent.event.cdp.CDPStructuredEvent)

Aggregations

CDPStructuredEvent (com.sequenceiq.cloudbreak.structuredevent.event.cdp.CDPStructuredEvent)14 CDPOperationDetails (com.sequenceiq.cloudbreak.structuredevent.event.cdp.CDPOperationDetails)5 CDPStructuredEventEntity (com.sequenceiq.cloudbreak.structuredevent.domain.CDPStructuredEventEntity)4 FlowDetails (com.sequenceiq.cloudbreak.structuredevent.event.FlowDetails)4 List (java.util.List)4 Test (org.junit.jupiter.api.Test)4 JsonUtil (com.sequenceiq.cloudbreak.common.json.JsonUtil)3 StructuredEventType (com.sequenceiq.cloudbreak.structuredevent.event.StructuredEventType)3 CDPStructuredRestCallEvent (com.sequenceiq.cloudbreak.structuredevent.event.cdp.CDPStructuredRestCallEvent)3 ArrayList (java.util.ArrayList)3 Inject (javax.inject.Inject)3 Crn (com.sequenceiq.cloudbreak.auth.crn.Crn)2 AnonymizerUtil (com.sequenceiq.cloudbreak.common.anonymizer.AnonymizerUtil)2 AccountAwareResourceRepository (com.sequenceiq.cloudbreak.common.dal.repository.AccountAwareResourceRepository)2 CloudbreakServiceException (com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException)2 AbstractAccountAwareResourceService (com.sequenceiq.cloudbreak.common.service.account.AbstractAccountAwareResourceService)2 CDPPagingStructuredEventRepository (com.sequenceiq.cloudbreak.structuredevent.repository.CDPPagingStructuredEventRepository)2 CDPStructuredEventRepository (com.sequenceiq.cloudbreak.structuredevent.repository.CDPStructuredEventRepository)2 CDPStructuredEventService (com.sequenceiq.cloudbreak.structuredevent.service.CDPStructuredEventService)2 CDPStructuredEventEntityToCDPStructuredEventConverter (com.sequenceiq.cloudbreak.structuredevent.service.converter.CDPStructuredEventEntityToCDPStructuredEventConverter)2