use of com.sequenceiq.cloudbreak.domain.HostMetadata in project cloudbreak by hortonworks.
the class AmbariHostsJoinStatusCheckerTask method checkStatus.
@Override
public boolean checkStatus(AmbariHostsCheckerContext hosts) {
try {
AmbariClient ambariClient = hosts.getAmbariClient();
Map<String, String> hostNames = ambariClient.getHostStatuses();
for (HostMetadata hostMetadata : hosts.getHostsInCluster()) {
boolean contains = false;
for (Entry<String, String> hostName : hostNames.entrySet()) {
if (hostName.getKey().equals(hostMetadata.getHostName()) && !"UNKNOWN".equals(hostName.getValue())) {
contains = true;
break;
}
}
if (!contains) {
LOGGER.info("The host {} currently not part of the cluster, waiting for join", hostMetadata.getHostName());
return false;
}
}
} catch (Exception ignored) {
LOGGER.info("Did not join all hosts yet, polling");
return false;
}
return true;
}
use of com.sequenceiq.cloudbreak.domain.HostMetadata in project cloudbreak by hortonworks.
the class AppMasterFilter method filter.
@Override
@SuppressWarnings("unchecked")
public List<HostMetadata> filter(long clusterId, Map<String, String> config, List<HostMetadata> hosts) throws HostFilterException {
List<HostMetadata> result = new ArrayList<>(hosts);
try {
String resourceManagerAddress = config.get(ConfigParam.YARN_RM_WEB_ADDRESS.key());
WebTarget target = restClient.target("http://" + resourceManagerAddress + HostFilterService.RM_WS_PATH).path("apps").queryParam("state", "RUNNING");
String appResponse = target.request(MediaType.APPLICATION_JSON).get(String.class);
JsonNode jsonNode = JsonUtil.readTree(appResponse);
JsonNode apps = jsonNode.get(APPS_NODE);
if (apps != null && apps.has(APP_NODE)) {
JsonNode app = apps.get(APP_NODE);
Collection<String> hostsWithAM = new HashSet<>();
for (JsonNode node : app) {
String hostName = node.get(AM_KEY).textValue();
hostsWithAM.add(hostName.substring(0, hostName.lastIndexOf(':')));
}
result = filter(hostsWithAM, result);
}
} catch (Exception e) {
throw new HostFilterException("Error filtering based on ApplicationMaster location", e);
}
return result;
}
use of com.sequenceiq.cloudbreak.domain.HostMetadata in project cloudbreak by hortonworks.
the class ConsulServerFilter method filter.
@Override
public List<HostMetadata> filter(long clusterId, Map<String, String> config, List<HostMetadata> hosts) {
List<HostMetadata> copy = new ArrayList<>(hosts);
Cluster cluster = clusterRepository.findById(clusterId);
for (HostMetadata host : hosts) {
InstanceMetaData instanceMetaData = instanceMetadataRepository.findHostInStack(cluster.getStack().getId(), host.getHostName());
if (instanceMetaData != null && instanceMetaData.getConsulServer()) {
copy.remove(host);
}
}
return copy;
}
use of com.sequenceiq.cloudbreak.domain.HostMetadata in project cloudbreak by hortonworks.
the class HostFilterService method filterHostsForDecommission.
public List<HostMetadata> filterHostsForDecommission(Cluster cluster, Set<HostMetadata> hosts, String hostGroup) {
List<HostMetadata> filteredList = new ArrayList<>(hosts);
LOGGER.info("Ambari service config, hostGroup: {}, originalList: {}", hostGroup, filteredList);
HttpClientConfig clientConfig = tlsSecurityService.buildTLSClientConfigForPrimaryGateway(cluster.getStack().getId(), cluster.getAmbariIp());
AmbariClient ambariClient = ambariClientProvider.getAmbariClient(clientConfig, cluster.getStack().getGatewayPort(), cluster);
Map<String, String> config = configurationService.getConfiguration(ambariClient, hostGroup);
LOGGER.info("Ambari service config, hostGroup: {}, config: {}", hostGroup, config);
for (HostFilter hostFilter : hostFilters) {
try {
filteredList = hostFilter.filter(cluster.getId(), config, filteredList);
LOGGER.info("Filtered with hostfilter: {}, filteredList: {}", hostFilter.getClass().getSimpleName(), filteredList);
} catch (HostFilterException e) {
LOGGER.warn("Filter didn't succeed, moving to next filter", e);
}
}
LOGGER.info("Returned filtered hosts: {}", filteredList);
return filteredList;
}
use of com.sequenceiq.cloudbreak.domain.HostMetadata in project cloudbreak by hortonworks.
the class HostGroupAssociationBuilder method buildHostGroupAssociations.
public Map<String, List<Map<String, String>>> buildHostGroupAssociations(Iterable<HostGroup> hostGroups) {
Map<String, List<Map<String, String>>> hostGroupMappings = new HashMap<>();
LOGGER.info("Computing host - hostGroup mappings based on hostGroup - instanceGroup associations");
for (HostGroup hostGroup : hostGroups) {
List<Map<String, String>> hostInfoForHostGroup = new ArrayList<>();
if (hostGroup.getConstraint().getInstanceGroup() != null) {
Map<String, String> topologyMapping = getTopologyMapping(hostGroup);
Long instanceGroupId = hostGroup.getConstraint().getInstanceGroup().getId();
List<InstanceMetaData> metas = instanceMetadataRepository.findAliveInstancesInInstanceGroup(instanceGroupId);
if (metas.isEmpty()) {
for (HostMetadata hostMetadata : hostGroup.getHostMetadata()) {
Map<String, String> hostInfo = new HashMap<>();
hostInfo.put(FQDN, hostMetadata.getHostName());
hostInfoForHostGroup.add(hostInfo);
}
} else {
for (InstanceMetaData meta : metas) {
Map<String, String> hostInfo = new HashMap<>();
hostInfo.put(FQDN, meta.getDiscoveryFQDN());
String localityIndicator = meta.getLocalityIndicator();
if (localityIndicator != null) {
if (topologyMapping.isEmpty()) {
// Azure
if (localityIndicator.startsWith("/")) {
hostInfo.put("rack", meta.getLocalityIndicator());
// Openstack
} else {
hostInfo.put("rack", '/' + meta.getLocalityIndicator());
}
// With topology mapping
} else {
hostInfo.put("hypervisor", meta.getLocalityIndicator());
hostInfo.put("rack", topologyMapping.get(meta.getLocalityIndicator()));
}
}
hostInfoForHostGroup.add(hostInfo);
}
}
} else {
for (HostMetadata hostMetadata : hostGroup.getHostMetadata()) {
Map<String, String> hostInfo = new HashMap<>();
hostInfo.put(FQDN, hostMetadata.getHostName());
hostInfoForHostGroup.add(hostInfo);
}
}
hostGroupMappings.put(hostGroup.getName(), hostInfoForHostGroup);
}
LOGGER.info("Computed host-hostGroup associations: {}", hostGroupMappings);
return hostGroupMappings;
}
Aggregations