use of com.sequenceiq.flow.core.FlowParameters in project cloudbreak by hortonworks.
the class ClusterUpgradeActions method upgradeClusterManager.
@Bean(name = "CLUSTER_MANAGER_UPGRADE_STATE")
public Action<?, ?> upgradeClusterManager() {
return new AbstractClusterUpgradeAction<>(ClusterUpgradeInitSuccess.class) {
@Override
protected ClusterUpgradeContext createFlowContext(FlowParameters flowParameters, StateContext<FlowState, FlowEvent> stateContext, ClusterUpgradeInitSuccess payload) {
return ClusterUpgradeContext.from(flowParameters, payload);
}
@Override
protected void doExecute(ClusterUpgradeContext context, ClusterUpgradeInitSuccess payload, Map<Object, Object> variables) {
Image currentImage = getCurrentImage(variables).getImage();
Image targetImage = getTargetImage(variables).getImage();
clusterUpgradeService.upgradeClusterManager(context.getStackId());
Selectable event = new ClusterManagerUpgradeRequest(context.getStackId(), !clusterUpgradeService.isClusterRuntimeUpgradeNeeded(currentImage, targetImage));
sendEvent(context, event.selector(), event);
}
@Override
protected Object getFailurePayload(ClusterUpgradeInitSuccess payload, Optional<ClusterUpgradeContext> flowContext, Exception ex) {
return ClusterUpgradeFailedEvent.from(payload, ex, DetailedStackStatus.CLUSTER_MANAGER_UPGRADE_FAILED);
}
};
}
use of com.sequenceiq.flow.core.FlowParameters in project cloudbreak by hortonworks.
the class ClusterUpgradeActions method initClusterUpgrade.
@Bean(name = "CLUSTER_UPGRADE_INIT_STATE")
public Action<?, ?> initClusterUpgrade() {
return new AbstractClusterUpgradeAction<>(ClusterUpgradeTriggerEvent.class) {
@Inject
private ImageComponentUpdaterService imageComponentUpdaterService;
@Inject
private ClusterUpgradeTargetImageService clusterUpgradeTargetImageService;
@Override
protected void doExecute(ClusterUpgradeContext context, ClusterUpgradeTriggerEvent payload, Map<Object, Object> variables) {
try {
UpgradeImageInfo images = imageComponentUpdaterService.updateForUpgrade(payload.getImageId(), payload.getResourceId());
variables.put(CURRENT_IMAGE, images.getCurrentStatedImage());
variables.put(TARGET_IMAGE, images.getTargetStatedImage());
clusterUpgradeTargetImageService.saveImage(context.getStackId(), images.getTargetStatedImage());
clusterUpgradeService.initUpgradeCluster(context.getStackId(), getTargetImage(variables));
Selectable event = new ClusterUpgradeInitRequest(context.getStackId(), isPatchUpgrade(images.getCurrentStatedImage().getImage(), images.getTargetStatedImage().getImage()));
sendEvent(context, event.selector(), event);
} catch (Exception e) {
LOGGER.error("Error during updating cluster components with image id: [{}]", payload.getImageId(), e);
ClusterUpgradeFailedEvent upgradeFailedEvent = new ClusterUpgradeFailedEvent(payload.getResourceId(), e, DetailedStackStatus.CLUSTER_MANAGER_UPGRADE_FAILED);
sendEvent(context, upgradeFailedEvent);
}
}
@Override
protected Object getFailurePayload(ClusterUpgradeTriggerEvent payload, Optional<ClusterUpgradeContext> flowContext, Exception ex) {
return ClusterUpgradeFailedEvent.from(payload, ex, DetailedStackStatus.CLUSTER_MANAGER_UPGRADE_FAILED);
}
@Override
protected ClusterUpgradeContext createFlowContext(FlowParameters flowParameters, StateContext<FlowState, FlowEvent> stateContext, ClusterUpgradeTriggerEvent payload) {
return ClusterUpgradeContext.from(flowParameters, payload);
}
};
}
use of com.sequenceiq.flow.core.FlowParameters in project cloudbreak by hortonworks.
the class DatabaseRestoreActions method databaseRestoreFailedAction.
@Bean(name = "DATABASE_RESTORE_FAILED_STATE")
public Action<?, ?> databaseRestoreFailedAction() {
return new AbstractBackupRestoreActions<>(DatabaseRestoreFailedEvent.class) {
@Override
protected BackupRestoreContext createFlowContext(FlowParameters flowParameters, StateContext<FlowState, FlowEvent> stateContext, DatabaseRestoreFailedEvent payload) {
Flow flow = getFlow(flowParameters.getFlowId());
flow.setFlowFailed(payload.getException());
return BackupRestoreContext.from(flowParameters, payload, null, null, true);
}
@Override
protected void doExecute(BackupRestoreContext context, DatabaseRestoreFailedEvent payload, Map<Object, Object> variables) {
backupRestoreStatusService.handleDatabaseRestoreFailure(context.getStackId(), payload.getException().getMessage(), payload.getDetailedStatus());
sendEvent(context, DATABASE_RESTORE_FAIL_HANDLED_EVENT.event(), payload);
}
};
}
use of com.sequenceiq.flow.core.FlowParameters in project cloudbreak by hortonworks.
the class DatabaseBackupActions method databaseBackupFailedAction.
@Bean(name = "DATABASE_BACKUP_FAILED_STATE")
public Action<?, ?> databaseBackupFailedAction() {
return new AbstractBackupRestoreActions<>(DatabaseBackupFailedEvent.class) {
@Override
protected BackupRestoreContext createFlowContext(FlowParameters flowParameters, StateContext<FlowState, FlowEvent> stateContext, DatabaseBackupFailedEvent payload) {
Flow flow = getFlow(flowParameters.getFlowId());
flow.setFlowFailed(payload.getException());
return BackupRestoreContext.from(flowParameters, payload, null, null, true);
}
@Override
protected void doExecute(BackupRestoreContext context, DatabaseBackupFailedEvent payload, Map<Object, Object> variables) {
backupRestoreStatusService.handleDatabaseBackupFailure(context.getStackId(), payload.getException().getMessage(), payload.getDetailedStatus());
sendEvent(context, DATABASE_BACKUP_FAIL_HANDLED_EVENT.event(), payload);
}
};
}
use of com.sequenceiq.flow.core.FlowParameters in project cloudbreak by hortonworks.
the class AbstractInstanceTerminationAction method createFlowContext.
@Override
protected InstanceTerminationContext createFlowContext(FlowParameters flowParameters, StateContext<InstanceTerminationState, InstanceTerminationEvent> stateContext, P payload) {
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()).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);
Set<String> instanceIds = payload.getInstanceIds();
CloudStack cloudStack = cloudStackConverter.convert(stack, instanceIds);
List<CloudResource> cloudResources = stack.getResources().stream().map(r -> cloudResourceConverter.convert(r)).collect(Collectors.toList());
List<InstanceMetaData> instanceMetaDataList = new ArrayList<>();
List<CloudInstance> cloudInstances = new ArrayList<>();
DetailedEnvironmentResponse environment = environmentClientService.getByCrnAsInternal(stack.getEnvironmentCrn());
for (String instanceId : instanceIds) {
InstanceMetaData instanceMetaData = instanceMetaDataService.findByStackIdAndInstanceId(stack.getId(), instanceId).orElseThrow(NotFoundException.notFound("instanceMetadata", instanceId));
CloudInstance cloudInstance = metadataConverter.convert(instanceMetaData, environment, stack.getStackAuthentication());
instanceMetaDataList.add(instanceMetaData);
cloudInstances.add(cloudInstance);
}
return new InstanceTerminationContext(flowParameters, stack, cloudContext, cloudCredential, cloudStack, cloudResources, cloudInstances, instanceMetaDataList);
}
Aggregations