Search in sources :

Example 1 with SUCCESS

use of com.sequenceiq.cloudbreak.polling.PollingResult.SUCCESS in project cloudbreak by hortonworks.

the class RemoveHostsHandler method removeHostsFromOrchestrator.

private PollingResult removeHostsFromOrchestrator(Stack stack, List<String> hostNames, HostOrchestrator hostOrchestrator, List<GatewayConfig> allGatewayConfigs) throws CloudbreakException {
    LOGGER.debug("Remove hosts from orchestrator: {}", hostNames);
    try {
        Map<String, String> removeNodePrivateIPsByFQDN = new HashMap<>();
        stack.getNotTerminatedInstanceMetaDataSet().stream().filter(instanceMetaData -> instanceMetaData.getDiscoveryFQDN() != null).filter(instanceMetaData -> hostNames.stream().anyMatch(hn -> hn.equals(instanceMetaData.getDiscoveryFQDN()))).forEach(instanceMetaData -> removeNodePrivateIPsByFQDN.put(instanceMetaData.getDiscoveryFQDN(), instanceMetaData.getPrivateIp()));
        Set<Node> remainingNodes = stackUtil.collectNodes(stack).stream().filter(node -> !removeNodePrivateIPsByFQDN.containsValue(node.getPrivateIp())).collect(Collectors.toSet());
        ExitCriteriaModel exitCriteriaModel = clusterDeletionBasedModel(stack.getId(), stack.getCluster().getId());
        hostOrchestrator.tearDown(stack, allGatewayConfigs, removeNodePrivateIPsByFQDN, remainingNodes, exitCriteriaModel);
    } catch (CloudbreakOrchestratorException e) {
        LOGGER.error("Failed to delete orchestrator components while decommissioning: ", e);
        throw new CloudbreakException("Removing selected nodes from master node failed, " + "please check if selected nodes are still reachable from master node using terminal and " + "nodes are in sync between CM, CDP and provider side or you can remove selected nodes forcefully.");
    }
    return SUCCESS;
}
Also used : Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) CloudbreakException(com.sequenceiq.cloudbreak.service.CloudbreakException) RemoveHostsRequest(com.sequenceiq.cloudbreak.reactor.api.event.orchestration.RemoveHostsRequest) LoggerFactory(org.slf4j.LoggerFactory) EventSelectorUtil(com.sequenceiq.flow.event.EventSelectorUtil) HashMap(java.util.HashMap) Selectable(com.sequenceiq.cloudbreak.common.event.Selectable) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) Event(reactor.bus.Event) SUCCESS(com.sequenceiq.cloudbreak.polling.PollingResult.SUCCESS) Map(java.util.Map) RemoveHostsFailed(com.sequenceiq.cloudbreak.reactor.api.event.orchestration.RemoveHostsFailed) EventHandler(com.sequenceiq.flow.reactor.api.handler.EventHandler) HostOrchestrator(com.sequenceiq.cloudbreak.orchestrator.host.HostOrchestrator) ClusterDeletionBasedExitCriteriaModel.clusterDeletionBasedModel(com.sequenceiq.cloudbreak.core.bootstrap.service.ClusterDeletionBasedExitCriteriaModel.clusterDeletionBasedModel) Logger(org.slf4j.Logger) Node(com.sequenceiq.cloudbreak.common.orchestration.Node) Set(java.util.Set) ExitCriteriaModel(com.sequenceiq.cloudbreak.orchestrator.state.ExitCriteriaModel) EventBus(reactor.bus.EventBus) CloudbreakOrchestratorException(com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorException) Collectors(java.util.stream.Collectors) GatewayConfigService(com.sequenceiq.cloudbreak.service.GatewayConfigService) List(java.util.List) Component(org.springframework.stereotype.Component) StackUtil(com.sequenceiq.cloudbreak.util.StackUtil) RemoveHostsSuccess(com.sequenceiq.cloudbreak.reactor.api.event.orchestration.RemoveHostsSuccess) GatewayConfig(com.sequenceiq.cloudbreak.orchestrator.model.GatewayConfig) PollingResult(com.sequenceiq.cloudbreak.polling.PollingResult) StackService(com.sequenceiq.cloudbreak.service.stack.StackService) ExitCriteriaModel(com.sequenceiq.cloudbreak.orchestrator.state.ExitCriteriaModel) CloudbreakOrchestratorException(com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorException) HashMap(java.util.HashMap) Node(com.sequenceiq.cloudbreak.common.orchestration.Node) CloudbreakException(com.sequenceiq.cloudbreak.service.CloudbreakException)

Example 2 with SUCCESS

use of com.sequenceiq.cloudbreak.polling.PollingResult.SUCCESS in project cloudbreak by hortonworks.

the class RemoveHostsHandler method removeHostsFromOrchestrator.

private PollingResult removeHostsFromOrchestrator(Stack stack, List<String> hostNames) throws CloudbreakException {
    LOGGER.debug("Remove hosts from orchestrator: [{}]", hostNames);
    try {
        Map<String, String> removeNodePrivateIPsByFQDN = stack.getAllInstanceMetaDataList().stream().filter(instanceMetaData -> Objects.nonNull(instanceMetaData.getDiscoveryFQDN())).filter(instanceMetaData -> hostNames.stream().anyMatch(hn -> hn.equals(instanceMetaData.getDiscoveryFQDN()))).collect(Collectors.toMap(instanceMetaData -> instanceMetaData.getDiscoveryFQDN(), instanceMeataData -> instanceMeataData.getPrivateIp()));
        Set<InstanceMetaData> remainingInstanceMetaDatas = stack.getNotDeletedInstanceMetaDataList().stream().filter(instanceMetaData -> !shouldRemove(instanceMetaData, removeNodePrivateIPsByFQDN)).collect(Collectors.toSet());
        Set<InstanceMetaData> invalidInstanceMetadata = remainingInstanceMetaDatas.stream().filter(instanceMetaData -> Objects.isNull(instanceMetaData.getDiscoveryFQDN())).collect(Collectors.toSet());
        Set<InstanceMetaData> validRemainingNodes = remainingInstanceMetaDatas.stream().filter(instanceMetaData -> Objects.nonNull(instanceMetaData.getDiscoveryFQDN())).collect(Collectors.toSet());
        Set<Node> remainingNodes = validRemainingNodes.stream().map(im -> new Node(im.getPrivateIp(), im.getPublicIp(), im.getInstanceId(), im.getInstanceGroup().getTemplate().getInstanceType(), im.getDiscoveryFQDN(), im.getInstanceGroup().getGroupName())).collect(Collectors.toSet());
        List<GatewayConfig> remainingGatewayConfigs = gatewayConfigService.getGatewayConfigs(stack, validRemainingNodes);
        LOGGER.debug("Tearing down [{}]. The following were dropped because they did not contain a FQDN [{}]. The remaining nodes are [{}].", removeNodePrivateIPsByFQDN, invalidInstanceMetadata, remainingNodes);
        hostOrchestrator.tearDown(stack, remainingGatewayConfigs, removeNodePrivateIPsByFQDN, remainingNodes, new StackBasedExitCriteriaModel(stack.getId()));
    } catch (CloudbreakOrchestratorException e) {
        LOGGER.info("Failed to delete orchestrator components while decommissioning: ", e);
        throw new CloudbreakException("Failed to delete orchestrator components while decommissioning: ", e);
    }
    return SUCCESS;
}
Also used : CloudbreakException(com.sequenceiq.cloudbreak.service.CloudbreakException) LoggerFactory(org.slf4j.LoggerFactory) EventSelectorUtil(com.sequenceiq.flow.event.EventSelectorUtil) Selectable(com.sequenceiq.cloudbreak.common.event.Selectable) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) RemoveHostsFromOrchestrationSuccess(com.sequenceiq.freeipa.flow.freeipa.downscale.event.removehosts.RemoveHostsFromOrchestrationSuccess) Event(reactor.bus.Event) SUCCESS(com.sequenceiq.cloudbreak.polling.PollingResult.SUCCESS) Map(java.util.Map) StackService(com.sequenceiq.freeipa.service.stack.StackService) EventHandler(com.sequenceiq.flow.reactor.api.handler.EventHandler) StackBasedExitCriteriaModel(com.sequenceiq.freeipa.orchestrator.StackBasedExitCriteriaModel) REMOVE_HOSTS_FROM_ORCHESTRATION_FAILED_EVENT(com.sequenceiq.freeipa.flow.freeipa.downscale.DownscaleFlowEvent.REMOVE_HOSTS_FROM_ORCHESTRATION_FAILED_EVENT) InstanceMetaData(com.sequenceiq.freeipa.entity.InstanceMetaData) Stack(com.sequenceiq.freeipa.entity.Stack) HostOrchestrator(com.sequenceiq.cloudbreak.orchestrator.host.HostOrchestrator) RemoveHostsFromOrchestrationRequest(com.sequenceiq.freeipa.flow.freeipa.downscale.event.removehosts.RemoveHostsFromOrchestrationRequest) Logger(org.slf4j.Logger) Node(com.sequenceiq.cloudbreak.common.orchestration.Node) Set(java.util.Set) EventBus(reactor.bus.EventBus) CloudbreakOrchestratorException(com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorException) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) List(java.util.List) Component(org.springframework.stereotype.Component) GatewayConfigService(com.sequenceiq.freeipa.service.GatewayConfigService) DownscaleFailureEvent(com.sequenceiq.freeipa.flow.freeipa.downscale.event.DownscaleFailureEvent) GatewayConfig(com.sequenceiq.cloudbreak.orchestrator.model.GatewayConfig) PollingResult(com.sequenceiq.cloudbreak.polling.PollingResult) BootstrapService(com.sequenceiq.freeipa.service.BootstrapService) InstanceMetaData(com.sequenceiq.freeipa.entity.InstanceMetaData) CloudbreakOrchestratorException(com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorException) Node(com.sequenceiq.cloudbreak.common.orchestration.Node) StackBasedExitCriteriaModel(com.sequenceiq.freeipa.orchestrator.StackBasedExitCriteriaModel) CloudbreakException(com.sequenceiq.cloudbreak.service.CloudbreakException) GatewayConfig(com.sequenceiq.cloudbreak.orchestrator.model.GatewayConfig)

Aggregations

Selectable (com.sequenceiq.cloudbreak.common.event.Selectable)2 Node (com.sequenceiq.cloudbreak.common.orchestration.Node)2 CloudbreakOrchestratorException (com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorException)2 HostOrchestrator (com.sequenceiq.cloudbreak.orchestrator.host.HostOrchestrator)2 GatewayConfig (com.sequenceiq.cloudbreak.orchestrator.model.GatewayConfig)2 PollingResult (com.sequenceiq.cloudbreak.polling.PollingResult)2 SUCCESS (com.sequenceiq.cloudbreak.polling.PollingResult.SUCCESS)2 CloudbreakException (com.sequenceiq.cloudbreak.service.CloudbreakException)2 EventSelectorUtil (com.sequenceiq.flow.event.EventSelectorUtil)2 EventHandler (com.sequenceiq.flow.reactor.api.handler.EventHandler)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Map (java.util.Map)2 Set (java.util.Set)2 Collectors (java.util.stream.Collectors)2 Inject (javax.inject.Inject)2 Logger (org.slf4j.Logger)2 LoggerFactory (org.slf4j.LoggerFactory)2 Component (org.springframework.stereotype.Component)2 Event (reactor.bus.Event)2