@Test public void testGetConfigurationEnabled() 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); assertTrue(feature.getConfiguration(bucket).isEnabled()); new SpectraDeleteFeature(session).delete(Collections.singletonList(bucket), new DisabledLoginCallback(), new Delete.DisabledCallback()); session.close(); }
@Override public VersioningConfiguration getConfiguration(final Path file) throws BackgroundException { final Ds3Client client = new SpectraClientBuilder().wrap(session.getClient(), session.getHost()); final Path container = containerService.getContainer(file); if(container.isRoot()) { return VersioningConfiguration.empty(); } if(cache.contains(container)) { return cache.get(container); } try { final GetBucketSpectraS3Response bucket = client.getBucketSpectraS3(new GetBucketSpectraS3Request(container.getName())); final GetDataPolicySpectraS3Response policy = client.getDataPolicySpectraS3( new GetDataPolicySpectraS3Request(bucket.getBucketResult().getDataPolicyId())); final VersioningConfiguration configuration = new VersioningConfiguration( policy.getDataPolicyResult().getVersioning() == VersioningLevel.KEEP_MULTIPLE_VERSIONS, false); cache.put(container, configuration); return configuration; } catch(FailedRequestException e) { throw new SpectraExceptionMappingService().map("Cannot read container configuration", e); } catch(IOException e) { throw new DefaultIOExceptionMappingService().map("Cannot read container configuration", e); } }
SpectraVersioningFeature implements Versioning { @Override public VersioningConfiguration getConfiguration(final Path file) throws BackgroundException { final Ds3Client client = new SpectraClientBuilder().wrap(session.getClient(), session.getHost()); final Path container = containerService.getContainer(file); if(container.isRoot()) { return VersioningConfiguration.empty(); } if(cache.contains(container)) { return cache.get(container); } try { final GetBucketSpectraS3Response bucket = client.getBucketSpectraS3(new GetBucketSpectraS3Request(container.getName())); final GetDataPolicySpectraS3Response policy = client.getDataPolicySpectraS3( new GetDataPolicySpectraS3Request(bucket.getBucketResult().getDataPolicyId())); final VersioningConfiguration configuration = new VersioningConfiguration( policy.getDataPolicyResult().getVersioning() == VersioningLevel.KEEP_MULTIPLE_VERSIONS, false); cache.put(container, configuration); return configuration; } catch(FailedRequestException e) { throw new SpectraExceptionMappingService().map("Cannot read container configuration", e); } catch(IOException e) { throw new DefaultIOExceptionMappingService().map("Cannot read container configuration", e); } } }
SpectraVersioningFeature implements Versioning { @Override public VersioningConfiguration getConfiguration(final Path file) throws BackgroundException { final Ds3Client client = new SpectraClientBuilder().wrap(session.getClient(), session.getHost()); final Path container = containerService.getContainer(file); if(container.isRoot()) { return VersioningConfiguration.empty(); } if(cache.contains(container)) { return cache.get(container); } try { final GetBucketSpectraS3Response bucket = client.getBucketSpectraS3(new GetBucketSpectraS3Request(container.getName())); final GetDataPolicySpectraS3Response policy = client.getDataPolicySpectraS3( new GetDataPolicySpectraS3Request(bucket.getBucketResult().getDataPolicyId())); final VersioningConfiguration configuration = new VersioningConfiguration( policy.getDataPolicyResult().getVersioning() == VersioningLevel.KEEP_MULTIPLE_VERSIONS, false); cache.put(container, configuration); return configuration; } catch(FailedRequestException e) { throw new SpectraExceptionMappingService().map("Cannot read container configuration", e); } catch(IOException e) { throw new DefaultIOExceptionMappingService().map("Cannot read container configuration", e); } } SpectraVersioningFeature(final SpectraSession session); }
SpectraVersioningFeature implements Versioning { @Override public VersioningConfiguration getConfiguration(final Path file) throws BackgroundException { final Ds3Client client = new SpectraClientBuilder().wrap(session.getClient(), session.getHost()); final Path container = containerService.getContainer(file); if(container.isRoot()) { return VersioningConfiguration.empty(); } if(cache.contains(container)) { return cache.get(container); } try { final GetBucketSpectraS3Response bucket = client.getBucketSpectraS3(new GetBucketSpectraS3Request(container.getName())); final GetDataPolicySpectraS3Response policy = client.getDataPolicySpectraS3( new GetDataPolicySpectraS3Request(bucket.getBucketResult().getDataPolicyId())); final VersioningConfiguration configuration = new VersioningConfiguration( policy.getDataPolicyResult().getVersioning() == VersioningLevel.KEEP_MULTIPLE_VERSIONS, false); cache.put(container, configuration); return configuration; } catch(FailedRequestException e) { throw new SpectraExceptionMappingService().map("Cannot read container configuration", e); } catch(IOException e) { throw new DefaultIOExceptionMappingService().map("Cannot read container configuration", e); } } 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 VersioningConfiguration getConfiguration(final Path file) throws BackgroundException { final Ds3Client client = new SpectraClientBuilder().wrap(session.getClient(), session.getHost()); final Path container = containerService.getContainer(file); if(container.isRoot()) { return VersioningConfiguration.empty(); } if(cache.contains(container)) { return cache.get(container); } try { final GetBucketSpectraS3Response bucket = client.getBucketSpectraS3(new GetBucketSpectraS3Request(container.getName())); final GetDataPolicySpectraS3Response policy = client.getDataPolicySpectraS3( new GetDataPolicySpectraS3Request(bucket.getBucketResult().getDataPolicyId())); final VersioningConfiguration configuration = new VersioningConfiguration( policy.getDataPolicyResult().getVersioning() == VersioningLevel.KEEP_MULTIPLE_VERSIONS, false); cache.put(container, configuration); return configuration; } catch(FailedRequestException e) { throw new SpectraExceptionMappingService().map("Cannot read container configuration", e); } catch(IOException e) { throw new DefaultIOExceptionMappingService().map("Cannot read container configuration", e); } } 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; }