use of com.sequenceiq.cloudbreak.reactor.api.event.cluster.upgrade.ClusterUpgradeRequest in project cloudbreak by hortonworks.
the class ClusterUpgradeHandler method doAccept.
@Override
protected Selectable doAccept(HandlerEvent<ClusterUpgradeRequest> event) {
LOGGER.debug("Accepting Cluster upgrade event..");
ClusterUpgradeRequest request = event.getData();
Long stackId = request.getResourceId();
Selectable result;
try {
Stack stack = stackService.getByIdWithClusterInTransaction(stackId);
Optional<String> remoteDataContext = getRemoteDataContext(stack);
ClusterApi connector = clusterApiConnectors.getConnector(stack);
Set<ClusterComponent> components = parcelService.getParcelComponentsByBlueprint(stack);
connector.upgradeClusterRuntime(components, request.isPatchUpgrade(), remoteDataContext);
ParcelOperationStatus parcelOperationStatus = parcelService.removeUnusedParcelComponents(stack, components);
if (parcelOperationStatus.getFailed().isEmpty()) {
result = new ClusterUpgradeSuccess(request.getResourceId());
} else {
LOGGER.info("There are failed parcel removals: {}", parcelOperationStatus);
CloudbreakException exception = new CloudbreakException(format("Failed to remove the following parcels: %s", parcelOperationStatus.getFailed()));
result = new ClusterUpgradeFailedEvent(request.getResourceId(), exception, DetailedStackStatus.CLUSTER_UPGRADE_FAILED);
}
} catch (Exception e) {
LOGGER.error("Cluster upgrade event failed", e);
result = new ClusterUpgradeFailedEvent(request.getResourceId(), e, DetailedStackStatus.CLUSTER_UPGRADE_FAILED);
}
return result;
}
use of com.sequenceiq.cloudbreak.reactor.api.event.cluster.upgrade.ClusterUpgradeRequest in project cloudbreak by hortonworks.
the class ClusterUpgradeActions method upgradeCluster.
@Bean(name = "CLUSTER_UPGRADE_STATE")
public Action<?, ?> upgradeCluster() {
return new AbstractClusterUpgradeAction<>(ClusterManagerUpgradeSuccess.class) {
@Override
protected ClusterUpgradeContext createFlowContext(FlowParameters flowParameters, StateContext<FlowState, FlowEvent> stateContext, ClusterManagerUpgradeSuccess payload) {
return ClusterUpgradeContext.from(flowParameters, payload);
}
@Override
protected void doExecute(ClusterUpgradeContext context, ClusterManagerUpgradeSuccess payload, Map<Object, Object> variables) {
Image currentImage = getCurrentImage(variables).getImage();
Image targetImage = getTargetImage(variables).getImage();
boolean clusterRuntimeUpgradeNeeded = clusterUpgradeService.upgradeCluster(context.getStackId(), currentImage, targetImage);
Selectable event;
if (clusterRuntimeUpgradeNeeded) {
event = new ClusterUpgradeRequest(context.getStackId(), isPatchUpgrade(currentImage, targetImage));
} else {
event = new ClusterUpgradeSuccess(context.getStackId());
}
sendEvent(context, event.selector(), event);
}
@Override
protected Object getFailurePayload(ClusterManagerUpgradeSuccess payload, Optional<ClusterUpgradeContext> flowContext, Exception ex) {
return ClusterUpgradeFailedEvent.from(payload, ex, DetailedStackStatus.CLUSTER_UPGRADE_FAILED);
}
};
}
Aggregations