/** * Get the S3_STAGING_RESOURCE full path from the bucket name as well as other details. * * @return the s3 managed location. */ public String getS3StagingLocation() { return configurationHelper.getProperty(ConfigurationValue.S3_URL_PROTOCOL) + configurationHelper.getProperty(ConfigurationValue.S3_STAGING_BUCKET_NAME) + configurationHelper.getProperty(ConfigurationValue.S3_URL_PATH_DELIMITER) + configurationHelper.getProperty(ConfigurationValue.S3_STAGING_RESOURCE_BASE); }
/** * Gets a property value as a boolean. * * @param configurationValue the boolean configuration value * * @return the boolean property value */ public Boolean getBooleanProperty(ConfigurationValue configurationValue) { return getBooleanProperty(configurationValue, environment); }
/** * Gets a property value and validates that it is not blank or null. * * @param configurationValue {@link ConfigurationValue} * * @return the string value */ public String getRequiredProperty(ConfigurationValue configurationValue) { return getRequiredProperty(configurationValue, environment); }
/** * Gets a property value as a {@link BigDecimal}. * * @param configurationValue the {@link BigDecimal} configuration value * @param environment the environment containing the property * * @return the {@link BigDecimal} property value */ public BigDecimal getBigDecimalRequiredProperty(ConfigurationValue configurationValue, Environment environment) { String bigDecimalStringValue = getRequiredProperty(configurationValue, environment); BigDecimal bigDecimalValue = null; try { // Converts the string value to BigDecimal bigDecimalValue = new BigDecimal(bigDecimalStringValue); } catch (NumberFormatException numberFormatException) { logErrorAndThrowIllegalStateException(configurationValue, "BigDecimal", bigDecimalStringValue, numberFormatException); } return bigDecimalValue; }
when(configurationHelper.getProperty(ConfigurationValue.S3_ATTRIBUTE_NAME_VALIDATE_PATH_PREFIX)).thenReturn(S3_ATTRIBUTE_NAME_VALIDATE_PATH_PREFIX); when(storageHelper.getBooleanStorageAttributeValueByName(S3_ATTRIBUTE_NAME_VALIDATE_PATH_PREFIX, storageEntity, false, true)).thenReturn(true); when(configurationHelper.getProperty(ConfigurationValue.S3_ATTRIBUTE_NAME_VALIDATE_FILE_EXISTENCE)) .thenReturn(S3_ATTRIBUTE_NAME_VALIDATE_FILE_EXISTENCE); when(storageHelper.getBooleanStorageAttributeValueByName(S3_ATTRIBUTE_NAME_VALIDATE_FILE_EXISTENCE, storageEntity, false, true)).thenReturn(true); when(configurationHelper.getProperty(ConfigurationValue.S3_ATTRIBUTE_NAME_BUCKET_NAME)).thenReturn(S3_ATTRIBUTE_NAME_BUCKET_NAME); when(storageHelper.getStorageAttributeValueByName(S3_ATTRIBUTE_NAME_BUCKET_NAME, storageEntity, true)).thenReturn(S3_BUCKET_NAME); when(configurationHelper.getRequiredProperty(ConfigurationValue.S3_ARCHIVE_TO_GLACIER_TAG_KEY)).thenReturn(S3_OBJECT_TAG_KEY); when(configurationHelper.getRequiredProperty(ConfigurationValue.S3_ARCHIVE_TO_GLACIER_TAG_VALUE)).thenReturn(S3_OBJECT_TAG_VALUE); when(configurationHelper.getRequiredProperty(ConfigurationValue.S3_ARCHIVE_TO_GLACIER_ROLE_ARN)).thenReturn(S3_OBJECT_TAGGER_ROLE_ARN); when(configurationHelper.getRequiredProperty(ConfigurationValue.S3_ARCHIVE_TO_GLACIER_ROLE_SESSION_NAME)) .thenReturn(S3_OBJECT_TAGGER_ROLE_SESSION_NAME); when(storageUnitDaoHelper.getStorageUnitEntity(STORAGE_NAME, businessObjectDataEntity)).thenReturn(storageUnitEntity); when(configurationHelper.getProperty(ConfigurationValue.S3_ENDPOINT)).thenReturn(S3_ENDPOINT); verify(storagePolicyDaoHelper).getStoragePolicyEntityByKeyAndVersion(storagePolicyKey, STORAGE_POLICY_VERSION); verify(storagePolicyHelper, times(2)).storagePolicyKeyAndVersionToString(storagePolicyKey, STORAGE_POLICY_VERSION); verify(configurationHelper).getProperty(ConfigurationValue.S3_ATTRIBUTE_NAME_VALIDATE_PATH_PREFIX); verify(storageHelper).getBooleanStorageAttributeValueByName(S3_ATTRIBUTE_NAME_VALIDATE_PATH_PREFIX, storageEntity, false, true); verify(configurationHelper).getProperty(ConfigurationValue.S3_ATTRIBUTE_NAME_VALIDATE_FILE_EXISTENCE); verify(storageHelper).getBooleanStorageAttributeValueByName(S3_ATTRIBUTE_NAME_VALIDATE_FILE_EXISTENCE, storageEntity, false, true); verify(configurationHelper).getProperty(ConfigurationValue.S3_ATTRIBUTE_NAME_BUCKET_NAME); verify(storageHelper).getStorageAttributeValueByName(S3_ATTRIBUTE_NAME_BUCKET_NAME, storageEntity, true); verify(configurationHelper).getRequiredProperty(ConfigurationValue.S3_ARCHIVE_TO_GLACIER_TAG_KEY); verify(configurationHelper).getRequiredProperty(ConfigurationValue.S3_ARCHIVE_TO_GLACIER_TAG_VALUE); verify(configurationHelper).getRequiredProperty(ConfigurationValue.S3_ARCHIVE_TO_GLACIER_ROLE_ARN); verify(configurationHelper).getRequiredProperty(ConfigurationValue.S3_ARCHIVE_TO_GLACIER_ROLE_SESSION_NAME); verify(storageUnitDaoHelper).getStorageUnitEntity(STORAGE_NAME, businessObjectDataEntity);
/** * Gets a property value as {@link BigDecimal}. Additionally it ensures that the property value is not negative. * * @param configurationValue the {@link BigDecimal} configuration value * * @return the non-negative {@link BigDecimal} property value */ public BigDecimal getNonNegativeBigDecimalRequiredProperty(ConfigurationValue configurationValue) { return getNonNegativeBigDecimalRequiredProperty(configurationValue, environment); }
/** * Gets a property value as a {@link BigDecimal}. * * @param configurationValue the {@link BigDecimal} configuration value * * @return the {@link BigDecimal} property value */ public BigDecimal getBigDecimalRequiredProperty(ConfigurationValue configurationValue) { return getBigDecimalRequiredProperty(configurationValue, environment); }
.getStorageAttributeValueByName(configurationHelper.getProperty(ConfigurationValue.S3_ATTRIBUTE_NAME_BUCKET_NAME), storagePolicyEntity.getStorage(), true); String s3ObjectTagKey = configurationHelper.getRequiredProperty(ConfigurationValue.S3_ARCHIVE_TO_GLACIER_TAG_KEY); String s3ObjectTagValue = configurationHelper.getRequiredProperty(ConfigurationValue.S3_ARCHIVE_TO_GLACIER_TAG_VALUE); String s3ObjectTaggerRoleArn = configurationHelper.getRequiredProperty(ConfigurationValue.S3_ARCHIVE_TO_GLACIER_ROLE_ARN); String s3ObjectTaggerRoleSessionName = configurationHelper.getRequiredProperty(ConfigurationValue.S3_ARCHIVE_TO_GLACIER_ROLE_SESSION_NAME); storagePolicyTransitionParamsDto.setS3Endpoint(configurationHelper.getProperty(ConfigurationValue.S3_ENDPOINT)); storagePolicyTransitionParamsDto.setS3BucketName(s3BucketName); storagePolicyTransitionParamsDto.setS3KeyPrefix(s3KeyPrefix);
/** * Gets a property value as {@link BigDecimal}. Additionally it ensures that the property value is not negative. * * @param configurationValue the {@link BigDecimal} configuration value * * @return the non-negative {@link BigDecimal} property value */ public BigDecimal getNonNegativeBigDecimalRequiredProperty(ConfigurationValue configurationValue) { return getNonNegativeBigDecimalRequiredProperty(configurationValue, environment); }
/** * Gets a property value as a {@link BigDecimal}. * * @param configurationValue the {@link BigDecimal} configuration value * @param environment the environment containing the property * * @return the {@link BigDecimal} property value */ public BigDecimal getBigDecimalRequiredProperty(ConfigurationValue configurationValue, Environment environment) { String bigDecimalStringValue = getRequiredProperty(configurationValue, environment); BigDecimal bigDecimalValue = null; try { // Converts the string value to BigDecimal bigDecimalValue = new BigDecimal(bigDecimalStringValue); } catch (NumberFormatException numberFormatException) { logErrorAndThrowIllegalStateException(configurationValue, "BigDecimal", bigDecimalStringValue, numberFormatException); } return bigDecimalValue; }
/** * Gets a property value as a {@link BigDecimal}. * * @param configurationValue the {@link BigDecimal} configuration value * * @return the {@link BigDecimal} property value */ public BigDecimal getBigDecimalRequiredProperty(ConfigurationValue configurationValue) { return getBigDecimalRequiredProperty(configurationValue, environment); }
/** * TODO replace uses of this method with ConfigurationHelper Gets the configuration value as string. */ public String getConfigurationValueAsString(ConfigurationValue configurationValue) { return configurationHelper.getProperty(configurationValue); }
.getStorageAttributeValueByName(configurationHelper.getProperty(ConfigurationValue.S3_ATTRIBUTE_NAME_BUCKET_NAME), storagePolicyEntity.getStorage(), true); String s3ObjectTagKey = configurationHelper.getRequiredProperty(ConfigurationValue.S3_ARCHIVE_TO_GLACIER_TAG_KEY); String s3ObjectTagValue = configurationHelper.getRequiredProperty(ConfigurationValue.S3_ARCHIVE_TO_GLACIER_TAG_VALUE); String s3ObjectTaggerRoleArn = configurationHelper.getRequiredProperty(ConfigurationValue.S3_ARCHIVE_TO_GLACIER_ROLE_ARN); String s3ObjectTaggerRoleSessionName = configurationHelper.getRequiredProperty(ConfigurationValue.S3_ARCHIVE_TO_GLACIER_ROLE_SESSION_NAME); storagePolicyTransitionParamsDto.setS3Endpoint(configurationHelper.getProperty(ConfigurationValue.S3_ENDPOINT)); storagePolicyTransitionParamsDto.setS3BucketName(s3BucketName); storagePolicyTransitionParamsDto.setS3KeyPrefix(s3KeyPrefix);
/** * Gets a property value as a boolean. * * @param configurationValue the boolean configuration value * * @return the boolean property value */ public Boolean getBooleanProperty(ConfigurationValue configurationValue) { return getBooleanProperty(configurationValue, environment); }
/** * Selects the EMR cluster pricing with the lowest core instance price. We will select one pricing randomly if there are multiple pricings that meet the * lowest core price criteria. * <p> * Returns null if the given list is empty * * @param emrClusterPrices the list of pricing to select from * * @return the pricing with the lowest core price */ EmrClusterPriceDto getEmrClusterPriceWithLowestCoreInstancePrice(final List<EmrClusterPriceDto> emrClusterPrices) { final List<EmrClusterPriceDto> lowestCoreInstancePriceEmrClusters = getEmrClusterPricesWithinLowestCoreInstancePriceThreshold(emrClusterPrices, configurationHelper.getNonNegativeBigDecimalRequiredProperty(ConfigurationValue.EMR_CLUSTER_LOWEST_CORE_INSTANCE_PRICE_PERCENTAGE)); if (!lowestCoreInstancePriceEmrClusters.isEmpty()) { // Pick one randomly from the lowest core instance price list final EmrClusterPriceDto selectedEmrClusterPriceDto = lowestCoreInstancePriceEmrClusters.get(new Random().nextInt(lowestCoreInstancePriceEmrClusters.size())); // Log the selected pricing as well as the pricing list LOGGER.info("selectedEmrCluster={} from lowestCoreInstancePriceEmrClusters={}", jsonHelper.objectToJson(selectedEmrClusterPriceDto), jsonHelper.objectToJson(lowestCoreInstancePriceEmrClusters)); return selectedEmrClusterPriceDto; } else { return null; } }
/** * Gets a property value and validates that it is not blank or null. * * @param configurationValue {@link ConfigurationValue} * * @return the string value */ public String getRequiredProperty(ConfigurationValue configurationValue) { return getRequiredProperty(configurationValue, environment); }
/** * Gets a property value as {@link BigDecimal}. Additionally it ensures that the property value is not negative. * * @param configurationValue the {@link BigDecimal} configuration value * @param environment the environment containing the property * * @return the non-negative {@link BigDecimal} property value */ public BigDecimal getNonNegativeBigDecimalRequiredProperty(ConfigurationValue configurationValue, Environment environment) { final BigDecimal nonNegativeBigDecimalPropertyValue = getBigDecimalRequiredProperty(configurationValue, environment); if (nonNegativeBigDecimalPropertyValue.signum() == -1) { throw new IllegalStateException(String .format("Configuration \"%s\" has an invalid non-negative BigDecimal value: \"%s\".", configurationValue.getKey(), nonNegativeBigDecimalPropertyValue)); } return nonNegativeBigDecimalPropertyValue; }
@Override public String getCronExpression() { return configurationHelper.getProperty(ConfigurationValue.RELATIONAL_TABLE_SCHEMA_UPDATE_JOB_CRON_EXPRESSION); }
when(configurationHelper.getRequiredProperty(ConfigurationValue.S3_OBJECT_DELETE_TAG_KEY)).thenReturn(S3_OBJECT_TAG_KEY); when(configurationHelper.getRequiredProperty(ConfigurationValue.S3_OBJECT_DELETE_TAG_VALUE)).thenReturn(S3_OBJECT_TAG_VALUE); when(configurationHelper.getRequiredProperty(ConfigurationValue.S3_OBJECT_DELETE_ROLE_ARN)).thenReturn(S3_OBJECT_TAGGER_ROLE_ARN); when(configurationHelper.getRequiredProperty(ConfigurationValue.S3_OBJECT_DELETE_ROLE_SESSION_NAME)).thenReturn(S3_OBJECT_TAGGER_ROLE_SESSION_NAME); when(herdStringHelper.getConfigurationValueAsInteger(ConfigurationValue.BDATA_FINAL_DESTROY_DELAY_IN_DAYS)) .thenReturn(BDATA_FINAL_DESTROY_DELAY_IN_DAYS); when(storageUnitDao.getStorageUnitsByStoragePlatformAndBusinessObjectData(StoragePlatformEntity.S3, businessObjectDataEntity)) .thenReturn(Arrays.asList(storageUnitEntity)); when(configurationHelper.getProperty(ConfigurationValue.S3_ATTRIBUTE_NAME_VALIDATE_PATH_PREFIX)).thenReturn(S3_ATTRIBUTE_NAME_VALIDATE_PATH_PREFIX); when(storageHelper.getBooleanStorageAttributeValueByName(S3_ATTRIBUTE_NAME_VALIDATE_PATH_PREFIX, storageEntity, false, true)).thenReturn(true); when(configurationHelper.getProperty(ConfigurationValue.S3_ATTRIBUTE_NAME_BUCKET_NAME)).thenReturn(S3_ATTRIBUTE_NAME_BUCKET_NAME); when(storageHelper.getStorageAttributeValueByName(S3_ATTRIBUTE_NAME_BUCKET_NAME, storageEntity, true)).thenReturn(S3_BUCKET_NAME); when(s3KeyPrefixHelper.buildS3KeyPrefix(storageEntity, businessObjectFormatEntity, businessObjectDataKey)).thenReturn(TEST_S3_KEY_PREFIX); when(configurationHelper.getProperty(ConfigurationValue.S3_ENDPOINT)).thenReturn(S3_ENDPOINT); verify(configurationHelper).getRequiredProperty(ConfigurationValue.S3_OBJECT_DELETE_TAG_KEY); verify(configurationHelper).getRequiredProperty(ConfigurationValue.S3_OBJECT_DELETE_TAG_VALUE); verify(configurationHelper).getRequiredProperty(ConfigurationValue.S3_OBJECT_DELETE_ROLE_ARN); verify(configurationHelper).getRequiredProperty(ConfigurationValue.S3_OBJECT_DELETE_ROLE_SESSION_NAME); verify(herdStringHelper).getConfigurationValueAsInteger(ConfigurationValue.BDATA_FINAL_DESTROY_DELAY_IN_DAYS); verify(businessObjectDataDaoHelper).getBusinessObjectDataEntity(businessObjectDataKey); verify(herdDao).getCurrentTimestamp(); verify(storageUnitDao).getStorageUnitsByStoragePlatformAndBusinessObjectData(StoragePlatformEntity.S3, businessObjectDataEntity); verify(configurationHelper).getProperty(ConfigurationValue.S3_ATTRIBUTE_NAME_VALIDATE_PATH_PREFIX); verify(storageHelper).getBooleanStorageAttributeValueByName(S3_ATTRIBUTE_NAME_VALIDATE_PATH_PREFIX, storageEntity, false, true); verify(configurationHelper).getProperty(ConfigurationValue.S3_ATTRIBUTE_NAME_BUCKET_NAME);
@Test public void checkPermissionsAssertDoNothingWhenAuthorizationDisabled() { NamespaceEntity expectedNamespaceEntity = new NamespaceEntity(); Collection<String> requestedIamRoleNames = new ArrayList<>(); when(configurationHelper.getBooleanProperty(any())).thenReturn(false); namespaceIamRoleAuthorizationHelper.checkPermissions(expectedNamespaceEntity, requestedIamRoleNames); verify(configurationHelper).getBooleanProperty(ConfigurationValue.NAMESPACE_IAM_ROLE_AUTHORIZATION_ENABLED); verifyNoMoreInteractions(configurationHelper, namespaceIamRoleAuthorizationDao); }