List of usage examples for com.amazonaws.services.s3 AmazonS3Client AmazonS3Client
@SdkInternalApi AmazonS3Client(AmazonS3ClientParams s3ClientParams)
From source file:org.apache.usergrid.apm.service.CrashUtil.java
License:Apache License
public static String getCrashSummary(String fullAppName, String s3CrashFileName) { DeploymentConfig config = DeploymentConfig.geDeploymentConfig(); AWSCredentials credentials = new BasicAWSCredentials(config.getAccessKey(), config.getSecretKey()); AmazonS3Client s3Client = new AmazonS3Client(credentials); String s3FullFileName = AWSUtil.formS3CrashFileUrl(fullAppName, s3CrashFileName); log.info("Crash file bucket " + config.getS3LogBucket() + " and file name : " + s3FullFileName); GetObjectRequest objectRequest = new GetObjectRequest(config.getS3LogBucket(), s3FullFileName); String crashSummary = null;//from w w w . j a v a 2s .c om try { S3Object s3Object = s3Client.getObject(objectRequest); InputStream is = s3Object.getObjectContent(); String fileContents = IOUtils.toString(is); CrashLogParser parser = null; if (fileContents != null) { if (s3CrashFileName.endsWith(".crash")) { parser = new iOSCrashLogParser(); if (parser.parseCrashLog(fileContents)) crashSummary = parser.getCrashSummary(); else { log.error("problem parsing ios crash file for app " + fullAppName + " file: " + s3CrashFileName); crashSummary = "Not able to get summary for iOS crash log"; } } else if (s3CrashFileName.endsWith(".stacktrace")) { parser = new AndroidCrashLogParser(); if (parser.parseCrashLog(fileContents)) crashSummary = parser.getCrashSummary(); else { log.error("problem parsing Android crash file for app " + fullAppName + " file: " + s3CrashFileName); crashSummary = "Not able to get summary for Android crash log"; } } } } catch (AmazonServiceException e1) { e1.printStackTrace(); log.error("Promblem downloading crash file from S3 for " + s3FullFileName, e1); } catch (Exception e) { e.printStackTrace(); log.error("Promblem downloading crash file from S3 for S3 for " + s3FullFileName, e); } log.info("Crash summary " + crashSummary); if (crashSummary != null && crashSummary.length() > 250) { crashSummary = crashSummary.substring(0, 249); } return crashSummary; }
From source file:org.apache.usergrid.apm.service.ServiceFactory.java
License:Apache License
/** @return the applicationService */ public static ApplicationService getApplicationService() { if (applicationService == null) { ApplicationServiceImpl applicationServiceImpl = new ApplicationServiceImpl(); String accessKey = DeploymentConfig.geDeploymentConfig().getAccessKey(); String secretKey = DeploymentConfig.geDeploymentConfig().getSecretKey(); AWSCredentials awsCredentials = new BasicAWSCredentials(accessKey, secretKey); AmazonSQSClient sqsClient = getSQSClient(); AmazonS3 s3Client = new AmazonS3Client(awsCredentials); AmazonIdentityManagementClient identityManagementClient = new AmazonIdentityManagementClient( awsCredentials);/*w w w . ja v a 2 s . c o m*/ applicationServiceImpl.setAwsCredentials(awsCredentials); applicationServiceImpl.setSqsClient(sqsClient); applicationServiceImpl.setS3Client(s3Client); applicationServiceImpl.setXStream(ServiceFactory.getAppConfigXStream()); applicationServiceImpl.setIdentityManagementClient(identityManagementClient); applicationService = applicationServiceImpl; } return applicationService; }
From source file:org.apache.usergrid.apm.util.AwsS3Util.java
License:Apache License
public static String generatePresignedURL(String appId, String fileName) { DeploymentConfig config = DeploymentConfig.geDeploymentConfig(); AWSCredentials credentials = new BasicAWSCredentials(config.getAccessKey(), config.getSecretKey()); AmazonS3Client client = new AmazonS3Client(credentials); String env = config.getEnvironment(); String s3FullFileName = env + "/crashlog/" + appId + "/" + fileName; GeneratePresignedUrlRequest request = new GeneratePresignedUrlRequest(config.getS3LogBucket(), s3FullFileName, HttpMethod.GET); request.setExpiration(new Date(System.currentTimeMillis() + (120 * 60 * 1000))); //expires in 2 hour return client.generatePresignedUrl(request).toString(); }
From source file:org.apache.usergrid.apm.util.CrashLogUploadToS3Simulator.java
License:Apache License
public static boolean uploadSimulatedCrashLogsToS3(String appId, String fileName) { DeploymentConfig config = DeploymentConfig.geDeploymentConfig(); AWSCredentials credentials = new BasicAWSCredentials(config.getAccessKey(), config.getSecretKey()); AmazonS3Client s3Client = new AmazonS3Client(credentials); PutObjectRequest putObjectRequest;/*from ww w . j a va 2 s . c om*/ String s3FullFileName = config.getEnvironment() + "/crashlog/" + appId + "/" + fileName; try { ObjectMetadata metaData = new ObjectMetadata(); metaData.setHeader(Headers.S3_CANNED_ACL, CannedAccessControlList.AuthenticatedRead); putObjectRequest = new PutObjectRequest(config.getS3LogBucket(), s3FullFileName, new ByteArrayInputStream(fileName.getBytes("UTF-8")), null); PutObjectResult result = s3Client.putObject(putObjectRequest); return true; } catch (UnsupportedEncodingException e) { e.printStackTrace(); } return false; }
From source file:org.apache.usergrid.apm.util.GenerateSimulatedMobileData.java
License:Apache License
public static boolean uploadSimulatedCrashLogsToS3(App app, String fileName) { DeploymentConfig config = DeploymentConfig.geDeploymentConfig(); AWSCredentials credentials = new BasicAWSCredentials(config.getAccessKey(), config.getSecretKey()); AmazonS3Client s3Client = new AmazonS3Client(credentials); PutObjectRequest putObjectRequest;// w ww . jav a 2 s.c om String s3FullFileName = config.getEnvironment() + "/" + config.getS3CrashLogFolder() + "/" + app.getFullAppName() + "/" + fileName; String sampleCrashFileName = null; if (fileName.endsWith(".crash")) //it's an iOS crash file sampleCrashFileName = "ios-crash-log-example.txt"; else if (fileName.endsWith(".stacktrace")) sampleCrashFileName = "android-crash-log-example.txt"; try { ObjectMetadata metaData = new ObjectMetadata(); metaData.setHeader(Headers.S3_CANNED_ACL, CannedAccessControlList.AuthenticatedRead); InputStream is = Thread.currentThread().getContextClassLoader() .getResourceAsStream(sampleCrashFileName); putObjectRequest = new PutObjectRequest(config.getS3LogBucket(), s3FullFileName, is, null); //new ByteArrayInputStream( //fileName.getBytes("UTF-8")),null); PutObjectResult result = s3Client.putObject(putObjectRequest); return true; } catch (Exception e) { e.printStackTrace(); } return false; }
From source file:org.applicationMigrator.migrationclient.FileTransferClient.java
License:Apache License
public void downloadFiles(String outputFilesPaths[]) throws IOException, InterruptedException, ClassNotFoundException { if (outputFilesPaths == null) { return;/*www.ja va 2 s . com*/ } AWSCredentials awsCredentials = currentUser.getAwsCredentials(); Environment.getExternalStorageDirectory().setReadable(true, false); Environment.getExternalStorageDirectory().setWritable(true, false); for (String outputFilePath : outputFilesPaths) { String fileName = getFileName(outputFilePath); String userName = currentUser.getUserNameString(); String keyNameString = userName + "/" + applicationName + "/" + fileName; AmazonS3 s3client = new AmazonS3Client(awsCredentials); S3Object s3Object = s3client.getObject(new GetObjectRequest(BUCKET_NAME, keyNameString)); try { writeObjectToFile(s3Object, outputFilePath); File outputFile = new File(outputFilePath); outputFile.setReadable(true, false); outputFile.setWritable(true, false); } catch (Exception ignored) { } } }
From source file:org.applicationMigrator.migrationclient.FileTransferClient.java
License:Apache License
private void uploadFile(AWSCredentials awsCredentials, String sourcePathString, String destinationPathString, boolean forceUpload) throws FileNotFoundException { // TODO Think about one file being used by many apps (e.g HP1.pdf read // through Adobe reader and OpenOffice) AmazonS3 s3client = new AmazonS3Client(awsCredentials); boolean fileIsPresentOnServer = checkIfFileIsPresentOnServer(s3client, BUCKET_NAME, destinationPathString); if (fileIsPresentOnServer && !forceUpload) return;// w ww .j a v a 2 s . c om try { File file = new File(sourcePathString); if (!file.exists()) throw new FileNotFoundException(); s3client.putObject(new PutObjectRequest(BUCKET_NAME, destinationPathString, file)); } catch (AmazonServiceException ase) { throw ase; } catch (AmazonClientException ace) { throw ace; } // TODO:verify completion of upload operation }
From source file:org.applicationMigrator.serverAgent.ServerAgentFileTransferClient.java
License:Apache License
public void downloadFiles(String outputFilesPaths[], String credentialsFilePath) throws IOException, InterruptedException { if (outputFilesPaths == null) { return;/*from w ww. j av a2 s. com*/ } AWSCredentials awsCredentials = getCredentials(credentialsFilePath); Environment.getExternalStorageDirectory().setReadable(true, false); Environment.getExternalStorageDirectory().setWritable(true, false); for (String outputFilePath : outputFilesPaths) { String fileName = getFileName(outputFilePath); String keyNameString = userName + "/" + applicationName + "/" + fileName; AmazonS3 s3client = new AmazonS3Client(awsCredentials); S3Object s3Object = s3client.getObject(new GetObjectRequest(BUCKET_NAME, keyNameString)); try { writeObjectToFile(s3Object, outputFilePath); File outputFile = new File(outputFilePath); outputFile.setReadable(true, false); outputFile.setWritable(true, false); } catch (Exception e) { /*File erroneousFile = new File(outputFilePath); if (erroneousFile.exists()) erroneousFile.delete();*/ } } }
From source file:org.applicationMigrator.serverAgent.ServerAgentFileTransferClient.java
License:Apache License
private void uploadFile(AWSCredentials awsCredentials, String sourcePathString, String destinationPathString, boolean forceUpload) throws FileNotFoundException { // TODO Think about one file being used by many apps (e.g HP1.pdf read // through Adobe reader and OpenOffice) AmazonS3 s3client = new AmazonS3Client(awsCredentials); boolean fileIsPresentOnServer = checkIfFileIsPresentOnServer(s3client, BUCKET_NAME, destinationPathString); if (fileIsPresentOnServer && !forceUpload) return;//from w w w . ja va 2s . co m try { File file = new File(sourcePathString); if (!file.exists()) throw new FileNotFoundException(); s3client.putObject(new PutObjectRequest(BUCKET_NAME, destinationPathString, 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()); throw ase; } 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()); throw ace; } // TODO:verify completion of upload operation }
From source file:org.benetech.secureapp.generator.AmazonS3Utils.java
License:Open Source License
private static AmazonS3 getS3() throws S3Exception { String awsKey = getAwsKey();//from w w w .jav a2 s.co m if (awsKey == null) throw new S3Exception("AWS Key can not be null"); String awsSecret = getAwsSecret(); AmazonS3 s3client = new AmazonS3Client(new BasicAWSCredentials(awsKey, awsSecret)); return s3client; }