Search in sources :

Example 1 with Payload

use of com.sequenceiq.cloudbreak.cloud.event.Payload in project cloudbreak by hortonworks.

the class DisableOnGCPRestartAction method restart.

@Override
public void restart(String flowId, String flowChainId, String event, Object payload) {
    Payload stackPayload = (Payload) payload;
    Stack stack = stackService.getById(stackPayload.getStackId());
    if (stack.getPlatformVariant().equals(GCP)) {
        flowLogService.terminate(stackPayload.getStackId(), flowId);
    } else {
        restart(flowId, flowChainId, event, payload, stack);
    }
}
Also used : Payload(com.sequenceiq.cloudbreak.cloud.event.Payload) Stack(com.sequenceiq.cloudbreak.domain.Stack)

Example 2 with Payload

use of com.sequenceiq.cloudbreak.cloud.event.Payload in project cloudbreak by hortonworks.

the class FillInMemoryStateStoreRestartAction method restart.

@Override
public void restart(String flowId, String flowChainId, String event, Object payload) {
    Payload stackPayload = (Payload) payload;
    Stack stack = stackService.getByIdWithLists(stackPayload.getStackId());
    restart(flowId, flowChainId, event, payload, stack);
}
Also used : Payload(com.sequenceiq.cloudbreak.cloud.event.Payload) Stack(com.sequenceiq.cloudbreak.domain.Stack)

Example 3 with Payload

use of com.sequenceiq.cloudbreak.cloud.event.Payload in project cloudbreak by hortonworks.

the class AbstractStackDownscaleAction method extractInstanceIds.

private Set<String> extractInstanceIds(P payload, Map<Object, Object> variables, Stack stack) {
    if (payload instanceof StackDownscaleTriggerEvent) {
        StackDownscaleTriggerEvent ssc = (StackDownscaleTriggerEvent) payload;
        Set<String> instanceIds;
        if (ssc.getHostNames() == null || ssc.getHostNames().isEmpty()) {
            Map<String, String> unusedInstanceIds = stackScalingService.getUnusedInstanceIds(ssc.getInstanceGroup(), ssc.getAdjustment(), stack);
            instanceIds = new HashSet<>(unusedInstanceIds.keySet());
        } else {
            Set<InstanceMetaData> imds = stack.getInstanceGroupByInstanceGroupName(ssc.getInstanceGroup()).getInstanceMetaData();
            instanceIds = imds.stream().filter(imd -> ssc.getHostNames().contains(imd.getDiscoveryFQDN())).map(InstanceMetaData::getInstanceId).collect(Collectors.toSet());
        }
        variables.put(INSTANCEIDS, instanceIds);
        return instanceIds;
    }
    return getInstanceIds(variables);
}
Also used : InstanceMetaData(com.sequenceiq.cloudbreak.domain.InstanceMetaData) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) AvailabilityZone.availabilityZone(com.sequenceiq.cloudbreak.cloud.model.AvailabilityZone.availabilityZone) StackScaleTriggerEvent(com.sequenceiq.cloudbreak.core.flow2.event.StackScaleTriggerEvent) StackToCloudStackConverter(com.sequenceiq.cloudbreak.converter.spi.StackToCloudStackConverter) Location.location(com.sequenceiq.cloudbreak.cloud.model.Location.location) MDCBuilder(com.sequenceiq.cloudbreak.logger.MDCBuilder) StackFailureEvent(com.sequenceiq.cloudbreak.reactor.api.event.StackFailureEvent) HashSet(java.util.HashSet) Inject(javax.inject.Inject) ResourceToCloudResourceConverter(com.sequenceiq.cloudbreak.converter.spi.ResourceToCloudResourceConverter) StateContext(org.springframework.statemachine.StateContext) AbstractAction(com.sequenceiq.cloudbreak.core.flow2.AbstractAction) Map(java.util.Map) Location(com.sequenceiq.cloudbreak.cloud.model.Location) CredentialToCloudCredentialConverter(com.sequenceiq.cloudbreak.converter.spi.CredentialToCloudCredentialConverter) Stack(com.sequenceiq.cloudbreak.domain.Stack) InstanceMetaData(com.sequenceiq.cloudbreak.domain.InstanceMetaData) StackDownscaleTriggerEvent(com.sequenceiq.cloudbreak.core.flow2.event.StackDownscaleTriggerEvent) Region.region(com.sequenceiq.cloudbreak.cloud.model.Region.region) Set(java.util.Set) CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) Collectors(java.util.stream.Collectors) Payload(com.sequenceiq.cloudbreak.cloud.event.Payload) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) Optional(java.util.Optional) StackService(com.sequenceiq.cloudbreak.service.stack.StackService) StackScalingService(com.sequenceiq.cloudbreak.service.stack.flow.StackScalingService) StackDownscaleTriggerEvent(com.sequenceiq.cloudbreak.core.flow2.event.StackDownscaleTriggerEvent)

Example 4 with Payload

use of com.sequenceiq.cloudbreak.cloud.event.Payload in project cloudbreak by hortonworks.

the class StackStopRestartAction method restart.

@Override
public void restart(String flowId, String flowChainId, String event, Object payload) {
    Payload stackPayload = (Payload) payload;
    Stack stack = stackService.getByIdWithLists(stackPayload.getStackId());
    stackUpdater.updateStackStatus(stack.getId(), DetailedStackStatus.STOP_REQUESTED, stack.getStatusReason());
    super.restart(flowId, flowChainId, event, payload);
}
Also used : Payload(com.sequenceiq.cloudbreak.cloud.event.Payload) Stack(com.sequenceiq.cloudbreak.domain.Stack)

Example 5 with Payload

use of com.sequenceiq.cloudbreak.cloud.event.Payload in project cloudbreak by hortonworks.

the class Flow2Handler method accept.

@Override
public void accept(Event<? extends Payload> event) {
    String key = (String) event.getKey();
    Payload payload = event.getData();
    String flowId = getFlowId(event);
    String flowChainId = getFlowChainId(event);
    switch(key) {
        case FLOW_CANCEL:
            cancelRunningFlows(payload.getStackId());
            break;
        case FLOW_FINAL:
            finalizeFlow(flowId, flowChainId, payload.getStackId());
            break;
        default:
            if (flowId == null) {
                LOGGER.debug("flow trigger arrived: key: {}, payload: {}", key, payload);
                FlowConfiguration<?> flowConfig = flowConfigurationMap.get(key);
                if (flowConfig != null && flowConfig.getFlowTriggerCondition().isFlowTriggerable(payload.getStackId())) {
                    if (!isFlowAcceptable(key, payload)) {
                        LOGGER.info("Flow operation not allowed, other flow is running. Stack ID {}, event {}", payload.getStackId(), key);
                        return;
                    }
                    flowId = UUID.randomUUID().toString();
                    Flow flow = flowConfig.createFlow(flowId, payload.getStackId());
                    flow.initialize();
                    flowLogService.save(flowId, flowChainId, key, payload, null, flowConfig.getClass(), flow.getCurrentState());
                    acceptFlow(payload);
                    pruneMDCContext(flowId);
                    runningFlows.put(flow, flowChainId);
                    flow.sendEvent(key, payload);
                }
            } else {
                LOGGER.debug("flow control event arrived: key: {}, flowid: {}, payload: {}", key, flowId, payload);
                Flow flow = runningFlows.get(flowId);
                if (flow != null) {
                    flowLogService.save(flowId, flowChainId, key, payload, flow.getVariables(), flow.getFlowConfigClass(), flow.getCurrentState());
                    flow.sendEvent(key, payload);
                } else {
                    LOGGER.info("Cancelled flow finished running. Stack ID {}, flow ID {}, event {}", payload.getStackId(), flowId, key);
                }
            }
            break;
    }
}
Also used : Payload(com.sequenceiq.cloudbreak.cloud.event.Payload)

Aggregations

Payload (com.sequenceiq.cloudbreak.cloud.event.Payload)7 Stack (com.sequenceiq.cloudbreak.domain.Stack)5 MDCBuilder (com.sequenceiq.cloudbreak.logger.MDCBuilder)2 Map (java.util.Map)2 Optional (java.util.Optional)2 Set (java.util.Set)2 JsonReader (com.cedarsoftware.util.io.JsonReader)1 Acceptable (com.sequenceiq.cloudbreak.cloud.Acceptable)1 CloudContext (com.sequenceiq.cloudbreak.cloud.context.CloudContext)1 AvailabilityZone.availabilityZone (com.sequenceiq.cloudbreak.cloud.model.AvailabilityZone.availabilityZone)1 CloudCredential (com.sequenceiq.cloudbreak.cloud.model.CloudCredential)1 CloudStack (com.sequenceiq.cloudbreak.cloud.model.CloudStack)1 Location (com.sequenceiq.cloudbreak.cloud.model.Location)1 Location.location (com.sequenceiq.cloudbreak.cloud.model.Location.location)1 Region.region (com.sequenceiq.cloudbreak.cloud.model.Region.region)1 CredentialToCloudCredentialConverter (com.sequenceiq.cloudbreak.converter.spi.CredentialToCloudCredentialConverter)1 ResourceToCloudResourceConverter (com.sequenceiq.cloudbreak.converter.spi.ResourceToCloudResourceConverter)1 StackToCloudStackConverter (com.sequenceiq.cloudbreak.converter.spi.StackToCloudStackConverter)1 AbstractAction (com.sequenceiq.cloudbreak.core.flow2.AbstractAction)1 FlowChainHandler (com.sequenceiq.cloudbreak.core.flow2.chain.FlowChainHandler)1