use of com.sequenceiq.cloudbreak.domain.HostMetadata in project cloudbreak by hortonworks.
the class AmbariClusterService method updateHostMetadata.
@Override
public void updateHostMetadata(Long clusterId, Map<String, List<String>> hostsPerHostGroup, HostMetadataState hostMetadataState) {
for (Entry<String, List<String>> hostGroupEntry : hostsPerHostGroup.entrySet()) {
HostGroup hostGroup = hostGroupService.getByClusterIdAndName(clusterId, hostGroupEntry.getKey());
if (hostGroup != null) {
Set<String> existingHosts = hostMetadataRepository.findEmptyHostsInHostGroup(hostGroup.getId()).stream().map(HostMetadata::getHostName).collect(Collectors.toSet());
hostGroupEntry.getValue().stream().filter(hostName -> !existingHosts.contains(hostName)).forEach(hostName -> {
HostMetadata hostMetadataEntry = new HostMetadata();
hostMetadataEntry.setHostName(hostName);
hostMetadataEntry.setHostGroup(hostGroup);
hostMetadataEntry.setHostMetadataState(hostMetadataState);
hostGroup.getHostMetadata().add(hostMetadataEntry);
});
hostGroupService.save(hostGroup);
}
}
}
use of com.sequenceiq.cloudbreak.domain.HostMetadata 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.domain.HostMetadata 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.domain.HostMetadata in project cloudbreak by hortonworks.
the class AmbariClusterModificationService method startCluster.
@Override
public int startCluster(Stack stack) throws CloudbreakException {
AmbariClient ambariClient = clientFactory.getAmbariClient(stack, stack.getCluster());
PollingResult ambariHealthCheckResult = ambariPollingServiceProvider.ambariHealthChecker(stack, ambariClient);
if (isExited(ambariHealthCheckResult)) {
throw new CancellationException("Cluster was terminated while waiting for Ambari to start.");
} else if (isTimeout(ambariHealthCheckResult)) {
throw new CloudbreakException("Ambari server was not restarted properly.");
}
LOGGER.info("Starting Ambari agents on the hosts.");
Set<HostMetadata> hostsInCluster = hostMetadataRepository.findHostsInCluster(stack.getCluster().getId());
PollingResult hostsJoinedResult = ambariPollingServiceProvider.ambariHostJoin(stack, ambariClient, hostsInCluster);
if (isExited(hostsJoinedResult)) {
throw new CancellationException("Cluster was terminated while starting Ambari agents.");
}
LOGGER.info("Start all Hadoop services");
eventService.fireCloudbreakEvent(stack.getId(), UPDATE_IN_PROGRESS.name(), cloudbreakMessagesService.getMessage(AMBARI_CLUSTER_SERVICES_STARTING.code()));
int requestId = ambariClient.startAllServices();
if (requestId == -1) {
LOGGER.error("Failed to start Hadoop services.");
throw new CloudbreakException("Failed to start Hadoop services.");
}
return requestId;
}
use of com.sequenceiq.cloudbreak.domain.HostMetadata in project cloudbreak by hortonworks.
the class TestUtil method hostMetadata.
public static Set<HostMetadata> hostMetadata(HostGroup hostGroup, int count) {
Set<HostMetadata> hostMetadataSet = new HashSet<>();
for (int i = 1; i <= count; i++) {
HostMetadata hostMetadata = new HostMetadata();
hostMetadata.setHostName("hostname-" + (i + 1));
hostMetadata.setHostGroup(hostGroup);
hostMetadataSet.add(hostMetadata);
}
return hostMetadataSet;
}
Aggregations