Search in sources :

Example 1 with NoncurrentVersionTransition

use of com.amazonaws.services.s3.model.BucketLifecycleConfiguration.NoncurrentVersionTransition in project aws-sdk-android by aws-amplify.

the class BucketConfigurationXmlFactory method addNoncurrentTransitions.

private void addNoncurrentTransitions(XmlWriter xml, List<NoncurrentVersionTransition> transitions) {
    if (transitions == null || transitions.isEmpty()) {
        return;
    }
    for (final NoncurrentVersionTransition t : transitions) {
        if (t != null) {
            xml.start("NoncurrentVersionTransition");
            if (t.getDays() != -1) {
                xml.start("NoncurrentDays");
                xml.value(Integer.toString(t.getDays()));
                xml.end();
            }
            xml.start("StorageClass");
            xml.value(t.getStorageClass().toString());
            // </StorageClass>
            xml.end();
            // </NoncurrentVersionTransition>
            xml.end();
        }
    }
}
Also used : NoncurrentVersionTransition(com.amazonaws.services.s3.model.BucketLifecycleConfiguration.NoncurrentVersionTransition)

Example 2 with NoncurrentVersionTransition

use of com.amazonaws.services.s3.model.BucketLifecycleConfiguration.NoncurrentVersionTransition in project aws-sdk-android by aws-amplify.

the class BucketLifecycleSaxUnmarshallerTest method lifecycleConfigurationUnmarshaller_unmarshalls_properly.

@Test
public void lifecycleConfigurationUnmarshaller_unmarshalls_properly() throws Exception {
    Rule rule = getRule(parseLifecycleConfiguration(UNKNOWN_STORAGE_CLASS_RESPONSE), 0);
    assertEquals("logs-rule", rule.getId());
    assertEquals("logs/", rule.getPrefix());
    assertEquals(BucketLifecycleConfiguration.ENABLED, rule.getStatus());
    Transition transition = rule.getTransitions().get(0);
    assertEquals(30, transition.getDays());
    assertEquals(FUTURE_STORAGE_CLASS, transition.getStorageClassAsString());
    assertEquals(365, rule.getExpirationInDays());
    NoncurrentVersionTransition noncurrentVersionTransition = rule.getNoncurrentVersionTransitions().get(0);
    assertEquals(7, noncurrentVersionTransition.getDays());
    assertEquals(14, rule.getNoncurrentVersionExpirationInDays());
    // Test Filter
    LifecycleFilterPredicate predicate = rule.getFilter().getPredicate();
    assertTrue(predicate instanceof LifecycleAndOperator);
    List<LifecycleFilterPredicate> andOperands = ((LifecycleAndOperator) predicate).getOperands();
    assertEquals("prefix", ((LifecyclePrefixPredicate) andOperands.get(0)).getPrefix());
    assertEquals("key1", ((LifecycleTagPredicate) andOperands.get(1)).getTag().getKey());
    assertEquals("value1", ((LifecycleTagPredicate) andOperands.get(1)).getTag().getValue());
    assertEquals("key2", ((LifecycleTagPredicate) andOperands.get(2)).getTag().getKey());
    assertEquals("value2", ((LifecycleTagPredicate) andOperands.get(2)).getTag().getValue());
}
Also used : LifecycleAndOperator(com.amazonaws.services.s3.model.lifecycle.LifecycleAndOperator) LifecycleTagPredicate(com.amazonaws.services.s3.model.lifecycle.LifecycleTagPredicate) LifecycleFilterPredicate(com.amazonaws.services.s3.model.lifecycle.LifecycleFilterPredicate) Rule(com.amazonaws.services.s3.model.BucketLifecycleConfiguration.Rule) Test(org.junit.Test)

Example 3 with NoncurrentVersionTransition

use of com.amazonaws.services.s3.model.BucketLifecycleConfiguration.NoncurrentVersionTransition in project aws-sdk-android by aws-amplify.

the class LifecycleVersioningIntegrationTest method testRoundTrip.

@Test
public void testRoundTrip() throws Exception {
    s3.setBucketLifecycleConfiguration(BUCKET_NAME, new BucketLifecycleConfiguration().withRules(new Rule().withPrefix("/quick").withId("Quick").withStatus("Enabled").withNoncurrentVersionTransition(new NoncurrentVersionTransition().withDays(0).withStorageClass(StorageClass.Glacier)).withNoncurrentVersionExpirationInDays(7), new Rule().withPrefix("/slow").withId("Slow").withStatus("Enabled").withNoncurrentVersionTransition(new NoncurrentVersionTransition().withDays(7).withStorageClass(StorageClass.Glacier)).withNoncurrentVersionExpirationInDays(60)));
    BucketLifecycleConfiguration result = waitForBucketLifecycleConfigurationCreated(BUCKET_NAME);
    Assert.assertEquals(2, result.getRules().size());
    Assert.assertEquals(0, result.getRules().get(0).getNoncurrentVersionTransition().getDays());
    Assert.assertEquals(StorageClass.Glacier, result.getRules().get(0).getNoncurrentVersionTransition().getStorageClass());
    Assert.assertEquals(7, result.getRules().get(0).getNoncurrentVersionExpirationInDays());
    Assert.assertEquals(7, result.getRules().get(1).getNoncurrentVersionTransition().getDays());
    Assert.assertEquals(StorageClass.Glacier, result.getRules().get(1).getNoncurrentVersionTransition().getStorageClass());
    Assert.assertEquals(60, result.getRules().get(1).getNoncurrentVersionExpirationInDays());
}
Also used : BucketLifecycleConfiguration(com.amazonaws.services.s3.model.BucketLifecycleConfiguration) NoncurrentVersionTransition(com.amazonaws.services.s3.model.BucketLifecycleConfiguration.NoncurrentVersionTransition) Rule(com.amazonaws.services.s3.model.BucketLifecycleConfiguration.Rule) Test(org.junit.Test)

Example 4 with NoncurrentVersionTransition

use of com.amazonaws.services.s3.model.BucketLifecycleConfiguration.NoncurrentVersionTransition in project aws-sdk-android by aws-amplify.

the class BucketConfigurationXmlFactory method convertToXmlByteArray.

/**
 * Converts the specified {@link BucketLifecycleConfiguration} object to an
 * XML fragment that can be sent to Amazon S3.
 *
 * @param config The {@link BucketLifecycleConfiguration}
 */
/*
     * <LifecycleConfiguration> <Rule> <ID>logs-rule</ID>
     * <Status>Enabled</Status> <Transition> <Days>30</Days>
     * <StorageClass>GLACIER</StorageClass> </Transition> <Expiration>
     * <Days>365</Days> </Expiration> <NoncurrentVersionTransition>
     * <NoncurrentDays>7</NoncurrentDays> <StorageClass>GLACIER</StorageClass>
     * </NoncurrentVersionTransition> <NoncurrentVersionExpiration>
     * <NoncurrentDays>14</NoncurrentDays> </NoncurrentVersionExpiration>
     * <Filter> <!-- A filter can have only one of Prefix, Tag or And. -->
     * <Prefix>logs/</Prefix> <Tag> <Key>key1</Key> <Value>value1</Value> </Tag>
     * <And> <Prefix>logs/</Prefix> <Tag> <Key>key1</Key> <Value>value1</Value>
     * </Tag> <Tag> <Key>key1</Key> <Value>value1</Value> </Tag> </And>
     * </Filter> </Rule> <Rule> <ID>image-rule</ID> <Prefix>image/</Prefix>
     * <Status>Enabled</Status> <Transition>
     * <Date>2012-12-31T00:00:00.000Z</Date>
     * <StorageClass>GLACIER</StorageClass> </Transition> <Expiration>
     * <Date>2020-12-31T00:00:00.000Z</Date> </Expiration>
     * <AbortIncompleteMultipartUpload>
     * <DaysAfterInitiation>10</DaysAfterInitiation>
     * </AbortIncompleteMultipartUpload> </Rule> </LifecycleConfiguration>
     */
public byte[] convertToXmlByteArray(BucketLifecycleConfiguration config) throws AmazonClientException {
    final XmlWriter xml = new XmlWriter();
    xml.start("LifecycleConfiguration");
    for (final Rule rule : config.getRules()) {
        writeRule(xml, rule);
    }
    xml.end();
    return xml.getBytes();
}
Also used : CORSRule(com.amazonaws.services.s3.model.CORSRule) Rule(com.amazonaws.services.s3.model.BucketLifecycleConfiguration.Rule) ReplicationRule(com.amazonaws.services.s3.model.ReplicationRule) RoutingRule(com.amazonaws.services.s3.model.RoutingRule) RedirectRule(com.amazonaws.services.s3.model.RedirectRule) FilterRule(com.amazonaws.services.s3.model.FilterRule) XmlWriter(com.amazonaws.services.s3.internal.XmlWriter)

Aggregations

Rule (com.amazonaws.services.s3.model.BucketLifecycleConfiguration.Rule)3 NoncurrentVersionTransition (com.amazonaws.services.s3.model.BucketLifecycleConfiguration.NoncurrentVersionTransition)2 Test (org.junit.Test)2 XmlWriter (com.amazonaws.services.s3.internal.XmlWriter)1 BucketLifecycleConfiguration (com.amazonaws.services.s3.model.BucketLifecycleConfiguration)1 CORSRule (com.amazonaws.services.s3.model.CORSRule)1 FilterRule (com.amazonaws.services.s3.model.FilterRule)1 RedirectRule (com.amazonaws.services.s3.model.RedirectRule)1 ReplicationRule (com.amazonaws.services.s3.model.ReplicationRule)1 RoutingRule (com.amazonaws.services.s3.model.RoutingRule)1 LifecycleAndOperator (com.amazonaws.services.s3.model.lifecycle.LifecycleAndOperator)1 LifecycleFilterPredicate (com.amazonaws.services.s3.model.lifecycle.LifecycleFilterPredicate)1 LifecycleTagPredicate (com.amazonaws.services.s3.model.lifecycle.LifecycleTagPredicate)1