Search in sources :

Example 61 with TestFailException

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;
}
Also used : UmsVirtualGroupRight(com.sequenceiq.cloudbreak.auth.altus.UmsVirtualGroupRight) EnvironmentTestDto(com.sequenceiq.it.cloudbreak.dto.environment.EnvironmentTestDto) HashMap(java.util.HashMap) StatusRuntimeException(io.grpc.StatusRuntimeException) TestFailException(com.sequenceiq.it.cloudbreak.exception.TestFailException)

Example 62 with TestFailException

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);
        }
    }
}
Also used : EC2UnexpectedException(com.amazonaws.services.lambda.model.EC2UnexpectedException) EbsInstanceBlockDevice(com.amazonaws.services.ec2.model.EbsInstanceBlockDevice) StopInstancesResult(com.amazonaws.services.ec2.model.StopInstancesResult) WaiterParameters(com.amazonaws.waiters.WaiterParameters) LoggerFactory(org.slf4j.LoggerFactory) TerminateInstancesResult(com.amazonaws.services.ec2.model.TerminateInstancesResult) BooleanUtils(org.apache.commons.lang3.BooleanUtils) StopInstancesRequest(com.amazonaws.services.ec2.model.StopInstancesRequest) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) EC2Client(com.sequenceiq.it.cloudbreak.util.aws.amazonec2.client.EC2Client) InstanceBlockDeviceMapping(com.amazonaws.services.ec2.model.InstanceBlockDeviceMapping) TestFailException(com.sequenceiq.it.cloudbreak.exception.TestFailException) DescribeInstancesRequest(com.amazonaws.services.ec2.model.DescribeInstancesRequest) Map(java.util.Map) AmazonEC2(com.amazonaws.services.ec2.AmazonEC2) DescribeVolumesRequest(com.amazonaws.services.ec2.model.DescribeVolumesRequest) Volume(com.amazonaws.services.ec2.model.Volume) InstanceState(com.amazonaws.services.ec2.model.InstanceState) Instance(com.amazonaws.services.ec2.model.Instance) WaiterUnrecoverableException(com.amazonaws.waiters.WaiterUnrecoverableException) SdxUtil(com.sequenceiq.it.cloudbreak.util.SdxUtil) Reservation(com.amazonaws.services.ec2.model.Reservation) FixedDelayStrategy(com.amazonaws.waiters.FixedDelayStrategy) Logger(org.slf4j.Logger) Collection(java.util.Collection) DescribeVolumesResult(com.amazonaws.services.ec2.model.DescribeVolumesResult) Log(com.sequenceiq.it.cloudbreak.log.Log) Set(java.util.Set) DescribeInstancesResult(com.amazonaws.services.ec2.model.DescribeInstancesResult) WaiterTimedOutException(com.amazonaws.waiters.WaiterTimedOutException) TerminateInstancesRequest(com.amazonaws.services.ec2.model.TerminateInstancesRequest) Collectors(java.util.stream.Collectors) String.format(java.lang.String.format) Objects(java.util.Objects) MaxAttemptsRetryStrategy(com.amazonaws.waiters.MaxAttemptsRetryStrategy) List(java.util.List) Component(org.springframework.stereotype.Component) PollingStrategy(com.amazonaws.waiters.PollingStrategy) Tag(com.amazonaws.services.ec2.model.Tag) EC2UnexpectedException(com.amazonaws.services.lambda.model.EC2UnexpectedException) WaiterTimedOutException(com.amazonaws.waiters.WaiterTimedOutException) MaxAttemptsRetryStrategy(com.amazonaws.waiters.MaxAttemptsRetryStrategy) WaiterUnrecoverableException(com.amazonaws.waiters.WaiterUnrecoverableException) AmazonEC2(com.amazonaws.services.ec2.AmazonEC2) DescribeInstancesRequest(com.amazonaws.services.ec2.model.DescribeInstancesRequest) TerminateInstancesRequest(com.amazonaws.services.ec2.model.TerminateInstancesRequest) WaiterParameters(com.amazonaws.waiters.WaiterParameters) DescribeInstancesResult(com.amazonaws.services.ec2.model.DescribeInstancesResult) InstanceState(com.amazonaws.services.ec2.model.InstanceState) PollingStrategy(com.amazonaws.waiters.PollingStrategy) TestFailException(com.sequenceiq.it.cloudbreak.exception.TestFailException) TerminateInstancesResult(com.amazonaws.services.ec2.model.TerminateInstancesResult) FixedDelayStrategy(com.amazonaws.waiters.FixedDelayStrategy)

Example 63 with TestFailException

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;
}
Also used : TestFailException(com.sequenceiq.it.cloudbreak.exception.TestFailException)

Example 64 with TestFailException

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);
    }
}
Also used : TestFailException(com.sequenceiq.it.cloudbreak.exception.TestFailException)

Example 65 with TestFailException

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);
    }
}
Also used : 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