Search in sources :

Example 1 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) {
    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);
    }
}
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 2 with ImageCatalogV4Endpoint

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;
}
Also used : TestException(org.testng.TestException) ImageCatalogV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.imagecatalog.responses.ImageCatalogV4Response) TestException(org.testng.TestException)

Example 3 with ImageCatalogV4Endpoint

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();
}
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) ImageCatalogTestDto(com.sequenceiq.it.cloudbreak.dto.imagecatalog.ImageCatalogTestDto) UpdateImageCatalogV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.imagecatalog.requests.UpdateImageCatalogV4Request) ImageCatalogV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.imagecatalog.requests.ImageCatalogV4Request) Description(com.sequenceiq.it.cloudbreak.context.Description) Test(org.testng.annotations.Test)

Example 4 with ImageCatalogV4Endpoint

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();
}
Also used : UpdateImageCatalogV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.imagecatalog.requests.UpdateImageCatalogV4Request) 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) ImageCatalogTestDto(com.sequenceiq.it.cloudbreak.dto.imagecatalog.ImageCatalogTestDto) ImageCatalogV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.imagecatalog.responses.ImageCatalogV4Response) Description(com.sequenceiq.it.cloudbreak.context.Description) Test(org.testng.annotations.Test)

Example 5 with ImageCatalogV4Endpoint

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();
    }
}
Also used : ImageV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.imagecatalog.responses.ImageV4Response) TestFailException(com.sequenceiq.it.cloudbreak.exception.TestFailException) TestFailException(com.sequenceiq.it.cloudbreak.exception.TestFailException)

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