Search in sources :

Example 11 with LifecycleRule

use of com.google.cloud.storage.BucketInfo.LifecycleRule in project terra-workspace-manager by DataBiosphere.

the class UpdateGcsBucketStepTest method testUndoStep.

@Test
public void testUndoStep() throws InterruptedException, RetryException {
    final StepResult result = updateGcsBucketStep.undoStep(mockFlightContext);
    verify(mockBuiltBucketCow, times(2)).update();
    assertEquals(StepResult.getStepResultSuccess(), result);
    final StorageClass storageClass = storageClassCaptor.getValue();
    assertEquals(StorageClass.NEARLINE, storageClass);
    final List<LifecycleRule> rules = lifecycleRulesCaptor.getValue();
    assertThat(rules, hasSize(1));
    final LifecycleAction action = rules.get(0).getAction();
    assertEquals(SetStorageClassLifecycleAction.TYPE, action.getActionType());
    assertEquals(StorageClass.COLDLINE, ((SetStorageClassLifecycleAction) action).getStorageClass());
    final LifecycleCondition condition = rules.get(0).getCondition();
    assertEquals(45, condition.getAge());
    assertEquals(toGoogleDateTime(OFFSET_DATE_TIME_2).getValue(), condition.getCreatedBefore().getValue());
    assertEquals(1, condition.getNumberOfNewerVersions());
    assertTrue(condition.getIsLive());
    assertThat(condition.getMatchesStorageClass(), hasSize(1));
    assertEquals(StorageClass.STANDARD, condition.getMatchesStorageClass().get(0));
}
Also used : LifecycleCondition(com.google.cloud.storage.BucketInfo.LifecycleRule.LifecycleCondition) StorageClass(com.google.cloud.storage.StorageClass) StepResult(bio.terra.stairway.StepResult) LifecycleRule(com.google.cloud.storage.BucketInfo.LifecycleRule) LifecycleAction(com.google.cloud.storage.BucketInfo.LifecycleRule.LifecycleAction) DeleteLifecycleAction(com.google.cloud.storage.BucketInfo.LifecycleRule.DeleteLifecycleAction) SetStorageClassLifecycleAction(com.google.cloud.storage.BucketInfo.LifecycleRule.SetStorageClassLifecycleAction) BaseUnitTest(bio.terra.workspace.common.BaseUnitTest) Test(org.junit.jupiter.api.Test)

Example 12 with LifecycleRule

use of com.google.cloud.storage.BucketInfo.LifecycleRule in project terra-workspace-manager by DataBiosphere.

the class UpdateGcsBucketStepTest method testDoStep.

@Test
public void testDoStep() throws InterruptedException, RetryException {
    final StepResult result = updateGcsBucketStep.doStep(mockFlightContext);
    verify(mockBuiltBucketCow, times(2)).update();
    assertEquals(StepResult.getStepResultSuccess(), result);
    final StorageClass storageClass = storageClassCaptor.getValue();
    assertEquals(StorageClass.STANDARD, storageClass);
    final List<LifecycleRule> rules = lifecycleRulesCaptor.getValue();
    assertThat(rules, hasSize(2));
    assertEquals(DeleteLifecycleAction.TYPE, rules.get(0).getAction().getActionType());
    final LifecycleCondition rule1condition = rules.get(0).getCondition();
    assertEquals(31, rule1condition.getAge());
    // TODO: [PF-933] This (and all other date checks in this test) work around the fact that
    // Stairway FlightMap loses time zone data at serialization time by normalizing to UTC via call
    // to getValue().  Once PF-933 is addressed, these assertions should all revert to apply time
    // zone comparison by removing the getValue() call from both sides of the equality assertion.
    assertEquals(toGoogleDateTime(OFFSET_DATE_TIME_2).getValue(), rule1condition.getCreatedBefore().getValue());
    assertEquals(3, rule1condition.getNumberOfNewerVersions());
    assertTrue(rule1condition.getIsLive());
    assertThat(rule1condition.getMatchesStorageClass(), hasSize(2));
    assertEquals(StorageClass.ARCHIVE, rule1condition.getMatchesStorageClass().get(0));
    assertEquals(StorageClass.STANDARD, rule1condition.getMatchesStorageClass().get(1));
    final LifecycleAction rule2action = rules.get(1).getAction();
    assertEquals(SetStorageClassLifecycleAction.TYPE, rule2action.getActionType());
    assertEquals(StorageClass.NEARLINE, ((SetStorageClassLifecycleAction) rule2action).getStorageClass());
    final LifecycleCondition rule2condition = rules.get(1).getCondition();
    assertEquals(15, rule2condition.getAge());
    assertEquals(toGoogleDateTime(OFFSET_DATE_TIME_1).getValue(), rule2condition.getCreatedBefore().getValue());
    assertEquals(5, rule2condition.getNumberOfNewerVersions());
    assertTrue(rule2condition.getIsLive());
    assertThat(rule2condition.getMatchesStorageClass(), hasSize(1));
    assertEquals(StorageClass.ARCHIVE, rule2condition.getMatchesStorageClass().get(0));
}
Also used : LifecycleCondition(com.google.cloud.storage.BucketInfo.LifecycleRule.LifecycleCondition) StorageClass(com.google.cloud.storage.StorageClass) StepResult(bio.terra.stairway.StepResult) LifecycleRule(com.google.cloud.storage.BucketInfo.LifecycleRule) LifecycleAction(com.google.cloud.storage.BucketInfo.LifecycleRule.LifecycleAction) DeleteLifecycleAction(com.google.cloud.storage.BucketInfo.LifecycleRule.DeleteLifecycleAction) SetStorageClassLifecycleAction(com.google.cloud.storage.BucketInfo.LifecycleRule.SetStorageClassLifecycleAction) BaseUnitTest(bio.terra.workspace.common.BaseUnitTest) Test(org.junit.jupiter.api.Test)

Example 13 with LifecycleRule

use of com.google.cloud.storage.BucketInfo.LifecycleRule in project java-storage by googleapis.

the class BucketInfoTest method testRuleMappingIsCorrect_setLifeCycleRules_nonEmpty.

@Test
public void testRuleMappingIsCorrect_setLifeCycleRules_nonEmpty() {
    LifecycleRule lifecycleRule = new LifecycleRule(LifecycleAction.newDeleteAction(), LifecycleCondition.newBuilder().setAge(10).build());
    Rule lifecycleDeleteAfter10 = lifecycleRule.toPb();
    Bucket bucket = bi().setLifecycleRules(ImmutableList.of(lifecycleRule)).build().toPb();
    assertEquals(lifecycle(lifecycleDeleteAfter10), bucket.getLifecycle());
}
Also used : Bucket(com.google.api.services.storage.model.Bucket) LifecycleRule(com.google.cloud.storage.BucketInfo.LifecycleRule) Rule(com.google.api.services.storage.model.Bucket.Lifecycle.Rule) NumNewerVersionsDeleteRule(com.google.cloud.storage.BucketInfo.NumNewerVersionsDeleteRule) AgeDeleteRule(com.google.cloud.storage.BucketInfo.AgeDeleteRule) IsLiveDeleteRule(com.google.cloud.storage.BucketInfo.IsLiveDeleteRule) RawDeleteRule(com.google.cloud.storage.BucketInfo.RawDeleteRule) DeleteRule(com.google.cloud.storage.BucketInfo.DeleteRule) CreatedBeforeDeleteRule(com.google.cloud.storage.BucketInfo.CreatedBeforeDeleteRule) LifecycleRule(com.google.cloud.storage.BucketInfo.LifecycleRule) Test(org.junit.Test)

Example 14 with LifecycleRule

use of com.google.cloud.storage.BucketInfo.LifecycleRule in project java-storage by googleapis.

the class BucketInfoTest method testLifecycleRules.

@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());
    Rule lifecycleRule = new LifecycleRule(LifecycleAction.newSetStorageClassAction(StorageClass.COLDLINE), LifecycleCondition.newBuilder().setIsLive(true).setNumberOfNewerVersions(10).setDaysSinceNoncurrentTime(30).setNoncurrentTimeBefore(new DateTime(System.currentTimeMillis())).setCustomTimeBefore(new DateTime(System.currentTimeMillis())).setDaysSinceCustomTime(30).build()).toPb();
    assertEquals(StorageClass.COLDLINE.toString(), lifecycleRule.getAction().getStorageClass());
    assertTrue(lifecycleRule.getCondition().getIsLive());
    assertEquals(10, lifecycleRule.getCondition().getNumNewerVersions().intValue());
    assertEquals(30, lifecycleRule.getCondition().getDaysSinceNoncurrentTime().intValue());
    assertNotNull(lifecycleRule.getCondition().getNoncurrentTimeBefore());
    assertEquals(StorageClass.COLDLINE.toString(), lifecycleRule.getAction().getStorageClass());
    assertEquals(30, lifecycleRule.getCondition().getDaysSinceCustomTime().intValue());
    assertNotNull(lifecycleRule.getCondition().getCustomTimeBefore());
    Rule unsupportedRule = new LifecycleRule(LifecycleAction.newLifecycleAction("This action type doesn't exist"), LifecycleCondition.newBuilder().setAge(10).build()).toPb();
    unsupportedRule.setAction(unsupportedRule.getAction().setType("This action type also doesn't exist"));
    LifecycleRule.fromPb(// If this doesn't throw an exception, unsupported rules are working
    unsupportedRule);
}
Also used : LifecycleRule(com.google.cloud.storage.BucketInfo.LifecycleRule) Rule(com.google.api.services.storage.model.Bucket.Lifecycle.Rule) NumNewerVersionsDeleteRule(com.google.cloud.storage.BucketInfo.NumNewerVersionsDeleteRule) AgeDeleteRule(com.google.cloud.storage.BucketInfo.AgeDeleteRule) IsLiveDeleteRule(com.google.cloud.storage.BucketInfo.IsLiveDeleteRule) RawDeleteRule(com.google.cloud.storage.BucketInfo.RawDeleteRule) DeleteRule(com.google.cloud.storage.BucketInfo.DeleteRule) CreatedBeforeDeleteRule(com.google.cloud.storage.BucketInfo.CreatedBeforeDeleteRule) LifecycleRule(com.google.cloud.storage.BucketInfo.LifecycleRule) DateTime(com.google.api.client.util.DateTime) Test(org.junit.Test)

Aggregations

LifecycleRule (com.google.cloud.storage.BucketInfo.LifecycleRule)14 BaseUnitTest (bio.terra.workspace.common.BaseUnitTest)5 Test (org.junit.jupiter.api.Test)5 StepResult (bio.terra.stairway.StepResult)4 SetStorageClassLifecycleAction (com.google.cloud.storage.BucketInfo.LifecycleRule.SetStorageClassLifecycleAction)4 StorageClass (com.google.cloud.storage.StorageClass)4 BucketInfo (com.google.cloud.storage.BucketInfo)3 LifecycleCondition (com.google.cloud.storage.BucketInfo.LifecycleRule.LifecycleCondition)3 Test (org.junit.Test)3 BucketCow (bio.terra.cloudres.google.storage.BucketCow)2 StorageCow (bio.terra.cloudres.google.storage.StorageCow)2 ApiGcpGcsBucketLifecycleRule (bio.terra.workspace.generated.model.ApiGcpGcsBucketLifecycleRule)2 DateTime (com.google.api.client.util.DateTime)2 Rule (com.google.api.services.storage.model.Bucket.Lifecycle.Rule)2 Bucket (com.google.cloud.storage.Bucket)2 AgeDeleteRule (com.google.cloud.storage.BucketInfo.AgeDeleteRule)2 CreatedBeforeDeleteRule (com.google.cloud.storage.BucketInfo.CreatedBeforeDeleteRule)2 DeleteRule (com.google.cloud.storage.BucketInfo.DeleteRule)2 IsLiveDeleteRule (com.google.cloud.storage.BucketInfo.IsLiveDeleteRule)2 DeleteLifecycleAction (com.google.cloud.storage.BucketInfo.LifecycleRule.DeleteLifecycleAction)2