use of com.sequenceiq.cloudbreak.common.event.Payload in project cloudbreak by hortonworks.
the class DisableOnGCPRestartAction method restart.
@Override
public void restart(FlowParameters flowParameters, String flowChainId, String event, Object payload) {
Payload stackPayload = (Payload) payload;
Stack stack = stackService.getByIdWithTransaction(stackPayload.getResourceId());
if (stack.getPlatformVariant().equals(GCP)) {
try {
flowLogService.terminate(stackPayload.getResourceId(), flowParameters.getFlowId());
} catch (TransactionExecutionException e) {
throw new TransactionRuntimeExecutionException(e);
}
} else {
restart(flowParameters, flowChainId, event, payload, stack);
}
}
use of com.sequenceiq.cloudbreak.common.event.Payload in project cloudbreak by hortonworks.
the class FillInMemoryStateStoreRestartAction method restart.
@Override
public void restart(FlowParameters flowParameters, String flowChainId, String event, Object payload) {
Payload datalakePayload = (Payload) payload;
SdxCluster sdxCluster = sdxService.getById(datalakePayload.getResourceId());
sdxStatusService.updateInMemoryStateStore(sdxCluster);
MDCBuilder.buildMdcContext(sdxCluster);
MDCBuilder.addFlowId(flowParameters.getFlowId());
LOGGER.debug("MDC context and InMemoryStateStore entry have been restored for flow: '{}', flow chain: '{}', event: '{}'", flowParameters.getFlowId(), flowChainId, event);
super.restart(flowParameters, flowChainId, event, payload);
}
use of com.sequenceiq.cloudbreak.common.event.Payload in project cloudbreak by hortonworks.
the class AbstractStackTerminationAction method createFlowContext.
@Override
protected StackTerminationContext createFlowContext(FlowParameters flowParameters, StateContext<StackTerminationState, StackTerminationEvent> stateContext, P payload) {
Map<Object, Object> variables = stateContext.getExtendedState().getVariables();
TerminationType terminationType = (TerminationType) variables.getOrDefault(TERMINATION_TYPE, TerminationType.REGULAR);
Stack stack = stackService.getByIdWithListsInTransaction(payload.getResourceId());
stack.setResources(new HashSet<>(resourceService.getAllByStackId(payload.getResourceId())));
MDCBuilder.buildMdcContext(stack);
Location location = location(region(stack.getRegion()), availabilityZone(stack.getAvailabilityZone()));
CloudContext cloudContext = CloudContext.Builder.builder().withId(stack.getId()).withName(stack.getName()).withOriginalName(stack.getOriginalName()).withCrn(stack.getResourceCrn()).withPlatform(stack.getCloudPlatform()).withVariant(stack.getPlatformVariant()).withLocation(location).withWorkspaceId(stack.getWorkspace().getId()).withAccountId(Crn.safeFromString(stack.getResourceCrn()).getAccountId()).withTenantId(stack.getTenant().getId()).build();
CloudCredential cloudCredential = stackUtil.getCloudCredential(stack);
CloudStack cloudStack = cloudStackConverter.convert(stack);
List<CloudResource> resources = stack.getResources().stream().map(r -> cloudResourceConverter.convert(r)).collect(Collectors.toList());
return createStackTerminationContext(flowParameters, stack, cloudContext, cloudCredential, cloudStack, resources, terminationType);
}
use of com.sequenceiq.cloudbreak.common.event.Payload in project cloudbreak by hortonworks.
the class StopStartDownscaleActions method stopInstancesAction.
@Bean(name = "STOPSTART_DOWNSCALE_STOP_INSTANCE_STATE")
public Action<?, ?> stopInstancesAction() {
return new AbstractStopStartDownscaleActions<>(StopStartDownscaleDecommissionViaCMResult.class) {
@Override
protected void doExecute(StopStartDownscaleContext context, StopStartDownscaleDecommissionViaCMResult payload, Map<Object, Object> variables) throws Exception {
Stack stack = context.getStack();
if (payload.getNotDecommissionedHostFqdns().size() > 0) {
stopStartDownscaleFlowService.logCouldNotDecommission(stack.getId(), payload.getNotDecommissionedHostFqdns());
}
Set<String> decommissionedFqdns = payload.getDecommissionedHostFqdns();
stopStartDownscaleFlowService.clusterDownscalingStoppingInstances(stack.getId(), context.getHostGroupName(), decommissionedFqdns);
Set<Long> instancesToStop = stackService.getPrivateIdsForHostNames(stack.getNotDeletedAndNotZombieInstanceMetaDataList(), payload.getDecommissionedHostFqdns());
List<InstanceMetaData> instanceMetaDataList = stack.getNotDeletedAndNotZombieInstanceMetaDataList();
List<InstanceMetaData> instanceMetaDataForHg = instanceMetaDataList.stream().filter(x -> x.getInstanceGroupName().equals(context.getHostGroupName())).collect(Collectors.toList());
LOGGER.debug("InstanceInfoPreStop. hostGroup={}, allInstanceCount={}, hgInstanceCount={}. AllNotDeletedInstances=[{}]", context.getHostGroupName(), instanceMetaDataList.size(), instanceMetaDataForHg.size(), instanceMetaDataList);
List<InstanceMetaData> toStopInstanceMetadataList = new LinkedList<>();
for (InstanceMetaData instanceMetaData : instanceMetaDataForHg) {
if (instancesToStop.contains(instanceMetaData.getPrivateId())) {
toStopInstanceMetadataList.add(instanceMetaData);
}
}
LOGGER.debug("toStopInstanceMetadata: count={}, metadata=[{}]", toStopInstanceMetadataList.size(), toStopInstanceMetadataList);
List<CloudInstance> cloudInstancesToStop = instanceMetaDataToCloudInstanceConverter.convert(toStopInstanceMetadataList, context.getStack().getEnvironmentCrn(), context.getStack().getStackAuthentication());
StopStartDownscaleStopInstancesRequest request = new StopStartDownscaleStopInstancesRequest(context.getCloudContext(), context.getCloudCredential(), context.getCloudStack(), cloudInstancesToStop);
sendEvent(context, request);
}
};
}
use of com.sequenceiq.cloudbreak.common.event.Payload in project cloudbreak by hortonworks.
the class StopStartUpscaleActions method startInstancesAction.
@Bean(name = "STOPSTART_UPSCALE_START_INSTANCE_STATE")
public Action<?, ?> startInstancesAction() {
return new AbstractStopStartUpscaleActions<>(StopStartUpscaleTriggerEvent.class) {
@Override
protected void prepareExecution(StopStartUpscaleTriggerEvent payload, Map<Object, Object> variables) {
variables.put(HOSTGROUPNAME, payload.getHostGroupName());
variables.put(ADJUSTMENT, payload.getAdjustment());
}
@Override
protected void doExecute(StopStartUpscaleContext context, StopStartUpscaleTriggerEvent payload, Map<Object, Object> variables) throws Exception {
clusterUpscaleFlowService.startingInstances(context.getStack().getId(), payload.getHostGroupName(), payload.getAdjustment());
sendEvent(context);
}
@Override
protected Selectable createRequest(StopStartUpscaleContext context) {
Stack stack = context.getStack();
List<InstanceMetaData> instanceMetaDataList = stack.getNotDeletedAndNotZombieInstanceMetaDataList();
List<InstanceMetaData> instanceMetaDataForHg = instanceMetaDataList.stream().filter(x -> x.getInstanceGroupName().equals(context.getHostGroupName())).collect(Collectors.toList());
List<InstanceMetaData> stoppedInstancesInHg = instanceMetaDataForHg.stream().filter(s -> s.getInstanceStatus() == STOPPED).collect(Collectors.toList());
LOGGER.info("NotDeletedInstanceMetadata totalCount={}. count for hostGroup: {}={}, stoppedInstancesInHgCount={}", instanceMetaDataList.size(), context.getHostGroupName(), instanceMetaDataForHg.size(), stoppedInstancesInHg.size());
List<CloudInstance> stoppedCloudInstancesForHg = instanceMetaDataToCloudInstanceConverter.convert(stoppedInstancesInHg, stack.getEnvironmentCrn(), stack.getStackAuthentication());
List<CloudInstance> allCloudInstancesForHg = instanceMetaDataToCloudInstanceConverter.convert(instanceMetaDataForHg, stack.getEnvironmentCrn(), stack.getStackAuthentication());
return new StopStartUpscaleStartInstancesRequest(context.getCloudContext(), context.getCloudCredential(), context.getCloudStack(), context.getHostGroupName(), stoppedCloudInstancesForHg, allCloudInstancesForHg, Collections.emptyList(), context.getAdjustment());
}
};
}
Aggregations