static LifecycleRule fromPb(Rule rule) { LifecycleAction lifecycleAction; Rule.Action action = rule.getAction(); Rule.Condition condition = rule.getCondition();
private void writeObject(ObjectOutputStream out) throws IOException { out.defaultWriteObject(); out.writeUTF(rule.toString()); }
static LifecycleRule fromPb(Rule rule) { LifecycleAction lifecycleAction; Rule.Action action = rule.getAction(); Rule.Condition condition = rule.getCondition();
Rule toPb() { Rule rule = new Rule(); Rule.Action action = new Rule.Action().setType(lifecycleAction.getActionType()); if (lifecycleAction.getActionType().equals(SetStorageClassLifecycleAction.TYPE)) { action.setStorageClass( ((SetStorageClassLifecycleAction) lifecycleAction).getStorageClass().toString()); } rule.setAction(action); Rule.Condition condition = new Rule.Condition() .setAge(lifecycleCondition.getAge()) .setCreatedBefore( lifecycleCondition.getCreatedBefore() == null ? null : new DateTime(true, lifecycleCondition.getCreatedBefore().getValue(), 0)) .setIsLive(lifecycleCondition.getIsLive()) .setNumNewerVersions(lifecycleCondition.getNumberOfNewerVersions()) .setMatchesStorageClass( lifecycleCondition.getMatchesStorageClass() == null ? null : transform( lifecycleCondition.getMatchesStorageClass(), Functions.toStringFunction())); rule.setCondition(condition); return rule; }
static DeleteRule fromPb(Rule rule) { if (rule.getAction() != null && SUPPORTED_ACTION.endsWith(rule.getAction().getType())) { Rule.Condition condition = rule.getCondition(); Integer age = condition.getAge(); if (age != null) { return new AgeDeleteRule(age); } DateTime dateTime = condition.getCreatedBefore(); if (dateTime != null) { return new CreatedBeforeDeleteRule(dateTime.getValue()); } Integer numNewerVersions = condition.getNumNewerVersions(); if (numNewerVersions != null) { return new NumNewerVersionsDeleteRule(numNewerVersions); } Boolean isLive = condition.getIsLive(); if (isLive != null) { return new IsLiveDeleteRule(isLive); } } return new RawDeleteRule(rule); } }
static DeleteRule fromPb(Rule rule) { if (rule.getAction() != null && SUPPORTED_ACTION.endsWith(rule.getAction().getType())) { Rule.Condition condition = rule.getCondition(); Integer age = condition.getAge(); if (age != null) { return new AgeDeleteRule(age); } DateTime dateTime = condition.getCreatedBefore(); if (dateTime != null) { return new CreatedBeforeDeleteRule(dateTime.getValue()); } Integer numNewerVersions = condition.getNumNewerVersions(); if (numNewerVersions != null) { return new NumNewerVersionsDeleteRule(numNewerVersions); } Boolean isLive = condition.getIsLive(); if (isLive != null) { return new IsLiveDeleteRule(isLive); } } return new RawDeleteRule(rule); } }
private void writeObject(ObjectOutputStream out) throws IOException { out.defaultWriteObject(); out.writeUTF(rule.toString()); }
private void writeObject(ObjectOutputStream out) throws IOException { out.defaultWriteObject(); out.writeUTF(rule.toString()); }
Rule toPb() { Rule rule = new Rule(); rule.setAction(new Rule.Action().setType(SUPPORTED_ACTION)); Rule.Condition condition = new Rule.Condition(); populateCondition(condition); rule.setCondition(condition); return rule; }
Rule toPb() { Rule rule = new Rule(); rule.setAction(new Rule.Action().setType(SUPPORTED_ACTION)); Rule.Condition condition = new Rule.Condition(); populateCondition(condition); rule.setCondition(condition); return rule; }
@Test public void testDeleteRules() { AgeDeleteRule ageRule = new AgeDeleteRule(10); assertEquals(10, ageRule.getDaysToLive()); assertEquals(10, ageRule.getDaysToLive()); assertEquals(Type.AGE, ageRule.getType()); assertEquals(Type.AGE, ageRule.getType()); CreatedBeforeDeleteRule createBeforeRule = new CreatedBeforeDeleteRule(1); assertEquals(1, createBeforeRule.getTimeMillis()); assertEquals(1, createBeforeRule.getTimeMillis()); assertEquals(Type.CREATE_BEFORE, createBeforeRule.getType()); NumNewerVersionsDeleteRule versionsRule = new NumNewerVersionsDeleteRule(2); assertEquals(2, versionsRule.getNumNewerVersions()); assertEquals(2, versionsRule.getNumNewerVersions()); assertEquals(Type.NUM_NEWER_VERSIONS, versionsRule.getType()); IsLiveDeleteRule isLiveRule = new IsLiveDeleteRule(true); assertTrue(isLiveRule.isLive()); assertEquals(Type.IS_LIVE, isLiveRule.getType()); assertEquals(Type.IS_LIVE, isLiveRule.getType()); Rule rule = new Rule().set("a", "b"); RawDeleteRule rawRule = new RawDeleteRule(rule); assertEquals(Type.IS_LIVE, isLiveRule.getType()); assertEquals(Type.IS_LIVE, isLiveRule.getType()); ImmutableList<DeleteRule> rules = ImmutableList.of(ageRule, createBeforeRule, versionsRule, isLiveRule, rawRule); for (DeleteRule delRule : rules) { assertEquals(delRule, DeleteRule.fromPb(delRule.toPb())); } }
Rule toPb() { Rule rule = new Rule(); Rule.Action action = new Rule.Action().setType(lifecycleAction.getActionType()); if (lifecycleAction.getActionType().equals(SetStorageClassLifecycleAction.TYPE)) { action.setStorageClass( ((SetStorageClassLifecycleAction) lifecycleAction).getStorageClass().toString()); } rule.setAction(action); Rule.Condition condition = new Rule.Condition() .setAge(lifecycleCondition.getAge()) .setCreatedBefore( lifecycleCondition.getCreatedBefore() == null ? null : new DateTime(true, lifecycleCondition.getCreatedBefore().getValue(), 0)) .setIsLive(lifecycleCondition.getIsLive()) .setNumNewerVersions(lifecycleCondition.getNumberOfNewerVersions()) .setMatchesStorageClass( lifecycleCondition.getMatchesStorageClass() == null ? null : transform( lifecycleCondition.getMatchesStorageClass(), Functions.toStringFunction())); rule.setCondition(condition); return rule; }
@Test public void testLifecycleRules() { Rule deleteLifecycleRule = new LifecycleRule( LifecycleAction.newDeleteAction(), LifecycleCondition.newBuilder().setAge(10).build()) .toPb(); assertEquals( LifecycleRule.DeleteLifecycleAction.TYPE, deleteLifecycleRule.getAction().getType()); assertEquals(10, deleteLifecycleRule.getCondition().getAge().intValue()); Rule setStorageClassLifecycleRule = new LifecycleRule( LifecycleAction.newSetStorageClassAction(StorageClass.COLDLINE), LifecycleCondition.newBuilder() .setIsLive(true) .setNumberOfNewerVersions(10) .build()) .toPb(); assertEquals( StorageClass.COLDLINE.toString(), setStorageClassLifecycleRule.getAction().getStorageClass()); assertTrue(setStorageClassLifecycleRule.getCondition().getIsLive()); assertEquals(10, setStorageClassLifecycleRule.getCondition().getNumNewerVersions().intValue()); } }
static DeleteRule fromPb(Rule rule) { if (rule.getAction() != null && SUPPORTED_ACTION.endsWith(rule.getAction().getType())) { Rule.Condition condition = rule.getCondition(); Integer age = condition.getAge(); if (age != null) { return new AgeDeleteRule(age); } DateTime dateTime = condition.getCreatedBefore(); if (dateTime != null) { return new CreatedBeforeDeleteRule(dateTime.getValue()); } Integer numNewerVersions = condition.getNumNewerVersions(); if (numNewerVersions != null) { return new NumNewerVersionsDeleteRule(numNewerVersions); } Boolean isLive = condition.getIsLive(); if (isLive != null) { return new IsLiveDeleteRule(isLive); } } return new RawDeleteRule(rule); } }
Rule toPb() { Rule rule = new Rule(); rule.setAction(new Rule.Action().setType(SUPPORTED_ACTION)); Rule.Condition condition = new Rule.Condition(); populateCondition(condition); rule.setCondition(condition); return rule; }