use of com.amazonaws.services.s3.model.Tag in project SimianArmy by Netflix.
the class EBSSnapshotJanitorCrawler method getSnapshotResources.
private List<Resource> getSnapshotResources(String... snapshotIds) {
refreshSnapshotToAMIs();
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;
}
use of com.amazonaws.services.s3.model.Tag in project ice by Netflix.
the class BasicManagers method doWork.
private void doWork() {
logger.info("trying to find new tag group and data managers...");
Set<Product> products = Sets.newHashSet(this.products);
Map<Product, BasicTagGroupManager> tagGroupManagers = Maps.newHashMap(this.tagGroupManagers);
TreeMap<Key, BasicDataManager> costManagers = Maps.newTreeMap(this.costManagers);
TreeMap<Key, BasicDataManager> usageManagers = Maps.newTreeMap(this.usageManagers);
Set<Product> newProducts = Sets.newHashSet();
AmazonS3Client s3Client = AwsUtils.getAmazonS3Client();
for (S3ObjectSummary s3ObjectSummary : s3Client.listObjects(config.workS3BucketName, config.workS3BucketPrefix + TagGroupWriter.DB_PREFIX).getObjectSummaries()) {
String key = s3ObjectSummary.getKey();
Product product;
if (key.endsWith("_all")) {
product = null;
} else {
String name = key.substring((config.workS3BucketPrefix + TagGroupWriter.DB_PREFIX).length());
product = config.productService.getProductByName(name);
}
if (!products.contains(product)) {
products.add(product);
newProducts.add(product);
}
}
for (Product product : newProducts) {
tagGroupManagers.put(product, new BasicTagGroupManager(product));
for (ConsolidateType consolidateType : ConsolidateType.values()) {
Key key = new Key(product, consolidateType);
costManagers.put(key, new BasicDataManager(product, consolidateType, true));
usageManagers.put(key, new BasicDataManager(product, consolidateType, false));
}
}
if (newProducts.size() > 0) {
this.costManagers = costManagers;
this.usageManagers = usageManagers;
this.tagGroupManagers = tagGroupManagers;
this.products = products;
}
}
use of com.amazonaws.services.s3.model.Tag in project GNS by MobilityFirst.
the class AWSEC2 method addInstanceTags.
/**
* Adds keys and values from tagmap to the tags of the given instance.
*
* @param ec2
* @param createdInstanceId
* @param tagmap
*/
public static void addInstanceTags(AmazonEC2 ec2, String createdInstanceId, Map<String, String> tagmap) {
List<String> resources = new LinkedList<>();
resources.add(createdInstanceId);
List<Tag> tags = new LinkedList<>();
for (Entry<String, String> entry : tagmap.entrySet()) {
Tag nameTag = new Tag(entry.getKey(), entry.getValue());
tags.add(nameTag);
}
CreateTagsRequest ctr = new CreateTagsRequest(resources, tags);
ec2.createTags(ctr);
}
use of com.amazonaws.services.s3.model.Tag in project aws-doc-sdk-examples by awsdocs.
the class CreateInstance method main.
public static void main(String[] args) {
final String USAGE = "To run this example, supply an instance name and AMI image id\n" + "Ex: CreateInstance <instance-name> <ami-image-id>\n";
if (args.length != 2) {
System.out.println(USAGE);
System.exit(1);
}
String name = args[0];
String ami_id = args[1];
final AmazonEC2 ec2 = AmazonEC2ClientBuilder.defaultClient();
RunInstancesRequest run_request = new RunInstancesRequest().withImageId(ami_id).withInstanceType(InstanceType.T1Micro).withMaxCount(1).withMinCount(1);
RunInstancesResult run_response = ec2.runInstances(run_request);
String instance_id = run_response.getReservation().getReservationId();
Tag tag = new Tag().withKey("Name").withValue(name);
CreateTagsRequest tag_request = new CreateTagsRequest().withTags(tag);
CreateTagsResult tag_response = ec2.createTags(tag_request);
System.out.printf("Successfully started EC2 instance %s based on AMI %s", instance_id, ami_id);
}
use of com.amazonaws.services.s3.model.Tag in project XRTB by benmfaul.
the class Configuration method processDirectory.
public void processDirectory(AmazonS3Client s3, ObjectListing listing, String bucket) throws Exception {
for (S3ObjectSummary objectSummary : listing.getObjectSummaries()) {
long size = objectSummary.getSize();
System.out.println("*** Processing S3 " + objectSummary.getKey() + ", size = " + size);
S3Object object = s3.getObject(new GetObjectRequest(bucket, objectSummary.getKey()));
String bucketName = object.getBucketName();
String keyName = object.getKey();
if (keyName.contains("Darren")) {
System.out.println("HERE");
}
GetObjectTaggingRequest request = new GetObjectTaggingRequest(bucketName, keyName);
GetObjectTaggingResult result = s3.getObjectTagging(request);
List<Tag> tags = result.getTagSet();
String type = null;
String name = null;
if (tags.isEmpty()) {
System.err.println("Error: " + keyName + " has no tags");
} else {
for (Tag tag : tags) {
String key = tag.getKey();
String value = tag.getValue();
if (key.equals("type")) {
type = value;
}
if (key.equals("name")) {
name = value;
}
}
if (name == null)
throw new Exception("Error: " + keyName + " is missing a name tag");
if (name.contains(" "))
throw new Exception("Error: " + keyName + " has a name attribute with a space in it");
if (type == null)
throw new Exception("Error: " + keyName + " has no type tag");
if (!name.startsWith("$"))
name = "$" + name;
readData(type, name, object, size);
}
}
}
Aggregations