Search in sources :

Example 6 with ImageCatalogPlatform

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));
}
Also used : ImageCatalogPlatform(com.sequenceiq.cloudbreak.service.image.catalog.model.ImageCatalogPlatform) Image(com.sequenceiq.cloudbreak.cloud.model.catalog.Image) StatedImages(com.sequenceiq.cloudbreak.service.image.StatedImages) Test(org.junit.jupiter.api.Test)

Example 7 with ImageCatalogPlatform

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));
}
Also used : ImageCatalogPlatform(com.sequenceiq.cloudbreak.service.image.catalog.model.ImageCatalogPlatform) Image(com.sequenceiq.cloudbreak.cloud.model.catalog.Image) StatedImages(com.sequenceiq.cloudbreak.service.image.StatedImages) Test(org.junit.jupiter.api.Test)

Example 8 with ImageCatalogPlatform

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());
}
Also used : ImageCatalogPlatform(com.sequenceiq.cloudbreak.service.image.catalog.model.ImageCatalogPlatform) StatedImage(com.sequenceiq.cloudbreak.service.image.StatedImage) Image(com.sequenceiq.cloudbreak.cloud.model.catalog.Image) ImageCatalog(com.sequenceiq.cloudbreak.domain.ImageCatalog) StatedImage(com.sequenceiq.cloudbreak.service.image.StatedImage) Test(org.junit.jupiter.api.Test)

Example 9 with ImageCatalogPlatform

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());
}
Also used : ImageCatalogPlatform(com.sequenceiq.cloudbreak.service.image.catalog.model.ImageCatalogPlatform) Test(org.junit.Test)

Example 10 with ImageCatalogPlatform

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.");
    }
}
Also used : EntitlementService(com.sequenceiq.cloudbreak.auth.altus.EntitlementService) UserProfileService(com.sequenceiq.cloudbreak.service.user.UserProfileService) LoggerFactory(org.slf4j.LoggerFactory) TransactionRuntimeExecutionException(com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionRuntimeExecutionException) StringUtils(org.apache.commons.lang3.StringUtils) CloudbreakRestRequestThreadLocalService(com.sequenceiq.cloudbreak.structuredevent.CloudbreakRestRequestThreadLocalService) ThreadBasedUserCrnProvider(com.sequenceiq.cloudbreak.auth.ThreadBasedUserCrnProvider) TransactionService(com.sequenceiq.cloudbreak.common.service.TransactionService) Map(java.util.Map) AuthorizationResourceType(com.sequenceiq.authorization.resource.AuthorizationResourceType) Images(com.sequenceiq.cloudbreak.cloud.model.catalog.Images) CloudbreakImageCatalogException(com.sequenceiq.cloudbreak.core.CloudbreakImageCatalogException) NotFoundException(com.sequenceiq.cloudbreak.common.exception.NotFoundException) EnumSet(java.util.EnumSet) ResourceWithId(com.sequenceiq.authorization.service.list.ResourceWithId) ImmutableSet(com.google.common.collect.ImmutableSet) ImageCatalogRepository(com.sequenceiq.cloudbreak.repository.ImageCatalogRepository) WorkspaceResourceRepository(com.sequenceiq.cloudbreak.workspace.repository.workspace.WorkspaceResourceRepository) Collections.emptyList(java.util.Collections.emptyList) Predicate(java.util.function.Predicate) Collection(java.util.Collection) Set(java.util.Set) ImageCatalogPlatform(com.sequenceiq.cloudbreak.service.image.catalog.model.ImageCatalogPlatform) Crn(com.sequenceiq.cloudbreak.auth.crn.Crn) Collectors(java.util.stream.Collectors) ImageCatalog(com.sequenceiq.cloudbreak.domain.ImageCatalog) Sets(com.google.common.collect.Sets) Objects(java.util.Objects) List(java.util.List) MDCUtils(com.sequenceiq.cloudbreak.logger.MDCUtils) CollectionUtils(org.springframework.util.CollectionUtils) TransactionExecutionException(com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionExecutionException) UserProfile(com.sequenceiq.cloudbreak.domain.UserProfile) PreferencesService(com.sequenceiq.cloudbreak.service.account.PreferencesService) Optional(java.util.Optional) UserProfileHandler(com.sequenceiq.cloudbreak.service.user.UserProfileHandler) Collectors.partitioningBy(java.util.stream.Collectors.partitioningBy) OwnerAssignmentService(com.sequenceiq.authorization.service.OwnerAssignmentService) HashMap(java.util.HashMap) BooleanUtils(org.apache.commons.lang3.BooleanUtils) CompositeAuthResourcePropertyProvider(com.sequenceiq.authorization.service.CompositeAuthResourcePropertyProvider) ImageCatalogPlatform.imageCatalogPlatform(com.sequenceiq.cloudbreak.service.image.catalog.model.ImageCatalogPlatform.imageCatalogPlatform) StringUtils.isNotEmpty(org.apache.commons.lang3.StringUtils.isNotEmpty) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Inject(javax.inject.Inject) Value(org.springframework.beans.factory.annotation.Value) Strings(com.google.common.base.Strings) CrnResourceDescriptor(com.sequenceiq.cloudbreak.auth.crn.CrnResourceDescriptor) StatedImage.statedImage(com.sequenceiq.cloudbreak.service.image.StatedImage.statedImage) ImageType(com.sequenceiq.common.api.type.ImageType) CloudbreakImageCatalogV3(com.sequenceiq.cloudbreak.cloud.model.catalog.CloudbreakImageCatalogV3) Nonnull(javax.annotation.Nonnull) NotFoundException.notFound(com.sequenceiq.cloudbreak.common.exception.NotFoundException.notFound) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) Logger(org.slf4j.Logger) Collections.emptySet(java.util.Collections.emptySet) StatedImages.statedImages(com.sequenceiq.cloudbreak.service.image.StatedImages.statedImages) RegionAwareCrnGenerator(com.sequenceiq.cloudbreak.auth.crn.RegionAwareCrnGenerator) Image(com.sequenceiq.cloudbreak.cloud.model.catalog.Image) Workspace(com.sequenceiq.cloudbreak.workspace.model.Workspace) NameOrCrn(com.sequenceiq.cloudbreak.api.endpoint.v4.dto.NameOrCrn) CloudbreakImageNotFoundException(com.sequenceiq.cloudbreak.core.CloudbreakImageNotFoundException) ImageCatalogServiceProxy(com.sequenceiq.cloudbreak.service.image.catalog.ImageCatalogServiceProxy) Collectors.toList(java.util.stream.Collectors.toList) Component(org.springframework.stereotype.Component) User(com.sequenceiq.cloudbreak.workspace.model.User) CustomImage(com.sequenceiq.cloudbreak.domain.CustomImage) NameUtil.generateArchiveName(com.sequenceiq.cloudbreak.util.NameUtil.generateArchiveName) Comparator(java.util.Comparator) AbstractWorkspaceAwareResourceService(com.sequenceiq.cloudbreak.service.AbstractWorkspaceAwareResourceService) User(com.sequenceiq.cloudbreak.workspace.model.User) ImageCatalogPlatform(com.sequenceiq.cloudbreak.service.image.catalog.model.ImageCatalogPlatform) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException)

Aggregations

ImageCatalogPlatform (com.sequenceiq.cloudbreak.service.image.catalog.model.ImageCatalogPlatform)19 Image (com.sequenceiq.cloudbreak.cloud.model.catalog.Image)10 CloudbreakImageCatalogException (com.sequenceiq.cloudbreak.core.CloudbreakImageCatalogException)6 ImageCatalog (com.sequenceiq.cloudbreak.domain.ImageCatalog)6 CloudbreakImageNotFoundException (com.sequenceiq.cloudbreak.core.CloudbreakImageNotFoundException)5 Test (org.junit.jupiter.api.Test)5 BadRequestException (com.sequenceiq.cloudbreak.common.exception.BadRequestException)4 Optional (java.util.Optional)4 Inject (javax.inject.Inject)4 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)4 ClouderaManagerRepo (com.sequenceiq.cloudbreak.cloud.model.ClouderaManagerRepo)3 Images (com.sequenceiq.cloudbreak.cloud.model.catalog.Images)3 NotFoundException (com.sequenceiq.cloudbreak.common.exception.NotFoundException)3 StatedImage (com.sequenceiq.cloudbreak.service.image.StatedImage)3 StatedImages (com.sequenceiq.cloudbreak.service.image.StatedImages)3 ClouderaManagerStackDescriptorV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.util.responses.ClouderaManagerStackDescriptorV4Response)2 StackMatrixV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.util.responses.StackMatrixV4Response)2 Measure (com.sequenceiq.cloudbreak.aspect.Measure)2 Image (com.sequenceiq.cloudbreak.cloud.model.Image)2 StackType (com.sequenceiq.cloudbreak.cloud.model.component.StackType)2