Search in sources :

Example 71 with AmbariClient

use of com.sequenceiq.ambari.client.AmbariClient 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;
}
Also used : CancellationException(com.sequenceiq.cloudbreak.cloud.scheduler.CancellationException) PollingResult(com.sequenceiq.cloudbreak.service.PollingResult) CloudbreakException(com.sequenceiq.cloudbreak.service.CloudbreakException) AmbariClient(com.sequenceiq.ambari.client.AmbariClient) HostMetadata(com.sequenceiq.cloudbreak.domain.HostMetadata)

Example 72 with AmbariClient

use of com.sequenceiq.ambari.client.AmbariClient in project cloudbreak by hortonworks.

the class AmbariClusterModificationService method stopCluster.

@Override
public void stopCluster(Stack stack) throws CloudbreakException {
    AmbariClient ambariClient = clientFactory.getAmbariClient(stack, stack.getCluster());
    try {
        boolean stopped = true;
        Collection<Map<String, String>> values = ambariClient.getHostComponentsStates().values();
        for (Map<String, String> value : values) {
            for (String state : value.values()) {
                if (!"INSTALLED".equals(state)) {
                    stopped = false;
                }
            }
        }
        if (!stopped) {
            LOGGER.info("Stop all Hadoop services");
            eventService.fireCloudbreakEvent(stack.getId(), UPDATE_IN_PROGRESS.name(), cloudbreakMessagesService.getMessage(AMBARI_CLUSTER_SERVICES_STOPPING.code()));
            int requestId = ambariClient.stopAllServices();
            if (requestId != -1) {
                LOGGER.info("Waiting for Hadoop services to stop on stack");
                PollingResult servicesStopResult = ambariOperationService.waitForOperations(stack, ambariClient, singletonMap("stop services", requestId), STOP_AMBARI_PROGRESS_STATE).getLeft();
                if (isExited(servicesStopResult)) {
                    throw new CancellationException("Cluster was terminated while waiting for Hadoop services to start");
                } else if (isTimeout(servicesStopResult)) {
                    throw new CloudbreakException("Timeout while stopping Ambari services.");
                }
            } else {
                LOGGER.warn("Failed to stop Hadoop services.");
                throw new CloudbreakException("Failed to stop Hadoop services.");
            }
            eventService.fireCloudbreakEvent(stack.getId(), UPDATE_IN_PROGRESS.name(), cloudbreakMessagesService.getMessage(AMBARI_CLUSTER_SERVICES_STOPPED.code()));
        }
    } catch (AmbariConnectionException ignored) {
        LOGGER.debug("Ambari not running on the gateway machine, no need to stop it.");
    }
}
Also used : CancellationException(com.sequenceiq.cloudbreak.cloud.scheduler.CancellationException) PollingResult(com.sequenceiq.cloudbreak.service.PollingResult) CloudbreakException(com.sequenceiq.cloudbreak.service.CloudbreakException) AmbariConnectionException(com.sequenceiq.ambari.client.AmbariConnectionException) Map(java.util.Map) Collections.singletonMap(java.util.Collections.singletonMap) AmbariClient(com.sequenceiq.ambari.client.AmbariClient)

Example 73 with AmbariClient

use of com.sequenceiq.ambari.client.AmbariClient in project cloudbreak by hortonworks.

the class AmbariClusterSecurityService method updateUserNamePassword.

@Override
public void updateUserNamePassword(Stack stack, String newPassword) throws CloudbreakException {
    Cluster cluster = clusterService.getById(stack.getCluster().getId());
    AmbariClient client = clientFactory.getAmbariClient(stack, cluster.getUserName(), cluster.getPassword());
    changeAmbariPassword(cluster.getUserName(), cluster.getPassword(), newPassword, stack, client);
}
Also used : Cluster(com.sequenceiq.cloudbreak.domain.Cluster) AmbariClient(com.sequenceiq.ambari.client.AmbariClient)

Example 74 with AmbariClient

use of com.sequenceiq.ambari.client.AmbariClient in project cloudbreak by hortonworks.

the class AmbariClusterSecurityService method replaceUserNamePassword.

@Override
public void replaceUserNamePassword(Stack stack, String newUserName, String newPassword) throws CloudbreakException {
    AmbariClient ambariClient = clientFactory.getAmbariClient(stack, stack.getCluster().getUserName(), stack.getCluster().getPassword());
    ambariClient = ambariUserHandler.createAmbariUser(newUserName, newPassword, stack, ambariClient);
    ambariClient.deleteUser(stack.getCluster().getUserName());
}
Also used : AmbariClient(com.sequenceiq.ambari.client.AmbariClient)

Example 75 with AmbariClient

use of com.sequenceiq.ambari.client.AmbariClient in project cloudbreak by hortonworks.

the class AmbariClusterSecurityService method disableSecurity.

@Override
public void disableSecurity(Stack stack) {
    try {
        AmbariClient ambariClient = clientFactory.getAmbariClient(stack, stack.getCluster());
        int opId = ambariClient.disableKerberos();
        if (opId == -1) {
            return;
        }
        Map<String, Integer> operationRequests = singletonMap("DISABLE_KERBEROS_REQUEST", opId);
        Pair<PollingResult, Exception> pair = ambariOperationService.waitForOperations(stack, ambariClient, operationRequests, DISABLE_KERBEROS_STATE);
        ambariClusterConnectorPollingResultChecker.checkPollingResult(pair.getLeft(), cloudbreakMessagesService.getMessage(AMBARI_CLUSTER_DISABLE_KERBEROS_FAILED.code()));
    } catch (CancellationException cancellationException) {
        throw cancellationException;
    } catch (Exception e) {
        throw new AmbariOperationFailedException(e.getMessage(), e);
    }
}
Also used : CancellationException(com.sequenceiq.cloudbreak.cloud.scheduler.CancellationException) PollingResult(com.sequenceiq.cloudbreak.service.PollingResult) CloudbreakException(com.sequenceiq.cloudbreak.service.CloudbreakException) CancellationException(com.sequenceiq.cloudbreak.cloud.scheduler.CancellationException) AmbariClient(com.sequenceiq.ambari.client.AmbariClient)

Aggregations

AmbariClient (com.sequenceiq.ambari.client.AmbariClient)78 Test (org.junit.Test)39 Cluster (com.sequenceiq.cloudbreak.domain.Cluster)37 Stack (com.sequenceiq.cloudbreak.domain.Stack)32 HttpClientConfig (com.sequenceiq.cloudbreak.client.HttpClientConfig)23 HostMetadata (com.sequenceiq.cloudbreak.domain.HostMetadata)16 CloudbreakException (com.sequenceiq.cloudbreak.service.CloudbreakException)16 HashMap (java.util.HashMap)16 PollingResult (com.sequenceiq.cloudbreak.service.PollingResult)15 CancellationException (com.sequenceiq.cloudbreak.cloud.scheduler.CancellationException)14 HostGroup (com.sequenceiq.cloudbreak.domain.HostGroup)14 Matchers.anyString (org.mockito.Matchers.anyString)14 Map (java.util.Map)13 AmbariConnectionException (com.sequenceiq.ambari.client.AmbariConnectionException)10 Collections.singletonMap (java.util.Collections.singletonMap)9 HashSet (java.util.HashSet)9 HostGroupAdjustmentJson (com.sequenceiq.cloudbreak.api.model.HostGroupAdjustmentJson)6 Status (com.sequenceiq.cloudbreak.api.model.Status)6 List (java.util.List)6 ImmutablePair (org.apache.commons.lang3.tuple.ImmutablePair)6