@Test public void testDetermineImageFromCatalogWithNonExistingCatalogName() { when(imageCatalogService.get(WORKSPACE_ID, "aCatalog")).thenThrow(new NotFoundException("Image catalog not found with name: aCatalog")); ImageSettingsV4Request imageRequest = new ImageSettingsV4Request(); imageRequest.setCatalog("aCatalog"); imageRequest.setOs(OS); CloudbreakImageCatalogException exception = assertThrows(CloudbreakImageCatalogException.class, () -> underTest.determineImageFromCatalog( WORKSPACE_ID, imageRequest, PLATFORM, TestUtil.blueprint(), true, true, TestUtil.user(USER_ID, USER_ID_STRING), image -> true)); assertEquals("Image catalog not found with name: aCatalog", exception.getMessage()); }
@Measure(ImageService.class) public StatedImage determineImageFromCatalog(Long workspaceId, ImageSettingsV4Request imageSettings, String platformString, Blueprint blueprint, boolean useBaseImage, boolean baseImageEnabled, User user, Predicate<com.sequenceiq.cloudbreak.cloud.model.catalog.Image> imagePredicate) throws CloudbreakImageNotFoundException, CloudbreakImageCatalogException { if (useBaseImage && !baseImageEnabled) { throw new CloudbreakImageCatalogException("Inconsistent request, base images are disabled but custom repo information is submitted!"); } if (imageSettings != null && StringUtils.isNotEmpty(imageSettings.getId())) { LOGGER.debug("Image id is specified for the stack."); StatedImage image = imageCatalogService.getImageByCatalogName(workspaceId, imageSettings.getId(), imageSettings.getCatalog()); return checkIfBasePermitted(image, baseImageEnabled); } String clusterVersion = getClusterVersion(blueprint); Set<String> operatingSystems; try { operatingSystems = getSupportedOperatingSystems(workspaceId, imageSettings, clusterVersion, platformString); } catch (Exception ex) { throw new CloudbreakImageCatalogException(ex); } ImageCatalog imageCatalog = getImageCatalogFromRequestOrDefault(workspaceId, imageSettings, user); ImageFilter imageFilter = new ImageFilter(imageCatalog, ImmutableSet.of(platformString), null, baseImageEnabled, operatingSystems, clusterVersion); LOGGER.info("Image id is not specified for the stack."); if (baseImageEnabled && useBaseImage) { LOGGER.info("Trying to select a base image."); return imageCatalogService.getLatestBaseImageDefaultPreferred(imageFilter, imagePredicate); } LOGGER.info("Trying to select a prewarmed image."); return imageCatalogService.getImagePrewarmedDefaultPreferred(imageFilter, imagePredicate); }
ImageService { @Measure(ImageService.class) public StatedImage determineImageFromCatalog(Long workspaceId, ImageSettingsV4Request imageSettings, String platformString, Blueprint blueprint, boolean useBaseImage, boolean baseImageEnabled, User user, Predicate<com.sequenceiq.cloudbreak.cloud.model.catalog.Image> imagePredicate) throws CloudbreakImageNotFoundException, CloudbreakImageCatalogException { if (useBaseImage && !baseImageEnabled) { throw new CloudbreakImageCatalogException("Inconsistent request, base images are disabled but custom repo information is submitted!"); } if (imageSettings != null && StringUtils.isNotEmpty(imageSettings.getId())) { LOGGER.debug("Image id is specified for the stack."); StatedImage image = imageCatalogService.getImageByCatalogName(workspaceId, imageSettings.getId(), imageSettings.getCatalog()); return checkIfBasePermitted(image, baseImageEnabled); } String clusterVersion = getClusterVersion(blueprint); Set<String> operatingSystems; try { operatingSystems = getSupportedOperatingSystems(workspaceId, imageSettings, clusterVersion, platformString); } catch (Exception ex) { throw new CloudbreakImageCatalogException(ex); } ImageCatalog imageCatalog = getImageCatalogFromRequestOrDefault(workspaceId, imageSettings, user); ImageFilter imageFilter = new ImageFilter(imageCatalog, ImmutableSet.of(platformString), null, baseImageEnabled, operatingSystems, clusterVersion); LOGGER.info("Image id is not specified for the stack."); if (baseImageEnabled && useBaseImage) { LOGGER.info("Trying to select a base image."); return imageCatalogService.getLatestBaseImageDefaultPreferred(imageFilter, imagePredicate); } LOGGER.info("Trying to select a prewarmed image."); return imageCatalogService.getImagePrewarmedDefaultPreferred(imageFilter, imagePredicate); } }
ImageService { @Measure(ImageService.class) public StatedImage determineImageFromCatalog(Long workspaceId, ImageSettingsV4Request imageSettings, String platformString, Blueprint blueprint, boolean useBaseImage, boolean baseImageEnabled, User user, Predicate<com.sequenceiq.cloudbreak.cloud.model.catalog.Image> imagePredicate) throws CloudbreakImageNotFoundException, CloudbreakImageCatalogException { if (useBaseImage && !baseImageEnabled) { throw new CloudbreakImageCatalogException("Inconsistent request, base images are disabled but custom repo information is submitted!"); } if (imageSettings != null && StringUtils.isNotEmpty(imageSettings.getId())) { LOGGER.debug("Image id is specified for the stack."); StatedImage image = imageCatalogService.getImageByCatalogName(workspaceId, imageSettings.getId(), imageSettings.getCatalog()); return checkIfBasePermitted(image, baseImageEnabled); } String clusterVersion = getClusterVersion(blueprint); Set<String> operatingSystems; try { operatingSystems = getSupportedOperatingSystems(workspaceId, imageSettings, clusterVersion, platformString); } catch (Exception ex) { throw new CloudbreakImageCatalogException(ex); } ImageCatalog imageCatalog = getImageCatalogFromRequestOrDefault(workspaceId, imageSettings, user); ImageFilter imageFilter = new ImageFilter(imageCatalog, ImmutableSet.of(platformString), null, baseImageEnabled, operatingSystems, clusterVersion); LOGGER.info("Image id is not specified for the stack."); if (baseImageEnabled && useBaseImage) { LOGGER.info("Trying to select a base image."); return imageCatalogService.getLatestBaseImageDefaultPreferred(imageFilter, imagePredicate); } LOGGER.info("Trying to select a prewarmed image."); return imageCatalogService.getImagePrewarmedDefaultPreferred(imageFilter, imagePredicate); }  }
ImageService { @Measure(ImageService.class) public StatedImage determineImageFromCatalog(Long workspaceId, ImageSettingsV4Request imageSettings, String platformString, Blueprint blueprint, boolean useBaseImage, boolean baseImageEnabled, User user, Predicate<com.sequenceiq.cloudbreak.cloud.model.catalog.Image> imagePredicate) throws CloudbreakImageNotFoundException, CloudbreakImageCatalogException { if (useBaseImage && !baseImageEnabled) { throw new CloudbreakImageCatalogException("Inconsistent request, base images are disabled but custom repo information is submitted!"); } if (imageSettings != null && StringUtils.isNotEmpty(imageSettings.getId())) { LOGGER.debug("Image id is specified for the stack."); StatedImage image = imageCatalogService.getImageByCatalogName(workspaceId, imageSettings.getId(), imageSettings.getCatalog()); return checkIfBasePermitted(image, baseImageEnabled); } String clusterVersion = getClusterVersion(blueprint); Set<String> operatingSystems; try { operatingSystems = getSupportedOperatingSystems(workspaceId, imageSettings, clusterVersion, platformString); } catch (Exception ex) { throw new CloudbreakImageCatalogException(ex); } ImageCatalog imageCatalog = getImageCatalogFromRequestOrDefault(workspaceId, imageSettings, user); ImageFilter imageFilter = new ImageFilter(imageCatalog, ImmutableSet.of(platformString), null, baseImageEnabled, operatingSystems, clusterVersion); LOGGER.info("Image id is not specified for the stack."); if (baseImageEnabled && useBaseImage) { LOGGER.info("Trying to select a base image."); return imageCatalogService.getLatestBaseImageDefaultPreferred(imageFilter, imagePredicate); } LOGGER.info("Trying to select a prewarmed image."); return imageCatalogService.getImagePrewarmedDefaultPreferred(imageFilter, imagePredicate); }  Image getImage(Long stackId); @Measure(ImageService.class) void create(Stack stack, String platformString, StatedImage imgFromCatalog); @Measure(ImageService.class) StatedImage determineImageFromCatalog(Long workspaceId, ImageSettingsV4Request imageSettings, String platformString,
            Blueprint blueprint, boolean useBaseImage, boolean baseImageEnabled,
            User user, Predicate<com.sequenceiq.cloudbreak.cloud.model.catalog.Image> imagePredicate); String determineImageName(String platformString, String region, com.sequenceiq.cloudbreak.cloud.model.catalog.Image imgFromCatalog); Set<Component> getComponents(Stack stack, Map<InstanceGroupType, String> userData, StatedImage statedImage, String imageName); StackType determineStackType(StackDetails stackDetails); void decorateImageWithUserDataForStack(Stack stack, Map<InstanceGroupType, String> userData); }
ImageService { @Measure(ImageService.class) public StatedImage determineImageFromCatalog(Long workspaceId, ImageSettingsV4Request imageSettings, String platformString, Blueprint blueprint, boolean useBaseImage, boolean baseImageEnabled, User user, Predicate<com.sequenceiq.cloudbreak.cloud.model.catalog.Image> imagePredicate) throws CloudbreakImageNotFoundException, CloudbreakImageCatalogException { if (useBaseImage && !baseImageEnabled) { throw new CloudbreakImageCatalogException("Inconsistent request, base images are disabled but custom repo information is submitted!"); } if (imageSettings != null && StringUtils.isNotEmpty(imageSettings.getId())) { LOGGER.debug("Image id is specified for the stack."); StatedImage image = imageCatalogService.getImageByCatalogName(workspaceId, imageSettings.getId(), imageSettings.getCatalog()); return checkIfBasePermitted(image, baseImageEnabled); } String clusterVersion = getClusterVersion(blueprint); Set<String> operatingSystems; try { operatingSystems = getSupportedOperatingSystems(workspaceId, imageSettings, clusterVersion, platformString); } catch (Exception ex) { throw new CloudbreakImageCatalogException(ex); } ImageCatalog imageCatalog = getImageCatalogFromRequestOrDefault(workspaceId, imageSettings, user); ImageFilter imageFilter = new ImageFilter(imageCatalog, ImmutableSet.of(platformString), null, baseImageEnabled, operatingSystems, clusterVersion); LOGGER.info("Image id is not specified for the stack."); if (baseImageEnabled && useBaseImage) { LOGGER.info("Trying to select a base image."); return imageCatalogService.getLatestBaseImageDefaultPreferred(imageFilter, imagePredicate); } LOGGER.info("Trying to select a prewarmed image."); return imageCatalogService.getImagePrewarmedDefaultPreferred(imageFilter, imagePredicate); }  Image getImage(Long stackId); @Measure(ImageService.class) void create(Stack stack, String platformString, StatedImage imgFromCatalog); @Measure(ImageService.class) StatedImage determineImageFromCatalog(Long workspaceId, ImageSettingsV4Request imageSettings, String platformString,
            Blueprint blueprint, boolean useBaseImage, boolean baseImageEnabled,
            User user, Predicate<com.sequenceiq.cloudbreak.cloud.model.catalog.Image> imagePredicate); String determineImageName(String platformString, String region, com.sequenceiq.cloudbreak.cloud.model.catalog.Image imgFromCatalog); Set<Component> getComponents(Stack stack, Map<InstanceGroupType, String> userData, StatedImage statedImage, String imageName); StackType determineStackType(StackDetails stackDetails); void decorateImageWithUserDataForStack(Stack stack, Map<InstanceGroupType, String> userData);  }