Search in sources :

Example 21 with UpgradeV4Request

use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.tags.upgrade.UpgradeV4Request in project cloudbreak by hortonworks.

the class DistroXUpgradeServiceTest method testCmLicenseMissing.

@Test
public void testCmLicenseMissing() {
    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.FALSE);
    when(clouderaManagerLicenseProvider.getLicense(any())).thenThrow(new BadRequestException("No valid CM license is present"));
    BadRequestException exception = Assertions.assertThrows(BadRequestException.class, () -> underTest.triggerUpgrade(CLUSTER, WS_ID, USER_CRN, request));
    assertEquals(exception.getMessage(), "No valid CM license is present");
}
Also used : UpgradeV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.upgrade.UpgradeV4Response) UpgradeV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.tags.upgrade.UpgradeV4Request) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) Test(org.junit.jupiter.api.Test)

Example 22 with UpgradeV4Request

use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.tags.upgrade.UpgradeV4Request 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 23 with UpgradeV4Request

use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.tags.upgrade.UpgradeV4Request in project cloudbreak by hortonworks.

the class DistroXUpgradeV1Controller method upgradeCluster.

private DistroXUpgradeV1Response upgradeCluster(String clusterNameOrCrn, DistroXUpgradeV1Request distroxUpgradeRequest, NameOrCrn nameOrCrn, InternalUpgradeSettings internalUpgradeSettings) {
    String userCrn = ThreadBasedUserCrnProvider.getUserCrn();
    UpgradeV4Request request = upgradeConverter.convert(distroxUpgradeRequest, internalUpgradeSettings);
    Long workspaceId = restRequestThreadLocalService.getRequestedWorkspaceId();
    if (request.isDryRun() || request.isShowAvailableImagesSet()) {
        LOGGER.info("Checking for upgrade for cluster [{}] with request: {}", clusterNameOrCrn, request);
        UpgradeV4Response upgradeV4Response = upgradeAvailabilityService.checkForUpgrade(nameOrCrn, workspaceId, request, userCrn);
        return upgradeConverter.convert(upgradeV4Response);
    } else {
        LOGGER.info("Triggering upgrade for cluster [{}] with request: {}", clusterNameOrCrn, request);
        UpgradeV4Response upgradeV4Response = upgradeService.triggerUpgrade(nameOrCrn, workspaceId, userCrn, request);
        return upgradeConverter.convert(upgradeV4Response);
    }
}
Also used : UpgradeV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.upgrade.UpgradeV4Response) UpgradeV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.tags.upgrade.UpgradeV4Request)

Example 24 with UpgradeV4Request

use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.tags.upgrade.UpgradeV4Request in project cloudbreak by hortonworks.

the class StackUpgradeOperations method checkForClusterUpgrade.

public UpgradeV4Response checkForClusterUpgrade(String accountId, @NotNull Stack stack, Long workspaceId, UpgradeV4Request request) {
    MDCBuilder.buildMdcContext(stack);
    stack.setInstanceGroups(instanceGroupService.getByStackAndFetchTemplates(stack.getId()));
    boolean osUpgrade = upgradeService.isOsUpgrade(request);
    boolean replaceVms = determineReplaceVmsParameter(stack, request.getReplaceVms());
    if (replaceVms) {
        StackInstanceCount stackInstanceCount = instanceMetaDataService.countByStackId(stack.getId());
        Integer upgradeNodeCountLimit = limitConfiguration.getUpgradeNodeCountLimit();
        LOGGER.debug("Instance count: {} and limit: [{}]", stackInstanceCount == null ? "null" : stackInstanceCount.asString(), upgradeNodeCountLimit);
        if (stackInstanceCount != null && stackInstanceCount.getInstanceCount() > upgradeNodeCountLimit) {
            throw new BadRequestException(String.format("There are %s nodes in the cluster. Upgrade has a limit of %s nodes, above the limit it is unstable. " + "Please downscale the cluster below the limit and retry the upgrade.", stackInstanceCount.getInstanceCount(), upgradeNodeCountLimit));
        }
    }
    UpgradeV4Response upgradeResponse = clusterUpgradeAvailabilityService.checkForUpgradesByName(stack, osUpgrade, replaceVms, request.getInternalUpgradeSettings());
    if (CollectionUtils.isNotEmpty(upgradeResponse.getUpgradeCandidates())) {
        clusterUpgradeAvailabilityService.filterUpgradeOptions(accountId, upgradeResponse, request, stack.isDatalake());
    }
    validateAttachedDataHubsForDataLake(accountId, workspaceId, stack, upgradeResponse);
    LOGGER.debug("Upgrade response after validations: {}", upgradeResponse);
    return upgradeResponse;
}
Also used : StackInstanceCount(com.sequenceiq.cloudbreak.domain.projection.StackInstanceCount) UpgradeV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.upgrade.UpgradeV4Response) BadRequestException(javax.ws.rs.BadRequestException)

Example 25 with UpgradeV4Request

use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.tags.upgrade.UpgradeV4Request in project cloudbreak by hortonworks.

the class SdxUpgradeClusterConverter method sdxUpgradeRequestToUpgradeV4Request.

public UpgradeV4Request sdxUpgradeRequestToUpgradeV4Request(SdxUpgradeRequest sdxUpgradeRequest) {
    UpgradeV4Request upgradeV4Request = new UpgradeV4Request();
    upgradeV4Request.setImageId(sdxUpgradeRequest.getImageId());
    upgradeV4Request.setRuntime(sdxUpgradeRequest.getRuntime());
    upgradeV4Request.setDryRun(sdxUpgradeRequest.isDryRun());
    upgradeV4Request.setLockComponents(sdxUpgradeRequest.getLockComponents());
    if (Objects.nonNull(sdxUpgradeRequest.getShowAvailableImages())) {
        upgradeV4Request.setShowAvailableImages(UpgradeShowAvailableImages.valueOf(sdxUpgradeRequest.getShowAvailableImages().name()));
    }
    upgradeV4Request.setReplaceVms(Optional.ofNullable(sdxUpgradeRequest.getReplaceVms()).orElse(SdxUpgradeReplaceVms.ENABLED).getBooleanValue());
    return upgradeV4Request;
}
Also used : UpgradeV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.tags.upgrade.UpgradeV4Request)

Aggregations

UpgradeV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.tags.upgrade.UpgradeV4Request)54 UpgradeV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.upgrade.UpgradeV4Response)44 Test (org.junit.jupiter.api.Test)42 ImageInfoV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.image.ImageInfoV4Response)35 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)14 InternalUpgradeSettings (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.InternalUpgradeSettings)10 BadRequestException (com.sequenceiq.cloudbreak.common.exception.BadRequestException)10 Cluster (com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster)9 DisplayName (org.junit.jupiter.api.DisplayName)9 ClusterView (com.sequenceiq.cloudbreak.domain.view.ClusterView)7 StackView (com.sequenceiq.cloudbreak.domain.view.StackView)7 ImageChangeDto (com.sequenceiq.cloudbreak.service.image.ImageChangeDto)7 DistroXUpgradeV1Request (com.sequenceiq.distrox.api.v1.distrox.model.upgrade.DistroXUpgradeV1Request)7 Test (org.junit.Test)7 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)7 StackImageChangeV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackImageChangeV4Request)6 ImageComponentVersions (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.image.ImageComponentVersions)6 EntitlementService (com.sequenceiq.cloudbreak.auth.altus.EntitlementService)6 BlueprintUpgradeOption (com.sequenceiq.cloudbreak.domain.BlueprintUpgradeOption)6 List (java.util.List)6