Search in sources :

Example 6 with ImageComponentVersions

use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.image.ImageComponentVersions in project cloudbreak by hortonworks.

the class SdxRuntimeUpgradeServiceTest method testShowLatestOnlyShouldReturnLatestUpgradeCandidatesPerRuntime.

@Test
public void testShowLatestOnlyShouldReturnLatestUpgradeCandidatesPerRuntime() {
    when(entitlementService.runtimeUpgradeEnabled(any())).thenReturn(true);
    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.LATEST_ONLY);
    UpgradeV4Response actualResponse = underTest.filterSdxUpgradeResponse(ACCOUNT_ID, sdxCluster.getClusterName(), sdxUpgradeRequest, upgradeV4Response);
    assertEquals(2, actualResponse.getUpgradeCandidates().size());
    assertFalse(actualResponse.getUpgradeCandidates().stream().anyMatch(imageInfoV4Response -> imageInfoV4Response.getImageId().equals(IMAGE_ID + 1)));
    assertTrue(actualResponse.getUpgradeCandidates().stream().anyMatch(imageInfoV4Response -> imageInfoV4Response.getImageId().equals(IMAGE_ID + 2)));
    assertTrue(actualResponse.getUpgradeCandidates().stream().anyMatch(imageInfoV4Response -> imageInfoV4Response.getImageId().equals(IMAGE_ID + 3)));
}
Also used : UpgradeV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.upgrade.UpgradeV4Response) Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) BeforeEach(org.junit.jupiter.api.BeforeEach) RestClientFactory(com.sequenceiq.cloudbreak.client.RestClientFactory) SdxCluster(com.sequenceiq.datalake.entity.SdxCluster) SdxUpgradeResponse(com.sequenceiq.sdx.api.model.SdxUpgradeResponse) SdxUpgradeShowAvailableImages(com.sequenceiq.sdx.api.model.SdxUpgradeShowAvailableImages) ArgumentMatchers.anyLong(org.mockito.ArgumentMatchers.anyLong) ImageComponentVersions(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.image.ImageComponentVersions) PaywallAccessChecker(com.sequenceiq.cloudbreak.auth.PaywallAccessChecker) EntitlementService(com.sequenceiq.cloudbreak.auth.altus.EntitlementService) SdxClusterShape(com.sequenceiq.sdx.api.model.SdxClusterShape) Mock(org.mockito.Mock) SdxReactorFlowManager(com.sequenceiq.datalake.flow.SdxReactorFlowManager) StringUtils(org.apache.commons.lang3.StringUtils) JsonCMLicense(com.sequenceiq.cloudbreak.auth.JsonCMLicense) ArrayList(java.util.ArrayList) Mockito.doThrow(org.mockito.Mockito.doThrow) CloudbreakMessagesService(com.sequenceiq.cloudbreak.message.CloudbreakMessagesService) SdxUpgradeClusterConverter(com.sequenceiq.datalake.controller.sdx.SdxUpgradeClusterConverter) ImageInfoV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.image.ImageInfoV4Response) ThreadBasedUserCrnProvider(com.sequenceiq.cloudbreak.auth.ThreadBasedUserCrnProvider) ArgumentCaptor(org.mockito.ArgumentCaptor) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) UpgradeV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.upgrade.UpgradeV4Response) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) SdxService(com.sequenceiq.datalake.service.sdx.SdxService) InjectMocks(org.mockito.InjectMocks) RegionAwareInternalCrnGenerator(com.sequenceiq.cloudbreak.auth.crn.RegionAwareInternalCrnGenerator) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) MockitoExtension(org.mockito.junit.jupiter.MockitoExtension) StackV4Endpoint(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.StackV4Endpoint) ReflectionTestUtils(org.springframework.test.util.ReflectionTestUtils) Mockito.times(org.mockito.Mockito.times) Mockito.when(org.mockito.Mockito.when) Crn(com.sequenceiq.cloudbreak.auth.crn.Crn) Mockito.verify(org.mockito.Mockito.verify) DisplayName(org.junit.jupiter.api.DisplayName) RegionAwareInternalCrnGeneratorFactory(com.sequenceiq.cloudbreak.auth.crn.RegionAwareInternalCrnGeneratorFactory) Test(org.junit.jupiter.api.Test) List(java.util.List) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) SdxUpgradeReplaceVms(com.sequenceiq.sdx.api.model.SdxUpgradeReplaceVms) SdxUpgradeRequest(com.sequenceiq.sdx.api.model.SdxUpgradeRequest) ClouderaManagerLicenseProvider(com.sequenceiq.cloudbreak.auth.ClouderaManagerLicenseProvider) Assertions.assertDoesNotThrow(org.junit.jupiter.api.Assertions.assertDoesNotThrow) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) ImageInfoV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.image.ImageInfoV4Response) ImageComponentVersions(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.image.ImageComponentVersions) Test(org.junit.jupiter.api.Test)

Example 7 with ImageComponentVersions

use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.image.ImageComponentVersions in project cloudbreak by hortonworks.

the class SdxRuntimeUpgradeService method validateRuntime.

private String validateRuntime(List<ImageInfoV4Response> upgradeCandidates, String runtime) {
    String imageId;
    Supplier<Stream<ImageInfoV4Response>> imagesWithMatchingRuntime = () -> upgradeCandidates.stream().filter(imageInfoV4Response -> runtime.equals(imageInfoV4Response.getComponentVersions().getCdp()));
    boolean hasCompatibleImageWithRuntime = imagesWithMatchingRuntime.get().anyMatch(e -> true);
    if (!hasCompatibleImageWithRuntime) {
        String availableRuntimes = upgradeCandidates.stream().map(ImageInfoV4Response::getComponentVersions).map(ImageComponentVersions::getCdp).distinct().collect(Collectors.joining(","));
        String errorMessage;
        if (StringUtils.isEmpty(availableRuntimes)) {
            errorMessage = String.format("There is no image eligible for the cluster upgrade with runtime: %s.", runtime);
        } else {
            errorMessage = String.format("There is no image eligible for the cluster upgrade with runtime: %s. " + "Please choose a runtime from the following: %s", runtime, availableRuntimes);
        }
        throw new BadRequestException(errorMessage);
    } else {
        ImageInfoV4Response imageInfoV4Response = imagesWithMatchingRuntime.get().max(ImageInfoV4Response.creationBasedComparator()).orElseThrow();
        imageId = imageInfoV4Response.getImageId();
    }
    return imageId;
}
Also used : BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) Stream(java.util.stream.Stream) ImageInfoV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.image.ImageInfoV4Response) ImageComponentVersions(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.image.ImageComponentVersions)

Example 8 with ImageComponentVersions

use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.image.ImageComponentVersions in project cloudbreak by hortonworks.

the class DistroXUpgradeAvailabilityServiceTest method createImageResponse.

private ImageInfoV4Response createImageResponse(long creation, String cdp) {
    ImageInfoV4Response image = new ImageInfoV4Response();
    image.setCreated(creation);
    image.setComponentVersions(new ImageComponentVersions("dontcare", "dontcare", cdp, "dontcare", "dontcare", "dontcare", List.of()));
    return image;
}
Also used : ImageInfoV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.image.ImageInfoV4Response) ImageComponentVersions(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.image.ImageComponentVersions)

Example 9 with ImageComponentVersions

use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.image.ImageComponentVersions in project cloudbreak by hortonworks.

the class ComponentVersionProviderTest method testGetComponentVersions.

@Test
void testGetComponentVersions() {
    ImageComponentVersions componentVersions = underTest.getComponentVersions(createPackageVersions(), CENTOS_7, OS_PATCH_LEVEL);
    List<ParcelInfoResponse> parcelInfoResponseList = componentVersions.getParcelInfoResponseList();
    assertEquals(4, parcelInfoResponseList.size());
    assertIterableEquals(createParcelInfoList(), parcelInfoResponseList);
    assertEquals(CENTOS_7, componentVersions.getOs());
    assertEquals(OS_PATCH_LEVEL, componentVersions.getOsPatchLevel());
    assertEquals("7.2.10", componentVersions.getCdp());
    assertEquals("7.4.2", componentVersions.getCm());
    assertEquals("16151091", componentVersions.getCdpGBN());
    assertEquals("15633910", componentVersions.getCmGBN());
}
Also used : ImageComponentVersions(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.image.ImageComponentVersions) ParcelInfoResponse(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.image.ParcelInfoResponse) Test(org.junit.jupiter.api.Test)

Example 10 with ImageComponentVersions

use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.image.ImageComponentVersions in project cloudbreak by hortonworks.

the class UpgradeOptionsResponseFactoryTest method testCreateV4ResponseShouldReturnTheUpgradeOptionsFromTheGivenParameters.

@Test
public void testCreateV4ResponseShouldReturnTheUpgradeOptionsFromTheGivenParameters() throws CloudbreakImageNotFoundException {
    ImageCatalogPlatform imageCatalogPlatform = imageCatalogPlatform(CLOUD_PLATFORM);
    Map<String, String> packageVersions = createPackageVersions();
    ImageComponentVersions expectedPackageVersions = creatExpectedPackageVersions();
    Image currentImage = createImage(packageVersions);
    ImageFilterResult availableImages = createAvailableImages(packageVersions);
    when(platformStringTransformer.getPlatformStringForImageCatalogByRegion(anyString(), anyString())).thenReturn(imageCatalogPlatform);
    when(imageService.determineImageName(CLOUD_PLATFORM, imageCatalogPlatform, REGION, currentImage)).thenReturn(IMAGE_NAME);
    when(imageService.determineImageName(CLOUD_PLATFORM, imageCatalogPlatform, REGION, availableImages.getImages().get(0))).thenReturn(IMAGE_NAME);
    when(componentVersionProvider.getComponentVersions(eq(packageVersions), any(), any())).thenReturn(expectedPackageVersions);
    UpgradeV4Response actual = underTest.createV4Response(currentImage, availableImages, CLOUD_PLATFORM, REGION, IMAGE_CATALOG_NAME);
    assertEquals(IMAGE_ID, actual.getCurrent().getImageId());
    assertEquals(IMAGE_CATALOG_NAME, actual.getCurrent().getImageCatalogName());
    assertEquals(IMAGE_NAME, actual.getCurrent().getImageName());
    assertEquals(expectedPackageVersions, actual.getCurrent().getComponentVersions());
    assertEquals(CREATION_DATE, actual.getCurrent().getCreated());
    assertEquals(IMAGE_ID, actual.getUpgradeCandidates().get(0).getImageId());
    assertEquals(IMAGE_CATALOG_NAME, actual.getUpgradeCandidates().get(0).getImageCatalogName());
    assertEquals(IMAGE_NAME, actual.getUpgradeCandidates().get(0).getImageName());
    assertEquals(expectedPackageVersions, actual.getUpgradeCandidates().get(0).getComponentVersions());
    assertEquals(CREATION_DATE, actual.getUpgradeCandidates().get(0).getCreated());
}
Also used : UpgradeV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.upgrade.UpgradeV4Response) ImageCatalogPlatform(com.sequenceiq.cloudbreak.service.image.catalog.model.ImageCatalogPlatform) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) ImageFilterResult(com.sequenceiq.cloudbreak.service.upgrade.image.ImageFilterResult) Image(com.sequenceiq.cloudbreak.cloud.model.catalog.Image) ImageComponentVersions(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.image.ImageComponentVersions) Test(org.junit.Test)

Aggregations

ImageComponentVersions (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.image.ImageComponentVersions)11 ImageInfoV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.image.ImageInfoV4Response)5 UpgradeV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.upgrade.UpgradeV4Response)3 BadRequestException (com.sequenceiq.cloudbreak.common.exception.BadRequestException)3 Test (org.junit.jupiter.api.Test)3 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)3 StackV4Endpoint (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.StackV4Endpoint)2 ClouderaManagerLicenseProvider (com.sequenceiq.cloudbreak.auth.ClouderaManagerLicenseProvider)2 JsonCMLicense (com.sequenceiq.cloudbreak.auth.JsonCMLicense)2 PaywallAccessChecker (com.sequenceiq.cloudbreak.auth.PaywallAccessChecker)2 ThreadBasedUserCrnProvider (com.sequenceiq.cloudbreak.auth.ThreadBasedUserCrnProvider)2 EntitlementService (com.sequenceiq.cloudbreak.auth.altus.EntitlementService)2 Crn (com.sequenceiq.cloudbreak.auth.crn.Crn)2 RegionAwareInternalCrnGenerator (com.sequenceiq.cloudbreak.auth.crn.RegionAwareInternalCrnGenerator)2 RegionAwareInternalCrnGeneratorFactory (com.sequenceiq.cloudbreak.auth.crn.RegionAwareInternalCrnGeneratorFactory)2 RestClientFactory (com.sequenceiq.cloudbreak.client.RestClientFactory)2 CloudbreakMessagesService (com.sequenceiq.cloudbreak.message.CloudbreakMessagesService)2 SdxUpgradeClusterConverter (com.sequenceiq.datalake.controller.sdx.SdxUpgradeClusterConverter)2 SdxCluster (com.sequenceiq.datalake.entity.SdxCluster)2 SdxReactorFlowManager (com.sequenceiq.datalake.flow.SdxReactorFlowManager)2