Search in sources :

Example 36 with Stack

use of com.sequenceiq.cloudbreak.domain.stack.Stack in project cloudbreak by hortonworks.

the class StartExternalDatabaseHandler method doAccept.

@Override
protected Selectable doAccept(HandlerEvent<StartExternalDatabaseRequest> event) {
    LOGGER.debug("In StartExternalDatabaseHandler.doAccept");
    StartExternalDatabaseRequest request = event.getData();
    Stack stack = stackService.getById(request.getResourceId());
    DatabaseAvailabilityType externalDatabase = ObjectUtils.defaultIfNull(stack.getExternalDatabaseCreationType(), DatabaseAvailabilityType.NONE);
    LOGGER.debug("External database: {} for stack {}", externalDatabase.name(), stack.getName());
    LOGGER.debug("Getting environment CRN for stack {}", stack.getName());
    DetailedEnvironmentResponse environment = environmentClientService.getByCrn(stack.getEnvironmentCrn());
    Selectable result;
    try {
        if (StackType.WORKLOAD != stack.getType()) {
            LOGGER.debug("External database start in Cloudbreak service is required for WORKLOAD stacks only.");
            result = new StartExternalDatabaseResult(stack.getId(), EXTERNAL_DATABASE_STARTED_EVENT.event(), stack.getName(), null);
        } else if (externalDatabase.isEmbedded()) {
            LOGGER.info("External database for stack {} is not requested. Start is not possible.", stack.getName());
            result = new StartExternalDatabaseResult(stack.getId(), EXTERNAL_DATABASE_STARTED_EVENT.event(), stack.getName(), null);
        } else if (!externalDatabaseConfig.isExternalDatabasePauseSupportedFor(CloudPlatform.valueOf(environment.getCloudPlatform()))) {
            LOGGER.debug("External database pause is not supported for '{}' cloud platform.", environment.getCloudPlatform());
            result = new StartExternalDatabaseResult(stack.getId(), EXTERNAL_DATABASE_STARTED_EVENT.event(), stack.getName(), null);
        } else {
            LOGGER.debug("Updating stack {} status from {} to {}", stack.getName(), stack.getStatus().name(), DetailedStackStatus.EXTERNAL_DATABASE_START_IN_PROGRESS.name());
            stackUpdaterService.updateStatus(stack.getId(), DetailedStackStatus.EXTERNAL_DATABASE_START_IN_PROGRESS, ResourceEvent.CLUSTER_EXTERNAL_DATABASE_START_COMMANCED, "External database start in progress");
            startService.startDatabase(stack.getCluster(), externalDatabase, environment);
            LOGGER.debug("Updating stack {} status from {} to {}", stack.getName(), stack.getStatus().name(), DetailedStackStatus.EXTERNAL_DATABASE_START_FINISHED.name());
            stackUpdaterService.updateStatus(stack.getId(), DetailedStackStatus.EXTERNAL_DATABASE_START_FINISHED, ResourceEvent.CLUSTER_EXTERNAL_DATABASE_START_FINISHED, "External database start finished");
            result = new StartExternalDatabaseResult(stack.getId(), EXTERNAL_DATABASE_STARTED_EVENT.event(), stack.getName(), stack.getCluster().getDatabaseServerCrn());
        }
    } catch (UserBreakException e) {
        LOGGER.error("Database 'start' polling exited before timeout. Cause: ", e);
        result = startFailedEvent(stack, e);
    } catch (PollerStoppedException e) {
        LOGGER.error(String.format("Database 'start' poller stopped for stack: %s", stack.getName()), e);
        result = startFailedEvent(stack, e);
    } catch (PollerException e) {
        LOGGER.error(String.format("Database 'start' polling failed for stack: %s", stack.getName()), e);
        result = startFailedEvent(stack, e);
    }
    return result;
}
Also used : UserBreakException(com.dyngr.exception.UserBreakException) Selectable(com.sequenceiq.cloudbreak.common.event.Selectable) StartExternalDatabaseResult(com.sequenceiq.cloudbreak.reactor.api.event.externaldatabase.StartExternalDatabaseResult) PollerException(com.dyngr.exception.PollerException) DetailedEnvironmentResponse(com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse) StartExternalDatabaseRequest(com.sequenceiq.cloudbreak.reactor.api.event.externaldatabase.StartExternalDatabaseRequest) PollerStoppedException(com.dyngr.exception.PollerStoppedException) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) DatabaseAvailabilityType(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.database.DatabaseAvailabilityType)

Example 37 with Stack

use of com.sequenceiq.cloudbreak.domain.stack.Stack in project cloudbreak by hortonworks.

the class AbstractExternalDatabaseStopAction method createFlowContext.

@Override
protected ExternalDatabaseContext createFlowContext(FlowParameters flowParameters, StateContext<ExternalDatabaseStopState, ExternalDatabaseStopEvent> stateContext, P payload) {
    Stack stack = stackService.getByIdWithClusterInTransaction(payload.getResourceId());
    MDCBuilder.buildMdcContext(stack);
    beforeReturnFlowContext(flowParameters, stateContext, payload);
    return new ExternalDatabaseContext(flowParameters, stack);
}
Also used : ExternalDatabaseContext(com.sequenceiq.cloudbreak.core.flow2.externaldatabase.ExternalDatabaseContext) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack)

Example 38 with Stack

use of com.sequenceiq.cloudbreak.domain.stack.Stack in project cloudbreak by hortonworks.

the class StopExternalDatabaseHandler method defaultFailureEvent.

@Override
protected Selectable defaultFailureEvent(Long resourceId, Exception e, Event<StopExternalDatabaseRequest> event) {
    Stack stack = stackService.getById(event.getData().getResourceId());
    LOGGER.error(String.format("Exception during DB 'stop' for stack/cluster: %s", stack.getName()), e);
    return stopFailedEvent(stack, e);
}
Also used : Stack(com.sequenceiq.cloudbreak.domain.stack.Stack)

Example 39 with Stack

use of com.sequenceiq.cloudbreak.domain.stack.Stack in project cloudbreak by hortonworks.

the class CmDiagnosticsFlowService method executeCmDiagnosticOperation.

private void executeCmDiagnosticOperation(Long stackId, String operation, Set<String> excludeHosts, CmDiagnosticsFlowOperation func) throws CloudbreakOrchestratorFailedException {
    LOGGER.debug("CM Diagnostics {} will be called only on the primary gateway address", operation);
    Stack stack = stackService.getByIdWithListsInTransaction(stackId);
    List<GatewayConfig> gatewayConfigs = gatewayConfigService.getAllGatewayConfigs(stack);
    String primaryGatewayIp = gatewayConfigService.getPrimaryGatewayIp(stack);
    Set<String> hosts = Set.of(primaryGatewayIp);
    OrchestratorMetadataFilter filter = OrchestratorMetadataFilter.Builder.newBuilder().includeHosts(hosts).exlcudeHosts(excludeHosts).build();
    Set<Node> filteredNodes = filter.apply(stack.getAllNodes());
    ClusterDeletionBasedExitCriteriaModel exitModel = new ClusterDeletionBasedExitCriteriaModel(stackId, stack.getCluster().getId());
    if (filteredNodes.isEmpty()) {
        LOGGER.debug("CM Diagnostics {} has been skipped. (no target minions)", operation);
    } else {
        LOGGER.debug("CM Diagnostics operation '{}' has been started.", operation);
        func.apply(gatewayConfigs, filteredNodes, exitModel);
        LOGGER.debug("CM Diagnostics operation '{}' has been finished.", operation);
    }
}
Also used : OrchestratorMetadataFilter(com.sequenceiq.cloudbreak.orchestrator.metadata.OrchestratorMetadataFilter) Node(com.sequenceiq.cloudbreak.common.orchestration.Node) ClusterDeletionBasedExitCriteriaModel(com.sequenceiq.cloudbreak.core.bootstrap.service.ClusterDeletionBasedExitCriteriaModel) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) GatewayConfig(com.sequenceiq.cloudbreak.orchestrator.model.GatewayConfig)

Example 40 with Stack

use of com.sequenceiq.cloudbreak.domain.stack.Stack in project cloudbreak by hortonworks.

the class ExternalDatabaseTerminationActions method externalDatabaseTermination.

@Bean(name = "WAIT_FOR_EXTERNAL_DATABASE_TERMINATION_STATE")
public Action<?, ?> externalDatabaseTermination() {
    return new AbstractExternalDatabaseTerminationAction<>(TerminationEvent.class) {

        @Override
        protected void doExecute(ExternalDatabaseContext context, TerminationEvent payload, Map<Object, Object> variables) {
            Stack stack = context.getStack();
            TerminateExternalDatabaseRequest request = new TerminateExternalDatabaseRequest(stack.getId(), "TerminateExternalDatabaseRequest", stack.getName(), stack.getResourceCrn(), payload.getTerminationType().isForced());
            sendEvent(context, request);
        }
    };
}
Also used : ExternalDatabaseContext(com.sequenceiq.cloudbreak.core.flow2.externaldatabase.ExternalDatabaseContext) AbstractExternalDatabaseTerminationAction(com.sequenceiq.cloudbreak.core.flow2.externaldatabase.terminate.action.AbstractExternalDatabaseTerminationAction) ExternalDatabaseTerminationEvent(com.sequenceiq.cloudbreak.core.flow2.externaldatabase.terminate.config.ExternalDatabaseTerminationEvent) TerminationEvent(com.sequenceiq.cloudbreak.reactor.api.event.stack.TerminationEvent) Map(java.util.Map) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) TerminateExternalDatabaseRequest(com.sequenceiq.cloudbreak.reactor.api.event.externaldatabase.TerminateExternalDatabaseRequest) Bean(org.springframework.context.annotation.Bean)

Aggregations

Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)1041 Test (org.junit.jupiter.api.Test)326 Cluster (com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster)255 Test (org.junit.Test)208 InstanceMetaData (com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData)158 Map (java.util.Map)114 DetailedEnvironmentResponse (com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse)113 InstanceGroup (com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup)112 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)111 List (java.util.List)101 Set (java.util.Set)101 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)100 Collectors (java.util.stream.Collectors)84 Optional (java.util.Optional)83 HashSet (java.util.HashSet)82 Inject (javax.inject.Inject)80 Logger (org.slf4j.Logger)78 LoggerFactory (org.slf4j.LoggerFactory)78 DetailedStackStatus (com.sequenceiq.cloudbreak.api.endpoint.v4.common.DetailedStackStatus)69 StackStatus (com.sequenceiq.cloudbreak.domain.stack.StackStatus)67