/** * Parses the {@link ServiceProperties} from the given XML stream. * * @param stream * @throws IOException * @throws SAXException * @throws ParserConfigurationException */ public static ServiceProperties readServicePropertiesFromStream(final InputStream stream) throws SAXException, IOException, ParserConfigurationException { SAXParser saxParser = Utility.getSAXParser(); ServicePropertiesHandler handler = new ServicePropertiesHandler(); handler.props.setLogging(null); handler.props.setHourMetrics(null); handler.props.setMinuteMetrics(null); handler.props.setCors(null); saxParser.parse(stream, handler); return handler.props; }
/** * Generate a <code>FileServiceProperties</code> from a new <code>ServiceProperties</code>. */ public FileServiceProperties() { this(new ServiceProperties()); }
/** * Gets the Cross-Origin Resource Sharing (CORS) properties. * * @return A {@link CorsProperties} object which represents the CORS properties. */ public CorsProperties getCors() { return this.serviceProperties.getCors(); }
/** * Generate a <code>FileServiceProperties</code> from the given <code>ServiceProperties</code>. * * @param properties * The <code>ServiceProperties</code> to use */ FileServiceProperties(ServiceProperties properties) { this.serviceProperties = properties; this.serviceProperties.setLogging(null); this.serviceProperties.setDefaultServiceVersion(null); }
/** * Parses the {@link ServiceProperties} from the given XML stream. * * @param stream * @throws IOException * @throws SAXException * @throws ParserConfigurationException */ public static ServiceProperties readServicePropertiesFromStream(final InputStream stream) throws SAXException, IOException, ParserConfigurationException { SAXParser saxParser = Utility.getSAXParser(); ServicePropertiesHandler handler = new ServicePropertiesHandler(); handler.props.setLogging(null); handler.props.setHourMetrics(null); handler.props.setMinuteMetrics(null); handler.props.setCors(null); handler.props.setDeleteRetentionPolicy(null); handler.props.setStaticWebsiteProperties(null); saxParser.parse(stream, handler); return handler.props; }
props.getLogging().setLogOperationTypes(EnumSet.of(LoggingOperations.READ, LoggingOperations.WRITE)); props.getLogging().setRetentionIntervalInDays(5); props.getLogging().setVersion("1.0"); props.getHourMetrics().setMetricsLevel(MetricsLevel.SERVICE); props.getHourMetrics().setRetentionIntervalInDays(6); props.getHourMetrics().setVersion("1.0"); props.getMinuteMetrics().setMetricsLevel(MetricsLevel.SERVICE); props.getMinuteMetrics().setRetentionIntervalInDays(6); props.getMinuteMetrics().setVersion("1.0"); props.getCors().getCorsRules().clear(); ServiceProperties newProps = new ServiceProperties(); newProps.setLogging(null); newProps.setHourMetrics(null); newProps.setMinuteMetrics(null); Arrays.asList("x-ms-meta-data*", "x-ms-meta-source*", "x-ms-meta-abc", "x-ms-meta-bcd")); ruleBasic.setMaxAgeInSeconds(500); newProps.getCors().getCorsRules().add(ruleBasic); props.setCors(newProps.getCors()); assertServicePropertiesAreEqual(props, callDownloadServiceProperties(client)); newProps.setLogging(props.getLogging()); newProps.setHourMetrics(props.getHourMetrics());
xmlw.startTag(Constants.EMPTY_STRING, Constants.AnalyticsConstants.STORAGE_SERVICE_PROPERTIES_ELEMENT); if (properties.getLogging() != null) { writeLoggingProperties(xmlw, properties.getLogging()); if (properties.getHourMetrics() != null) { writeMetricsProperties(xmlw, properties.getHourMetrics(), Constants.AnalyticsConstants.HOUR_METRICS_ELEMENT); if (properties.getMinuteMetrics() != null) { writeMetricsProperties(xmlw, properties.getMinuteMetrics(), Constants.AnalyticsConstants.MINUTE_METRICS_ELEMENT); if (properties.getCors() != null) { writeCorsProperties(xmlw, properties.getCors()); if (properties.getDefaultServiceVersion() != null) { Utility.serializeElement(xmlw, Constants.AnalyticsConstants.DEFAULT_SERVICE_VERSION, properties.getDefaultServiceVersion());
if (properties.getLogging() != null) { writeLoggingProperties(xmlw, properties.getLogging()); if (properties.getHourMetrics() != null) { writeMetricsProperties(xmlw, properties.getHourMetrics(), Constants.AnalyticsConstants.HOUR_METRICS_ELEMENT); if (properties.getMinuteMetrics() != null) { writeMetricsProperties(xmlw, properties.getMinuteMetrics(), Constants.AnalyticsConstants.MINUTE_METRICS_ELEMENT); if (properties.getCors() != null) { writeCorsProperties(xmlw, properties.getCors()); if (properties.getDefaultServiceVersion() != null) { xmlw.writeStartElement(Constants.AnalyticsConstants.DEFAULT_SERVICE_VERSION); xmlw.writeCharacters(properties.getDefaultServiceVersion()); xmlw.writeEndElement(); if (properties.getDeleteRetentionPolicy() != null) { writeDeleteRetentionPolicy(xmlw, properties.getDeleteRetentionPolicy()); if (properties.getStaticWebsiteProperties() != null) { writeStaticWebsiteProperties(xmlw, properties.getStaticWebsiteProperties());
this.props.getLogging().setRetentionIntervalInDays(this.retentionPolicyDays); this.props.getHourMetrics().setRetentionIntervalInDays(this.retentionPolicyDays); this.props.getMinuteMetrics().setRetentionIntervalInDays(this.retentionPolicyDays); this.props.getCors().getCorsRules().add(this.rule); this.props.getLogging().setVersion(value); this.props.getLogging().getLogOperationTypes().add(LoggingOperations.DELETE); this.props.getLogging().getLogOperationTypes().add(LoggingOperations.READ); this.props.getLogging().getLogOperationTypes().add(LoggingOperations.WRITE); MetricsProperties metrics = this.props.getHourMetrics(); if (Constants.AnalyticsConstants.VERSION_ELEMENT.equals(currentNode)) { metrics.setVersion(value); MetricsProperties metrics = this.props.getMinuteMetrics(); if (Constants.AnalyticsConstants.VERSION_ELEMENT.equals(currentNode)) { metrics.setVersion(value); this.props.setDefaultServiceVersion(value); boolean enabled = Boolean.parseBoolean(value); if (enabled) { this.props.getDeleteRetentionPolicy().setEnabled(true);
/** * Test Analytics Disable Service Properties * * @throws StorageException * @throws InterruptedException */ @Test public void testAnalyticsDisable() throws StorageException, InterruptedException { ServiceClient client = TestHelper.createCloudBlobClient(); ServiceProperties props = new ServiceProperties(); props.setDefaultServiceVersion(Constants.HeaderConstants.TARGET_STORAGE_VERSION); testAnalyticsDisable(client, props); client = TestHelper.createCloudQueueClient(); props = new ServiceProperties(); testAnalyticsDisable(client, props); client = TestHelper.createCloudTableClient(); props = new ServiceProperties(); testAnalyticsDisable(client, props); }
props.getHourMetrics().setMetricsLevel(MetricsLevel.DISABLED); props.getHourMetrics().setRetentionIntervalInDays(null); props.getMinuteMetrics().setMetricsLevel(MetricsLevel.DISABLED); props.getMinuteMetrics().setRetentionIntervalInDays(null); callUploadServiceProps(client, props, null); props.getHourMetrics().setRetentionIntervalInDays(1); props.getHourMetrics().setMetricsLevel(MetricsLevel.SERVICE); props.getMinuteMetrics().setRetentionIntervalInDays(1); props.getMinuteMetrics().setMetricsLevel(MetricsLevel.SERVICE); callUploadServiceProps(client, props, null); props.getHourMetrics().setRetentionIntervalInDays(2); props.getHourMetrics().setMetricsLevel(MetricsLevel.SERVICE_AND_API); props.getMinuteMetrics().setRetentionIntervalInDays(2); props.getMinuteMetrics().setMetricsLevel(MetricsLevel.SERVICE_AND_API); callUploadServiceProps(client, props, null); props.getLogging().setRetentionIntervalInDays(null); props.getLogging().setLogOperationTypes(EnumSet.noneOf(LoggingOperations.class)); callUploadServiceProps(client, props, null); props.getLogging().setRetentionIntervalInDays(3); props.getLogging().setLogOperationTypes(EnumSet.noneOf(LoggingOperations.class)); callUploadServiceProps(client, props, null); props.getLogging().setRetentionIntervalInDays(null); props.getLogging().setLogOperationTypes(EnumSet.allOf(LoggingOperations.class)); callUploadServiceProps(client, props, null);
/** * Sets the Cross-Origin Resource Sharing (CORS) properties. * * @param cors * A {@link CorsProperties} object which represents the CORS properties. */ public void setCors(CorsProperties cors) { this.serviceProperties.setCors(cors); }
public void uploadServiceProperties(final ServiceProperties properties, QueueRequestOptions options, OperationContext opContext) throws StorageException { if (!Utility.isNullOrEmpty(properties.getDefaultServiceVersion())) { throw new IllegalArgumentException(SR.DEFAULT_SERVICE_VERSION_ONLY_SET_FOR_BLOB_SERVICE);
@Override public LoggingConfiguration getConfiguration(final Path container) throws BackgroundException { try { final ServiceProperties properties = session.getClient().downloadServiceProperties(null, context); final LoggingConfiguration configuration = new LoggingConfiguration( !properties.getLogging().getLogOperationTypes().isEmpty(), "$logs" ); // When you have configured Storage Logging to log request data from your storage account, it saves the log data // to blobs in a container named $logs in your storage account. configuration.setContainers(Collections.singletonList( new Path("/$logs", EnumSet.of(Path.Type.volume, Path.Type.directory))) ); return configuration; } catch(StorageException e) { throw new AzureExceptionMappingService().map("Cannot read container configuration", e); } }
/** * Gets the hour metrics properties. * * @return A {@link MetricsProperties} object which represents the hour metrics properties. */ public MetricsProperties getHourMetrics() { return this.serviceProperties.getHourMetrics(); }
/** * Gets the minute metrics properties. * * @return A {@link MetricsProperties} object which represents the minute metrics properties. */ public MetricsProperties getMinuteMetrics() { return this.serviceProperties.getMinuteMetrics(); }
@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); } } }
/** * Sets the hour metrics properties. * * @param metrics * A {@link MetricsProperties} object which represents the hour metrics properties. */ public void setHourMetrics(final MetricsProperties metrics) { this.serviceProperties.setHourMetrics(metrics); }
private void testAnalyticsDefaultServiceVersion(ServiceClient client, ServiceProperties props) throws StorageException, InterruptedException { if (client.getClass().equals(CloudBlobClient.class)) { props.setDefaultServiceVersion("2009-09-19"); callUploadServiceProps(client, props, null); assertServicePropertiesAreEqual(props, callDownloadServiceProperties(client)); props.setDefaultServiceVersion("2011-08-18"); callUploadServiceProps(client, props, null); assertServicePropertiesAreEqual(props, callDownloadServiceProperties(client)); props.setDefaultServiceVersion("2012-02-12"); callUploadServiceProps(client, props, null); assertServicePropertiesAreEqual(props, callDownloadServiceProperties(client)); props.setDefaultServiceVersion(Constants.HeaderConstants.TARGET_STORAGE_VERSION); callUploadServiceProps(client, props, null); assertServicePropertiesAreEqual(props, callDownloadServiceProperties(client)); } else { try { props.setDefaultServiceVersion("2009-09-19"); callUploadServiceProps(client, props, null); fail("Should not be able to set default Service Version for non Blob Client"); } catch (IllegalArgumentException e) { assertEquals(e.getMessage(), SR.DEFAULT_SERVICE_VERSION_ONLY_SET_FOR_BLOB_SERVICE); } catch (Exception e) { fail(); } } }
this.props.getLogging().setRetentionIntervalInDays(this.retentionPolicyDays); this.props.getHourMetrics().setRetentionIntervalInDays(this.retentionPolicyDays); this.props.getMinuteMetrics().setRetentionIntervalInDays(this.retentionPolicyDays); this.props.getCors().getCorsRules().add(this.rule); this.props.getLogging().setVersion(value); this.props.getLogging().getLogOperationTypes().add(LoggingOperations.DELETE); this.props.getLogging().getLogOperationTypes().add(LoggingOperations.READ); this.props.getLogging().getLogOperationTypes().add(LoggingOperations.WRITE); MetricsProperties metrics = this.props.getHourMetrics(); if (Constants.AnalyticsConstants.VERSION_ELEMENT.equals(currentNode)) { metrics.setVersion(value); MetricsProperties metrics = this.props.getMinuteMetrics(); if (Constants.AnalyticsConstants.VERSION_ELEMENT.equals(currentNode)) { metrics.setVersion(value); this.props.setDefaultServiceVersion(value);