Search in sources :

Example 6 with ImageCatalog

use of com.sequenceiq.freeipa.api.v1.freeipa.stack.model.image.ImageCatalog in project cloudbreak by hortonworks.

the class FreeIpaCreationHandler method setImage.

private void setImage(EnvironmentDto environment, CreateFreeIpaRequest createFreeIpaRequest) {
    if (environment.getFreeIpaCreation() != null) {
        String imageCatalog = environment.getFreeIpaCreation().getImageCatalog();
        String imageId = environment.getFreeIpaCreation().getImageId();
        if (!Strings.isNullOrEmpty(imageId)) {
            LOGGER.info("FreeIPA creation with a pre-defined image catalog and image id: '{}', '{}'", imageCatalog, imageId);
            ImageSettingsRequest imageSettings = new ImageSettingsRequest();
            imageSettings.setCatalog(imageCatalog);
            imageSettings.setId(imageId);
            createFreeIpaRequest.setImage(imageSettings);
        } else {
            LOGGER.info("FreeIPA creation without pre-defined image settings. FreeIpa serivce is going to handle default settings.");
        }
    }
}
Also used : ImageSettingsRequest(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.image.ImageSettingsRequest)

Example 7 with ImageCatalog

use of com.sequenceiq.freeipa.api.v1.freeipa.stack.model.image.ImageCatalog in project cloudbreak by hortonworks.

the class FreeIpaImageProvider method getImage.

@Override
public Optional<ImageWrapper> getImage(ImageSettingsRequest imageSettings, String region, String platform) {
    String imageId = imageSettings.getId();
    String catalogUrl = StringUtils.isNotBlank(imageSettings.getCatalog()) ? imageSettings.getCatalog() : defaultCatalogUrl;
    String imageOs = StringUtils.isNotBlank(imageSettings.getOs()) ? imageSettings.getOs() : defaultOs;
    ImageCatalog cachedImageCatalog = imageCatalogProvider.getImageCatalog(catalogUrl);
    return findImageForAppVersion(region, platform, imageId, imageOs, cachedImageCatalog).or(() -> retryAfterEvictingCache(region, platform, imageId, catalogUrl, imageOs)).map(i -> new ImageWrapper(i, catalogUrl, null));
}
Also used : ImageWrapper(com.sequenceiq.freeipa.dto.ImageWrapper) ImageCatalog(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.image.ImageCatalog)

Example 8 with ImageCatalog

use of com.sequenceiq.freeipa.api.v1.freeipa.stack.model.image.ImageCatalog in project cloudbreak by hortonworks.

the class FreeIpaImageProvider method retryAfterEvictingCache.

private Optional<Image> retryAfterEvictingCache(String region, String platform, String imageId, String catalogUrl, String imageOs) {
    LOGGER.debug("Image not found with the parameters: imageId: {}, imageOs: {}, region: {}, platform: {}", imageId, imageOs, region, platform);
    LOGGER.debug("Evicting image catalog cache to retry.");
    imageCatalogProvider.evictImageCatalogCache(catalogUrl);
    ImageCatalog renewedImageCatalog = imageCatalogProvider.getImageCatalog(catalogUrl);
    return findImageForAppVersion(region, platform, imageId, imageOs, renewedImageCatalog);
}
Also used : ImageCatalog(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.image.ImageCatalog)

Example 9 with ImageCatalog

use of com.sequenceiq.freeipa.api.v1.freeipa.stack.model.image.ImageCatalog in project cloudbreak by hortonworks.

the class ImageCatalogChangeService method changeImageCatalog.

public void changeImageCatalog(String environmentCrn, String accountId, String imageCatalog) {
    try {
        final Stack stack = stackService.getByEnvironmentCrnAndAccountId(environmentCrn, accountId);
        MDCBuilder.buildMdcContext(stack);
        if (flowLogService.isOtherFlowRunning(stack.getId())) {
            throw new CloudbreakServiceException(String.format("Operation is running for stack '%s'. Please try again later.", stack.getName()));
        }
        final ImageSettingsRequest imageRequest = getImageSettingsRequestForNewCatalogWithCurrentImageSettings(imageCatalog, stack.getImage());
        imageService.changeImage(stack, imageRequest);
    } catch (ImageNotFoundException e) {
        LOGGER.info("Could not find current image in new catalog", e);
        throw new CloudbreakServiceException("Could not find current image in new catalog", e);
    }
}
Also used : ImageSettingsRequest(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.image.ImageSettingsRequest) CloudbreakServiceException(com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException) Stack(com.sequenceiq.freeipa.entity.Stack)

Example 10 with ImageCatalog

use of com.sequenceiq.freeipa.api.v1.freeipa.stack.model.image.ImageCatalog in project cloudbreak by hortonworks.

the class ImageCatalogProvider method getImageCatalog.

@Cacheable(cacheNames = "imageCatalogCache", key = "#catalogUrl")
public ImageCatalog getImageCatalog(String catalogUrl) {
    try {
        if (Objects.nonNull(catalogUrl)) {
            long started = System.currentTimeMillis();
            String content = readCatalogContent(catalogUrl);
            ImageCatalog catalog = objectMapper.readValue(content, ImageCatalog.class);
            if (Objects.nonNull(catalog)) {
                ImageCatalog filteredCatalog = filterImagesByOsType(catalog);
                long timeOfParse = System.currentTimeMillis() - started;
                LOGGER.debug("ImageCatalog was fetched and parsed from '{}' and took '{}' ms.", catalogUrl, timeOfParse);
                return filteredCatalog;
            }
            throw new ImageCatalogException(String.format("Failed to read the content of '%s' as an image catalog.", catalogUrl));
        }
        throw new ImageCatalogException("Unable to fetch image catalog. The catalogUrl is null.");
    } catch (ImageCatalogException e) {
        throw e;
    } catch (RuntimeException e) {
        throw new ImageCatalogException(String.format("Failed to get image catalog: %s from %s", e.getCause(), catalogUrl), e);
    } catch (JsonMappingException e) {
        throw new ImageCatalogException(String.format("Invalid json format for image catalog with error: %s", e.getMessage()), e);
    } catch (IOException e) {
        throw new ImageCatalogException(String.format("Failed to read image catalog from file: '%s'", catalogUrl));
    }
}
Also used : JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException) IOException(java.io.IOException) ImageCatalog(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.image.ImageCatalog) Cacheable(org.springframework.cache.annotation.Cacheable)

Aggregations

ImageCatalog (com.sequenceiq.freeipa.api.v1.freeipa.stack.model.image.ImageCatalog)16 Image (com.sequenceiq.freeipa.api.v1.freeipa.stack.model.image.Image)7 FreeIpaVersions (com.sequenceiq.freeipa.api.v1.freeipa.stack.model.image.FreeIpaVersions)5 Test (org.junit.Test)5 ImageSettingsRequest (com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.image.ImageSettingsRequest)4 Stack (com.sequenceiq.freeipa.entity.Stack)4 ImageWrapper (com.sequenceiq.freeipa.dto.ImageWrapper)3 Images (com.sequenceiq.freeipa.api.v1.freeipa.stack.model.image.Images)2 Versions (com.sequenceiq.freeipa.api.v1.freeipa.stack.model.image.Versions)2 GenerateImageCatalogResponse (com.sequenceiq.freeipa.api.v1.freeipa.stack.model.imagecatalog.GenerateImageCatalogResponse)2 Test (org.junit.jupiter.api.Test)2 JsonMappingException (com.fasterxml.jackson.databind.JsonMappingException)1 CloudbreakServiceException (com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException)1 ImageSettingsBase (com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.image.ImageSettingsBase)1 ImageEntity (com.sequenceiq.freeipa.entity.ImageEntity)1 IOException (java.io.IOException)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 Comparator (java.util.Comparator)1 List (java.util.List)1