Search in sources :

Example 11 with Images

use of com.sequenceiq.freeipa.api.v1.freeipa.stack.model.image.Images in project cloudbreak by hortonworks.

the class FreeIpaImageProviderTest method testGetImagesGivenUuidInputFound.

@Test
public void testGetImagesGivenUuidInputFound() {
    ImageSettingsRequest is = setupImageSettingsRequest(IMAGE_UUID, null, null);
    List<ImageWrapper> images = underTest.getImages(is, DEFAULT_REGION, DEFAULT_PLATFORM);
    assertEquals(1, images.size());
    ImageWrapper imageWrapper = images.get(0);
    assertEquals(DEFAULT_CATALOG_URL, imageWrapper.getCatalogUrl());
    assertNull(imageWrapper.getCatalogName());
    Image image = imageWrapper.getImage();
    assertEquals(DEFAULT_OS, image.getOs());
    assertEquals(LATEST_DATE, image.getDate());
    assertEquals(IMAGE_UUID, image.getUuid());
}
Also used : ImageSettingsRequest(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.image.ImageSettingsRequest) ImageWrapper(com.sequenceiq.freeipa.dto.ImageWrapper) Image(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.image.Image) Test(org.junit.jupiter.api.Test)

Example 12 with Images

use of com.sequenceiq.freeipa.api.v1.freeipa.stack.model.image.Images in project cloudbreak by hortonworks.

the class FreeIpaImageProviderTest method testGetImagesGivenAllInput.

@Test
public void testGetImagesGivenAllInput() {
    ImageSettingsRequest is = setupImageSettingsRequest(EXISTING_ID, CUSTOM_IMAGE_CATALOG_URL, DEFAULT_OS);
    List<ImageWrapper> images = underTest.getImages(is, DEFAULT_REGION, DEFAULT_PLATFORM);
    assertEquals(1, images.size());
    ImageWrapper imageWrapper = images.get(0);
    assertEquals(CUSTOM_IMAGE_CATALOG_URL, imageWrapper.getCatalogUrl());
    assertNull(imageWrapper.getCatalogName());
    Image image = imageWrapper.getImage();
    assertEquals(DEFAULT_OS, image.getOs());
    assertEquals(LATEST_DATE, image.getDate());
    assertEquals(IMAGE_UUID, image.getUuid());
}
Also used : ImageSettingsRequest(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.image.ImageSettingsRequest) ImageWrapper(com.sequenceiq.freeipa.dto.ImageWrapper) Image(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.image.Image) Test(org.junit.jupiter.api.Test)

Example 13 with Images

use of com.sequenceiq.freeipa.api.v1.freeipa.stack.model.image.Images in project cloudbreak by hortonworks.

the class CoreImageProvider method getImages.

@Override
public List<ImageWrapper> getImages(ImageSettingsRequest imageSettings, String region, String platform) {
    try {
        ImagesV4Response imagesV4Response = imageCatalogV4Endpoint.getImagesByName(WORKSPACE_ID_DEFAULT, imageSettings.getCatalog(), null, platform, null, null, false);
        LOGGER.debug("Images received: {}", imagesV4Response);
        return Optional.ofNullable(imagesV4Response.getFreeipaImages()).orElseGet(List::of).stream().map(this::convert).flatMap(Optional::stream).map(img -> new ImageWrapper(img, null, imageSettings.getCatalog())).collect(Collectors.toList());
    } catch (WebApplicationException e) {
        String errorMessage = messageExtractor.getErrorMessage(e);
        LOGGER.warn("Fetching images failed with: {}", errorMessage, e);
        return List.of();
    } catch (Exception e) {
        LOGGER.warn("Fetching images failed", e);
        return List.of();
    }
}
Also used : ImageSettingsRequest(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.image.ImageSettingsRequest) Logger(org.slf4j.Logger) ImageCatalogV4Endpoint(com.sequenceiq.cloudbreak.api.endpoint.v4.imagecatalog.ImageCatalogV4Endpoint) LoggerFactory(org.slf4j.LoggerFactory) WebApplicationExceptionMessageExtractor(com.sequenceiq.cloudbreak.common.exception.WebApplicationExceptionMessageExtractor) ImageV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.imagecatalog.responses.ImageV4Response) Collectors(java.util.stream.Collectors) Inject(javax.inject.Inject) Value(org.springframework.beans.factory.annotation.Value) List(java.util.List) Service(org.springframework.stereotype.Service) Optional(java.util.Optional) WebApplicationException(javax.ws.rs.WebApplicationException) ImageWrapper(com.sequenceiq.freeipa.dto.ImageWrapper) Image(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.image.Image) ImagesV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.imagecatalog.responses.ImagesV4Response) Optional(java.util.Optional) WebApplicationException(javax.ws.rs.WebApplicationException) ImageWrapper(com.sequenceiq.freeipa.dto.ImageWrapper) ImagesV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.imagecatalog.responses.ImagesV4Response) WebApplicationException(javax.ws.rs.WebApplicationException)

Example 14 with Images

use of com.sequenceiq.freeipa.api.v1.freeipa.stack.model.image.Images in project cloudbreak by hortonworks.

the class FreeIpaImageProvider method getImages.

public List<ImageWrapper> getImages(ImageSettingsRequest imageSettings, String region, String platform) {
    String imageId = imageSettings.getId();
    String catalogUrl = StringUtils.isNotBlank(imageSettings.getCatalog()) ? imageSettings.getCatalog() : defaultCatalogUrl;
    String imageOs = StringUtils.isNotBlank(imageSettings.getOs()) ? imageSettings.getOs() : defaultOs;
    ImageCatalog cachedImageCatalog = imageCatalogProvider.getImageCatalog(catalogUrl);
    List<Image> compatibleImages = findImage(imageId, imageOs, cachedImageCatalog.getImages().getFreeipaImages(), region, platform);
    List<String> imagesInVersions = filterFreeIpaVersionsByAppVersion(cachedImageCatalog.getVersions().getFreeIpaVersions()).stream().map(FreeIpaVersions::getImageIds).flatMap(Collection::stream).distinct().collect(Collectors.toList());
    LOGGER.debug("Compatible images: {} " + System.lineSeparator() + "Images in versions: {}", compatibleImages, imagesInVersions);
    return compatibleImages.stream().filter(image -> imagesInVersions.contains(image.getUuid())).map(image -> new ImageWrapper(image, catalogUrl, null)).collect(Collectors.toList());
}
Also used : ImageSettingsRequest(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.image.ImageSettingsRequest) Logger(org.slf4j.Logger) Predicate(java.util.function.Predicate) Collection(java.util.Collection) FreeIpaVersions(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.image.FreeIpaVersions) LoggerFactory(org.slf4j.LoggerFactory) Set(java.util.Set) Function(java.util.function.Function) Collectors(java.util.stream.Collectors) StringUtils(org.apache.commons.lang3.StringUtils) CollectionUtils(org.apache.commons.collections4.CollectionUtils) ImageCatalog(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.image.ImageCatalog) Inject(javax.inject.Inject) Value(org.springframework.beans.factory.annotation.Value) List(java.util.List) Matcher(java.util.regex.Matcher) Service(org.springframework.stereotype.Service) Map(java.util.Map) Optional(java.util.Optional) Pattern(java.util.regex.Pattern) ImageWrapper(com.sequenceiq.freeipa.dto.ImageWrapper) Comparator(java.util.Comparator) Image(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.image.Image) Collections(java.util.Collections) ImageWrapper(com.sequenceiq.freeipa.dto.ImageWrapper) Collection(java.util.Collection) Image(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.image.Image) ImageCatalog(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.image.ImageCatalog)

Example 15 with Images

use of com.sequenceiq.freeipa.api.v1.freeipa.stack.model.image.Images in project cloudbreak by hortonworks.

the class ImageCatalogProvider method filterImagesByOsType.

private ImageCatalog filterImagesByOsType(ImageCatalog catalog) {
    LOGGER.debug("Filtering images by OS type {}", getEnabledLinuxTypes());
    if ((CollectionUtils.isEmpty(getEnabledLinuxTypes()) || Objects.isNull(catalog.getImages())) && Objects.nonNull(catalog.getVersions())) {
        return catalog;
    }
    List<Image> catalogImages = catalog.getImages().getFreeipaImages();
    List<Image> filterImages = filterImages(catalogImages, enabledOsPredicate());
    List<FreeIpaVersions> filteredVersions = filterVersions(catalog, filterImages);
    return new ImageCatalog(new Images(filterImages), new Versions(filteredVersions));
}
Also used : FreeIpaVersions(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.image.FreeIpaVersions) FreeIpaVersions(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.image.FreeIpaVersions) Versions(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.image.Versions) Images(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.image.Images) Image(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.image.Image) ImageCatalog(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.image.ImageCatalog)

Aggregations

ImageSettingsRequest (com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.image.ImageSettingsRequest)11 Image (com.sequenceiq.freeipa.api.v1.freeipa.stack.model.image.Image)10 ImageWrapper (com.sequenceiq.freeipa.dto.ImageWrapper)10 Test (org.junit.jupiter.api.Test)8 ImageCatalog (com.sequenceiq.freeipa.api.v1.freeipa.stack.model.image.ImageCatalog)5 FreeIpaVersions (com.sequenceiq.freeipa.api.v1.freeipa.stack.model.image.FreeIpaVersions)4 Images (com.sequenceiq.freeipa.api.v1.freeipa.stack.model.image.Images)2 List (java.util.List)2 Optional (java.util.Optional)2 Collectors (java.util.stream.Collectors)2 Inject (javax.inject.Inject)2 Test (org.junit.Test)2 Logger (org.slf4j.Logger)2 LoggerFactory (org.slf4j.LoggerFactory)2 Value (org.springframework.beans.factory.annotation.Value)2 Service (org.springframework.stereotype.Service)2 ImageCatalogV4Endpoint (com.sequenceiq.cloudbreak.api.endpoint.v4.imagecatalog.ImageCatalogV4Endpoint)1 ImageV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.imagecatalog.responses.ImageV4Response)1 ImagesV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.imagecatalog.responses.ImagesV4Response)1 WebApplicationExceptionMessageExtractor (com.sequenceiq.cloudbreak.common.exception.WebApplicationExceptionMessageExtractor)1