use of com.sequenceiq.cloudbreak.service.image.catalog.model.ImageCatalogPlatform in project cloudbreak by hortonworks.
the class ImageBasedDefaultCDHEntriesTest method shouldFallBackToAwsInCaseOfMissingCdhImages.
@Test
public void shouldFallBackToAwsInCaseOfMissingCdhImages() throws CloudbreakImageCatalogException {
ImageCatalogPlatform imageCatalogPlatform = imageCatalogPlatform(CloudPlatform.YARN.name());
List<Image> imageList = getImages();
when(images.getCdhImages()).thenReturn(imageList);
when(emptyImages.getCdhImages()).thenReturn(Collections.emptyList());
StatedImages statedImages = StatedImages.statedImages(images, null, null);
StatedImages emptyStatedImages = StatedImages.statedImages(emptyImages, null, null);
when(imageCatalogService.getImages(0L, IMAGE_CATALOG_NAME, imageCatalogPlatform)).thenReturn(emptyStatedImages);
when(imageCatalogService.getImages(0L, IMAGE_CATALOG_NAME, imageCatalogPlatform)).thenReturn(statedImages);
Map<String, ImageBasedDefaultCDHInfo> actual = victim.getEntries(0L, imageCatalogPlatform, IMAGE_CATALOG_NAME);
Image image = imageList.stream().filter(Image::isDefaultImage).findFirst().get();
verify(image, actual.get(IMAGE_VERSION));
}
use of com.sequenceiq.cloudbreak.service.image.catalog.model.ImageCatalogPlatform in project cloudbreak by hortonworks.
the class ImageBasedDefaultCDHEntriesTest method shouldReturnImageBasedDefaultCDHInfoMapByPlatformAndImageCatalog.
@Test
public void shouldReturnImageBasedDefaultCDHInfoMapByPlatformAndImageCatalog() throws CloudbreakImageCatalogException {
List<Image> imageList = getImages();
when(images.getCdhImages()).thenReturn(imageList);
ImageCatalogPlatform imageCatalogPlatform = imageCatalogPlatform(PLATFORM);
StatedImages statedImages = StatedImages.statedImages(images, null, null);
when(imageCatalogService.getImages(0L, IMAGE_CATALOG_NAME, imageCatalogPlatform)).thenReturn(statedImages);
Map<String, ImageBasedDefaultCDHInfo> actual = victim.getEntries(0L, imageCatalogPlatform, IMAGE_CATALOG_NAME);
Image image = imageList.stream().filter(Image::isDefaultImage).findFirst().get();
verify(image, actual.get(IMAGE_VERSION));
}
use of com.sequenceiq.cloudbreak.service.image.catalog.model.ImageCatalogPlatform in project cloudbreak by hortonworks.
the class StackImageServiceTest method testChangeImageCatalogOutOfFlow.
@Test
public void testChangeImageCatalogOutOfFlow() throws CloudbreakImageNotFoundException, CloudbreakImageCatalogException, IOException {
ImageCatalog imageCatalog = mock(ImageCatalog.class);
ImageCatalogPlatform imageCatalogPlatform = imageCatalogPlatform(stack.getCloudPlatform());
Image targetImage = anImage(IMAGE_ID);
StatedImage targetStatedImage = StatedImage.statedImage(targetImage, TARGET_IMAGE_CATALOG_URL, TARGET_IMAGE_CATALOG);
when(componentConfigProviderService.getImage(stack.getId())).thenReturn(anImageComponent());
when(imageCatalogService.getImageCatalogByName(stack.getWorkspace().getId(), TARGET_IMAGE_CATALOG)).thenReturn(imageCatalog);
when(imageCatalog.getName()).thenReturn(TARGET_IMAGE_CATALOG);
when(imageCatalog.getImageCatalogUrl()).thenReturn(TARGET_IMAGE_CATALOG_URL);
when(imageCatalogService.getImage(TARGET_IMAGE_CATALOG_URL, TARGET_IMAGE_CATALOG, IMAGE_ID)).thenReturn(targetStatedImage);
when(imageService.determineImageName(stack.getCloudPlatform().toLowerCase(), imageCatalogPlatform, stack.getRegion(), targetStatedImage.getImage())).thenReturn(IMAGE_NAME);
when(platformStringTransformer.getPlatformStringForImageCatalog(stack.getCloudPlatform(), stack.getPlatformVariant())).thenReturn(imageCatalogPlatform);
victim.changeImageCatalog(stack, TARGET_IMAGE_CATALOG);
verify(componentConfigProviderService).replaceImageComponentWithNew(componentArgumentCaptor.capture());
com.sequenceiq.cloudbreak.cloud.model.Image newImage = componentArgumentCaptor.getValue().getAttributes().get(com.sequenceiq.cloudbreak.cloud.model.Image.class);
assertEquals(TARGET_IMAGE_CATALOG, newImage.getImageCatalogName());
assertEquals(TARGET_IMAGE_CATALOG_URL, newImage.getImageCatalogUrl());
assertEquals(IMAGE_ID, newImage.getImageId());
}
use of com.sequenceiq.cloudbreak.service.image.catalog.model.ImageCatalogPlatform in project cloudbreak by hortonworks.
the class ImageCatalogServiceTest method testGetImagesFromDefaultWithPlatform.
@Test
public void testGetImagesFromDefaultWithPlatform() throws CloudbreakImageCatalogException, IOException {
setupUserProfileService();
setupImageCatalogProvider(DEFAULT_CATALOG_URL, V2_CB_CATALOG_FILE);
ImageCatalogPlatform imageCatalogPlatform = imageCatalogPlatform("AWS");
when(platformStringTransformer.getPlatformStringForImageCatalog(any(ImageCatalogPlatform.class), anyBoolean())).thenReturn(imageCatalogPlatform);
underTest.getImagesFromDefault(ORG_ID, null, imageCatalogPlatform, Collections.emptySet(), false);
verify(entitlementService, times(1)).baseImageEnabled(Objects.requireNonNull(Crn.fromString(user.getUserCrn())).getAccountId());
verify(entitlementService, never()).baseImageEnabled(user.getUserCrn());
verify(stackImageFilterService, never()).getApplicableImages(anyLong(), anyString(), anyString());
verify(stackImageFilterService, never()).getApplicableImages(anyLong(), anyString());
}
use of com.sequenceiq.cloudbreak.service.image.catalog.model.ImageCatalogPlatform in project cloudbreak by hortonworks.
the class ImageCatalogService method getImagesFromDefault.
public Images getImagesFromDefault(Long workspaceId, String stackName, ImageCatalogPlatform platform, Set<String> operatingSystems, boolean govCloud) throws CloudbreakImageCatalogException {
if (platform != null && isNotEmpty(platform.name()) && isNotEmpty(stackName)) {
throw new BadRequestException("Platform or stackName cannot be filled in the same request.");
}
if (platform != null && isNotEmpty(platform.name())) {
User user = getLoggedInUser();
Set<ImageCatalogPlatform> platforms = Set.of(platformStringTransformer.getPlatformStringForImageCatalog(platform, govCloud));
ImageFilter imageFilter = new ImageFilter(getDefaultImageCatalog(user), platforms, null, baseImageEnabled(), operatingSystems, null);
return getStatedImagesFilteredByOperatingSystems(imageFilter, image -> true).getImages();
} else if (isNotEmpty(stackName)) {
return stackImageFilterService.getApplicableImages(workspaceId, stackName);
} else {
throw new BadRequestException("Either platform or stackName should be filled in request.");
}
}
Aggregations