Search in sources :

Example 31 with TestFailException

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);
    }
}
Also used : Storage(com.google.api.services.storage.Storage) StorageObject(com.google.api.services.storage.model.StorageObject) StringUtils(org.apache.commons.lang3.StringUtils) Objects(com.google.api.services.storage.model.Objects) TestFailException(com.sequenceiq.it.cloudbreak.exception.TestFailException) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) URISyntaxException(java.net.URISyntaxException) GoogleJsonResponseException(com.google.api.client.googleapis.json.GoogleJsonResponseException) TestFailException(com.sequenceiq.it.cloudbreak.exception.TestFailException) IOException(java.io.IOException)

Example 32 with TestFailException

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);
    }
}
Also used : Storage(com.google.api.services.storage.Storage) StringUtils(org.apache.commons.lang3.StringUtils) Objects(com.google.api.services.storage.model.Objects) TestFailException(com.sequenceiq.it.cloudbreak.exception.TestFailException) URI(java.net.URI) URISyntaxException(java.net.URISyntaxException) GoogleJsonResponseException(com.google.api.client.googleapis.json.GoogleJsonResponseException) TestFailException(com.sequenceiq.it.cloudbreak.exception.TestFailException) IOException(java.io.IOException)

Example 33 with TestFailException

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);
        }
    }
}
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) WaiterParameters(com.amazonaws.waiters.WaiterParameters) DescribeInstancesResult(com.amazonaws.services.ec2.model.DescribeInstancesResult) InstanceState(com.amazonaws.services.ec2.model.InstanceState) PollingStrategy(com.amazonaws.waiters.PollingStrategy) StopInstancesResult(com.amazonaws.services.ec2.model.StopInstancesResult) TestFailException(com.sequenceiq.it.cloudbreak.exception.TestFailException) StopInstancesRequest(com.amazonaws.services.ec2.model.StopInstancesRequest) FixedDelayStrategy(com.amazonaws.waiters.FixedDelayStrategy)

Example 34 with TestFailException

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

Example 35 with TestFailException

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());
    }
}
Also used : BlueprintTestDto(com.sequenceiq.it.cloudbreak.dto.blueprint.BlueprintTestDto) TestFailException(com.sequenceiq.it.cloudbreak.exception.TestFailException) IOException(java.io.IOException)

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