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);
}
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);
}
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);
}
}
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);
}
Aggregations