use of com.sequenceiq.cloudbreak.service.image.StatedImage in project cloudbreak by hortonworks.
the class StackImageUpdateActions method checkImageVersion.
@Bean(name = "CHECK_IMAGE_VERSIONS_STATE")
public AbstractStackImageUpdateAction<?> checkImageVersion() {
return new AbstractStackImageUpdateAction<>(StackImageUpdateTriggerEvent.class) {
@Override
protected void doExecute(StackContext context, StackImageUpdateTriggerEvent payload, Map<Object, Object> variables) {
getFlowMessageService().fireEventAndLog(context.getStack().getId(), Status.UPDATE_IN_PROGRESS.name(), STACK_IMAGE_UPDATE_STARTED);
if (!getStackImageUpdateService().isCbVersionOk(context.getStack())) {
throw new OperationException("Stack must be created at least with Cloudbreak version [" + StackImageUpdateService.MIN_VERSION + ']');
}
StatedImage newImage = getStackImageUpdateService().getNewImageIfVersionsMatch(context.getStack(), payload.getNewImageId(), payload.getImageCatalogName(), payload.getImageCatalogUrl());
sendEvent(context, new ImageUpdateEvent(StackImageUpdateEvent.CHECK_IMAGE_VERESIONS_FINISHED_EVENT.event(), context.getStack().getId(), newImage));
}
};
}
use of com.sequenceiq.cloudbreak.service.image.StatedImage in project cloudbreak by hortonworks.
the class StackImageUpdateService method getNewImageIfVersionsMatch.
public StatedImage getNewImageIfVersionsMatch(Stack stack, String newImageId, String imageCatalogName, String imageCatalogUrl) {
try {
restRequestThreadLocalService.setWorkspace(stack.getWorkspace());
Image currentImage = stackImageService.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);
}
}
use of com.sequenceiq.cloudbreak.service.image.StatedImage in project cloudbreak by hortonworks.
the class StackImageUpdateService method getNewImage.
private StatedImage getNewImage(String newImageId, String imageCatalogName, String imageCatalogUrl, Image currentImage) throws CloudbreakImageNotFoundException, CloudbreakImageCatalogException {
StatedImage newImage;
newImage = StringUtils.isNotBlank(imageCatalogName) && StringUtils.isNotBlank(imageCatalogUrl) ? imageCatalogService.getImage(imageCatalogUrl, imageCatalogName, newImageId) : imageCatalogService.getImage(currentImage.getImageCatalogUrl(), currentImage.getImageCatalogName(), newImageId);
return newImage;
}
use of com.sequenceiq.cloudbreak.service.image.StatedImage in project cloudbreak by hortonworks.
the class StackImageUpdateService method isValidImage.
public boolean isValidImage(Stack stack, String newImageId, String imageCatalogName, String imageCatalogUrl) {
if (isCbVersionOk(stack)) {
try {
Image currentImage = stackImageService.getCurrentImage(stack);
StatedImage newImage = getNewImage(newImageId, imageCatalogName, imageCatalogUrl, currentImage);
boolean cloudPlatformMatches = isCloudPlatformMatches(stack, newImage);
boolean osVersionsMatch = isOsVersionsMatch(currentImage, newImage);
boolean stackMatchIfPrewarmed = isStackMatchIfPrewarmed(newImage);
CheckResult checkPackageVersionsStatus = checkPackageVersions(stack, newImage);
boolean aggregatedValidationResult = cloudPlatformMatches && osVersionsMatch && stackMatchIfPrewarmed;
if (!aggregatedValidationResult) {
LOGGER.info("Image validation for {}:\n " + "Valid platform? {}\n " + "Valid os? {}\n " + "Valid stack (prewarmed only)? {}", newImageId, cloudPlatformMatches, osVersionsMatch, stackMatchIfPrewarmed);
}
if (checkPackageVersionsStatus.getStatus() != EventStatus.OK) {
LOGGER.info("Image validation for {}:\n " + "Valid package versions? {}", newImageId, checkPackageVersionsStatus);
}
return aggregatedValidationResult;
} catch (CloudbreakImageNotFoundException e) {
LOGGER.debug("Cloudbreak Image not found", e);
return false;
} catch (CloudbreakImageCatalogException e) {
LOGGER.debug("Cloudbreak Image catalog error", e);
return false;
}
}
return false;
}
use of com.sequenceiq.cloudbreak.service.image.StatedImage in project cloudbreak by hortonworks.
the class StackImageService method replaceStackImageComponent.
private void replaceStackImageComponent(Stack stack, StatedImage targetImage) {
try {
Image newImage = getImageModelFromStatedImage(stack, componentConfigProviderService.getImage(stack.getId()), targetImage);
Component imageComponent = new Component(ComponentType.IMAGE, ComponentType.IMAGE.name(), new Json(newImage), stack);
componentConfigProviderService.replaceImageComponentWithNew(imageComponent);
} catch (CloudbreakImageNotFoundException e) {
LOGGER.info("Could not find image", e);
throw new CloudbreakServiceException("Could not find image", e);
}
}
Aggregations