@Test public void testShowAvailableImagesShouldReturnAllUpgradeCandidates() { ImageComponentVersions imageComponentVersionsFor702 = new ImageComponentVersions(); imageComponentVersionsFor702.setCm(V_7_0_2); imageComponentVersionsFor702.setCdp(V_7_0_2); ImageComponentVersions imageComponentVersionsFor703 = new ImageComponentVersions(); imageComponentVersionsFor703.setCm(V_7_0_3); imageComponentVersionsFor703.setCdp(V_7_0_3); ImageInfoV4Response imageInfo1 = new ImageInfoV4Response(); imageInfo1.setImageId(IMAGE_ID + 1); imageInfo1.setCreated(1); imageInfo1.setComponentVersions(imageComponentVersionsFor702); ImageInfoV4Response imageInfo2 = new ImageInfoV4Response(); imageInfo2.setImageId(IMAGE_ID + 2); imageInfo2.setCreated(2); imageInfo2.setComponentVersions(imageComponentVersionsFor702); ImageInfoV4Response imageInfo3 = new ImageInfoV4Response(); imageInfo3.setImageId(IMAGE_ID + 3); imageInfo3.setCreated(3); imageInfo3.setComponentVersions(imageComponentVersionsFor703); UpgradeV4Response upgradeV4Response = new UpgradeV4Response(); upgradeV4Response.setUpgradeCandidates(List.of(imageInfo1, imageInfo2, imageInfo3)); sdxUpgradeRequest.setShowAvailableImages(SdxUpgradeShowAvailableImages.SHOW); underTest.filterSdxUpgradeResponse(sdxUpgradeRequest, upgradeV4Response); assertEquals(3, upgradeV4Response.getUpgradeCandidates().size()); assertTrue(upgradeV4Response.getUpgradeCandidates().stream().anyMatch(imageInfoV4Response -> imageInfoV4Response.getImageId().equals(IMAGE_ID + 1))); assertTrue(upgradeV4Response.getUpgradeCandidates().stream().anyMatch(imageInfoV4Response -> imageInfoV4Response.getImageId().equals(IMAGE_ID + 2))); assertTrue(upgradeV4Response.getUpgradeCandidates().stream().anyMatch(imageInfoV4Response -> imageInfoV4Response.getImageId().equals(IMAGE_ID + 3))); }
@VisibleForTesting void filterSdxUpgradeResponse(SdxUpgradeRequest upgradeSdxClusterRequest, UpgradeV4Response upgradeV4Response) { List<ImageInfoV4Response> upgradeCandidates = upgradeV4Response.getUpgradeCandidates(); if (CollectionUtils.isNotEmpty(upgradeCandidates) && Objects.nonNull(upgradeSdxClusterRequest)) { if (SdxUpgradeShowAvailableImages.LATEST_ONLY == upgradeSdxClusterRequest.getShowAvailableImages()) { Map<String, Optional<ImageInfoV4Response>> latestImageByRuntime = upgradeCandidates.stream() .collect(Collectors.groupingBy(imageInfoV4Response -> imageInfoV4Response.getComponentVersions().getCdp(), Collectors.maxBy(Comparator.comparingLong(ImageInfoV4Response::getCreated)))); List<ImageInfoV4Response> latestImages = latestImageByRuntime.values() .stream() .flatMap(Optional::stream) .collect(Collectors.toList()); upgradeV4Response.setUpgradeCandidates(latestImages); LOGGER.debug("Filtering for latest image per runtimes {}", latestImageByRuntime.keySet()); } else if (upgradeSdxClusterRequest.isDryRun()) { ImageInfoV4Response latestImage = upgradeCandidates.stream().max(getComparator()).orElseThrow(); upgradeV4Response.setUpgradeCandidates(List.of(latestImage)); LOGGER.debug("Choosing latest image with id {} as dry-run is specified", latestImage.getImageId()); } } }
SdxRuntimeUpgradeService { @VisibleForTesting void filterSdxUpgradeResponse(SdxUpgradeRequest upgradeSdxClusterRequest, UpgradeV4Response upgradeV4Response) { List<ImageInfoV4Response> upgradeCandidates = upgradeV4Response.getUpgradeCandidates(); if (CollectionUtils.isNotEmpty(upgradeCandidates) && Objects.nonNull(upgradeSdxClusterRequest)) { if (SdxUpgradeShowAvailableImages.LATEST_ONLY == upgradeSdxClusterRequest.getShowAvailableImages()) { Map<String, Optional<ImageInfoV4Response>> latestImageByRuntime = upgradeCandidates.stream() .collect(Collectors.groupingBy(imageInfoV4Response -> imageInfoV4Response.getComponentVersions().getCdp(), Collectors.maxBy(Comparator.comparingLong(ImageInfoV4Response::getCreated)))); List<ImageInfoV4Response> latestImages = latestImageByRuntime.values() .stream() .flatMap(Optional::stream) .collect(Collectors.toList()); upgradeV4Response.setUpgradeCandidates(latestImages); LOGGER.debug("Filtering for latest image per runtimes {}", latestImageByRuntime.keySet()); } else if (upgradeSdxClusterRequest.isDryRun()) { ImageInfoV4Response latestImage = upgradeCandidates.stream().max(getComparator()).orElseThrow(); upgradeV4Response.setUpgradeCandidates(List.of(latestImage)); LOGGER.debug("Choosing latest image with id {} as dry-run is specified", latestImage.getImageId()); } } } }
SdxRuntimeUpgradeService { @VisibleForTesting void filterSdxUpgradeResponse(SdxUpgradeRequest upgradeSdxClusterRequest, UpgradeV4Response upgradeV4Response) { List<ImageInfoV4Response> upgradeCandidates = upgradeV4Response.getUpgradeCandidates(); if (CollectionUtils.isNotEmpty(upgradeCandidates) && Objects.nonNull(upgradeSdxClusterRequest)) { if (SdxUpgradeShowAvailableImages.LATEST_ONLY == upgradeSdxClusterRequest.getShowAvailableImages()) { Map<String, Optional<ImageInfoV4Response>> latestImageByRuntime = upgradeCandidates.stream() .collect(Collectors.groupingBy(imageInfoV4Response -> imageInfoV4Response.getComponentVersions().getCdp(), Collectors.maxBy(Comparator.comparingLong(ImageInfoV4Response::getCreated)))); List<ImageInfoV4Response> latestImages = latestImageByRuntime.values() .stream() .flatMap(Optional::stream) .collect(Collectors.toList()); upgradeV4Response.setUpgradeCandidates(latestImages); LOGGER.debug("Filtering for latest image per runtimes {}", latestImageByRuntime.keySet()); } else if (upgradeSdxClusterRequest.isDryRun()) { ImageInfoV4Response latestImage = upgradeCandidates.stream().max(getComparator()).orElseThrow(); upgradeV4Response.setUpgradeCandidates(List.of(latestImage)); LOGGER.debug("Choosing latest image with id {} as dry-run is specified", latestImage.getImageId()); } } }  }
SdxRuntimeUpgradeService { @VisibleForTesting void filterSdxUpgradeResponse(SdxUpgradeRequest upgradeSdxClusterRequest, UpgradeV4Response upgradeV4Response) { List<ImageInfoV4Response> upgradeCandidates = upgradeV4Response.getUpgradeCandidates(); if (CollectionUtils.isNotEmpty(upgradeCandidates) && Objects.nonNull(upgradeSdxClusterRequest)) { if (SdxUpgradeShowAvailableImages.LATEST_ONLY == upgradeSdxClusterRequest.getShowAvailableImages()) { Map<String, Optional<ImageInfoV4Response>> latestImageByRuntime = upgradeCandidates.stream() .collect(Collectors.groupingBy(imageInfoV4Response -> imageInfoV4Response.getComponentVersions().getCdp(), Collectors.maxBy(Comparator.comparingLong(ImageInfoV4Response::getCreated)))); List<ImageInfoV4Response> latestImages = latestImageByRuntime.values() .stream() .flatMap(Optional::stream) .collect(Collectors.toList()); upgradeV4Response.setUpgradeCandidates(latestImages); LOGGER.debug("Filtering for latest image per runtimes {}", latestImageByRuntime.keySet()); } else if (upgradeSdxClusterRequest.isDryRun()) { ImageInfoV4Response latestImage = upgradeCandidates.stream().max(getComparator()).orElseThrow(); upgradeV4Response.setUpgradeCandidates(List.of(latestImage)); LOGGER.debug("Choosing latest image with id {} as dry-run is specified", latestImage.getImageId()); } } }  SdxUpgradeResponse checkForUpgradeByName(String userCrn, String clusterName, SdxUpgradeRequest upgradeSdxClusterRequest, String accountId); SdxUpgradeResponse checkForUpgradeByCrn(String userCrn, String crn, SdxUpgradeRequest upgradeSdxClusterRequest, String accountId); SdxUpgradeResponse triggerUpgradeByName(String userCrn, String clusterName, SdxUpgradeRequest upgradeRequest, String accountId); SdxUpgradeResponse triggerUpgradeByCrn(String userCrn, String clusterCrn, SdxUpgradeRequest upgradeRequest, String accountId); boolean isRuntimeUpgradeEnabled(String userCrn); boolean isOsUpgrade(SdxUpgradeRequest request); }
SdxRuntimeUpgradeService { @VisibleForTesting void filterSdxUpgradeResponse(SdxUpgradeRequest upgradeSdxClusterRequest, UpgradeV4Response upgradeV4Response) { List<ImageInfoV4Response> upgradeCandidates = upgradeV4Response.getUpgradeCandidates(); if (CollectionUtils.isNotEmpty(upgradeCandidates) && Objects.nonNull(upgradeSdxClusterRequest)) { if (SdxUpgradeShowAvailableImages.LATEST_ONLY == upgradeSdxClusterRequest.getShowAvailableImages()) { Map<String, Optional<ImageInfoV4Response>> latestImageByRuntime = upgradeCandidates.stream() .collect(Collectors.groupingBy(imageInfoV4Response -> imageInfoV4Response.getComponentVersions().getCdp(), Collectors.maxBy(Comparator.comparingLong(ImageInfoV4Response::getCreated)))); List<ImageInfoV4Response> latestImages = latestImageByRuntime.values() .stream() .flatMap(Optional::stream) .collect(Collectors.toList()); upgradeV4Response.setUpgradeCandidates(latestImages); LOGGER.debug("Filtering for latest image per runtimes {}", latestImageByRuntime.keySet()); } else if (upgradeSdxClusterRequest.isDryRun()) { ImageInfoV4Response latestImage = upgradeCandidates.stream().max(getComparator()).orElseThrow(); upgradeV4Response.setUpgradeCandidates(List.of(latestImage)); LOGGER.debug("Choosing latest image with id {} as dry-run is specified", latestImage.getImageId()); } } }  SdxUpgradeResponse checkForUpgradeByName(String userCrn, String clusterName, SdxUpgradeRequest upgradeSdxClusterRequest, String accountId); SdxUpgradeResponse checkForUpgradeByCrn(String userCrn, String crn, SdxUpgradeRequest upgradeSdxClusterRequest, String accountId); SdxUpgradeResponse triggerUpgradeByName(String userCrn, String clusterName, SdxUpgradeRequest upgradeRequest, String accountId); SdxUpgradeResponse triggerUpgradeByCrn(String userCrn, String clusterCrn, SdxUpgradeRequest upgradeRequest, String accountId); boolean isRuntimeUpgradeEnabled(String userCrn); boolean isOsUpgrade(SdxUpgradeRequest request);  }