Search in sources :

Example 16 with HttpClientConfig

use of com.sequenceiq.cloudbreak.client.HttpClientConfig in project cloudbreak by hortonworks.

the class ClusterServiceRunner method runAmbariServices.

public void runAmbariServices(Long stackId) throws CloudbreakException {
    Stack stack = stackService.getByIdWithLists(stackId);
    Cluster cluster = stack.getCluster();
    Orchestrator orchestrator = stack.getOrchestrator();
    MDCBuilder.buildMdcContext(cluster);
    OrchestratorType orchestratorType = orchestratorTypeResolver.resolveType(orchestrator.getType());
    if (orchestratorType.containerOrchestrator()) {
        Map<String, List<Container>> containers = containerRunner.runClusterContainers(stack);
        Container ambariServerContainer = containers.get(DockerContainer.AMBARI_SERVER.name()).stream().findFirst().get();
        String ambariServerIp = ambariServerContainer.getHost();
        HttpClientConfig ambariClientConfig = buildAmbariClientConfig(stack, ambariServerIp);
        clusterService.updateAmbariClientConfig(cluster.getId(), ambariClientConfig);
        Map<String, List<String>> hostsPerHostGroup = new HashMap<>();
        for (Entry<String, List<Container>> containersEntry : containers.entrySet()) {
            List<String> hostNames = new ArrayList<>();
            for (Container container : containersEntry.getValue()) {
                hostNames.add(container.getHost());
            }
            hostsPerHostGroup.put(containersEntry.getKey(), hostNames);
        }
        clusterService.updateHostMetadata(cluster.getId(), hostsPerHostGroup, HostMetadataState.CONTAINER_RUNNING);
    } else if (orchestratorType.hostOrchestrator()) {
        hostRunner.runAmbariServices(stack, cluster);
        String gatewayIp = gatewayConfigService.getPrimaryGatewayIp(stack);
        HttpClientConfig ambariClientConfig = buildAmbariClientConfig(stack, gatewayIp);
        clusterService.updateAmbariClientConfig(cluster.getId(), ambariClientConfig);
        Map<String, List<String>> hostsPerHostGroup = new HashMap<>();
        for (InstanceMetaData instanceMetaData : stack.getRunningInstanceMetaData()) {
            String groupName = instanceMetaData.getInstanceGroup().getGroupName();
            if (!hostsPerHostGroup.keySet().contains(groupName)) {
                hostsPerHostGroup.put(groupName, new ArrayList<>());
            }
            hostsPerHostGroup.get(groupName).add(instanceMetaData.getDiscoveryFQDN());
        }
        clusterService.updateHostMetadata(cluster.getId(), hostsPerHostGroup, HostMetadataState.SERVICES_RUNNING);
    } else {
        LOGGER.info(String.format("Please implement %s orchestrator because it is not on classpath.", orchestrator.getType()));
        throw new CloudbreakException(String.format("Please implement %s orchestrator because it is not on classpath.", orchestrator.getType()));
    }
}
Also used : HttpClientConfig(com.sequenceiq.cloudbreak.client.HttpClientConfig) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Cluster(com.sequenceiq.cloudbreak.domain.Cluster) OrchestratorType(com.sequenceiq.cloudbreak.common.model.OrchestratorType) Orchestrator(com.sequenceiq.cloudbreak.domain.Orchestrator) Stack(com.sequenceiq.cloudbreak.domain.Stack) InstanceMetaData(com.sequenceiq.cloudbreak.domain.InstanceMetaData) DockerContainer(com.sequenceiq.cloudbreak.orchestrator.container.DockerContainer) Container(com.sequenceiq.cloudbreak.domain.Container) CloudbreakException(com.sequenceiq.cloudbreak.service.CloudbreakException) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) EnumMap(java.util.EnumMap)

Example 17 with HttpClientConfig

use of com.sequenceiq.cloudbreak.client.HttpClientConfig in project cloudbreak by hortonworks.

the class AmbariDecommissioner method decommissionAmbariNodes.

public Set<String> decommissionAmbariNodes(Stack stack, Map<String, HostMetadata> hostsToRemove) throws CloudbreakException {
    Cluster cluster = stack.getCluster();
    HttpClientConfig clientConfig = tlsSecurityService.buildTLSClientConfigForPrimaryGateway(stack.getId(), cluster.getAmbariIp());
    AmbariClient ambariClient = ambariClientProvider.getAmbariClient(clientConfig, stack.getGatewayPort(), cluster);
    Map<String, HostMetadata> unhealthyHosts = new HashMap<>();
    Map<String, HostMetadata> healthyHosts = new HashMap<>();
    for (Entry<String, HostMetadata> hostToRemove : hostsToRemove.entrySet()) {
        if ("UNKNOWN".equals(ambariClient.getHostState(hostToRemove.getKey()))) {
            unhealthyHosts.put(hostToRemove.getKey(), hostToRemove.getValue());
        } else {
            healthyHosts.put(hostToRemove.getKey(), hostToRemove.getValue());
        }
    }
    Set<String> deletedHosts = new HashSet<>();
    Map<String, Map<String, String>> runningComponents = ambariClient.getHostComponentsStates();
    if (!unhealthyHosts.isEmpty()) {
        List<String> hostList = new ArrayList<>(hostsToRemove.keySet());
        removeHostsFromOrchestrator(stack, ambariClient, hostList);
        for (Entry<String, HostMetadata> host : unhealthyHosts.entrySet()) {
            deleteHostFromAmbari(host.getValue(), runningComponents, ambariClient);
            hostMetadataRepository.delete(host.getValue().getId());
            deletedHosts.add(host.getKey());
        }
    }
    if (!healthyHosts.isEmpty()) {
        deletedHosts.addAll(decommissionAmbariNodes(stack, healthyHosts, runningComponents, ambariClient));
    }
    return deletedHosts;
}
Also used : HttpClientConfig(com.sequenceiq.cloudbreak.client.HttpClientConfig) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Cluster(com.sequenceiq.cloudbreak.domain.Cluster) Map(java.util.Map) HashMap(java.util.HashMap) Collections.singletonMap(java.util.Collections.singletonMap) AmbariClient(com.sequenceiq.ambari.client.AmbariClient) HostMetadata(com.sequenceiq.cloudbreak.domain.HostMetadata) HashSet(java.util.HashSet)

Example 18 with HttpClientConfig

use of com.sequenceiq.cloudbreak.client.HttpClientConfig in project cloudbreak by hortonworks.

the class AmbariDecommissioner method collectDownscaleCandidates.

private Iterable<HostMetadata> collectDownscaleCandidates(Stack stack, Cluster cluster, String hostGroupName, Integer scalingAdjustment) {
    List<HostMetadata> downScaleCandidates;
    HttpClientConfig clientConfig = tlsSecurityService.buildTLSClientConfigForPrimaryGateway(stack.getId(), cluster.getAmbariIp());
    HostGroup hostGroup = hostGroupService.getByClusterIdAndName(cluster.getId(), hostGroupName);
    Set<HostMetadata> hostsInHostGroup = hostGroup.getHostMetadata();
    List<HostMetadata> filteredHostList = hostFilterService.filterHostsForDecommission(cluster, hostsInHostGroup, hostGroupName);
    int reservedInstances = hostsInHostGroup.size() - filteredHostList.size();
    String blueprintName = cluster.getBlueprint().getAmbariName();
    AmbariClient ambariClient = ambariClientProvider.getAmbariClient(clientConfig, stack.getGatewayPort(), cluster);
    if (ambariClient.getBlueprintMap(blueprintName).get(hostGroupName).contains(DATANODE)) {
        int replication = getReplicationFactor(ambariClient, hostGroupName);
        verifyNodeCount(replication, scalingAdjustment, filteredHostList.size(), reservedInstances);
        downScaleCandidates = checkAndSortByAvailableSpace(stack, ambariClient, replication, scalingAdjustment, filteredHostList);
    } else {
        verifyNodeCount(NO_REPLICATION, scalingAdjustment, filteredHostList.size(), reservedInstances);
        downScaleCandidates = filteredHostList;
    }
    return downScaleCandidates;
}
Also used : HttpClientConfig(com.sequenceiq.cloudbreak.client.HttpClientConfig) HostGroup(com.sequenceiq.cloudbreak.domain.HostGroup) HostMetadata(com.sequenceiq.cloudbreak.domain.HostMetadata) AmbariClient(com.sequenceiq.ambari.client.AmbariClient)

Example 19 with HttpClientConfig

use of com.sequenceiq.cloudbreak.client.HttpClientConfig in project cloudbreak by hortonworks.

the class TlsSecurityService method buildGatewayConfig.

public GatewayConfig buildGatewayConfig(Long stackId, InstanceMetaData gatewayInstance, Integer gatewayPort, SaltClientConfig saltClientConfig, Boolean knoxGatewayEnabled) {
    SecurityConfig securityConfig = securityConfigRepository.findOneByStackId(stackId);
    String connectionIp = getGatewayIp(securityConfig, gatewayInstance);
    HttpClientConfig conf = buildTLSClientConfig(stackId, connectionIp, gatewayInstance);
    return new GatewayConfig(connectionIp, gatewayInstance.getPublicIpWrapper(), gatewayInstance.getPrivateIp(), gatewayInstance.getDiscoveryFQDN(), gatewayPort, conf.getServerCert(), conf.getClientCert(), conf.getClientKey(), saltClientConfig.getSaltPassword(), saltClientConfig.getSaltBootPassword(), saltClientConfig.getSignatureKeyPem(), knoxGatewayEnabled, InstanceMetadataType.GATEWAY_PRIMARY.equals(gatewayInstance.getInstanceMetadataType()), securityConfig.getSaltSignPrivateKeyDecoded(), securityConfig.getSaltSignPublicKeyDecoded());
}
Also used : HttpClientConfig(com.sequenceiq.cloudbreak.client.HttpClientConfig) SecurityConfig(com.sequenceiq.cloudbreak.domain.SecurityConfig) GatewayConfig(com.sequenceiq.cloudbreak.orchestrator.model.GatewayConfig)

Aggregations

HttpClientConfig (com.sequenceiq.cloudbreak.client.HttpClientConfig)19 AmbariClient (com.sequenceiq.ambari.client.AmbariClient)16 Cluster (com.sequenceiq.cloudbreak.domain.Cluster)11 Stack (com.sequenceiq.cloudbreak.domain.Stack)10 Test (org.junit.Test)9 HashMap (java.util.HashMap)6 HostGroup (com.sequenceiq.cloudbreak.domain.HostGroup)5 HostMetadata (com.sequenceiq.cloudbreak.domain.HostMetadata)4 List (java.util.List)4 Blueprint (com.sequenceiq.cloudbreak.domain.Blueprint)3 ArrayList (java.util.ArrayList)3 LinkedHashMap (java.util.LinkedHashMap)3 Map (java.util.Map)3 CloudbreakException (com.sequenceiq.cloudbreak.service.CloudbreakException)2 Collections.singletonMap (java.util.Collections.singletonMap)2 OrchestratorType (com.sequenceiq.cloudbreak.common.model.OrchestratorType)1 NotFoundException (com.sequenceiq.cloudbreak.controller.NotFoundException)1 Container (com.sequenceiq.cloudbreak.domain.Container)1 InstanceMetaData (com.sequenceiq.cloudbreak.domain.InstanceMetaData)1 Orchestrator (com.sequenceiq.cloudbreak.domain.Orchestrator)1