use of com.sequenceiq.sdx.api.model.SdxUpgradeRequest in project cloudbreak by hortonworks.
the class SdxUpgradeControllerTest method testUpgradeClusterByNameWhenRequestIsDryRunAndRuntimeIsDisabled.
@Test
void testUpgradeClusterByNameWhenRequestIsDryRunAndRuntimeIsDisabled() {
SdxUpgradeResponse sdxUpgradeResponse = new SdxUpgradeResponse();
sdxUpgradeResponse.setReason("No image available to upgrade");
SdxUpgradeRequest request = new SdxUpgradeRequest();
request.setDryRun(true);
when(sdxRuntimeUpgradeService.checkForUpgradeByName(eq(USER_CRN), eq(CLUSTER_NAME), eq(request), anyString())).thenReturn(sdxUpgradeResponse);
SdxUpgradeResponse response = doAs(USER_CRN, () -> underTest.upgradeClusterByName(CLUSTER_NAME, request));
verify(sdxRuntimeUpgradeService, times(1)).checkForUpgradeByName(eq(USER_CRN), eq(CLUSTER_NAME), eq(request), anyString());
assertEquals("No image available to upgrade", response.getReason());
}
use of com.sequenceiq.sdx.api.model.SdxUpgradeRequest in project cloudbreak by hortonworks.
the class SdxUpgradeControllerTest method testUpgradeClusterByNameWhenRequestIsEmptyAndRuntimeIsEnabled.
@Test
void testUpgradeClusterByNameWhenRequestIsEmptyAndRuntimeIsEnabled() {
SdxUpgradeRequest request = new SdxUpgradeRequest();
doAs(USER_CRN, () -> underTest.upgradeClusterByName(CLUSTER_NAME, request));
verify(sdxRuntimeUpgradeService).triggerUpgradeByName(USER_CRN, CLUSTER_NAME, request, Crn.fromString(USER_CRN).getAccountId());
}
use of com.sequenceiq.sdx.api.model.SdxUpgradeRequest in project cloudbreak by hortonworks.
the class SdxUpgradeControllerTest method testUpgradeClusterByNameWhenRequestIsShowImagesAndRuntimeIsDisabledShouldNotSetLockComponent.
@Test
@DisplayName("when show images is requested and runtime upgrade is enabled it should not set the lock components flag")
void testUpgradeClusterByNameWhenRequestIsShowImagesAndRuntimeIsDisabledShouldNotSetLockComponent() {
SdxUpgradeRequest request = new SdxUpgradeRequest();
request.setShowAvailableImages(SdxUpgradeShowAvailableImages.SHOW);
SdxUpgradeResponse sdxUpgradeResponse = new SdxUpgradeResponse();
sdxUpgradeResponse.setReason("No image available to upgrade");
when(sdxRuntimeUpgradeService.checkForUpgradeByName(USER_CRN, CLUSTER_NAME, request, ACCOUNT_ID)).thenReturn(sdxUpgradeResponse);
SdxUpgradeResponse response = doAs(USER_CRN, () -> underTest.upgradeClusterByName(CLUSTER_NAME, request));
verify(sdxRuntimeUpgradeService, times(1)).checkForUpgradeByName(any(), any(), upgradeRequestArgumentCaptor.capture(), anyString());
SdxUpgradeRequest capturedRequest = upgradeRequestArgumentCaptor.getValue();
assertNull(capturedRequest.getLockComponents());
assertEquals("No image available to upgrade", response.getReason());
}
use of com.sequenceiq.sdx.api.model.SdxUpgradeRequest in project cloudbreak by hortonworks.
the class SdxRuntimeUpgradeService method filterBySdxUpgradeRequestParams.
private UpgradeV4Response filterBySdxUpgradeRequestParams(SdxUpgradeRequest upgradeSdxClusterRequest, UpgradeV4Response upgradeV4Response) {
UpgradeV4Response filteredUpgradeResponse = new UpgradeV4Response(upgradeV4Response.getCurrent(), upgradeV4Response.getUpgradeCandidates(), upgradeV4Response.getReason());
if (CollectionUtils.isNotEmpty(filteredUpgradeResponse.getUpgradeCandidates())) {
List<ImageInfoV4Response> upgradeCandidates = filteredUpgradeResponse.getUpgradeCandidates();
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());
filteredUpgradeResponse.setUpgradeCandidates(latestImages);
LOGGER.debug("Filtering for latest image per runtimes {}", latestImageByRuntime.keySet());
} else if (upgradeSdxClusterRequest.isDryRun()) {
ImageInfoV4Response latestImage = upgradeCandidates.stream().max(ImageInfoV4Response.creationBasedComparator()).orElseThrow();
filteredUpgradeResponse.setUpgradeCandidates(List.of(latestImage));
LOGGER.debug("Choosing latest image with id {} as dry-run is specified", latestImage.getImageId());
} else {
filteredUpgradeResponse.setUpgradeCandidates(upgradeCandidates);
}
}
return filteredUpgradeResponse;
}
use of com.sequenceiq.sdx.api.model.SdxUpgradeRequest in project cloudbreak by hortonworks.
the class SdxRuntimeUpgradeServiceTest method testCheckForUpgradeByCrnWhenDisabledAndPatchUpdatesNotAvailable.
@Test
@DisplayName("Test checkForUpgradeByCrn() when Runtime Upgrade is disabled and patch updates are not available")
public void testCheckForUpgradeByCrnWhenDisabledAndPatchUpdatesNotAvailable() {
ImageInfoV4Response currentImageInfo = new ImageInfoV4Response();
currentImageInfo.setImageId(IMAGE_ID);
currentImageInfo.setCreated(1);
currentImageInfo.setComponentVersions(creatImageComponentVersions(MATCHING_TARGET_RUNTIME, MATCHING_TARGET_RUNTIME));
ImageInfoV4Response imageInfo = new ImageInfoV4Response();
imageInfo.setImageId(IMAGE_ID);
imageInfo.setCreated(1);
imageInfo.setComponentVersions(creatImageComponentVersions("7.2.0", "7.2.0"));
ImageInfoV4Response imageInfo2 = new ImageInfoV4Response();
imageInfo2.setImageId(IMAGE_ID_LAST);
imageInfo2.setCreated(2);
imageInfo2.setComponentVersions(creatImageComponentVersions("7.3.0", "7.3.0"));
List<ImageInfoV4Response> candidates = List.of(imageInfo, imageInfo2);
response.setCurrent(currentImageInfo);
response.setUpgradeCandidates(candidates);
SdxUpgradeResponse expectedResponse = new SdxUpgradeResponse(response.getCurrent(), candidates, response.getReason(), response.getFlowIdentifier());
when(sdxService.getByCrn(anyString(), anyString())).thenReturn(sdxCluster);
when(entitlementService.runtimeUpgradeEnabled(any())).thenReturn(false);
when(stackV4Endpoint.checkForClusterUpgradeByName(anyLong(), anyString(), any(), anyString())).thenReturn(response);
ArgumentCaptor<UpgradeV4Response> upgradeV4ResponseCaptor = ArgumentCaptor.forClass(UpgradeV4Response.class);
when(sdxUpgradeClusterConverter.upgradeResponseToSdxUpgradeResponse(upgradeV4ResponseCaptor.capture())).thenReturn(expectedResponse);
when(regionAwareInternalCrnGenerator.getInternalCrnForServiceAsString()).thenReturn("crn");
when(regionAwareInternalCrnGeneratorFactory.iam()).thenReturn(regionAwareInternalCrnGenerator);
SdxUpgradeResponse actualResponse = underTest.checkForUpgradeByCrn(USER_CRN, STACK_CRN, new SdxUpgradeRequest(), ACCOUNT_ID);
UpgradeV4Response capturedUpgradeV4Response = upgradeV4ResponseCaptor.getValue();
assertEquals(expectedResponse, actualResponse);
assertEquals(0, capturedUpgradeV4Response.getUpgradeCandidates().size());
}
Aggregations