Search in sources :

Example 6 with ImageCatalogV4Endpoint

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

the class AbstractCloudProvider method getLatestBaseImage.

public String getLatestBaseImage(ImageCatalogTestDto imageCatalogTestDto, CloudbreakClient cloudbreakClient, String platform, boolean govCloud) {
    try {
        List<BaseImageV4Response> images = cloudbreakClient.getDefaultClient().imageCatalogV4Endpoint().getImagesByName(cloudbreakClient.getWorkspaceId(), imageCatalogTestDto.getRequest().getName(), null, platform, null, null, govCloud).getBaseImages();
        if (images.size() == 0) {
            throw new IllegalStateException("Images are empty, there is not any base image on provider " + platform);
        }
        BaseImageV4Response baseImage = images.get(images.size() - 1);
        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 Base Image Date: %s | ID: %s | Description: %s ", baseImage.getDate(), baseImage.getUuid(), baseImage.getDescription()));
        return baseImage.getUuid();
    } catch (Exception e) {
        LOGGER.error("Cannot fetch base images of {} image catalog, because of {}", imageCatalogTestDto.getRequest().getName(), e);
        throw new TestFailException(" Cannot fetch base images of " + imageCatalogTestDto.getRequest().getName() + " image catalog", e);
    }
}
Also used : BaseImageV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.imagecatalog.responses.BaseImageV4Response) TestFailException(com.sequenceiq.it.cloudbreak.exception.TestFailException) TestFailException(com.sequenceiq.it.cloudbreak.exception.TestFailException)

Example 7 with ImageCatalogV4Endpoint

use of com.sequenceiq.cloudbreak.api.endpoint.v4.imagecatalog.ImageCatalogV4Endpoint 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)

Example 8 with ImageCatalogV4Endpoint

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

the class ImageCatalogServiceTest method testImageLookupByImageCatalogNameAndImageID.

@Test
public void testImageLookupByImageCatalogNameAndImageID() throws Exception {
    ImageV4Response imageResponse = getImageResponse();
    ImagesV4Response imagesV4Response = new ImagesV4Response();
    imagesV4Response.setCdhImages(List.of(imageResponse));
    ImageSettingsV4Request imageSettingsV4Request = new ImageSettingsV4Request();
    imageSettingsV4Request.setCatalog(IMAGE_CATALOG_NAME);
    imageSettingsV4Request.setId(IMAGE_ID);
    when(cloudbreakInternalCrnClient.withInternalCrn()).thenReturn(cloudbreakServiceCrnEndpoints);
    when(cloudbreakServiceCrnEndpoints.imageCatalogV4Endpoint()).thenReturn(imageCatalogV4Endpoint);
    when(imageCatalogV4Endpoint.getImageByCatalogNameAndImageId(any(), eq(IMAGE_CATALOG_NAME), eq(IMAGE_ID), any())).thenReturn(imagesV4Response);
    ThreadBasedUserCrnProvider.doAs(USER_CRN, () -> {
        ImageV4Response actual = victim.getImageResponseFromImageRequest(imageSettingsV4Request, CloudPlatform.AWS);
        assertEquals(imageResponse, actual);
    });
}
Also used : ImageSettingsV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.image.ImageSettingsV4Request) ImageV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.imagecatalog.responses.ImageV4Response) ImagesV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.imagecatalog.responses.ImagesV4Response) Test(org.junit.jupiter.api.Test)

Example 9 with ImageCatalogV4Endpoint

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

the class ImageCatalogService method getResourceCrnByResourceName.

@Override
public String getResourceCrnByResourceName(String resourceName) {
    String initiatorUserCrn = ThreadBasedUserCrnProvider.getUserCrn();
    ImageCatalogV4Endpoint imageCatalogV4Endpoint = cloudbreakInternalCrnClient.withInternalCrn().imageCatalogV4Endpoint();
    ImageCatalogV4Response response = imageCatalogV4Endpoint.getByNameInternal(SdxService.WORKSPACE_ID_DEFAULT, resourceName, false, initiatorUserCrn);
    return response.getCrn();
}
Also used : ImageCatalogV4Endpoint(com.sequenceiq.cloudbreak.api.endpoint.v4.imagecatalog.ImageCatalogV4Endpoint) ImageCatalogV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.imagecatalog.responses.ImageCatalogV4Response)

Example 10 with ImageCatalogV4Endpoint

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

the class ImageCatalogGetImagesByNameAction method action.

@Override
public ImageCatalogTestDto action(TestContext testContext, ImageCatalogTestDto testDto, CloudbreakClient cloudbreakClient) throws Exception {
    Log.when(LOGGER, "Get Imagecatalog by name: " + testDto.getRequest().getName());
    try {
        ImageCatalogV4Endpoint imageCatalogV4Endpoint = cloudbreakClient.getDefaultClient().imageCatalogV4Endpoint();
        testDto.setResponseByProvider(getImagesV4Response(testDto, cloudbreakClient, imageCatalogV4Endpoint));
        Log.whenJson(LOGGER, "images have been fetched successfully: ", testDto.getRequest());
    } catch (Exception e) {
        LOGGER.warn("Cannot get images of ImageCatalog : {}", testDto.getRequest().getName());
        throw e;
    }
    return testDto;
}
Also used : ImageCatalogV4Endpoint(com.sequenceiq.cloudbreak.api.endpoint.v4.imagecatalog.ImageCatalogV4Endpoint)

Aggregations

ImageV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.imagecatalog.responses.ImageV4Response)6 TestFailException (com.sequenceiq.it.cloudbreak.exception.TestFailException)6 ImageCatalogV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.imagecatalog.responses.ImageCatalogV4Response)4 ImagesV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.imagecatalog.responses.ImagesV4Response)4 ImageCatalogV4Endpoint (com.sequenceiq.cloudbreak.api.endpoint.v4.imagecatalog.ImageCatalogV4Endpoint)3 NotImplementedException (org.apache.commons.lang3.NotImplementedException)3 ImageCatalogV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.imagecatalog.requests.ImageCatalogV4Request)2 UpdateImageCatalogV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.imagecatalog.requests.UpdateImageCatalogV4Request)2 BaseImageV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.imagecatalog.responses.BaseImageV4Response)2 ImageCatalogV4Responses (com.sequenceiq.cloudbreak.api.endpoint.v4.imagecatalog.responses.ImageCatalogV4Responses)2 CloudPlatform (com.sequenceiq.cloudbreak.common.mappable.CloudPlatform)2 ImageCatalogGetImagesByNameAction (com.sequenceiq.it.cloudbreak.action.v4.imagecatalog.ImageCatalogGetImagesByNameAction)2 EnvironmentTestClient (com.sequenceiq.it.cloudbreak.client.EnvironmentTestClient)2 ImageCatalogTestClient (com.sequenceiq.it.cloudbreak.client.ImageCatalogTestClient)2 StackTestClient (com.sequenceiq.it.cloudbreak.client.StackTestClient)2 Description (com.sequenceiq.it.cloudbreak.context.Description)2 MockedTestContext (com.sequenceiq.it.cloudbreak.context.MockedTestContext)2 RunningParameter.expectedMessage (com.sequenceiq.it.cloudbreak.context.RunningParameter.expectedMessage)2 RunningParameter.key (com.sequenceiq.it.cloudbreak.context.RunningParameter.key)2 TestContext (com.sequenceiq.it.cloudbreak.context.TestContext)2