use of com.sequenceiq.cloudbreak.common.event.Selectable in project cloudbreak by hortonworks.
the class StackImageUpdateActions method setImageAction.
@Bean(name = "SET_IMAGE_STATE")
public AbstractStackImageUpdateAction<?> setImageAction() {
return new AbstractStackImageUpdateAction<>(StackEvent.class) {
@Override
protected void doExecute(StackContext context, StackEvent payload, Map<Object, Object> variables) {
CloudStack cloudStack = getCloudStackConverter().convert(context.getStack());
Collection<Resource> resources = getResourceService().getAllByStackId(context.getStack().getId());
List<CloudResource> cloudResources = resources.stream().map(resource -> getResourceToCloudResourceConverter().convert(resource)).collect(Collectors.toList());
UpdateImageRequest<Selectable> request = new UpdateImageRequest<>(context.getCloudContext(), context.getCloudCredential(), cloudStack, cloudResources);
sendEvent(context, request);
}
};
}
use of com.sequenceiq.cloudbreak.common.event.Selectable in project cloudbreak by hortonworks.
the class StackStartActions method stackStartAction.
@Bean(name = "START_STATE")
public Action<?, ?> stackStartAction() {
return new AbstractStackStartAction<>(StackEvent.class) {
@Override
protected void doExecute(StackStartStopContext context, StackEvent payload, Map<Object, Object> variables) {
stackStartStopService.startStackStart(context);
sendEvent(context);
}
@Override
protected Selectable createRequest(StackStartStopContext context) {
Stack stack = context.getStack();
LOGGER.debug("Assembling start request for stack: {}", stack);
List<CloudInstance> cloudInstances = instanceMetaDataToCloudInstanceConverter.convert(stack.getNotDeletedAndNotZombieInstanceMetaDataList(), stack.getEnvironmentCrn(), stack.getStackAuthentication());
List<CloudResource> resources = stack.getResources().stream().map(s -> resourceToCloudResourceConverter.convert(s)).collect(Collectors.toList());
cloudInstances.forEach(instance -> context.getStack().getParameters().forEach(instance::putParameter));
return new StartInstancesRequest(context.getCloudContext(), context.getCloudCredential(), resources, cloudInstances);
}
};
}
use of com.sequenceiq.cloudbreak.common.event.Selectable in project cloudbreak by hortonworks.
the class StackDownscaleActions method stackDownscaleAction.
@Bean(name = "DOWNSCALE_STATE")
public Action<?, ?> stackDownscaleAction() {
return new AbstractStackDownscaleAction<>(DownscaleStackCollectResourcesResult.class) {
@Override
protected void doExecute(StackScalingFlowContext context, DownscaleStackCollectResourcesResult payload, Map<Object, Object> variables) {
Selectable request = new DownscaleStackRequest(context.getCloudContext(), context.getCloudCredential(), context.getCloudStack(), (List<CloudResource>) variables.get(RESOURCES), (List<CloudInstance>) variables.get(INSTANCES), payload.getResourcesToScale());
sendEvent(context, request);
}
};
}
use of com.sequenceiq.cloudbreak.common.event.Selectable in project cloudbreak by hortonworks.
the class StackStopActions method stackStopAction.
@Bean(name = "STOP_STATE")
public Action<?, ?> stackStopAction() {
return new AbstractStackStopAction<>(StackEvent.class) {
@Override
protected void doExecute(StackStartStopContext context, StackEvent payload, Map<Object, Object> variables) {
stackStartStopService.startStackStop(context);
sendEvent(context);
}
@Override
protected Selectable createRequest(StackStartStopContext context) {
Stack stack = context.getStack();
List<CloudInstance> cloudInstances = instanceMetaDataToCloudInstanceConverter.convert(context.getInstanceMetaData(), stack.getEnvironmentCrn(), stack.getStackAuthentication());
List<CloudResource> cloudResources = stack.getResources().stream().map(s -> resourceToCloudResourceConverter.convert(s)).collect(Collectors.toList());
cloudInstances.forEach(instance -> stack.getParameters().forEach(instance::putParameter));
return new StopInstancesRequest(context.getCloudContext(), context.getCloudCredential(), cloudResources, cloudInstances);
}
};
}
use of com.sequenceiq.cloudbreak.common.event.Selectable in project cloudbreak by hortonworks.
the class StackUpscaleActions method finishExtendMetadata.
@Bean(name = "EXTEND_METADATA_FINISHED_STATE")
public Action<?, ?> finishExtendMetadata() {
return new AbstractStackUpscaleAction<>(CollectMetadataResult.class) {
@Override
protected void doExecute(StackScalingFlowContext context, CollectMetadataResult payload, Map<Object, Object> variables) throws TransactionExecutionException {
Integer adjustment = context.getHostGroupWithAdjustment().values().stream().reduce(0, Integer::sum);
Set<String> upscaleCandidateAddresses = stackUpscaleService.finishExtendMetadata(context.getStack(), adjustment, payload);
variables.put(UPSCALE_CANDIDATE_ADDRESSES, upscaleCandidateAddresses);
Set<String> hostGroups = context.getHostGroupWithAdjustment().keySet();
List<InstanceGroup> scaledInstanceGroups = instanceGroupService.findByStackIdAndInstanceGroupNames(payload.getResourceId(), hostGroups);
boolean gatewayWasUpscaled = scaledInstanceGroups.stream().anyMatch(instanceGroup -> InstanceGroupType.GATEWAY.equals(instanceGroup.getInstanceGroupType()));
if (gatewayWasUpscaled) {
LOGGER.info("Gateway type instance group");
Stack stack = stackService.getByIdWithListsInTransaction(context.getStack().getId());
InstanceMetaData gatewayMetaData = stack.getPrimaryGatewayInstance();
if (null == gatewayMetaData) {
throw new CloudbreakServiceException("Could not get gateway instance metadata from the cloud provider.");
}
DetailedEnvironmentResponse environment = environmentClientService.getByCrnAsInternal(stack.getEnvironmentCrn());
CloudInstance gatewayInstance = metadataConverter.convert(gatewayMetaData, environment, stack.getStackAuthentication());
LOGGER.info("Send GetSSHFingerprintsRequest because we need to collect SSH fingerprints");
Selectable sshFingerPrintReq = new GetSSHFingerprintsRequest<GetSSHFingerprintsResult>(context.getCloudContext(), context.getCloudCredential(), gatewayInstance);
sendEvent(context, sshFingerPrintReq);
} else {
StackEvent bootstrapPayload = new StackEvent(context.getStack().getId());
sendEvent(context, StackUpscaleEvent.BOOTSTRAP_NEW_NODES_EVENT.event(), bootstrapPayload);
}
}
};
}
Aggregations