class ClusterUpgradeService {

    public void clusterUpgradeFinished(long stackId, StatedImage currentImage, StatedImage targetImage) {
        Image targetIm = targetImage.getImage();
        Image currentIm = currentImage.getImage();
        String clusterStackVersion = NullUtil.getIfNotNull(targetIm.getStackDetails(), StackDetails::getVersion);
        String currentRuntimeBuildNumber = NullUtil.getIfNotNull(currentIm.getStackDetails(), StackDetails::getStackBuildNumber);
        boolean clusterRuntimeUpgradeNeeded =
                isUpdateNeeded(currentRuntimeBuildNumber, NullUtil.getIfNotNull(targetIm.getStackDetails(), StackDetails::getStackBuildNumber));

        clusterService.updateClusterStatusByStackId(stackId, Status.AVAILABLE);
        stackUpdater.updateStackStatus(stackId, DetailedStackStatus.CLUSTER_UPGRADE_FINISHED, "Cluster stack was successfully upgraded.");
        if (clusterRuntimeUpgradeNeeded) {
            flowMessageService.fireEventAndLog(stackId, Status.AVAILABLE.name(), CLUSTER_UPGRADE_FINISHED, clusterStackVersion);
        } else {
            flowMessageService.fireEventAndLog(stackId, Status.AVAILABLE.name(), CLUSTER_UPGRADE_FINISHED_NOVERSION);
        }
    }

}