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());
}
}
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);
}
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);
}
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());
}
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);
}
Aggregations