Search in sources :

Example 6 with PollingResult

use of com.sequenceiq.cloudbreak.service.PollingResult in project cloudbreak by hortonworks.

the class AmbariClusterSecurityService method prepareSecurity.

@Override
public void prepareSecurity(Stack stack) {
    try {
        AmbariClient ambariClient = clientFactory.getAmbariClient(stack, stack.getCluster());
        Map<String, Integer> operationRequests = new HashMap<>();
        Stream.of("ZOOKEEPER", "HDFS", "YARN", "MAPREDUCE2", "KERBEROS").forEach(s -> {
            int opId = s.equals("ZOOKEEPER") ? ambariClient.startService(s) : ambariClient.stopService(s);
            if (opId != -1) {
                operationRequests.put(s + "_SERVICE_STATE", opId);
            }
        });
        if (operationRequests.isEmpty()) {
            return;
        }
        Pair<PollingResult, Exception> pair = ambariOperationService.waitForOperations(stack, ambariClient, operationRequests, PREPARE_DEKERBERIZING);
        ambariClusterConnectorPollingResultChecker.checkPollingResult(pair.getLeft(), cloudbreakMessagesService.getMessage(AMBARI_CLUSTER_PREPARE_DEKERBERIZING_FAILED.code()));
    } catch (CancellationException cancellationException) {
        throw cancellationException;
    } catch (Exception e) {
        throw new AmbariOperationFailedException(e.getMessage(), e);
    }
}
Also used : HashMap(java.util.HashMap) 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)

Example 7 with PollingResult

use of com.sequenceiq.cloudbreak.service.PollingResult 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 8 with PollingResult

use of com.sequenceiq.cloudbreak.service.PollingResult 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 9 with PollingResult

use of com.sequenceiq.cloudbreak.service.PollingResult 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 10 with PollingResult

use of com.sequenceiq.cloudbreak.service.PollingResult in project cloudbreak by hortonworks.

the class AmbariClusterSecurityServiceTest method testPrepareSecurityWhenExceptionOccursWhichNotCancellationThenShouldThrowAmbariOperationFailedException.

@Test
public void testPrepareSecurityWhenExceptionOccursWhichNotCancellationThenShouldThrowAmbariOperationFailedException() throws CloudbreakException {
    Stack stack = TestUtil.stack();
    Cluster cluster = TestUtil.cluster();
    stack.setCluster(cluster);
    AmbariClient ambariClient = Mockito.mock(AmbariClient.class);
    when(clientFactory.getAmbariClient(stack, stack.getCluster())).thenReturn(ambariClient);
    when(ambariClient.startService(anyString())).thenReturn(1);
    when(ambariClient.stopService(anyString())).thenReturn(1);
    Map<String, Integer> operationRequests = new HashMap<>();
    operationRequests.put("ZOOKEEPER_SERVICE_STATE", 1);
    operationRequests.put("HDFS_SERVICE_STATE", 1);
    operationRequests.put("YARN_SERVICE_STATE", 1);
    operationRequests.put("MAPREDUCE2_SERVICE_STATE", 1);
    operationRequests.put("KERBEROS_SERVICE_STATE", 1);
    ImmutablePair<PollingResult, Exception> pair = new ImmutablePair<>(PollingResult.EXIT, null);
    String failed = "failed";
    when(ambariOperationService.waitForOperations(stack, ambariClient, operationRequests, PREPARE_DEKERBERIZING)).thenThrow(new AmbariConnectionException("failed"));
    when(cloudbreakMessagesService.getMessage(AMBARI_CLUSTER_PREPARE_DEKERBERIZING_FAILED.code())).thenReturn("failed");
    doThrow(new AmbariOperationFailedException("cancel")).when(ambariClusterConnectorPollingResultChecker).checkPollingResult(pair.getLeft(), failed);
    thrown.expect(AmbariOperationFailedException.class);
    thrown.expectMessage("failed");
    underTest.prepareSecurity(stack);
    verify(ambariOperationService, times(1)).waitForOperations(stack, ambariClient, operationRequests, PREPARE_DEKERBERIZING);
    verify(cloudbreakMessagesService, times(1)).getMessage(AMBARI_CLUSTER_PREPARE_DEKERBERIZING_FAILED.code());
    verify(ambariClusterConnectorPollingResultChecker, times(1)).checkPollingResult(pair.getLeft(), failed);
}
Also used : HashMap(java.util.HashMap) Cluster(com.sequenceiq.cloudbreak.domain.Cluster) Matchers.anyString(org.mockito.Matchers.anyString) AmbariConnectionException(com.sequenceiq.ambari.client.AmbariConnectionException) CloudbreakException(com.sequenceiq.cloudbreak.service.CloudbreakException) AmbariConnectionException(com.sequenceiq.ambari.client.AmbariConnectionException) ExpectedException(org.junit.rules.ExpectedException) CancellationException(com.sequenceiq.cloudbreak.cloud.scheduler.CancellationException) Stack(com.sequenceiq.cloudbreak.domain.Stack) ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair) PollingResult(com.sequenceiq.cloudbreak.service.PollingResult) AmbariClient(com.sequenceiq.ambari.client.AmbariClient) Test(org.junit.Test)

Aggregations

PollingResult (com.sequenceiq.cloudbreak.service.PollingResult)19 CloudbreakException (com.sequenceiq.cloudbreak.service.CloudbreakException)16 AmbariClient (com.sequenceiq.ambari.client.AmbariClient)15 CancellationException (com.sequenceiq.cloudbreak.cloud.scheduler.CancellationException)15 Cluster (com.sequenceiq.cloudbreak.domain.Cluster)9 AmbariConnectionException (com.sequenceiq.ambari.client.AmbariConnectionException)8 Stack (com.sequenceiq.cloudbreak.domain.Stack)8 ImmutablePair (org.apache.commons.lang3.tuple.ImmutablePair)6 Test (org.junit.Test)6 ExpectedException (org.junit.rules.ExpectedException)6 Matchers.anyString (org.mockito.Matchers.anyString)6 HashMap (java.util.HashMap)5 HostMetadata (com.sequenceiq.cloudbreak.domain.HostMetadata)4 CloudbreakServiceException (com.sequenceiq.cloudbreak.service.CloudbreakServiceException)4 HostGroup (com.sequenceiq.cloudbreak.domain.HostGroup)3 HostOrchestrator (com.sequenceiq.cloudbreak.orchestrator.host.HostOrchestrator)3 GatewayConfig (com.sequenceiq.cloudbreak.orchestrator.model.GatewayConfig)3 HttpResponseException (groovyx.net.http.HttpResponseException)3 Collections.singletonMap (java.util.Collections.singletonMap)3 List (java.util.List)3