use of com.sequenceiq.cloudbreak.cloud.model.catalog.CloudbreakImageCatalogV3 in project cloudbreak by hortonworks.
the class ImageCatalogService method getImages.
public StatedImages getImages(ImageFilter imageFilter) throws CloudbreakImageCatalogException {
LOGGER.info("Determine images for imageCatalogUrl: '{}', platforms: '{}' and Cloudbreak version: '{}'.", imageFilter.getImageCatalog().getImageCatalogUrl(), imageFilter.getPlatforms(), imageFilter.getCbVersion());
validateRequestPlatforms(imageFilter.getPlatforms());
CloudbreakImageCatalogV3 imageCatalogV3 = imageCatalogProvider.getImageCatalogV3(imageFilter.getImageCatalog().getImageCatalogUrl());
if (imageCatalogV3 != null) {
LOGGER.info("Image catalog found, filtering the images..");
return imageCatalogServiceProxy.getImages(imageCatalogV3, imageFilter);
} else {
LOGGER.warn("Image catalog {} not found, returning empty response", imageFilter.getImageCatalog());
return statedImages(emptyImages(), imageFilter.getImageCatalog().getImageCatalogUrl(), imageFilter.getImageCatalog().getName());
}
}
use of com.sequenceiq.cloudbreak.cloud.model.catalog.CloudbreakImageCatalogV3 in project cloudbreak by hortonworks.
the class VersionBasedImageProvider method getImages.
public StatedImages getImages(CloudbreakImageCatalogV3 imageCatalogV3, ImageFilter imageFilter) {
Set<String> suppertedVersions;
Set<String> vMImageUUIDs = new HashSet<>();
Set<String> defaultVMImageUUIDs = new HashSet<>();
String currentCbVersion;
List<CloudbreakVersion> cloudbreakVersions = cloudbreakVersionListProvider.getVersions(imageCatalogV3);
currentCbVersion = getCBVersion(imageFilter, cloudbreakVersions);
List<CloudbreakVersion> exactMatchedImages = cloudbreakVersions.stream().filter(cloudbreakVersion -> cloudbreakVersion.getVersions().contains(currentCbVersion)).collect(toList());
if (!exactMatchedImages.isEmpty()) {
for (CloudbreakVersion exactMatchedImg : exactMatchedImages) {
vMImageUUIDs.addAll(exactMatchedImg.getImageIds());
defaultVMImageUUIDs.addAll(exactMatchedImg.getDefaults());
}
suppertedVersions = Collections.singleton(currentCbVersion);
} else {
LOGGER.debug("No image found with exact match for version {} Trying prefix matching", currentCbVersion);
PrefixMatchImages prefixMatchImages = prefixMatcherService.prefixMatchForCBVersion(imageFilter.getCbVersion(), cloudbreakVersions);
vMImageUUIDs.addAll(prefixMatchImages.getvMImageUUIDs());
defaultVMImageUUIDs.addAll(prefixMatchImages.getDefaultVMImageUUIDs());
suppertedVersions = prefixMatchImages.getSupportedVersions();
}
LOGGER.info("The following images are matching for CB version ({}): {} ", currentCbVersion, vMImageUUIDs);
List<Image> baseImages = filterImagesByPlatforms(imageFilter.getPlatforms(), imageCatalogV3.getImages().getBaseImages(), vMImageUUIDs);
List<Image> cdhImages = filterImagesByPlatforms(imageFilter.getPlatforms(), imageCatalogV3.getImages().getCdhImages(), vMImageUUIDs);
List<Image> freeipaImages = filterImagesByPlatforms(imageFilter.getPlatforms(), imageCatalogV3.getImages().getFreeIpaImages(), vMImageUUIDs);
List<Image> defaultImages = defaultVMImageUUIDs.stream().map(imageId -> getImage(imageId, imageCatalogV3.getImages())).flatMap(Optional::stream).collect(Collectors.toList());
Collection<String> latestDefaultImageUuids = latestDefaultImageUuidProvider.getLatestDefaultImageUuids(imageFilter.getPlatforms(), defaultImages);
(!freeipaImages.isEmpty() ? freeipaImages.stream() : Stream.of(baseImages.stream(), cdhImages.stream()).reduce(Stream::concat).orElseGet(Stream::empty)).forEach(img -> img.setDefaultImage(latestDefaultImageUuids.contains(img.getUuid())));
if (!imageFilter.isBaseImageEnabled()) {
baseImages.clear();
}
return statedImages(new Images(baseImages, cdhImages, freeipaImages, suppertedVersions), imageFilter.getImageCatalog().getImageCatalogUrl(), imageFilter.getImageCatalog().getName());
}
use of com.sequenceiq.cloudbreak.cloud.model.catalog.CloudbreakImageCatalogV3 in project cloudbreak by hortonworks.
the class LockedComponentServiceTest method testIsComponentsLockedShouldReturnFalseWhenTheComponentVersionsAreMatches.
@Test
public void testIsComponentsLockedShouldReturnFalseWhenTheComponentVersionsAreMatches() throws CloudbreakImageNotFoundException, CloudbreakImageCatalogException {
Image currentImage = new Image("imageName", Map.of(), "redhat6", "redhat6", "", "default", "default-id", Map.of());
when(componentConfigProviderService.getImage(STACK_ID)).thenReturn(currentImage);
CloudbreakImageCatalogV3 imageCatalog = new CloudbreakImageCatalogV3(null, null);
when(imageCatalogProvider.getImageCatalogV3(currentImage.getImageCatalogUrl())).thenReturn(imageCatalog);
com.sequenceiq.cloudbreak.cloud.model.catalog.Image currentCatalogImage = mock(com.sequenceiq.cloudbreak.cloud.model.catalog.Image.class);
when(imageProvider.getCurrentImageFromCatalog(currentImage.getImageId(), imageCatalog)).thenReturn(currentCatalogImage);
com.sequenceiq.cloudbreak.cloud.model.catalog.Image targetCatalogImage = mock(com.sequenceiq.cloudbreak.cloud.model.catalog.Image.class);
when(imageProvider.getCurrentImageFromCatalog(TARGET_IMAGE_ID, imageCatalog)).thenReturn(targetCatalogImage);
when(imageFilterParamsFactory.getStackRelatedParcels(stack)).thenReturn(ACTIVATED_PARCELS);
when(lockedComponentChecker.isUpgradePermitted(currentCatalogImage, targetCatalogImage, ACTIVATED_PARCELS)).thenReturn(false);
assertFalse(underTest.isComponentsLocked(stack, TARGET_IMAGE_ID));
verify(componentConfigProviderService).getImage(STACK_ID);
verify(imageCatalogProvider).getImageCatalogV3(currentImage.getImageCatalogUrl());
verify(imageProvider).getCurrentImageFromCatalog(currentImage.getImageId(), imageCatalog);
verify(imageProvider).getCurrentImageFromCatalog(TARGET_IMAGE_ID, imageCatalog);
verify(imageFilterParamsFactory).getStackRelatedParcels(stack);
verify(lockedComponentChecker).isUpgradePermitted(currentCatalogImage, targetCatalogImage, ACTIVATED_PARCELS);
}
use of com.sequenceiq.cloudbreak.cloud.model.catalog.CloudbreakImageCatalogV3 in project cloudbreak by hortonworks.
the class ClusterUpgradeAvailabilityServiceTest method testCheckForUpgradesByNameShouldReturnImagesFromFallbackCatalogWhenThereAreAvailableImagesButImageCatalogByNameNotFound.
@Test
public void testCheckForUpgradesByNameShouldReturnImagesFromFallbackCatalogWhenThereAreAvailableImagesButImageCatalogByNameNotFound() throws CloudbreakImageNotFoundException, CloudbreakImageCatalogException {
Stack stack = createStack(createStackStatus(Status.AVAILABLE), StackType.WORKLOAD);
com.sequenceiq.cloudbreak.cloud.model.Image currentImage = createCurrentImage();
Result result = Mockito.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));
ImageFilterParams imageFilterParams = createImageFilterParams(stack, currentImageFromCatalog);
UpgradeV4Response response = new UpgradeV4Response();
when(imageFilterParamsFactory.create(currentImageFromCatalog, lockComponents, stack, INTERNAL_UPGRADE_SETTINGS)).thenReturn(imageFilterParams);
when(clusterRepairService.repairWithDryRun(stack.getId())).thenReturn(result);
when(result.isError()).thenReturn(false);
when(imageService.getImage(stack.getId())).thenReturn(currentImage);
when(imageCatalogService.getImageCatalogByName(stack.getWorkspace().getId(), CATALOG_NAME)).thenThrow(new NotFoundException("not found"));
when(imageCatalogProvider.getImageCatalogV3(FALLBACK_CATALOG_URL)).thenReturn(imageCatalog);
ImageFilterResult filteredImages = createFilteredImages(properImage);
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);
when(instanceMetaDataService.anyInstanceStopped(stack.getId())).thenReturn(false);
UpgradeV4Response actual = underTest.checkForUpgradesByName(stack, lockComponents, true, INTERNAL_UPGRADE_SETTINGS);
assertEquals(response, actual);
verify(imageService).getImage(stack.getId());
verify(imageCatalogProvider).getImageCatalogV3(FALLBACK_CATALOG_URL);
verify(clusterUpgradeImageFilter).filter(ACCOUNT_ID, imageCatalog, imageFilterParams);
verify(upgradeOptionsResponseFactory).createV4Response(currentImageFromCatalog, filteredImages, stack.getCloudPlatform(), stack.getRegion(), currentImage.getImageCatalogName());
}
use of com.sequenceiq.cloudbreak.cloud.model.catalog.CloudbreakImageCatalogV3 in project cloudbreak by hortonworks.
the class ClusterUpgradeAvailabilityServiceTest method testCheckForUpgradesByNameShouldReturnImagesWhenThereAreAvailableImagesUsingImageCatalogByName.
@Test
public void testCheckForUpgradesByNameShouldReturnImagesWhenThereAreAvailableImagesUsingImageCatalogByName() throws CloudbreakImageNotFoundException, CloudbreakImageCatalogException {
Stack stack = createStack(createStackStatus(Status.AVAILABLE), StackType.WORKLOAD);
com.sequenceiq.cloudbreak.cloud.model.Image currentImage = createCurrentImage();
Result result = Mockito.mock(Result.class);
ImageCatalog imageCatalogDomain = createImageCatalogDomain();
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));
ImageFilterParams imageFilterParams = createImageFilterParams(stack, currentImageFromCatalog);
UpgradeV4Response response = new UpgradeV4Response();
when(imageFilterParamsFactory.create(currentImageFromCatalog, lockComponents, stack, INTERNAL_UPGRADE_SETTINGS)).thenReturn(imageFilterParams);
when(clusterRepairService.repairWithDryRun(stack.getId())).thenReturn(result);
when(result.isError()).thenReturn(false);
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(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);
when(instanceMetaDataService.anyInstanceStopped(stack.getId())).thenReturn(false);
UpgradeV4Response actual = underTest.checkForUpgradesByName(stack, lockComponents, true, INTERNAL_UPGRADE_SETTINGS);
assertEquals(response, actual);
verify(imageService).getImage(stack.getId());
verify(imageCatalogProvider).getImageCatalogV3(CATALOG_URL);
verify(clusterUpgradeImageFilter).filter(ACCOUNT_ID, imageCatalog, imageFilterParams);
verify(upgradeOptionsResponseFactory).createV4Response(currentImageFromCatalog, filteredImages, stack.getCloudPlatform(), stack.getRegion(), currentImage.getImageCatalogName());
}
Aggregations