Search in sources :

Example 36 with CloudbreakImageCatalogV3

use of com.sequenceiq.cloudbreak.cloud.model.catalog.CloudbreakImageCatalogV3 in project cloudbreak by hortonworks.

the class ClusterUpgradeAvailabilityServiceTest method testGetImagesToUpgradeShouldReturnEmptyListWhenTheClusterIsNotRepairable.

@Test
public void testGetImagesToUpgradeShouldReturnEmptyListWhenTheClusterIsNotRepairable() throws CloudbreakImageNotFoundException, CloudbreakImageCatalogException {
    com.sequenceiq.cloudbreak.cloud.model.Image currentImage = createCurrentImage();
    ImageCatalog imageCatalogDomain = createImageCatalogDomain();
    Result<Map<HostGroupName, Set<InstanceMetaData>>, RepairValidation> result = mock(Result.class);
    Image currentImageFromCatalog = mock(com.sequenceiq.cloudbreak.cloud.model.catalog.Image.class);
    Image properImage = mock(com.sequenceiq.cloudbreak.cloud.model.catalog.Image.class);
    Image otherImage = mock(com.sequenceiq.cloudbreak.cloud.model.catalog.Image.class);
    CloudbreakImageCatalogV3 imageCatalog = createImageCatalog(List.of(properImage, otherImage, currentImageFromCatalog));
    UpgradeV4Response response = new UpgradeV4Response();
    ImageInfoV4Response imageInfo = new ImageInfoV4Response();
    imageInfo.setImageId(IMAGE_ID);
    imageInfo.setCreated(1);
    imageInfo.setComponentVersions(createExpectedPackageVersions());
    response.setUpgradeCandidates(List.of(imageInfo));
    Stack stack = createStack(createStackStatus(Status.AVAILABLE), StackType.WORKLOAD);
    RepairValidation repairValidation = mock(RepairValidation.class);
    ImageFilterParams imageFilterParams = createImageFilterParams(stack, currentImageFromCatalog);
    when(clusterRepairService.repairWithDryRun(stack.getId())).thenReturn(result);
    when(clusterRepairService.repairWithDryRun(stack.getId())).thenReturn(result);
    when(result.isError()).thenReturn(true);
    when(imageService.getImage(stack.getId())).thenReturn(currentImage);
    when(imageCatalogService.getImageCatalogByName(stack.getWorkspace().getId(), CATALOG_NAME)).thenReturn(imageCatalogDomain);
    when(imageCatalogProvider.getImageCatalogV3(CATALOG_URL)).thenReturn(imageCatalog);
    ImageFilterResult filteredImages = createFilteredImages(properImage);
    when(imageFilterParamsFactory.create(currentImageFromCatalog, lockComponents, stack, INTERNAL_UPGRADE_SETTINGS)).thenReturn(imageFilterParams);
    when(clusterUpgradeImageFilter.filter(ACCOUNT_ID, imageCatalog, imageFilterParams)).thenReturn(filteredImages);
    when(upgradeOptionsResponseFactory.createV4Response(currentImageFromCatalog, filteredImages, stack.getCloudPlatform(), stack.getRegion(), currentImage.getImageCatalogName())).thenReturn(response);
    when(imageProvider.getCurrentImageFromCatalog(CURRENT_IMAGE_ID, imageCatalog)).thenReturn(currentImageFromCatalog);
    String validationError = "External RDS is not attached.";
    when(result.getError()).thenReturn(repairValidation);
    when(repairValidation.getValidationErrors()).thenReturn(Collections.singletonList(validationError));
    when(instanceMetaDataService.anyInstanceStopped(stack.getId())).thenReturn(false);
    UpgradeV4Response actual = underTest.checkForUpgradesByName(stack, lockComponents, true, INTERNAL_UPGRADE_SETTINGS);
    assertNull(actual.getCurrent());
    assertEquals(1, actual.getUpgradeCandidates().size());
    assertEquals(validationError, actual.getReason());
}
Also used : RepairValidation(com.sequenceiq.cloudbreak.service.cluster.model.RepairValidation) CloudbreakImageCatalogV3(com.sequenceiq.cloudbreak.cloud.model.catalog.CloudbreakImageCatalogV3) Image(com.sequenceiq.cloudbreak.cloud.model.catalog.Image) ImageCatalog(com.sequenceiq.cloudbreak.domain.ImageCatalog) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) UpgradeV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.upgrade.UpgradeV4Response) ImageFilterParams(com.sequenceiq.cloudbreak.service.upgrade.image.ImageFilterParams) ImageInfoV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.image.ImageInfoV4Response) ImageFilterResult(com.sequenceiq.cloudbreak.service.upgrade.image.ImageFilterResult) Map(java.util.Map) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 37 with CloudbreakImageCatalogV3

use of com.sequenceiq.cloudbreak.cloud.model.catalog.CloudbreakImageCatalogV3 in project cloudbreak by hortonworks.

the class CustomImageProviderTest method getImageFromCatalog.

private Image getImageFromCatalog(String catalogFile, String imageId) throws IOException, CloudbreakImageNotFoundException {
    String catalogJson = FileReaderUtils.readFileFromClasspath(catalogFile);
    CloudbreakImageCatalogV3 catalog = JsonUtil.readValue(catalogJson, CloudbreakImageCatalogV3.class);
    Images images = catalog.getImages();
    List<Image> imagesAll = List.of(images.getBaseImages(), images.getCdhImages(), images.getFreeIpaImages()).stream().flatMap(List::stream).collect(Collectors.toList());
    Optional<? extends Image> image = findImageByImageId(imageId, imagesAll);
    if (image.isEmpty()) {
        throw new CloudbreakImageNotFoundException(String.format("No image was found with id %s", imageId));
    }
    return image.get();
}
Also used : Images(com.sequenceiq.cloudbreak.cloud.model.catalog.Images) CloudbreakImageNotFoundException(com.sequenceiq.cloudbreak.core.CloudbreakImageNotFoundException) CloudbreakImageCatalogV3(com.sequenceiq.cloudbreak.cloud.model.catalog.CloudbreakImageCatalogV3) VmImage(com.sequenceiq.cloudbreak.domain.VmImage) Image(com.sequenceiq.cloudbreak.cloud.model.catalog.Image) CustomImage(com.sequenceiq.cloudbreak.domain.CustomImage)

Example 38 with CloudbreakImageCatalogV3

use of com.sequenceiq.cloudbreak.cloud.model.catalog.CloudbreakImageCatalogV3 in project cloudbreak by hortonworks.

the class DefaultImageCatalogServiceTest method testGetImageFromDefaultCatalogWithoutRuntime.

@Test
public void testGetImageFromDefaultCatalogWithoutRuntime() throws CloudbreakImageNotFoundException, CloudbreakImageCatalogException {
    CloudbreakImageCatalogV3 freeipaImageCatalogV3 = mock(CloudbreakImageCatalogV3.class);
    Images images = mock(Images.class);
    Image expected = mock(Image.class);
    Image notExpectedByCreated = mock(Image.class);
    Image notExpectedByProvider = mock(Image.class);
    Map<String, Map<String, String>> expectedImageSetByProvider = Map.of("aws", Map.of());
    Map<String, Map<String, String>> notExpectedImageSetByProvider = Map.of("azure", Map.of());
    List<Image> imageList = List.of(expected, notExpectedByCreated, notExpectedByProvider);
    when(imageCatalogProvider.getImageCatalogV3(DEFAULT_FREEIPA_CATALOG_URL)).thenReturn(freeipaImageCatalogV3);
    when(freeipaImageCatalogV3.getImages()).thenReturn(images);
    when(images.getFreeIpaImages()).thenReturn(imageList);
    when(expected.getImageSetsByProvider()).thenReturn(expectedImageSetByProvider);
    when(expected.getCreated()).thenReturn(2L);
    when(notExpectedByCreated.getImageSetsByProvider()).thenReturn(expectedImageSetByProvider);
    when(notExpectedByCreated.getCreated()).thenReturn(1L);
    when(notExpectedByProvider.getImageSetsByProvider()).thenReturn(notExpectedImageSetByProvider);
    when(notExpectedByProvider.getCreated()).thenReturn(0L);
    StatedImage actual = victim.getImageFromDefaultCatalog(ImageType.FREEIPA.name(), imageCatalogPlatform("aws"));
    assertEquals(expected, actual.getImage());
}
Also used : Images(com.sequenceiq.cloudbreak.cloud.model.catalog.Images) CloudbreakImageCatalogV3(com.sequenceiq.cloudbreak.cloud.model.catalog.CloudbreakImageCatalogV3) Image(com.sequenceiq.cloudbreak.cloud.model.catalog.Image) Map(java.util.Map) Test(org.junit.jupiter.api.Test)

Example 39 with CloudbreakImageCatalogV3

use of com.sequenceiq.cloudbreak.cloud.model.catalog.CloudbreakImageCatalogV3 in project cloudbreak by hortonworks.

the class ImageCatalogProviderTest method shouldReturnImageCatalogWithForceRefresh.

@Test
public void shouldReturnImageCatalogWithForceRefresh() throws CloudbreakImageCatalogException {
    ImageCatalogWrapper imageCatalogWrapper = mock(ImageCatalogWrapper.class);
    CloudbreakImageCatalogV3 imageCatalogV3 = mock(CloudbreakImageCatalogV3.class);
    when(cachedImageCatalogWrapperProvider.getImageCatalogWrapper(IMAGE_CATALOG_URL)).thenReturn(imageCatalogWrapper);
    when(imageCatalogWrapper.getImageCatalog()).thenReturn(imageCatalogV3);
    CloudbreakImageCatalogV3 actual = victim.getImageCatalogV3(IMAGE_CATALOG_URL, true);
    assertEquals(imageCatalogV3, actual);
    verify(cachedImageCatalogWrapperProvider).evictImageCatalogCache(IMAGE_CATALOG_URL);
}
Also used : ImageCatalogWrapper(com.sequenceiq.cloudbreak.service.image.catalog.model.ImageCatalogWrapper) CloudbreakImageCatalogV3(com.sequenceiq.cloudbreak.cloud.model.catalog.CloudbreakImageCatalogV3) Test(org.junit.jupiter.api.Test)

Example 40 with CloudbreakImageCatalogV3

use of com.sequenceiq.cloudbreak.cloud.model.catalog.CloudbreakImageCatalogV3 in project cloudbreak by hortonworks.

the class ImageCatalogServiceTest method setupImageCatalogProviderWithoutVersions.

private void setupImageCatalogProviderWithoutVersions(String catalogUrl, String catalogFile) throws IOException, CloudbreakImageCatalogException {
    String catalogJson = FileReaderUtils.readFileFromClasspath(catalogFile);
    CloudbreakImageCatalogV3 catalog = JsonUtil.readValue(catalogJson, CloudbreakImageCatalogV3.class);
    ReflectionTestUtils.setField(catalog, "versions", null);
    when(imageCatalog.getImageCatalogUrl()).thenReturn(catalogUrl);
    when(imageCatalogProvider.getImageCatalogV3(catalogUrl)).thenReturn(catalog);
}
Also used : CloudbreakImageCatalogV3(com.sequenceiq.cloudbreak.cloud.model.catalog.CloudbreakImageCatalogV3) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString)

Aggregations

CloudbreakImageCatalogV3 (com.sequenceiq.cloudbreak.cloud.model.catalog.CloudbreakImageCatalogV3)48 Test (org.junit.jupiter.api.Test)21 Image (com.sequenceiq.cloudbreak.cloud.model.catalog.Image)17 Test (org.junit.Test)14 ImageFilterResult (com.sequenceiq.cloudbreak.service.upgrade.image.ImageFilterResult)10 UpgradeV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.upgrade.UpgradeV4Response)8 ImageFilterParams (com.sequenceiq.cloudbreak.service.upgrade.image.ImageFilterParams)8 ImageCatalog (com.sequenceiq.cloudbreak.domain.ImageCatalog)7 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)7 Images (com.sequenceiq.cloudbreak.cloud.model.catalog.Images)6 CloudbreakVersion (com.sequenceiq.cloudbreak.cloud.model.catalog.CloudbreakVersion)5 CloudbreakImageCatalogException (com.sequenceiq.cloudbreak.core.CloudbreakImageCatalogException)5 StatedImages (com.sequenceiq.cloudbreak.service.image.StatedImages)5 Image (com.sequenceiq.cloudbreak.cloud.model.Image)4 CloudbreakImageNotFoundException (com.sequenceiq.cloudbreak.core.CloudbreakImageNotFoundException)4 List (java.util.List)4 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 Versions (com.sequenceiq.cloudbreak.cloud.model.catalog.Versions)3 ImageFilter (com.sequenceiq.cloudbreak.service.image.ImageFilter)3 ImageCatalogWrapper (com.sequenceiq.cloudbreak.service.image.catalog.model.ImageCatalogWrapper)3