Search in sources :

Example 1 with StackView

use of com.sequenceiq.cloudbreak.domain.view.StackView in project cloudbreak by hortonworks.

the class AbstractClusterResetAction method createFlowContext.

@Override
protected ClusterViewContext createFlowContext(String flowId, StateContext<ClusterResetState, ClusterResetEvent> stateContext, P payload) {
    StackView stack = stackService.getByIdView(payload.getStackId());
    MDCBuilder.buildMdcContext(stack.getId().toString(), stack.getName(), stack.getOwner(), "CLUSTER");
    return new ClusterViewContext(flowId, stack);
}
Also used : StackView(com.sequenceiq.cloudbreak.domain.view.StackView) ClusterViewContext(com.sequenceiq.cloudbreak.core.flow2.cluster.ClusterViewContext)

Example 2 with StackView

use of com.sequenceiq.cloudbreak.domain.view.StackView 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)

Example 3 with StackView

use of com.sequenceiq.cloudbreak.domain.view.StackView in project cloudbreak by hortonworks.

the class UpscaleFlowEventChainFactory method createFlowTriggerEventQueue.

@Override
public Queue<Selectable> createFlowTriggerEventQueue(StackAndClusterUpscaleTriggerEvent event) {
    StackView stackView = stackService.getByIdView(event.getStackId());
    ClusterView clusterView = stackView.getClusterView();
    Queue<Selectable> flowEventChain = new ConcurrentLinkedQueue<>();
    flowEventChain.add(new StackSyncTriggerEvent(STACK_SYNC_EVENT.event(), event.getStackId(), false, event.accepted()));
    flowEventChain.add(new StackScaleTriggerEvent(ADD_INSTANCES_EVENT.event(), event.getStackId(), event.getInstanceGroup(), event.getAdjustment(), event.getHostNames()));
    if (ScalingType.isClusterUpScale(event.getScalingType()) && clusterView != null) {
        HostGroup hostGroup = hostGroupService.getByClusterIdAndInstanceGroupName(clusterView.getId(), event.getInstanceGroup());
        flowEventChain.add(new ClusterScaleTriggerEvent(CLUSTER_UPSCALE_TRIGGER_EVENT.event(), stackView.getId(), hostGroup.getName(), event.getAdjustment()));
    }
    return flowEventChain;
}
Also used : ClusterView(com.sequenceiq.cloudbreak.domain.view.ClusterView) StackScaleTriggerEvent(com.sequenceiq.cloudbreak.core.flow2.event.StackScaleTriggerEvent) Selectable(com.sequenceiq.cloudbreak.cloud.event.Selectable) ClusterScaleTriggerEvent(com.sequenceiq.cloudbreak.core.flow2.event.ClusterScaleTriggerEvent) StackSyncTriggerEvent(com.sequenceiq.cloudbreak.core.flow2.event.StackSyncTriggerEvent) HostGroup(com.sequenceiq.cloudbreak.domain.HostGroup) StackView(com.sequenceiq.cloudbreak.domain.view.StackView) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue)

Example 4 with StackView

use of com.sequenceiq.cloudbreak.domain.view.StackView in project cloudbreak by hortonworks.

the class StackTerminationFailureAction method createFlowContext.

@Override
protected StackFailureContext createFlowContext(String flowId, StateContext<StackTerminationState, StackTerminationEvent> stateContext, StackFailureEvent payload) {
    Flow flow = getFlow(flowId);
    StackView stackView = stackService.getByIdView(payload.getStackId());
    MDCBuilder.buildMdcContext(stackView);
    flow.setFlowFailed(payload.getException());
    return new StackFailureContext(flowId, stackView);
}
Also used : StackFailureContext(com.sequenceiq.cloudbreak.core.flow2.stack.StackFailureContext) StackView(com.sequenceiq.cloudbreak.domain.view.StackView) Flow(com.sequenceiq.cloudbreak.core.flow2.Flow)

Example 5 with StackView

use of com.sequenceiq.cloudbreak.domain.view.StackView in project cloudbreak by hortonworks.

the class FlexUsageGenerator method getFlexUsageHdpInstances.

private List<FlexUsageHdpInstanceJson> getFlexUsageHdpInstances(Iterable<CloudbreakUsage> usages) {
    Map<Long, FlexUsageHdpInstanceJson> flexUsageJsonsByStackId = new HashMap<>();
    for (CloudbreakUsage usage : usages) {
        Long stackId = usage.getStackId();
        if (!flexUsageJsonsByStackId.containsKey(stackId)) {
            FlexUsageHdpInstanceJson usageJson = new FlexUsageHdpInstanceJson();
            usageJson.setGuid(usage.getStackUuid());
            usageJson.setParentGuid(usage.getParentUuid());
            usageJson.setClusterName(usage.getStackName());
            usageJson.setBlueprintName(usage.getBlueprintName());
            usageJson.setFlexSubscriptionId(usage.getFlexId());
            usageJson.setProvider(usage.getProvider());
            usageJson.setRegion(usage.getRegion());
            usageJson.setPeakUsage(usage.getPeak());
            usageJson.setUsageDate(formatInstant(usage.getDay().toInstant(), FLEX_USAGE_DAY_FORMAT_PATTERN));
            StackView stack = stackService.getByIdView(usage.getStackId());
            usageJson.setCreationTime(formatInstant(Instant.ofEpochMilli(stack.getCreated()), FLEX_TIME_ZONE_FORMAT_PATTERN));
            usageJson.setTerminationTime(getTerminationTime(stack));
            flexUsageJsonsByStackId.put(stackId, usageJson);
        } else {
            FlexUsageHdpInstanceJson usageJson = flexUsageJsonsByStackId.get(stackId);
            Integer actPeak = usage.getPeak() != null ? usage.getPeak() : 0;
            Integer peak = usageJson.getPeakUsage() != null ? usageJson.getPeakUsage() : 0;
            int newPeak = peak + actPeak;
            usageJson.setPeakUsage(newPeak);
        }
    }
    return new ArrayList<>(flexUsageJsonsByStackId.values());
}
Also used : FlexUsageHdpInstanceJson(com.sequenceiq.cloudbreak.api.model.flex.FlexUsageHdpInstanceJson) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) StackView(com.sequenceiq.cloudbreak.domain.view.StackView) CloudbreakUsage(com.sequenceiq.cloudbreak.domain.CloudbreakUsage)

Aggregations

StackView (com.sequenceiq.cloudbreak.domain.view.StackView)18 ClusterView (com.sequenceiq.cloudbreak.domain.view.ClusterView)5 HostGroup (com.sequenceiq.cloudbreak.domain.HostGroup)4 Selectable (com.sequenceiq.cloudbreak.cloud.event.Selectable)3 Flow (com.sequenceiq.cloudbreak.core.flow2.Flow)3 ClusterViewContext (com.sequenceiq.cloudbreak.core.flow2.cluster.ClusterViewContext)2 ClusterAndStackDownscaleTriggerEvent (com.sequenceiq.cloudbreak.core.flow2.event.ClusterAndStackDownscaleTriggerEvent)2 ClusterScaleTriggerEvent (com.sequenceiq.cloudbreak.core.flow2.event.ClusterScaleTriggerEvent)2 StackScaleTriggerEvent (com.sequenceiq.cloudbreak.core.flow2.event.StackScaleTriggerEvent)2 StackFailureContext (com.sequenceiq.cloudbreak.core.flow2.stack.StackFailureContext)2 HostGroupService (com.sequenceiq.cloudbreak.service.hostgroup.HostGroupService)2 StackService (com.sequenceiq.cloudbreak.service.stack.StackService)2 List (java.util.List)2 Map (java.util.Map)2 ConcurrentLinkedQueue (java.util.concurrent.ConcurrentLinkedQueue)2 Collectors (java.util.stream.Collectors)2 Sets (com.google.common.collect.Sets)1 DetailedStackStatus (com.sequenceiq.cloudbreak.api.model.DetailedStackStatus)1 InstanceGroupType (com.sequenceiq.cloudbreak.api.model.InstanceGroupType)1 InstanceMetadataType (com.sequenceiq.cloudbreak.api.model.InstanceMetadataType)1