Search in sources :

Example 1 with FreeIpaVersions

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

the class ImageCatalogProviderTest method testReadImageCatalogFromFileWithoutVersionsButWithAdvertisedFlag.

@Test
public void testReadImageCatalogFromFileWithoutVersionsButWithAdvertisedFlag() {
    String path = getPath(IMAGE_CATALOG_WITHOUT_VERSIONS);
    ReflectionTestUtils.setField(underTest, "etcConfigDir", path);
    ReflectionTestUtils.setField(underTest, "enabledLinuxTypes", CB_CENTOS_7_FILTER);
    ImageCatalog catalog = underTest.getImageCatalog(IMAGE_CATALOG_WITHOUT_VERSIONS);
    List<com.sequenceiq.freeipa.api.v1.freeipa.stack.model.image.Image> images = catalog.getImages().getFreeipaImages();
    assertEquals(2, images.size());
    FreeIpaVersions freeIpaVersions = catalog.getVersions().getFreeIpaVersions().get(0);
    assertEquals(1, freeIpaVersions.getImageIds().size());
    assertEquals("91851893-8340-411d-afb7-e1b55107fb10", freeIpaVersions.getImageIds().get(0));
}
Also used : FreeIpaVersions(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.image.FreeIpaVersions) Image(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.image.Image) ImageCatalog(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.image.ImageCatalog) Test(org.junit.Test)

Example 2 with FreeIpaVersions

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

the class ImageCatalogProviderTest method testReadImageCatalogFromFile.

@Test
public void testReadImageCatalogFromFile() {
    String path = getPath(IMAGE_CATALOG_JSON);
    ReflectionTestUtils.setField(underTest, "etcConfigDir", path);
    ReflectionTestUtils.setField(underTest, "enabledLinuxTypes", Collections.emptyList());
    ImageCatalog catalog = underTest.getImageCatalog(IMAGE_CATALOG_JSON);
    List<com.sequenceiq.freeipa.api.v1.freeipa.stack.model.image.Image> images = catalog.getImages().getFreeipaImages();
    assertEquals(4, images.size());
    assertEquals("61851893-8340-411d-afb7-e1b55107fb10", images.get(0).getUuid());
    FreeIpaVersions freeIpaVersions = catalog.getVersions().getFreeIpaVersions().get(0);
    assertEquals(2, freeIpaVersions.getImageIds().size());
    assertEquals("61851893-8340-411d-afb7-e1b55107fb10", freeIpaVersions.getImageIds().get(0));
    assertEquals(1, freeIpaVersions.getDefaults().size());
    assertEquals(List.of("71851893-8340-411d-afb7-e1b55107fb10"), freeIpaVersions.getDefaults());
    assertEquals(4, freeIpaVersions.getVersions().size());
}
Also used : FreeIpaVersions(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.image.FreeIpaVersions) Image(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.image.Image) ImageCatalog(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.image.ImageCatalog) Test(org.junit.Test)

Example 3 with FreeIpaVersions

use of com.sequenceiq.freeipa.api.v1.freeipa.stack.model.image.FreeIpaVersions 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 4 with FreeIpaVersions

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

the class ImageCatalogProvider method getVersions.

private Versions getVersions(ImageCatalog catalog) {
    if (catalog.getVersions() == null || catalog.getVersions().getFreeIpaVersions() == null) {
        LOGGER.debug("FreeIPA versions are missing from the image catalog, generating it based on the current svc version and on advertised flags.");
        List<String> advertisedImageUuids = catalog.getImages().getFreeipaImages().stream().filter(Image::isAdvertised).map(Image::getUuid).collect(Collectors.toList());
        List<FreeIpaVersions> versionList = List.of(new FreeIpaVersions(List.of(freeIpaVersion), List.of(), advertisedImageUuids));
        Versions versions = new Versions(versionList);
        LOGGER.debug("Generated versions: '{}'", versions);
        return versions;
    } else {
        return catalog.getVersions();
    }
}
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) Image(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.image.Image)

Example 5 with FreeIpaVersions

use of com.sequenceiq.freeipa.api.v1.freeipa.stack.model.image.FreeIpaVersions 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

FreeIpaVersions (com.sequenceiq.freeipa.api.v1.freeipa.stack.model.image.FreeIpaVersions)5 Image (com.sequenceiq.freeipa.api.v1.freeipa.stack.model.image.Image)5 ImageCatalog (com.sequenceiq.freeipa.api.v1.freeipa.stack.model.image.ImageCatalog)4 Versions (com.sequenceiq.freeipa.api.v1.freeipa.stack.model.image.Versions)2 Test (org.junit.Test)2 ImageSettingsRequest (com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.image.ImageSettingsRequest)1 Images (com.sequenceiq.freeipa.api.v1.freeipa.stack.model.image.Images)1 ImageWrapper (com.sequenceiq.freeipa.dto.ImageWrapper)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 Comparator (java.util.Comparator)1 List (java.util.List)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Set (java.util.Set)1 Function (java.util.function.Function)1 Predicate (java.util.function.Predicate)1 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1 Collectors (java.util.stream.Collectors)1