Search in sources :

Example 1 with ImageType

use of com.sequenceiq.common.api.type.ImageType 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 2 with ImageType

use of com.sequenceiq.common.api.type.ImageType in project cloudbreak by hortonworks.

the class DefaultImageCatalogService method getImageFromDefaultCatalog.

public StatedImage getImageFromDefaultCatalog(String type, String provider) throws CloudbreakImageCatalogException, CloudbreakImageNotFoundException {
    ImageType imageType = ImageType.valueOf(type);
    StatedImage statedImage;
    switch(imageType) {
        case FREEIPA:
            List<Image> images = imageCatalogProvider.getImageCatalogV3(defaultFreeIpaCatalogUrl).getImages().getFreeIpaImages();
            Optional<Image> image = images.stream().filter(i -> i.getImageSetsByProvider().keySet().stream().anyMatch(key -> key.equalsIgnoreCase(provider))).max(getImageComparing(images));
            statedImage = statedImage(image.orElseThrow(() -> new CloudbreakImageNotFoundException(String.format("Could not find any image with provider: '%s' in catalog: '%s'", provider, FREEIPA_DEFAULT_CATALOG_NAME))), defaultFreeIpaCatalogUrl, FREEIPA_DEFAULT_CATALOG_NAME);
            break;
        case RUNTIME:
            throw new BadRequestException(String.format("Runtime is required in case of '%s' image type", imageType));
        default:
            throw new BadRequestException(String.format("Type '%s' is not supported.", type));
    }
    return statedImage;
}
Also used : BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) 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) CloudbreakImageNotFoundException(com.sequenceiq.cloudbreak.core.CloudbreakImageNotFoundException) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) Image(com.sequenceiq.cloudbreak.cloud.model.catalog.Image) StatedImage.statedImage(com.sequenceiq.cloudbreak.service.image.StatedImage.statedImage) ImageType(com.sequenceiq.common.api.type.ImageType)

Aggregations

Image (com.sequenceiq.cloudbreak.cloud.model.catalog.Image)2 BadRequestException (com.sequenceiq.cloudbreak.common.exception.BadRequestException)2 CloudbreakImageCatalogException (com.sequenceiq.cloudbreak.core.CloudbreakImageCatalogException)2 CloudbreakImageNotFoundException (com.sequenceiq.cloudbreak.core.CloudbreakImageNotFoundException)2 ImageCatalog (com.sequenceiq.cloudbreak.domain.ImageCatalog)2 StatedImage.statedImage (com.sequenceiq.cloudbreak.service.image.StatedImage.statedImage)2 ImageType (com.sequenceiq.common.api.type.ImageType)2 Comparator (java.util.Comparator)2 List (java.util.List)2 Objects (java.util.Objects)2 Optional (java.util.Optional)2 Set (java.util.Set)2 Inject (javax.inject.Inject)2 Value (org.springframework.beans.factory.annotation.Value)2 Component (org.springframework.stereotype.Component)2 ImageCatalogPlatform (com.sequenceiq.cloudbreak.service.image.catalog.model.ImageCatalogPlatform)1