use of com.amazonaws.services.s3.model.metrics.MetricsConfiguration in project aws-sdk-android by aws-amplify.
the class BucketConfigurationXmlFactory method convertToXmlByteArray.
/**
* Converts the specified
* {@link com.amazonaws.services.s3.model.metrics.MetricsConfiguration}
* object to an XML fragment that can be sent to Amazon S3.
*
* @param config The
* {@link com.amazonaws.services.s3.model.metrics.MetricsConfiguration}
* .
*/
/*
* <MetricsConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
* <Id>metrics-id</Id> <Filter> <!-- A filter should have only one of
* Prefix, Tag or And--> <Prefix>prefix</Prefix> <Tag> <Key>Project</Key>
* <Value>Foo</Value> </Tag> <And> <Prefix>documents/</Prefix> <Tag>
* <Key>foo</Key> <Value>bar</Value> </Tag> </And> </Filter>
* </MetricsConfiguration>
*/
public byte[] convertToXmlByteArray(MetricsConfiguration config) throws AmazonClientException {
final XmlWriter xml = new XmlWriter();
xml.start("MetricsConfiguration", "xmlns", Constants.XML_NAMESPACE);
addParameterIfNotNull(xml, "Id", config.getId());
writeMetricsFilter(xml, config.getFilter());
xml.end();
return xml.getBytes();
}
use of com.amazonaws.services.s3.model.metrics.MetricsConfiguration in project aws-sdk-android by aws-amplify.
the class BucketMetricsSaxUnmarshallerTest method listResponse_unmarshalls_properly.
@Test
public void listResponse_unmarshalls_properly() throws Exception {
ListBucketMetricsConfigurationsResult result = parseListBucketMetricsConfigurationsResponse(LIST_RESPONSE);
assertTrue(result.isTruncated());
assertEquals("token1", result.getContinuationToken());
assertEquals("token2", result.getNextContinuationToken());
List<MetricsConfiguration> metricsConfigurationList = result.getMetricsConfigurationList();
assertEquals(2, metricsConfigurationList.size());
// Test first metrics configuration
MetricsConfiguration configuration = metricsConfigurationList.get(0);
MetricsFilter filter = configuration.getFilter();
assertEquals("id1", configuration.getId());
assertNotNull(filter);
List<MetricsFilterPredicate> operands = ((MetricsAndOperator) filter.getPredicate()).getOperands();
assertEquals(2, operands.size());
assertEquals("documents/", ((MetricsPrefixPredicate) operands.get(0)).getPrefix());
assertEquals("foo", ((MetricsTagPredicate) operands.get(1)).getTag().getKey());
assertEquals("bar", ((MetricsTagPredicate) operands.get(1)).getTag().getValue());
// Test second metrics configuration
configuration = metricsConfigurationList.get(1);
assertEquals("id2", configuration.getId());
MetricsTagPredicate tagPredicate = (MetricsTagPredicate) configuration.getFilter().getPredicate();
assertEquals("key", tagPredicate.getTag().getKey());
assertEquals("value", tagPredicate.getTag().getValue());
}
use of com.amazonaws.services.s3.model.metrics.MetricsConfiguration in project aws-sdk-android by aws-amplify.
the class BucketMetricsSaxUnmarshallerTest method getResponse_unmarshalls_properly.
@Test
public void getResponse_unmarshalls_properly() throws Exception {
MetricsConfiguration configuration = parseGetBucketMetricsConfigurationResponse(GET_RESPONSE).getMetricsConfiguration();
MetricsFilter filter = configuration.getFilter();
assertEquals("metrics-id", configuration.getId());
List<MetricsFilterPredicate> operands = ((MetricsAndOperator) filter.getPredicate()).getOperands();
assertEquals(3, operands.size());
assertEquals("documents/", ((MetricsPrefixPredicate) operands.get(0)).getPrefix());
assertEquals("foo", ((MetricsTagPredicate) operands.get(1)).getTag().getKey());
assertEquals("bar", ((MetricsTagPredicate) operands.get(1)).getTag().getValue());
assertEquals("", ((MetricsTagPredicate) operands.get(2)).getTag().getKey());
assertEquals("", ((MetricsTagPredicate) operands.get(2)).getTag().getValue());
}
use of com.amazonaws.services.s3.model.metrics.MetricsConfiguration in project aws-sdk-android by aws-amplify.
the class AmazonS3Client method setBucketMetricsConfiguration.
@Override
public SetBucketMetricsConfigurationResult setBucketMetricsConfiguration(SetBucketMetricsConfigurationRequest setBucketMetricsConfigurationRequest) throws AmazonServiceException, AmazonClientException {
new SetBucketMetricsConfigurationRequest();
assertParameterNotNull(setBucketMetricsConfigurationRequest, "The request cannot be null");
final String bucketName = assertStringNotEmpty(setBucketMetricsConfigurationRequest.getBucketName(), "BucketName");
final MetricsConfiguration metricsConfiguration = assertNotNull(setBucketMetricsConfigurationRequest.getMetricsConfiguration(), "Metrics Configuration");
final String id = assertNotNull(metricsConfiguration.getId(), "Metrics Id");
final Request<SetBucketMetricsConfigurationRequest> request = createRequest(bucketName, null, setBucketMetricsConfigurationRequest, HttpMethodName.PUT);
request.addParameter("metrics", null);
request.addParameter("id", id);
final byte[] bytes = bucketConfigurationXmlFactory.convertToXmlByteArray(metricsConfiguration);
request.addHeader("Content-Length", String.valueOf(bytes.length));
request.addHeader("Content-Type", "application/xml");
request.setContent(new ByteArrayInputStream(bytes));
return invoke(request, new Unmarshallers.SetBucketMetricsConfigurationUnmarshaller(), bucketName, null);
}
Aggregations