Search in sources :

Example 1 with ImageCatalogWrapper

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

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

the class ImageCatalogProviderTest method shouldReturnImageCatalogWithoutForceRefresh.

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

Example 3 with ImageCatalogWrapper

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

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

the class ImageCatalogProviderTest method shouldReturnImageCatalogWithForceRefresh.

@Test
public void shouldReturnImageCatalogWithForceRefresh() throws CloudbreakImageCatalogException {
    ImageCatalogWrapper imageCatalogWrapper = mock(ImageCatalogWrapper.class);
    CloudbreakImageCatalogV3 imageCatalogV3 = mock(CloudbreakImageCatalogV3.class);
    when(cachedImageCatalogWrapperProvider.getImageCatalogWrapper(IMAGE_CATALOG_URL)).thenReturn(imageCatalogWrapper);
    when(imageCatalogWrapper.getImageCatalog()).thenReturn(imageCatalogV3);
    CloudbreakImageCatalogV3 actual = victim.getImageCatalogV3(IMAGE_CATALOG_URL, true);
    assertEquals(imageCatalogV3, actual);
    verify(cachedImageCatalogWrapperProvider).evictImageCatalogCache(IMAGE_CATALOG_URL);
}
Also used : ImageCatalogWrapper(com.sequenceiq.cloudbreak.service.image.catalog.model.ImageCatalogWrapper) CloudbreakImageCatalogV3(com.sequenceiq.cloudbreak.cloud.model.catalog.CloudbreakImageCatalogV3) Test(org.junit.jupiter.api.Test)

Aggregations

ImageCatalogWrapper (com.sequenceiq.cloudbreak.service.image.catalog.model.ImageCatalogWrapper)4 CloudbreakImageCatalogV3 (com.sequenceiq.cloudbreak.cloud.model.catalog.CloudbreakImageCatalogV3)3 Test (org.junit.jupiter.api.Test)3 ImageCatalogMetaData (com.sequenceiq.cloudbreak.service.image.catalog.model.ImageCatalogMetaData)2 JsonMappingException (com.fasterxml.jackson.databind.JsonMappingException)1 CloudbreakImageCatalogException (com.sequenceiq.cloudbreak.core.CloudbreakImageCatalogException)1 IOException (java.io.IOException)1 Client (javax.ws.rs.client.Client)1 WebTarget (javax.ws.rs.client.WebTarget)1 Response (javax.ws.rs.core.Response)1 Cacheable (org.springframework.cache.annotation.Cacheable)1