Search in sources :

Example 1 with ImageCatalogMetaData

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

the class ImageCatalogProviderTest method shouldReturnImageCatalogMetaData.

@Test
public void shouldReturnImageCatalogMetaData() throws CloudbreakImageCatalogException {
    ImageCatalogWrapper imageCatalogWrapper = mock(ImageCatalogWrapper.class);
    ImageCatalogMetaData imageCatalogMetaData = mock(ImageCatalogMetaData.class);
    when(cachedImageCatalogWrapperProvider.getImageCatalogWrapper(IMAGE_CATALOG_URL)).thenReturn(imageCatalogWrapper);
    when(imageCatalogWrapper.getImageCatalogMetaData()).thenReturn(imageCatalogMetaData);
    ImageCatalogMetaData actual = victim.getImageCatalogMetaData(IMAGE_CATALOG_URL);
    assertEquals(imageCatalogMetaData, actual);
    verifyNoMoreInteractions(cachedImageCatalogWrapperProvider);
}
Also used : ImageCatalogWrapper(com.sequenceiq.cloudbreak.service.image.catalog.model.ImageCatalogWrapper) ImageCatalogMetaData(com.sequenceiq.cloudbreak.service.image.catalog.model.ImageCatalogMetaData) Test(org.junit.jupiter.api.Test)

Example 2 with ImageCatalogMetaData

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

the class ImageCatalogServiceTest method testGetRuntimeVersionsFromDefault.

@Test
public void testGetRuntimeVersionsFromDefault() throws CloudbreakImageCatalogException {
    List<String> expected = List.of("7.2.1");
    ImageCatalogMetaData imageCatalogMetaData = mock(ImageCatalogMetaData.class);
    when(imageCatalogProvider.getImageCatalogMetaData(DEFAULT_CATALOG_URL)).thenReturn(imageCatalogMetaData);
    when(imageCatalogMetaData.getRuntimeVersions()).thenReturn(expected);
    List<String> actual = underTest.getRuntimeVersionsFromDefault();
    assertEquals(expected, actual);
}
Also used : ImageCatalogMetaData(com.sequenceiq.cloudbreak.service.image.catalog.model.ImageCatalogMetaData) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Example 3 with ImageCatalogMetaData

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

the class ImageCatalogServiceTest method testGetImageMetaDataContainsDistinctListOfVersionsInReversedOrder.

@Test
public void testGetImageMetaDataContainsDistinctListOfVersionsInReversedOrder() {
    ImageCatalogMetaData imageCatalogMetaData = victim.getImageCatalogMetaData(imageCatalogV3);
    assertEquals(List.of(RUNTIME_7210, RUNTIME_722, RUNTIME_721), imageCatalogMetaData.getRuntimeVersions());
}
Also used : ImageCatalogMetaData(com.sequenceiq.cloudbreak.service.image.catalog.model.ImageCatalogMetaData) Test(org.junit.jupiter.api.Test)

Example 4 with ImageCatalogMetaData

use of com.sequenceiq.cloudbreak.service.image.catalog.model.ImageCatalogMetaData 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 5 with ImageCatalogMetaData

use of com.sequenceiq.cloudbreak.service.image.catalog.model.ImageCatalogMetaData 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)

Aggregations

ImageCatalogMetaData (com.sequenceiq.cloudbreak.service.image.catalog.model.ImageCatalogMetaData)5 CloudbreakImageCatalogV3 (com.sequenceiq.cloudbreak.cloud.model.catalog.CloudbreakImageCatalogV3)2 CloudbreakImageCatalogException (com.sequenceiq.cloudbreak.core.CloudbreakImageCatalogException)2 ImageCatalogWrapper (com.sequenceiq.cloudbreak.service.image.catalog.model.ImageCatalogWrapper)2 Test (org.junit.jupiter.api.Test)2 JsonMappingException (com.fasterxml.jackson.databind.JsonMappingException)1 Image (com.sequenceiq.cloudbreak.cloud.model.catalog.Image)1 Versioned (com.sequenceiq.cloudbreak.common.type.Versioned)1 ImageFilter (com.sequenceiq.cloudbreak.service.image.ImageFilter)1 StatedImages (com.sequenceiq.cloudbreak.service.image.StatedImages)1 ImageFilterResult (com.sequenceiq.cloudbreak.service.upgrade.image.ImageFilterResult)1 VersionComparator (com.sequenceiq.cloudbreak.util.VersionComparator)1 IOException (java.io.IOException)1 List (java.util.List)1 Collectors.toList (java.util.stream.Collectors.toList)1 Client (javax.ws.rs.client.Client)1 WebTarget (javax.ws.rs.client.WebTarget)1 Response (javax.ws.rs.core.Response)1 Test (org.junit.Test)1 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)1