use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.image.ImageInfoV4Response in project cloudbreak by hortonworks.
the class DistroXUpgradeService method initUpgrade.
private UpgradeV4Response initUpgrade(UpgradeV4Request request, UpgradeV4Response upgradeV4Response, NameOrCrn cluster, Long workspaceId, String userCrn) {
ImageInfoV4Response image = imageSelector.determineImageId(request, upgradeV4Response.getUpgradeCandidates());
ImageChangeDto imageChangeDto = createImageChangeDto(cluster, workspaceId, image);
Stack stack = stackService.getByNameOrCrnInWorkspace(cluster, workspaceId);
boolean lockComponents = request.getLockComponents() != null ? request.getLockComponents() : isComponentsLocked(stack, image);
validateOsUpgradeEntitled(lockComponents, request);
boolean replaceVms = determineReplaceVmsParam(upgradeV4Response, lockComponents, stack);
String upgradeVariant = calculateUpgradeVariant(stack, userCrn);
FlowIdentifier flowIdentifier = reactorFlowManager.triggerDistroXUpgrade(stack.getId(), imageChangeDto, replaceVms, lockComponents, upgradeVariant);
UpgradeV4Response response = new UpgradeV4Response("Upgrade started with Image: " + image.getImageId(), flowIdentifier);
response.setReplaceVms(replaceVms);
return response;
}
use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.image.ImageInfoV4Response in project cloudbreak by hortonworks.
the class DistroXUpgradeService method createImageChangeDto.
private ImageChangeDto createImageChangeDto(NameOrCrn cluster, Long workspaceId, ImageInfoV4Response image) {
StackImageChangeV4Request stackImageChangeRequest = new StackImageChangeV4Request();
stackImageChangeRequest.setImageId(image.getImageId());
stackImageChangeRequest.setImageCatalogName(image.getImageCatalogName());
return stackCommonService.createImageChangeDto(cluster, workspaceId, stackImageChangeRequest);
}
use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.image.ImageInfoV4Response in project cloudbreak by hortonworks.
the class SdxRuntimeUpgradeServiceTest method testCheckForUpgradeByCrnWhenDisabledAndRequestRuntimeParamIsWrong.
@Test
@DisplayName("Test checkForUpgradeByCrn() when Runtime Upgrade is disabled and request runtime param is wrong")
public void testCheckForUpgradeByCrnWhenDisabledAndRequestRuntimeParamIsWrong() {
SdxUpgradeRequest sdxUpgradeRequest = new SdxUpgradeRequest();
sdxUpgradeRequest.setRuntime("7.2.0");
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, sdxUpgradeRequest, ACCOUNT_ID);
UpgradeV4Response capturedUpgradeV4Response = upgradeV4ResponseCaptor.getValue();
assertEquals(expectedResponse, actualResponse);
assertEquals(0, capturedUpgradeV4Response.getUpgradeCandidates().size());
assertTrue(capturedUpgradeV4Response.getReason().contains("it is not possible to upgrade from [7.0.2] to [7.2.0] runtime"));
}
use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.image.ImageInfoV4Response in project cloudbreak by hortonworks.
the class SdxRuntimeUpgradeServiceTest method testCheckForUpgradeByCrnWhenDisabledAndRequestImageIdParamIsWrong.
@Test
@DisplayName("Test checkForUpgradeByCrn() when Runtime Upgrade is disabled and request imageid param is wrong")
public void testCheckForUpgradeByCrnWhenDisabledAndRequestImageIdParamIsWrong() {
SdxUpgradeRequest sdxUpgradeRequest = new SdxUpgradeRequest();
sdxUpgradeRequest.setImageId(IMAGE_ID_LAST);
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, sdxUpgradeRequest, ACCOUNT_ID);
UpgradeV4Response capturedUpgradeV4Response = upgradeV4ResponseCaptor.getValue();
assertEquals(expectedResponse, actualResponse);
assertEquals(0, capturedUpgradeV4Response.getUpgradeCandidates().size());
assertTrue(capturedUpgradeV4Response.getReason().contains("The version of target runtime has to be the same as the current one"));
}
use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.image.ImageInfoV4Response in project cloudbreak by hortonworks.
the class SdxRuntimeUpgradeServiceTest method testShowAvailableImagesShouldReturnAllUpgradeCandidates.
@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(ACCOUNT_ID, sdxCluster.getClusterName(), 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)));
}
Aggregations