Search in sources :

Example 41 with Stack

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

the class ReactorFlowManager method notify.

private void notify(String selector, Acceptable acceptable) {
    Event<Acceptable> event = eventFactory.createEventWithErrHandler(acceptable);
    reactor.notify(selector, event);
    try {
        Boolean accepted = true;
        if (event.getData().accepted() != null) {
            accepted = event.getData().accepted().await(WAIT_FOR_ACCEPT, TimeUnit.SECONDS);
        }
        if (accepted == null || !accepted) {
            Stack stack = stackService.get(event.getData().getStackId());
            throw new FlowsAlreadyRunningException(String.format("Stack %s has flows under operation, request not allowed.", stack.getName()));
        }
    } catch (InterruptedException e) {
        throw new CloudbreakApiException(e.getMessage());
    }
}
Also used : FlowsAlreadyRunningException(com.sequenceiq.cloudbreak.controller.FlowsAlreadyRunningException) Acceptable(com.sequenceiq.cloudbreak.cloud.Acceptable) CloudbreakApiException(com.sequenceiq.cloudbreak.controller.CloudbreakApiException) Stack(com.sequenceiq.cloudbreak.domain.Stack)

Example 42 with Stack

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

the class AbstractStackDownscaleAction method extractInstanceIds.

private Set<String> extractInstanceIds(P payload, Map<Object, Object> variables, Stack stack) {
    if (payload instanceof StackDownscaleTriggerEvent) {
        StackDownscaleTriggerEvent ssc = (StackDownscaleTriggerEvent) payload;
        Set<String> instanceIds;
        if (ssc.getHostNames() == null || ssc.getHostNames().isEmpty()) {
            Map<String, String> unusedInstanceIds = stackScalingService.getUnusedInstanceIds(ssc.getInstanceGroup(), ssc.getAdjustment(), stack);
            instanceIds = new HashSet<>(unusedInstanceIds.keySet());
        } else {
            Set<InstanceMetaData> imds = stack.getInstanceGroupByInstanceGroupName(ssc.getInstanceGroup()).getInstanceMetaData();
            instanceIds = imds.stream().filter(imd -> ssc.getHostNames().contains(imd.getDiscoveryFQDN())).map(InstanceMetaData::getInstanceId).collect(Collectors.toSet());
        }
        variables.put(INSTANCEIDS, instanceIds);
        return instanceIds;
    }
    return getInstanceIds(variables);
}
Also used : InstanceMetaData(com.sequenceiq.cloudbreak.domain.InstanceMetaData) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) AvailabilityZone.availabilityZone(com.sequenceiq.cloudbreak.cloud.model.AvailabilityZone.availabilityZone) StackScaleTriggerEvent(com.sequenceiq.cloudbreak.core.flow2.event.StackScaleTriggerEvent) StackToCloudStackConverter(com.sequenceiq.cloudbreak.converter.spi.StackToCloudStackConverter) Location.location(com.sequenceiq.cloudbreak.cloud.model.Location.location) MDCBuilder(com.sequenceiq.cloudbreak.logger.MDCBuilder) StackFailureEvent(com.sequenceiq.cloudbreak.reactor.api.event.StackFailureEvent) HashSet(java.util.HashSet) Inject(javax.inject.Inject) ResourceToCloudResourceConverter(com.sequenceiq.cloudbreak.converter.spi.ResourceToCloudResourceConverter) StateContext(org.springframework.statemachine.StateContext) AbstractAction(com.sequenceiq.cloudbreak.core.flow2.AbstractAction) Map(java.util.Map) Location(com.sequenceiq.cloudbreak.cloud.model.Location) CredentialToCloudCredentialConverter(com.sequenceiq.cloudbreak.converter.spi.CredentialToCloudCredentialConverter) Stack(com.sequenceiq.cloudbreak.domain.Stack) InstanceMetaData(com.sequenceiq.cloudbreak.domain.InstanceMetaData) StackDownscaleTriggerEvent(com.sequenceiq.cloudbreak.core.flow2.event.StackDownscaleTriggerEvent) Region.region(com.sequenceiq.cloudbreak.cloud.model.Region.region) Set(java.util.Set) CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) Collectors(java.util.stream.Collectors) Payload(com.sequenceiq.cloudbreak.cloud.event.Payload) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) Optional(java.util.Optional) StackService(com.sequenceiq.cloudbreak.service.stack.StackService) StackScalingService(com.sequenceiq.cloudbreak.service.stack.flow.StackScalingService) StackDownscaleTriggerEvent(com.sequenceiq.cloudbreak.core.flow2.event.StackDownscaleTriggerEvent)

Example 43 with Stack

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

the class StackDownscaleService method finishStackDownscale.

public void finishStackDownscale(StackScalingFlowContext context, String instanceGroupName, Collection<String> instanceIds) {
    Stack stack = context.getStack();
    InstanceGroup g = stack.getInstanceGroupByInstanceGroupName(instanceGroupName);
    int nodeCount = stackScalingService.updateRemovedResourcesState(stack, instanceIds, g);
    List<String> fqdns = instanceMetaDataRepository.findAllByInstanceIdIn(instanceIds).stream().map(InstanceMetaData::getDiscoveryFQDN).collect(toList());
    stackUpdater.updateStackStatus(stack.getId(), DetailedStackStatus.DOWNSCALE_COMPLETED, String.format("Downscale of the cluster infrastructure finished successfully. Terminated node(s): %s", fqdns));
    flowMessageService.fireEventAndLog(stack.getId(), Msg.STACK_DOWNSCALE_SUCCESS, AVAILABLE.name(), fqdns);
    if (stack.getCluster() != null && stack.getCluster().getEmailNeeded()) {
        emailSenderService.sendDownScaleSuccessEmail(stack.getCluster().getOwner(), stack.getCluster().getEmailTo(), stackUtil.extractAmbariIp(stack), stack.getCluster().getName());
        flowMessageService.fireEventAndLog(context.getStack().getId(), Msg.STACK_NOTIFICATION_EMAIL, AVAILABLE.name());
    }
    usageService.scaleUsagesForStack(stack.getId(), instanceGroupName, nodeCount);
}
Also used : Stack(com.sequenceiq.cloudbreak.domain.Stack) InstanceGroup(com.sequenceiq.cloudbreak.domain.InstanceGroup)

Example 44 with Stack

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

the class InstanceTerminationService method finishInstanceTermination.

public void finishInstanceTermination(InstanceTerminationContext context, RemoveInstanceResult payload) {
    Stack stack = context.getStack();
    List<InstanceMetaData> instanceMetaDataList = context.getInstanceMetaDataList();
    for (InstanceMetaData instanceMetaData : instanceMetaDataList) {
        String instanceId = instanceMetaData.getInstanceId();
        InstanceGroup instanceGroup = stack.getInstanceGroupByInstanceGroupId(instanceMetaData.getInstanceGroup().getId());
        stackScalingService.updateRemovedResourcesState(stack, Collections.singleton(instanceId), instanceGroup);
        if (stack.getCluster() != null) {
            HostMetadata hostMetadata = hostMetadataRepository.findHostInClusterByName(stack.getCluster().getId(), instanceMetaData.getDiscoveryFQDN());
            if (hostMetadata != null) {
                LOGGER.info("Remove obsolete host: {}", hostMetadata.getHostName());
                stackScalingService.removeHostmetadataIfExists(stack, instanceMetaData, hostMetadata);
            }
        }
    }
    LOGGER.info("Terminate instance result: {}", payload);
    stackUpdater.updateStackStatus(stack.getId(), DetailedStackStatus.AVAILABLE, "Instance removed");
    flowMessageService.fireEventAndLog(stack.getId(), Msg.STACK_REMOVING_INSTANCE_FINISHED, AVAILABLE.name());
}
Also used : InstanceMetaData(com.sequenceiq.cloudbreak.domain.InstanceMetaData) Stack(com.sequenceiq.cloudbreak.domain.Stack) InstanceGroup(com.sequenceiq.cloudbreak.domain.InstanceGroup) HostMetadata(com.sequenceiq.cloudbreak.domain.HostMetadata)

Example 45 with Stack

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

the class AbstractStackCreationAction method createFlowContext.

@Override
protected StackContext createFlowContext(String flowId, StateContext<StackCreationState, StackCreationEvent> stateContext, P payload) {
    Stack stack = stackService.getByIdWithLists(payload.getStackId());
    MDCBuilder.buildMdcContext(stack);
    Location location = location(region(stack.getRegion()), availabilityZone(stack.getAvailabilityZone()));
    CloudContext cloudContext = new CloudContext(stack.getId(), stack.getName(), stack.cloudPlatform(), stack.getOwner(), stack.getPlatformVariant(), location);
    CloudCredential cloudCredential = credentialConverter.convert(stack.getCredential());
    CloudStack cloudStack = cloudStackConverter.convert(stack);
    return new StackContext(flowId, stack, cloudContext, cloudCredential, cloudStack);
}
Also used : CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) StackContext(com.sequenceiq.cloudbreak.core.flow2.stack.StackContext) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) Stack(com.sequenceiq.cloudbreak.domain.Stack) Location(com.sequenceiq.cloudbreak.cloud.model.Location)

Aggregations

Stack (com.sequenceiq.cloudbreak.domain.Stack)207 Cluster (com.sequenceiq.cloudbreak.domain.Cluster)74 Test (org.junit.Test)70 AmbariClient (com.sequenceiq.ambari.client.AmbariClient)32 InstanceMetaData (com.sequenceiq.cloudbreak.domain.InstanceMetaData)30 CloudbreakException (com.sequenceiq.cloudbreak.service.CloudbreakException)26 DetailedStackStatus (com.sequenceiq.cloudbreak.api.model.DetailedStackStatus)23 ArrayList (java.util.ArrayList)20 List (java.util.List)20 BadRequestException (com.sequenceiq.cloudbreak.controller.BadRequestException)18 HostGroup (com.sequenceiq.cloudbreak.domain.HostGroup)18 InstanceGroup (com.sequenceiq.cloudbreak.domain.InstanceGroup)18 HashMap (java.util.HashMap)18 HashSet (java.util.HashSet)18 Blueprint (com.sequenceiq.cloudbreak.domain.Blueprint)17 Map (java.util.Map)17 Matchers.anyString (org.mockito.Matchers.anyString)16 HostMetadata (com.sequenceiq.cloudbreak.domain.HostMetadata)15 Set (java.util.Set)15 CancellationException (com.sequenceiq.cloudbreak.cloud.scheduler.CancellationException)14