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