public static void main(String[] args) { final AmazonGlacier glacier = AmazonGlacierClientBuilder.defaultClient(); ListVaultsRequest request = new ListVaultsRequest(); boolean list_complete = false; int total_vaults = 0; System.out.println("Your Amazon Glacier vaults:"); while (!list_complete) { ListVaultsResult result = glacier.listVaults(request); List<DescribeVaultOutput> vault_list = result.getVaultList(); for (DescribeVaultOutput v: vault_list) { total_vaults += 1; System.out.println("* " + v.getVaultName()); } // check for further results. String marker = result.getMarker(); if (marker != null) { request.setMarker(marker); } else { list_complete = true; } } if (total_vaults == 0) { System.out.println(" no vaults found."); } }
@Produces @Omakase public GlacierClient getGlacierClient() { RuntimeCredentialsProvider provider = new RuntimeCredentialsProvider(); AmazonGlacier amazonGlacier = new AmazonGlacierClient(provider); return new GlacierClient(httpClient, provider, amazonGlacier); }
/** * Collect data for Glacier. * * @param stats * current statistics object. * @param account * currently used credentials object. * @param region * currently used aws region. */ public static void scanGlacier(AwsStats stats, AwsAccount account, Regions region) { LOG.debug("Scan for Glacier in region " + region.getName() + " in account " + account.getAccountId()); try { AmazonGlacier glacier = new AmazonGlacierClient(account.getCredentials()); glacier.setRegion(Region.getRegion(region)); // DescribeVaultRequest dvr = new DescribeVaultRequest(); ListVaultsRequest lvr = new ListVaultsRequest(); int totalItems = 0; for (DescribeVaultOutput dvo : glacier.listVaults(lvr).getVaultList()) { AwsResource res = new AwsResource(dvo.getVaultName(), account.getAccountId(), AwsResourceType.Glacier, region); res.addInfo("NumberOfArchives", dvo.getNumberOfArchives()); res.addInfo("VaultARN", dvo.getVaultARN()); res.addInfo(AwsTag.SizeInBytes, dvo.getSizeInBytes()); stats.add(res); totalItems++; } LOG.info(totalItems + " Glacier in region " + region.getName() + " in account " + account.getAccountId()); } catch (AmazonServiceException ase) { if (ase.getErrorCode().contains("AccessDenied")) { LOG.info("Access denied for Glacier in region " + region.getName() + " in account " + account.getAccountId()); } else { LOG.error("Exception of Glacier: " + ase.getMessage()); } } }
/** * Construct a service implementation using the specified client object. * * @param client The low-level client which the service implementation will * use to make API calls. */ public GlacierImpl(AmazonGlacier client) { ServiceModel model = V1ModelLoader.load(Glacier.class, Glacier.class.getAnnotation(V1ServiceInterface.class).model()); this.service = new ServiceImpl<AmazonGlacier>(model, client); }
public GlacierImpl(ServiceImpl<AmazonGlacier> service) { this.service = service; }
@Override public AmazonGlacier client() { return service.getClient(); }
/** * Creates a new AWS Glacier Client. * * @param httpClient * the underlying http client used by the Glacier client. * @param runtimeCredentialsProvider * the {@link RuntimeCredentialsProvider} used when creating the {@link AmazonGlacier} client. * @param amazonGlacier * a {@link AmazonGlacier} client instance that has been created using the runtime credential provider above. */ public GlacierClient(HttpClient httpClient, RuntimeCredentialsProvider runtimeCredentialsProvider, AmazonGlacier amazonGlacier) { this.httpClient = httpClient; this.runtimeCredentialsProvider = runtimeCredentialsProvider; this.amazonGlacier = amazonGlacier; }