Search in sources :

Example 1 with MetricsConfiguration

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();
}
Also used : XmlWriter(com.amazonaws.services.s3.internal.XmlWriter)

Example 2 with MetricsConfiguration

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());
}
Also used : MetricsTagPredicate(com.amazonaws.services.s3.model.metrics.MetricsTagPredicate) MetricsConfiguration(com.amazonaws.services.s3.model.metrics.MetricsConfiguration) MetricsFilterPredicate(com.amazonaws.services.s3.model.metrics.MetricsFilterPredicate) ListBucketMetricsConfigurationsResult(com.amazonaws.services.s3.model.ListBucketMetricsConfigurationsResult) MetricsAndOperator(com.amazonaws.services.s3.model.metrics.MetricsAndOperator) MetricsFilter(com.amazonaws.services.s3.model.metrics.MetricsFilter) Test(org.junit.Test)

Example 3 with MetricsConfiguration

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());
}
Also used : MetricsTagPredicate(com.amazonaws.services.s3.model.metrics.MetricsTagPredicate) MetricsConfiguration(com.amazonaws.services.s3.model.metrics.MetricsConfiguration) MetricsFilterPredicate(com.amazonaws.services.s3.model.metrics.MetricsFilterPredicate) MetricsAndOperator(com.amazonaws.services.s3.model.metrics.MetricsAndOperator) MetricsFilter(com.amazonaws.services.s3.model.metrics.MetricsFilter) Test(org.junit.Test)

Example 4 with MetricsConfiguration

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);
}
Also used : Unmarshallers(com.amazonaws.services.s3.model.transform.Unmarshallers) MetricsConfiguration(com.amazonaws.services.s3.model.metrics.MetricsConfiguration) ByteArrayInputStream(java.io.ByteArrayInputStream)

Aggregations

MetricsConfiguration (com.amazonaws.services.s3.model.metrics.MetricsConfiguration)3 MetricsAndOperator (com.amazonaws.services.s3.model.metrics.MetricsAndOperator)2 MetricsFilter (com.amazonaws.services.s3.model.metrics.MetricsFilter)2 MetricsFilterPredicate (com.amazonaws.services.s3.model.metrics.MetricsFilterPredicate)2 MetricsTagPredicate (com.amazonaws.services.s3.model.metrics.MetricsTagPredicate)2 Test (org.junit.Test)2 XmlWriter (com.amazonaws.services.s3.internal.XmlWriter)1 ListBucketMetricsConfigurationsResult (com.amazonaws.services.s3.model.ListBucketMetricsConfigurationsResult)1 Unmarshallers (com.amazonaws.services.s3.model.transform.Unmarshallers)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1