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()));
}
}
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;
}
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;
}
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());
}
Aggregations