@Test @Ignore public void testSetConfiguration() throws Exception { final Host host = new Host(new SpectraProtocol() { @Override public Scheme getScheme() { return Scheme.http; } }, System.getProperties().getProperty("spectra.hostname"), Integer.valueOf(System.getProperties().getProperty("spectra.port")), new Credentials( System.getProperties().getProperty("spectra.user"), System.getProperties().getProperty("spectra.key") )); final SpectraSession session = new SpectraSession(host, new DisabledX509TrustManager(), new DefaultX509KeyManager()); session.open(Proxy.DIRECT, new DisabledHostKeyCallback(), new DisabledLoginCallback()); session.login(Proxy.DIRECT, new DisabledLoginCallback(), new DisabledCancelCallback()); final Path bucket = new Path(new S3HomeFinderService(session).find(), UUID.randomUUID().toString(), EnumSet.of(Path.Type.directory, Path.Type.volume)); new SpectraDirectoryFeature(session, new SpectraWriteFeature(session)).mkdir(bucket, null, new TransferStatus()); final Versioning feature = new SpectraVersioningFeature(session); feature.setConfiguration(bucket, new DisabledLoginCallback(), new VersioningConfiguration(true, false)); assertTrue(feature.getConfiguration(bucket).isEnabled()); new SpectraDeleteFeature(session).delete(Collections.singletonList(bucket), new DisabledLoginCallback(), new Delete.DisabledCallback()); session.close(); }
@Override public void setConfiguration(final Path file, final PasswordCallback prompt, final VersioningConfiguration configuration) throws BackgroundException { final Path container = containerService.getContainer(file); try { final VersioningConfiguration current = this.getConfiguration(container); if(configuration.isEnabled()) { if(current.isEnabled()) { log.debug(String.format("Versioning already enabled for bucket %s", container)); } else { log.debug(String.format("Enable bucket versioning for %s", container)); final Ds3Client client = new SpectraClientBuilder().wrap(session.getClient(), session.getHost()); final GetBucketSpectraS3Response bucket = client.getBucketSpectraS3(new GetBucketSpectraS3Request(container.getName())); final UUID id = bucket.getBucketResult().getDataPolicyId(); client.modifyDataPolicySpectraS3(new ModifyDataPolicySpectraS3Request(id).withVersioning(VersioningLevel.KEEP_MULTIPLE_VERSIONS)); } } else { log.warn(String.format("Disable bucket versioning for %s is not supported", container)); } cache.remove(container); } catch(FailedRequestException e) { throw new SpectraExceptionMappingService().map("Failure to write attributes of {0}", e, container); } catch(IOException e) { throw new DefaultIOExceptionMappingService().map("Failure to write attributes of {0}", e, container); } }
SpectraVersioningFeature implements Versioning { @Override public void setConfiguration(final Path file, final PasswordCallback prompt, final VersioningConfiguration configuration) throws BackgroundException { final Path container = containerService.getContainer(file); try { final VersioningConfiguration current = this.getConfiguration(container); if(configuration.isEnabled()) { if(current.isEnabled()) { log.debug(String.format("Versioning already enabled for bucket %s", container)); } else { log.debug(String.format("Enable bucket versioning for %s", container)); final Ds3Client client = new SpectraClientBuilder().wrap(session.getClient(), session.getHost()); final GetBucketSpectraS3Response bucket = client.getBucketSpectraS3(new GetBucketSpectraS3Request(container.getName())); final UUID id = bucket.getBucketResult().getDataPolicyId(); client.modifyDataPolicySpectraS3(new ModifyDataPolicySpectraS3Request(id).withVersioning(VersioningLevel.KEEP_MULTIPLE_VERSIONS)); } } else { log.warn(String.format("Disable bucket versioning for %s is not supported", container)); } cache.remove(container); } catch(FailedRequestException e) { throw new SpectraExceptionMappingService().map("Failure to write attributes of {0}", e, container); } catch(IOException e) { throw new DefaultIOExceptionMappingService().map("Failure to write attributes of {0}", e, container); } } }
SpectraVersioningFeature implements Versioning { @Override public void setConfiguration(final Path file, final PasswordCallback prompt, final VersioningConfiguration configuration) throws BackgroundException { final Path container = containerService.getContainer(file); try { final VersioningConfiguration current = this.getConfiguration(container); if(configuration.isEnabled()) { if(current.isEnabled()) { log.debug(String.format("Versioning already enabled for bucket %s", container)); } else { log.debug(String.format("Enable bucket versioning for %s", container)); final Ds3Client client = new SpectraClientBuilder().wrap(session.getClient(), session.getHost()); final GetBucketSpectraS3Response bucket = client.getBucketSpectraS3(new GetBucketSpectraS3Request(container.getName())); final UUID id = bucket.getBucketResult().getDataPolicyId(); client.modifyDataPolicySpectraS3(new ModifyDataPolicySpectraS3Request(id).withVersioning(VersioningLevel.KEEP_MULTIPLE_VERSIONS)); } } else { log.warn(String.format("Disable bucket versioning for %s is not supported", container)); } cache.remove(container); } catch(FailedRequestException e) { throw new SpectraExceptionMappingService().map("Failure to write attributes of {0}", e, container); } catch(IOException e) { throw new DefaultIOExceptionMappingService().map("Failure to write attributes of {0}", e, container); } } SpectraVersioningFeature(final SpectraSession session); }
SpectraVersioningFeature implements Versioning { @Override public void setConfiguration(final Path file, final PasswordCallback prompt, final VersioningConfiguration configuration) throws BackgroundException { final Path container = containerService.getContainer(file); try { final VersioningConfiguration current = this.getConfiguration(container); if(configuration.isEnabled()) { if(current.isEnabled()) { log.debug(String.format("Versioning already enabled for bucket %s", container)); } else { log.debug(String.format("Enable bucket versioning for %s", container)); final Ds3Client client = new SpectraClientBuilder().wrap(session.getClient(), session.getHost()); final GetBucketSpectraS3Response bucket = client.getBucketSpectraS3(new GetBucketSpectraS3Request(container.getName())); final UUID id = bucket.getBucketResult().getDataPolicyId(); client.modifyDataPolicySpectraS3(new ModifyDataPolicySpectraS3Request(id).withVersioning(VersioningLevel.KEEP_MULTIPLE_VERSIONS)); } } else { log.warn(String.format("Disable bucket versioning for %s is not supported", container)); } cache.remove(container); } catch(FailedRequestException e) { throw new SpectraExceptionMappingService().map("Failure to write attributes of {0}", e, container); } catch(IOException e) { throw new DefaultIOExceptionMappingService().map("Failure to write attributes of {0}", e, container); } } SpectraVersioningFeature(final SpectraSession session); @Override Versioning withCache(final LRUCache<Path, VersioningConfiguration> cache); @Override VersioningConfiguration getConfiguration(final Path file); @Override void setConfiguration(final Path file, final PasswordCallback prompt, final VersioningConfiguration configuration); @Override boolean isRevertable(final Path file); @Override void revert(final Path file); @Override Credentials getToken(final String mfaSerial, final PasswordCallback callback); }
SpectraVersioningFeature implements Versioning { @Override public void setConfiguration(final Path file, final PasswordCallback prompt, final VersioningConfiguration configuration) throws BackgroundException { final Path container = containerService.getContainer(file); try { final VersioningConfiguration current = this.getConfiguration(container); if(configuration.isEnabled()) { if(current.isEnabled()) { log.debug(String.format("Versioning already enabled for bucket %s", container)); } else { log.debug(String.format("Enable bucket versioning for %s", container)); final Ds3Client client = new SpectraClientBuilder().wrap(session.getClient(), session.getHost()); final GetBucketSpectraS3Response bucket = client.getBucketSpectraS3(new GetBucketSpectraS3Request(container.getName())); final UUID id = bucket.getBucketResult().getDataPolicyId(); client.modifyDataPolicySpectraS3(new ModifyDataPolicySpectraS3Request(id).withVersioning(VersioningLevel.KEEP_MULTIPLE_VERSIONS)); } } else { log.warn(String.format("Disable bucket versioning for %s is not supported", container)); } cache.remove(container); } catch(FailedRequestException e) { throw new SpectraExceptionMappingService().map("Failure to write attributes of {0}", e, container); } catch(IOException e) { throw new DefaultIOExceptionMappingService().map("Failure to write attributes of {0}", e, container); } } SpectraVersioningFeature(final SpectraSession session); @Override Versioning withCache(final LRUCache<Path, VersioningConfiguration> cache); @Override VersioningConfiguration getConfiguration(final Path file); @Override void setConfiguration(final Path file, final PasswordCallback prompt, final VersioningConfiguration configuration); @Override boolean isRevertable(final Path file); @Override void revert(final Path file); @Override Credentials getToken(final String mfaSerial, final PasswordCallback callback); static final String KEY_REVERTABLE; }