List of usage examples for com.amazonaws AmazonServiceException getErrorType
public ErrorType getErrorType()
From source file:com.netflix.dynomitemanager.sidecore.backup.S3Backup.java
License:Apache License
/** * Uses the Amazon S3 API to upload the AOF/RDB to S3 * Filename: Backup location + DC + Rack + App + Token *///ww w. j av a 2s .c o m @Override public boolean upload(File file, DateTime todayStart) { logger.info("Snapshot backup: sending " + file.length() + " bytes to S3"); /* Key name is comprised of the * backupDir + DC + Rack + token + Date */ String keyName = config.getBackupLocation() + "/" + iid.getInstance().getDatacenter() + "/" + iid.getInstance().getRack() + "/" + iid.getInstance().getToken() + "/" + todayStart.getMillis(); // Get bucket location. logger.info("Key in Bucket: " + keyName); logger.info("S3 Bucket Name:" + config.getBucketName()); AmazonS3Client s3Client = new AmazonS3Client(cred.getAwsCredentialProvider()); try { // Checking if the S3 bucket exists, and if does not, then we create it if (!(s3Client.doesBucketExist(config.getBucketName()))) { logger.error("Bucket with name: " + config.getBucketName() + " does not exist"); return false; } else { logger.info("Uploading data to S3\n"); // Create a list of UploadPartResponse objects. You get one of these for // each part upload. List<PartETag> partETags = new ArrayList<PartETag>(); InitiateMultipartUploadRequest initRequest = new InitiateMultipartUploadRequest( config.getBucketName(), keyName); InitiateMultipartUploadResult initResponse = s3Client.initiateMultipartUpload(initRequest); long contentLength = file.length(); long filePosition = 0; long partSize = this.initPartSize; try { for (int i = 1; filePosition < contentLength; i++) { // Last part can be less than initPartSize (500MB). Adjust part size. partSize = Math.min(partSize, (contentLength - filePosition)); // Create request to upload a part. UploadPartRequest uploadRequest = new UploadPartRequest() .withBucketName(config.getBucketName()).withKey(keyName) .withUploadId(initResponse.getUploadId()).withPartNumber(i) .withFileOffset(filePosition).withFile(file).withPartSize(partSize); // Upload part and add response to our list. partETags.add(s3Client.uploadPart(uploadRequest).getPartETag()); filePosition += partSize; } CompleteMultipartUploadRequest compRequest = new CompleteMultipartUploadRequest( config.getBucketName(), keyName, initResponse.getUploadId(), partETags); s3Client.completeMultipartUpload(compRequest); } catch (Exception e) { logger.error("Abosting multipart upload due to error"); s3Client.abortMultipartUpload(new AbortMultipartUploadRequest(config.getBucketName(), keyName, initResponse.getUploadId())); } return true; } } catch (AmazonServiceException ase) { logger.error( "AmazonServiceException;" + " request made it to Amazon S3, but was rejected with an error "); logger.error("Error Message: " + ase.getMessage()); logger.error("HTTP Status Code: " + ase.getStatusCode()); logger.error("AWS Error Code: " + ase.getErrorCode()); logger.error("Error Type: " + ase.getErrorType()); logger.error("Request ID: " + ase.getRequestId()); return false; } catch (AmazonClientException ace) { logger.error("AmazonClientException;" + " the client encountered " + "an internal error while trying to " + "communicate with S3, "); logger.error("Error Message: " + ace.getMessage()); return false; } }
From source file:com.netflix.dynomitemanager.sidecore.backup.S3Restore.java
License:Apache License
/** * Uses the Amazon S3 API to restore from S3 *//*w w w . j a v a 2 s. c o m*/ @Override public boolean restoreData(String dateString) { long time = restoreTime(dateString); if (time > -1) { logger.info("Restoring data from S3."); AmazonS3Client s3Client = new AmazonS3Client(cred.getAwsCredentialProvider()); try { /* construct the key for the backup data */ String keyName = config.getBackupLocation() + "/" + iid.getInstance().getDatacenter() + "/" + iid.getInstance().getRack() + "/" + iid.getInstance().getToken() + "/" + time; logger.info("S3 Bucket Name: " + config.getBucketName()); logger.info("Key in Bucket: " + keyName); // Checking if the S3 bucket exists, and if does not, then we create it if (!(s3Client.doesBucketExist(config.getBucketName()))) { logger.error("Bucket with name: " + config.getBucketName() + " does not exist"); } else { S3Object s3object = s3Client.getObject(new GetObjectRequest(config.getBucketName(), keyName)); logger.info("Content-Type: " + s3object.getObjectMetadata().getContentType()); String filepath = null; if (config.isAof()) { filepath = config.getPersistenceLocation() + "/appendonly.aof"; } else { filepath = config.getPersistenceLocation() + "/nfredis.rdb"; } IOUtils.copy(s3object.getObjectContent(), new FileOutputStream(new File(filepath))); } return true; } catch (AmazonServiceException ase) { logger.error("AmazonServiceException;" + " request made it to Amazon S3, but was rejected with an error "); logger.error("Error Message: " + ase.getMessage()); logger.error("HTTP Status Code: " + ase.getStatusCode()); logger.error("AWS Error Code: " + ase.getErrorCode()); logger.error("Error Type: " + ase.getErrorType()); logger.error("Request ID: " + ase.getRequestId()); } catch (AmazonClientException ace) { logger.error("AmazonClientException;" + " the client encountered " + "an internal error while trying to " + "communicate with S3, "); logger.error("Error Message: " + ace.getMessage()); } catch (IOException io) { logger.error("File storing error: " + io.getMessage()); } } else { logger.error("Date in FP: " + dateString); } return false; }
From source file:com.netflix.spinnaker.kork.aws.AwsMetricsSupport.java
License:Apache License
static String[] buildExceptionTags(AmazonWebServiceRequest originalRequest, Exception exception) { final AmazonServiceException ase = amazonServiceException(exception); String targetAccountId = DEFAULT_UNKNOWN; if (ase.getHttpHeaders() != null) { targetAccountId = ase.getHttpHeaders().get("targetAccountId"); }//from ww w . j a v a 2s . com return new String[] { "requestType", originalRequest.getClass().getSimpleName(), "statusCode", Integer.toString(ase.getStatusCode()), "errorCode", Optional.ofNullable(ase.getErrorCode()).orElse(DEFAULT_UNKNOWN), "serviceName", Optional.ofNullable(ase.getServiceName()).orElse(DEFAULT_UNKNOWN), "errorType", Optional.ofNullable(ase.getErrorType()).orElse(AmazonServiceException.ErrorType.Unknown).name(), "accountId", Optional.ofNullable(targetAccountId).orElse(DEFAULT_UNKNOWN) }; }
From source file:com.neu.cloud.Controller.FifthUseCaseController.java
private void uploadInS3(String uploadFilePath, String uploadFileName, String dateForFolder) { String bucketName = "reports-sppard"; String keyName = "UseCase5-" + dateForFolder + "/" + uploadFileName; AmazonS3 s3client = new AmazonS3Client( new BasicAWSCredentials("AKIAJ2E67YVFQ5PZSWQA", "xiVuejpUofGonrsiy2owvu/wgeNKq5nYjxYVC0ma")); try {//from w w w .j a va2s. c o m System.out.println("Uploading a new object to S3 from a file\n"); File file = new File(uploadFilePath + uploadFileName); s3client.putObject(new PutObjectRequest(bucketName, keyName, file)); } catch (AmazonServiceException ase) { System.out.println("Caught an AmazonServiceException, which " + "means your request made it " + "to Amazon S3, but was rejected with an error response" + " for some reason."); System.out.println("Error Message: " + ase.getMessage()); System.out.println("HTTP Status Code: " + ase.getStatusCode()); System.out.println("AWS Error Code: " + ase.getErrorCode()); System.out.println("Error Type: " + ase.getErrorType()); System.out.println("Request ID: " + ase.getRequestId()); } catch (AmazonClientException ace) { System.out.println("Caught an AmazonClientException, which " + "means the client encountered " + "an internal error while trying to " + "communicate with S3, " + "such as not being able to access the network."); System.out.println("Error Message: " + ace.getMessage()); } }
From source file:com.neu.cloud.Controller.FirstUseCaseController.java
private void uploadInS3(String uploadFilePath, String uploadFileName, String dateForFolder) { String bucketName = "reports-sppard"; String keyName = "UseCase1-" + dateForFolder + "/" + uploadFileName; AmazonS3 s3client = new AmazonS3Client( new BasicAWSCredentials("AKIAJ2E67YVFQ5PZSWQA", "xiVuejpUofGonrsiy2owvu/wgeNKq5nYjxYVC0ma")); try {//from w ww. j a v a 2s .c o m System.out.println("Uploading a new object to S3 from a file\n"); File file = new File(uploadFilePath + uploadFileName); s3client.putObject(new PutObjectRequest(bucketName, keyName, file)); } catch (AmazonServiceException ase) { System.out.println("Caught an AmazonServiceException, which " + "means your request made it " + "to Amazon S3, but was rejected with an error response" + " for some reason."); System.out.println("Error Message: " + ase.getMessage()); System.out.println("HTTP Status Code: " + ase.getStatusCode()); System.out.println("AWS Error Code: " + ase.getErrorCode()); System.out.println("Error Type: " + ase.getErrorType()); System.out.println("Request ID: " + ase.getRequestId()); } catch (AmazonClientException ace) { System.out.println("Caught an AmazonClientException, which " + "means the client encountered " + "an internal error while trying to " + "communicate with S3, " + "such as not being able to access the network."); System.out.println("Error Message: " + ace.getMessage()); } }
From source file:com.neu.cloud.Controller.FourthUseCaseController.java
private void uploadInS3(String uploadFilePath, String uploadFileName, String dateForFolder) { String bucketName = "reports-sppard"; String keyName = "UseCase4-" + dateForFolder + "/" + uploadFileName; AmazonS3 s3client = new AmazonS3Client( new BasicAWSCredentials("AKIAJ2E67YVFQ5PZSWQA", "xiVuejpUofGonrsiy2owvu/wgeNKq5nYjxYVC0ma")); try {/* ww w.ja v a2 s . c o m*/ System.out.println("Uploading a new object to S3 from a file\n"); File file = new File(uploadFilePath + uploadFileName); s3client.putObject(new PutObjectRequest(bucketName, keyName, file)); } catch (AmazonServiceException ase) { System.out.println("Caught an AmazonServiceException, which " + "means your request made it " + "to Amazon S3, but was rejected with an error response" + " for some reason."); System.out.println("Error Message: " + ase.getMessage()); System.out.println("HTTP Status Code: " + ase.getStatusCode()); System.out.println("AWS Error Code: " + ase.getErrorCode()); System.out.println("Error Type: " + ase.getErrorType()); System.out.println("Request ID: " + ase.getRequestId()); } catch (AmazonClientException ace) { System.out.println("Caught an AmazonClientException, which " + "means the client encountered " + "an internal error while trying to " + "communicate with S3, " + "such as not being able to access the network."); System.out.println("Error Message: " + ace.getMessage()); } }
From source file:com.neu.cloud.Controller.SecondUseCaseController.java
private void uploadInS3(String uploadFilePath, String uploadFileName, String dateForFolder) { String bucketName = "reports-sppard"; String keyName = "UseCase2-" + dateForFolder + "/" + uploadFileName; AmazonS3 s3client = new AmazonS3Client( new BasicAWSCredentials("AKIAJ2E67YVFQ5PZSWQA", "xiVuejpUofGonrsiy2owvu/wgeNKq5nYjxYVC0ma")); try {//w w w .j a v a 2 s .c o m System.out.println("Uploading a new object to S3 from a file\n"); File file = new File(uploadFilePath + uploadFileName); s3client.putObject(new PutObjectRequest(bucketName, keyName, file)); } catch (AmazonServiceException ase) { System.out.println("Caught an AmazonServiceException, which " + "means your request made it " + "to Amazon S3, but was rejected with an error response" + " for some reason."); System.out.println("Error Message: " + ase.getMessage()); System.out.println("HTTP Status Code: " + ase.getStatusCode()); System.out.println("AWS Error Code: " + ase.getErrorCode()); System.out.println("Error Type: " + ase.getErrorType()); System.out.println("Request ID: " + ase.getRequestId()); } catch (AmazonClientException ace) { System.out.println("Caught an AmazonClientException, which " + "means the client encountered " + "an internal error while trying to " + "communicate with S3, " + "such as not being able to access the network."); System.out.println("Error Message: " + ace.getMessage()); } }
From source file:com.neu.cloud.Controller.ThirdUseCaseController.java
private void uploadInS3(String uploadFilePath, String uploadFileName, String dateForFolder) { String bucketName = "reports-sppard"; String keyName = "UseCase3-" + dateForFolder + "/" + uploadFileName; AmazonS3 s3client = new AmazonS3Client( new BasicAWSCredentials("AKIAJ2E67YVFQ5PZSWQA", "xiVuejpUofGonrsiy2owvu/wgeNKq5nYjxYVC0ma")); try {//from w w w . j a v a 2 s . co m System.out.println("Uploading a new object to S3 from a file\n"); File file = new File(uploadFilePath + uploadFileName); s3client.putObject(new PutObjectRequest(bucketName, keyName, file)); } catch (AmazonServiceException ase) { System.out.println("Caught an AmazonServiceException, which " + "means your request made it " + "to Amazon S3, but was rejected with an error response" + " for some reason."); System.out.println("Error Message: " + ase.getMessage()); System.out.println("HTTP Status Code: " + ase.getStatusCode()); System.out.println("AWS Error Code: " + ase.getErrorCode()); System.out.println("Error Type: " + ase.getErrorType()); System.out.println("Request ID: " + ase.getRequestId()); } catch (AmazonClientException ace) { System.out.println("Caught an AmazonClientException, which " + "means the client encountered " + "an internal error while trying to " + "communicate with S3, " + "such as not being able to access the network."); System.out.println("Error Message: " + ace.getMessage()); } }
From source file:com.onemenu.server.util.awsnotification.SNSMobilePush.java
License:Open Source License
public static void pushIOSNotification(String message, String deviceToken, Map<String, Object> customData, int badge) throws IOException { AmazonSNS sns = new AmazonSNSClient(new PropertiesCredentials( SNSMobilePush.class.getClassLoader().getResourceAsStream("AwsCredentials.properties"))); sns.setEndpoint("https://sns.us-west-2.amazonaws.com"); if (logger.isDebugEnabled()) { logger.debug("===========================================\n"); logger.debug("Getting Started with Amazon SNS IOS"); logger.debug("===========================================\n"); }//from w ww .j a v a2 s.c o m try { SNSMobilePush push = new SNSMobilePush(sns); String applicationName = ConfigCache.getValue(ConfigKey.APPLICATION_NAME, "One-Menu"); String _message = MessageGenerator.getAppleMessage(message, null, badge, customData); boolean isSandBox = Boolean.parseBoolean(ConfigCache.getValue(ConfigKey.IS_SAND_BOX, "true")); Platform platform = null; String Certificate = null; String Private_Key = null; if (isSandBox) { platform = Platform.APNS_SANDBOX; Certificate = S_Certificate; Private_Key = S_Private_Key; } else { platform = Platform.APNS; Certificate = P_Certificate; Private_Key = P_Private_Key; } push.snsClientWrapper.notification(platform, Certificate, Private_Key, deviceToken, applicationName, attributesMap, _message); } catch (AmazonServiceException ase) { logger.error("Caught an AmazonServiceException, which means your request made it " + "to Amazon SNS, but was rejected with an error response for some reason."); logger.error("Error Message: " + ase.getMessage()); logger.error("HTTP Status Code: " + ase.getStatusCode()); logger.error("AWS Error Code: " + ase.getErrorCode()); logger.error("Error Type: " + ase.getErrorType()); logger.error("Request ID: " + ase.getRequestId()); } catch (AmazonClientException ace) { logger.error("Caught an AmazonClientException, which means the client encountered " + "a serious internal problem while trying to communicate with SNS, such as not " + "being able to access the network."); logger.error("Error Message: " + ace.getMessage()); } }
From source file:com.onemenu.server.util.awsnotification.SNSMobilePush.java
License:Open Source License
public static void pushAndroidNotification(String message, String deviceToken, Map<String, Object> customData) throws IOException { AmazonSNS sns = new AmazonSNSClient(new PropertiesCredentials( SNSMobilePush.class.getClassLoader().getResourceAsStream("AwsCredentials.properties"))); sns.setEndpoint("https://sns.us-west-2.amazonaws.com"); if (logger.isDebugEnabled()) { logger.debug("===========================================\n"); logger.debug("Getting Started with Amazon SNS android"); logger.debug("===========================================\n"); }// ww w. j a v a 2 s . c o m try { SNSMobilePush push = new SNSMobilePush(sns); String applicationName = ConfigCache.getValue(ConfigKey.APPLICATION_NAME, "One-Menu"); String serverAPIKey = ""; String _message = MessageGenerator.getSampleAndroidMessage("NewOrder", message, customData); push.snsClientWrapper.notification(Platform.GCM, "", serverAPIKey, deviceToken, applicationName, attributesMap, _message); } catch (AmazonServiceException ase) { logger.error("Caught an AmazonServiceException, which means your request made it " + "to Amazon SNS, but was rejected with an error response for some reason."); logger.error("Error Message: " + ase.getMessage()); logger.error("HTTP Status Code: " + ase.getStatusCode()); logger.error("AWS Error Code: " + ase.getErrorCode()); logger.error("Error Type: " + ase.getErrorType()); logger.error("Request ID: " + ase.getRequestId()); } catch (AmazonClientException ace) { logger.error("Caught an AmazonClientException, which means the client encountered " + "a serious internal problem while trying to communicate with SNS, such as not " + "being able to access the network."); logger.error("Error Message: " + ace.getMessage()); } }