Search in sources :

Example 6 with StackImageChangeV4Request

use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackImageChangeV4Request in project cloudbreak by hortonworks.

the class DistroXUpgradeServiceTest method testTriggerFlowWhenReplaceVmsParamIsFalse.

@Test
public void testTriggerFlowWhenReplaceVmsParamIsFalse() {
    // GIVEN
    UpgradeV4Request request = new UpgradeV4Request();
    UpgradeV4Response response = new UpgradeV4Response();
    response.setReplaceVms(false);
    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());
}
Also used : UpgradeV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.upgrade.UpgradeV4Response) ImageChangeDto(com.sequenceiq.cloudbreak.service.image.ImageChangeDto) StackImageChangeV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackImageChangeV4Request) UpgradeV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.tags.upgrade.UpgradeV4Request) ImageInfoV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.image.ImageInfoV4Response) FlowIdentifier(com.sequenceiq.flow.api.model.FlowIdentifier) JsonCMLicense(com.sequenceiq.cloudbreak.auth.JsonCMLicense) Test(org.junit.jupiter.api.Test)

Example 7 with StackImageChangeV4Request

use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackImageChangeV4Request in project cloudbreak by hortonworks.

the class SdxUpgradeService method changeImage.

public void changeImage(Long id, UpgradeOptionV4Response upgradeOption) {
    SdxCluster cluster = sdxService.getById(id);
    String targetImageId = upgradeOption.getUpgrade().getImageId();
    StackImageChangeV4Request stackImageChangeRequest = new StackImageChangeV4Request();
    stackImageChangeRequest.setImageId(targetImageId);
    stackImageChangeRequest.setImageCatalogName(upgradeOption.getUpgrade().getImageCatalogName());
    sdxStatusService.setStatusForDatalakeAndNotify(DatalakeStatusEnum.CHANGE_IMAGE_IN_PROGRESS, "Changing image", cluster);
    try {
        String initiatorUserCrn = ThreadBasedUserCrnProvider.getUserCrn();
        FlowIdentifier flowIdentifier = ThreadBasedUserCrnProvider.doAsInternalActor(regionAwareInternalCrnGeneratorFactory.iam().getInternalCrnForServiceAsString(), () -> stackV4Endpoint.changeImageInternal(0L, cluster.getClusterName(), stackImageChangeRequest, initiatorUserCrn));
        cloudbreakFlowService.saveLastCloudbreakFlowChainId(cluster, flowIdentifier);
    } catch (WebApplicationException e) {
        String exceptionMessage = exceptionMessageExtractor.getErrorMessage(e);
        String message = String.format("Stack change image failed on cluster: [%s]. Message: [%s]", cluster.getClusterName(), exceptionMessage);
        throw new CloudbreakApiException(message, e);
    }
}
Also used : StackImageChangeV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackImageChangeV4Request) WebApplicationException(javax.ws.rs.WebApplicationException) SdxCluster(com.sequenceiq.datalake.entity.SdxCluster) FlowIdentifier(com.sequenceiq.flow.api.model.FlowIdentifier) CloudbreakApiException(com.sequenceiq.cloudbreak.exception.CloudbreakApiException)

Example 8 with StackImageChangeV4Request

use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackImageChangeV4Request in project cloudbreak by hortonworks.

the class StackCommonServiceTest method testChangeImageInWorkspace.

@Test
public void testChangeImageInWorkspace() {
    StackImageChangeV4Request stackImageChangeRequest = new StackImageChangeV4Request();
    when(stackService.getIdByNameOrCrnInWorkspace(STACK_NAME, WORKSPACE_ID)).thenReturn(STACK_ID);
    when(stackOperationService.updateImage(any(ImageChangeDto.class))).thenReturn(new FlowIdentifier(FlowType.FLOW, "id"));
    FlowIdentifier result = underTest.changeImageInWorkspace(STACK_NAME, WORKSPACE_ID, stackImageChangeRequest);
    assertEquals(FlowType.FLOW, result.getType());
    assertEquals("id", result.getPollableId());
}
Also used : ImageChangeDto(com.sequenceiq.cloudbreak.service.image.ImageChangeDto) StackImageChangeV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackImageChangeV4Request) FlowIdentifier(com.sequenceiq.flow.api.model.FlowIdentifier) Test(org.junit.jupiter.api.Test)

Example 9 with StackImageChangeV4Request

use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackImageChangeV4Request in project cloudbreak by hortonworks.

the class DistroXUpgradeServiceTest method testTriggerFlowWithoutTurnOffReplaceVmsParam.

@Test
public void testTriggerFlowWithoutTurnOffReplaceVmsParam() {
    // GIVEN
    UpgradeV4Request request = createRequest(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);
    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(true);
    FlowIdentifier flowIdentifier = new FlowIdentifier(FlowType.FLOW_CHAIN, "asdf");
    when(reactorFlowManager.triggerDistroXUpgrade(eq(STACK_ID), eq(imageChangeDto), anyBoolean(), anyBoolean(), anyString())).thenReturn(flowIdentifier);
    // WHEN
    UpgradeV4Response result = underTest.triggerUpgrade(CLUSTER, WS_ID, USER_CRN, request);
    // THEN
    verify(reactorFlowManager).triggerDistroXUpgrade(STACK_ID, imageChangeDto, true, true, "variant");
    assertTrue(result.isReplaceVms());
}
Also used : UpgradeV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.upgrade.UpgradeV4Response) ImageChangeDto(com.sequenceiq.cloudbreak.service.image.ImageChangeDto) StackImageChangeV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackImageChangeV4Request) UpgradeV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.tags.upgrade.UpgradeV4Request) ImageInfoV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.image.ImageInfoV4Response) FlowIdentifier(com.sequenceiq.flow.api.model.FlowIdentifier) JsonCMLicense(com.sequenceiq.cloudbreak.auth.JsonCMLicense) Test(org.junit.jupiter.api.Test)

Example 10 with StackImageChangeV4Request

use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackImageChangeV4Request 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));
}
Also used : UpgradeV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.upgrade.UpgradeV4Response) ImageChangeDto(com.sequenceiq.cloudbreak.service.image.ImageChangeDto) StackImageChangeV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackImageChangeV4Request) UpgradeV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.tags.upgrade.UpgradeV4Request) ImageInfoV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.image.ImageInfoV4Response) Test(org.junit.jupiter.api.Test)

Aggregations

StackImageChangeV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackImageChangeV4Request)12 ImageChangeDto (com.sequenceiq.cloudbreak.service.image.ImageChangeDto)9 Test (org.junit.jupiter.api.Test)9 FlowIdentifier (com.sequenceiq.flow.api.model.FlowIdentifier)7 UpgradeV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.tags.upgrade.UpgradeV4Request)6 ImageInfoV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.image.ImageInfoV4Response)6 UpgradeV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.upgrade.UpgradeV4Response)6 JsonCMLicense (com.sequenceiq.cloudbreak.auth.JsonCMLicense)4 ImageCatalog (com.sequenceiq.cloudbreak.domain.ImageCatalog)1 CloudbreakApiException (com.sequenceiq.cloudbreak.exception.CloudbreakApiException)1 SdxCluster (com.sequenceiq.datalake.entity.SdxCluster)1 WebApplicationException (javax.ws.rs.WebApplicationException)1