@Test public void testUpdateImageComponents() throws CloudbreakImageCatalogException, CloudbreakImageNotFoundException { Stack stack = TestUtil.stack(); Cluster cluster = TestUtil.cluster(); stack.setCluster(cluster); StatedImage targetImage = ImageTestUtil.getImageFromCatalog(true, "targetImageUuid", TARGET_STACK_VERSION); Image originalImage = ImageTestUtil.getImage(true, "originalImageUuid", STACK_VERSION); Component originalImageComponent = new Component(ComponentType.IMAGE, ComponentType.IMAGE.name(), new Json(originalImage), stack); when(componentConfigProviderService.getComponentsByStackId(stack.getId())).thenReturn(Set.of(originalImageComponent)); when(imageService.determineImageName(anyString(), anyString(), any(Image.class))).thenReturn("imageName"); when(imageService.getComponents(eq(stack), anyMap(), any(StatedImage.class), anyString())).thenReturn(createComponents(stack, targetImage)); underTest.updateComponentsByStackId(stack, targetImage, Map.of(InstanceGroupType.GATEWAY, "gw user data")); ArgumentCaptor<Set<Component>> componentCatcher = ArgumentCaptor.forClass(Set.class); verify(componentConfigProviderService, times(1)).store(componentCatcher.capture()); assertEquals(3, componentCatcher.getValue().size()); assertTrue(componentCatcher.getValue().stream().anyMatch( component -> { Object version = component.getAttributes().getValue("version"); if (Objects.nonNull(version)) { return ((String) version).contains(TARGET_STACK_VERSION); } else { return false; } })); assertTrue(componentCatcher.getValue().stream().anyMatch( component -> { Object userData = component.getAttributes().getValue("userdata"); if (Objects.nonNull(userData)) { return ((Map<String, String>) userData).get(InstanceGroupType.GATEWAY.name()).contains("gw user data"); } else { return false; } })); }
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; }
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; } }
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; }  }
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; }  Set<Component> updateComponentsByStackId(Stack stack, StatedImage targetImage, Map<InstanceGroupType, String> userData); }
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; }  Set<Component> updateComponentsByStackId(Stack stack, StatedImage targetImage, Map<InstanceGroupType, String> userData);  }