Search in sources :

Example 21 with TestFailException

use of com.sequenceiq.it.cloudbreak.exception.TestFailException in project cloudbreak by hortonworks.

the class CloudbreakUserCache method getUserByDisplayName.

public CloudbreakUser getUserByDisplayName(String name) {
    if (MapUtils.isEmpty(usersByAccount)) {
        initRealUmsUserCache();
    }
    if (isInitialized()) {
        CloudbreakUser user = usersByAccount.values().stream().flatMap(Collection::stream).filter(u -> u.getDisplayName().equals(name)).findFirst().orElseThrow(() -> new TestFailException(String.format("There is no real UMS user with::%n name: %s%n deployment: %s%n account: %s%n", name, realUmsUserDeployment, realUmsUserAccount)));
        LOGGER.info(" Real UMS user has been found:: \nDisplay name: {} \nCrn: {} \nAccess key: {} \nSecret key: {} \nAdmin: {} ", user.getDisplayName(), user.getCrn(), user.getAccessKey(), user.getSecretKey(), user.getAdmin());
        return user;
    } else {
        throw new TestFailException("Cannot get real UMS user by name, because of 'ums-users/api-credentials.json' is not available.");
    }
}
Also used : TestFailException(com.sequenceiq.it.cloudbreak.exception.TestFailException)

Example 22 with TestFailException

use of com.sequenceiq.it.cloudbreak.exception.TestFailException in project cloudbreak by hortonworks.

the class S3ClientActions method deleteNonVersionedBucket.

public void deleteNonVersionedBucket(String baseLocation) {
    AmazonS3 s3Client = buildS3Client();
    String bucketName = getBucketName();
    String prefix = StringUtils.substringAfterLast(baseLocation, "/");
    if (s3Client.doesBucketExistV2(bucketName)) {
        try {
            ListObjectsRequest listObjectsRequest = new ListObjectsRequest().withBucketName(bucketName).withPrefix(prefix);
            ObjectListing objectListing = s3Client.listObjects(listObjectsRequest);
            do {
                List<DeleteObjectsRequest.KeyVersion> deletableObjects = Lists.newArrayList();
                for (S3ObjectSummary objectSummary : objectListing.getObjectSummaries()) {
                    deletableObjects.add(new DeleteObjectsRequest.KeyVersion(objectSummary.getKey()));
                }
                DeleteObjectsRequest deleteObjectsRequest = new DeleteObjectsRequest(bucketName);
                deleteObjectsRequest.setKeys(deletableObjects);
                s3Client.deleteObjects(deleteObjectsRequest);
                if (objectListing.isTruncated()) {
                    objectListing = s3Client.listNextBatchOfObjects(objectListing);
                }
            } while (objectListing.isTruncated());
        } catch (AmazonServiceException e) {
            LOGGER.error("Amazon S3 couldn't process the call. So it has been returned with error!", e);
            throw new TestFailException("Amazon S3 couldn't process the call.", e);
        } catch (SdkClientException e) {
            LOGGER.error("Amazon S3 response could not been parsed, because of error!", e);
            throw new TestFailException("Amazon S3 response could not been parsed", e);
        } finally {
            s3Client.shutdown();
        }
    } else {
        LOGGER.error("Amazon S3 bucket is not present with name: {}", bucketName);
        throw new TestFailException("Amazon S3 bucket is not present with name: " + bucketName);
    }
}
Also used : AmazonS3(com.amazonaws.services.s3.AmazonS3) ListObjectsRequest(com.amazonaws.services.s3.model.ListObjectsRequest) SdkClientException(com.amazonaws.SdkClientException) AmazonServiceException(com.amazonaws.AmazonServiceException) TestFailException(com.sequenceiq.it.cloudbreak.exception.TestFailException) ObjectListing(com.amazonaws.services.s3.model.ObjectListing) S3ObjectSummary(com.amazonaws.services.s3.model.S3ObjectSummary) DeleteObjectsRequest(com.amazonaws.services.s3.model.DeleteObjectsRequest)

Example 23 with TestFailException

use of com.sequenceiq.it.cloudbreak.exception.TestFailException in project cloudbreak by hortonworks.

the class AzureCloudBlobClientActions method deleteAllFolders.

public SdxTestDto deleteAllFolders(TestContext testContext, SdxTestDto sdxTestDto, SdxClient sdxClient) {
    String containerName = getContainerName(sdxTestDto.getRequest().getCloudStorage().getBaseLocation());
    CloudBlobContainer cloudBlobContainer = getCloudBlobContainer(containerName);
    try {
        for (ListBlobItem blob : cloudBlobContainer.listBlobs()) {
            String blobName = blob.getUri().getPath().split("/", 3)[2];
            String blobUriPath = blob.getUri().getPath();
            if (blob instanceof CloudBlob) {
                ((CloudBlob) blob).deleteIfExists();
            } else {
                if (blobName.endsWith("/")) {
                    blobName = blobName.replaceAll(".$", "");
                }
                CloudBlobDirectory blobDirectory = cloudBlobContainer.getDirectoryReference(blobName);
                deleteBlobsInDirectory(blobDirectory);
            }
        }
    } catch (StorageException | URISyntaxException e) {
        LOGGER.error("Azure Adls Gen 2 Blob couldn't process the call. So it has been returned with error!", e);
        throw new TestFailException("Azure Adls Gen 2 Blob couldn't process the call.", e);
    }
    return sdxTestDto;
}
Also used : CloudBlob(com.microsoft.azure.storage.blob.CloudBlob) ListBlobItem(com.microsoft.azure.storage.blob.ListBlobItem) CloudBlobDirectory(com.microsoft.azure.storage.blob.CloudBlobDirectory) TestFailException(com.sequenceiq.it.cloudbreak.exception.TestFailException) CloudBlobContainer(com.microsoft.azure.storage.blob.CloudBlobContainer) URISyntaxException(java.net.URISyntaxException) StorageException(com.microsoft.azure.storage.StorageException)

Example 24 with TestFailException

use of com.sequenceiq.it.cloudbreak.exception.TestFailException in project cloudbreak by hortonworks.

the class AzureCloudBlobClientActions method getLoggingUrl.

public String getLoggingUrl(String baseLocation, String clusterLogPath) {
    String containerName = getContainerName(baseLocation);
    CloudBlobContainer cloudBlobContainer = getCloudBlobContainer(containerName);
    String keyPrefix = StringUtils.substringAfterLast(baseLocation, "/");
    Log.log(LOGGER, format(" Azure Blob Storage URI: %s", cloudBlobContainer.getStorageUri()));
    Log.log(LOGGER, format(" Azure Blob Container: %s", cloudBlobContainer.getName()));
    Log.log(LOGGER, format(" Azure Blob Key Prefix: %s", keyPrefix));
    Log.log(LOGGER, format(" Azure Blob Cluster Logs: %s", clusterLogPath));
    try {
        CloudBlobDirectory storageDirectory = cloudBlobContainer.getDirectoryReference(keyPrefix);
        CloudBlobDirectory logsDirectory = storageDirectory.getDirectoryReference(clusterLogPath);
        if (logsDirectory.listBlobs().iterator().hasNext()) {
            return String.format("https://autotestingapi.blob.core.windows.net/%s/%s%s", containerName, keyPrefix, clusterLogPath);
        } else {
            LOGGER.error("Azure Adls Gen 2 Blob is NOT present at '{}' container in '{}' storage directory with path: [{}]", containerName, keyPrefix, clusterLogPath);
            throw new TestFailException(format("Azure Adls Gen 2 Blob is NOT present at '%s' container in '%s' storage directory with path: [%s]", containerName, keyPrefix, clusterLogPath));
        }
    } catch (StorageException | URISyntaxException e) {
        LOGGER.error("Azure Adls Gen 2 Blob couldn't process the call. So it has been returned with error!", e);
        throw new TestFailException("Azure Adls Gen 2 Blob couldn't process the call.", e);
    }
}
Also used : CloudBlobDirectory(com.microsoft.azure.storage.blob.CloudBlobDirectory) TestFailException(com.sequenceiq.it.cloudbreak.exception.TestFailException) CloudBlobContainer(com.microsoft.azure.storage.blob.CloudBlobContainer) URISyntaxException(java.net.URISyntaxException) StorageException(com.microsoft.azure.storage.StorageException)

Example 25 with TestFailException

use of com.sequenceiq.it.cloudbreak.exception.TestFailException in project cloudbreak by hortonworks.

the class AzureClientActions method createResourceGroup.

public ResourceGroup createResourceGroup(String resourceGroupName, Map<String, String> tags) {
    if (StringUtils.isNotBlank(resourceGroupName)) {
        LOGGER.info(format("Creating resource group '%s'...", resourceGroupName));
        Map<String, String> allTags = new HashMap<>();
        allTags.putAll(tags);
        allTags.putAll(commonCloudProperties.getTags());
        ResourceGroup resourceGroup;
        resourceGroup = azure.resourceGroups().define(resourceGroupName).withRegion(azureProperties.getRegion()).withTags(allTags).create();
        if (resourceGroup.provisioningState().equalsIgnoreCase("Succeeded")) {
            LOGGER.info(format("New resource group '%s' has been created.", resourceGroupName));
            Log.then(LOGGER, format(" New resource group '%s' has been created. ", resourceGroupName));
            return resourceGroup;
        } else {
            LOGGER.error("Failed to provision the resource group '{}'!", resourceGroupName);
            throw new TestFailException(format("Failed to provision the resource group '%s'!", resourceGroupName));
        }
    } else {
        LOGGER.error("Resource group name has not been provided! So create new resource group for environment is not possible.");
        throw new TestFailException("Resource group name has not been provided! So create new resource group for environment is not possible.");
    }
}
Also used : HashMap(java.util.HashMap) TestFailException(com.sequenceiq.it.cloudbreak.exception.TestFailException) ResourceGroup(com.microsoft.azure.management.resources.ResourceGroup)

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