use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.tags.upgrade.UpgradeV4Request in project cloudbreak by hortonworks.
the class DistroXUpgradeServiceTest method testTriggerDistroXUpgradeShouldThrowBadRequestExceptionWhenTheOsUpgradeIsDisabledByEntitlement.
@Test
public void testTriggerDistroXUpgradeShouldThrowBadRequestExceptionWhenTheOsUpgradeIsDisabledByEntitlement() {
UpgradeV4Request request = createRequest(false);
request.setLockComponents(true);
UpgradeV4Response response = new UpgradeV4Response();
response.setReplaceVms(true);
response.setUpgradeCandidates(List.of(mock(ImageInfoV4Response.class)));
when(upgradeAvailabilityService.checkForUpgrade(CLUSTER, WS_ID, request, USER_CRN)).thenReturn(response);
ImageInfoV4Response imageInfoV4Response = new ImageInfoV4Response();
imageInfoV4Response.setImageId("imgId");
imageInfoV4Response.setImageCatalogName("catalogName");
when(imageSelector.determineImageId(request, response.getUpgradeCandidates())).thenReturn(imageInfoV4Response);
ArgumentCaptor<StackImageChangeV4Request> imageChangeRequestArgumentCaptor = ArgumentCaptor.forClass(StackImageChangeV4Request.class);
ImageChangeDto imageChangeDto = new ImageChangeDto(STACK_ID, imageInfoV4Response.getImageId());
when(stackCommonService.createImageChangeDto(eq(CLUSTER), eq(WS_ID), imageChangeRequestArgumentCaptor.capture())).thenReturn(imageChangeDto);
when(stackService.getByNameOrCrnInWorkspace(CLUSTER, WS_ID)).thenReturn(stack);
Assertions.assertThrows(BadRequestException.class, () -> underTest.triggerUpgrade(CLUSTER, WS_ID, USER_CRN, request));
}
use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.tags.upgrade.UpgradeV4Request in project cloudbreak by hortonworks.
the class DistroXUpgradeServiceTest method createRequest.
private UpgradeV4Request createRequest(boolean osUpgradeEnabled) {
UpgradeV4Request request = new UpgradeV4Request();
request.setInternalUpgradeSettings(new InternalUpgradeSettings(true, true, osUpgradeEnabled));
return request;
}
use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.tags.upgrade.UpgradeV4Request in project cloudbreak by hortonworks.
the class DistroXUpgradeServiceTest method testTriggerFlowWithoutPaywallCheck.
@Test
public void testTriggerFlowWithoutPaywallCheck() {
UpgradeV4Request request = new UpgradeV4Request();
UpgradeV4Response response = new UpgradeV4Response();
response.setUpgradeCandidates(List.of(mock(ImageInfoV4Response.class)));
when(upgradeAvailabilityService.checkForUpgrade(CLUSTER, WS_ID, request, USER_CRN)).thenReturn(response);
when(entitlementService.isInternalRepositoryForUpgradeAllowed(ACCOUNT_ID)).thenReturn(Boolean.TRUE);
ImageInfoV4Response imageInfoV4Response = new ImageInfoV4Response();
imageInfoV4Response.setImageId("imgId");
imageInfoV4Response.setImageCatalogName("catalogName");
when(imageSelector.determineImageId(request, response.getUpgradeCandidates())).thenReturn(imageInfoV4Response);
ArgumentCaptor<StackImageChangeV4Request> imageChangeRequestArgumentCaptor = ArgumentCaptor.forClass(StackImageChangeV4Request.class);
ImageChangeDto imageChangeDto = new ImageChangeDto(STACK_ID, imageInfoV4Response.getImageId());
when(stackCommonService.createImageChangeDto(eq(CLUSTER), eq(WS_ID), imageChangeRequestArgumentCaptor.capture())).thenReturn(imageChangeDto);
when(stackService.getByNameOrCrnInWorkspace(CLUSTER, WS_ID)).thenReturn(stack);
when(lockedComponentService.isComponentsLocked(stack, imageInfoV4Response.getImageId())).thenReturn(LOCK_COMPONENTS);
FlowIdentifier flowIdentifier = new FlowIdentifier(FlowType.FLOW_CHAIN, "asdf");
when(reactorFlowManager.triggerDistroXUpgrade(eq(STACK_ID), eq(imageChangeDto), anyBoolean(), eq(LOCK_COMPONENTS), anyString())).thenReturn(flowIdentifier);
UpgradeV4Response result = underTest.triggerUpgrade(CLUSTER, WS_ID, USER_CRN, request);
verifyNoInteractions(paywallAccessChecker);
assertEquals(flowIdentifier, result.getFlowIdentifier());
assertTrue(result.getReason().contains(imageInfoV4Response.getImageId()));
StackImageChangeV4Request imageChangeV4Request = imageChangeRequestArgumentCaptor.getValue();
assertEquals(imageInfoV4Response.getImageId(), imageChangeV4Request.getImageId());
assertEquals(imageInfoV4Response.getImageCatalogName(), imageChangeV4Request.getImageCatalogName());
}
use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.tags.upgrade.UpgradeV4Request in project cloudbreak by hortonworks.
the class DistroXUpgradeServiceTest method testTriggerFlowWithTurnOffReplaceVmsParam.
@Test
public void testTriggerFlowWithTurnOffReplaceVmsParam() {
// GIVEN
UpgradeV4Request request = new UpgradeV4Request();
UpgradeV4Response response = new UpgradeV4Response();
response.setReplaceVms(true);
response.setUpgradeCandidates(List.of(mock(ImageInfoV4Response.class)));
when(upgradeAvailabilityService.checkForUpgrade(CLUSTER, WS_ID, request, USER_CRN)).thenReturn(response);
when(entitlementService.isInternalRepositoryForUpgradeAllowed(ACCOUNT_ID)).thenReturn(Boolean.FALSE);
when(clouderaManagerLicenseProvider.getLicense(any())).thenReturn(new JsonCMLicense());
ImageInfoV4Response imageInfoV4Response = new ImageInfoV4Response();
imageInfoV4Response.setImageId("imgId");
imageInfoV4Response.setImageCatalogName("catalogName");
when(imageSelector.determineImageId(request, response.getUpgradeCandidates())).thenReturn(imageInfoV4Response);
ArgumentCaptor<StackImageChangeV4Request> imageChangeRequestArgumentCaptor = ArgumentCaptor.forClass(StackImageChangeV4Request.class);
ImageChangeDto imageChangeDto = new ImageChangeDto(STACK_ID, imageInfoV4Response.getImageId());
when(stackCommonService.createImageChangeDto(eq(CLUSTER), eq(WS_ID), imageChangeRequestArgumentCaptor.capture())).thenReturn(imageChangeDto);
when(stackService.getByNameOrCrnInWorkspace(CLUSTER, WS_ID)).thenReturn(stack);
when(lockedComponentService.isComponentsLocked(stack, imageInfoV4Response.getImageId())).thenReturn(LOCK_COMPONENTS);
FlowIdentifier flowIdentifier = new FlowIdentifier(FlowType.FLOW_CHAIN, "asdf");
when(reactorFlowManager.triggerDistroXUpgrade(eq(STACK_ID), eq(imageChangeDto), anyBoolean(), eq(LOCK_COMPONENTS), anyString())).thenReturn(flowIdentifier);
// WHEN
UpgradeV4Response result = underTest.triggerUpgrade(CLUSTER, WS_ID, USER_CRN, request);
// THEN
verify(reactorFlowManager).triggerDistroXUpgrade(STACK_ID, imageChangeDto, false, LOCK_COMPONENTS, "variant");
assertFalse(result.isReplaceVms());
}
Aggregations