use of com.sequenceiq.it.cloudbreak.exception.TestFailException in project cloudbreak by hortonworks.
the class GcpClientActions method listBucketSelectedObject.
public void listBucketSelectedObject(String baseLocation, boolean zeroContent) {
Storage storage = buildStorage();
URI baseLocationUri = getBaseLocationUri(baseLocation);
String bucketName = baseLocationUri.getHost();
String selectedObjectPath = baseLocationUri.getPath();
String keyPrefix = Arrays.stream(StringUtils.split(selectedObjectPath, "/")).filter(StringUtils::isNotEmpty).collect(Collectors.toList()).get(0);
List<StorageObject> filteredObjects;
Log.log(LOGGER, format(" Google GCS Bucket: %s", bucketName));
Log.log(LOGGER, format(" Google GCS Key Prefix: %s", keyPrefix));
Log.log(LOGGER, format(" Google GCS Object: %s", selectedObjectPath));
try {
Storage.Objects.List listObjectsOperation = storage.objects().list(bucketName).setPrefix(keyPrefix);
Objects storageObjects;
do {
storageObjects = listObjectsOperation.execute();
if (storageObjects == null || storageObjects.getItems() == null) {
LOGGER.error("Google GCS path: '{}' does not exist!", keyPrefix);
throw new TestFailException(String.format(" Google GCS path: '%s' does not exist! ", keyPrefix));
}
filteredObjects = storageObjects.getItems().stream().filter(storageObject -> {
try {
URI selfLink = new URI(storageObject.getSelfLink());
return selfLink.getPath().contains(selectedObjectPath);
} catch (URISyntaxException e) {
LOGGER.error("Google GCS object: '{}' path: '{}' is not a valid URI!", storageObject.getName(), storageObject.getSelfLink());
throw new TestFailException(String.format(" Google GCS object: '%s' path: '%s' is not a valid URI!", storageObject.getName(), storageObject.getSelfLink()));
}
}).collect(Collectors.toList());
listObjectsOperation.setPageToken(storageObjects.getNextPageToken());
} while (StringUtils.isNotEmpty(storageObjects.getNextPageToken()));
Log.log(LOGGER, format(" Google GCS object: '%s' contains '%d' sub-objects.", selectedObjectPath, filteredObjects.size()));
for (StorageObject objectSummary : filteredObjects.stream().limit(10).collect(Collectors.toList())) {
if (objectSummary.getSize().compareTo(BigInteger.ZERO) == 0 && !zeroContent) {
LOGGER.error("Google GCS path: '{}' has 0 bytes of content!", selectedObjectPath);
throw new TestFailException(String.format(" Google GCS path: '%s' has 0 bytes of content! ", selectedObjectPath));
}
}
} catch (Exception e) {
String msg = String.format("Failed to list bucket object '%s' from base location '%s'", bucketName, baseLocationUri);
LOGGER.error(msg, e);
throw new TestFailException(msg, e);
}
}
use of com.sequenceiq.it.cloudbreak.exception.TestFailException in project cloudbreak by hortonworks.
the class GcpClientActions method getLoggingUrl.
public String getLoggingUrl(String baseLocation, String clusterLogPath) {
Storage storage = buildStorage();
URI baseLocationUri = getBaseLocationUri(baseLocation);
String bucketName = baseLocationUri.getHost();
String keyPrefix = Arrays.stream(StringUtils.split(baseLocationUri.getPath(), "/")).filter(StringUtils::isNotEmpty).collect(Collectors.toList()).get(0);
Log.log(LOGGER, format(" Google GCS URI: %s", baseLocationUri));
Log.log(LOGGER, format(" Google GCS Bucket: %s", bucketName));
Log.log(LOGGER, format(" Google GCS Key Prefix: %s", keyPrefix));
Log.log(LOGGER, format(" Google GCS Cluster Logs: %s", clusterLogPath));
try {
Storage.Objects.List listObjectsOperation = storage.objects().list(bucketName).setPrefix(keyPrefix);
Objects storageObjects = listObjectsOperation.execute();
if (!storageObjects.isEmpty()) {
return String.format("https://console.cloud.google.com/storage/browser/%s/%s%s?project=gcp-dev-cloudbreak", bucketName, keyPrefix, clusterLogPath);
} else {
LOGGER.error("Google GCS path: '{}' does not exist!", baseLocationUri);
throw new TestFailException(String.format(" Google GCS path: '%s' does not exist! ", baseLocationUri));
}
} catch (Exception e) {
String msg = String.format("Google GCS bucket '%s' is NOT present!", bucketName);
LOGGER.error(msg, e);
throw new TestFailException(msg, e);
}
}
use of com.sequenceiq.it.cloudbreak.exception.TestFailException in project cloudbreak by hortonworks.
the class EC2ClientActions method stopHostGroupInstances.
public void stopHostGroupInstances(List<String> instanceIds) {
AmazonEC2 ec2Client = buildEC2Client();
StopInstancesResult stopInstancesResult = ec2Client.stopInstances(new StopInstancesRequest().withInstanceIds(instanceIds));
for (String instanceId : instanceIds) {
try {
Log.log(LOGGER, format(" EC2 instance [%s] state is [%s] ", instanceId, Objects.requireNonNull(stopInstancesResult.getStoppingInstances().stream().filter(instance -> instance.getInstanceId().equals(instanceId)).findAny().orElse(null)).getCurrentState().getName()));
ec2Client.waiters().instanceStopped().run(new WaiterParameters<DescribeInstancesRequest>(new DescribeInstancesRequest().withInstanceIds(instanceId)).withPollingStrategy(new PollingStrategy(new MaxAttemptsRetryStrategy(80), new FixedDelayStrategy(30))));
DescribeInstancesResult describeInstanceResult = ec2Client.describeInstances(new DescribeInstancesRequest().withInstanceIds(instanceId));
InstanceState actualInstanceState = describeInstanceResult.getReservations().get(0).getInstances().get(0).getState();
if (STOPPED_STATE.equals(actualInstanceState.getName())) {
Log.log(LOGGER, format(" EC2 Instance: %s state is: %s ", instanceId, STOPPED_STATE));
} else {
LOGGER.error("EC2 Instance: {} stop has not been successful. So the actual state is: {} ", instanceId, actualInstanceState.getName());
throw new TestFailException(" EC2 Instance: " + instanceId + " stop has not been successful, because of the actual state is: " + actualInstanceState.getName());
}
} catch (WaiterUnrecoverableException e) {
LOGGER.error("EC2 Instance {} stop has not been successful, because of WaiterUnrecoverableException: {}", instanceId, e);
} catch (WaiterTimedOutException e) {
LOGGER.error("EC2 Instance {} stop has not been successful, because of WaiterTimedOutException: {}", instanceId, e);
} catch (EC2UnexpectedException e) {
LOGGER.error("EC2 Instance {} stop has not been successful, because of EC2UnexpectedException: {}", instanceId, e);
}
}
}
use of com.sequenceiq.it.cloudbreak.exception.TestFailException in project cloudbreak by hortonworks.
the class TagsUtil method verifyTags.
public void verifyTags(TaggedResponse response, TestContext testContext) {
SoftAssert softAssert = new SoftAssert();
try {
validateTestNameTag(getTagValueFromResponse(response, TEST_NAME_TAG), TEST_NAME_TAG, testContext);
DEFAULT_TAGS.forEach(tagKey -> {
String tagValue = getTagValueFromResponse(response, tagKey);
if (tagKey.equalsIgnoreCase("owner")) {
validateOwnerTag(tagValue, tagKey, testContext);
} else if (tagKey.equalsIgnoreCase("Cloudera-Creator-Resource-Name")) {
validateClouderaCreatorResourceNameTag(tagValue, tagKey, testContext);
} else {
if (StringUtils.isNotBlank(tagValue)) {
Log.log(LOGGER, format(" PASSED:: Default tag: [%s] value: [%s] is present! ", tagKey, tagValue));
}
softAssert.assertNotNull(tagValue, format(MISSING_DEFAULT_TAG, tagKey));
}
});
softAssert.assertAll();
} catch (NullPointerException e) {
LOGGER.error("Tag validation is not possible, because of response: {} throws: {}!", response, e.getMessage(), e);
throw new TestFailException(format(" Tag validation is not possible, because of response: %s", response), e);
}
}
use of com.sequenceiq.it.cloudbreak.exception.TestFailException in project cloudbreak by hortonworks.
the class ResourceCreator method createDefaultBlueprintInternal.
public BlueprintTestDto createDefaultBlueprintInternal(TestContext testContext, String accountId, String runtimeVersion) {
try {
String bluepint = ResourceUtil.readResourceAsString(testContext.getApplicationContext(), "classpath:/blueprint/clouderamanager.bp").replaceAll("CDH_RUNTIME", runtimeVersion);
BlueprintTestDto testDto = testContext.given(BlueprintTestDto.class).withAccountId(accountId).withBlueprint(bluepint).when(blueprintTestClient.createInternalV4());
testDto.validate();
return testDto;
} catch (IOException e) {
throw new TestFailException(e.getMessage());
}
}
Aggregations