Search in sources :

Example 11 with ImageCatalogPlatform

use of com.sequenceiq.cloudbreak.service.image.catalog.model.ImageCatalogPlatform in project cloudbreak by hortonworks.

the class ImageService method create.

@Measure(ImageService.class)
public Set<Component> create(Stack stack, StatedImage imgFromCatalog) throws CloudbreakImageNotFoundException, CloudbreakImageCatalogException {
    String region = stack.getRegion();
    String cloudPlatform = stack.getCloudPlatform();
    ImageCatalogPlatform platformString = platformStringTransformer.getPlatformStringForImageCatalog(cloudPlatform, stack.getPlatformVariant());
    LOGGER.debug("Determined image from catalog: {}", imgFromCatalog);
    String imageName = determineImageName(cloudPlatform, platformString, region, imgFromCatalog.getImage());
    LOGGER.debug("Selected VM image for CloudPlatform '{}' and region '{}' is: {} from: {} image catalog", platformString, region, imageName, imgFromCatalog.getImageCatalogUrl());
    Set<Component> components = getComponents(stack, Map.of(), imgFromCatalog, EnumSet.of(IMAGE, CDH_PRODUCT_DETAILS, CM_REPO_DETAILS));
    componentConfigProviderService.store(components);
    return components;
}
Also used : ImageCatalogPlatform(com.sequenceiq.cloudbreak.service.image.catalog.model.ImageCatalogPlatform) Component(com.sequenceiq.cloudbreak.domain.stack.Component) Measure(com.sequenceiq.cloudbreak.aspect.Measure)

Example 12 with ImageCatalogPlatform

use of com.sequenceiq.cloudbreak.service.image.catalog.model.ImageCatalogPlatform in project cloudbreak by hortonworks.

the class ImageService method determineImageFromCatalog.

// CHECKSTYLE:OFF
@Measure(ImageService.class)
public StatedImage determineImageFromCatalog(Long workspaceId, ImageSettingsV4Request imageSettings, String platformString, String variant, Blueprint blueprint, boolean useBaseImage, boolean baseImageEnabled, User user, Predicate<com.sequenceiq.cloudbreak.cloud.model.catalog.Image> imagePredicate) throws CloudbreakImageNotFoundException, CloudbreakImageCatalogException {
    ImageCatalogPlatform platform = platformStringTransformer.getPlatformStringForImageCatalog(platformString, variant);
    if (imageSettings != null && StringUtils.isNotEmpty(imageSettings.getId())) {
        LOGGER.debug("Image id {} is specified for the stack.", imageSettings.getId());
        if (imageSettings.getCatalog() == null) {
            imageSettings.setCatalog(CDP_DEFAULT_CATALOG_NAME);
        }
        StatedImage image = imageCatalogService.getImageByCatalogName(workspaceId, imageSettings.getId(), imageSettings.getCatalog());
        return checkIfBasePermitted(image, baseImageEnabled);
    } else if (useBaseImage && !baseImageEnabled) {
        throw new CloudbreakImageCatalogException("Inconsistent request, base images are disabled but custom repo information is submitted!");
    }
    String clusterVersion = getClusterVersion(blueprint);
    Set<String> operatingSystems;
    try {
        operatingSystems = getSupportedOperatingSystems(workspaceId, imageSettings, clusterVersion, platform);
    } catch (Exception ex) {
        throw new CloudbreakImageCatalogException(ex);
    }
    ImageCatalog imageCatalog = getImageCatalogFromRequestOrDefault(workspaceId, imageSettings, user);
    ImageFilter imageFilter = new ImageFilter(imageCatalog, Set.of(platform), null, baseImageEnabled, operatingSystems, clusterVersion);
    LOGGER.info("Image id is not specified for the stack.");
    if (baseImageEnabled && useBaseImage) {
        LOGGER.info("Trying to select a base image.");
        return imageCatalogService.getLatestBaseImageDefaultPreferred(imageFilter, imagePredicate);
    }
    LOGGER.info("Trying to select a prewarmed image.");
    return imageCatalogService.getImagePrewarmedDefaultPreferred(imageFilter, imagePredicate);
}
Also used : ImageCatalogPlatform(com.sequenceiq.cloudbreak.service.image.catalog.model.ImageCatalogPlatform) ImageCatalog(com.sequenceiq.cloudbreak.domain.ImageCatalog) CloudbreakImageCatalogException(com.sequenceiq.cloudbreak.core.CloudbreakImageCatalogException) NotFoundException(com.sequenceiq.cloudbreak.common.exception.NotFoundException) IOException(java.io.IOException) CloudbreakImageNotFoundException(com.sequenceiq.cloudbreak.core.CloudbreakImageNotFoundException) CloudbreakImageCatalogException(com.sequenceiq.cloudbreak.core.CloudbreakImageCatalogException) Measure(com.sequenceiq.cloudbreak.aspect.Measure)

Example 13 with ImageCatalogPlatform

use of com.sequenceiq.cloudbreak.service.image.catalog.model.ImageCatalogPlatform in project cloudbreak by hortonworks.

the class DefaultImageCatalogService method getImageFromDefaultCatalog.

public StatedImage getImageFromDefaultCatalog(String type, ImageCatalogPlatform provider, String runtime) throws CloudbreakImageCatalogException, CloudbreakImageNotFoundException {
    ImageType imageType = ImageType.valueOf(type);
    StatedImage statedImage;
    switch(imageType) {
        case FREEIPA:
            throw new BadRequestException(String.format("Runtime is not supported in case of '%s' image type", imageType));
        case RUNTIME:
            ImageCatalog imageCatalog = getCloudbreakDefaultImageCatalog();
            ImageFilter imageFilter = new ImageFilter(imageCatalog, Set.of(provider), null, false, null, runtime);
            statedImage = imageCatalogService.getImagePrewarmedDefaultPreferred(imageFilter, i -> true);
            break;
        default:
            throw new BadRequestException(String.format("Image type '%s' is not supported.", type));
    }
    return statedImage;
}
Also used : BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) ImageCatalogPlatform(com.sequenceiq.cloudbreak.service.image.catalog.model.ImageCatalogPlatform) Set(java.util.Set) Image(com.sequenceiq.cloudbreak.cloud.model.catalog.Image) ImageCatalog(com.sequenceiq.cloudbreak.domain.ImageCatalog) CloudbreakImageNotFoundException(com.sequenceiq.cloudbreak.core.CloudbreakImageNotFoundException) Value(org.springframework.beans.factory.annotation.Value) Inject(javax.inject.Inject) Objects(java.util.Objects) ImageType(com.sequenceiq.common.api.type.ImageType) Component(org.springframework.stereotype.Component) List(java.util.List) StatedImage.statedImage(com.sequenceiq.cloudbreak.service.image.StatedImage.statedImage) Optional(java.util.Optional) CloudbreakImageCatalogException(com.sequenceiq.cloudbreak.core.CloudbreakImageCatalogException) Comparator(java.util.Comparator) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) ImageCatalog(com.sequenceiq.cloudbreak.domain.ImageCatalog) ImageType(com.sequenceiq.common.api.type.ImageType)

Example 14 with ImageCatalogPlatform

use of com.sequenceiq.cloudbreak.service.image.catalog.model.ImageCatalogPlatform in project cloudbreak by hortonworks.

the class UpgradeOptionsResponseFactory method getImageName.

private String getImageName(Image image, String cloudPlatform, String region) {
    String imageName;
    try {
        ImageCatalogPlatform platformString = platformStringTransformer.getPlatformStringForImageCatalogByRegion(cloudPlatform, region);
        imageName = imageService.determineImageName(cloudPlatform, platformString, region, image);
    } catch (CloudbreakImageNotFoundException e) {
        throw new NotFoundException(String.format("Image (%s) name not found", image.getUuid()), e);
    }
    return imageName;
}
Also used : ImageCatalogPlatform(com.sequenceiq.cloudbreak.service.image.catalog.model.ImageCatalogPlatform) CloudbreakImageNotFoundException(com.sequenceiq.cloudbreak.core.CloudbreakImageNotFoundException) CloudbreakImageNotFoundException(com.sequenceiq.cloudbreak.core.CloudbreakImageNotFoundException) NotFoundException(com.sequenceiq.cloudbreak.common.exception.NotFoundException)

Example 15 with ImageCatalogPlatform

use of com.sequenceiq.cloudbreak.service.image.catalog.model.ImageCatalogPlatform in project cloudbreak by hortonworks.

the class CmSyncImageCollectorServiceTest method testCollectImagesWhenNoImageUuidAndImageCatalogExceptionThenReturnsEmpty.

@Test
void testCollectImagesWhenNoImageUuidAndImageCatalogExceptionThenReturnsEmpty() throws CloudbreakImageNotFoundException, CloudbreakImageCatalogException {
    ImageCatalogPlatform imageCatalogPlatform = imageCatalogPlatform(CURRENT_CLOUD_PLATFORM);
    setupStack(true, true);
    Set<String> candidateImageUuids = Set.of();
    when(imageCatalogService.getAllCdhImages(USER_CRN, WORKSPCE_ID, CURRENT_IMAGE_CATALOG_NAME, Set.of(imageCatalogPlatform(CURRENT_CLOUD_PLATFORM)))).thenThrow(new CloudbreakImageCatalogException("My custom image catalog exception"));
    when(imageService.getCurrentImageCatalogName(STACK_ID)).thenReturn(CURRENT_IMAGE_CATALOG_NAME);
    when(platformStringTransformer.getPlatformStringForImageCatalogSet(anyObject(), anyString())).thenReturn(Set.of(imageCatalogPlatform));
    Set<Image> collectedImages = underTest.collectImages(USER_CRN, stack, candidateImageUuids);
    assertThat(collectedImages, emptyCollectionOf(Image.class));
    verify(imageService).getCurrentImageCatalogName(STACK_ID);
    verify(imageCatalogService).getAllCdhImages(USER_CRN, WORKSPCE_ID, CURRENT_IMAGE_CATALOG_NAME, Set.of(imageCatalogPlatform));
    verify(imageService, never()).getCurrentImage(anyLong());
    verify(imageCatalogService, never()).getImageByCatalogName(anyLong(), anyString(), anyString());
}
Also used : ImageCatalogPlatform(com.sequenceiq.cloudbreak.service.image.catalog.model.ImageCatalogPlatform) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) StatedImage(com.sequenceiq.cloudbreak.service.image.StatedImage) Image(com.sequenceiq.cloudbreak.cloud.model.catalog.Image) CloudbreakImageCatalogException(com.sequenceiq.cloudbreak.core.CloudbreakImageCatalogException) Test(org.junit.jupiter.api.Test)

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