Search in sources :

Example 6 with FlowConfiguration

use of com.sequenceiq.cloudbreak.core.flow2.config.FlowConfiguration in project cloudbreak by hortonworks.

the class Flow2ConfigTest method testFlowConfigurationMapInitIfAlreadyExists.

@Test
public void testFlowConfigurationMapInitIfAlreadyExists() {
    List<FlowConfiguration<?>> flowConfigs = new ArrayList<>();
    StackSyncFlowConfig stackSyncFlowConfig = new StackSyncFlowConfig();
    flowConfigs.add(stackSyncFlowConfig);
    flowConfigs.add(stackSyncFlowConfig);
    given(this.flowConfigs.iterator()).willReturn(flowConfigs.iterator());
    thrown.expect(UnsupportedOperationException.class);
    thrown.expectMessage("Event already registered: STACK_SYNC_TRIGGER_EVENT");
    underTest.flowConfigurationMap();
}
Also used : StackSyncFlowConfig(com.sequenceiq.cloudbreak.core.flow2.stack.sync.StackSyncFlowConfig) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 7 with FlowConfiguration

use of com.sequenceiq.cloudbreak.core.flow2.config.FlowConfiguration in project cloudbreak by hortonworks.

the class Flow2InitializerTest method testInitialize.

@Test
public void testInitialize() {
    List<FlowConfiguration<?>> flowConfigs = new ArrayList<>();
    flowConfigs.add(new StackSyncFlowConfig());
    flowConfigs.add(new StackTerminationFlowConfig());
    given(this.flowConfigs.stream()).willReturn(flowConfigs.stream());
    underTest.init();
    verify(reactor, times(1)).on(any(Selector.class), any(Consumer.class));
}
Also used : StackSyncFlowConfig(com.sequenceiq.cloudbreak.core.flow2.stack.sync.StackSyncFlowConfig) StackTerminationFlowConfig(com.sequenceiq.cloudbreak.core.flow2.stack.termination.StackTerminationFlowConfig) Consumer(reactor.fn.Consumer) ArrayList(java.util.ArrayList) Selector(reactor.bus.selector.Selector) Test(org.junit.Test)

Example 8 with FlowConfiguration

use of com.sequenceiq.cloudbreak.core.flow2.config.FlowConfiguration in project cloudbreak by hortonworks.

the class Flow2Handler method restartFlow.

public void restartFlow(String flowId) {
    FlowLog flowLog = flowLogRepository.findFirstByFlowIdOrderByCreatedDesc(flowId);
    if (RESTARTABLE_FLOWS.contains(flowLog.getFlowType())) {
        Optional<FlowConfiguration<?>> flowConfig = flowConfigs.stream().filter(fc -> fc.getClass().equals(flowLog.getFlowType())).findFirst();
        Payload payload = (Payload) JsonReader.jsonToJava(flowLog.getPayload());
        Flow flow = flowConfig.get().createFlow(flowId, payload.getStackId());
        runningFlows.put(flow, flowLog.getFlowChainId());
        if (flowLog.getFlowChainId() != null) {
            flowChainHandler.restoreFlowChain(flowLog.getFlowChainId());
        }
        Map<Object, Object> variables = (Map<Object, Object>) JsonReader.jsonToJava(flowLog.getVariables());
        flow.initialize(flowLog.getCurrentState(), variables);
        RestartAction restartAction = flowConfig.get().getRestartAction(flowLog.getNextEvent());
        if (restartAction != null) {
            restartAction.restart(flowId, flowLog.getFlowChainId(), flowLog.getNextEvent(), payload);
            return;
        }
    }
    flowLogService.terminate(flowLog.getStackId(), flowId);
}
Also used : ClusterUpgradeFlowConfig(com.sequenceiq.cloudbreak.core.flow2.cluster.upgrade.ClusterUpgradeFlowConfig) Arrays(java.util.Arrays) FlowConfiguration(com.sequenceiq.cloudbreak.core.flow2.config.FlowConfiguration) StackStopFlowConfig(com.sequenceiq.cloudbreak.core.flow2.stack.stop.StackStopFlowConfig) StackSyncFlowConfig(com.sequenceiq.cloudbreak.core.flow2.stack.sync.StackSyncFlowConfig) LoggerFactory(org.slf4j.LoggerFactory) JsonReader(com.cedarsoftware.util.io.JsonReader) FlowLog(com.sequenceiq.cloudbreak.domain.FlowLog) TERMINATION_EVENT(com.sequenceiq.cloudbreak.core.flow2.stack.termination.StackTerminationEvent.TERMINATION_EVENT) MDCBuilder(com.sequenceiq.cloudbreak.logger.MDCBuilder) Acceptable(com.sequenceiq.cloudbreak.cloud.Acceptable) Inject(javax.inject.Inject) ClusterDownscaleFlowConfig(com.sequenceiq.cloudbreak.core.flow2.cluster.downscale.ClusterDownscaleFlowConfig) ManualStackRepairTriggerFlowConfig(com.sequenceiq.cloudbreak.core.flow2.stack.repair.ManualStackRepairTriggerFlowConfig) Event(reactor.bus.Event) ClusterTerminationFlowConfig(com.sequenceiq.cloudbreak.core.flow2.cluster.termination.ClusterTerminationFlowConfig) ClusterStopFlowConfig(com.sequenceiq.cloudbreak.core.flow2.cluster.stop.ClusterStopFlowConfig) Map(java.util.Map) FlowChains(com.sequenceiq.cloudbreak.core.flow2.chain.FlowChains) FlowLogService(com.sequenceiq.cloudbreak.service.flowlog.FlowLogService) ChangePrimaryGatewayFlowConfig(com.sequenceiq.cloudbreak.core.flow2.cluster.repair.ChangePrimaryGatewayFlowConfig) StackTerminationFlowConfig(com.sequenceiq.cloudbreak.core.flow2.stack.termination.StackTerminationFlowConfig) StackDownscaleConfig(com.sequenceiq.cloudbreak.core.flow2.stack.downscale.StackDownscaleConfig) InstanceTerminationFlowConfig(com.sequenceiq.cloudbreak.core.flow2.stack.instance.termination.InstanceTerminationFlowConfig) Logger(org.slf4j.Logger) ClusterCreationFlowConfig(com.sequenceiq.cloudbreak.core.flow2.cluster.provision.ClusterCreationFlowConfig) ClusterCredentialChangeFlowConfig(com.sequenceiq.cloudbreak.core.flow2.cluster.userpasswd.ClusterCredentialChangeFlowConfig) Resource(javax.annotation.Resource) Set(java.util.Set) ClusterResetFlowConfig(com.sequenceiq.cloudbreak.core.flow2.cluster.reset.ClusterResetFlowConfig) ClusterUpscaleFlowConfig(com.sequenceiq.cloudbreak.core.flow2.cluster.upscale.ClusterUpscaleFlowConfig) UUID(java.util.UUID) StackCreationFlowConfig(com.sequenceiq.cloudbreak.core.flow2.stack.provision.StackCreationFlowConfig) Payload(com.sequenceiq.cloudbreak.cloud.event.Payload) ClusterStartFlowConfig(com.sequenceiq.cloudbreak.core.flow2.cluster.start.ClusterStartFlowConfig) ClusterSyncFlowConfig(com.sequenceiq.cloudbreak.core.flow2.cluster.sync.ClusterSyncFlowConfig) List(java.util.List) Component(org.springframework.stereotype.Component) StackUpscaleConfig(com.sequenceiq.cloudbreak.core.flow2.stack.upscale.StackUpscaleConfig) FlowChainHandler(com.sequenceiq.cloudbreak.core.flow2.chain.FlowChainHandler) LoggerContextKey(com.sequenceiq.cloudbreak.logger.LoggerContextKey) FlowLogRepository(com.sequenceiq.cloudbreak.repository.FlowLogRepository) Optional(java.util.Optional) StackStartFlowConfig(com.sequenceiq.cloudbreak.core.flow2.stack.start.StackStartFlowConfig) Consumer(reactor.fn.Consumer) Collections(java.util.Collections) FlowConfiguration(com.sequenceiq.cloudbreak.core.flow2.config.FlowConfiguration) FlowLog(com.sequenceiq.cloudbreak.domain.FlowLog) Payload(com.sequenceiq.cloudbreak.cloud.event.Payload) Map(java.util.Map)

Aggregations

StackSyncFlowConfig (com.sequenceiq.cloudbreak.core.flow2.stack.sync.StackSyncFlowConfig)4 ArrayList (java.util.ArrayList)4 Flow (com.sequenceiq.cloudbreak.core.flow2.Flow)3 StackTerminationFlowConfig (com.sequenceiq.cloudbreak.core.flow2.stack.termination.StackTerminationFlowConfig)3 Test (org.junit.Test)3 FlowEvent (com.sequenceiq.cloudbreak.core.flow2.FlowEvent)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Consumer (reactor.fn.Consumer)2 JsonReader (com.cedarsoftware.util.io.JsonReader)1 Acceptable (com.sequenceiq.cloudbreak.cloud.Acceptable)1 Payload (com.sequenceiq.cloudbreak.cloud.event.Payload)1 FlowAdapter (com.sequenceiq.cloudbreak.core.flow2.FlowAdapter)1 FlowState (com.sequenceiq.cloudbreak.core.flow2.FlowState)1 FlowChainHandler (com.sequenceiq.cloudbreak.core.flow2.chain.FlowChainHandler)1 FlowChains (com.sequenceiq.cloudbreak.core.flow2.chain.FlowChains)1 ClusterDownscaleFlowConfig (com.sequenceiq.cloudbreak.core.flow2.cluster.downscale.ClusterDownscaleFlowConfig)1 ClusterCreationFlowConfig (com.sequenceiq.cloudbreak.core.flow2.cluster.provision.ClusterCreationFlowConfig)1 ChangePrimaryGatewayFlowConfig (com.sequenceiq.cloudbreak.core.flow2.cluster.repair.ChangePrimaryGatewayFlowConfig)1 ClusterResetFlowConfig (com.sequenceiq.cloudbreak.core.flow2.cluster.reset.ClusterResetFlowConfig)1