Search in sources :

Example 1 with ProgressEventType

use of com.amazonaws.event.ProgressEventType in project hadoop by apache.

the class ProgressableProgressListener method progressChanged.

@Override
public void progressChanged(ProgressEvent progressEvent) {
    if (progress != null) {
        progress.progress();
    }
    // There are 3 http ops here, but this should be close enough for now
    ProgressEventType pet = progressEvent.getEventType();
    if (pet == TRANSFER_PART_STARTED_EVENT || pet == TRANSFER_COMPLETED_EVENT) {
        fs.incrementWriteOperations();
    }
    long transferred = upload.getProgress().getBytesTransferred();
    long delta = transferred - lastBytesTransferred;
    fs.incrementPutProgressStatistics(key, delta);
    lastBytesTransferred = transferred;
}
Also used : ProgressEventType(com.amazonaws.event.ProgressEventType)

Example 2 with ProgressEventType

use of com.amazonaws.event.ProgressEventType in project photon-model by vmware.

the class AWSCostStatsService method downloadParseAndCreateStats.

private void downloadParseAndCreateStats(AWSCostStatsCreationContext statsData, String awsBucketName) throws IOException {
    try {
        // Creating a working directory for downloading and processing the bill
        final Path workingDirPath = Paths.get(System.getProperty(TEMP_DIR_LOCATION), UUID.randomUUID().toString());
        Files.createDirectories(workingDirPath);
        AWSCsvBillParser parser = new AWSCsvBillParser();
        final String csvBillZipFileName = parser.getCsvBillFileName(statsData.billMonthToDownload, statsData.accountId, true);
        Path csvBillZipFilePath = Paths.get(workingDirPath.toString(), csvBillZipFileName);
        ProgressListener listener = new ProgressListener() {

            @Override
            public void progressChanged(ProgressEvent progressEvent) {
                try {
                    ProgressEventType eventType = progressEvent.getEventType();
                    if (ProgressEventType.TRANSFER_COMPLETED_EVENT.equals(eventType)) {
                        OperationContext.restoreOperationContext(statsData.opContext);
                        LocalDate billMonth = new LocalDate(statsData.billMonthToDownload.getYear(), statsData.billMonthToDownload.getMonthOfYear(), 1);
                        logWithContext(statsData, Level.INFO, () -> String.format("Processing" + " bill for the month: %s.", billMonth));
                        parser.parseDetailedCsvBill(statsData.ignorableInvoiceCharge, csvBillZipFilePath, statsData.awsAccountIdToComputeStates.keySet(), getHourlyStatsConsumer(billMonth, statsData), getMonthlyStatsConsumer(billMonth, statsData));
                        deleteTempFiles();
                        // Continue downloading and processing the bills for past and current months' bills
                        statsData.billMonthToDownload = statsData.billMonthToDownload.plusMonths(1);
                        handleCostStatsCreationRequest(statsData);
                    } else if (ProgressEventType.TRANSFER_FAILED_EVENT.equals(eventType)) {
                        deleteTempFiles();
                        billDownloadFailureHandler(statsData, awsBucketName, new IOException("Download of AWS CSV Bill '" + csvBillZipFileName + "' failed."));
                    }
                } catch (Exception exception) {
                    deleteTempFiles();
                    billDownloadFailureHandler(statsData, awsBucketName, exception);
                }
            }

            private void deleteTempFiles() {
                try {
                    Files.deleteIfExists(csvBillZipFilePath);
                    Files.deleteIfExists(workingDirPath);
                } catch (IOException e) {
                // Ignore IO exception while cleaning files.
                }
            }
        };
        GetObjectRequest getObjectRequest = new GetObjectRequest(awsBucketName, csvBillZipFileName).withGeneralProgressListener(listener);
        statsData.s3Client.download(getObjectRequest, csvBillZipFilePath.toFile());
    } catch (AmazonS3Exception s3Exception) {
        billDownloadFailureHandler(statsData, awsBucketName, s3Exception);
    }
}
Also used : Path(java.nio.file.Path) ProgressEventType(com.amazonaws.event.ProgressEventType) ProgressListener(com.amazonaws.event.ProgressListener) AWSCsvBillParser(com.vmware.photon.controller.model.adapters.awsadapter.util.AWSCsvBillParser) IOException(java.io.IOException) AmazonS3Exception(com.amazonaws.services.s3.model.AmazonS3Exception) ProgressEvent(com.amazonaws.event.ProgressEvent) LocalDate(org.joda.time.LocalDate) GetObjectRequest(com.amazonaws.services.s3.model.GetObjectRequest) AmazonS3Exception(com.amazonaws.services.s3.model.AmazonS3Exception) IOException(java.io.IOException)

Aggregations

ProgressEventType (com.amazonaws.event.ProgressEventType)2 ProgressEvent (com.amazonaws.event.ProgressEvent)1 ProgressListener (com.amazonaws.event.ProgressListener)1 AmazonS3Exception (com.amazonaws.services.s3.model.AmazonS3Exception)1 GetObjectRequest (com.amazonaws.services.s3.model.GetObjectRequest)1 AWSCsvBillParser (com.vmware.photon.controller.model.adapters.awsadapter.util.AWSCsvBillParser)1 IOException (java.io.IOException)1 Path (java.nio.file.Path)1 LocalDate (org.joda.time.LocalDate)1