Package com.sequenceiq.ambari.client

Examples of com.sequenceiq.ambari.client.AmbariClient


                JsonNode hostGroup = hostGroupsIterator.next();
                if (hostGroup.path("name").isMissingNode()) {
                    throw new BadRequestException("Invalid blueprint: every 'host_group' must have a 'name' attribute.");
                }
            }
            new AmbariClient().validateBlueprint(blueprintText);
        } catch (InvalidBlueprintException e) {
            throw new BadRequestException("Invalid Blueprint: At least one host group with 'slave_' prefix is required in the blueprint.", e);
        } catch (IOException e) {
            throw new BadRequestException("Invalid Blueprint: Failed to parse JSON.", e);
        }
View Full Code Here


    @Override
    public String getClusterJson(String ambariIp, Long stackId) {
        Stack stack = stackRepository.findOne(stackId);
        MDCBuilder.buildMdcContext(stack);
        AmbariClient ambariClient = createAmbariClient(ambariIp);
        try {
            String clusterJson = ambariClient.getClusterAsJson();
            if (clusterJson == null) {
                throw new InternalServerException(String.format("Cluster response coming from Ambari server was null. [Ambari Server IP: '%s']", ambariIp));
            }
            return clusterJson;
        } catch (HttpResponseException e) {
View Full Code Here

        }
    }

    @VisibleForTesting
    protected AmbariClient createAmbariClient(String ambariIp) {
        return new AmbariClient(ambariIp, PORT);
    }
View Full Code Here

    public void waitForAmbariServer(Long stackId, String ambariIp) {
        Stack stack = stackRepository.findById(stackId);
        MDCBuilder.buildMdcContext(stack);
        try {
            boolean ambariRunning = false;
            AmbariClient ambariClient = createAmbariClient(ambariIp);
            int pollingAttempt = 0;
            LOGGER.info("Starting polling of Ambari server's status [Ambari server IP: '{}'].", ambariIp);
            while (!ambariRunning && !(pollingAttempt >= MAX_POLLING_ATTEMPTS)) {
                try {
                    String ambariHealth = ambariClient.healthCheck();
                    LOGGER.info("Ambari health check returned: {} [Ambari server IP: '{}']", ambariHealth, ambariIp);
                    if ("RUNNING".equals(ambariHealth)) {
                        ambariRunning = true;
                    }
                } catch (Exception e) {
View Full Code Here

        }
    }

    @VisibleForTesting
    protected AmbariClient createAmbariClient(String ambariIp) {
        return new AmbariClient(ambariIp);
    }
View Full Code Here

            LOGGER.info("Starting Ambari cluster installation [Ambari server address: {}]", stack.getAmbariIp());
            stackUpdater.updateStackStatus(stack.getId(), Status.UPDATE_IN_PROGRESS);
            cluster.setCreationStarted(new Date().getTime());
            cluster = clusterRepository.save(cluster);
            Blueprint blueprint = cluster.getBlueprint();
            AmbariClient ambariClient = createAmbariClient(stack.getAmbariIp());

            addBlueprint(stack, ambariClient, blueprint);
            Map<String, List<String>> hostGroupMappings = recommend(stack, ambariClient, blueprint.getBlueprintName());
            saveHostMetadata(cluster, hostGroupMappings);
            ambariClient.createCluster(cluster.getName(), blueprint.getBlueprintName(), hostGroupMappings);
            waitForClusterInstall(stack, ambariClient);
            clusterCreateSuccess(cluster, new Date().getTime(), stack.getAmbariIp());
        } catch (AmbariHostsUnavailableException | AmbariOperationFailedException | InvalidHostGroupHostAssociation e) {
            LOGGER.error(e.getMessage(), e);
            clusterCreateFailed(cluster, e.getMessage());
View Full Code Here

        Stack stack = stackRepository.findOneWithLists(stackId);
        Cluster cluster = clusterRepository.findOneWithLists(stack.getCluster().getId());
        MDCBuilder.buildMdcContext(cluster);
        try {
            stackUpdater.updateStackStatus(stack.getId(), Status.UPDATE_IN_PROGRESS);
            AmbariClient ambariClient = createAmbariClient(stack.getAmbariIp());
            waitForHosts(stack, ambariClient);
            Map<String, String> hosts = findHosts(stack.getId(), hostGroupAdjustments);
            addHostMetadata(cluster, hosts);
            Map<String, Integer> installRequests = installServices(hosts, stack, ambariClient);
            waitForAmbariOperations(stack, ambariClient, installRequests);
            ambariClient.startAllServices();
            if (ambariClient.getServiceComponentsMap().containsKey("NAGIOS")) {
                ambariClient.restartServiceComponents("NAGIOS", Arrays.asList("NAGIOS_SERVER"));
            }
            updateHostSuccessful(cluster, hosts.keySet(), false);
        } catch (AmbariHostsUnavailableException | AmbariOperationFailedException e) {
            LOGGER.error(e.getMessage(), e);
            updateHostFailed(cluster, e.getMessage());
View Full Code Here

        Cluster cluster = stack.getCluster();
        MDCBuilder.buildMdcContext(cluster);
        LOGGER.info("Decommision requested");
        try {
            stackUpdater.updateStackStatus(stack.getId(), Status.UPDATE_IN_PROGRESS);
            AmbariClient ambariClient = createAmbariClient(stack.getAmbariIp());
            Set<HostMetadata> metadataToRemove = new HashSet<>();
            for (HostGroupAdjustmentJson hostGroupAdjustment : hosts) {
                LOGGER.info("Decommisioning {} hosts", -1 * hostGroupAdjustment.getScalingAdjustment());
                Set<HostMetadata> hostsInHostGroup = hostMetadataRepository.findHostsInHostgroup(hostGroupAdjustment.getHostGroup(), cluster.getId());
                int i = 0;
                for (HostMetadata hostMetadata : hostsInHostGroup) {
                    String hostName = hostMetadata.getHostName();
                    InstanceMetaData instanceMetaData = instanceMetadataRepository.findHostInStack(stack.getId(), hostName);
                    if (!instanceMetaData.getAmbariServer()) {
                        if (i < -1 * hostGroupAdjustment.getScalingAdjustment()) {
                            LOGGER.info("Host '{}' will be removed from Ambari cluster", hostName);
                            metadataToRemove.add(hostMetadata);
                            Set<String> components = ambariClient.getHostComponentsMap(hostName).keySet();
                            Map<String, Integer> installRequests = new HashMap<>();
                            if (components.contains("NODEMANAGER")) {
                                Integer requestId = ambariClient.decommissionNodeManager(hostName);
                                installRequests.put("NODEMANAGER_DECOMMISION", requestId);
                            }
                            if (components.contains("DATANODE")) {
                                Integer requestId = ambariClient.decommissionDataNode(hostName);
                                installRequests.put("DATANODE_DECOMMISION", requestId);
                            }
                            List<String> componentsList = new ArrayList<>();
                            componentsList.addAll(components);
                            Map<String, Integer> stopRequests = ambariClient.stopComponentsOnHost(hostName, componentsList);
                            installRequests.putAll(stopRequests);
                            waitForAmbariOperations(stack, ambariClient, installRequests);
                            ambariClient.deleteHostComponents(hostName, componentsList);
                            ambariClient.deleteHost(hostName);

                            installRequests = new HashMap<>();
                            Integer zookeeperRequestId = ambariClient.restartServiceComponents("ZOOKEEPER", Arrays.asList("ZOOKEEPER_SERVER"));
                            installRequests.put("ZOOKEEPER", zookeeperRequestId);
                            if (ambariClient.getServiceComponentsMap().containsKey("NAGIOS")) {
                                Integer nagiosRequestId = ambariClient.restartServiceComponents("NAGIOS", Arrays.asList("NAGIOS_SERVER"));
                                installRequests.put("NAGIOS", nagiosRequestId);
                            }
                            waitForAmbariOperations(stack, ambariClient, installRequests);
                        } else {
                            break;
View Full Code Here

        }
    }

    @VisibleForTesting
    protected AmbariClient createAmbariClient(String ambariIp) {
        return new AmbariClient(ambariIp, AmbariClusterService.PORT);
    }
View Full Code Here

    }

    private boolean setClusterState(Stack stack, boolean stopped) {
        MDCBuilder.buildMdcContext(stack);
        boolean result = true;
        AmbariClient ambariClient = new AmbariClient(stack.getAmbariIp(), AmbariClusterService.PORT);
        long stackId = stack.getId();
        String action = stopped ? "stop" : "start";
        int requestId = -1;
        try {
            if (stopped) {
                requestId = ambariClient.stopAllServices();
            } else {
                requestId = ambariClient.startAllServices();
            }
        } catch (Exception e) {
            LOGGER.warn(String.format("Failed to %s Hadoop services", action), e);
            result = false;
        }
View Full Code Here

TOP

Related Classes of com.sequenceiq.ambari.client.AmbariClient

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.