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();
}
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());
}
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;
}
}
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;
}
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);
});
}
Aggregations