List of usage examples for com.amazonaws.util StringUtils isNullOrEmpty
public static boolean isNullOrEmpty(String value)
From source file:AmazonKinesisFirehoseToRedshiftSample.java
License:Open Source License
/** * Initialize the parameters./*from ww w.j ava 2s . c o m*/ * * @throws Exception */ private static void init() throws Exception { // Load the parameters from properties file loadConfig(); // Initialize the clients initClients(); // Validate AccountId parameter is set if (StringUtils.isNullOrEmpty(accountId)) { throw new IllegalArgumentException( "AccountId is empty. Please enter the accountId in " + CONFIG_FILE + " file"); } }
From source file:AmazonKinesisFirehoseToRedshiftSample.java
License:Open Source License
/** * Load the input parameters from properties file. * * @throws FileNotFoundException/* ww w .ja v a 2s. c om*/ * @throws IOException */ private static void loadConfig() throws FileNotFoundException, IOException { try (InputStream configStream = Thread.currentThread().getContextClassLoader() .getResourceAsStream(CONFIG_FILE)) { if (configStream == null) { throw new FileNotFoundException(); } properties = new Properties(); properties.load(configStream); } // Read properties accountId = properties.getProperty("customerAccountId"); createS3Bucket = Boolean.valueOf(properties.getProperty("createS3Bucket")); s3RegionName = properties.getProperty("s3RegionName"); s3BucketName = properties.getProperty("s3BucketName").trim(); s3BucketARN = getBucketARN(s3BucketName); s3ObjectPrefix = properties.getProperty("s3ObjectPrefix").trim(); String sizeInMBsProperty = properties.getProperty("destinationSizeInMBs"); s3DestinationSizeInMBs = StringUtils.isNullOrEmpty(sizeInMBsProperty) ? null : Integer.parseInt(sizeInMBsProperty.trim()); String intervalInSecondsProperty = properties.getProperty("destinationIntervalInSeconds"); s3DestinationIntervalInSeconds = StringUtils.isNullOrEmpty(intervalInSecondsProperty) ? null : Integer.parseInt(intervalInSecondsProperty.trim()); clusterJDBCUrl = properties.getProperty("clusterJDBCUrl"); username = properties.getProperty("username"); password = properties.getProperty("password"); dataTableName = properties.getProperty("dataTableName"); copyOptions = properties.getProperty("copyOptions"); deliveryStreamName = properties.getProperty("deliveryStreamName"); firehoseRegion = properties.getProperty("firehoseRegion"); iamRoleName = properties.getProperty("iamRoleName"); iamRegion = properties.getProperty("iamRegion"); // Update Delivery Stream Destination related properties enableUpdateDestination = Boolean.valueOf(properties.getProperty("updateDestination")); updatedCopyOptions = properties.getProperty("updatedCopyOptions"); }
From source file:AmazonKinesisFirehoseToS3Sample.java
License:Open Source License
/** * Load the input parameters from properties file. * * @throws FileNotFoundException//w w w . j a v a 2 s . co m * @throws IOException */ private static void loadConfig() throws FileNotFoundException, IOException { try (InputStream configStream = Thread.currentThread().getContextClassLoader() .getResourceAsStream(CONFIG_FILE)) { if (configStream == null) { throw new FileNotFoundException(); } properties = new Properties(); properties.load(configStream); } // Read properties accountId = properties.getProperty("customerAccountId"); createS3Bucket = Boolean.valueOf(properties.getProperty("createS3Bucket")); s3RegionName = properties.getProperty("s3RegionName"); s3BucketName = properties.getProperty("s3BucketName").trim(); s3BucketARN = getBucketARN(s3BucketName); s3ObjectPrefix = properties.getProperty("s3ObjectPrefix").trim(); String sizeInMBsProperty = properties.getProperty("destinationSizeInMBs"); s3DestinationSizeInMBs = StringUtils.isNullOrEmpty(sizeInMBsProperty) ? null : Integer.parseInt(sizeInMBsProperty.trim()); String intervalInSecondsProperty = properties.getProperty("destinationIntervalInSeconds"); s3DestinationIntervalInSeconds = StringUtils.isNullOrEmpty(intervalInSecondsProperty) ? null : Integer.parseInt(intervalInSecondsProperty.trim()); deliveryStreamName = properties.getProperty("deliveryStreamName"); s3DestinationAWSKMSKeyId = properties.getProperty("destinationAWSKMSKeyId"); firehoseRegion = properties.getProperty("firehoseRegion"); iamRoleName = properties.getProperty("iamRoleName"); iamRegion = properties.getProperty("iamRegion"); // Update Delivery Stream Destination related properties enableUpdateDestination = Boolean.valueOf(properties.getProperty("updateDestination")); updateS3ObjectPrefix = properties.getProperty("updateS3ObjectPrefix").trim(); String updateSizeInMBsProperty = properties.getProperty("updateSizeInMBs"); updateSizeInMBs = StringUtils.isNullOrEmpty(updateSizeInMBsProperty) ? null : Integer.parseInt(updateSizeInMBsProperty.trim()); String updateIntervalInSecondsProperty = properties.getProperty("updateIntervalInSeconds"); updateIntervalInSeconds = StringUtils.isNullOrEmpty(updateIntervalInSecondsProperty) ? null : Integer.parseInt(updateIntervalInSecondsProperty.trim()); }
From source file:AmazonKinesisFirehoseToS3Sample.java
License:Open Source License
/** * Method to create delivery stream for S3 destination configuration. * * @throws Exception/*from w ww . ja va 2s . c o m*/ */ private static void createDeliveryStream() throws Exception { boolean deliveryStreamExists = false; LOG.info("Checking if " + deliveryStreamName + " already exits"); List<String> deliveryStreamNames = listDeliveryStreams(); if (deliveryStreamNames != null && deliveryStreamNames.contains(deliveryStreamName)) { deliveryStreamExists = true; LOG.info("DeliveryStream " + deliveryStreamName + " already exists. Not creating the new delivery stream"); } else { LOG.info("DeliveryStream " + deliveryStreamName + " does not exist"); } if (!deliveryStreamExists) { // Create deliveryStream CreateDeliveryStreamRequest createDeliveryStreamRequest = new CreateDeliveryStreamRequest(); createDeliveryStreamRequest.setDeliveryStreamName(deliveryStreamName); S3DestinationConfiguration s3DestinationConfiguration = new S3DestinationConfiguration(); s3DestinationConfiguration.setBucketARN(s3BucketARN); s3DestinationConfiguration.setPrefix(s3ObjectPrefix); // Could also specify GZIP or ZIP s3DestinationConfiguration.setCompressionFormat(CompressionFormat.UNCOMPRESSED); // Encryption configuration is optional EncryptionConfiguration encryptionConfiguration = new EncryptionConfiguration(); if (!StringUtils.isNullOrEmpty(s3DestinationAWSKMSKeyId)) { encryptionConfiguration.setKMSEncryptionConfig( new KMSEncryptionConfig().withAWSKMSKeyARN(s3DestinationAWSKMSKeyId)); } else { encryptionConfiguration.setNoEncryptionConfig(NoEncryptionConfig.NoEncryption); } s3DestinationConfiguration.setEncryptionConfiguration(encryptionConfiguration); BufferingHints bufferingHints = null; if (s3DestinationSizeInMBs != null || s3DestinationIntervalInSeconds != null) { bufferingHints = new BufferingHints(); bufferingHints.setSizeInMBs(s3DestinationSizeInMBs); bufferingHints.setIntervalInSeconds(s3DestinationIntervalInSeconds); } s3DestinationConfiguration.setBufferingHints(bufferingHints); // Create and set IAM role so that firehose service has access to the S3Buckets to put data // and KMS keys (if provided) to encrypt data. Please check the trustPolicyDocument.json and // permissionsPolicyDocument.json files for the trust and permissions policies set for the role. String iamRoleArn = createIamRole(s3ObjectPrefix); s3DestinationConfiguration.setRoleARN(iamRoleArn); createDeliveryStreamRequest.setS3DestinationConfiguration(s3DestinationConfiguration); firehoseClient.createDeliveryStream(createDeliveryStreamRequest); // The Delivery Stream is now being created. LOG.info("Creating DeliveryStream : " + deliveryStreamName); waitForDeliveryStreamToBecomeAvailable(deliveryStreamName); } }
From source file:AbstractAmazonKinesisFirehoseDelivery.java
License:Open Source License
/** * Method to create the S3 bucket in specified region. * * @throws Exception//from w w w . j a v a 2 s. co m */ protected static void createS3Bucket() throws Exception { if (StringUtils.isNullOrEmpty(s3BucketName.trim())) { throw new IllegalArgumentException( "Bucket name is empty. Please enter a bucket name " + "in firehosetos3sample.properties file"); } // Create S3 bucket if specified in the properties if (createS3Bucket) { s3Client.createBucket(s3BucketName); LOG.info("Created bucket " + s3BucketName + " in S3 to deliver Firehose records"); } }
From source file:AbstractAmazonKinesisFirehoseDelivery.java
License:Open Source License
/** * Returns true if the KMS Key ARN is specified in properties file. * * @return true, if KMS Key is specified *///from www .j ava2s . c om private static boolean containsKMSKeyARN() { return !StringUtils.isNullOrEmpty(s3DestinationAWSKMSKeyId); }
From source file:access.controller.AccessController.java
License:Apache License
/** * Requests a file download that has been prepared by this Access component. This will return the raw bytes of the * resource./*from ww w .j ava 2s.c om*/ * * @param dataId * The Id of the Data Item to get. Assumes this file is ready to be downloaded. */ @SuppressWarnings("rawtypes") @RequestMapping(value = "/file/{dataId}", method = RequestMethod.GET) public ResponseEntity accessFile(@PathVariable(value = "dataId") String dataId, @RequestParam(value = "fileName", required = false) String name) { final String returnAction = "returningFileBytes"; try { // Get the DataResource item DataResource data = accessor.getData(dataId); String fileName = StringUtils.isNullOrEmpty(name) ? dataId : name; pzLogger.log(String.format("Processing Data File for %s", dataId), Severity.INFORMATIONAL, new AuditElement(ACCESS, "beginProcessingFile", dataId)); if (data == null) { pzLogger.log(String.format("Data not found for requested Id %s", dataId), Severity.WARNING); return new ResponseEntity<>( new ErrorResponse(String.format("Data not found: %s", dataId), ACCESS_COMPONENT_NAME), HttpStatus.NOT_FOUND); } if (data.getDataType() instanceof TextDataType) { // Stream the Bytes back TextDataType textData = (TextDataType) data.getDataType(); pzLogger.log(String.format("Returning Bytes for %s", dataId), Severity.INFORMATIONAL, new AuditElement(ACCESS, returnAction, dataId)); return getResponse(MediaType.TEXT_PLAIN, String.format("%s%s", fileName, ".txt"), textData.getContent().getBytes()); } else if (data.getDataType() instanceof PostGISDataType) { // Obtain geoJSON from postGIS StringBuilder geoJSON = getPostGISGeoJSON(data); // Log the Request pzLogger.log(String.format("Returning Bytes for %s of length %s", dataId, geoJSON.length()), Severity.INFORMATIONAL, new AuditElement(ACCESS, returnAction, dataId)); // Stream the Bytes back return getResponse(MediaType.TEXT_PLAIN, String.format("%s%s", fileName, ".geojson"), geoJSON.toString().getBytes()); } else if (!(data.getDataType() instanceof FileRepresentation)) { String message = String.format("File download not available for Data Id %s; type is %s", dataId, data.getDataType().getClass().getSimpleName()); pzLogger.log(message, Severity.WARNING, new AuditElement(ACCESS, "accessBytesError", "")); throw new InvalidInputException(message); } else { byte[] bytes = accessUtilities.getBytesForDataResource(data); // Log the Request pzLogger.log(String.format("Returning Bytes for %s of length %s", dataId, bytes.length), Severity.INFORMATIONAL, new AuditElement(ACCESS, returnAction, dataId)); // Preserve the file extension from the original file. String originalFileName = ((FileRepresentation) data.getDataType()).getLocation().getFileName(); String extension = FilenameUtils.getExtension(originalFileName); // Stream the Bytes back return getResponse(MediaType.APPLICATION_OCTET_STREAM, String.format("%s.%s", fileName, extension), bytes); } } catch (Exception exception) { String error = String.format("Error fetching Data %s: %s", dataId, exception.getMessage()); LOGGER.error(error, exception); pzLogger.log(error, Severity.ERROR, new AuditElement(ACCESS, "errorAccessingBytes", dataId)); return new ResponseEntity<>( new ErrorResponse("Error fetching File: " + exception.getMessage(), ACCESS_COMPONENT_NAME), HttpStatus.INTERNAL_SERVER_ERROR); } }
From source file:ai.serotonin.backup.Base.java
License:Mozilla Public License
String getArchivePassword() { if (!configRoot.has("password")) return null; final String password = configRoot.get("password").asText(); if (StringUtils.isNullOrEmpty(password)) return null; return password; }
From source file:com.er.sylvite.CustomEnvironmentVariableCredentialsProvider.java
License:Open Source License
@Override public AWSCredentials getCredentials() { String prefix = System.getProperty(PREFIX_ENV_VAR, DEFAULT_PREFIX); String accessKeyEnvVar = prefix + "_" + ACCESS_KEY_ENV_VAR; String secretKeyEnvVar = prefix + "_" + SECRET_KEY_ENV_VAR; String accessKey = System.getenv(accessKeyEnvVar); String secretKey = System.getenv(secretKeyEnvVar); accessKey = StringUtils.trim(accessKey); secretKey = StringUtils.trim(secretKey); if (StringUtils.isNullOrEmpty(accessKey) || StringUtils.isNullOrEmpty(secretKey)) { throw new AmazonClientException("Unable to load AWS credentials from environment variables " + "(" + accessKeyEnvVar + " and " + secretKeyEnvVar + ")"); }// w w w .j a va2 s.c o m return new BasicAWSCredentials(accessKey, secretKey); }
From source file:com.hpe.caf.worker.datastore.s3.S3DataStore.java
License:Apache License
public S3DataStore(final S3DataStoreConfiguration s3DataStoreConfiguration) { if (s3DataStoreConfiguration == null) { throw new ArgumentException("s3DataStoreConfiguration was null."); }/*ww w.j a va2s .com*/ ClientConfiguration clientCfg = new ClientConfiguration(); if (!StringUtils.isNullOrEmpty(s3DataStoreConfiguration.getProxyHost())) { clientCfg.setProtocol(Protocol.valueOf(s3DataStoreConfiguration.getProxyProtocol())); clientCfg.setProxyHost(s3DataStoreConfiguration.getProxyHost()); clientCfg.setProxyPort(s3DataStoreConfiguration.getProxyPort()); } AWSCredentials credentials = new BasicAWSCredentials(s3DataStoreConfiguration.getAccessKey(), s3DataStoreConfiguration.getSecretKey()); bucketName = s3DataStoreConfiguration.getBucketName(); amazonS3Client = new AmazonS3Client(credentials, clientCfg); amazonS3Client.setBucketAccelerateConfiguration(new SetBucketAccelerateConfigurationRequest(bucketName, new BucketAccelerateConfiguration(BucketAccelerateStatus.Enabled))); }