Search in sources :

Example 6 with Flow

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

the class AbstractStackFailureAction method createFlowContext.

@Override
protected StackFailureContext createFlowContext(String flowId, StateContext<S, E> stateContext, StackFailureEvent payload) {
    Flow flow = getFlow(flowId);
    StackView stack = stackService.getByIdView(payload.getStackId());
    MDCBuilder.buildMdcContext(stack);
    flow.setFlowFailed(payload.getException());
    return new StackFailureContext(flowId, stack);
}
Also used : StackView(com.sequenceiq.cloudbreak.domain.view.StackView) Flow(com.sequenceiq.cloudbreak.core.flow2.Flow)

Example 7 with Flow

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

the class StackTerminationService method handleStackTerminationError.

public void handleStackTerminationError(StackView stackView, StackFailureEvent payload, boolean forced, Boolean deleteDependencies) {
    String stackUpdateMessage;
    Msg eventMessage;
    DetailedStackStatus status;
    if (!forced) {
        Exception errorDetails = payload.getException();
        stackUpdateMessage = "Termination failed: " + errorDetails.getMessage();
        status = DetailedStackStatus.DELETE_FAILED;
        eventMessage = Msg.STACK_INFRASTRUCTURE_DELETE_FAILED;
        stackUpdater.updateStackStatus(stackView.getId(), status, stackUpdateMessage);
        LOGGER.error("Error during stack termination flow: ", errorDetails);
    } else {
        terminationService.finalizeTermination(stackView.getId(), true);
        clusterService.updateClusterStatusByStackId(stackView.getId(), DELETE_COMPLETED);
        stackUpdateMessage = "Stack was force terminated.";
        status = DetailedStackStatus.DELETE_COMPLETED;
        eventMessage = Msg.STACK_FORCED_DELETE_COMPLETED;
        if (deleteDependencies) {
            dependecyDeletionService.deleteDependencies(stackView);
        }
    }
    flowMessageService.fireEventAndLog(stackView.getId(), eventMessage, status.name(), stackUpdateMessage);
    if (stackView.getClusterView() != null && stackView.getClusterView().getEmailNeeded()) {
        String ambariIp = stackUtil.extractAmbariIp(stackView);
        if (forced) {
            emailSenderService.sendTerminationSuccessEmail(stackView.getClusterView().getOwner(), stackView.getClusterView().getEmailTo(), ambariIp, stackView.getClusterView().getName());
        } else {
            emailSenderService.sendTerminationFailureEmail(stackView.getClusterView().getOwner(), stackView.getClusterView().getEmailTo(), ambariIp, stackView.getClusterView().getName());
        }
        flowMessageService.fireEventAndLog(stackView.getId(), Msg.STACK_NOTIFICATION_EMAIL, status.name());
    }
}
Also used : Msg(com.sequenceiq.cloudbreak.core.flow2.stack.Msg) DetailedStackStatus(com.sequenceiq.cloudbreak.api.model.DetailedStackStatus)

Example 8 with Flow

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

the class ReactorFlowManagerTest method shouldReturnTheNextFailureTransition.

@Test
public void shouldReturnTheNextFailureTransition() {
    InstanceGroupAdjustmentJson instanceGroupAdjustment = new InstanceGroupAdjustmentJson();
    HostGroupAdjustmentJson hostGroupAdjustment = new HostGroupAdjustmentJson();
    underTest.triggerProvisioning(stackId);
    underTest.triggerClusterInstall(stackId);
    underTest.triggerClusterReInstall(stackId);
    underTest.triggerStackStop(stackId);
    underTest.triggerStackStart(stackId);
    underTest.triggerClusterStop(stackId);
    underTest.triggerClusterStart(stackId);
    underTest.triggerTermination(stackId, false, false);
    underTest.triggerTermination(stackId, false, true);
    underTest.triggerStackUpscale(stackId, instanceGroupAdjustment, true);
    underTest.triggerStackDownscale(stackId, instanceGroupAdjustment);
    underTest.triggerStackRemoveInstance(stackId, "hostgroup", "hostname");
    underTest.triggerClusterUpscale(stackId, hostGroupAdjustment);
    underTest.triggerClusterDownscale(stackId, hostGroupAdjustment);
    underTest.triggerClusterSync(stackId);
    underTest.triggerStackSync(stackId);
    underTest.triggerFullSync(stackId);
    underTest.triggerClusterCredentialReplace(stackId, "admin", "admin1");
    underTest.triggerClusterCredentialUpdate(stackId, "admin1");
    underTest.triggerClusterTermination(stackId, false, false);
    underTest.triggerClusterTermination(stackId, true, false);
    underTest.triggerClusterUpgrade(stackId);
    underTest.triggerManualRepairFlow(stackId);
    underTest.triggerStackRepairFlow(stackId, new UnhealthyInstances());
    underTest.triggerClusterRepairFlow(stackId, new HashMap<>(), true);
    underTest.triggerEphemeralUpdate(stackId);
    // Not start from 0 because flow cancellations
    int count = 5;
    for (Method method : underTest.getClass().getDeclaredMethods()) {
        if (method.getName().startsWith("trigger")) {
            count++;
        }
    }
    verify(reactor, times(count)).notify((Object) anyObject(), any(Event.class));
}
Also used : UnhealthyInstances(com.sequenceiq.cloudbreak.service.stack.repair.UnhealthyInstances) Event(reactor.bus.Event) ClusterTerminationEvent(com.sequenceiq.cloudbreak.core.flow2.cluster.termination.ClusterTerminationEvent) HostGroupAdjustmentJson(com.sequenceiq.cloudbreak.api.model.HostGroupAdjustmentJson) InstanceGroupAdjustmentJson(com.sequenceiq.cloudbreak.api.model.InstanceGroupAdjustmentJson) Method(java.lang.reflect.Method) Test(org.junit.Test)

Example 9 with Flow

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

the class Flow2ConfigTest method testFlowConfigurationMapInit.

@Test
public void testFlowConfigurationMapInit() {
    List<FlowConfiguration<?>> flowConfigs = new ArrayList<>();
    flowConfigs.add(new StackSyncFlowConfig());
    flowConfigs.add(new StackTerminationFlowConfig());
    given(this.flowConfigs.iterator()).willReturn(flowConfigs.iterator());
    Map<String, FlowConfiguration<?>> flowConfigMap = underTest.flowConfigurationMap();
    assertEquals("Not all flow type appeared in map!", countEvents(flowConfigs), flowConfigMap.size());
}
Also used : StackSyncFlowConfig(com.sequenceiq.cloudbreak.core.flow2.stack.sync.StackSyncFlowConfig) StackTerminationFlowConfig(com.sequenceiq.cloudbreak.core.flow2.stack.termination.StackTerminationFlowConfig) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 10 with Flow

use of com.sequenceiq.cloudbreak.core.flow2.Flow 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

Flow (com.sequenceiq.cloudbreak.core.flow2.Flow)6 StackFailureContext (com.sequenceiq.cloudbreak.core.flow2.stack.StackFailureContext)2 StackSyncFlowConfig (com.sequenceiq.cloudbreak.core.flow2.stack.sync.StackSyncFlowConfig)2 StackTerminationFlowConfig (com.sequenceiq.cloudbreak.core.flow2.stack.termination.StackTerminationFlowConfig)2 StackView (com.sequenceiq.cloudbreak.domain.view.StackView)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Test (org.junit.Test)2 Event (reactor.bus.Event)2 JsonReader (com.cedarsoftware.util.io.JsonReader)1 DetailedStackStatus (com.sequenceiq.cloudbreak.api.model.DetailedStackStatus)1 HostGroupAdjustmentJson (com.sequenceiq.cloudbreak.api.model.HostGroupAdjustmentJson)1 InstanceGroupAdjustmentJson (com.sequenceiq.cloudbreak.api.model.InstanceGroupAdjustmentJson)1 Acceptable (com.sequenceiq.cloudbreak.cloud.Acceptable)1 Payload (com.sequenceiq.cloudbreak.cloud.event.Payload)1 FlowAdapter (com.sequenceiq.cloudbreak.core.flow2.FlowAdapter)1 FlowEvent (com.sequenceiq.cloudbreak.core.flow2.FlowEvent)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