Search in sources :

Example 76 with Stack

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

the class ClusterStartHandler method accept.

@Override
public void accept(Event<ClusterStartRequest> event) {
    ClusterStartRequest request = event.getData();
    ClusterStartResult result;
    int requestId;
    try {
        Stack stack = stackService.getByIdWithListsInTransaction(request.getResourceId());
        Optional<Stack> datalakeStack = datalakeService.getDatalakeStackByDatahubStack(stack);
        CmTemplateProcessor blueprintProcessor = getCmTemplateProcessor(stack.getCluster());
        if (datalakeStack.isPresent() && clusterServicesRestartService.isRDCRefreshNeeded(stack, datalakeStack.get())) {
            requestId = clusterServicesRestartService.refreshClusterOnStart(stack, datalakeStack.get(), blueprintProcessor);
        } else {
            requestId = apiConnectors.getConnector(stack).startCluster();
        }
        handleStopStartScalingFeature(stack, blueprintProcessor);
        result = new ClusterStartResult(request, requestId);
    } catch (Exception e) {
        result = new ClusterStartResult(e.getMessage(), e, request);
    }
    eventBus.notify(result.selector(), new Event<>(event.getHeaders(), result));
}
Also used : ClusterStartResult(com.sequenceiq.cloudbreak.reactor.api.event.cluster.ClusterStartResult) CmTemplateProcessor(com.sequenceiq.cloudbreak.cmtemplate.CmTemplateProcessor) ClusterStartRequest(com.sequenceiq.cloudbreak.reactor.api.event.cluster.ClusterStartRequest) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack)

Example 77 with Stack

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

the class ClusterStopHandler method accept.

@Override
public void accept(Event<ClusterStopRequest> event) {
    ClusterStopRequest request = event.getData();
    ClusterStopResult result;
    try {
        Stack stack = stackService.getByIdWithListsInTransaction(request.getResourceId());
        boolean clusterManagerRunning = apiConnectors.getConnector(stack).clusterStatusService().isClusterManagerRunning();
        if (clusterManagerRunning) {
            apiConnectors.getConnector(stack).stopCluster(true);
        } else {
            LOGGER.info("Cluster manager isn't running, cannot stop it.");
        }
        result = new ClusterStopResult(request);
    } catch (Exception e) {
        LOGGER.warn("Cannot stop the cluster: ", e);
        result = new ClusterStopResult(e.getMessage(), e, request);
    }
    eventBus.notify(result.selector(), new Event<>(event.getHeaders(), result));
}
Also used : ClusterStopRequest(com.sequenceiq.cloudbreak.reactor.api.event.cluster.ClusterStopRequest) ClusterStopResult(com.sequenceiq.cloudbreak.reactor.api.event.cluster.ClusterStopResult) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack)

Example 78 with Stack

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

the class DeregisterServicesHandler method accept.

@Override
public void accept(Event<DeregisterServicesRequest> event) {
    DeregisterServicesResult result;
    try {
        LOGGER.info("Received DeregisterServicesRequest event: {}", event.getData());
        Stack stack = stackService.getByIdWithListsInTransaction(event.getData().getResourceId());
        ClusterApi clusterApi = clusterApiConnectors.getConnector(stack);
        Optional<DatalakeDto> datalakeDto = Optional.empty();
        Optional<Stack> dataLakeOptional = datalakeService.getDatalakeStackByDatahubStack(stack);
        if (dataLakeOptional.isPresent()) {
            Stack dataLake = dataLakeOptional.get();
            HttpClientConfig httpClientConfig = tlsSecurityService.buildTLSClientConfigForPrimaryGateway(dataLake.getId(), dataLake.getClusterManagerIp(), dataLake.cloudPlatform());
            datalakeDto = Optional.ofNullable(DatalakeDto.DatalakeDtoBuilder.aDatalakeDto().withGatewayPort(dataLake.getGatewayPort()).withHttpClientConfig(httpClientConfig).withPassword(dataLake.getCluster().getCloudbreakAmbariPassword()).withUser(dataLake.getCluster().getCloudbreakAmbariUser()).withName(dataLake.getName()).build());
        }
        clusterApi.clusterSecurityService().deregisterServices(stack.getName(), datalakeDto);
        LOGGER.info("Finished disabling Security");
        result = new DeregisterServicesResult(event.getData());
    } catch (Exception e) {
        LOGGER.warn("An error has occured during disabling security", e);
        result = new DeregisterServicesResult(e.getMessage(), e, event.getData());
    }
    LOGGER.info("Sending out DeregisterServicesResult: {}", result);
    eventBus.notify(result.selector(), new Event<>(event.getHeaders(), result));
    LOGGER.info("DeregisterServicesResult has been sent");
}
Also used : ClusterApi(com.sequenceiq.cloudbreak.cluster.api.ClusterApi) HttpClientConfig(com.sequenceiq.cloudbreak.client.HttpClientConfig) DatalakeDto(com.sequenceiq.cloudbreak.dto.datalake.DatalakeDto) DeregisterServicesResult(com.sequenceiq.cloudbreak.reactor.api.event.cluster.DeregisterServicesResult) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack)

Example 79 with Stack

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

the class DatabaseBackupHandler method doAccept.

@Override
protected Selectable doAccept(HandlerEvent<DatabaseBackupRequest> event) {
    DatabaseBackupRequest request = event.getData();
    Selectable result;
    Long stackId = request.getResourceId();
    LOGGER.debug("Backing up database on stack {}, backup id {}", stackId, request.getBackupId());
    try {
        Stack stack = stackService.getByIdWithListsInTransaction(stackId);
        Cluster cluster = stack.getCluster();
        InstanceMetaData gatewayInstance = stack.getPrimaryGatewayInstance();
        GatewayConfig gatewayConfig = gatewayConfigService.getGatewayConfig(stack, gatewayInstance, cluster.hasGateway());
        Set<String> gatewayFQDN = Collections.singleton(gatewayInstance.getDiscoveryFQDN());
        ExitCriteriaModel exitModel = ClusterDeletionBasedExitCriteriaModel.clusterDeletionBasedModel(stackId, cluster.getId());
        String rangerAdminGroup = rangerVirtualGroupService.getRangerVirtualGroup(stack);
        SaltConfig saltConfig = saltConfigGenerator.createSaltConfig(request.getBackupLocation(), request.getBackupId(), rangerAdminGroup, request.getCloseConnections(), stack);
        hostOrchestrator.backupDatabase(gatewayConfig, gatewayFQDN, stackUtil.collectReachableNodes(stack), saltConfig, exitModel);
        result = new DatabaseBackupSuccess(stackId);
    } catch (Exception e) {
        LOGGER.error("Database backup event failed", e);
        result = new DatabaseBackupFailedEvent(stackId, e, DetailedStackStatus.DATABASE_BACKUP_FAILED);
    }
    return result;
}
Also used : ExitCriteriaModel(com.sequenceiq.cloudbreak.orchestrator.state.ExitCriteriaModel) ClusterDeletionBasedExitCriteriaModel(com.sequenceiq.cloudbreak.core.bootstrap.service.ClusterDeletionBasedExitCriteriaModel) Cluster(com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster) DatabaseBackupRequest(com.sequenceiq.cloudbreak.reactor.api.event.cluster.dr.backup.DatabaseBackupRequest) SaltConfig(com.sequenceiq.cloudbreak.orchestrator.model.SaltConfig) DatabaseBackupFailedEvent(com.sequenceiq.cloudbreak.reactor.api.event.cluster.dr.backup.DatabaseBackupFailedEvent) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) Selectable(com.sequenceiq.cloudbreak.common.event.Selectable) DatabaseBackupSuccess(com.sequenceiq.cloudbreak.reactor.api.event.cluster.dr.backup.DatabaseBackupSuccess) GatewayConfig(com.sequenceiq.cloudbreak.orchestrator.model.GatewayConfig)

Example 80 with Stack

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

the class AmbariStopServerAndAgentHandler method accept.

@Override
public void accept(Event<AmbariStopServerAndAgentRequest> event) {
    AmbariStopServerAndAgentRequest request = event.getData();
    Long stackId = request.getResourceId();
    AmbariStopServerAndAgentResult result;
    try {
        Stack stack = stackService.getByIdWithListsInTransaction(stackId);
        GatewayConfig primaryGatewayConfig = gatewayConfigService.getPrimaryGatewayConfig(stack);
        Set<Node> allNodes = stackUtil.collectNodes(stack);
        hostOrchestrator.stopClusterManagerOnMaster(primaryGatewayConfig, allNodes, clusterDeletionBasedModel(stack.getId(), stack.getCluster().getId()));
        result = new AmbariStopServerAndAgentResult(request);
    } catch (Exception e) {
        String message = "Failed to start ambari agent and/or server on new host.";
        LOGGER.error(message, e);
        result = new AmbariStopServerAndAgentResult(message, e, request);
    }
    eventBus.notify(result.selector(), new Event<>(event.getHeaders(), result));
}
Also used : Node(com.sequenceiq.cloudbreak.common.orchestration.Node) AmbariStopServerAndAgentRequest(com.sequenceiq.cloudbreak.reactor.api.event.cluster.AmbariStopServerAndAgentRequest) AmbariStopServerAndAgentResult(com.sequenceiq.cloudbreak.reactor.api.event.cluster.AmbariStopServerAndAgentResult) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) GatewayConfig(com.sequenceiq.cloudbreak.orchestrator.model.GatewayConfig)

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