@Test public void testReadImageCatalogFromFile() { String path = getPath(IMAGE_CATALOG_JSON); ReflectionTestUtils.setField(underTest, "etcConfigDir", path); ReflectionTestUtils.setField(underTest, "enabledLinuxTypes", Collections.emptyList()); ImageCatalog catalog = underTest.getImageCatalog(IMAGE_CATALOG_JSON); List<com.sequenceiq.freeipa.api.model.image.Image> images = catalog.getImages().getFreeipaImages(); assertEquals(4, images.size()); assertEquals("61851893-8340-411d-afb7-e1b55107fb10", images.get(0).getUuid()); FreeIpaVersions freeIpaVersions = catalog.getVersions().getFreeIpaVersions().get(0); assertEquals(2, freeIpaVersions.getImageIds().size()); assertEquals("61851893-8340-411d-afb7-e1b55107fb10", freeIpaVersions.getImageIds().get(0)); assertEquals(1, freeIpaVersions.getDefaults().size()); assertEquals(List.of("71851893-8340-411d-afb7-e1b55107fb10"), freeIpaVersions.getDefaults()); assertEquals(4, freeIpaVersions.getVersions().size()); }
@Cacheable(cacheNames = "imageCatalogCache", key = "#catalogUrl") public ImageCatalog getImageCatalog(String catalogUrl) { ImageCatalog catalog; if (catalogUrl == null) { LOGGER.info("No image catalog was defined!"); return null; } try { long started = System.currentTimeMillis(); String content; if (catalogUrl.startsWith("http")) { Client client = RestClientUtil.get(); WebTarget target = client.target(catalogUrl); Response response = target.request().get(); content = readResponse(target, response); } else { content = readCatalogFromFile(catalogUrl); } catalog = filterImagesByOsType(objectMapper.readValue(content, ImageCatalog.class)); long timeOfParse = System.currentTimeMillis() - started; LOGGER.debug("ImageCatalog was fetched and parsed from '{}' and took '{}' ms.", catalogUrl, timeOfParse); } catch (RuntimeException e) { throw new ImageCatalogException(String.format("Failed to get image catalog: %s from %s", e.getCause(), catalogUrl), e); } catch (JsonMappingException e) { throw new ImageCatalogException(String.format("Invalid json format for image catalog with error: %s", e.getMessage()), e); } catch (IOException e) { throw new ImageCatalogException(String.format("Failed to read image catalog from file: '%s'", catalogUrl), e); } return catalog; }
ImageCatalogProvider { @Cacheable(cacheNames = "imageCatalogCache", key = "#catalogUrl") public ImageCatalog getImageCatalog(String catalogUrl) { ImageCatalog catalog; if (catalogUrl == null) { LOGGER.info("No image catalog was defined!"); return null; } try { long started = System.currentTimeMillis(); String content; if (catalogUrl.startsWith("http")) { Client client = RestClientUtil.get(); WebTarget target = client.target(catalogUrl); Response response = target.request().get(); content = readResponse(target, response); } else { content = readCatalogFromFile(catalogUrl); } catalog = filterImagesByOsType(objectMapper.readValue(content, ImageCatalog.class)); long timeOfParse = System.currentTimeMillis() - started; LOGGER.debug("ImageCatalog was fetched and parsed from '{}' and took '{}' ms.", catalogUrl, timeOfParse); } catch (RuntimeException e) { throw new ImageCatalogException(String.format("Failed to get image catalog: %s from %s", e.getCause(), catalogUrl), e); } catch (JsonMappingException e) { throw new ImageCatalogException(String.format("Invalid json format for image catalog with error: %s", e.getMessage()), e); } catch (IOException e) { throw new ImageCatalogException(String.format("Failed to read image catalog from file: '%s'", catalogUrl), e); } return catalog; } }
ImageCatalogProvider { @Cacheable(cacheNames = "imageCatalogCache", key = "#catalogUrl") public ImageCatalog getImageCatalog(String catalogUrl) { ImageCatalog catalog; if (catalogUrl == null) { LOGGER.info("No image catalog was defined!"); return null; } try { long started = System.currentTimeMillis(); String content; if (catalogUrl.startsWith("http")) { Client client = RestClientUtil.get(); WebTarget target = client.target(catalogUrl); Response response = target.request().get(); content = readResponse(target, response); } else { content = readCatalogFromFile(catalogUrl); } catalog = filterImagesByOsType(objectMapper.readValue(content, ImageCatalog.class)); long timeOfParse = System.currentTimeMillis() - started; LOGGER.debug("ImageCatalog was fetched and parsed from '{}' and took '{}' ms.", catalogUrl, timeOfParse); } catch (RuntimeException e) { throw new ImageCatalogException(String.format("Failed to get image catalog: %s from %s", e.getCause(), catalogUrl), e); } catch (JsonMappingException e) { throw new ImageCatalogException(String.format("Invalid json format for image catalog with error: %s", e.getMessage()), e); } catch (IOException e) { throw new ImageCatalogException(String.format("Failed to read image catalog from file: '%s'", catalogUrl), e); } return catalog; }  }
ImageCatalogProvider { @Cacheable(cacheNames = "imageCatalogCache", key = "#catalogUrl") public ImageCatalog getImageCatalog(String catalogUrl) { ImageCatalog catalog; if (catalogUrl == null) { LOGGER.info("No image catalog was defined!"); return null; } try { long started = System.currentTimeMillis(); String content; if (catalogUrl.startsWith("http")) { Client client = RestClientUtil.get(); WebTarget target = client.target(catalogUrl); Response response = target.request().get(); content = readResponse(target, response); } else { content = readCatalogFromFile(catalogUrl); } catalog = filterImagesByOsType(objectMapper.readValue(content, ImageCatalog.class)); long timeOfParse = System.currentTimeMillis() - started; LOGGER.debug("ImageCatalog was fetched and parsed from '{}' and took '{}' ms.", catalogUrl, timeOfParse); } catch (RuntimeException e) { throw new ImageCatalogException(String.format("Failed to get image catalog: %s from %s", e.getCause(), catalogUrl), e); } catch (JsonMappingException e) { throw new ImageCatalogException(String.format("Invalid json format for image catalog with error: %s", e.getMessage()), e); } catch (IOException e) { throw new ImageCatalogException(String.format("Failed to read image catalog from file: '%s'", catalogUrl), e); } return catalog; }  @Cacheable(cacheNames = "imageCatalogCache", key = "#catalogUrl") ImageCatalog getImageCatalog(String catalogUrl); @CacheEvict(value = "imageCatalogCache", key = "#catalogUrl") void evictImageCatalogCache(String catalogUrl); }
ImageCatalogProvider { @Cacheable(cacheNames = "imageCatalogCache", key = "#catalogUrl") public ImageCatalog getImageCatalog(String catalogUrl) { ImageCatalog catalog; if (catalogUrl == null) { LOGGER.info("No image catalog was defined!"); return null; } try { long started = System.currentTimeMillis(); String content; if (catalogUrl.startsWith("http")) { Client client = RestClientUtil.get(); WebTarget target = client.target(catalogUrl); Response response = target.request().get(); content = readResponse(target, response); } else { content = readCatalogFromFile(catalogUrl); } catalog = filterImagesByOsType(objectMapper.readValue(content, ImageCatalog.class)); long timeOfParse = System.currentTimeMillis() - started; LOGGER.debug("ImageCatalog was fetched and parsed from '{}' and took '{}' ms.", catalogUrl, timeOfParse); } catch (RuntimeException e) { throw new ImageCatalogException(String.format("Failed to get image catalog: %s from %s", e.getCause(), catalogUrl), e); } catch (JsonMappingException e) { throw new ImageCatalogException(String.format("Invalid json format for image catalog with error: %s", e.getMessage()), e); } catch (IOException e) { throw new ImageCatalogException(String.format("Failed to read image catalog from file: '%s'", catalogUrl), e); } return catalog; }  @Cacheable(cacheNames = "imageCatalogCache", key = "#catalogUrl") ImageCatalog getImageCatalog(String catalogUrl); @CacheEvict(value = "imageCatalogCache", key = "#catalogUrl") void evictImageCatalogCache(String catalogUrl);  }