Search in sources :

Example 11 with PollingResult

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

the class AmbariClusterSecurityServiceTest method testDisableSecurityWhenCancellationExceptionOccursThenShouldThrowCancellationException.

@Test
public void testDisableSecurityWhenCancellationExceptionOccursThenShouldThrowCancellationException() 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.disableKerberos()).thenReturn(1);
    Map<String, Integer> operationRequests = singletonMap("DISABLE_KERBEROS_REQUEST", 1);
    ImmutablePair<PollingResult, Exception> pair = new ImmutablePair<>(PollingResult.EXIT, null);
    String failed = "failed";
    when(ambariOperationService.waitForOperations(stack, ambariClient, operationRequests, DISABLE_KERBEROS_STATE)).thenThrow(new CancellationException("cancel"));
    when(cloudbreakMessagesService.getMessage(AMBARI_CLUSTER_DISABLE_KERBEROS_FAILED.code())).thenReturn("failed");
    doThrow(new CancellationException("cancel")).when(ambariClusterConnectorPollingResultChecker).checkPollingResult(pair.getLeft(), failed);
    thrown.expect(CancellationException.class);
    thrown.expectMessage("cancel");
    underTest.disableSecurity(stack);
    verify(ambariOperationService, times(1)).waitForOperations(stack, ambariClient, operationRequests, DISABLE_KERBEROS_STATE);
    verify(cloudbreakMessagesService, times(1)).getMessage(AMBARI_CLUSTER_DISABLE_KERBEROS_FAILED.code());
    verify(ambariClusterConnectorPollingResultChecker, times(1)).checkPollingResult(pair.getLeft(), failed);
}
Also used : ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair) CancellationException(com.sequenceiq.cloudbreak.cloud.scheduler.CancellationException) PollingResult(com.sequenceiq.cloudbreak.service.PollingResult) Cluster(com.sequenceiq.cloudbreak.domain.Cluster) Matchers.anyString(org.mockito.Matchers.anyString) 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) AmbariClient(com.sequenceiq.ambari.client.AmbariClient) Test(org.junit.Test)

Example 12 with PollingResult

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

the class AmbariClusterSecurityServiceTest method testPrepareSecurityWhenCancellationExceptionOccursThenShouldThrowCancellationException.

@Test
public void testPrepareSecurityWhenCancellationExceptionOccursThenShouldThrowCancellationException() 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 CancellationException("cancel"));
    when(cloudbreakMessagesService.getMessage(AMBARI_CLUSTER_PREPARE_DEKERBERIZING_FAILED.code())).thenReturn("failed");
    doThrow(new CancellationException("cancel")).when(ambariClusterConnectorPollingResultChecker).checkPollingResult(pair.getLeft(), failed);
    thrown.expect(CancellationException.class);
    thrown.expectMessage("cancel");
    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 : ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair) HashMap(java.util.HashMap) CancellationException(com.sequenceiq.cloudbreak.cloud.scheduler.CancellationException) PollingResult(com.sequenceiq.cloudbreak.service.PollingResult) Cluster(com.sequenceiq.cloudbreak.domain.Cluster) Matchers.anyString(org.mockito.Matchers.anyString) 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) AmbariClient(com.sequenceiq.ambari.client.AmbariClient) Test(org.junit.Test)

Example 13 with PollingResult

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

the class AmbariClusterSecurityServiceTest method testDisableSecurityWhenEverythingWorks.

@Test
public void testDisableSecurityWhenEverythingWorks() 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.disableKerberos()).thenReturn(1);
    Map<String, Integer> operationRequests = singletonMap("DISABLE_KERBEROS_REQUEST", 1);
    ImmutablePair<PollingResult, Exception> pair = new ImmutablePair<>(PollingResult.SUCCESS, null);
    String failed = "failed";
    when(ambariOperationService.waitForOperations(stack, ambariClient, operationRequests, DISABLE_KERBEROS_STATE)).thenReturn(pair);
    when(cloudbreakMessagesService.getMessage(AMBARI_CLUSTER_DISABLE_KERBEROS_FAILED.code())).thenReturn("failed");
    doNothing().when(ambariClusterConnectorPollingResultChecker).checkPollingResult(pair.getLeft(), failed);
    underTest.disableSecurity(stack);
    verify(ambariOperationService, times(1)).waitForOperations(stack, ambariClient, operationRequests, DISABLE_KERBEROS_STATE);
    verify(cloudbreakMessagesService, times(1)).getMessage(AMBARI_CLUSTER_DISABLE_KERBEROS_FAILED.code());
    verify(ambariClusterConnectorPollingResultChecker, times(1)).checkPollingResult(pair.getLeft(), failed);
}
Also used : ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair) PollingResult(com.sequenceiq.cloudbreak.service.PollingResult) Cluster(com.sequenceiq.cloudbreak.domain.Cluster) Matchers.anyString(org.mockito.Matchers.anyString) 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) AmbariClient(com.sequenceiq.ambari.client.AmbariClient) Test(org.junit.Test)

Example 14 with PollingResult

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

the class ClusterBootstrapper method bootstrapOnHost.

@SuppressFBWarnings("REC_CATCH_EXCEPTION")
@SuppressWarnings("unchecked")
public void bootstrapOnHost(Stack stack) throws CloudbreakException {
    Set<Node> nodes = new HashSet<>();
    String domain = hostDiscoveryService.determineDomain(stack.getCustomDomain(), stack.getName(), stack.isClusterNameAsSubdomain());
    for (InstanceMetaData im : stack.getRunningInstanceMetaData()) {
        if (im.getPrivateIp() == null && im.getPublicIpWrapper() == null) {
            LOGGER.warn("Skipping instance metadata because the public ip and private ips are null '{}'.", im);
        } else {
            String generatedHostName = hostDiscoveryService.generateHostname(stack.getCustomHostname(), im.getInstanceGroupName(), im.getPrivateId(), stack.isHostgroupNameAsHostname());
            nodes.add(new Node(im.getPrivateIp(), im.getPublicIpWrapper(), generatedHostName, domain, im.getInstanceGroupName()));
        }
    }
    try {
        HostOrchestrator hostOrchestrator = hostOrchestratorResolver.get(stack.getOrchestrator().getType());
        List<GatewayConfig> allGatewayConfig = new ArrayList<>();
        Boolean enableKnox = stack.getCluster().getGateway().getEnableGateway();
        for (InstanceMetaData gateway : stack.getGatewayInstanceMetadata()) {
            GatewayConfig gatewayConfig = gatewayConfigService.getGatewayConfig(stack, gateway, enableKnox);
            allGatewayConfig.add(gatewayConfig);
            PollingResult bootstrapApiPolling = hostBootstrapApiPollingService.pollWithTimeoutSingleFailure(hostBootstrapApiCheckerTask, new HostBootstrapApiContext(stack, gatewayConfig, hostOrchestrator), POLL_INTERVAL, MAX_POLLING_ATTEMPTS);
            validatePollingResultForCancellation(bootstrapApiPolling, "Polling of bootstrap API was cancelled.");
        }
        ClusterComponent saltComponent = clusterComponentProvider.getComponent(stack.getCluster().getId(), ComponentType.SALT_STATE);
        if (saltComponent == null) {
            byte[] stateConfigZip = hostOrchestrator.getStateConfigZip();
            saltComponent = new ClusterComponent(ComponentType.SALT_STATE, new Json(singletonMap(ComponentType.SALT_STATE.name(), Base64.encodeBase64String(stateConfigZip))), stack.getCluster());
            clusterComponentProvider.store(saltComponent);
        }
        hostOrchestrator.bootstrap(allGatewayConfig, nodes, clusterDeletionBasedModel(stack.getId(), null));
        InstanceMetaData primaryGateway = stack.getPrimaryGatewayInstance();
        GatewayConfig gatewayConfig = gatewayConfigService.getGatewayConfig(stack, primaryGateway, enableKnox);
        String gatewayIp = gatewayConfigService.getGatewayIp(stack, primaryGateway);
        PollingResult allNodesAvailabilityPolling = hostClusterAvailabilityPollingService.pollWithTimeoutSingleFailure(hostClusterAvailabilityCheckerTask, new HostOrchestratorClusterContext(stack, hostOrchestrator, gatewayConfig, nodes), POLL_INTERVAL, MAX_POLLING_ATTEMPTS);
        validatePollingResultForCancellation(allNodesAvailabilityPolling, "Polling of all nodes availability was cancelled.");
        Orchestrator orchestrator = stack.getOrchestrator();
        orchestrator.setApiEndpoint(gatewayIp + ':' + stack.getGatewayPort());
        orchestrator.setType(hostOrchestrator.name());
        orchestratorRepository.save(orchestrator);
        if (TIMEOUT.equals(allNodesAvailabilityPolling)) {
            clusterBootstrapperErrorHandler.terminateFailedNodes(hostOrchestrator, null, stack, gatewayConfig, nodes);
        }
    } catch (Exception e) {
        throw new CloudbreakException(e);
    }
}
Also used : HostOrchestratorClusterContext(com.sequenceiq.cloudbreak.core.bootstrap.service.host.context.HostOrchestratorClusterContext) HostOrchestrator(com.sequenceiq.cloudbreak.orchestrator.host.HostOrchestrator) ClusterComponent(com.sequenceiq.cloudbreak.domain.ClusterComponent) Node(com.sequenceiq.cloudbreak.orchestrator.model.Node) ArrayList(java.util.ArrayList) HostBootstrapApiContext(com.sequenceiq.cloudbreak.core.bootstrap.service.host.context.HostBootstrapApiContext) Json(com.sequenceiq.cloudbreak.domain.json.Json) Orchestrator(com.sequenceiq.cloudbreak.domain.Orchestrator) HostOrchestrator(com.sequenceiq.cloudbreak.orchestrator.host.HostOrchestrator) CloudbreakException(com.sequenceiq.cloudbreak.service.CloudbreakException) CloudbreakOrchestratorCancelledException(com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorCancelledException) CloudbreakOrchestratorException(com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorException) CancellationException(com.sequenceiq.cloudbreak.cloud.scheduler.CancellationException) InstanceMetaData(com.sequenceiq.cloudbreak.domain.InstanceMetaData) PollingResult(com.sequenceiq.cloudbreak.service.PollingResult) CloudbreakException(com.sequenceiq.cloudbreak.service.CloudbreakException) HashSet(java.util.HashSet) GatewayConfig(com.sequenceiq.cloudbreak.orchestrator.model.GatewayConfig) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Example 15 with PollingResult

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

the class AmbariDecommissioner method getDFSSpace.

private Map<String, Map<Long, Long>> getDFSSpace(Stack stack, AmbariClient client) {
    AmbariDFSSpaceRetrievalTask dfsSpaceTask = new AmbariDFSSpaceRetrievalTask();
    PollingResult result = ambariClientPollingService.pollWithTimeoutSingleFailure(dfsSpaceTask, new AmbariClientPollerObject(stack, client), AmbariDFSSpaceRetrievalTask.AMBARI_RETRYING_INTERVAL, AmbariDFSSpaceRetrievalTask.AMBARI_RETRYING_COUNT);
    if (result == SUCCESS) {
        return dfsSpaceTask.getDfsSpace();
    } else {
        throw new CloudbreakServiceException("Failed to get dfs space from ambari!");
    }
}
Also used : CloudbreakServiceException(com.sequenceiq.cloudbreak.service.CloudbreakServiceException) PollingResult(com.sequenceiq.cloudbreak.service.PollingResult) AmbariClientPollerObject(com.sequenceiq.cloudbreak.service.cluster.flow.AmbariClientPollerObject) AmbariDFSSpaceRetrievalTask(com.sequenceiq.cloudbreak.service.cluster.flow.AmbariDFSSpaceRetrievalTask)

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