Search in sources :

Example 1 with ImageV4Response

use of com.sequenceiq.cloudbreak.api.endpoint.v4.imagecatalog.responses.ImageV4Response in project cloudbreak by hortonworks.

the class CoreImageProviderTest method anImageResponse.

private ImageV4Response anImageResponse() {
    ImageV4Response response = new ImageV4Response();
    response.setDate(DATE);
    response.setDescription(DESCRIPTION);
    response.setUuid(UUID);
    response.setOsType(OS_TYPE);
    response.setImageSetsByProvider(VM_IMAGES);
    return response;
}
Also used : ImageV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.imagecatalog.responses.ImageV4Response)

Example 2 with ImageV4Response

use of com.sequenceiq.cloudbreak.api.endpoint.v4.imagecatalog.responses.ImageV4Response 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 3 with ImageV4Response

use of com.sequenceiq.cloudbreak.api.endpoint.v4.imagecatalog.responses.ImageV4Response in project cloudbreak by hortonworks.

the class AwsCloudProvider method getPreviousPreWarmedImageID.

@Override
public String getPreviousPreWarmedImageID(TestContext testContext, ImageCatalogTestDto imageCatalogTestDto, CloudbreakClient cloudbreakClient) {
    if (awsProperties.getBaseimage().getImageId() == null || awsProperties.getBaseimage().getImageId().isEmpty()) {
        try {
            List<ImageV4Response> images = cloudbreakClient.getDefaultClient().imageCatalogV4Endpoint().getImagesByName(cloudbreakClient.getWorkspaceId(), imageCatalogTestDto.getRequest().getName(), null, CloudPlatform.AWS.name(), null, null, false).getCdhImages();
            ImageV4Response olderImage = images.get(images.size() - 2);
            Log.log(LOGGER, format(" Image Catalog Name: %s ", imageCatalogTestDto.getRequest().getName()));
            Log.log(LOGGER, format(" Image Catalog URL: %s ", imageCatalogTestDto.getRequest().getUrl()));
            Log.log(LOGGER, format(" Selected Pre-warmed Image Date: %s | ID: %s | Description: %s | Stack Version: %s ", olderImage.getDate(), olderImage.getUuid(), olderImage.getStackDetails().getVersion(), olderImage.getDescription()));
            awsProperties.getBaseimage().setImageId(olderImage.getUuid());
            return olderImage.getUuid();
        } catch (Exception e) {
            LOGGER.error("Cannot fetch pre-warmed images of {} image catalog!", imageCatalogTestDto.getRequest().getName());
            throw new TestFailException(" Cannot fetch pre-warmed images of " + imageCatalogTestDto.getRequest().getName() + " image catalog!", e);
        }
    } else {
        Log.log(LOGGER, format(" Image Catalog Name: %s ", commonCloudProperties().getImageCatalogName()));
        Log.log(LOGGER, format(" Image Catalog URL: %s ", commonCloudProperties().getImageCatalogUrl()));
        Log.log(LOGGER, format(" Image ID for SDX create: %s ", awsProperties.getBaseimage().getImageId()));
        return awsProperties.getBaseimage().getImageId();
    }
}
Also used : ImageV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.imagecatalog.responses.ImageV4Response) TestFailException(com.sequenceiq.it.cloudbreak.exception.TestFailException) TestFailException(com.sequenceiq.it.cloudbreak.exception.TestFailException)

Example 4 with ImageV4Response

use of com.sequenceiq.cloudbreak.api.endpoint.v4.imagecatalog.responses.ImageV4Response in project cloudbreak by hortonworks.

the class ImageCatalogServiceTest method getImageResponse.

private ImageV4Response getImageResponse() {
    Map<String, Map<String, String>> imageSetsByProvider = new HashMap<>();
    imageSetsByProvider.put("aws", null);
    BaseStackDetailsV4Response stackDetails = new BaseStackDetailsV4Response();
    stackDetails.setVersion("7.2.7");
    ImageV4Response imageV4Response = new ImageV4Response();
    imageV4Response.setImageSetsByProvider(imageSetsByProvider);
    imageV4Response.setStackDetails(stackDetails);
    return imageV4Response;
}
Also used : HashMap(java.util.HashMap) ImageV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.imagecatalog.responses.ImageV4Response) HashMap(java.util.HashMap) Map(java.util.Map) BaseStackDetailsV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.imagecatalog.responses.BaseStackDetailsV4Response)

Example 5 with ImageV4Response

use of com.sequenceiq.cloudbreak.api.endpoint.v4.imagecatalog.responses.ImageV4Response in project cloudbreak by hortonworks.

the class ImageCatalogService method getImageResponseFromImageRequest.

public ImageV4Response getImageResponseFromImageRequest(ImageSettingsV4Request imageSettingsV4Request, CloudPlatform cloudPlatform) {
    String accountId = ThreadBasedUserCrnProvider.getAccountId();
    if (imageSettingsV4Request == null) {
        return null;
    }
    ImageCatalogV4Endpoint imageCatalogV4Endpoint = cloudbreakInternalCrnClient.withInternalCrn().imageCatalogV4Endpoint();
    try {
        LOGGER.info("Calling cloudbreak to get image response for the given image catalog {} and image id {}", imageSettingsV4Request.getCatalog(), imageSettingsV4Request.getId());
        ImagesV4Response imagesV4Response = null;
        try {
            if (StringUtils.isBlank(imageSettingsV4Request.getCatalog())) {
                imagesV4Response = imageCatalogV4Endpoint.getImageByImageId(SdxService.WORKSPACE_ID_DEFAULT, imageSettingsV4Request.getId(), accountId);
            } else {
                imagesV4Response = imageCatalogV4Endpoint.getImageByCatalogNameAndImageId(SdxService.WORKSPACE_ID_DEFAULT, imageSettingsV4Request.getCatalog(), imageSettingsV4Request.getId(), accountId);
            }
        } catch (Exception e) {
            LOGGER.error("Sdx service fails to get image using image id", e);
        }
        if (imagesV4Response == null) {
            return null;
        }
        for (ImageV4Response imageV4Response : imagesV4Response.getCdhImages()) {
            // find the image can be used on the cloud platform of the environment
            if (imageV4Response.getImageSetsByProvider() != null) {
                if (imageV4Response.getImageSetsByProvider().containsKey(cloudPlatform.name().toLowerCase())) {
                    return imageV4Response;
                }
            }
        }
        String errorMessage = String.format("SDX cluster is on the cloud platform %s, but the image requested with uuid %s:%s does not support it", cloudPlatform.name(), imageSettingsV4Request.getCatalog() != null ? imageSettingsV4Request.getCatalog() : "default", imageSettingsV4Request.getId());
        LOGGER.error(errorMessage);
        return null;
    } catch (javax.ws.rs.NotFoundException e) {
        LOGGER.info("Sdx cluster not found on CB side", e);
        return null;
    }
}
Also used : ImageCatalogV4Endpoint(com.sequenceiq.cloudbreak.api.endpoint.v4.imagecatalog.ImageCatalogV4Endpoint) ImageV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.imagecatalog.responses.ImageV4Response) ImagesV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.imagecatalog.responses.ImagesV4Response) CloudbreakServiceException(com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException)

Aggregations

ImageV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.imagecatalog.responses.ImageV4Response)16 TestFailException (com.sequenceiq.it.cloudbreak.exception.TestFailException)4 BaseStackDetailsV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.imagecatalog.responses.BaseStackDetailsV4Response)3 ImagesV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.imagecatalog.responses.ImagesV4Response)3 NotImplementedException (org.apache.commons.lang3.NotImplementedException)3 StackV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackV4Request)2 AbstractEntityConverterTest (com.sequenceiq.cloudbreak.converter.AbstractEntityConverterTest)2 SdxCluster (com.sequenceiq.datalake.entity.SdxCluster)2 FlowIdentifier (com.sequenceiq.flow.api.model.FlowIdentifier)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Test (org.junit.Test)2 Test (org.junit.jupiter.api.Test)2 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)2 ImageCatalogV4Endpoint (com.sequenceiq.cloudbreak.api.endpoint.v4.imagecatalog.ImageCatalogV4Endpoint)1 BaseImageV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.imagecatalog.responses.BaseImageV4Response)1 ImageSettingsV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.image.ImageSettingsV4Request)1 ImageStackDetails (com.sequenceiq.cloudbreak.cloud.model.catalog.ImageStackDetails)1 BadRequestException (com.sequenceiq.cloudbreak.common.exception.BadRequestException)1 CloudbreakServiceException (com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException)1