List of usage examples for com.amazonaws.services.ec2.model Tag getKey
public String getKey()
The key of the tag.
From source file:com.infinitechaos.vpcviewer.web.rest.dto.TagDTO.java
License:Open Source License
public TagDTO(Tag tag) { this.key = tag.getKey(); this.value = tag.getValue(); }
From source file:com.ipcglobal.awscdh.config.ManageEc2.java
License:Apache License
/** * Find tag name./*from w w w . j a v a 2 s. co m*/ * * @param instance the instance * @return the string */ public static String findTagName(Instance instance) { for (Tag tag : instance.getTags()) if ("name".equalsIgnoreCase(tag.getKey())) return tag.getValue(); return ""; }
From source file:com.keybox.manage.db.SystemDB.java
License:Apache License
/** * HelpMethode to Transform EC2Instanz in HostSystem * //ww w .j av a2s . c o m * @param instance EC2Instanz * @param ec2Region EC2Region * @param awsCrde AWS Credential * @return hostSystem */ private static HostSystem transformerEC2InstanzToHostSystem(Instance instance, String ec2Region) { HostSystem hostSystem = new HostSystem(); hostSystem.setInstance(instance.getInstanceId()); //check for public dns if doesn't exist set to ip or pvt dns if (!"true".equals(AppConfig.getProperty("useEC2PvtDNS")) && StringUtils.isNotEmpty(instance.getPublicDnsName())) { hostSystem.setHost(instance.getPublicDnsName()); } else if (!"true".equals(AppConfig.getProperty("useEC2PvtDNS")) && StringUtils.isNotEmpty(instance.getPublicIpAddress())) { hostSystem.setHost(instance.getPublicIpAddress()); } else if (StringUtils.isNotEmpty(instance.getPrivateDnsName())) { hostSystem.setHost(instance.getPrivateDnsName()); } else { hostSystem.setHost(instance.getPrivateIpAddress()); } hostSystem.setApplicationKey(PrivateKeyDB.getEC2KeyByNmRegion(instance.getKeyName(), ec2Region)); hostSystem.setEc2Region(ec2Region); hostSystem.setStatusCd(instance.getState().getName().toUpperCase()); hostSystem.setUser(AppConfig.getProperty("defaultEC2User")); for (Tag tag : instance.getTags()) { if ("Name".equals(tag.getKey())) { hostSystem.setDisplayNm(tag.getValue()); } } return hostSystem; }
From source file:com.meltmedia.jgroups.aws.AWS_PING.java
License:Apache License
/** * Gets the list of private IP addresses found in AWS based on the filters and * tag names defined./*from w ww . j av a 2s .c o m*/ * * @return the list of private IP addresses found on AWS. */ protected List<String> getPrivateIpAddresses() { List<String> result = new ArrayList<String>(); List<Filter> filters = new ArrayList<Filter>(); // if there are aws tags defined, then look them up and create filters. if (awsTagNames != null) { Collection<Tag> instanceTags = getInstanceTags(ec2, instanceId); for (Tag instanceTag : instanceTags) { if (awsTagNames.contains(instanceTag.getKey())) { filters.add(new Filter("tag:" + instanceTag.getKey(), Arrays.asList(instanceTag.getValue()))); } } } // if there are aws filters defined, then add them to the list. if (awsFilters != null) { filters.addAll(awsFilters); } DescribeInstancesRequest request = new DescribeInstancesRequest().withFilters(filters); if (log.isDebugEnabled()) { log.debug("Describing AWS instances with the following filters [" + filters + "]"); log.debug("Making AWS Request {" + request + "}"); } // NOTE: the reservations group nodes together by when they were started. We // need to dig through all of the reservations. DescribeInstancesResult filterResult = ec2.describeInstances(request); for (Reservation reservation : filterResult.getReservations()) { for (Instance instance : reservation.getInstances()) { result.add(instance.getPrivateIpAddress()); } } if (log.isDebugEnabled()) { log.debug("Instances found [" + result + "]"); } return result; }
From source file:com.netflix.simianarmy.aws.conformity.rule.InstanceHasTag.java
License:Apache License
/** * Gets the tag keys for a list of instance ids of the same region. The default implementation * is using an AWS client. The method can be overridden in subclasses to get the tags differently. * @param region//from ww w . jav a 2s .c om * the region of the instances * @param instanceIds * the instance ids, all instances should be in the same region. * @return * the map from instance id to the list of tag keys the instance has */ protected Map<String, List<String>> getInstanceTags(String region, String... instanceIds) { Map<String, List<String>> result = Maps.newHashMap(); if (instanceIds == null || instanceIds.length == 0) { return result; } AWSClient awsClient = new AWSClient(region, awsCredentialsProvider); for (Instance instance : awsClient.describeInstances(instanceIds)) { // Ignore instances that are in VPC if (!"running".equals(instance.getState().getName())) { LOGGER.info(String.format("Instance %s is not running, state is %s.", instance.getInstanceId(), instance.getState().getName())); continue; } List<String> tags = Lists.newArrayList(); for (Tag instanceTag : instance.getTags()) { tags.add(instanceTag.getKey()); } result.put(instance.getInstanceId(), tags); } return result; }
From source file:com.netflix.simianarmy.aws.janitor.crawler.EBSSnapshotJanitorCrawler.java
License:Apache License
private List<Resource> getSnapshotResources(String... snapshotIds) { refreshSnapshotToAMIs();/* w w w . j a v a 2s. co m*/ List<Resource> resources = new LinkedList<Resource>(); AWSClient awsClient = getAWSClient(); for (Snapshot snapshot : awsClient.describeSnapshots(snapshotIds)) { Resource snapshotResource = new AWSResource().withId(snapshot.getSnapshotId()) .withRegion(getAWSClient().region()).withResourceType(AWSResourceType.EBS_SNAPSHOT) .withLaunchTime(snapshot.getStartTime()).withDescription(snapshot.getDescription()); for (Tag tag : snapshot.getTags()) { LOGGER.debug(String.format("Adding tag %s = %s to resource %s", tag.getKey(), tag.getValue(), snapshotResource.getId())); snapshotResource.setTag(tag.getKey(), tag.getValue()); } snapshotResource.setOwnerEmail(getOwnerEmailForResource(snapshotResource)); ((AWSResource) snapshotResource).setAWSResourceState(snapshot.getState()); Collection<String> amis = snapshotToAMIs.get(snapshotResource.getId()); if (amis != null) { snapshotResource.setAdditionalField(SNAPSHOT_FIELD_AMIS, StringUtils.join(amis, ",")); } resources.add(snapshotResource); } return resources; }
From source file:com.netflix.simianarmy.aws.janitor.crawler.EBSVolumeJanitorCrawler.java
License:Apache License
private List<Resource> getVolumeResources(String... volumeIds) { List<Resource> resources = new LinkedList<Resource>(); AWSClient awsClient = getAWSClient(); for (Volume volume : awsClient.describeVolumes(volumeIds)) { Resource volumeResource = new AWSResource().withId(volume.getVolumeId()) .withRegion(getAWSClient().region()).withResourceType(AWSResourceType.EBS_VOLUME) .withLaunchTime(volume.getCreateTime()); for (Tag tag : volume.getTags()) { LOGGER.info(String.format("Adding tag %s = %s to resource %s", tag.getKey(), tag.getValue(), volumeResource.getId())); volumeResource.setTag(tag.getKey(), tag.getValue()); }//from www.j a v a 2 s.c o m volumeResource.setOwnerEmail(getOwnerEmailForResource(volumeResource)); volumeResource.setDescription(getVolumeDescription(volume)); ((AWSResource) volumeResource).setAWSResourceState(volume.getState()); resources.add(volumeResource); } return resources; }
From source file:com.netflix.simianarmy.aws.janitor.crawler.EBSVolumeJanitorCrawler.java
License:Apache License
private String getVolumeDescription(Volume volume) { StringBuilder description = new StringBuilder(); Integer size = volume.getSize(); description.append(String.format("size=%s", size == null ? "unknown" : size)); for (Tag tag : volume.getTags()) { description.append(String.format("; %s=%s", tag.getKey(), tag.getValue())); }/*from ww w . j av a2 s. com*/ return description.toString(); }
From source file:com.netflix.simianarmy.aws.janitor.crawler.InstanceJanitorCrawler.java
License:Apache License
private List<Resource> getInstanceResources(String... instanceIds) { List<Resource> resources = new LinkedList<Resource>(); AWSClient awsClient = getAWSClient(); Map<String, AutoScalingInstanceDetails> idToASGInstance = new HashMap<String, AutoScalingInstanceDetails>(); for (AutoScalingInstanceDetails instanceDetails : awsClient.describeAutoScalingInstances(instanceIds)) { idToASGInstance.put(instanceDetails.getInstanceId(), instanceDetails); }//from w ww . java 2s . c o m for (Instance instance : awsClient.describeInstances(instanceIds)) { Resource instanceResource = new AWSResource().withId(instance.getInstanceId()) .withRegion(getAWSClient().region()).withResourceType(AWSResourceType.INSTANCE) .withLaunchTime(instance.getLaunchTime()); for (Tag tag : instance.getTags()) { instanceResource.setTag(tag.getKey(), tag.getValue()); } String description = String.format("type=%s; host=%s", instance.getInstanceType(), instance.getPublicDnsName() == null ? "" : instance.getPublicDnsName()); instanceResource.setDescription(description); instanceResource.setOwnerEmail(getOwnerEmailForResource(instanceResource)); String asgName = getAsgName(instanceResource, idToASGInstance); if (asgName != null) { instanceResource.setAdditionalField(INSTANCE_FIELD_ASG_NAME, asgName); LOGGER.info(String.format("instance %s has a ASG tag name %s.", instanceResource.getId(), asgName)); } if (instance.getState() != null) { ((AWSResource) instanceResource).setAWSResourceState(instance.getState().getName()); } resources.add(instanceResource); } return resources; }
From source file:com.netflix.simianarmy.aws.janitor.VolumeTaggingMonkey.java
License:Apache License
/** * The constructor.// www.jav a2 s. com * @param ctx the context */ public VolumeTaggingMonkey(Context ctx) { super(ctx); this.config = ctx.configuration(); this.awsClients = ctx.awsClients(); this.calendar = ctx.calendar(); awsClientToInstanceToOwner = Maps.newHashMap(); for (AWSClient awsClient : awsClients) { Map<String, String> instanceToOwner = Maps.newHashMap(); awsClientToInstanceToOwner.put(awsClient, instanceToOwner); for (Instance instance : awsClient.describeInstances()) { for (Tag tag : instance.getTags()) { if (tag.getKey().equals(JanitorMonkey.OWNER_TAG_KEY)) { instanceToOwner.put(instance.getInstanceId(), tag.getValue()); } } } } }