class ClusterUpgradeService {

    public boolean upgradeCluster(long stackId, Image currentImage, Image targetImage) {
        String currentRuntimeBuildNumber = NullUtil.getIfNotNull(currentImage.getStackDetails(), StackDetails::getStackBuildNumber);
        boolean clusterManagerUpdateNeeded = isUpdateNeeded(currentImage.getCmBuildNumber(), targetImage.getCmBuildNumber());
        boolean clusterRuntimeUpgradeNeeded =
                isUpdateNeeded(currentRuntimeBuildNumber, NullUtil.getIfNotNull(targetImage.getStackDetails(), StackDetails::getStackBuildNumber));

        if (clusterManagerUpdateNeeded) {
            flowMessageService.fireEventAndLog(stackId, Status.UPDATE_IN_PROGRESS.name(), CLUSTER_MANAGER_UPGRADE_FINISHED, targetImage.getVersion());
        }
        clusterService.updateClusterStatusByStackId(stackId, Status.UPDATE_IN_PROGRESS);
        if (clusterRuntimeUpgradeNeeded) {
            flowMessageService.fireEventAndLog(stackId, Status.UPDATE_IN_PROGRESS.name(), CLUSTER_UPGRADE);
        } else {
            flowMessageService.fireEventAndLog(stackId, Status.UPDATE_IN_PROGRESS.name(), CLUSTER_UPGRADE_NOT_NEEDED, currentRuntimeBuildNumber);
        }
        return clusterRuntimeUpgradeNeeded;
    }

}