Search in sources :

Example 26 with CloudbreakImageCatalogV3

use of com.sequenceiq.cloudbreak.cloud.model.catalog.CloudbreakImageCatalogV3 in project cloudbreak by hortonworks.

the class SdxControllerTest method generateImageCatalogTest.

@Test
void generateImageCatalogTest() {
    CloudbreakImageCatalogV3 imageCatalog = mock(CloudbreakImageCatalogV3.class);
    when(sdxImageCatalogService.generateImageCatalog(SDX_CLUSTER_NAME)).thenReturn(imageCatalog);
    SdxGenerateImageCatalogResponse actual = sdxController.generateImageCatalog(SDX_CLUSTER_NAME);
    assertEquals(imageCatalog, actual.getImageCatalog());
}
Also used : CloudbreakImageCatalogV3(com.sequenceiq.cloudbreak.cloud.model.catalog.CloudbreakImageCatalogV3) SdxGenerateImageCatalogResponse(com.sequenceiq.sdx.api.model.SdxGenerateImageCatalogResponse) Test(org.junit.jupiter.api.Test)

Example 27 with CloudbreakImageCatalogV3

use of com.sequenceiq.cloudbreak.cloud.model.catalog.CloudbreakImageCatalogV3 in project cloudbreak by hortonworks.

the class CachedImageCatalogWrapperProvider method filterImagesByOsType.

private CloudbreakImageCatalogV3 filterImagesByOsType(CloudbreakImageCatalogV3 catalog) {
    LOGGER.debug("Filtering images by OS type {}", getEnabledLinuxTypes());
    if (CollectionUtils.isEmpty(getEnabledLinuxTypes())) {
        return catalog;
    }
    Images catalogImages = catalog.getImages();
    List<Image> filteredBaseImages = filterImages(catalogImages.getBaseImages(), enabledOsPredicate());
    List<Image> filteredCdhImages = filterImages(catalogImages.getCdhImages(), enabledOsPredicate());
    List<Image> filteredFreeipaImages = filterImages(catalogImages.getFreeIpaImages(), enabledOsPredicate());
    Images images = new Images(filteredBaseImages, filteredCdhImages, filteredFreeipaImages, catalogImages.getSuppertedVersions());
    return new CloudbreakImageCatalogV3(images, catalog.getVersions());
}
Also used : Images(com.sequenceiq.cloudbreak.cloud.model.catalog.Images) CloudbreakImageCatalogV3(com.sequenceiq.cloudbreak.cloud.model.catalog.CloudbreakImageCatalogV3) Image(com.sequenceiq.cloudbreak.cloud.model.catalog.Image)

Example 28 with CloudbreakImageCatalogV3

use of com.sequenceiq.cloudbreak.cloud.model.catalog.CloudbreakImageCatalogV3 in project cloudbreak by hortonworks.

the class CachedImageCatalogWrapperProvider method getImageCatalogWrapper.

@Cacheable(cacheNames = "imageCatalogCache", key = "#catalogUrl")
public ImageCatalogWrapper getImageCatalogWrapper(String catalogUrl) throws CloudbreakImageCatalogException {
    try {
        if (Objects.nonNull(catalogUrl)) {
            long started = System.currentTimeMillis();
            String content;
            if (catalogUrl.startsWith("http")) {
                Client client = restClientFactory.getOrCreateDefault();
                WebTarget target = client.target(catalogUrl);
                Response response = target.request().get();
                content = readResponse(target, response);
            } else {
                content = readCatalogFromFile(catalogUrl);
            }
            CloudbreakImageCatalogV3 catalog = objectMapper.readValue(content, CloudbreakImageCatalogV3.class);
            if (Objects.nonNull(catalog)) {
                imageCatalogServiceProxy.validate(catalog);
                cleanAndValidateMaps(catalog);
                catalog = filterImagesByOsType(catalog);
                ImageCatalogMetaData metaData = imageCatalogServiceProxy.getImageCatalogMetaData(catalog);
                long timeOfParse = System.currentTimeMillis() - started;
                LOGGER.debug("ImageCatalog has been get and parsed from '{}' and took '{}' ms.", catalogUrl, timeOfParse);
                return new ImageCatalogWrapper(catalog, metaData);
            }
            throw new CloudbreakImageCatalogException(String.format("Failed to read the content of '%s' as an image catalog.", catalogUrl));
        }
        throw new CloudbreakImageCatalogException("Unable to fetch image catalog. The catalogUrl is null.");
    } catch (CloudbreakImageCatalogException e) {
        throw e;
    } catch (RuntimeException e) {
        throw new CloudbreakImageCatalogException(String.format("Failed to get image catalog: %s from %s", e.getMessage(), catalogUrl), e);
    } catch (JsonMappingException e) {
        throw new CloudbreakImageCatalogException(e.getMessage(), e);
    } catch (IOException e) {
        throw new CloudbreakImageCatalogException(String.format("Failed to read image catalog from file: '%s'", catalogUrl), e);
    }
}
Also used : Response(javax.ws.rs.core.Response) JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException) ImageCatalogWrapper(com.sequenceiq.cloudbreak.service.image.catalog.model.ImageCatalogWrapper) CloudbreakImageCatalogV3(com.sequenceiq.cloudbreak.cloud.model.catalog.CloudbreakImageCatalogV3) ImageCatalogMetaData(com.sequenceiq.cloudbreak.service.image.catalog.model.ImageCatalogMetaData) WebTarget(javax.ws.rs.client.WebTarget) IOException(java.io.IOException) Client(javax.ws.rs.client.Client) CloudbreakImageCatalogException(com.sequenceiq.cloudbreak.core.CloudbreakImageCatalogException) Cacheable(org.springframework.cache.annotation.Cacheable)

Example 29 with CloudbreakImageCatalogV3

use of com.sequenceiq.cloudbreak.cloud.model.catalog.CloudbreakImageCatalogV3 in project cloudbreak by hortonworks.

the class ImageCatalogService method getImageCatalogMetaData.

default ImageCatalogMetaData getImageCatalogMetaData(CloudbreakImageCatalogV3 imageCatalogV3) {
    ImageFilterResult imageFilterResult = getImageFilterResult(imageCatalogV3);
    List<String> runtimes = imageFilterResult.getImages().stream().map(Image::getVersion).distinct().map(version -> (Versioned) () -> version).sorted(VERSION_COMPARATOR.reversed()).map(Versioned::getVersion).collect(toList());
    return new ImageCatalogMetaData(runtimes);
}
Also used : Collectors.toList(java.util.stream.Collectors.toList) List(java.util.List) ImageCatalogMetaData(com.sequenceiq.cloudbreak.service.image.catalog.model.ImageCatalogMetaData) Versioned(com.sequenceiq.cloudbreak.common.type.Versioned) CloudbreakImageCatalogException(com.sequenceiq.cloudbreak.core.CloudbreakImageCatalogException) ImageFilterResult(com.sequenceiq.cloudbreak.service.upgrade.image.ImageFilterResult) CloudbreakImageCatalogV3(com.sequenceiq.cloudbreak.cloud.model.catalog.CloudbreakImageCatalogV3) VersionComparator(com.sequenceiq.cloudbreak.util.VersionComparator) StatedImages(com.sequenceiq.cloudbreak.service.image.StatedImages) Image(com.sequenceiq.cloudbreak.cloud.model.catalog.Image) ImageFilter(com.sequenceiq.cloudbreak.service.image.ImageFilter) Versioned(com.sequenceiq.cloudbreak.common.type.Versioned) ImageCatalogMetaData(com.sequenceiq.cloudbreak.service.image.catalog.model.ImageCatalogMetaData) ImageFilterResult(com.sequenceiq.cloudbreak.service.upgrade.image.ImageFilterResult)

Example 30 with CloudbreakImageCatalogV3

use of com.sequenceiq.cloudbreak.cloud.model.catalog.CloudbreakImageCatalogV3 in project cloudbreak by hortonworks.

the class SdxImageCatalogServiceTest method shouldCallGenererateImageCatalog.

@Test
void shouldCallGenererateImageCatalog() {
    CloudbreakImageCatalogV3 imageCatalogV3 = mock(CloudbreakImageCatalogV3.class);
    GenerateImageCatalogV4Response response = new GenerateImageCatalogV4Response(imageCatalogV3);
    when(stackV4Endpoint.generateImageCatalogInternal(WORKSPACE_ID_DEFAULT, CLUSTER_NAME, USER_CRN)).thenReturn(response);
    when(regionAwareInternalCrnGenerator.getInternalCrnForServiceAsString()).thenReturn("crn");
    when(regionAwareInternalCrnGeneratorFactory.iam()).thenReturn(regionAwareInternalCrnGenerator);
    when(regionAwareInternalCrnGenerator.getInternalCrnForServiceAsString()).thenReturn("crn");
    when(regionAwareInternalCrnGeneratorFactory.iam()).thenReturn(regionAwareInternalCrnGenerator);
    CloudbreakImageCatalogV3 actual = ThreadBasedUserCrnProvider.doAs(USER_CRN, () -> underTest.generateImageCatalog(CLUSTER_NAME));
    assertEquals(imageCatalogV3, actual);
}
Also used : GenerateImageCatalogV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.imagecatalog.GenerateImageCatalogV4Response) CloudbreakImageCatalogV3(com.sequenceiq.cloudbreak.cloud.model.catalog.CloudbreakImageCatalogV3) Test(org.junit.jupiter.api.Test)

Aggregations

CloudbreakImageCatalogV3 (com.sequenceiq.cloudbreak.cloud.model.catalog.CloudbreakImageCatalogV3)48 Test (org.junit.jupiter.api.Test)21 Image (com.sequenceiq.cloudbreak.cloud.model.catalog.Image)17 Test (org.junit.Test)14 ImageFilterResult (com.sequenceiq.cloudbreak.service.upgrade.image.ImageFilterResult)10 UpgradeV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.upgrade.UpgradeV4Response)8 ImageFilterParams (com.sequenceiq.cloudbreak.service.upgrade.image.ImageFilterParams)8 ImageCatalog (com.sequenceiq.cloudbreak.domain.ImageCatalog)7 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)7 Images (com.sequenceiq.cloudbreak.cloud.model.catalog.Images)6 CloudbreakVersion (com.sequenceiq.cloudbreak.cloud.model.catalog.CloudbreakVersion)5 CloudbreakImageCatalogException (com.sequenceiq.cloudbreak.core.CloudbreakImageCatalogException)5 StatedImages (com.sequenceiq.cloudbreak.service.image.StatedImages)5 Image (com.sequenceiq.cloudbreak.cloud.model.Image)4 CloudbreakImageNotFoundException (com.sequenceiq.cloudbreak.core.CloudbreakImageNotFoundException)4 List (java.util.List)4 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 Versions (com.sequenceiq.cloudbreak.cloud.model.catalog.Versions)3 ImageFilter (com.sequenceiq.cloudbreak.service.image.ImageFilter)3 ImageCatalogWrapper (com.sequenceiq.cloudbreak.service.image.catalog.model.ImageCatalogWrapper)3