Search in sources :

Example 26 with InstanceMetaData

use of com.sequenceiq.cloudbreak.domain.InstanceMetaData in project cloudbreak by hortonworks.

the class AmbariClusterCreationSuccessHandler method handleClusterCreationSuccess.

public void handleClusterCreationSuccess(Stack stack, Cluster cluster) {
    LOGGER.info("Cluster created successfully. Cluster name: {}", cluster.getName());
    Long now = new Date().getTime();
    cluster.setCreationFinished(now);
    cluster.setUpSince(now);
    cluster = clusterService.updateCluster(cluster);
    Collection<InstanceMetaData> updatedInstances = new ArrayList<>();
    for (InstanceGroup instanceGroup : stack.getInstanceGroups()) {
        Set<InstanceMetaData> instances = instanceGroup.getAllInstanceMetaData();
        for (InstanceMetaData instanceMetaData : instances) {
            if (!instanceMetaData.isTerminated()) {
                instanceMetaData.setInstanceStatus(InstanceStatus.REGISTERED);
                updatedInstances.add(instanceMetaData);
            }
        }
    }
    instanceMetadataRepository.save(updatedInstances);
    Collection<HostMetadata> hostMetadata = new ArrayList<>();
    for (HostMetadata host : hostMetadataRepository.findHostsInCluster(cluster.getId())) {
        host.setHostMetadataState(HostMetadataState.HEALTHY);
        hostMetadata.add(host);
    }
    hostMetadataRepository.save(hostMetadata);
}
Also used : InstanceMetaData(com.sequenceiq.cloudbreak.domain.InstanceMetaData) ArrayList(java.util.ArrayList) Date(java.util.Date) InstanceGroup(com.sequenceiq.cloudbreak.domain.InstanceGroup) HostMetadata(com.sequenceiq.cloudbreak.domain.HostMetadata)

Example 27 with InstanceMetaData

use of com.sequenceiq.cloudbreak.domain.InstanceMetaData in project cloudbreak by hortonworks.

the class ChangePrimaryGatewayService method primaryGatewayChanged.

@Transactional
public void primaryGatewayChanged(long stackId, String newPrimaryGatewayFQDN) throws CloudbreakException {
    Set<InstanceMetaData> imds = instanceMetaDataRepository.findNotTerminatedForStack(stackId);
    Optional<InstanceMetaData> formerPrimaryGateway = imds.stream().filter(imd -> imd.getInstanceMetadataType() == InstanceMetadataType.GATEWAY_PRIMARY).findFirst();
    Optional<InstanceMetaData> newPrimaryGateway = imds.stream().filter(imd -> imd.getDiscoveryFQDN().equals(newPrimaryGatewayFQDN)).findFirst();
    if (newPrimaryGateway.isPresent() && formerPrimaryGateway.isPresent()) {
        InstanceMetaData fpg = formerPrimaryGateway.get();
        fpg.setInstanceMetadataType(InstanceMetadataType.GATEWAY);
        instanceMetaDataRepository.save(fpg);
        InstanceMetaData npg = newPrimaryGateway.get();
        npg.setInstanceMetadataType(InstanceMetadataType.GATEWAY_PRIMARY);
        instanceMetaDataRepository.save(npg);
        Stack updatedStack = stackService.getByIdWithLists(stackId);
        String gatewayIp = gatewayConfigService.getPrimaryGatewayIp(updatedStack);
        Cluster cluster = updatedStack.getCluster();
        cluster.setAmbariIp(gatewayIp);
        clusterRepository.save(cluster);
    } else {
        throw new CloudbreakException("Primary gateway change was not successful.");
    }
}
Also used : InstanceMetaData(com.sequenceiq.cloudbreak.domain.InstanceMetaData) CloudbreakException(com.sequenceiq.cloudbreak.service.CloudbreakException) StackView(com.sequenceiq.cloudbreak.domain.view.StackView) InstanceMetaDataRepository(com.sequenceiq.cloudbreak.repository.InstanceMetaDataRepository) UPDATE_FAILED(com.sequenceiq.cloudbreak.api.model.Status.UPDATE_FAILED) Msg(com.sequenceiq.cloudbreak.core.flow2.stack.Msg) ClusterService(com.sequenceiq.cloudbreak.service.cluster.ClusterService) UPDATE_IN_PROGRESS(com.sequenceiq.cloudbreak.api.model.Status.UPDATE_IN_PROGRESS) Inject(javax.inject.Inject) Stack(com.sequenceiq.cloudbreak.domain.Stack) AmbariClusterConnector(com.sequenceiq.cloudbreak.service.cluster.ambari.AmbariClusterConnector) InstanceMetaData(com.sequenceiq.cloudbreak.domain.InstanceMetaData) AVAILABLE(com.sequenceiq.cloudbreak.api.model.Status.AVAILABLE) Transactional(javax.transaction.Transactional) DetailedStackStatus(com.sequenceiq.cloudbreak.api.model.DetailedStackStatus) Set(java.util.Set) FlowMessageService(com.sequenceiq.cloudbreak.core.flow2.stack.FlowMessageService) Cluster(com.sequenceiq.cloudbreak.domain.Cluster) InstanceMetadataType(com.sequenceiq.cloudbreak.api.model.InstanceMetadataType) ClusterRepository(com.sequenceiq.cloudbreak.repository.ClusterRepository) StackUpdater(com.sequenceiq.cloudbreak.repository.StackUpdater) GatewayConfigService(com.sequenceiq.cloudbreak.service.GatewayConfigService) Component(org.springframework.stereotype.Component) StackUtil(com.sequenceiq.cloudbreak.util.StackUtil) Optional(java.util.Optional) StackService(com.sequenceiq.cloudbreak.service.stack.StackService) Cluster(com.sequenceiq.cloudbreak.domain.Cluster) CloudbreakException(com.sequenceiq.cloudbreak.service.CloudbreakException) Stack(com.sequenceiq.cloudbreak.domain.Stack) Transactional(javax.transaction.Transactional)

Example 28 with InstanceMetaData

use of com.sequenceiq.cloudbreak.domain.InstanceMetaData 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 29 with InstanceMetaData

use of com.sequenceiq.cloudbreak.domain.InstanceMetaData 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 30 with InstanceMetaData

use of com.sequenceiq.cloudbreak.domain.InstanceMetaData in project cloudbreak by hortonworks.

the class ClusterRepairFlowEventChainFactory method createFlowTriggerEventQueue.

@Override
public Queue<Selectable> createFlowTriggerEventQueue(ClusterRepairTriggerEvent event) {
    StackView stackView = stackService.getByIdView(event.getStackId());
    Queue<Selectable> flowChainTriggers = new ConcurrentLinkedDeque<>();
    Map<String, List<String>> failedNodesMap = event.getFailedNodesMap();
    for (Entry<String, List<String>> failedNodes : failedNodesMap.entrySet()) {
        String hostGroupName = failedNodes.getKey();
        List<String> hostNames = failedNodes.getValue();
        HostGroup hostGroup = hostGroupService.getByClusterIdAndName(stackView.getClusterView().getId(), hostGroupName);
        InstanceGroup instanceGroup = hostGroup.getConstraint().getInstanceGroup();
        if (InstanceGroupType.GATEWAY.equals(instanceGroup.getInstanceGroupType())) {
            List<InstanceMetaData> primary = instanceMetadataRepository.findAllByInstanceGroup(instanceGroup).stream().filter(imd -> hostNames.contains(imd.getDiscoveryFQDN()) && imd.getInstanceMetadataType() == InstanceMetadataType.GATEWAY_PRIMARY).collect(Collectors.toList());
            if (!primary.isEmpty()) {
                flowChainTriggers.add(new ChangePrimaryGatewayTriggerEvent(ChangePrimaryGatewayEvent.CHANGE_PRIMARY_GATEWAY_TRIGGER_EVENT.event(), event.getStackId(), event.accepted()));
            }
        }
        flowChainTriggers.add(new ClusterAndStackDownscaleTriggerEvent(FlowChainTriggers.FULL_DOWNSCALE_TRIGGER_EVENT, event.getStackId(), hostGroupName, new HashSet<>(hostNames), ScalingType.DOWNSCALE_TOGETHER, event.accepted()));
        if (!event.isRemoveOnly()) {
            flowChainTriggers.add(new StackAndClusterUpscaleTriggerEvent(FlowChainTriggers.FULL_UPSCALE_TRIGGER_EVENT, event.getStackId(), hostGroupName, hostNames.size(), ScalingType.UPSCALE_TOGETHER, Sets.newHashSet(hostNames)));
            // we need to update all ephemeral clusters that are connected to a datalake
            if (InstanceGroupType.GATEWAY.equals(instanceGroup.getInstanceGroupType()) && !stackService.findClustersConnectedToDatalake(event.getStackId()).isEmpty()) {
                flowChainTriggers.add(new EphemeralClustersUpgradeTriggerEvent(FlowChainTriggers.EPHEMERAL_CLUSTERS_UPDATE_TRIGGER_EVENT, event.getStackId(), event.accepted()));
            }
        }
    }
    return flowChainTriggers;
}
Also used : StackView(com.sequenceiq.cloudbreak.domain.view.StackView) StackAndClusterUpscaleTriggerEvent(com.sequenceiq.cloudbreak.core.flow2.event.StackAndClusterUpscaleTriggerEvent) InstanceMetaDataRepository(com.sequenceiq.cloudbreak.repository.InstanceMetaDataRepository) LoggerFactory(org.slf4j.LoggerFactory) HostGroupService(com.sequenceiq.cloudbreak.service.hostgroup.HostGroupService) ClusterRepairTriggerEvent(com.sequenceiq.cloudbreak.reactor.api.event.orchestration.ClusterRepairTriggerEvent) InstanceGroupType(com.sequenceiq.cloudbreak.api.model.InstanceGroupType) InstanceGroup(com.sequenceiq.cloudbreak.domain.InstanceGroup) HashSet(java.util.HashSet) Inject(javax.inject.Inject) Map(java.util.Map) ChangePrimaryGatewayTriggerEvent(com.sequenceiq.cloudbreak.reactor.api.event.orchestration.ChangePrimaryGatewayTriggerEvent) ChangePrimaryGatewayEvent(com.sequenceiq.cloudbreak.core.flow2.cluster.repair.ChangePrimaryGatewayEvent) HostGroup(com.sequenceiq.cloudbreak.domain.HostGroup) Logger(org.slf4j.Logger) InstanceMetaData(com.sequenceiq.cloudbreak.domain.InstanceMetaData) Selectable(com.sequenceiq.cloudbreak.cloud.event.Selectable) ClusterAndStackDownscaleTriggerEvent(com.sequenceiq.cloudbreak.core.flow2.event.ClusterAndStackDownscaleTriggerEvent) Collectors(java.util.stream.Collectors) ConcurrentLinkedDeque(java.util.concurrent.ConcurrentLinkedDeque) Sets(com.google.common.collect.Sets) InstanceMetadataType(com.sequenceiq.cloudbreak.api.model.InstanceMetadataType) List(java.util.List) Component(org.springframework.stereotype.Component) ScalingType(com.sequenceiq.cloudbreak.common.type.ScalingType) Entry(java.util.Map.Entry) EphemeralClustersUpgradeTriggerEvent(com.sequenceiq.cloudbreak.reactor.api.event.orchestration.EphemeralClustersUpgradeTriggerEvent) Queue(java.util.Queue) StackService(com.sequenceiq.cloudbreak.service.stack.StackService) ClusterAndStackDownscaleTriggerEvent(com.sequenceiq.cloudbreak.core.flow2.event.ClusterAndStackDownscaleTriggerEvent) HostGroup(com.sequenceiq.cloudbreak.domain.HostGroup) EphemeralClustersUpgradeTriggerEvent(com.sequenceiq.cloudbreak.reactor.api.event.orchestration.EphemeralClustersUpgradeTriggerEvent) ConcurrentLinkedDeque(java.util.concurrent.ConcurrentLinkedDeque) InstanceGroup(com.sequenceiq.cloudbreak.domain.InstanceGroup) InstanceMetaData(com.sequenceiq.cloudbreak.domain.InstanceMetaData) ChangePrimaryGatewayTriggerEvent(com.sequenceiq.cloudbreak.reactor.api.event.orchestration.ChangePrimaryGatewayTriggerEvent) StackAndClusterUpscaleTriggerEvent(com.sequenceiq.cloudbreak.core.flow2.event.StackAndClusterUpscaleTriggerEvent) Selectable(com.sequenceiq.cloudbreak.cloud.event.Selectable) List(java.util.List) StackView(com.sequenceiq.cloudbreak.domain.view.StackView) HashSet(java.util.HashSet)

Aggregations

InstanceMetaData (com.sequenceiq.cloudbreak.domain.InstanceMetaData)71 InstanceGroup (com.sequenceiq.cloudbreak.domain.InstanceGroup)24 Stack (com.sequenceiq.cloudbreak.domain.Stack)23 ArrayList (java.util.ArrayList)18 HashSet (java.util.HashSet)17 Map (java.util.Map)16 HostMetadata (com.sequenceiq.cloudbreak.domain.HostMetadata)14 Test (org.junit.Test)14 HashMap (java.util.HashMap)13 CloudInstance (com.sequenceiq.cloudbreak.cloud.model.CloudInstance)12 Cluster (com.sequenceiq.cloudbreak.domain.Cluster)12 HostGroup (com.sequenceiq.cloudbreak.domain.HostGroup)11 GatewayConfig (com.sequenceiq.cloudbreak.orchestrator.model.GatewayConfig)9 CloudbreakException (com.sequenceiq.cloudbreak.service.CloudbreakException)9 List (java.util.List)9 Set (java.util.Set)9 Inject (javax.inject.Inject)8 CloudContext (com.sequenceiq.cloudbreak.cloud.context.CloudContext)7 CloudCredential (com.sequenceiq.cloudbreak.cloud.model.CloudCredential)7 Matchers.anyString (org.mockito.Matchers.anyString)7