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