use of com.sequenceiq.cloudbreak.core.flow2.stack.downscale.StackScalingFlowContext in project cloudbreak by hortonworks.
the class AbstractStackUpscaleAction method createFlowContext.
@Override
protected StackScalingFlowContext createFlowContext(String flowId, StateContext<StackUpscaleState, StackUpscaleEvent> stateContext, P payload) {
Map<Object, Object> variables = stateContext.getExtendedState().getVariables();
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 StackScalingFlowContext(flowId, stack, cloudContext, cloudCredential, cloudStack, getInstanceGroupName(variables), Collections.emptySet(), getAdjustment(variables), getHostNames(variables));
}
use of com.sequenceiq.cloudbreak.core.flow2.stack.downscale.StackScalingFlowContext in project cloudbreak by hortonworks.
the class StackUpscaleActions method addInstances.
@Bean(name = "ADD_INSTANCES_STATE")
public Action<?, ?> addInstances() {
return new AbstractStackUpscaleAction<StackScaleTriggerEvent>(StackScaleTriggerEvent.class) {
@Override
protected void prepareExecution(StackScaleTriggerEvent payload, Map<Object, Object> variables) {
variables.put(INSTANCEGROUPNAME, payload.getInstanceGroup());
variables.put(ADJUSTMENT, payload.getAdjustment());
variables.put(HOSTNAMES, payload.getHostNames());
}
@Override
protected void doExecute(StackScalingFlowContext context, StackScaleTriggerEvent payload, Map<Object, Object> variables) {
stackUpscaleService.startAddInstances(context.getStack(), payload.getAdjustment());
sendEvent(context);
}
@Override
protected Selectable createRequest(StackScalingFlowContext context) {
LOGGER.debug("Assembling upscale stack event for stack: {}", context.getStack());
InstanceGroup group = context.getStack().getInstanceGroupByInstanceGroupName(context.getInstanceGroupName());
group.setNodeCount(group.getNodeCount() + context.getAdjustment());
CloudStack cloudStack = cloudStackConverter.convert(context.getStack());
instanceMetadataService.saveInstanceRequests(context.getStack(), cloudStack.getGroups());
List<CloudResource> resources = cloudResourceConverter.convert(context.getStack().getResources());
return new UpscaleStackRequest<UpscaleStackResult>(context.getCloudContext(), context.getCloudCredential(), cloudStack, resources);
}
};
}
use of com.sequenceiq.cloudbreak.core.flow2.stack.downscale.StackScalingFlowContext in project cloudbreak by hortonworks.
the class StackUpscaleActions method finishExtendMetadata.
@Bean(name = "EXTEND_METADATA_FINISHED_STATE")
public Action<?, ?> finishExtendMetadata() {
return new AbstractStackUpscaleAction<CollectMetadataResult>(CollectMetadataResult.class) {
@Override
protected void doExecute(StackScalingFlowContext context, CollectMetadataResult payload, Map<Object, Object> variables) {
Set<String> upscaleCandidateAddresses = stackUpscaleService.finishExtendMetadata(context.getStack(), context.getInstanceGroupName(), payload);
variables.put(UPSCALE_CANDIDATE_ADDRESSES, upscaleCandidateAddresses);
InstanceGroup ig = instanceGroupRepository.findOneByGroupNameInStack(payload.getStackId(), context.getInstanceGroupName());
if (InstanceGroupType.GATEWAY == ig.getInstanceGroupType()) {
InstanceMetaData gatewayMetaData = context.getStack().getPrimaryGatewayInstance();
CloudInstance gatewayInstance = metadataConverter.convert(gatewayMetaData);
Selectable sshFingerPrintReq = new GetSSHFingerprintsRequest<GetSSHFingerprintsResult>(context.getCloudContext(), context.getCloudCredential(), gatewayInstance);
sendEvent(context.getFlowId(), sshFingerPrintReq);
} else {
BootstrapNewNodesEvent bootstrapPayload = new BootstrapNewNodesEvent(context.getStack().getId(), upscaleCandidateAddresses);
sendEvent(context.getFlowId(), StackUpscaleEvent.BOOTSTRAP_NEW_NODES_EVENT.event(), bootstrapPayload);
}
}
};
}
use of com.sequenceiq.cloudbreak.core.flow2.stack.downscale.StackScalingFlowContext in project cloudbreak by hortonworks.
the class StackUpscaleActions method extendHostMetadata.
@Bean(name = "EXTEND_HOST_METADATA_STATE")
public Action<?, ?> extendHostMetadata() {
return new AbstractStackUpscaleAction<BootstrapNewNodesResult>(BootstrapNewNodesResult.class) {
@Override
protected void doExecute(StackScalingFlowContext context, BootstrapNewNodesResult payload, Map<Object, Object> variables) {
stackUpscaleService.extendingHostMetadata(context.getStack());
Selectable request = new ExtendHostMetadataRequest(context.getStack().getId(), payload.getRequest().getUpscaleCandidateAddresses());
sendEvent(context.getFlowId(), request);
}
};
}
use of com.sequenceiq.cloudbreak.core.flow2.stack.downscale.StackScalingFlowContext in project cloudbreak by hortonworks.
the class StackUpscaleActions method bootstrapNewNodes.
@Bean(name = "BOOTSTRAP_NEW_NODES_STATE")
public Action<?, ?> bootstrapNewNodes() {
return new AbstractStackUpscaleAction<BootstrapNewNodesEvent>(BootstrapNewNodesEvent.class) {
@Override
protected void doExecute(StackScalingFlowContext context, BootstrapNewNodesEvent payload, Map<Object, Object> variables) {
stackUpscaleService.bootstrappingNewNodes(context.getStack());
Selectable request = new BootstrapNewNodesRequest(context.getStack().getId(), payload.getUpscaleCandidateAddresses(), context.getHostNames());
sendEvent(context.getFlowId(), request);
}
};
}
Aggregations