use of com.sequenceiq.it.cloudbreak.exception.TestFailException in project cloudbreak by hortonworks.
the class EnvironmentUtil method getEnvironmentVirtualGroups.
public Map<UmsVirtualGroupRight, String> getEnvironmentVirtualGroups(TestContext testContext, UmsClient client) {
String accountId = testContext.getActingUserCrn().getAccountId();
String environmentCrn = testContext.given(EnvironmentTestDto.class).getCrn();
Map<UmsVirtualGroupRight, String> virtualGroups = new HashMap<>();
String virtualGroup = null;
for (UmsVirtualGroupRight right : UmsVirtualGroupRight.values()) {
try {
virtualGroup = client.getDefaultClient().getWorkloadAdministrationGroupName(accountId, MDCUtils.getRequestId(), right, environmentCrn, regionAwareInternalCrnGeneratorFactory);
} catch (StatusRuntimeException ex) {
if (Status.Code.NOT_FOUND != ex.getStatus().getCode()) {
LOGGER.info(format(" Virtual groups are missing for right: '%s' ", right.getRight()));
}
}
if (StringUtils.hasText(virtualGroup)) {
virtualGroups.put(right, virtualGroup);
}
}
if (MapUtils.isNotEmpty(virtualGroups)) {
Log.then(LOGGER, format(" Virtual groups are present [%s] for environment '%s' ", virtualGroups, environmentCrn));
LOGGER.info(String.format(" Virtual groups are present [%s] for environment '%s' ", virtualGroups, environmentCrn));
} else {
throw new TestFailException(String.format(" Cannot find virtual groups for environment '%s' ", environmentCrn));
}
return virtualGroups;
}
use of com.sequenceiq.it.cloudbreak.exception.TestFailException in project cloudbreak by hortonworks.
the class EC2ClientActions method deleteHostGroupInstances.
public void deleteHostGroupInstances(List<String> instanceIds) {
AmazonEC2 ec2Client = buildEC2Client();
TerminateInstancesResult terminateInstancesResult = ec2Client.terminateInstances(new TerminateInstancesRequest().withInstanceIds(instanceIds));
for (String instanceId : instanceIds) {
try {
Log.log(LOGGER, format(" EC2 instance [%s] state is [%s] ", instanceId, Objects.requireNonNull(terminateInstancesResult.getTerminatingInstances().stream().filter(instance -> instance.getInstanceId().equals(instanceId)).findAny().orElse(null)).getCurrentState().getName()));
ec2Client.waiters().instanceTerminated().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 (TERMINATED_STATE.equals(actualInstanceState.getName())) {
Log.log(LOGGER, format(" EC2 Instance: %s state is: %s ", instanceId, TERMINATED_STATE));
} else {
LOGGER.error("EC2 Instance: {} termination has not been successful. So the actual state is: {} ", instanceId, actualInstanceState.getName());
throw new TestFailException(" EC2 Instance: " + instanceId + " termination has not been successful, because of the actual state is: " + actualInstanceState.getName());
}
} catch (WaiterUnrecoverableException e) {
LOGGER.error("EC2 Instance {} termination has not been successful, because of WaiterUnrecoverableException: {}", instanceId, e);
} catch (WaiterTimedOutException e) {
LOGGER.error("EC2 Instance {} termination has not been successful, because of WaiterTimedOutException: {}", instanceId, e);
} catch (EC2UnexpectedException e) {
LOGGER.error("EC2 Instance {} termination has not been successful, because of EC2UnexpectedException: {}", instanceId, e);
}
}
}
use of com.sequenceiq.it.cloudbreak.exception.TestFailException in project cloudbreak by hortonworks.
the class SimpleRetryWrapper method run.
private T run() {
LOGGER.info("Trying [{}] action {} times, waiting {} seconds between.", name, retryTimes, retryWaitSeconds);
T result = null;
for (int timesTried = 1; timesTried <= retryTimes; timesTried++) {
try {
result = action.get();
LOGGER.info("[{}] action was successful on try {}.", name, timesTried);
break;
} catch (RuntimeException e) {
if (timesTried < retryTimes) {
LOGGER.warn("[{}] action failed on try {}, retrying after {} seconds.", name, timesTried, retryWaitSeconds, e);
try {
TimeUnit.SECONDS.sleep(retryWaitSeconds);
} catch (InterruptedException ignored) {
LOGGER.warn("[{}] action {} retry has been interrupted, because of: {}", action, timesTried, ignored.getMessage(), ignored);
}
} else {
LOGGER.error("Failed to run [{}] action {} times.", name, retryTimes, e);
throw new TestFailException(String.format("Failed to run [%s] action %d times.", name, retryTimes), e);
}
}
}
return result;
}
use of com.sequenceiq.it.cloudbreak.exception.TestFailException in project cloudbreak by hortonworks.
the class TagsUtil method validateOwnerTag.
private void validateOwnerTag(String tagValue, String tagKey, TestContext testContext) {
String actingUserName = testContext.getActingUserName();
if (StringUtils.isNotBlank(tagValue)) {
if (tagValue.equals(actingUserName) || tagValue.equals(sanitize(actingUserName))) {
Log.log(LOGGER, format(" PASSED:: Default tag: [%s] value: [%s] equals [%s] acting user name! ", tagKey, tagValue, actingUserName));
} else if (gcpLabelTransformedValue(tagValue, actingUserName)) {
Log.log(LOGGER, format(" PASSED:: Default tag: [%s] value: [%s] equals [%s] acting user name transformed to a GCP label value! ", tagKey, tagValue, actingUserName));
} else {
String message = format(ACTING_USER_NAME_VALUE_FAILURE_PATTERN, tagKey, tagValue, actingUserName);
LOGGER.error(message);
throw new TestFailException(message);
}
} else {
String message = format(TAG_VALUE_IS_NULL_FAILURE_PATTERN, tagKey);
LOGGER.error(message);
throw new TestFailException(message);
}
}
use of com.sequenceiq.it.cloudbreak.exception.TestFailException in project cloudbreak by hortonworks.
the class TagsUtil method validateTestNameTag.
private void validateTestNameTag(String tagValue, String tagKey, TestContext testContext) {
String testName = testContext.getTestMethodName().orElseThrow(() -> new TestFailException("Test method name cannot be found for tag validation!"));
if (StringUtils.isNotBlank(tagValue)) {
testName = applyLengthRestrictions(testContext.getCloudPlatform(), testName);
if (tagValue.equalsIgnoreCase(testName)) {
Log.log(LOGGER, format(" PASSED:: [%s] tag value: [%s] equals [%s] test method name! ", tagKey, tagValue, testName));
} else {
String message = format(TEST_NAME_TAG_VALUE_FAILURE_PATTERN, tagKey, tagValue, testName);
LOGGER.error(message);
throw new TestFailException(message);
}
} else {
String message = format(TAG_VALUE_IS_NULL_FAILURE_PATTERN, tagKey);
LOGGER.error(message);
throw new TestFailException(message);
}
}
Aggregations