Search in sources :

Example 21 with ImageSettingsRequest

use of com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.image.ImageSettingsRequest 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 22 with ImageSettingsRequest

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

the class CoreImageProvider method getImage.

@Override
public Optional<ImageWrapper> getImage(ImageSettingsRequest imageSettings, String region, String platform) {
    try {
        ImageV4Response imageV4Response = imageCatalogV4Endpoint.getSingleImageByCatalogNameAndImageId(WORKSPACE_ID_DEFAULT, imageSettings.getCatalog(), imageSettings.getId());
        Optional<Image> image = convert(imageV4Response);
        return image.map(i -> new ImageWrapper(i, defaultCatalogUrl, imageSettings.getCatalog()));
    } catch (Exception ex) {
        LOGGER.warn("Image lookup failed: {}", ex.getMessage());
        return Optional.empty();
    }
}
Also used : ImageWrapper(com.sequenceiq.freeipa.dto.ImageWrapper) ImageV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.imagecatalog.responses.ImageV4Response) Image(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.image.Image) WebApplicationException(javax.ws.rs.WebApplicationException)

Example 23 with ImageSettingsRequest

use of com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.image.ImageSettingsRequest 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 24 with ImageSettingsRequest

use of com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.image.ImageSettingsRequest 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 25 with ImageSettingsRequest

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

the class ImageService method imageEntityToImageSettingsRequest.

private ImageSettingsRequest imageEntityToImageSettingsRequest(ImageEntity imageEntity) {
    final ImageSettingsRequest imageSettings = new ImageSettingsRequest();
    imageSettings.setCatalog(Objects.requireNonNullElse(imageEntity.getImageCatalogName(), imageEntity.getImageCatalogUrl()));
    imageSettings.setId(imageEntity.getImageId());
    return imageSettings;
}
Also used : ImageSettingsRequest(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.image.ImageSettingsRequest)

Aggregations

ImageSettingsRequest (com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.image.ImageSettingsRequest)57 Test (org.junit.jupiter.api.Test)41 ImageWrapper (com.sequenceiq.freeipa.dto.ImageWrapper)28 Image (com.sequenceiq.freeipa.api.v1.freeipa.stack.model.image.Image)23 Stack (com.sequenceiq.freeipa.entity.Stack)23 ImageInfoResponse (com.sequenceiq.freeipa.api.v1.freeipa.upgrade.model.ImageInfoResponse)16 ImageEntity (com.sequenceiq.freeipa.entity.ImageEntity)7 InstanceMetaData (com.sequenceiq.freeipa.entity.InstanceMetaData)5 FreeIpaUpgradeRequest (com.sequenceiq.freeipa.api.v1.freeipa.upgrade.model.FreeIpaUpgradeRequest)4 ImageChangeEvent (com.sequenceiq.freeipa.flow.stack.image.change.event.ImageChangeEvent)4 WebApplicationException (javax.ws.rs.WebApplicationException)4 ImagesV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.imagecatalog.responses.ImagesV4Response)3 FlowIdentifier (com.sequenceiq.flow.api.model.FlowIdentifier)3 FlowParameters (com.sequenceiq.flow.core.FlowParameters)3 Backup (com.sequenceiq.freeipa.api.model.Backup)3 UpgradeEvent (com.sequenceiq.freeipa.flow.freeipa.upgrade.UpgradeEvent)3 ImageV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.imagecatalog.responses.ImageV4Response)2 Acceptable (com.sequenceiq.cloudbreak.common.event.Acceptable)2 BadRequestException (com.sequenceiq.cloudbreak.common.exception.BadRequestException)2 Telemetry (com.sequenceiq.common.api.telemetry.model.Telemetry)2