@Override public int hashCode() { final int prime = 31; int hashCode = 1; hashCode = prime * hashCode + ((getArchitecture() == null) ? 0 : getArchitecture().hashCode()); hashCode = prime * hashCode + ((getCreationDate() == null) ? 0 : getCreationDate().hashCode()); hashCode = prime * hashCode + ((getImageId() == null) ? 0 : getImageId().hashCode()); hashCode = prime * hashCode + ((getImageLocation() == null) ? 0 : getImageLocation().hashCode()); hashCode = prime * hashCode + ((getImageType() == null) ? 0 : getImageType().hashCode()); hashCode = prime * hashCode + ((getPublic() == null) ? 0 : getPublic().hashCode()); hashCode = prime * hashCode + ((getKernelId() == null) ? 0 : getKernelId().hashCode()); hashCode = prime * hashCode + ((getOwnerId() == null) ? 0 : getOwnerId().hashCode()); hashCode = prime * hashCode + ((getPlatform() == null) ? 0 : getPlatform().hashCode()); hashCode = prime * hashCode + ((getProductCodes() == null) ? 0 : getProductCodes().hashCode()); hashCode = prime * hashCode + ((getRamdiskId() == null) ? 0 : getRamdiskId().hashCode()); hashCode = prime * hashCode + ((getState() == null) ? 0 : getState().hashCode()); hashCode = prime * hashCode + ((getBlockDeviceMappings() == null) ? 0 : getBlockDeviceMappings().hashCode()); hashCode = prime * hashCode + ((getDescription() == null) ? 0 : getDescription().hashCode()); hashCode = prime * hashCode + ((getEnaSupport() == null) ? 0 : getEnaSupport().hashCode()); hashCode = prime * hashCode + ((getHypervisor() == null) ? 0 : getHypervisor().hashCode()); hashCode = prime * hashCode + ((getImageOwnerAlias() == null) ? 0 : getImageOwnerAlias().hashCode()); hashCode = prime * hashCode + ((getName() == null) ? 0 : getName().hashCode()); hashCode = prime * hashCode + ((getRootDeviceName() == null) ? 0 : getRootDeviceName().hashCode()); hashCode = prime * hashCode + ((getRootDeviceType() == null) ? 0 : getRootDeviceType().hashCode()); hashCode = prime * hashCode + ((getSriovNetSupport() == null) ? 0 : getSriovNetSupport().hashCode()); hashCode = prime * hashCode + ((getStateReason() == null) ? 0 : getStateReason().hashCode()); hashCode = prime * hashCode + ((getTags() == null) ? 0 : getTags().hashCode()); hashCode = prime * hashCode + ((getVirtualizationType() == null) ? 0 : getVirtualizationType().hashCode()); return hashCode; }
public Image unmarshall(StaxUnmarshallerContext context) throws Exception { Image image = new Image(); int originalDepth = context.getCurrentDepth(); int targetDepth = originalDepth + 1; image.setImageId(StringStaxUnmarshaller.getInstance().unmarshall(context)); continue; image.setImageLocation(StringStaxUnmarshaller.getInstance().unmarshall(context)); continue; image.setState(StringStaxUnmarshaller.getInstance().unmarshall(context)); continue; image.setOwnerId(StringStaxUnmarshaller.getInstance().unmarshall(context)); continue; image.setCreationDate(StringStaxUnmarshaller.getInstance().unmarshall(context)); continue; image.setPublic(BooleanStaxUnmarshaller.getInstance().unmarshall(context)); continue; image.getProductCodes().add(ProductCodeStaxUnmarshaller.getInstance().unmarshall(context)); continue; image.setArchitecture(StringStaxUnmarshaller.getInstance().unmarshall(context)); continue; image.setImageType(StringStaxUnmarshaller.getInstance().unmarshall(context));
.filter(img -> img.getName().startsWith(taupageNamePrefix)) .map(Image::getOwnerId) .map(taupageOwners::contains); taupageExpirationTimeProvider.getExpirationTime(region, image.getOwnerId(), image.getImageId())); if (optionalExpirationDate.isPresent()) { final ZonedDateTime expirationDate = optionalExpirationDate.get(); .withApplicationVersion(taupageYaml.map(TaupageYaml::getApplicationVersion).map(StringUtils::trimToNull).orElse(null)) .withMetaInfo(ImmutableMap.of( "ami_owner_id", image.getOwnerId(), "ami_id", image.getImageId(), "ami_name", image.getName(), "expiration_date", expirationDate.toString())) .build());
protected BlockDeviceMapping getRootBlockDeviceMapping(Image image) { String rootDeviceName = image.getRootDeviceName(); List<BlockDeviceMapping> mappings = image.getBlockDeviceMappings(); for (BlockDeviceMapping mapping : mappings) { String deviceName = mapping.getDeviceName(); if (rootDeviceName.equals(deviceName)) { return mapping; } } throw illegalState("Could not locate the root block device mapping for AMI [%s]", image.getImageId()); }
public String getId() { return image.getImageId(); } }
private List<BlockDeviceMapping> getAmiBlockDeviceMappings() { /* * AmazonEC2#describeImageAttribute does not work due to a bug * https://forums.aws.amazon.com/message.jspa?messageID=231972 */ for (final Image image: getParent().connect().describeImages().getImages()) { if (ami.equals(image.getImageId())) { return image.getBlockDeviceMappings(); } } throw new AmazonClientException("Unable to get AMI device mapping for " + ami); }
parameterName, lookupParameters.getProperty(parameterName), ami.getTags())) { isMissingLookupParams = true; break; return Optional.empty(); } else if (applicableAMIList.size() == 1) { return Optional.of(applicableAMIList.get(0).getImageId()); } else { String environment = ConfigurationContext. logger.info("Setting up AMI environment as " + environment); for (Image image : applicableAMIList) { for (Tag amiTag : image.getTags()) { if (AMI_TAG_TESTGRID_ENVIRONMENT.equals(amiTag.getKey())) { if (amiTag.getValue().equals(environment)) { return Optional.of(image.getImageId()); } else { logger.warn("Execution environment of TESTGRID_ENVIRONMENT is not set in config.properties."); return Optional.of(applicableAMIList.get(0).getImageId());
String ownerAlias = img.get(0).getImageOwnerAlias(); return FormValidation.ok(img.get(0).getImageLocation() + (ownerAlias != null ? " by " + ownerAlias : "")); } catch (AmazonClientException e) {
/** * Any block device mapping entries. * <p> * Returns a reference to this object so that method calls can be chained together. * * @param blockDeviceMappings Any block device mapping entries. * * @return A reference to this updated object so that method calls can be chained * together. */ public Image withBlockDeviceMappings(BlockDeviceMapping... blockDeviceMappings) { if (getBlockDeviceMappings() == null) setBlockDeviceMappings(new java.util.ArrayList<BlockDeviceMapping>(blockDeviceMappings.length)); for (BlockDeviceMapping value : blockDeviceMappings) { getBlockDeviceMappings().add(value); } return this; }
public String getName() { return image.getName(); }
private List<BlockDeviceMapping> getAmiBlockDeviceMappings() { /* * AmazonEC2#describeImageAttribute does not work due to a bug * https://forums.aws.amazon.com/message.jspa?messageID=231972 */ return getImage().getBlockDeviceMappings(); }
@Override public boolean isTrue() { Image image = service.getImage(imageId); return this.state.equals(image.getState()); }
private void updatePlatform() { // update the platform List<String> imageId = new ArrayList<String>(); imageId.add(amiId); List<Image> images = helper.getImages(null, imageId, ec2Client); if (images != null) { Image image = images.get(0); platform = image.getPlatform(); } if (platform == null || "".equals(platform)) { platform = "linux"; } }
private void setupRootDevice(List<BlockDeviceMapping> deviceMappings) { if (deleteRootOnTermination && getImage().getRootDeviceType().equals("ebs")) { // get the root device (only one expected in the blockmappings) final List<BlockDeviceMapping> rootDeviceMappings = getAmiBlockDeviceMappings(); BlockDeviceMapping rootMapping = null; for (final BlockDeviceMapping deviceMapping : rootDeviceMappings) { System.out.println("AMI had " + deviceMapping.getDeviceName()); System.out.println(deviceMapping.getEbs()); rootMapping = deviceMapping; break; } // Check if the root device is already in the mapping and update it for (final BlockDeviceMapping mapping : deviceMappings) { System.out.println("Request had " + mapping.getDeviceName()); if (rootMapping.getDeviceName().equals(mapping.getDeviceName())) { mapping.getEbs().setDeleteOnTermination(Boolean.TRUE); return; } } // Create a shadow of the AMI mapping (doesn't like reusing rootMapping directly) BlockDeviceMapping newMapping = new BlockDeviceMapping().withDeviceName(rootMapping.getDeviceName()); EbsBlockDevice newEbs = new EbsBlockDevice(); newEbs.setDeleteOnTermination(Boolean.TRUE); newMapping.setEbs(newEbs); deviceMappings.add(0, newMapping); } }
private Image getImage() { DescribeImagesRequest request = new DescribeImagesRequest().withImageIds(ami); for (final Image image : getParent().connect().describeImages(request).getImages()) { if (ami.equals(image.getImageId())) { return image; } } throw new AmazonClientException("Unable to find AMI " + ami); }
String ownerAlias = img.get(0).getImageOwnerAlias(); return FormValidation.ok(img.get(0).getImageLocation() + (ownerAlias != null ? " by " + ownerAlias : "")); } catch (AmazonClientException e) { return FormValidation.error(e.getMessage());
@Override public Optional<Boolean> isTaupageAmi() { return getAmi() .filter(image -> image.getName().startsWith(taupageNamePrefix)) .map(Image::getOwnerId) .map(taupageOwners::contains); }
@Override public void purgeAmi(String imageId) { Image image = getImage(imageId); List<String> snapshotIds = newArrayList(); List<BlockDeviceMapping> mappings = image.getBlockDeviceMappings(); for (BlockDeviceMapping mapping : mappings) { Optional<EbsBlockDevice> ebsBlockDevice = fromNullable(mapping.getEbs()); if (ebsBlockDevice.isPresent()) { snapshotIds.add(ebsBlockDevice.get().getSnapshotId()); } } DeregisterImageRequest request = new DeregisterImageRequest(); request.setImageId(imageId); client.deregisterImage(request); for (String snapshotId : snapshotIds) { deleteSnapshot(snapshotId); } }
return false; Image other = (Image) obj; if (other.getArchitecture() == null ^ this.getArchitecture() == null) return false; if (other.getArchitecture() != null && other.getArchitecture().equals(this.getArchitecture()) == false) return false; if (other.getCreationDate() == null ^ this.getCreationDate() == null) return false; if (other.getCreationDate() != null && other.getCreationDate().equals(this.getCreationDate()) == false) return false; if (other.getImageId() == null ^ this.getImageId() == null) return false; if (other.getImageId() != null && other.getImageId().equals(this.getImageId()) == false) return false; if (other.getImageLocation() == null ^ this.getImageLocation() == null) return false; if (other.getImageLocation() != null && other.getImageLocation().equals(this.getImageLocation()) == false) return false; if (other.getImageType() == null ^ this.getImageType() == null) return false; if (other.getImageType() != null && other.getImageType().equals(this.getImageType()) == false) return false; if (other.getPublic() == null ^ this.getPublic() == null) return false; if (other.getPublic() != null && other.getPublic().equals(this.getPublic()) == false) return false; if (other.getKernelId() == null ^ this.getKernelId() == null) return false; if (other.getKernelId() != null && other.getKernelId().equals(this.getKernelId()) == false)
@Override protected void doScan() { AmazonEC2Client c = getClient(); NeoRxClient neoRx = getNeoRxClient(); Preconditions.checkNotNull(neoRx); GraphNodeGarbageCollector gc = newGarbageCollector().bindScannerContext(); DescribeImagesRequest req = new DescribeImagesRequest().withOwners("self"); DescribeImagesResult result = c.describeImages(req); rateLimit(); result.getImages().forEach(i -> { try { ObjectNode n = convertAwsObject(i, getRegion()); String cypher = "merge (x:AwsAmi {aws_arn:{aws_arn}}) set x+={props} set x.updateTs=timestamp() return x"; neoRx.execCypher(cypher, "aws_arn", n.path("aws_arn").asText(), "props",n).forEach( r->{ gc.MERGE_ACTION.accept(r); getShadowAttributeRemover().removeTagAttributes("AwsAmi", n, r); }); incrementEntityCount(); } catch (RuntimeException e) { maybeThrow(e,"problem scanning AMI "+i.getImageId()); } }); }