Search in sources :

Example 1 with StatedImage

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));
        }
    };
}
Also used : StackContext(com.sequenceiq.cloudbreak.core.flow2.stack.StackContext) StackImageUpdateTriggerEvent(com.sequenceiq.cloudbreak.core.flow2.event.StackImageUpdateTriggerEvent) Map(java.util.Map) StatedImage(com.sequenceiq.cloudbreak.service.image.StatedImage) OperationException(com.sequenceiq.cloudbreak.service.OperationException) ImageUpdateEvent(com.sequenceiq.cloudbreak.reactor.api.event.stack.ImageUpdateEvent) Bean(org.springframework.context.annotation.Bean)

Example 2 with StatedImage

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);
    }
}
Also used : CloudbreakImageNotFoundException(com.sequenceiq.cloudbreak.core.CloudbreakImageNotFoundException) Image(com.sequenceiq.cloudbreak.cloud.model.Image) StatedImage(com.sequenceiq.cloudbreak.service.image.StatedImage) StatedImage(com.sequenceiq.cloudbreak.service.image.StatedImage) CloudbreakApiException(com.sequenceiq.cloudbreak.exception.CloudbreakApiException) OperationException(com.sequenceiq.cloudbreak.service.OperationException) CloudbreakImageCatalogException(com.sequenceiq.cloudbreak.core.CloudbreakImageCatalogException)

Example 3 with StatedImage

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;
}
Also used : StatedImage(com.sequenceiq.cloudbreak.service.image.StatedImage)

Example 4 with StatedImage

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;
}
Also used : CheckResult(com.sequenceiq.cloudbreak.core.flow2.CheckResult) CloudbreakImageNotFoundException(com.sequenceiq.cloudbreak.core.CloudbreakImageNotFoundException) Image(com.sequenceiq.cloudbreak.cloud.model.Image) StatedImage(com.sequenceiq.cloudbreak.service.image.StatedImage) StatedImage(com.sequenceiq.cloudbreak.service.image.StatedImage) CloudbreakImageCatalogException(com.sequenceiq.cloudbreak.core.CloudbreakImageCatalogException)

Example 5 with StatedImage

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);
    }
}
Also used : CloudbreakServiceException(com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException) CloudbreakImageNotFoundException(com.sequenceiq.cloudbreak.core.CloudbreakImageNotFoundException) Json(com.sequenceiq.cloudbreak.common.json.Json) Image(com.sequenceiq.cloudbreak.cloud.model.Image) StatedImage(com.sequenceiq.cloudbreak.service.image.StatedImage) Component(com.sequenceiq.cloudbreak.domain.stack.Component)

Aggregations

StatedImage (com.sequenceiq.cloudbreak.service.image.StatedImage)48 Image (com.sequenceiq.cloudbreak.cloud.model.catalog.Image)19 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)12 Test (org.junit.Test)12 Image (com.sequenceiq.cloudbreak.cloud.model.Image)11 Test (org.junit.jupiter.api.Test)10 CloudbreakImageNotFoundException (com.sequenceiq.cloudbreak.core.CloudbreakImageNotFoundException)9 Json (com.sequenceiq.cloudbreak.common.json.Json)7 CloudbreakImageCatalogException (com.sequenceiq.cloudbreak.core.CloudbreakImageCatalogException)7 InstanceMetaData (com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData)7 CheckResult (com.sequenceiq.cloudbreak.core.flow2.CheckResult)6 Map (java.util.Map)6 ImageCatalog (com.sequenceiq.cloudbreak.domain.ImageCatalog)5 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)5 CloudbreakDetails (com.sequenceiq.cloudbreak.cloud.model.CloudbreakDetails)4 CloudbreakServiceException (com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException)4 StackEvent (com.sequenceiq.cloudbreak.reactor.api.event.StackEvent)4 StackImageUpdateTriggerEvent (com.sequenceiq.cloudbreak.core.flow2.event.StackImageUpdateTriggerEvent)3 Cluster (com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster)3 ImageUpdateEvent (com.sequenceiq.cloudbreak.reactor.api.event.stack.ImageUpdateEvent)3