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();
}
}
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();
}
}
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);
}
}
}
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());
}
}
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));
}
}
Aggregations