Search in sources :

Example 1 with ImagesV4Response

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

the class ImageCatalogTest method testGetImageCatalogWhenCatalogDoesNotContainTheRequestedProvider.

@Test(dataProvider = TEST_CONTEXT_WITH_MOCK)
@Description(given = "image catalog get the default catalog with AWS provider but catalog does not contain AWS entry", when = "calling get on the default", then = "the response does not contains AWS images")
public void testGetImageCatalogWhenCatalogDoesNotContainTheRequestedProvider(MockedTestContext testContext) {
    String imgCatalogName = resourcePropertyProvider().getName();
    testContext.given(imgCatalogName, ImageCatalogTestDto.class).withName(imgCatalogName).withUrl(getImageCatalogMockServerSetup().getImageCatalogUrl()).when(imageCatalogTestClient.createV4(), key(imgCatalogName)).when(new ImageCatalogGetImagesByNameAction(CloudPlatform.AWS), key(imgCatalogName)).then((testContext1, entity, cloudbreakClient) -> {
        ImagesV4Response catalog = entity.getResponseByProvider();
        if (!catalog.getBaseImages().isEmpty()) {
            throw new IllegalArgumentException("The Images response should NOT contain results for AWS provider.");
        }
        return entity;
    }).validate();
}
Also used : ImageCatalogTestClient(com.sequenceiq.it.cloudbreak.client.ImageCatalogTestClient) MockedTestContext(com.sequenceiq.it.cloudbreak.context.MockedTestContext) TestContext(com.sequenceiq.it.cloudbreak.context.TestContext) RunningParameter.key(com.sequenceiq.it.cloudbreak.context.RunningParameter.key) Test(org.testng.annotations.Test) ImageCatalogV4Responses(com.sequenceiq.cloudbreak.api.endpoint.v4.imagecatalog.responses.ImageCatalogV4Responses) UpdateImageCatalogV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.imagecatalog.requests.UpdateImageCatalogV4Request) StackTestClient(com.sequenceiq.it.cloudbreak.client.StackTestClient) CloudPlatform(com.sequenceiq.cloudbreak.common.mappable.CloudPlatform) NotFoundException(javax.ws.rs.NotFoundException) ImageCatalogV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.imagecatalog.requests.ImageCatalogV4Request) Description(com.sequenceiq.it.cloudbreak.context.Description) Inject(javax.inject.Inject) ImageCatalogV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.imagecatalog.responses.ImageCatalogV4Response) EnvironmentTestClient(com.sequenceiq.it.cloudbreak.client.EnvironmentTestClient) ImageCatalogGetImagesByNameAction(com.sequenceiq.it.cloudbreak.action.v4.imagecatalog.ImageCatalogGetImagesByNameAction) BadRequestException(javax.ws.rs.BadRequestException) ImagesV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.imagecatalog.responses.ImagesV4Response) RunningParameter.expectedMessage(com.sequenceiq.it.cloudbreak.context.RunningParameter.expectedMessage) ImageCatalogTestDto(com.sequenceiq.it.cloudbreak.dto.imagecatalog.ImageCatalogTestDto) ImageCatalogGetImagesByNameAction(com.sequenceiq.it.cloudbreak.action.v4.imagecatalog.ImageCatalogGetImagesByNameAction) ImagesV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.imagecatalog.responses.ImagesV4Response) Description(com.sequenceiq.it.cloudbreak.context.Description) Test(org.testng.annotations.Test)

Example 2 with ImagesV4Response

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

the class CoreImageProviderTest method testGetImagesdReturnsEmptyListWhenFreeImagesNull.

@Test
public void testGetImagesdReturnsEmptyListWhenFreeImagesNull() throws Exception {
    when(imageCatalogV4Endpoint.getImagesByName(WORKSPACE_ID_DEFAULT, CATALOG_NAME, null, PLATFORM, null, null, false)).thenReturn(new ImagesV4Response());
    ImageSettingsRequest imageSettings = new ImageSettingsRequest();
    imageSettings.setCatalog(CATALOG_NAME);
    List<ImageWrapper> result = victim.getImages(imageSettings, "", PLATFORM);
    assertTrue(result.isEmpty());
}
Also used : ImageSettingsRequest(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.image.ImageSettingsRequest) ImageWrapper(com.sequenceiq.freeipa.dto.ImageWrapper) ImagesV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.imagecatalog.responses.ImagesV4Response) Test(org.junit.jupiter.api.Test)

Example 3 with ImagesV4Response

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

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

the class ImagesToImagesV4ResponseConverter method convert.

public ImagesV4Response convert(Images source) {
    ImagesV4Response res = new ImagesV4Response();
    List<BaseImageV4Response> baseImages = getBaseImageResponses(source);
    res.setBaseImages(baseImages);
    List<ImageV4Response> cdhImages = convertImages(source.getCdhImages(), StackType.CDH);
    res.setCdhImages(cdhImages);
    res.setSupportedVersions(source.getSuppertedVersions());
    res.setFreeipaImages(source.getFreeIpaImages().stream().map(image -> imageToImageV4ResponseConverter.convert(image)).collect(Collectors.toList()));
    return res;
}
Also used : BaseImageV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.imagecatalog.responses.BaseImageV4Response) BaseImageV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.imagecatalog.responses.BaseImageV4Response) ImageV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.imagecatalog.responses.ImageV4Response) ImagesV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.imagecatalog.responses.ImagesV4Response)

Example 5 with ImagesV4Response

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

Aggregations

ImagesV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.imagecatalog.responses.ImagesV4Response)8 ImageV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.imagecatalog.responses.ImageV4Response)4 ImageSettingsRequest (com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.image.ImageSettingsRequest)3 ImageWrapper (com.sequenceiq.freeipa.dto.ImageWrapper)3 Test (org.junit.jupiter.api.Test)3 ImageCatalogV4Endpoint (com.sequenceiq.cloudbreak.api.endpoint.v4.imagecatalog.ImageCatalogV4Endpoint)2 Image (com.sequenceiq.freeipa.api.v1.freeipa.stack.model.image.Image)2 Inject (javax.inject.Inject)2 ImageCatalogV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.imagecatalog.requests.ImageCatalogV4Request)1 UpdateImageCatalogV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.imagecatalog.requests.UpdateImageCatalogV4Request)1 BaseImageV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.imagecatalog.responses.BaseImageV4Response)1 ImageCatalogV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.imagecatalog.responses.ImageCatalogV4Response)1 ImageCatalogV4Responses (com.sequenceiq.cloudbreak.api.endpoint.v4.imagecatalog.responses.ImageCatalogV4Responses)1 ImageSettingsV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.image.ImageSettingsV4Request)1 CloudbreakServiceException (com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException)1 WebApplicationExceptionMessageExtractor (com.sequenceiq.cloudbreak.common.exception.WebApplicationExceptionMessageExtractor)1 CloudPlatform (com.sequenceiq.cloudbreak.common.mappable.CloudPlatform)1 AbstractEntityConverterTest (com.sequenceiq.cloudbreak.converter.AbstractEntityConverterTest)1 ImageCatalogGetImagesByNameAction (com.sequenceiq.it.cloudbreak.action.v4.imagecatalog.ImageCatalogGetImagesByNameAction)1 EnvironmentTestClient (com.sequenceiq.it.cloudbreak.client.EnvironmentTestClient)1