com.microsoft.azure.storage.LoggingOperations Java Examples
The following examples show how to use
com.microsoft.azure.storage.LoggingOperations.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AzureLoggingFeature.java From cyberduck with GNU General Public License v3.0 | 6 votes |
@Override public void setConfiguration(final Path container, final LoggingConfiguration configuration) throws BackgroundException { try { final ServiceProperties properties = session.getClient().downloadServiceProperties(null, context); final LoggingProperties l = new LoggingProperties(); if(configuration.isEnabled()) { l.setLogOperationTypes(EnumSet.allOf(LoggingOperations.class)); } else { l.setLogOperationTypes(EnumSet.noneOf(LoggingOperations.class)); } properties.setLogging(l); session.getClient().uploadServiceProperties(properties, null, context); } catch(StorageException e) { throw new AzureExceptionMappingService().map("Failure to write attributes of {0}", e, container); } }
Example #2
Source File: LogBlobIterator.java From azure-storage-android with Apache License 2.0 | 6 votes |
/** * Validates that the log given is of the correct log type. * * @param current * the current log * @return whether or not the log is of the correct type. */ private boolean isCorrectLogType(ListBlobItem current) { HashMap<String, String> metadata = ((CloudBlob) current).getMetadata(); String logType = metadata.get("LogType"); if (logType == null) { return true; } if (this.operations.contains(LoggingOperations.READ) && logType.contains("read")) { return true; } if (this.operations.contains(LoggingOperations.WRITE) && logType.contains("write")) { return true; } if (this.operations.contains(LoggingOperations.DELETE) && logType.contains("delete")) { return true; } return false; }
Example #3
Source File: CloudAnalyticsClient.java From azure-storage-android with Apache License 2.0 | 5 votes |
/** * Returns an enumerable collection of log blobs, retrieved lazily. * * @param service * A {@link StorageService} enumeration value that indicates which storage service to use. * @param startTime * A <code>java.util.Date</code> object representing the start of the time range for which logs should * be retrieved. * @param endTime * A <code>java.util.Date</code> object representing the end of the time range for which logs should * be retrieved. * @param operations * A {@link LoggingOperations} enumeration set that indicates which log types to return. * @param details * A {@link BlobListingDetails} enumeration set that indicates whether or not blob metadata should * be returned. None or METADATA are the only valid values. * @param options * A {@link BlobRequestOptions} object that specifies additional options for the request. * @param operationContext * An {@link OperationContext} object that represents the context for the current operation. * @return * An enumerable collection of objects that implement {@link ListBlobItem} and are retrieved lazily. * @throws StorageException * @throws URISyntaxException */ public Iterable<ListBlobItem> listLogBlobs(StorageService service, Date startTime, Date endTime, EnumSet<LoggingOperations> operations, BlobListingDetails details, BlobRequestOptions options, OperationContext operationContext) throws StorageException, URISyntaxException { Utility.assertNotNull("service", service); if (operations == null) { operations = EnumSet.allOf(LoggingOperations.class); } if (!(details == null || details.equals(BlobListingDetails.METADATA))) { throw new IllegalArgumentException(SR.INVALID_LISTING_DETAILS); } if (operations.equals(EnumSet.noneOf(LoggingOperations.class))) { throw new IllegalArgumentException(SR.INVALID_LOGGING_LEVEL); } EnumSet<BlobListingDetails> metadataDetails; if (details != null && (details.equals(BlobListingDetails.METADATA) || !operations.equals(EnumSet .allOf(LoggingOperations.class)))) { metadataDetails = EnumSet.of(BlobListingDetails.METADATA); } else { metadataDetails = EnumSet.noneOf(BlobListingDetails.class); } return new LogBlobIterable(this.getLogDirectory(service), startTime, endTime, operations, metadataDetails, options, operationContext); }
Example #4
Source File: LogBlobIterator.java From azure-storage-android with Apache License 2.0 | 5 votes |
public LogBlobIterator(final CloudBlobDirectory logDirectory, final Date startDate, final Date endDate, final EnumSet<LoggingOperations> operations, final EnumSet<BlobListingDetails> details, final BlobRequestOptions options, final OperationContext opContext) { TimeZone gmtTime = TimeZone.getTimeZone("GMT"); HOUR_FORMAT.setTimeZone(gmtTime); DAY_FORMAT.setTimeZone(gmtTime); MONTH_FORMAT.setTimeZone(gmtTime); YEAR_FORMAT.setTimeZone(gmtTime); this.logDirectory = logDirectory; this.operations = operations; this.details = details; this.opContext = opContext; if (options == null) { this.options = new BlobRequestOptions(); } else { this.options = options; } if (startDate != null) { this.startDate = new GregorianCalendar(); this.startDate.setTime(startDate); this.startDate.add(GregorianCalendar.MINUTE, (-this.startDate.get(GregorianCalendar.MINUTE))); this.startDate.setTimeZone(gmtTime); } if (endDate != null) { this.endDate = new GregorianCalendar(); this.endDate.setTime(endDate); this.endDate.setTimeZone(gmtTime); this.endPrefix = this.logDirectory.getPrefix() + HOUR_FORMAT.format(this.endDate.getTime()); } }
Example #5
Source File: LogBlobIterable.java From azure-storage-android with Apache License 2.0 | 5 votes |
protected LogBlobIterable(final CloudBlobDirectory logDirectory, final Date startTime, final Date endTime, final EnumSet<LoggingOperations> operations, final EnumSet<BlobListingDetails> details, final BlobRequestOptions options, final OperationContext opContext) { this.logDirectory = logDirectory; this.startTime = startTime; this.endTime = endTime; this.operations = operations; this.details = details; this.options = options; this.opContext = opContext; }
Example #6
Source File: QueryMetricsAndActivityLogs.java From azure-libraries-for-java with MIT License | 4 votes |
private static void addBlobTransactions(String storageConnectionString) throws IOException, URISyntaxException, InvalidKeyException, StorageException { // Get the script to upload // InputStream scriptFileAsStream = QueryMetricsAndActivityLogs .class .getResourceAsStream("/install_apache.sh"); // Get the size of the stream // int fileSize; ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); byte[] buffer = new byte[256]; int bytesRead; while ((bytesRead = scriptFileAsStream.read(buffer)) != -1) { outputStream.write(buffer, 0, bytesRead); } fileSize = outputStream.size(); outputStream.close(); // Upload the script file as block blob // CloudStorageAccount account = CloudStorageAccount.parse(storageConnectionString); CloudBlobClient cloudBlobClient = account.createCloudBlobClient(); CloudBlobContainer container = cloudBlobClient.getContainerReference("scripts"); container.createIfNotExists(); ServiceProperties serviceProps = cloudBlobClient.downloadServiceProperties(); // configure Storage logging and metrics LoggingProperties logProps = new LoggingProperties(); logProps.setLogOperationTypes(EnumSet.of(LoggingOperations.READ, LoggingOperations.WRITE)); logProps.setRetentionIntervalInDays(2); logProps.setVersion("1.0"); serviceProps.setLogging(logProps); MetricsProperties metricProps = new MetricsProperties(); metricProps.setMetricsLevel(MetricsLevel.SERVICE_AND_API); metricProps.setRetentionIntervalInDays(2); metricProps.setVersion("1.0"); serviceProps.setHourMetrics(metricProps); serviceProps.setMinuteMetrics(metricProps); // Set the default service version to be used for anonymous requests. serviceProps.setDefaultServiceVersion("2015-04-05"); // Set the service properties. cloudBlobClient.uploadServiceProperties(serviceProps); CloudBlockBlob blob = container.getBlockBlobReference("install_apache.sh"); blob.upload(scriptFileAsStream, fileSize); // give sometime for the infrastructure to process the records and fit into time grain. SdkContext.sleep(6 * 60000); }
Example #7
Source File: CloudAnalyticsClient.java From azure-storage-android with Apache License 2.0 | 3 votes |
/** * Returns an enumerable collection of log records, retrieved lazily. * * @param service * A {@link StorageService} enumeration value that indicates which storage service to use. * @param startTime * A <code>java.util.Date</code> object representing the start of the time range for which logs should * be retrieved. * @param endTime * A <code>java.util.Date</code> object representing the end of the time range for which logs should * be retrieved. * @param options * A {@link BlobRequestOptions} object that specifies additional options for the request. * @param operationContext * An {@link OperationContext} object that represents the context for the current operation. * @return * An enumerable collection of objects that implement {@link ListBlobItem} and are retrieved lazily. * @throws StorageException * @throws URISyntaxException */ public Iterable<LogRecord> listLogRecords(StorageService service, Date startTime, Date endTime, BlobRequestOptions options, OperationContext operationContext) throws StorageException, URISyntaxException { Utility.assertNotNull("service", service); EnumSet<LoggingOperations> operations = EnumSet.allOf(LoggingOperations.class); EnumSet<BlobListingDetails> metadataDetails = EnumSet.noneOf(BlobListingDetails.class); Iterator<ListBlobItem> blobIterator = new LogBlobIterable(this.getLogDirectory(service), startTime, endTime, operations, metadataDetails, options, operationContext).iterator(); return new LogRecordIterable(blobIterator); }