@Test public void testSetConfiguration() throws Exception { final Path test = new Path(new GoogleStorageHomeFinderService(session).find(), new AlphanumericRandomStringService().random().toLowerCase(), EnumSet.of(Path.Type.directory, Path.Type.volume)); new GoogleStorageDirectoryFeature(session).mkdir(test, null, new TransferStatus()); final GoogleStorageLifecycleFeature feature = new GoogleStorageLifecycleFeature(session); assertEquals(LifecycleConfiguration.empty(), feature.getConfiguration(test)); feature.setConfiguration(test, new LifecycleConfiguration(1, "COLDLINE", 2)); final LifecycleConfiguration read = feature.getConfiguration(test); assertEquals(1, read.getTransition(), 0L); assertEquals("COLDLINE", read.getStorageClass()); assertEquals(2, read.getExpiration(), 0L); feature.setConfiguration(test, LifecycleConfiguration.empty()); assertEquals(LifecycleConfiguration.empty(), feature.getConfiguration(test)); new GoogleStorageDeleteFeature(session).delete(Collections.singletonList(test), new DisabledLoginCallback(), new Delete.DisabledCallback()); }
@Override public void setConfiguration(final Path file, final LifecycleConfiguration configuration) throws BackgroundException { final Path container = containerService.getContainer(file); try { if(configuration.getTransition() != null || configuration.getExpiration() != null) { final Bucket.Lifecycle config = new Bucket.Lifecycle(); final List<Bucket.Lifecycle.Rule> rules = new ArrayList<>(); if(configuration.getTransition() != null) { rules.add(new Bucket.Lifecycle.Rule().setCondition(new Bucket.Lifecycle.Rule.Condition().setIsLive(true).setAge(configuration.getTransition())) .setAction(new Bucket.Lifecycle.Rule.Action().setType("SetStorageClass").setStorageClass(configuration.getStorageClass()))); } if(configuration.getExpiration() != null) { rules.add(new Bucket.Lifecycle.Rule().setCondition(new Bucket.Lifecycle.Rule.Condition().setIsLive(true).setAge(configuration.getExpiration())) .setAction(new Bucket.Lifecycle.Rule.Action().setType("Delete"))); } session.getClient().buckets().patch(container.getName(), new Bucket().setLifecycle( config.setRule(rules))).execute(); } else { session.getClient().buckets().patch(container.getName(), new Bucket().setLifecycle(new Bucket.Lifecycle().setRule(Collections.emptyList()))).execute(); } } catch(IOException e) { throw new GoogleStorageExceptionMappingService().map("Failure to write attributes of {0}", e, container); } }
GoogleStorageLifecycleFeature implements Lifecycle { @Override public void setConfiguration(final Path file, final LifecycleConfiguration configuration) throws BackgroundException { final Path container = containerService.getContainer(file); try { if(configuration.getTransition() != null || configuration.getExpiration() != null) { final Bucket.Lifecycle config = new Bucket.Lifecycle(); final List<Bucket.Lifecycle.Rule> rules = new ArrayList<>(); if(configuration.getTransition() != null) { rules.add(new Bucket.Lifecycle.Rule().setCondition(new Bucket.Lifecycle.Rule.Condition().setIsLive(true).setAge(configuration.getTransition())) .setAction(new Bucket.Lifecycle.Rule.Action().setType("SetStorageClass").setStorageClass(configuration.getStorageClass()))); } if(configuration.getExpiration() != null) { rules.add(new Bucket.Lifecycle.Rule().setCondition(new Bucket.Lifecycle.Rule.Condition().setIsLive(true).setAge(configuration.getExpiration())) .setAction(new Bucket.Lifecycle.Rule.Action().setType("Delete"))); } session.getClient().buckets().patch(container.getName(), new Bucket().setLifecycle( config.setRule(rules))).execute(); } else { session.getClient().buckets().patch(container.getName(), new Bucket().setLifecycle(new Bucket.Lifecycle().setRule(Collections.emptyList()))).execute(); } } catch(IOException e) { throw new GoogleStorageExceptionMappingService().map("Failure to write attributes of {0}", e, container); } } }
GoogleStorageLifecycleFeature implements Lifecycle { @Override public void setConfiguration(final Path file, final LifecycleConfiguration configuration) throws BackgroundException { final Path container = containerService.getContainer(file); try { if(configuration.getTransition() != null || configuration.getExpiration() != null) { final Bucket.Lifecycle config = new Bucket.Lifecycle(); final List<Bucket.Lifecycle.Rule> rules = new ArrayList<>(); if(configuration.getTransition() != null) { rules.add(new Bucket.Lifecycle.Rule().setCondition(new Bucket.Lifecycle.Rule.Condition().setIsLive(true).setAge(configuration.getTransition())) .setAction(new Bucket.Lifecycle.Rule.Action().setType("SetStorageClass").setStorageClass(configuration.getStorageClass()))); } if(configuration.getExpiration() != null) { rules.add(new Bucket.Lifecycle.Rule().setCondition(new Bucket.Lifecycle.Rule.Condition().setIsLive(true).setAge(configuration.getExpiration())) .setAction(new Bucket.Lifecycle.Rule.Action().setType("Delete"))); } session.getClient().buckets().patch(container.getName(), new Bucket().setLifecycle( config.setRule(rules))).execute(); } else { session.getClient().buckets().patch(container.getName(), new Bucket().setLifecycle(new Bucket.Lifecycle().setRule(Collections.emptyList()))).execute(); } } catch(IOException e) { throw new GoogleStorageExceptionMappingService().map("Failure to write attributes of {0}", e, container); } } GoogleStorageLifecycleFeature(final GoogleStorageSession session); }
GoogleStorageLifecycleFeature implements Lifecycle { @Override public void setConfiguration(final Path file, final LifecycleConfiguration configuration) throws BackgroundException { final Path container = containerService.getContainer(file); try { if(configuration.getTransition() != null || configuration.getExpiration() != null) { final Bucket.Lifecycle config = new Bucket.Lifecycle(); final List<Bucket.Lifecycle.Rule> rules = new ArrayList<>(); if(configuration.getTransition() != null) { rules.add(new Bucket.Lifecycle.Rule().setCondition(new Bucket.Lifecycle.Rule.Condition().setIsLive(true).setAge(configuration.getTransition())) .setAction(new Bucket.Lifecycle.Rule.Action().setType("SetStorageClass").setStorageClass(configuration.getStorageClass()))); } if(configuration.getExpiration() != null) { rules.add(new Bucket.Lifecycle.Rule().setCondition(new Bucket.Lifecycle.Rule.Condition().setIsLive(true).setAge(configuration.getExpiration())) .setAction(new Bucket.Lifecycle.Rule.Action().setType("Delete"))); } session.getClient().buckets().patch(container.getName(), new Bucket().setLifecycle( config.setRule(rules))).execute(); } else { session.getClient().buckets().patch(container.getName(), new Bucket().setLifecycle(new Bucket.Lifecycle().setRule(Collections.emptyList()))).execute(); } } catch(IOException e) { throw new GoogleStorageExceptionMappingService().map("Failure to write attributes of {0}", e, container); } } GoogleStorageLifecycleFeature(final GoogleStorageSession session); @Override void setConfiguration(final Path file, final LifecycleConfiguration configuration); @Override LifecycleConfiguration getConfiguration(final Path file); }
GoogleStorageLifecycleFeature implements Lifecycle { @Override public void setConfiguration(final Path file, final LifecycleConfiguration configuration) throws BackgroundException { final Path container = containerService.getContainer(file); try { if(configuration.getTransition() != null || configuration.getExpiration() != null) { final Bucket.Lifecycle config = new Bucket.Lifecycle(); final List<Bucket.Lifecycle.Rule> rules = new ArrayList<>(); if(configuration.getTransition() != null) { rules.add(new Bucket.Lifecycle.Rule().setCondition(new Bucket.Lifecycle.Rule.Condition().setIsLive(true).setAge(configuration.getTransition())) .setAction(new Bucket.Lifecycle.Rule.Action().setType("SetStorageClass").setStorageClass(configuration.getStorageClass()))); } if(configuration.getExpiration() != null) { rules.add(new Bucket.Lifecycle.Rule().setCondition(new Bucket.Lifecycle.Rule.Condition().setIsLive(true).setAge(configuration.getExpiration())) .setAction(new Bucket.Lifecycle.Rule.Action().setType("Delete"))); } session.getClient().buckets().patch(container.getName(), new Bucket().setLifecycle( config.setRule(rules))).execute(); } else { session.getClient().buckets().patch(container.getName(), new Bucket().setLifecycle(new Bucket.Lifecycle().setRule(Collections.emptyList()))).execute(); } } catch(IOException e) { throw new GoogleStorageExceptionMappingService().map("Failure to write attributes of {0}", e, container); } } GoogleStorageLifecycleFeature(final GoogleStorageSession session); @Override void setConfiguration(final Path file, final LifecycleConfiguration configuration); @Override LifecycleConfiguration getConfiguration(final Path file);  }