Search in sources :

Example 81 with TestFailException

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

the class GcpCloudProvider method getPreviousPreWarmedImageID.

@Override
public String getPreviousPreWarmedImageID(TestContext testContext, ImageCatalogTestDto imageCatalogTestDto, CloudbreakClient cloudbreakClient) {
    if (gcpProperties.getBaseimage().getImageId() == null || gcpProperties.getBaseimage().getImageId().isEmpty()) {
        try {
            List<ImageV4Response> images = cloudbreakClient.getDefaultClient().imageCatalogV4Endpoint().getImagesByName(cloudbreakClient.getWorkspaceId(), imageCatalogTestDto.getRequest().getName(), null, CloudPlatform.GCP.name(), null, null, false).getCdhImages();
            ImageV4Response olderImage = images.get(images.size() - 2);
            Log.log(LOGGER, format(" Image Catalog Name: %s ", imageCatalogTestDto.getRequest().getName()));
            Log.log(LOGGER, format(" Image Catalog URL: %s ", imageCatalogTestDto.getRequest().getUrl()));
            Log.log(LOGGER, format(" Selected Pre-warmed Image Date: %s | ID: %s | Description: %s | Stack Version: %s ", olderImage.getDate(), olderImage.getUuid(), olderImage.getStackDetails().getVersion(), olderImage.getDescription()));
            gcpProperties.getBaseimage().setImageId(olderImage.getUuid());
            return olderImage.getUuid();
        } catch (Exception e) {
            LOGGER.error("Cannot fetch pre-warmed images of {} image catalog!", imageCatalogTestDto.getRequest().getName());
            throw new TestFailException(" Cannot fetch pre-warmed images of " + imageCatalogTestDto.getRequest().getName() + " image catalog!", e);
        }
    } else {
        Log.log(LOGGER, format(" Image Catalog Name: %s ", commonCloudProperties().getImageCatalogName()));
        Log.log(LOGGER, format(" Image Catalog URL: %s ", commonCloudProperties().getImageCatalogUrl()));
        Log.log(LOGGER, format(" Image ID for SDX create: %s ", gcpProperties.getBaseimage().getImageId()));
        return gcpProperties.getBaseimage().getImageId();
    }
}
Also used : ImageV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.imagecatalog.responses.ImageV4Response) TestFailException(com.sequenceiq.it.cloudbreak.exception.TestFailException) NotImplementedException(org.apache.commons.lang3.NotImplementedException) TestFailException(com.sequenceiq.it.cloudbreak.exception.TestFailException)

Example 82 with TestFailException

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

the class MockCloudProvider method getPreviousPreWarmedImageID.

@Override
public String getPreviousPreWarmedImageID(TestContext testContext, ImageCatalogTestDto imageCatalogTestDto, CloudbreakClient cloudbreakClient) {
    if (mockProperties.getBaseimage().getRedhat7().getImageId() == null || mockProperties.getBaseimage().getRedhat7().getImageId().isEmpty()) {
        try {
            List<ImageV4Response> images = cloudbreakClient.getDefaultClient().imageCatalogV4Endpoint().getImagesByName(cloudbreakClient.getWorkspaceId(), imageCatalogTestDto.getRequest().getName(), null, CloudPlatform.MOCK.name(), null, null, false).getCdhImages();
            ImageV4Response olderImage = images.get(images.size() - 2);
            Log.log(LOGGER, format(" Image Catalog Name: %s ", imageCatalogTestDto.getRequest().getName()));
            Log.log(LOGGER, format(" Image Catalog URL: %s ", imageCatalogTestDto.getRequest().getUrl()));
            Log.log(LOGGER, format(" Selected Pre-warmed Image Date: %s | ID: %s | Description: %s | Stack Version: %s ", olderImage.getDate(), olderImage.getUuid(), olderImage.getStackDetails().getVersion(), olderImage.getDescription()));
            mockProperties.getBaseimage().getRedhat7().setImageId(olderImage.getUuid());
            return olderImage.getUuid();
        } catch (Exception e) {
            LOGGER.error("Cannot fetch pre-warmed images of {} image catalog!", imageCatalogTestDto.getRequest().getName());
            throw new TestFailException(" Cannot fetch pre-warmed images of " + imageCatalogTestDto.getRequest().getName() + " image catalog!", e);
        }
    } else {
        Log.log(LOGGER, format(" Image Catalog Name: %s ", commonCloudProperties().getImageCatalogName()));
        Log.log(LOGGER, format(" Image Catalog URL: %s ", commonCloudProperties().getImageCatalogUrl()));
        Log.log(LOGGER, format(" Image ID for SDX create: %s ", mockProperties.getBaseimage().getRedhat7().getImageId()));
        return mockProperties.getBaseimage().getRedhat7().getImageId();
    }
}
Also used : ImageV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.imagecatalog.responses.ImageV4Response) TestFailException(com.sequenceiq.it.cloudbreak.exception.TestFailException) NotImplementedException(org.apache.commons.lang3.NotImplementedException) TestFailException(com.sequenceiq.it.cloudbreak.exception.TestFailException)

Example 83 with TestFailException

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

the class CloudbreakUserCache method getAdminByAccountId.

public CloudbreakUser getAdminByAccountId(String accountId) {
    if (!usersByAccount.containsKey(accountId)) {
        throw new TestFailException("Real UMS '" + accountId + "' account ID is missing from 'ums-users/api-credentials.json' file." + " Please revise your account ID.");
    } else {
        LOGGER.info("Getting the requested real UMS admin by account Id: {}", accountId);
        try {
            CloudbreakUser adminUser = usersByAccount.values().stream().flatMap(Collection::stream).filter(CloudbreakUser::getAdmin).findFirst().orElseThrow(() -> new TestFailException(String.format("There is no real UMS admin in account: %s", accountId)));
            LOGGER.info(" Real UMS account admin has been found:: \nDisplay name: {} \nCrn: {} \nAccess key: {} \nSecret key: {} \nAdmin: {} ", adminUser.getDisplayName(), adminUser.getCrn(), adminUser.getAccessKey(), adminUser.getSecretKey(), adminUser.getAdmin());
            return adminUser;
        } catch (Exception e) {
            throw new TestFailException(String.format("Cannot get the real UMS admin in account: %s, because of: %s", accountId, e.getMessage()), e);
        }
    }
}
Also used : TestFailException(com.sequenceiq.it.cloudbreak.exception.TestFailException) TestFailException(com.sequenceiq.it.cloudbreak.exception.TestFailException) NoSuchElementException(java.util.NoSuchElementException)

Example 84 with TestFailException

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

the class CloudbreakUserCache method initRealUmsUserCache.

@PostConstruct
private void initRealUmsUserCache() {
    UmsUserStoreConfig umsUserStore = findUmsStore();
    if (umsUserStore.getFilePresent()) {
        Map<String, Map<String, List<CloudbreakUser>>> fetchedUserStore;
        List<CloudbreakUser> cloudbreakUsers;
        Set<String> accountIds = new HashSet<>();
        String accountId;
        LOGGER.info("Real UMS users are initializing by deployment: {} and account: {}.", realUmsUserDeployment, realUmsUserAccount);
        try {
            if (umsUserStore.getAtCustomPath()) {
                fetchedUserStore = JsonUtil.readValue(FileReaderUtils.readFileFromCustomPath(umsUserStore.getCustomFilePath()), new TypeReference<Map<String, Map<String, List<CloudbreakUser>>>>() {
                });
            } else {
                fetchedUserStore = JsonUtil.readValue(FileReaderUtils.readFileFromClasspathQuietly(umsUserStore.getClassFilePath()), new TypeReference<Map<String, Map<String, List<CloudbreakUser>>>>() {
                });
            }
            cloudbreakUsers = fetchedUserStore.entrySet().stream().filter(mowEnvs -> mowEnvs.getKey().equalsIgnoreCase(realUmsUserDeployment)).flatMap(selectedEnv -> selectedEnv.getValue().entrySet().stream().filter(mowAccs -> mowAccs.getKey().equalsIgnoreCase(realUmsUserAccount)).flatMap(selectedAcc -> selectedAcc.getValue().stream())).collect(Collectors.toList());
            cloudbreakUsers.forEach(user -> accountIds.add(Objects.requireNonNull(Crn.fromString(user.getCrn())).getAccountId()));
        } catch (Exception e) {
            throw new TestFailException(" Can't read UMS user store! It's possible you did run 'make fetch-secrets'. ", e);
        }
        if (CollectionUtils.isEmpty(accountIds)) {
            LOGGER.error(" Cannot gather account Ids from the initialized real UMS user CRNs. ");
            throw new TestFailException("Cannot gather account Ids from the initialized real UMS user CRNs.");
        } else {
            LOGGER.info(" Gathered account Ids based on the initialized real UMS user CRNs:: {}", accountIds);
            accountId = accountIds.stream().findFirst().orElseThrow(() -> new TestFailException(String.format("Account Id Not Found in:: %s", accountIds)));
            setUsersByAccount(Map.of(accountId, cloudbreakUsers));
        }
        usersByAccount.values().stream().flatMap(Collection::stream).forEach(user -> {
            LOGGER.info(" Initialized real UMS user in account ({}):: \nDisplay name: {} \nCrn: {} \nAccess key: {} \nSecret key: {} \nAdmin: {} ", accountId, user.getDisplayName(), user.getCrn(), user.getAccessKey(), user.getSecretKey(), user.getAdmin());
            CloudbreakUser.validateRealUmsUser(user);
        });
    } else {
        LOGGER.info("UMS user store is not available at path: '{}'. So initialization of real UMS user cache is not possible!", umsUserStore.getFetchedFilePath());
    }
}
Also used : LoggerFactory(org.slf4j.LoggerFactory) ClassPathResource(org.springframework.core.io.ClassPathResource) JsonUtil(com.sequenceiq.cloudbreak.common.json.JsonUtil) StringUtils(org.apache.commons.lang3.StringUtils) CollectionUtils(org.apache.commons.collections4.CollectionUtils) HashSet(java.util.HashSet) Value(org.springframework.beans.factory.annotation.Value) TestFailException(com.sequenceiq.it.cloudbreak.exception.TestFailException) Map(java.util.Map) FileReaderUtils(com.sequenceiq.cloudbreak.util.FileReaderUtils) NoSuchElementException(java.util.NoSuchElementException) TypeReference(com.fasterxml.jackson.core.type.TypeReference) Path(java.nio.file.Path) MapUtils(org.apache.commons.collections4.MapUtils) Logger(org.slf4j.Logger) Files(java.nio.file.Files) Collection(java.util.Collection) Set(java.util.Set) Crn(com.sequenceiq.cloudbreak.auth.crn.Crn) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) List(java.util.List) Component(org.springframework.stereotype.Component) Stream(java.util.stream.Stream) Paths(java.nio.file.Paths) PostConstruct(javax.annotation.PostConstruct) TestFailException(com.sequenceiq.it.cloudbreak.exception.TestFailException) TypeReference(com.fasterxml.jackson.core.type.TypeReference) Map(java.util.Map) TestFailException(com.sequenceiq.it.cloudbreak.exception.TestFailException) NoSuchElementException(java.util.NoSuchElementException) HashSet(java.util.HashSet) PostConstruct(javax.annotation.PostConstruct)

Example 85 with TestFailException

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

the class CloudProviderSideTagAssertion method verifyTags.

private void verifyTags(List<String> instanceIds, Map<String, String> customTags, TestContext testContext, String resourceName) {
    if ((instanceIds != null && !instanceIds.isEmpty()) || !instanceIds.contains(null)) {
        CloudFunctionality cloudFunctionality = cloudProviderProxy.getCloudFunctionality();
        Map<String, Map<String, String>> tagsByInstanceId = cloudFunctionality.listTagsByInstanceId(resourceName, instanceIds);
        tagsByInstanceId.forEach((id, tags) -> {
            LOGGER.info(" Verifying resource: {} instance ID: {} with tags: {}", resourceName, id, tags);
            tagsUtil.verifyTags(new MapToTaggedResponseAdapter(tags), testContext);
            customTags.forEach((key, value) -> assertThat(tags.get(cloudFunctionality.transformTagKeyOrValue(key))).isEqualTo(cloudFunctionality.transformTagKeyOrValue(value)));
        });
    } else {
        LOGGER.error("Tag validation is not possible, because of {} instance ids: {} null or contains null!", resourceName, instanceIds);
        throw new TestFailException(String.format(" Tag validation is not possible, because of %s instance ids: %s null or contains null ", resourceName, instanceIds));
    }
}
Also used : CloudFunctionality(com.sequenceiq.it.cloudbreak.util.CloudFunctionality) MapToTaggedResponseAdapter(com.sequenceiq.common.api.tag.response.MapToTaggedResponseAdapter) TestFailException(com.sequenceiq.it.cloudbreak.exception.TestFailException) Map(java.util.Map)

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