class StackComponentUpdater {

    public Set<Component> updateComponentsByStackId(Stack stack, StatedImage targetImage, Map<InstanceGroupType, String> userData)
            throws CloudbreakImageNotFoundException, CloudbreakImageCatalogException {
        String imageName = imageService.determineImageName(stack.cloudPlatform(), stack.getRegion(), targetImage.getImage());
        Set<Component> componentsFromDb = componentConfigProviderService.getComponentsByStackId(stack.getId());
        Set<Component> targetComponents = imageService.getComponents(stack, userData, targetImage, imageName);
        componentsFromDb.forEach(component -> setComponentIdIfAlreadyExists(targetComponents, component));
        componentConfigProviderService.store(targetComponents);

        LOGGER.info("Updated components:" + targetComponents);
        return targetComponents;
    }

}