@Test public void testImageCatalogFilterNothing() { String path = getPath(IMAGE_CATALOG_JSON); ReflectionTestUtils.setField(underTest, "etcConfigDir", path); ReflectionTestUtils.setField(underTest, "enabledLinuxTypes", Collections.emptyList()); ImageCatalog actualCatalog = underTest.getImageCatalog(IMAGE_CATALOG_JSON); List<String> actualOsTypes = getImageCatalogOses(actualCatalog); assertEquals(IMAGE_CATALOG_OS_TYPES, actualOsTypes); List<String> expectedIds = List.of("61851893-8340-411d-afb7-e1b55107fb10", "71851893-8340-411d-afb7-e1b55107fb10", "81851893-8340-411d-afb7-e1b55107fb10", "91851893-8340-411d-afb7-e1b55107fb10"); assertEquals(expectedIds, mapToUuid(actualCatalog.getImages().getFreeipaImages())); assertEquals(List.of("61851893-8340-411d-afb7-e1b55107fb10", "71851893-8340-411d-afb7-e1b55107fb10"), actualCatalog.getVersions().getFreeIpaVersions().get(0).getImageIds()); }
@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);  }