Java Code Examples for com.microsoft.azure.storage.ServiceProperties#setLogging()

The following examples show how to use com.microsoft.azure.storage.ServiceProperties#setLogging() . 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 vote down vote up
@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: QueryMetricsAndActivityLogs.java    From azure-libraries-for-java with MIT License 4 votes vote down vote up
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);
}