Search in sources :

Example 1 with LifecycleCondition

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

the class ControlledGcsBucketLifecycle method verifyUpdatedLifecycleRules.

private void verifyUpdatedLifecycleRules(List<? extends LifecycleRule> lifecycleRules) {
    final LifecycleRule rule = lifecycleRules.get(0);
    assertEquals(SetStorageClassLifecycleAction.TYPE, rule.getAction().getActionType());
    final SetStorageClassLifecycleAction setStorageClassLifecycleAction = (SetStorageClassLifecycleAction) rule.getAction();
    assertEquals(StorageClass.ARCHIVE, setStorageClassLifecycleAction.getStorageClass());
    final LifecycleCondition condition = rule.getCondition();
    assertEquals(30, condition.getAge());
    // The datetime gets simplified to midnight UTC somewhere along the line
    assertEquals(DateTime.parseRfc3339("1981-04-21"), condition.getCreatedBefore());
    assertTrue(condition.getIsLive());
    assertEquals(3, condition.getNumberOfNewerVersions());
    final List<StorageClass> matchesStorageClass = condition.getMatchesStorageClass();
    assertThat(matchesStorageClass, hasSize(1));
    assertEquals(StorageClass.ARCHIVE, matchesStorageClass.get(0));
}
Also used : LifecycleCondition(com.google.cloud.storage.BucketInfo.LifecycleRule.LifecycleCondition) SetStorageClassLifecycleAction(com.google.cloud.storage.BucketInfo.LifecycleRule.SetStorageClassLifecycleAction) GcpGcsBucketDefaultStorageClass(bio.terra.workspace.model.GcpGcsBucketDefaultStorageClass) StorageClass(com.google.cloud.storage.StorageClass) LifecycleRule(com.google.cloud.storage.BucketInfo.LifecycleRule)

Example 2 with LifecycleCondition

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

the class GcsApiConversionsTest method testLifecycleConditionConversions.

@Test
public void testLifecycleConditionConversions() {
    LifecycleCondition googleLifecycleCondition1 = toGcsApi(WSM_LIFECYCLE_RULE_CONDITION_1);
    assertEquals(WSM_LIFECYCLE_RULE_CONDITION_1.getAge(), googleLifecycleCondition1.getAge());
    assertEquals(toGoogleDateTimeDateOnly(WSM_LIFECYCLE_RULE_CONDITION_1.getCreatedBefore()), googleLifecycleCondition1.getCreatedBefore());
    ApiGcpGcsBucketLifecycleRuleCondition roundTrippedCondition = toWsmApi(googleLifecycleCondition1);
    // We can't compare the round-tripped condition with the original for equality, because the
    // conversion
    // to Google DateTime with dateOnly=true is lossy.
    assertEquals(WSM_LIFECYCLE_RULE_CONDITION_1.getAge(), roundTrippedCondition.getAge());
    assertEquals(WSM_LIFECYCLE_RULE_CONDITION_1.getDaysSinceCustomTime(), roundTrippedCondition.getDaysSinceCustomTime());
    assertEquals(WSM_LIFECYCLE_RULE_CONDITION_1.getDaysSinceNoncurrentTime(), roundTrippedCondition.getDaysSinceNoncurrentTime());
    assertThat(WSM_LIFECYCLE_RULE_CONDITION_1.getMatchesStorageClass(), containsInAnyOrder(roundTrippedCondition.getMatchesStorageClass().toArray()));
    assertEquals(WSM_LIFECYCLE_RULE_CONDITION_1.getCustomTimeBefore(), roundTrippedCondition.getCustomTimeBefore());
    assertEquals(WSM_LIFECYCLE_RULE_CONDITION_1.getNumNewerVersions(), roundTrippedCondition.getNumNewerVersions());
    ApiGcpGcsBucketLifecycleRuleCondition wsmCondition = toWsmApi(GCS_LIFECYCLE_CONDITION_1);
    assertEquals(42, wsmCondition.getAge());
    assertNull(wsmCondition.getMatchesStorageClass());
    assertFalse(wsmCondition.isLive());
    assertEquals(2, wsmCondition.getNumNewerVersions());
}
Also used : LifecycleCondition(com.google.cloud.storage.BucketInfo.LifecycleRule.LifecycleCondition) ApiGcpGcsBucketLifecycleRuleCondition(bio.terra.workspace.generated.model.ApiGcpGcsBucketLifecycleRuleCondition) BaseUnitTest(bio.terra.workspace.common.BaseUnitTest) Test(org.junit.jupiter.api.Test)

Example 3 with LifecycleCondition

use of com.google.cloud.storage.BucketInfo.LifecycleRule.LifecycleCondition 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 4 with LifecycleCondition

use of com.google.cloud.storage.BucketInfo.LifecycleRule.LifecycleCondition 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)

Aggregations

LifecycleCondition (com.google.cloud.storage.BucketInfo.LifecycleRule.LifecycleCondition)4 BaseUnitTest (bio.terra.workspace.common.BaseUnitTest)3 LifecycleRule (com.google.cloud.storage.BucketInfo.LifecycleRule)3 SetStorageClassLifecycleAction (com.google.cloud.storage.BucketInfo.LifecycleRule.SetStorageClassLifecycleAction)3 StorageClass (com.google.cloud.storage.StorageClass)3 Test (org.junit.jupiter.api.Test)3 StepResult (bio.terra.stairway.StepResult)2 DeleteLifecycleAction (com.google.cloud.storage.BucketInfo.LifecycleRule.DeleteLifecycleAction)2 LifecycleAction (com.google.cloud.storage.BucketInfo.LifecycleRule.LifecycleAction)2 ApiGcpGcsBucketLifecycleRuleCondition (bio.terra.workspace.generated.model.ApiGcpGcsBucketLifecycleRuleCondition)1 GcpGcsBucketDefaultStorageClass (bio.terra.workspace.model.GcpGcsBucketDefaultStorageClass)1