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