@Test public void testGetNewImageIfVersionsMatch() throws CloudbreakImageNotFoundException, CloudbreakImageCatalogException { com.sequenceiq.cloudbreak.cloud.model.Image imageInComponent = new com.sequenceiq.cloudbreak.cloud.model.Image("imageOldName", Collections.emptyMap(), "centos7", "centos", statedImage.getImageCatalogUrl(), statedImage.getImageCatalogName(), "uuid2", packageVersions); when(componentConfigProviderService.getImage(anyLong())).thenReturn(imageInComponent); when(imageCatalogService.getImage(anyString(), anyString(), anyString())).thenReturn(statedImage); StatedImage newImageIfVersionsMatch = underTest.getNewImageIfVersionsMatch(stack, "newimageid", "imagecatalogname", "imagecatalogurl"); assertNotNull(newImageIfVersionsMatch); }
public StatedImage getNewImageIfVersionsMatch(Stack stack, String newImageId, String imageCatalogName, String imageCatalogUrl) { try { Image currentImage = getCurrentImage(stack); StatedImage newImage = getNewImage(newImageId, imageCatalogName, imageCatalogUrl, currentImage); if (!isCloudPlatformMatches(stack, newImage)) { String message = messagesService.getMessage(Msg.CLOUDPLATFORM_DIFFERENT.code(), Lists.newArrayList(String.join(",", newImage.getImage().getImageSetsByProvider().keySet()), stack.cloudPlatform())); LOGGER.debug(message); throw new OperationException(message); } if (!isOsVersionsMatch(currentImage, newImage)) { String message = messagesService.getMessage(Msg.OSVERSION_DIFFERENT.code(), Lists.newArrayList(newImage.getImage().getOs(), newImage.getImage().getOsType(), currentImage.getOs(), currentImage.getOsType())); LOGGER.debug(message); throw new OperationException(message); } if (!isStackMatchIfPrewarmed(newImage)) { String message = "Stack versions don't match on prewarmed image with cluster's"; LOGGER.debug(message); throw new OperationException(message); } return newImage; } catch (CloudbreakImageNotFoundException e) { LOGGER.info("Cloudbreak Image not found", e); throw new CloudbreakApiException(e.getMessage(), e); } catch (CloudbreakImageCatalogException e) { LOGGER.info("Cloudbreak Image Catalog error", e); throw new CloudbreakApiException(e.getMessage(), e); } }
StackImageUpdateService { public StatedImage getNewImageIfVersionsMatch(Stack stack, String newImageId, String imageCatalogName, String imageCatalogUrl) { try { Image currentImage = getCurrentImage(stack); StatedImage newImage = getNewImage(newImageId, imageCatalogName, imageCatalogUrl, currentImage); if (!isCloudPlatformMatches(stack, newImage)) { String message = messagesService.getMessage(Msg.CLOUDPLATFORM_DIFFERENT.code(), Lists.newArrayList(String.join(",", newImage.getImage().getImageSetsByProvider().keySet()), stack.cloudPlatform())); LOGGER.debug(message); throw new OperationException(message); } if (!isOsVersionsMatch(currentImage, newImage)) { String message = messagesService.getMessage(Msg.OSVERSION_DIFFERENT.code(), Lists.newArrayList(newImage.getImage().getOs(), newImage.getImage().getOsType(), currentImage.getOs(), currentImage.getOsType())); LOGGER.debug(message); throw new OperationException(message); } if (!isStackMatchIfPrewarmed(newImage)) { String message = "Stack versions don't match on prewarmed image with cluster's"; LOGGER.debug(message); throw new OperationException(message); } return newImage; } catch (CloudbreakImageNotFoundException e) { LOGGER.info("Cloudbreak Image not found", e); throw new CloudbreakApiException(e.getMessage(), e); } catch (CloudbreakImageCatalogException e) { LOGGER.info("Cloudbreak Image Catalog error", e); throw new CloudbreakApiException(e.getMessage(), e); } } }
StackImageUpdateService { public StatedImage getNewImageIfVersionsMatch(Stack stack, String newImageId, String imageCatalogName, String imageCatalogUrl) { try { Image currentImage = getCurrentImage(stack); StatedImage newImage = getNewImage(newImageId, imageCatalogName, imageCatalogUrl, currentImage); if (!isCloudPlatformMatches(stack, newImage)) { String message = messagesService.getMessage(Msg.CLOUDPLATFORM_DIFFERENT.code(), Lists.newArrayList(String.join(",", newImage.getImage().getImageSetsByProvider().keySet()), stack.cloudPlatform())); LOGGER.debug(message); throw new OperationException(message); } if (!isOsVersionsMatch(currentImage, newImage)) { String message = messagesService.getMessage(Msg.OSVERSION_DIFFERENT.code(), Lists.newArrayList(newImage.getImage().getOs(), newImage.getImage().getOsType(), currentImage.getOs(), currentImage.getOsType())); LOGGER.debug(message); throw new OperationException(message); } if (!isStackMatchIfPrewarmed(newImage)) { String message = "Stack versions don't match on prewarmed image with cluster's"; LOGGER.debug(message); throw new OperationException(message); } return newImage; } catch (CloudbreakImageNotFoundException e) { LOGGER.info("Cloudbreak Image not found", e); throw new CloudbreakApiException(e.getMessage(), e); } catch (CloudbreakImageCatalogException e) { LOGGER.info("Cloudbreak Image Catalog error", e); throw new CloudbreakApiException(e.getMessage(), e); } }  }
StackImageUpdateService { public StatedImage getNewImageIfVersionsMatch(Stack stack, String newImageId, String imageCatalogName, String imageCatalogUrl) { try { Image currentImage = getCurrentImage(stack); StatedImage newImage = getNewImage(newImageId, imageCatalogName, imageCatalogUrl, currentImage); if (!isCloudPlatformMatches(stack, newImage)) { String message = messagesService.getMessage(Msg.CLOUDPLATFORM_DIFFERENT.code(), Lists.newArrayList(String.join(",", newImage.getImage().getImageSetsByProvider().keySet()), stack.cloudPlatform())); LOGGER.debug(message); throw new OperationException(message); } if (!isOsVersionsMatch(currentImage, newImage)) { String message = messagesService.getMessage(Msg.OSVERSION_DIFFERENT.code(), Lists.newArrayList(newImage.getImage().getOs(), newImage.getImage().getOsType(), currentImage.getOs(), currentImage.getOsType())); LOGGER.debug(message); throw new OperationException(message); } if (!isStackMatchIfPrewarmed(newImage)) { String message = "Stack versions don't match on prewarmed image with cluster's"; LOGGER.debug(message); throw new OperationException(message); } return newImage; } catch (CloudbreakImageNotFoundException e) { LOGGER.info("Cloudbreak Image not found", e); throw new CloudbreakApiException(e.getMessage(), e); } catch (CloudbreakImageCatalogException e) { LOGGER.info("Cloudbreak Image Catalog error", e); throw new CloudbreakApiException(e.getMessage(), e); } }  void storeNewImageComponent(Stack stack, StatedImage image); StatedImage getNewImageIfVersionsMatch(Stack stack, String newImageId, String imageCatalogName, String imageCatalogUrl); boolean isCbVersionOk(Stack stack); boolean isStackMatchIfPrewarmed(StatedImage image); CheckResult checkPackageVersions(Stack stack, StatedImage newImage); boolean isValidImage(Stack stack, String newImageId, String imageCatalogName, String imageCatalogUrl); }
StackImageUpdateService { public StatedImage getNewImageIfVersionsMatch(Stack stack, String newImageId, String imageCatalogName, String imageCatalogUrl) { try { Image currentImage = getCurrentImage(stack); StatedImage newImage = getNewImage(newImageId, imageCatalogName, imageCatalogUrl, currentImage); if (!isCloudPlatformMatches(stack, newImage)) { String message = messagesService.getMessage(Msg.CLOUDPLATFORM_DIFFERENT.code(), Lists.newArrayList(String.join(",", newImage.getImage().getImageSetsByProvider().keySet()), stack.cloudPlatform())); LOGGER.debug(message); throw new OperationException(message); } if (!isOsVersionsMatch(currentImage, newImage)) { String message = messagesService.getMessage(Msg.OSVERSION_DIFFERENT.code(), Lists.newArrayList(newImage.getImage().getOs(), newImage.getImage().getOsType(), currentImage.getOs(), currentImage.getOsType())); LOGGER.debug(message); throw new OperationException(message); } if (!isStackMatchIfPrewarmed(newImage)) { String message = "Stack versions don't match on prewarmed image with cluster's"; LOGGER.debug(message); throw new OperationException(message); } return newImage; } catch (CloudbreakImageNotFoundException e) { LOGGER.info("Cloudbreak Image not found", e); throw new CloudbreakApiException(e.getMessage(), e); } catch (CloudbreakImageCatalogException e) { LOGGER.info("Cloudbreak Image Catalog error", e); throw new CloudbreakApiException(e.getMessage(), e); } }  void storeNewImageComponent(Stack stack, StatedImage image); StatedImage getNewImageIfVersionsMatch(Stack stack, String newImageId, String imageCatalogName, String imageCatalogUrl); boolean isCbVersionOk(Stack stack); boolean isStackMatchIfPrewarmed(StatedImage image); CheckResult checkPackageVersions(Stack stack, StatedImage newImage); boolean isValidImage(Stack stack, String newImageId, String imageCatalogName, String imageCatalogUrl); static final String MIN_VERSION; }