Search in sources :

Example 11 with HostMetadata

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;
}
Also used : AmbariClient(com.sequenceiq.ambari.client.AmbariClient) HostMetadata(com.sequenceiq.cloudbreak.domain.HostMetadata)

Example 12 with HostMetadata

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;
}
Also used : ArrayList(java.util.ArrayList) JsonNode(com.fasterxml.jackson.databind.JsonNode) WebTarget(javax.ws.rs.client.WebTarget) HostMetadata(com.sequenceiq.cloudbreak.domain.HostMetadata) HashSet(java.util.HashSet)

Example 13 with HostMetadata

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;
}
Also used : InstanceMetaData(com.sequenceiq.cloudbreak.domain.InstanceMetaData) ArrayList(java.util.ArrayList) Cluster(com.sequenceiq.cloudbreak.domain.Cluster) HostMetadata(com.sequenceiq.cloudbreak.domain.HostMetadata)

Example 14 with HostMetadata

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;
}
Also used : HttpClientConfig(com.sequenceiq.cloudbreak.client.HttpClientConfig) ArrayList(java.util.ArrayList) HostMetadata(com.sequenceiq.cloudbreak.domain.HostMetadata) AmbariClient(com.sequenceiq.ambari.client.AmbariClient)

Example 15 with HostMetadata

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;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) HostGroup(com.sequenceiq.cloudbreak.domain.HostGroup) InstanceMetaData(com.sequenceiq.cloudbreak.domain.InstanceMetaData) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) HostMetadata(com.sequenceiq.cloudbreak.domain.HostMetadata)

Aggregations

HostMetadata (com.sequenceiq.cloudbreak.domain.HostMetadata)52 HostGroup (com.sequenceiq.cloudbreak.domain.HostGroup)20 AmbariClient (com.sequenceiq.ambari.client.AmbariClient)17 Cluster (com.sequenceiq.cloudbreak.domain.Cluster)16 HashSet (java.util.HashSet)16 InstanceMetaData (com.sequenceiq.cloudbreak.domain.InstanceMetaData)15 Stack (com.sequenceiq.cloudbreak.domain.Stack)14 Test (org.junit.Test)13 HttpClientConfig (com.sequenceiq.cloudbreak.client.HttpClientConfig)12 ArrayList (java.util.ArrayList)12 HashMap (java.util.HashMap)12 List (java.util.List)10 Map (java.util.Map)10 Status (com.sequenceiq.cloudbreak.api.model.Status)8 Collections.singletonMap (java.util.Collections.singletonMap)8 HostGroupAdjustmentJson (com.sequenceiq.cloudbreak.api.model.HostGroupAdjustmentJson)7 CloudbreakException (com.sequenceiq.cloudbreak.service.CloudbreakException)7 InstanceGroup (com.sequenceiq.cloudbreak.domain.InstanceGroup)6 LinkedHashMap (java.util.LinkedHashMap)5 Set (java.util.Set)5