Search in sources :

Example 96 with TestFailException

use of com.sequenceiq.it.cloudbreak.exception.TestFailException in project cloudbreak by hortonworks.

the class DistroXStopStartScaleTest method testStopStartScaleDistroX.

/**
 * The "Scaling" via Instance Stop/Start for DataHub ‘compute’ nodes (NodeManagers only) improves scaling performance
 * - at best, 4-6 minutes for a single node.
 *
 * @param testContext   Spring offers ApplicationContextAware interface to provide configuration of the Integration Test ApplicationContext.
 * @param iTestContext  TestNG offers the ITestContext interface to store and share test objects through test execution.
 */
@Test(dataProvider = TEST_CONTEXT)
@Description(given = "there is a running default Distrox cluster", when = "cluster has been scaled successfully by 4 compute nodes", then = "cluster compute nodes can be scaled down then up via stop then start instances at provider")
public void testStopStartScaleDistroX(TestContext testContext, ITestContext iTestContext) {
    AtomicReference<List<String>> instancesToStop = new AtomicReference<>();
    DistroXScaleTestParameters params = new DistroXScaleTestParameters(iTestContext.getCurrentXmlTest().getAllParameters());
    if (params.getTimes() < 1) {
        throw new TestFailException("Test should execute at least 1 round of scaling");
    }
    testContext.given(DistroXTestDto.class).when(distroXTestClient.scale(params.getHostGroup(), params.getScaleUpTarget())).awaitForFlow().then((tc, testDto, client) -> {
        instancesToStop.set(distroxUtil.getInstanceIds(testDto, client, params.getHostGroup()).stream().limit(params.getScaleDownTarget()).collect(Collectors.toList()));
        testDto.setInstanceIdsForActions(instancesToStop.get());
        return testDto;
    }).when(distroXTestClient.scaleStopInstances()).awaitForFlow().then(new DistroxStopStartScaleDurationAssertions(6, false)).when(distroXTestClient.scaleStartInstances(params.getHostGroup(), params.getScaleUpTarget())).awaitForFlow().when(distroXTestClient.get()).then(new DistroxStopStartScaleDurationAssertions(6, true));
    IntStream.range(1, params.getTimes()).forEach(i -> {
        testContext.given(DistroXTestDto.class).when(distroXTestClient.scaleStopInstances()).awaitForFlow().then(new DistroxStopStartScaleDurationAssertions(6, false)).when(distroXTestClient.scaleStartInstances(params.getHostGroup(), params.getScaleUpTarget())).awaitForFlow().when(distroXTestClient.get()).then(new DistroxStopStartScaleDurationAssertions(6, true));
    });
    testContext.given(DistroXTestDto.class).validate();
}
Also used : IntStream(java.util.stream.IntStream) TestContext(com.sequenceiq.it.cloudbreak.context.TestContext) ITestContext(org.testng.ITestContext) DistroxStopStartScaleDurationAssertions(com.sequenceiq.it.cloudbreak.assertion.distrox.DistroxStopStartScaleDurationAssertions) Test(org.testng.annotations.Test) AtomicReference(java.util.concurrent.atomic.AtomicReference) Collectors(java.util.stream.Collectors) CloudPlatform(com.sequenceiq.cloudbreak.common.mappable.CloudPlatform) DistroXTestDto(com.sequenceiq.it.cloudbreak.dto.distrox.DistroXTestDto) Description(com.sequenceiq.it.cloudbreak.context.Description) Inject(javax.inject.Inject) List(java.util.List) DistroXTestClient(com.sequenceiq.it.cloudbreak.client.DistroXTestClient) DistroxUtil(com.sequenceiq.it.cloudbreak.util.DistroxUtil) TestFailException(com.sequenceiq.it.cloudbreak.exception.TestFailException) AbstractE2ETest(com.sequenceiq.it.cloudbreak.testcase.e2e.AbstractE2ETest) DistroXTestDto(com.sequenceiq.it.cloudbreak.dto.distrox.DistroXTestDto) TestFailException(com.sequenceiq.it.cloudbreak.exception.TestFailException) List(java.util.List) AtomicReference(java.util.concurrent.atomic.AtomicReference) DistroxStopStartScaleDurationAssertions(com.sequenceiq.it.cloudbreak.assertion.distrox.DistroxStopStartScaleDurationAssertions) Description(com.sequenceiq.it.cloudbreak.context.Description) Test(org.testng.annotations.Test) AbstractE2ETest(com.sequenceiq.it.cloudbreak.testcase.e2e.AbstractE2ETest)

Example 97 with TestFailException

use of com.sequenceiq.it.cloudbreak.exception.TestFailException in project cloudbreak by hortonworks.

the class DistroXImagesTests method testDistroXWithBaseImageCanBeCreatedSuccessfully.

@Test(dataProvider = TEST_CONTEXT)
@UseSpotInstances
@Description(given = "there is a running cloudbreak", when = "a valid DistroX create request is sent (latest Base Image)", then = "DistroX should be available and deletable")
public void testDistroXWithBaseImageCanBeCreatedSuccessfully(TestContext testContext) {
    String imageSettings = resourcePropertyProvider().getName();
    String imageCatalog = resourcePropertyProvider().getName();
    String distrox = resourcePropertyProvider().getName();
    AtomicReference<String> selectedImageID = new AtomicReference<>();
    CloudProvider cloudProvider = testContext.getCloudProvider();
    testContext.given(imageCatalog, ImageCatalogTestDto.class).when((tc, dto, client) -> {
        selectedImageID.set(cloudProvider.getLatestBaseImageID(tc, dto, client));
        return dto;
    }).given(imageSettings, DistroXImageTestDto.class).withImageCatalog(cloudProvider.getImageCatalogName()).withImageId(selectedImageID.get()).given(distrox, DistroXTestDto.class).withImageSettings(imageSettings).when(distroXTestClient.create(), key(distrox)).await(STACK_AVAILABLE).awaitForHealthyInstances().then((tc, dto, client) -> {
        Log.log(LOGGER, format(" Image Catalog Name: %s ", dto.getResponse().getImage().getCatalogName()));
        Log.log(LOGGER, format(" Image Catalog URL: %s ", dto.getResponse().getImage().getCatalogUrl()));
        Log.log(LOGGER, format(" Image ID: %s ", dto.getResponse().getImage().getId()));
        if (!dto.getResponse().getImage().getId().equals(selectedImageID.get())) {
            throw new TestFailException(" The selected image ID is: " + dto.getResponse().getImage().getId() + " instead of: " + selectedImageID.get());
        }
        return dto;
    }).validate();
}
Also used : Ignore(org.testng.annotations.Ignore) CloudProvider(com.sequenceiq.it.cloudbreak.cloud.v4.CloudProvider) Logger(org.slf4j.Logger) TestContext(com.sequenceiq.it.cloudbreak.context.TestContext) DistroXImageTestDto(com.sequenceiq.it.cloudbreak.dto.distrox.image.DistroXImageTestDto) LoggerFactory(org.slf4j.LoggerFactory) InstanceStatus(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.InstanceStatus) Log(com.sequenceiq.it.cloudbreak.log.Log) RunningParameter.key(com.sequenceiq.it.cloudbreak.context.RunningParameter.key) HashMap(java.util.HashMap) Test(org.testng.annotations.Test) UseSpotInstances(com.sequenceiq.it.cloudbreak.util.spot.UseSpotInstances) AtomicReference(java.util.concurrent.atomic.AtomicReference) String.format(java.lang.String.format) DistroXTestDto(com.sequenceiq.it.cloudbreak.dto.distrox.DistroXTestDto) Description(com.sequenceiq.it.cloudbreak.context.Description) Inject(javax.inject.Inject) DistroXTestClient(com.sequenceiq.it.cloudbreak.client.DistroXTestClient) TestFailException(com.sequenceiq.it.cloudbreak.exception.TestFailException) Map(java.util.Map) HostGroupType(com.sequenceiq.it.cloudbreak.cloud.HostGroupType) AbstractE2ETest(com.sequenceiq.it.cloudbreak.testcase.e2e.AbstractE2ETest) ImageCatalogTestDto(com.sequenceiq.it.cloudbreak.dto.imagecatalog.ImageCatalogTestDto) DistroXImageTestDto(com.sequenceiq.it.cloudbreak.dto.distrox.image.DistroXImageTestDto) CloudProvider(com.sequenceiq.it.cloudbreak.cloud.v4.CloudProvider) ImageCatalogTestDto(com.sequenceiq.it.cloudbreak.dto.imagecatalog.ImageCatalogTestDto) TestFailException(com.sequenceiq.it.cloudbreak.exception.TestFailException) AtomicReference(java.util.concurrent.atomic.AtomicReference) Description(com.sequenceiq.it.cloudbreak.context.Description) Test(org.testng.annotations.Test) AbstractE2ETest(com.sequenceiq.it.cloudbreak.testcase.e2e.AbstractE2ETest) UseSpotInstances(com.sequenceiq.it.cloudbreak.util.spot.UseSpotInstances)

Example 98 with TestFailException

use of com.sequenceiq.it.cloudbreak.exception.TestFailException in project cloudbreak by hortonworks.

the class ExecuteQueryToMockInfrastructure method buildWebTarget.

private WebTarget buildWebTarget(String path, Function<WebTarget, WebTarget> decorateWebTarget) {
    CertificateTrustManager.SavingX509TrustManager x509TrustManager = new CertificateTrustManager.SavingX509TrustManager();
    TrustManager[] trustManagers = { x509TrustManager };
    SSLContext sslContext = SslConfigurator.newInstance().createSSLContext();
    try {
        sslContext.init(null, trustManagers, new SecureRandom());
    } catch (KeyManagementException e) {
        throw new TestFailException("Cannot init SSL Context: " + e.getMessage(), e);
    }
    Client client = RestClientUtil.createClient(sslContext, true);
    WebTarget target = client.target(getUrl());
    target = decorateWebTarget.apply(target.path(path));
    return target;
}
Also used : TestFailException(com.sequenceiq.it.cloudbreak.exception.TestFailException) CertificateTrustManager(com.sequenceiq.cloudbreak.client.CertificateTrustManager) SecureRandom(java.security.SecureRandom) SSLContext(javax.net.ssl.SSLContext) WebTarget(javax.ws.rs.client.WebTarget) Client(javax.ws.rs.client.Client) KeyManagementException(java.security.KeyManagementException) TrustManager(javax.net.ssl.TrustManager) CertificateTrustManager(com.sequenceiq.cloudbreak.client.CertificateTrustManager)

Example 99 with TestFailException

use of com.sequenceiq.it.cloudbreak.exception.TestFailException in project cloudbreak by hortonworks.

the class SshJClientActions method checkFilesByNameAndPath.

public <T extends AbstractSdxTestDto> T checkFilesByNameAndPath(T testDto, List<InstanceGroupV4Response> instanceGroups, List<String> hostGroupNames, String filePath, String fileName, long requiredNumberOfFiles, String user, String password) {
    String fileListCommand = String.format("find %s -type f -name %s", filePath, fileName);
    AtomicLong quantity = new AtomicLong(0);
    String appendMessage;
    if (StringUtils.isBlank(user) && StringUtils.isBlank(password)) {
        appendMessage = String.format("with 'cloudbreak' user and defaultPrivateKeyFile from 'application.yml'");
    } else if (StringUtils.isNotBlank(user) && StringUtils.isNotBlank(password)) {
        appendMessage = String.format("with user: '%s' and password: '%s' and defaultPrivateKeyFile from 'application.yml'", user, password);
    } else {
        LOGGER.error("Creating SSH client is not possible, because of one of the required parameter is missing: \nuser: '{}' \npassword: '{}'", user, password);
        throw new TestFailException(String.format("Creating SSH client is not possible, because of one of the required parameter is missing: " + "%nuser: '%s' %npassword: '%s'", user, password));
    }
    /**
     * Right now only the Private IP is available for an Instance.
     */
    getSdxInstanceGroupIps(instanceGroups, hostGroupNames, false).forEach(instanceIP -> {
        LOGGER.info("Creating SSH client on '{}' host " + appendMessage, instanceIP);
        try (SSHClient client = createSshClient(instanceIP, user, password, null)) {
            quantity.set(executefileListCommand(instanceIP, fileListCommand, client));
        } catch (Exception e) {
            LOGGER.error("Create SSH client is failing on '{}' host " + appendMessage + ", because of: {}", instanceIP, e.getMessage());
            throw new TestFailException(String.format(" Create SSH client is failing on '%s' host " + appendMessage, instanceIP), e);
        }
    });
    if (requiredNumberOfFiles == quantity.get()) {
        Log.log(LOGGER, " File '%s' is available at [%s] host group(s). ", filePath, hostGroupNames.toString());
    } else {
        LOGGER.error("File '{}' is NOT available at [{}] host group(s)!", filePath, hostGroupNames.toString());
        throw new TestFailException(String.format("File '%s' is NOT available at [%s] host group(s)!", filePath, hostGroupNames.toString()));
    }
    return testDto;
}
Also used : AtomicLong(java.util.concurrent.atomic.AtomicLong) TestFailException(com.sequenceiq.it.cloudbreak.exception.TestFailException) SSHClient(net.schmizz.sshj.SSHClient) TestFailException(com.sequenceiq.it.cloudbreak.exception.TestFailException)

Example 100 with TestFailException

use of com.sequenceiq.it.cloudbreak.exception.TestFailException in project cloudbreak by hortonworks.

the class SshJClientActions method executefileListCommand.

private long executefileListCommand(String instanceIP, String fileListCommand, SSHClient sshClient) {
    AtomicLong quantity = new AtomicLong(0);
    try {
        Pair<Integer, String> cmdOut = execute(sshClient, fileListCommand);
        Log.log(LOGGER, " Command exit status '%s' and result '%s'. ", cmdOut.getKey(), cmdOut.getValue());
        List<String> cmdOutputValues = Stream.of(cmdOut.getValue().split("[\\r\\n\\t]")).filter(Objects::nonNull).collect(Collectors.toList());
        boolean fileFound = cmdOutputValues.stream().anyMatch(outputValue -> outputValue.strip().startsWith("/"));
        String foundFilePath = cmdOutputValues.stream().filter(outputValue -> outputValue.strip().startsWith("/")).findFirst().orElse(null);
        Log.log(LOGGER, format(" The file is present '%s' at '%s' path. ", fileFound, foundFilePath));
        quantity.set(cmdOutputValues.stream().filter(outputValue -> outputValue.strip().startsWith("/")).count());
    } catch (Exception e) {
        LOGGER.error("SSH fail on '{}' host while running command: [{}]", instanceIP, fileListCommand);
        throw new TestFailException(String.format(" SSH fail on '%s' host while running command: [%s]! ", instanceIP, fileListCommand), e);
    }
    return quantity.get();
}
Also used : AtomicLong(java.util.concurrent.atomic.AtomicLong) TestFailException(com.sequenceiq.it.cloudbreak.exception.TestFailException) TestFailException(com.sequenceiq.it.cloudbreak.exception.TestFailException)

Aggregations

TestFailException (com.sequenceiq.it.cloudbreak.exception.TestFailException)101 List (java.util.List)15 Inject (javax.inject.Inject)14 Map (java.util.Map)13 Description (com.sequenceiq.it.cloudbreak.context.Description)12 TestContext (com.sequenceiq.it.cloudbreak.context.TestContext)12 Logger (org.slf4j.Logger)12 LoggerFactory (org.slf4j.LoggerFactory)12 Test (org.testng.annotations.Test)12 DistroXTestDto (com.sequenceiq.it.cloudbreak.dto.distrox.DistroXTestDto)10 WebApplicationException (javax.ws.rs.WebApplicationException)10 Log (com.sequenceiq.it.cloudbreak.log.Log)9 String.format (java.lang.String.format)9 Collectors (java.util.stream.Collectors)9 FreeIpaTestDto (com.sequenceiq.it.cloudbreak.dto.freeipa.FreeIpaTestDto)8 SdxTestDto (com.sequenceiq.it.cloudbreak.dto.sdx.SdxTestDto)8 IOException (java.io.IOException)8 URISyntaxException (java.net.URISyntaxException)8 ArrayList (java.util.ArrayList)8 Set (java.util.Set)8