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) {
try {
List<BaseImageV4Response> images = cloudbreakClient.getDefaultClient().imageCatalogV4Endpoint().getImagesByName(cloudbreakClient.getWorkspaceId(), imageCatalogTestDto.getRequest().getName(), null, platform, null, null).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 ImageCatalogCreateRetryAction method action.
@Override
public ImageCatalogTestDto action(TestContext testContext, ImageCatalogTestDto testDto, CloudbreakClient client) throws Exception {
Log.whenJson(LOGGER, format(" Image catalog post request with retry: %n"), testDto.getRequest());
ImageCatalogV4Response response = null;
Exception exc = null;
int counter = 0;
do {
try {
response = client.getDefaultClient().imageCatalogV4Endpoint().create(client.getWorkspaceId(), testDto.getRequest());
} catch (Exception e) {
Log.when(LOGGER, "Image catalog could not created - retry");
exc = e;
Thread.sleep(2000);
if (counter++ > 30) {
break;
}
}
} while (response == null);
if (response != null) {
testDto.setResponse(response);
} else {
throw new TestException("Image catalog could not created 30 times ", exc);
}
Log.whenJson(LOGGER, format(" Image catalog created successfully:%n"), testDto.getResponse());
return testDto;
}
use of com.sequenceiq.cloudbreak.api.endpoint.v4.imagecatalog.ImageCatalogV4Endpoint in project cloudbreak by hortonworks.
the class ImageCatalogTest method testGetImageCatalogsRequestFromExistingImageCatalog.
@Test(dataProvider = TEST_CONTEXT_WITH_MOCK)
@Description(given = "image catalog get request", when = "calling get request on catalog endpoint", then = "getting back the catalog request")
public void testGetImageCatalogsRequestFromExistingImageCatalog(MockedTestContext testContext) {
String imgCatalogName = resourcePropertyProvider().getName();
testContext.given(imgCatalogName, ImageCatalogTestDto.class).withName(imgCatalogName).withUrl(getImageCatalogMockServerSetup().getImageCatalogUrl()).when(imageCatalogTestClient.createV4(), key(imgCatalogName)).select(ImageCatalogTestDto::getRequest, key(imgCatalogName)).when((testContext1, entity, cloudbreakClient) -> {
ImageCatalogV4Request request = cloudbreakClient.getDefaultClient().imageCatalogV4Endpoint().getRequest(cloudbreakClient.getWorkspaceId(), imgCatalogName);
entity.setRequest(request);
return entity;
}).then((testContext1, entity, cloudbreakClient) -> {
ImageCatalogV4Request imgCatReq = testContext1.getSelected(imgCatalogName);
if (entity.getRequest().equals(imgCatReq)) {
throw new IllegalArgumentException("The requests are not identical.");
}
return entity;
}).validate();
}
use of com.sequenceiq.cloudbreak.api.endpoint.v4.imagecatalog.ImageCatalogV4Endpoint in project cloudbreak by hortonworks.
the class ImageCatalogTest method testUpdateImageCatalog.
@Test(dataProvider = TEST_CONTEXT_WITH_MOCK)
@Description(given = "image catalog update request", when = "calling update request with new url", then = "the image catalog list should contains the new url")
public void testUpdateImageCatalog(MockedTestContext testContext) {
String imgCatalogName = resourcePropertyProvider().getName();
testContext.given(imgCatalogName, ImageCatalogTestDto.class).withName(imgCatalogName).withUrl(getImageCatalogMockServerSetup().getImageCatalogUrl()).when(imageCatalogTestClient.createV4(), key(imgCatalogName)).select(ImageCatalogTestDto::getResponse, key(imgCatalogName)).when((testContext1, entity, cloudbreakClient) -> {
ImageCatalogV4Response originalResponse = entity.getResponse();
UpdateImageCatalogV4Request updateRequest = new UpdateImageCatalogV4Request();
updateRequest.setCrn(originalResponse.getCrn());
updateRequest.setName(originalResponse.getName());
updateRequest.setUrl(IMG_CATALOG_URL);
ImageCatalogV4Response updateResponse = cloudbreakClient.getDefaultClient().imageCatalogV4Endpoint().update(cloudbreakClient.getWorkspaceId(), updateRequest);
entity.setResponse(updateResponse);
return entity;
}, key(imgCatalogName)).then((testContext1, entity, cloudbreakClient) -> {
ImageCatalogV4Response originalRepsonse = testContext1.getSelected(imgCatalogName);
if (originalRepsonse.getUrl().equals(entity.getResponse().getUrl())) {
throw new IllegalArgumentException("The catalog URL should not be the same after update.");
}
return entity;
}, key(imgCatalogName)).validate();
}
use of com.sequenceiq.cloudbreak.api.endpoint.v4.imagecatalog.ImageCatalogV4Endpoint 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();
}
}
Aggregations