Search in sources :

Example 36 with UpgradeV4Request

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

the class DistroXUpgradeAvailabilityServiceTest method testCheckForUpgradeWhenDataLakeAndDataHubIsOnTheSameVersionAndUpgradeIsAvailable.

@Test
@DisplayName("this test simulates when the Data Lake and Data Hub version is the same (7.1.0)" + "and the only upgrade options for Data Hub is newer than the DL (7.2.0,7.3.0,7.4.0). this will NOT be filtered" + "since the different Data Hub version entitlement is enabled")
public void testCheckForUpgradeWhenDataLakeAndDataHubIsOnTheSameVersionAndUpgradeIsAvailable() {
    UpgradeV4Request request = new UpgradeV4Request();
    UpgradeV4Response response = new UpgradeV4Response();
    ImageInfoV4Response image1 = createImageResponse(2L, "7.2.0");
    ImageInfoV4Response image2 = createImageResponse(8L, "7.3.0");
    ImageInfoV4Response image3 = createImageResponse(6L, "7.4.0");
    response.setUpgradeCandidates(List.of(image1, image2, image3));
    StackView stackView = new StackView();
    ClusterView clusterView = new ClusterView();
    clusterView.setId(1L);
    ReflectionTestUtils.setField(stackView, "cluster", clusterView);
    when(stackService.getByNameOrCrnInWorkspace(CLUSTER, WORKSPACE_ID)).thenReturn(stack);
    when(stackUpgradeOperations.checkForClusterUpgrade(ACCOUNT_ID, stack, WORKSPACE_ID, request)).thenReturn(response);
    when(entitlementService.isDifferentDataHubAndDataLakeVersionAllowed(anyString())).thenReturn(true);
    UpgradeV4Response result = underTest.checkForUpgrade(CLUSTER, WORKSPACE_ID, request, USER_CRN);
    assertEquals(3, result.getUpgradeCandidates().size());
}
Also used : UpgradeV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.upgrade.UpgradeV4Response) ClusterView(com.sequenceiq.cloudbreak.domain.view.ClusterView) UpgradeV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.tags.upgrade.UpgradeV4Request) ImageInfoV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.image.ImageInfoV4Response) StackView(com.sequenceiq.cloudbreak.domain.view.StackView) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 37 with UpgradeV4Request

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

the class StackUpgradeOperationsTest method throwsBadRequestIfClusterHasMoreNodesThanTheLimit.

@Test
void throwsBadRequestIfClusterHasMoreNodesThanTheLimit() {
    UpgradeV4Request request = createUpgradeRequest(true);
    StackInstanceCount stackInstanceCount = mock(StackInstanceCount.class);
    when(stackInstanceCount.getInstanceCount()).thenReturn(201);
    when(limitConfiguration.getUpgradeNodeCountLimit()).thenReturn(200);
    when(instanceMetaDataService.countByStackId(any())).thenReturn(stackInstanceCount);
    BadRequestException exception = Assertions.assertThrows(BadRequestException.class, () -> underTest.checkForClusterUpgrade("accId", new Stack(), WORKSPACE_ID, request));
    assertEquals("There are 201 nodes in the cluster. Upgrade has a limit of 200 nodes, above the limit it is unstable. " + "Please downscale the cluster below the limit and retry the upgrade.", exception.getMessage());
}
Also used : StackInstanceCount(com.sequenceiq.cloudbreak.domain.projection.StackInstanceCount) UpgradeV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.tags.upgrade.UpgradeV4Request) BadRequestException(javax.ws.rs.BadRequestException) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) Test(org.junit.jupiter.api.Test)

Example 38 with UpgradeV4Request

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

the class StackUpgradeOperationsTest method testCheckForClusterUpgradeShouldReturnCompositeErrorWhenBothAttachedDataHubValidationsFail.

@Test
void testCheckForClusterUpgradeShouldReturnCompositeErrorWhenBothAttachedDataHubValidationsFail() {
    Stack stack = createStack(StackType.DATALAKE);
    StackViewV4Responses stackViewV4Responses = new StackViewV4Responses();
    UpgradeV4Request request = createUpgradeRequest(null);
    UpgradeV4Response upgradeResponseToReturn = createUpgradeResponse();
    UpgradeV4Response expectedResponse = createUpgradeResponse();
    expectedResponse.setReason("There are attached Data Hub clusters that are non-upgradeable There are attached Data Hub clusters in incorrect state");
    when(instanceGroupService.getByStackAndFetchTemplates(STACK_ID)).thenReturn(Collections.emptySet());
    when(upgradeService.isOsUpgrade(request)).thenReturn(false);
    StackInstanceCount instanceCount = mock(StackInstanceCount.class);
    when(instanceCount.getInstanceCount()).thenReturn(INSTANCE_COUNT);
    when(instanceMetaDataService.countByStackId(STACK_ID)).thenReturn(instanceCount);
    when(limitConfiguration.getUpgradeNodeCountLimit()).thenReturn(NODE_LIMIT);
    when(clusterUpgradeAvailabilityService.checkForUpgradesByName(stack, false, true, request.getInternalUpgradeSettings())).thenReturn(upgradeResponseToReturn);
    when(entitlementService.runtimeUpgradeEnabled(ACCOUNT_ID)).thenReturn(true);
    when(stackOperations.listByEnvironmentCrn(eq(WORKSPACE_ID), eq(ENVIRONMENT_CRN), any())).thenReturn(stackViewV4Responses);
    when(upgradePreconditionService.checkForRunningAttachedClusters(stackViewV4Responses, stack)).thenReturn("There are attached Data Hub clusters in incorrect state");
    when(upgradePreconditionService.checkForNonUpgradeableAttachedClusters(stackViewV4Responses)).thenReturn("There are attached Data Hub clusters that are non-upgradeable");
    UpgradeV4Response actual = underTest.checkForClusterUpgrade(ACCOUNT_ID, stack, WORKSPACE_ID, request);
    assertEquals(expectedResponse, actual);
    verify(instanceGroupService).getByStackAndFetchTemplates(STACK_ID);
    verify(upgradeService).isOsUpgrade(request);
    verify(instanceGroupService).getByStackAndFetchTemplates(STACK_ID);
    verify(limitConfiguration).getUpgradeNodeCountLimit();
    verify(clusterUpgradeAvailabilityService).checkForUpgradesByName(stack, false, true, request.getInternalUpgradeSettings());
    verify(clusterUpgradeAvailabilityService).filterUpgradeOptions(ACCOUNT_ID, upgradeResponseToReturn, request, true);
    verify(entitlementService).runtimeUpgradeEnabled(ACCOUNT_ID);
    verify(stackOperations).listByEnvironmentCrn(eq(WORKSPACE_ID), eq(ENVIRONMENT_CRN), any());
    verify(upgradePreconditionService).checkForRunningAttachedClusters(stackViewV4Responses, stack);
    verify(upgradePreconditionService).checkForNonUpgradeableAttachedClusters(stackViewV4Responses);
    verifyNoInteractions(clusterDBValidationService);
}
Also used : UpgradeV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.upgrade.UpgradeV4Response) StackInstanceCount(com.sequenceiq.cloudbreak.domain.projection.StackInstanceCount) UpgradeV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.tags.upgrade.UpgradeV4Request) StackViewV4Responses(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.StackViewV4Responses) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) Test(org.junit.jupiter.api.Test)

Example 39 with UpgradeV4Request

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

the class StackUpgradeOperationsTest method createUpgradeRequest.

private UpgradeV4Request createUpgradeRequest(Boolean replaceVm) {
    UpgradeV4Request upgradeRequest = new UpgradeV4Request();
    upgradeRequest.setReplaceVms(replaceVm);
    upgradeRequest.setInternalUpgradeSettings(new InternalUpgradeSettings(true, true, true));
    return upgradeRequest;
}
Also used : InternalUpgradeSettings(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.InternalUpgradeSettings) UpgradeV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.tags.upgrade.UpgradeV4Request)

Example 40 with UpgradeV4Request

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

the class DistroXUpgradeV1ControllerTest method testUpgradeCalledWithCrn.

@Test
public void testUpgradeCalledWithCrn() {
    DistroXUpgradeV1Request distroxUpgradeRequest = new DistroXUpgradeV1Request();
    UpgradeV4Request upgradeV4Request = new UpgradeV4Request();
    upgradeV4Request.setDryRun(Boolean.FALSE);
    when(upgradeAvailabilityService.isRuntimeUpgradeEnabledByAccountId(ACCOUNT_ID)).thenReturn(true);
    when(upgradeAvailabilityService.isOsUpgradeEnabledByAccountId(ACCOUNT_ID)).thenReturn(true);
    when(upgradeConverter.convert(distroxUpgradeRequest, new InternalUpgradeSettings(false, true, true))).thenReturn(upgradeV4Request);
    UpgradeV4Response upgradeV4Response = new UpgradeV4Response();
    when(upgradeService.triggerUpgrade(NameOrCrn.ofCrn(CLUSTER_NAME), WORKSPACE_ID, USER_CRN, upgradeV4Request)).thenReturn(upgradeV4Response);
    when(upgradeConverter.convert(upgradeV4Response)).thenReturn(new DistroXUpgradeV1Response());
    ThreadBasedUserCrnProvider.doAs(USER_CRN, () -> underTest.upgradeClusterByCrn(CLUSTER_NAME, distroxUpgradeRequest));
    verify(upgradeService).triggerUpgrade(NameOrCrn.ofCrn(CLUSTER_NAME), WORKSPACE_ID, USER_CRN, upgradeV4Request);
}
Also used : UpgradeV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.upgrade.UpgradeV4Response) InternalUpgradeSettings(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.InternalUpgradeSettings) UpgradeV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.tags.upgrade.UpgradeV4Request) DistroXUpgradeV1Response(com.sequenceiq.distrox.api.v1.distrox.model.upgrade.DistroXUpgradeV1Response) DistroXUpgradeV1Request(com.sequenceiq.distrox.api.v1.distrox.model.upgrade.DistroXUpgradeV1Request) Test(org.junit.jupiter.api.Test)

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