List of usage examples for com.amazonaws.event ProgressEventType TRANSFER_FAILED_EVENT
ProgressEventType TRANSFER_FAILED_EVENT
To view the source code for com.amazonaws.event ProgressEventType TRANSFER_FAILED_EVENT.
Click Source Link
From source file:com.vmware.photon.controller.model.adapters.awsadapter.AWSCostStatsService.java
License:Open Source License
private void downloadAndParse(AWSCostStatsCreationContext statsData, String awsBucketname, int year, int month, AWSCostStatsCreationStages next) throws IOException { // Creating a working directory for downloanding and processing the bill final Path workingDirPath = Paths.get(System.getProperty(TEMP_DIR_LOCATION), UUID.randomUUID().toString()); Files.createDirectories(workingDirPath); String accountId = statsData.computeDesc.customProperties.getOrDefault(AWSConstants.AWS_ACCOUNT_ID_KEY, null);//from w w w . j a v a2s. c o m AWSCsvBillParser parser = new AWSCsvBillParser(); final String csvBillZipFileName = parser.getCsvBillFileName(month, year, accountId, true); Path csvBillZipFilePath = Paths.get(workingDirPath.toString(), csvBillZipFileName); GetObjectRequest getObjectRequest = new GetObjectRequest(awsBucketname, csvBillZipFileName); Download download = statsData.s3Client.download(getObjectRequest, csvBillZipFilePath.toFile()); final StatelessService service = this; download.addProgressListener(new ProgressListener() { @Override public void progressChanged(ProgressEvent progressEvent) { try { ProgressEventType eventType = progressEvent.getEventType(); if (ProgressEventType.TRANSFER_COMPLETED_EVENT.equals(eventType)) { LocalDate monthDate = new LocalDate(year, month, 1); statsData.accountDetailsMap = parser.parseDetailedCsvBill(statsData.ignorableInvoiceCharge, csvBillZipFilePath, monthDate); deleteTempFiles(); OperationContext.restoreOperationContext(statsData.opContext); statsData.stage = next; handleCostStatsCreationRequest(statsData); } else if (ProgressEventType.TRANSFER_FAILED_EVENT.equals(eventType)) { deleteTempFiles(); throw new IOException("Download of AWS CSV Bill '" + csvBillZipFileName + "' failed."); } } catch (IOException e) { logSevere(e); AdapterUtils.sendFailurePatchToProvisioningTask(service, statsData.statsRequest.taskReference, e); } } private void deleteTempFiles() { try { Files.deleteIfExists(csvBillZipFilePath); Files.deleteIfExists(workingDirPath); } catch (IOException e) { // Ignore IO exception while cleaning files. } } }); }
From source file:modules.storage.AmazonS3Storage.java
License:Open Source License
@Override public F.Promise<Void> store(Path path, String key, String name) { Promise<Void> promise = Futures.promise(); TransferManager transferManager = new TransferManager(credentials); try {//from w w w .ja v a 2s . c om Upload upload = transferManager.upload(bucketName, key, path.toFile()); upload.addProgressListener((ProgressListener) progressEvent -> { if (progressEvent.getEventType().isTransferEvent()) { if (progressEvent.getEventType().equals(ProgressEventType.TRANSFER_COMPLETED_EVENT)) { transferManager.shutdownNow(); promise.success(null); } else if (progressEvent.getEventType().equals(ProgressEventType.TRANSFER_FAILED_EVENT)) { transferManager.shutdownNow(); logger.error(progressEvent.toString()); promise.failure(new Exception(progressEvent.toString())); } } }); } catch (AmazonServiceException ase) { logAmazonServiceException(ase); } catch (AmazonClientException ace) { logAmazonClientException(ace); } return F.Promise.wrap(promise.future()); }
From source file:modules.storage.AmazonS3Storage.java
License:Open Source License
@Override public F.Promise<Void> delete(String key, String name) { Promise<Void> promise = Futures.promise(); AmazonS3 amazonS3 = new AmazonS3Client(credentials); DeleteObjectRequest request = new DeleteObjectRequest(bucketName, key); request.withGeneralProgressListener(progressEvent -> { if (progressEvent.getEventType().isTransferEvent()) { if (progressEvent.getEventType().equals(ProgressEventType.TRANSFER_COMPLETED_EVENT)) { promise.success(null);/*from w w w.j av a 2s. co m*/ } else if (progressEvent.getEventType().equals(ProgressEventType.TRANSFER_FAILED_EVENT)) { logger.error(progressEvent.toString()); promise.failure(new Exception(progressEvent.toString())); } } }); try { amazonS3.deleteObject(request); } catch (AmazonServiceException ase) { logAmazonServiceException(ase); } catch (AmazonClientException ace) { logAmazonClientException(ace); } return F.Promise.wrap(promise.future()); }