Search in sources :

Example 36 with AmbariClient

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

the class AmbariClusterSecurityService method changeOriginalAmbariCredentialsAndCreateCloudbreakUser.

@Override
public void changeOriginalAmbariCredentialsAndCreateCloudbreakUser(Stack stack) throws CloudbreakException {
    Cluster cluster = stack.getCluster();
    LOGGER.info("Changing ambari credentials for cluster: {}, ambari ip: {}", cluster.getName(), cluster.getAmbariIp());
    AmbariClient client = clientFactory.getDefaultAmbariClient(stack);
    String cloudbreakUserName = ambariSecurityConfigProvider.getAmbariUserName(cluster);
    String cloudbreakPassword = ambariSecurityConfigProvider.getAmbariPassword(cluster);
    ambariUserHandler.createAmbariUser(cloudbreakUserName, cloudbreakPassword, stack, client);
    if (ADMIN.equals(cluster.getUserName())) {
        if (!ADMIN.equals(cluster.getPassword())) {
            changeAmbariPassword(ADMIN, ADMIN, cluster.getPassword(), stack, client);
        }
    } else {
        client = ambariUserHandler.createAmbariUser(cluster.getUserName(), cluster.getPassword(), stack, client);
        client.deleteUser(ADMIN);
    }
}
Also used : Cluster(com.sequenceiq.cloudbreak.domain.Cluster) AmbariClient(com.sequenceiq.ambari.client.AmbariClient)

Example 37 with AmbariClient

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

the class AmbariClusterSetupService method buildCluster.

@Override
public void buildCluster(Stack stack) {
    Cluster cluster = stack.getCluster();
    try {
        clusterService.updateCreationDateOnCluster(cluster);
        AmbariClient ambariClient = clientFactory.getAmbariClient(stack, stack.getCluster());
        Set<HostGroup> hostGroups = hostGroupService.getByCluster(cluster.getId());
        BlueprintPreparationObject blueprintPreparationObject = conversionService.convert(stack, BlueprintPreparationObject.class);
        Map<String, List<Map<String, String>>> hostGroupMappings = hostGroupAssociationBuilder.buildHostGroupAssociations(hostGroups);
        Set<HostMetadata> hostsInCluster = hostMetadataRepository.findHostsInCluster(cluster.getId());
        recipeEngine.executePostAmbariStartRecipes(stack, hostGroups);
        ambariRepositoryVersionService.setBaseRepoURL(stack.getName(), cluster.getId(), stack.getOrchestrator(), ambariClient);
        String blueprintText = centralBlueprintUpdater.getBlueprintText(blueprintPreparationObject);
        addBlueprint(stack.getId(), ambariClient, blueprintText, cluster.getTopologyValidation());
        cluster.setExtendedBlueprintText(blueprintText);
        clusterService.updateCluster(cluster);
        PollingResult waitForHostsResult = ambariPollingServiceProvider.hostsPollingService(stack, ambariClient, hostsInCluster);
        ambariClusterConnectorPollingResultChecker.checkPollingResult(waitForHostsResult, cloudbreakMessagesService.getMessage(AMBARI_CLUSTER_HOST_JOIN_FAILED.code()));
        ambariClusterTemplateService.addClusterTemplate(cluster, hostGroupMappings, ambariClient);
        Pair<PollingResult, Exception> pollingResult = ambariOperationService.waitForOperationsToStart(stack, ambariClient, singletonMap("INSTALL_START", 1), START_OPERATION_STATE);
        String message = pollingResult.getRight() == null ? cloudbreakMessagesService.getMessage(AMBARI_CLUSTER_INSTALL_FAILED.code()) : pollingResult.getRight().getMessage();
        ambariClusterConnectorPollingResultChecker.checkPollingResult(pollingResult.getLeft(), message);
        Pair<PollingResult, Exception> pollingResultExceptionPair = ambariOperationService.waitForOperations(stack, ambariClient, new HashMap<String, Integer>() {

            {
                put("CLUSTER_INSTALL", 1);
            }
        }, INSTALL_AMBARI_PROGRESS_STATE);
        ambariClusterConnectorPollingResultChecker.checkPollingResult(pollingResultExceptionPair.getLeft(), cloudbreakMessagesService.getMessage(AMBARI_CLUSTER_INSTALL_FAILED.code()));
        recipeEngine.executePostInstall(stack);
        ambariSmartSenseCapturer.capture(0, ambariClient);
        cluster = ambariViewProvider.provideViewInformation(ambariClient, cluster);
        ambariClusterCreationSuccessHandler.handleClusterCreationSuccess(stack, cluster);
    } catch (CancellationException cancellationException) {
        throw cancellationException;
    } catch (HttpResponseException hre) {
        throw new AmbariOperationFailedException("Ambari could not create the cluster: " + AmbariClientExceptionUtil.getErrorMessage(hre), hre);
    } catch (Exception e) {
        LOGGER.error("Error while building the Ambari cluster. Message {}, throwable: {}", e.getMessage(), e);
        throw new AmbariOperationFailedException(e.getMessage(), e);
    }
}
Also used : Cluster(com.sequenceiq.cloudbreak.domain.Cluster) HostGroup(com.sequenceiq.cloudbreak.domain.HostGroup) HttpResponseException(groovyx.net.http.HttpResponseException) CloudbreakException(com.sequenceiq.cloudbreak.service.CloudbreakException) HttpResponseException(groovyx.net.http.HttpResponseException) CloudbreakSecuritySetupException(com.sequenceiq.cloudbreak.core.CloudbreakSecuritySetupException) CancellationException(com.sequenceiq.cloudbreak.cloud.scheduler.CancellationException) CloudbreakServiceException(com.sequenceiq.cloudbreak.service.CloudbreakServiceException) CancellationException(com.sequenceiq.cloudbreak.cloud.scheduler.CancellationException) PollingResult(com.sequenceiq.cloudbreak.service.PollingResult) BlueprintPreparationObject(com.sequenceiq.cloudbreak.blueprint.BlueprintPreparationObject) List(java.util.List) AmbariClient(com.sequenceiq.ambari.client.AmbariClient) HostMetadata(com.sequenceiq.cloudbreak.domain.HostMetadata)

Example 38 with AmbariClient

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

the class AmbariClusterSetupService method waitForServices.

@Override
public void waitForServices(Stack stack, int requestId) throws CloudbreakException {
    AmbariClient ambariClient = clientFactory.getAmbariClient(stack, stack.getCluster());
    LOGGER.info("Waiting for Hadoop services to start on stack");
    PollingResult servicesStartResult = ambariOperationService.waitForOperations(stack, ambariClient, singletonMap("start services", requestId), START_AMBARI_PROGRESS_STATE).getLeft();
    if (isExited(servicesStartResult)) {
        throw new CancellationException("Cluster was terminated while waiting for Hadoop services to start");
    } else if (isTimeout(servicesStartResult)) {
        throw new CloudbreakException("Timeout while starting Ambari services.");
    }
    eventService.fireCloudbreakEvent(stack.getId(), UPDATE_IN_PROGRESS.name(), cloudbreakMessagesService.getMessage(AMBARI_CLUSTER_SERVICES_STARTED.code()));
}
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)

Example 39 with AmbariClient

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

the class AmbariClusterSetupService method waitForServer.

@Override
public void waitForServer(Stack stack) throws CloudbreakException {
    AmbariClient defaultClient = clientFactory.getDefaultAmbariClient(stack);
    AmbariClient client = clientFactory.getAmbariClient(stack, stack.getCluster());
    PollingResult pollingResult = ambariPollingServiceProvider.ambariStartupPollerObjectPollingService(stack, defaultClient, client);
    if (isSuccess(pollingResult)) {
        LOGGER.info("Ambari has successfully started! Polling result: {}", pollingResult);
    } else if (isExited(pollingResult)) {
        throw new CancellationException("Polling of Ambari server start has been cancelled.");
    } else {
        LOGGER.info("Could not start Ambari. polling result: {}", pollingResult);
        throw new CloudbreakException(String.format("Could not start Ambari. polling result: '%s'", pollingResult));
    }
}
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)

Example 40 with AmbariClient

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

the class ClusterCreationEvaluator method ambariHealthCheck.

private void ambariHealthCheck(PeriscopeUser user, AmbariStack ambariStack) {
    String host = ambariStack.getAmbari().getHost();
    try {
        AmbariClient client = ambariClientProvider.createAmbariClient(new Cluster(user, ambariStack));
        String healthCheckResult = client.healthCheck();
        if (!"RUNNING".equals(healthCheckResult)) {
            throw new AmbariHealtCheckException(String.format("Ambari on host '%s' is not in 'RUNNING' state.", host));
        }
    } catch (Exception ex) {
        throw new AmbariHealtCheckException(String.format("Health check failed on host '%s':", host), ex);
    }
}
Also used : Cluster(com.sequenceiq.periscope.domain.Cluster) TlsConfigurationException(com.sequenceiq.periscope.service.security.TlsConfigurationException) 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