Search in sources :

Example 11 with GatewayConfig

use of com.sequenceiq.cloudbreak.orchestrator.model.GatewayConfig in project cloudbreak by hortonworks.

the class HostMetadataSetup method updateWithHostData.

private void updateWithHostData(Stack stack, Collection<InstanceMetaData> metadataToUpdate) throws CloudbreakSecuritySetupException {
    try {
        List<String> privateIps = metadataToUpdate.stream().map(InstanceMetaData::getPrivateIp).collect(Collectors.toList());
        GatewayConfig gatewayConfig = gatewayConfigService.getPrimaryGatewayConfig(stack);
        HostOrchestrator hostOrchestrator = hostOrchestratorResolver.get(stack.getOrchestrator().getType());
        Map<String, String> members = hostOrchestrator.getMembers(gatewayConfig, privateIps);
        LOGGER.info("Received host names from hosts: {}, original targets: {}", members.values(), privateIps);
        for (InstanceMetaData instanceMetaData : metadataToUpdate) {
            instanceMetaData.setConsulServer(false);
            String address = members.get(instanceMetaData.getPrivateIp());
            instanceMetaData.setDiscoveryFQDN(address);
            LOGGER.info("Domain used for instance: {} original: {}, fqdn: {}", instanceMetaData.getInstanceId(), address, instanceMetaData.getDiscoveryFQDN());
        }
    } catch (Exception e) {
        throw new CloudbreakSecuritySetupException(e);
    }
}
Also used : InstanceMetaData(com.sequenceiq.cloudbreak.domain.InstanceMetaData) HostOrchestrator(com.sequenceiq.cloudbreak.orchestrator.host.HostOrchestrator) CloudbreakSecuritySetupException(com.sequenceiq.cloudbreak.core.CloudbreakSecuritySetupException) CloudbreakException(com.sequenceiq.cloudbreak.service.CloudbreakException) CloudbreakSecuritySetupException(com.sequenceiq.cloudbreak.core.CloudbreakSecuritySetupException) GatewayConfig(com.sequenceiq.cloudbreak.orchestrator.model.GatewayConfig)

Example 12 with GatewayConfig

use of com.sequenceiq.cloudbreak.orchestrator.model.GatewayConfig in project cloudbreak by hortonworks.

the class ClusterBootstrapper method bootstrapNewNodesOnHost.

private void bootstrapNewNodesOnHost(Stack stack, List<GatewayConfig> allGatewayConfigs, Set<Node> nodes, Set<Node> allNodes) throws CloudbreakException, CloudbreakOrchestratorException {
    HostOrchestrator hostOrchestrator = hostOrchestratorResolver.get(stack.getOrchestrator().getType());
    Cluster cluster = stack.getCluster();
    Boolean enableKnox = cluster.getGateway().getEnableGateway();
    for (InstanceMetaData gateway : stack.getGatewayInstanceMetadata()) {
        GatewayConfig gatewayConfig = gatewayConfigService.getGatewayConfig(stack, gateway, enableKnox);
        PollingResult bootstrapApiPolling = hostBootstrapApiPollingService.pollWithTimeoutSingleFailure(hostBootstrapApiCheckerTask, new HostBootstrapApiContext(stack, gatewayConfig, hostOrchestrator), POLL_INTERVAL, MAX_POLLING_ATTEMPTS);
        validatePollingResultForCancellation(bootstrapApiPolling, "Polling of bootstrap API was cancelled.");
    }
    byte[] stateZip = null;
    ClusterComponent stateComponent = clusterComponentProvider.getComponent(cluster.getId(), ComponentType.SALT_STATE);
    if (stateComponent != null) {
        String content = (String) stateComponent.getAttributes().getMap().getOrDefault(ComponentType.SALT_STATE.name(), "");
        if (!content.isEmpty()) {
            stateZip = Base64.decodeBase64(content);
        }
    }
    hostOrchestrator.bootstrapNewNodes(allGatewayConfigs, nodes, allNodes, stateZip, clusterDeletionBasedModel(stack.getId(), null));
    InstanceMetaData primaryGateway = stack.getPrimaryGatewayInstance();
    GatewayConfig gatewayConfig = gatewayConfigService.getGatewayConfig(stack, primaryGateway, enableKnox);
    PollingResult allNodesAvailabilityPolling = hostClusterAvailabilityPollingService.pollWithTimeoutSingleFailure(hostClusterAvailabilityCheckerTask, new HostOrchestratorClusterContext(stack, hostOrchestrator, gatewayConfig, nodes), POLL_INTERVAL, MAX_POLLING_ATTEMPTS);
    validatePollingResultForCancellation(allNodesAvailabilityPolling, "Polling of new nodes availability was cancelled.");
    if (TIMEOUT.equals(allNodesAvailabilityPolling)) {
        clusterBootstrapperErrorHandler.terminateFailedNodes(hostOrchestrator, null, stack, gatewayConfig, nodes);
    }
}
Also used : InstanceMetaData(com.sequenceiq.cloudbreak.domain.InstanceMetaData) HostOrchestratorClusterContext(com.sequenceiq.cloudbreak.core.bootstrap.service.host.context.HostOrchestratorClusterContext) HostOrchestrator(com.sequenceiq.cloudbreak.orchestrator.host.HostOrchestrator) ClusterComponent(com.sequenceiq.cloudbreak.domain.ClusterComponent) PollingResult(com.sequenceiq.cloudbreak.service.PollingResult) Cluster(com.sequenceiq.cloudbreak.domain.Cluster) HostBootstrapApiContext(com.sequenceiq.cloudbreak.core.bootstrap.service.host.context.HostBootstrapApiContext) GatewayConfig(com.sequenceiq.cloudbreak.orchestrator.model.GatewayConfig)

Example 13 with GatewayConfig

use of com.sequenceiq.cloudbreak.orchestrator.model.GatewayConfig in project cloudbreak by hortonworks.

the class AmbariClusterResetService method resetCluster.

public void resetCluster(Long stackId) throws CloudbreakOrchestratorException {
    Stack stack = stackRepository.findOneWithLists(stackId);
    try {
        InstanceMetaData gatewayInstance = stack.getPrimaryGatewayInstance();
        GatewayConfig gatewayConfig = gatewayConfigService.getGatewayConfig(stack, gatewayInstance, stack.getCluster().getGateway().getEnableGateway());
        OrchestratorType orchestratorType = orchestratorTypeResolver.resolveType(stack.getOrchestrator().getType());
        if (orchestratorType.hostOrchestrator()) {
            HostOrchestrator hostOrchestrator = hostOrchestratorResolver.get(stack.getOrchestrator().getType());
            Set<String> gatewayFQDN = Collections.singleton(gatewayInstance.getDiscoveryFQDN());
            ExitCriteriaModel exitCriteriaModel = clusterDeletionBasedModel(stack.getId(), stack.getCluster().getId());
            hostOrchestrator.resetAmbari(gatewayConfig, gatewayFQDN, stackUtil.collectNodes(stack), exitCriteriaModel);
        } else {
            throw new UnsupportedOperationException("ambari reset cluster works only with host orchestrator");
        }
    } catch (CloudbreakException e) {
        throw new CloudbreakOrchestratorFailedException(e);
    }
}
Also used : InstanceMetaData(com.sequenceiq.cloudbreak.domain.InstanceMetaData) ExitCriteriaModel(com.sequenceiq.cloudbreak.orchestrator.state.ExitCriteriaModel) CloudbreakOrchestratorFailedException(com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorFailedException) HostOrchestrator(com.sequenceiq.cloudbreak.orchestrator.host.HostOrchestrator) CloudbreakException(com.sequenceiq.cloudbreak.service.CloudbreakException) OrchestratorType(com.sequenceiq.cloudbreak.common.model.OrchestratorType) Stack(com.sequenceiq.cloudbreak.domain.Stack) GatewayConfig(com.sequenceiq.cloudbreak.orchestrator.model.GatewayConfig)

Example 14 with GatewayConfig

use of com.sequenceiq.cloudbreak.orchestrator.model.GatewayConfig in project cloudbreak by hortonworks.

the class AmbariClusterUpgradeService method upgradeCluster.

public void upgradeCluster(Long stackId) throws CloudbreakOrchestratorException {
    Stack stack = stackRepository.findOneWithLists(stackId);
    Cluster cluster = stack.getCluster();
    try {
        OrchestratorType orchestratorType = orchestratorTypeResolver.resolveType(stack.getOrchestrator().getType());
        if (orchestratorType.hostOrchestrator()) {
            HostOrchestrator hostOrchestrator = hostOrchestratorResolver.get(stack.getOrchestrator().getType());
            InstanceMetaData gatewayInstance = stack.getPrimaryGatewayInstance();
            GatewayConfig gatewayConfig = gatewayConfigService.getGatewayConfig(stack, gatewayInstance, cluster.getGateway().getEnableGateway());
            Set<String> gatewayFQDN = Collections.singleton(gatewayInstance.getDiscoveryFQDN());
            ExitCriteriaModel exitCriteriaModel = clusterDeletionBasedModel(stack.getId(), cluster.getId());
            AmbariRepo ambariRepo = componentConfigProvider.getAmbariRepo(cluster.getId());
            Map<String, SaltPillarProperties> servicePillar = new HashMap<>();
            Map<String, Object> credentials = new HashMap<>();
            credentials.put("username", ambariSecurityConfigProvider.getAmbariUserName(cluster));
            credentials.put("password", ambariSecurityConfigProvider.getAmbariPassword(cluster));
            servicePillar.put("ambari-credentials", new SaltPillarProperties("/ambari/credentials.sls", singletonMap("ambari", credentials)));
            if (ambariRepo != null) {
                servicePillar.put("ambari-repo", new SaltPillarProperties("/ambari/repo.sls", singletonMap("ambari", singletonMap("repo", ambariRepo))));
            }
            SaltConfig pillar = new SaltConfig(servicePillar);
            hostOrchestrator.upgradeAmbari(gatewayConfig, gatewayFQDN, stackUtil.collectNodes(stack), pillar, exitCriteriaModel);
        } else {
            throw new UnsupportedOperationException("Ambari upgrade works only with host orchestrator");
        }
    } catch (CloudbreakException e) {
        throw new CloudbreakOrchestratorFailedException(e);
    }
}
Also used : ExitCriteriaModel(com.sequenceiq.cloudbreak.orchestrator.state.ExitCriteriaModel) HostOrchestrator(com.sequenceiq.cloudbreak.orchestrator.host.HostOrchestrator) HashMap(java.util.HashMap) Cluster(com.sequenceiq.cloudbreak.domain.Cluster) SaltConfig(com.sequenceiq.cloudbreak.orchestrator.model.SaltConfig) OrchestratorType(com.sequenceiq.cloudbreak.common.model.OrchestratorType) SaltPillarProperties(com.sequenceiq.cloudbreak.orchestrator.model.SaltPillarProperties) Stack(com.sequenceiq.cloudbreak.domain.Stack) InstanceMetaData(com.sequenceiq.cloudbreak.domain.InstanceMetaData) CloudbreakOrchestratorFailedException(com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorFailedException) CloudbreakException(com.sequenceiq.cloudbreak.service.CloudbreakException) AmbariRepo(com.sequenceiq.cloudbreak.cloud.model.AmbariRepo) GatewayConfig(com.sequenceiq.cloudbreak.orchestrator.model.GatewayConfig)

Example 15 with GatewayConfig

use of com.sequenceiq.cloudbreak.orchestrator.model.GatewayConfig in project cloudbreak by hortonworks.

the class ClusterBootstrapperErrorHandlerTest method clusterBootstrapErrorHandlerWhenNodeCountLessThanOneAfterTheRollbackThenClusterProvisionFailed.

@Test
public void clusterBootstrapErrorHandlerWhenNodeCountLessThanOneAfterTheRollbackThenClusterProvisionFailed() throws CloudbreakOrchestratorFailedException {
    Stack stack = TestUtil.stack();
    doNothing().when(eventService).fireCloudbreakEvent(anyLong(), anyString(), anyString());
    when(orchestrator.getAvailableNodes(any(GatewayConfig.class), anySet())).thenReturn(new ArrayList<>());
    when(instanceGroupRepository.save(any(InstanceGroup.class))).then(returnsFirstArg());
    when(instanceMetaDataRepository.save(any(InstanceMetaData.class))).then(returnsFirstArg());
    when(instanceMetaDataRepository.findNotTerminatedByPrivateAddress(anyLong(), anyString())).thenAnswer((Answer<InstanceMetaData>) invocation -> {
        Object[] args = invocation.getArguments();
        String ip = (String) args[1];
        for (InstanceMetaData instanceMetaData : stack.getRunningInstanceMetaData()) {
            if (instanceMetaData.getPrivateIp().equals(ip)) {
                return instanceMetaData;
            }
        }
        return null;
    });
    when(instanceGroupRepository.findOneByGroupNameInStack(anyLong(), anyString())).thenAnswer((Answer<InstanceGroup>) invocation -> {
        Object[] args = invocation.getArguments();
        String name = (String) args[1];
        for (InstanceMetaData instanceMetaData : stack.getRunningInstanceMetaData()) {
            if (instanceMetaData.getInstanceGroup().getGroupName().equals(name)) {
                return instanceMetaData.getInstanceGroup();
            }
        }
        return null;
    });
    when(cloudbreakMessagesService.getMessage(eq("bootstrapper.error.invalide.nodecount"), any())).thenReturn("invalide.nodecount");
    thrown.expect(CloudbreakOrchestratorFailedException.class);
    thrown.expectMessage("invalide.nodecount");
    underTest.terminateFailedNodes(null, orchestrator, TestUtil.stack(), new GatewayConfig("10.0.0.1", "198.0.0.1", "10.0.0.1", 8443, false), prepareNodes(stack));
}
Also used : InstanceMetaData(com.sequenceiq.cloudbreak.domain.InstanceMetaData) Resource(com.sequenceiq.cloudbreak.domain.Resource) InstanceMetaDataRepository(com.sequenceiq.cloudbreak.repository.InstanceMetaDataRepository) ResourceRepository(com.sequenceiq.cloudbreak.repository.ResourceRepository) Mock(org.mockito.Mock) RunWith(org.junit.runner.RunWith) TestUtil(com.sequenceiq.cloudbreak.TestUtil) ServiceProviderConnectorAdapter(com.sequenceiq.cloudbreak.service.stack.connector.adapter.ServiceProviderConnectorAdapter) Matchers.anySet(org.mockito.Matchers.anySet) Matchers.anyString(org.mockito.Matchers.anyString) ArrayList(java.util.ArrayList) InstanceGroup(com.sequenceiq.cloudbreak.domain.InstanceGroup) CloudbreakMessagesService(com.sequenceiq.cloudbreak.service.messages.CloudbreakMessagesService) HashSet(java.util.HashSet) Answer(org.mockito.stubbing.Answer) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Matchers.eq(org.mockito.Matchers.eq) Matchers.anyLong(org.mockito.Matchers.anyLong) Stack(com.sequenceiq.cloudbreak.domain.Stack) ExpectedException(org.junit.rules.ExpectedException) InjectMocks(org.mockito.InjectMocks) HostMetadataRepository(com.sequenceiq.cloudbreak.repository.HostMetadataRepository) ServiceProviderMetadataAdapter(com.sequenceiq.cloudbreak.service.stack.connector.adapter.ServiceProviderMetadataAdapter) ResourceType(com.sequenceiq.cloudbreak.common.type.ResourceType) ContainerOrchestrator(com.sequenceiq.cloudbreak.orchestrator.container.ContainerOrchestrator) InstanceMetaData(com.sequenceiq.cloudbreak.domain.InstanceMetaData) InstanceGroupRepository(com.sequenceiq.cloudbreak.repository.InstanceGroupRepository) Set(java.util.Set) Mockito.times(org.mockito.Mockito.times) Test(org.junit.Test) Mockito.doNothing(org.mockito.Mockito.doNothing) Mockito.when(org.mockito.Mockito.when) Mockito.verify(org.mockito.Mockito.verify) AdditionalAnswers.returnsFirstArg(org.mockito.AdditionalAnswers.returnsFirstArg) Matchers.any(org.mockito.Matchers.any) Rule(org.junit.Rule) MockitoJUnitRunner(org.mockito.runners.MockitoJUnitRunner) CloudbreakOrchestratorFailedException(com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorFailedException) Node(com.sequenceiq.cloudbreak.orchestrator.model.Node) GatewayConfig(com.sequenceiq.cloudbreak.orchestrator.model.GatewayConfig) CloudbreakEventService(com.sequenceiq.cloudbreak.service.events.CloudbreakEventService) Matchers.anyString(org.mockito.Matchers.anyString) Stack(com.sequenceiq.cloudbreak.domain.Stack) GatewayConfig(com.sequenceiq.cloudbreak.orchestrator.model.GatewayConfig) InstanceGroup(com.sequenceiq.cloudbreak.domain.InstanceGroup) Test(org.junit.Test)

Aggregations

GatewayConfig (com.sequenceiq.cloudbreak.orchestrator.model.GatewayConfig)29 HostOrchestrator (com.sequenceiq.cloudbreak.orchestrator.host.HostOrchestrator)17 CloudbreakOrchestratorFailedException (com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorFailedException)15 Node (com.sequenceiq.cloudbreak.orchestrator.model.Node)13 CloudbreakException (com.sequenceiq.cloudbreak.service.CloudbreakException)13 InstanceMetaData (com.sequenceiq.cloudbreak.domain.InstanceMetaData)12 CloudbreakOrchestratorException (com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorException)12 Stack (com.sequenceiq.cloudbreak.domain.Stack)11 ArrayList (java.util.ArrayList)10 SaltConnector (com.sequenceiq.cloudbreak.orchestrator.salt.client.SaltConnector)9 IOException (java.io.IOException)9 HashSet (java.util.HashSet)9 Map (java.util.Map)9 Cluster (com.sequenceiq.cloudbreak.domain.Cluster)8 List (java.util.List)8 SaltConfig (com.sequenceiq.cloudbreak.orchestrator.model.SaltConfig)7 Set (java.util.Set)7 OrchestratorBootstrap (com.sequenceiq.cloudbreak.orchestrator.OrchestratorBootstrap)6 ExitCriteriaModel (com.sequenceiq.cloudbreak.orchestrator.state.ExitCriteriaModel)6 Collection (java.util.Collection)6