Search in sources :

Example 1 with StructuredEvent

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

the class CloudbreakEventController method getStructuredEventsZip.

@Override
public Response getStructuredEventsZip(Long stackId) {
    List<StructuredEvent> events = getStructuredEventsForStack(stackId);
    StreamingOutput streamingOutput = output -> {
        try (ZipOutputStream zipOutputStream = new ZipOutputStream(output)) {
            zipOutputStream.putNextEntry(new ZipEntry("struct-events.json"));
            zipOutputStream.write(JsonUtil.writeValueAsString(events).getBytes());
            zipOutputStream.closeEntry();
        }
    };
    return Response.ok(streamingOutput).header("content-disposition", "attachment; filename = struct-events.zip").build();
}
Also used : ZipOutputStream(java.util.zip.ZipOutputStream) Arrays(java.util.Arrays) IdentityUser(com.sequenceiq.cloudbreak.common.model.user.IdentityUser) StreamingOutput(javax.ws.rs.core.StreamingOutput) StructuredEventService(com.sequenceiq.cloudbreak.structuredevent.StructuredEventService) Maps(com.google.common.collect.Maps) Inject(javax.inject.Inject) List(java.util.List) Component(org.springframework.stereotype.Component) Response(javax.ws.rs.core.Response) CloudbreakEventsFacade(com.sequenceiq.cloudbreak.facade.CloudbreakEventsFacade) Map(java.util.Map) CloudbreakEventsJson(com.sequenceiq.cloudbreak.api.model.CloudbreakEventsJson) EventEndpoint(com.sequenceiq.cloudbreak.api.endpoint.v1.EventEndpoint) StructuredEvent(com.sequenceiq.cloudbreak.structuredevent.event.StructuredEvent) ZipEntry(java.util.zip.ZipEntry) JsonUtil(com.sequenceiq.cloudbreak.util.JsonUtil) ZipOutputStream(java.util.zip.ZipOutputStream) StructuredEvent(com.sequenceiq.cloudbreak.structuredevent.event.StructuredEvent) ZipEntry(java.util.zip.ZipEntry) StreamingOutput(javax.ws.rs.core.StreamingOutput)

Example 2 with StructuredEvent

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

the class FlowStructuredEventHandler 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("", flowType, "", flowId, fromId, "unknown", "FLOW_CANCEL", lastStateChange == -1L ? -1L : currentTime - lastStateChange);
        StructuredEvent structuredEvent = structuredFlowEventFactory.createStucturedFlowEvent(stackId, flowDetails, true);
        structuredEventClient.sendStructuredEvent(structuredEvent);
        lastStateChange = currentTime;
    }
}
Also used : StructuredEvent(com.sequenceiq.cloudbreak.structuredevent.event.StructuredEvent) FlowDetails(com.sequenceiq.cloudbreak.structuredevent.event.FlowDetails)

Example 3 with StructuredEvent

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

the class FlowStructuredEventHandler method transition.

@Override
public void transition(Transition<S, E> transition) {
    State<S, E> from = transition.getSource();
    State<S, E> to = transition.getTarget();
    Trigger<S, E> trigger = transition.getTrigger();
    Long currentTime = System.currentTimeMillis();
    String fromId = from != null ? from.getId().toString() : "unknown";
    String toId = to != null ? to.getId().toString() : "unknown";
    String eventId = trigger != null ? trigger.getEvent().toString() : "unknown";
    Boolean detailed = toId.equals(initState.toString()) || toId.equals(finalState.toString());
    FlowDetails flowDetails = new FlowDetails("", flowType, "", flowId, fromId, toId, eventId, lastStateChange == -1L ? -1L : currentTime - lastStateChange);
    StructuredEvent structuredEvent;
    if (exception == null) {
        structuredEvent = structuredFlowEventFactory.createStucturedFlowEvent(stackId, flowDetails, detailed);
    } else {
        structuredEvent = structuredFlowEventFactory.createStucturedFlowEvent(stackId, flowDetails, true, exception);
        exception = null;
    }
    structuredEventClient.sendStructuredEvent(structuredEvent);
    lastStateChange = currentTime;
}
Also used : StructuredEvent(com.sequenceiq.cloudbreak.structuredevent.event.StructuredEvent) FlowDetails(com.sequenceiq.cloudbreak.structuredevent.event.FlowDetails)

Aggregations

StructuredEvent (com.sequenceiq.cloudbreak.structuredevent.event.StructuredEvent)3 FlowDetails (com.sequenceiq.cloudbreak.structuredevent.event.FlowDetails)2 Maps (com.google.common.collect.Maps)1 EventEndpoint (com.sequenceiq.cloudbreak.api.endpoint.v1.EventEndpoint)1 CloudbreakEventsJson (com.sequenceiq.cloudbreak.api.model.CloudbreakEventsJson)1 IdentityUser (com.sequenceiq.cloudbreak.common.model.user.IdentityUser)1 CloudbreakEventsFacade (com.sequenceiq.cloudbreak.facade.CloudbreakEventsFacade)1 StructuredEventService (com.sequenceiq.cloudbreak.structuredevent.StructuredEventService)1 JsonUtil (com.sequenceiq.cloudbreak.util.JsonUtil)1 Arrays (java.util.Arrays)1 List (java.util.List)1 Map (java.util.Map)1 ZipEntry (java.util.zip.ZipEntry)1 ZipOutputStream (java.util.zip.ZipOutputStream)1 Inject (javax.inject.Inject)1 Response (javax.ws.rs.core.Response)1 StreamingOutput (javax.ws.rs.core.StreamingOutput)1 Component (org.springframework.stereotype.Component)1