List of usage examples for com.amazonaws AmazonClientException AmazonClientException
public AmazonClientException(Throwable t)
From source file:model.data.location.FileAccessFactory.java
License:Apache License
/** * Returns the InputStream for a file represented by an object implementing the FileLocation interface * /*from w w w . java 2 s .co m*/ * @param fileLocation * The file location * @return The File stream */ public InputStream getFile(FileLocation fileLocation) throws AmazonClientException, InvalidInputException { if (fileLocation instanceof FolderShare) { return ((FolderShare) fileLocation).getFile(); } else if (fileLocation instanceof S3FileStore) { try { return getS3File(fileLocation, s3ak, s3pk, s3ek); } catch (AmazonClientException exception) { // Add helpful text to Exception String systemError = String.format( "Could not retrieve File Bytes for S3 File. Failed with Message : %s. AWS Client Credentials may be incorrect or not specified.", exception.getMessage()); String userError = "There was an issue pushing the file to Piazza S3 Bucket. Please contact a Piazza administrator for details."; LOGGER.error(systemError, exception); throw new AmazonClientException(userError); } } else { throw new InvalidInputException("Unsupported Object type."); } }
From source file:n3phele.agent.repohandlers.S3Large.java
License:Open Source License
public Origin put(InputStream input, long length, String encoding) { Origin result = new Origin(source + "/" + root + "/" + key, 0, null, null); TransferManager tm = null;/*from w w w. j av a 2 s . c om*/ try { tm = new TransferManager(this.credentials); tm.getAmazonS3Client().setEndpoint(source.toString()); objectMetadata = new ObjectMetadata(); objectMetadata.setContentLength(this.length = length); this.encoding = encoding; if (encoding != null) objectMetadata.setContentType(this.encoding); log.info("Output: " + source + "/" + root + "/" + key + " Content-Type: " + encoding + "length: " + length); Upload upload = tm.upload(root, key, input, objectMetadata); upload.waitForCompletion(); // PutObjectResult object = s3().putObject(root, key, input, objectMetadata); result.setLength(length); ObjectMetadata od = s3().getObjectMetadata(root, key); result.setModified(od.getLastModified()); } catch (AmazonServiceException e) { throw e; } catch (AmazonClientException e) { throw e; } catch (InterruptedException e) { throw new AmazonClientException(e.getMessage()); } finally { try { input.close(); } catch (IOException e) { } try { tm.shutdownNow(); } catch (Exception e) { } try { s3().shutdown(); } catch (Exception e) { } } return result; }
From source file:net.smartcosmos.plugin.service.aws.queue.AwsQueueService.java
License:Apache License
@Override public String send(final IQueueRequest queueRequest) { Preconditions.checkNotNull(queueRequest.getMessageBody(), "messageBody must not be null"); Preconditions.checkNotNull(queueRequest.getQueueName(), "queueName must not be null"); if (onlineFlag) { final Region region = assignRegion(sqsAsyncClient); String targetQueueName = fetchQueueName(queueRequest); String queueUrl = sqsAsyncClient.getQueueUrl(new GetQueueUrlRequest(targetQueueName)).getQueueUrl(); LOG.debug("Queue URL for queue named {} in region {}: {}", queueRequest.getQueueName(), region.getName(), queueUrl); SendMessageRequest request = new SendMessageRequest(queueUrl, queueRequest.getMessageBody()); if (null != queueRequest.getMessageAttributes()) { for (Map.Entry<String, String> entry : queueRequest.getMessageAttributes().entrySet()) { if (entry.getValue() != null && entry.getValue().length() > 0) { if (entry.getKey().equals(Field.LAST_MODIFIED_TIMESTAMP_FIELD) || entry.getKey().equals(Field.FILE_CONTENT_LENGTH)) { request.addMessageAttributesEntry(entry.getKey(), new MessageAttributeValue() .withDataType("Number").withStringValue(entry.getValue())); } else { request.addMessageAttributesEntry(entry.getKey(), new MessageAttributeValue() .withDataType("String").withStringValue(entry.getValue())); }/* ww w.ja va 2 s. c o m*/ } } } if (queueRequest.getMoniker() != null && queueRequest.getMoniker().length() > 0) { request.addMessageAttributesEntry(Field.MONIKER_FIELD, new MessageAttributeValue() .withDataType("String").withStringValue(queueRequest.getMoniker())); } final String enqueueUrn = "urn:uuid:" + UUID.randomUUID().toString(); request.addMessageAttributesEntry(Field.QUEUE_URN_FIELD, new MessageAttributeValue().withDataType("String.URN").withStringValue(enqueueUrn)); request.addMessageAttributesEntry(Field.ENTITY_REFERENCE_TYPE, new MessageAttributeValue().withDataType("String.EntityReferenceType") .withStringValue(queueRequest.getEntityReferenceType().toString())); request.addMessageAttributesEntry(Field.REFERENCE_URN_FIELD, new MessageAttributeValue() .withDataType("String.ReferenceUrn").withStringValue(queueRequest.getReferenceUrn())); AwsQueueAsyncHandler asyncHandler = new AwsQueueAsyncHandler(queueRequest, region, enqueueUrn); sqsAsyncClient.sendMessageAsync(request, asyncHandler); return enqueueUrn; } else { throw new AmazonClientException("AWS Queue Service is not online"); } }
From source file:nyu.twitter.lg.FentchTwitter.java
License:Open Source License
/** * The only information needed to create a client are security credentials * consisting of the AWS Access Key ID and Secret Access Key. All other * configuration, such as the service endpoints, are performed * automatically. Client parameters, such as proxies, can be specified in an * optional ClientConfiguration object when constructing a client. * * @see com.amazonaws.auth.BasicAWSCredentials * @see com.amazonaws.auth.ProfilesConfigFile * @see com.amazonaws.ClientConfiguration *//* w w w. j a v a 2 s . c om*/ private static void init() throws Exception { /* * The ProfileCredentialsProvider will return your [New US East * (Virginia) Profile] credential profile by reading from the * credentials file located at (). */ // AWSCredentials credentials = null; AWSCredentialsProvider credentialsProvider = null; try { credentialsProvider = new ClasspathPropertiesFileCredentialsProvider(); // credentials = new ProfileCredentialsProvider( // "New US East (Virginia) Profile").getCredentials(); } catch (Exception e) { throw new AmazonClientException( // "Cannot load the credentials from the credential profiles file. " // + "Please make sure that your credentials file is at the correct " // + "location (), and is in valid format.", e); } dynamoDB = new AmazonDynamoDBClient(credentialsProvider); Region usEast1 = Region.getRegion(Regions.US_EAST_1); dynamoDB.setRegion(usEast1); }
From source file:org.apache.airavata.core.gfac.provider.impl.EC2Provider.java
License:Apache License
private List<Instance> startInstances(AmazonEC2Client ec2, String AMI_ID, String INS_TYPE, ExecutionContext executionContext) throws AmazonServiceException { // start only 1 instance RunInstancesRequest request = new RunInstancesRequest(AMI_ID, 1, 1); request.setKeyName(KEY_PAIR_NAME);/*from w w w. j a v a 2s . c o m*/ request.setInstanceType(INS_TYPE); RunInstancesResult result = ec2.runInstances(request); List<Instance> instances = result.getReservation().getInstances(); while (!allInstancesStateEqual(instances, InstanceStateName.Running)) { // instance status should not be Terminated if (anyInstancesStateEqual(instances, InstanceStateName.Terminated)) { throw new AmazonClientException("Some Instance is terminated before running a job"); } // notify the status for (Instance ins : instances) { // TODO //executionContext.getNotificationService().info("EC2 Instance " +ins.getInstanceId() + " is " + ins.getState().getName().toString()); } try { Thread.sleep(SLEEP_TIME_SECOND * 1000l); } catch (Exception ex) { // no op } DescribeInstancesRequest describeInstancesRequest = new DescribeInstancesRequest(); describeInstancesRequest.setInstanceIds(getInstanceIDs(instances)); DescribeInstancesResult describeInstancesResult = ec2.describeInstances(describeInstancesRequest); instances = describeInstancesResult.getReservations().get(0).getInstances(); } log.info("All instances is running"); return instances; }
From source file:org.apache.airavata.gfac.ec2.util.AmazonEC2Util.java
License:Apache License
/** * Starts an Amazon instance with the given information. * * @param ec2 Amazon ec2 client//from w w w . j a v a2s . com * @param amiId Amazon Machine Image (AMI) id * @param insType Instance type * @param jobExecutionContext Job Execution context * @param keyPairName Key pair name * @return list of instances * @throws AmazonServiceException AmazonServiceException */ public static List<Instance> startInstances(AmazonEC2Client ec2, String amiId, String insType, JobExecutionContext jobExecutionContext, String keyPairName) throws AmazonServiceException { // start only 1 instance RunInstancesRequest request = new RunInstancesRequest(amiId, 1, 1); request.setKeyName(keyPairName); request.setInstanceType(insType); RunInstancesResult result = ec2.runInstances(request); List<Instance> instances = result.getReservation().getInstances(); while (!allInstancesStateEqual(instances, InstanceStateName.Running)) { // instance status should not be Terminated if (anyInstancesStateEqual(instances, InstanceStateName.Terminated)) { throw new AmazonClientException("Some Instance is terminated before running a job"); } // notify the status for (Instance ins : instances) { jobExecutionContext.getNotificationService().publish(new EC2ProviderEvent( "EC2 Instance " + ins.getInstanceId() + " is " + ins.getState().getName())); } try { Thread.sleep(SLEEP_TIME_SECOND * 1000l); } catch (Exception ex) { // no op } DescribeInstancesRequest describeInstancesRequest = new DescribeInstancesRequest(); describeInstancesRequest.setInstanceIds(getInstanceIDs(instances)); DescribeInstancesResult describeInstancesResult = ec2.describeInstances(describeInstancesRequest); instances = describeInstancesResult.getReservations().get(0).getInstances(); } return instances; }
From source file:org.apache.beam.sdk.io.kinesis.auth.BasicAWSCredentialsProvider.java
License:Open Source License
public AWSCredentials getCredentials() { if (!StringUtils.isEmpty(this.accessKey) && !StringUtils.isEmpty(this.secretKey)) { return new BasicAWSCredentials(this.accessKey, this.secretKey); } else {/*ww w. ja v a 2s.co m*/ throw new AmazonClientException("Access key or secret key is null"); } }
From source file:org.apache.druid.common.aws.ConfigDrivenAwsCredentialsConfigProvider.java
License:Apache License
@Override public AWSCredentials getCredentials() { final String key = config.getAccessKey().getPassword(); final String secret = config.getSecretKey().getPassword(); if (!Strings.isNullOrEmpty(key) && !Strings.isNullOrEmpty(secret)) { return new AWSCredentials() { @Override// w ww .java 2s.com public String getAWSAccessKeyId() { return key; } @Override public String getAWSSecretKey() { return secret; } }; } throw new AmazonClientException("Unable to load AWS credentials from druid AWSCredentialsConfig"); }
From source file:org.apache.hadoop.dynamodb.DynamoDBClient.java
License:Open Source License
/** * @param roomNeeded number of bytes that writeBatch MUST make room for *///from w w w. j a v a 2s . c o m private BatchWriteItemResult writeBatch(Reporter reporter, final int roomNeeded) { final BatchWriteItemRequest batchWriteItemRequest = new BatchWriteItemRequest() .withRequestItems(writeBatchMap).withReturnConsumedCapacity(ReturnConsumedCapacity.TOTAL); RetryResult<BatchWriteItemResult> retryResult = getRetryDriver() .runWithRetry(new Callable<BatchWriteItemResult>() { @Override public BatchWriteItemResult call() throws UnsupportedEncodingException, InterruptedException { pauseExponentially(batchWriteRetries); BatchWriteItemResult result = dynamoDB.batchWriteItem(batchWriteItemRequest); Map<String, List<WriteRequest>> unprocessedItems = result.getUnprocessedItems(); if (unprocessedItems == null || unprocessedItems.isEmpty()) { batchWriteRetries = 0; } else { batchWriteRetries++; int unprocessedItemCount = 0; for (List<WriteRequest> unprocessedWriteRequests : unprocessedItems.values()) { unprocessedItemCount += unprocessedWriteRequests.size(); int batchSizeBytes = 0; for (WriteRequest request : unprocessedWriteRequests) { batchSizeBytes += DynamoDBUtil .getItemSizeBytes(request.getPutRequest().getItem()); } long maxItemsPerBatch = config.getLong(MAX_ITEMS_PER_BATCH, DEFAULT_MAX_ITEMS_PER_BATCH); long maxBatchSize = config.getLong(MAX_BATCH_SIZE, DEFAULT_MAX_BATCH_SIZE); if (unprocessedWriteRequests.size() >= maxItemsPerBatch || (maxBatchSize - batchSizeBytes) < roomNeeded) { throw new AmazonClientException("Full list of write requests not processed"); } } double consumed = 0.0; for (ConsumedCapacity consumedCapacity : result.getConsumedCapacity()) { consumed = consumedCapacity.getCapacityUnits(); } int batchSize = 0; for (List<WriteRequest> writeRequests : batchWriteItemRequest.getRequestItems() .values()) { batchSize += writeRequests.size(); } log.debug("BatchWriteItem attempted " + batchSize + " items, consumed " + consumed + " " + "wcu, left unprocessed " + unprocessedItemCount + " items," + " " + "now at " + "" + batchWriteRetries + " retries"); } return result; } }, reporter, PrintCounter.DynamoDBWriteThrottle); writeBatchMap.clear(); writeBatchMapSizeBytes = 0; // If some items failed to go through, add them back to the writeBatchMap Map<String, List<WriteRequest>> unprocessedItems = retryResult.result.getUnprocessedItems(); for (Entry<String, List<WriteRequest>> entry : unprocessedItems.entrySet()) { String key = entry.getKey(); List<WriteRequest> requests = entry.getValue(); for (WriteRequest request : requests) { writeBatchMapSizeBytes += DynamoDBUtil.getItemSizeBytes(request.getPutRequest().getItem()); } writeBatchMap.put(key, requests); } return retryResult.result; }
From source file:org.apache.hadoop.fs.s3a.AWSCredentialProviderList.java
License:Apache License
/** * Verify that the provider list is not empty. * @throws AmazonClientException if there are no providers. */// www . j a v a 2 s .c o m public void checkNotEmpty() { if (providers.isEmpty()) { throw new AmazonClientException(NO_AWS_CREDENTIAL_PROVIDERS); } }