@Override public List<AbstractResource<?>> describeVolumes(Account account, Region region, DateTime dt, Ec2Filter... filters) { AmazonEC2 ec2 = findClient(account, region); DescribeVolumesRequest req = new DescribeVolumesRequest(); for (Ec2Filter filter : filters) { Filter f = new Filter().withName(filter.getName()).withValues(filter.getValues()); req.withFilters(f); } log.debug("start describing volumes for account:{} in region:{} via api", account.getId() + "=>" + account.getName(), region); DescribeVolumesResult res = ec2.describeVolumes(req); List<Boolean> autoEnableIOs = new ArrayList<>(); List<List<ProductCode>> productCodes = new ArrayList<>(); for (Volume volume : res.getVolumes()) { autoEnableIOs.add(findAutoEnableIO(account, region, volume.getVolumeId())); productCodes.add(findProductCodes(account, region, volume.getVolumeId())); } return converter.toEc2Volumes(res.getVolumes(), autoEnableIOs, productCodes, account.getId(), region, dt); }
@Override public List<AbstractResource<?>> describeSnapshots(Account account, Region region, DateTime dt, Ec2Filter... filters) { AmazonEC2 ec2 = findClient(account, region); DescribeSnapshotsRequest req = new DescribeSnapshotsRequest(); for (Ec2Filter filter : filters) { Filter f = new Filter().withName(filter.getName()).withValues(filter.getValues()); req.withFilters(f); } log.debug("start describing snapshots for account:{} in region:{} via api", account.getId() + "=>" + account.getName(), region); DescribeSnapshotsResult res = ec2.describeSnapshots(req); List<List<CreateVolumePermission>> createVolumePermissions = new ArrayList<>(); List<List<ProductCode>> productCodes = new ArrayList<>(); for (Snapshot snapShot : res.getSnapshots()) { productCodes.add(findSnapshotProductCodes(account, region, snapShot.getSnapshotId())); createVolumePermissions.add(findCreateVolumePermissions(account, region, snapShot.getSnapshotId())); } return converter.toEc2Snapshots(res.getSnapshots(), createVolumePermissions, productCodes, account.getId(), region, dt); }
@Override protected ProductCode convertObject(String from) { ProductCode to = new ProductCode(); to.setProductCodeId(from); return to; }
public List<AbstractResource<?>> toEc2Volumes(List<Volume> volumes, List<Boolean> autoEnableIOs, List<List<ProductCode>> productCodes, String accountId, Region region, DateTime dt) { List<AbstractResource<?>> resources = new ArrayList<>(); for (int i = 0; i < volumes.size(); i++) { Ec2Volume ec2Volume = new Ec2Volume(); ec2Volume.setAutoEnableIO(autoEnableIOs.get(i)); ec2Volume.setProductCodes(productCodes.get(i)); conf(ec2Volume, accountId, region, dt); ec2Volume.setResource(volumes.get(i)); resources.add(ec2Volume); } log.debug("{} volumes found via api and converted to Ec2Volume", resources.size()); return resources; }
public List<AbstractResource<?>> toEc2Snapshots(List<Snapshot> snapshots, List<List<CreateVolumePermission>> createVolumePermissions, List<List<ProductCode>> productCodes, String accountId, Region region, DateTime dt) { List<AbstractResource<?>> resources = new ArrayList<>(); for (int i = 0; i < snapshots.size(); i++) { Ec2Snapshot ec2Snapshot = new Ec2Snapshot(); conf(ec2Snapshot, accountId, region, dt); ec2Snapshot.setResource(snapshots.get(i)); ec2Snapshot.setCreateVolumePermissions(createVolumePermissions.get(i)); ec2Snapshot.setProductCodes(productCodes.get(i)); resources.add(ec2Snapshot); } log.debug("{} snapshots found via api and converted to Ec2Snapshot", resources.size()); return resources; }
@Override public List<ProductCode> findProductCodes(Account account, Region region, String volumeId) { AmazonEC2 ec2 = findClient(account, region); DescribeVolumeAttributeRequest req = new DescribeVolumeAttributeRequest(); req.setVolumeId(volumeId); req.setAttribute("productCodes"); log.debug("start describing volume attribute product codes for account:{} in region:{} via api", account.getId() + "=>" + account.getName(), region); return ec2.describeVolumeAttribute(req).getProductCodes(); }
@Override public List<ProductCode> findSnapshotProductCodes(Account account, Region region, String snapshotId) { AmazonEC2 ec2 = findClient(account, region); DescribeSnapshotAttributeRequest req = new DescribeSnapshotAttributeRequest(); req.setAttribute("productCodes"); req.setSnapshotId(snapshotId); log.debug("start describing snapshot productCodes for account:{} in region:{} via api", account.getId() + "=>" + account.getName(), region); DescribeSnapshotAttributeResult res = ec2.describeSnapshotAttribute(req); return res.getProductCodes(); }
@Override public List<ProductCode> getProductCodes() { return (List<ProductCode>) resource.getAttribute("ProductCodes"); }
public List<ProductCode> getProductCodes() { return productCodes; }
public void setProductCodes(List<ProductCode> productCodes) { this.productCodes = productCodes; }
@Override public int compare(ProductCode p1, ProductCode p2) { return new CompareToBuilder().append(p1.getProductCodeId(), p2.getProductCodeId()).toComparison(); }
/** * Gets the value of the ProductCodes attribute. If this resource is not yet * loaded, a call to {@code load()} is made to retrieve the value of the * attribute. */ List<ProductCode> getProductCodes();
List<ProductCode> findProductCodes(Account account, Region region, String volumeId);
List<ProductCode> findSnapshotProductCodes(Account account, Region region, String snapshotId);