Search in sources :

Example 6 with Tag

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;
}
Also used : Snapshot(com.amazonaws.services.ec2.model.Snapshot) AWSResource(com.netflix.simianarmy.aws.AWSResource) Resource(com.netflix.simianarmy.Resource) AWSResource(com.netflix.simianarmy.aws.AWSResource) AWSClient(com.netflix.simianarmy.client.aws.AWSClient) Tag(com.amazonaws.services.ec2.model.Tag) LinkedList(java.util.LinkedList)

Example 7 with Tag

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;
    }
}
Also used : AmazonS3Client(com.amazonaws.services.s3.AmazonS3Client) Product(com.netflix.ice.tag.Product) S3ObjectSummary(com.amazonaws.services.s3.model.S3ObjectSummary)

Example 8 with Tag

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);
}
Also used : CreateTagsRequest(com.amazonaws.services.ec2.model.CreateTagsRequest) Tag(com.amazonaws.services.ec2.model.Tag) LinkedList(java.util.LinkedList)

Example 9 with Tag

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);
}
Also used : CreateTagsResult(com.amazonaws.services.ec2.model.CreateTagsResult) CreateTagsRequest(com.amazonaws.services.ec2.model.CreateTagsRequest) RunInstancesResult(com.amazonaws.services.ec2.model.RunInstancesResult) AmazonEC2(com.amazonaws.services.ec2.AmazonEC2) RunInstancesRequest(com.amazonaws.services.ec2.model.RunInstancesRequest) Tag(com.amazonaws.services.ec2.model.Tag)

Example 10 with Tag

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);
        }
    }
}
Also used : GetObjectTaggingRequest(com.amazonaws.services.s3.model.GetObjectTaggingRequest) S3ObjectSummary(com.amazonaws.services.s3.model.S3ObjectSummary) S3Object(com.amazonaws.services.s3.model.S3Object) GeoTag(com.xrtb.geo.GeoTag) Tag(com.amazonaws.services.s3.model.Tag) GetObjectRequest(com.amazonaws.services.s3.model.GetObjectRequest) GetObjectTaggingResult(com.amazonaws.services.s3.model.GetObjectTaggingResult)

Aggregations

Tag (com.amazonaws.services.ec2.model.Tag)14 ArrayList (java.util.ArrayList)6 LinkedList (java.util.LinkedList)5 List (java.util.List)4 DiscoveryNode (org.elasticsearch.cluster.node.DiscoveryNode)4 CreateTagsRequest (com.amazonaws.services.ec2.model.CreateTagsRequest)3 Instance (com.amazonaws.services.ec2.model.Instance)3 Resource (com.netflix.simianarmy.Resource)3 AWSResource (com.netflix.simianarmy.aws.AWSResource)3 AWSClient (com.netflix.simianarmy.client.aws.AWSClient)3 Settings (org.elasticsearch.common.settings.Settings)3 AmazonEC2 (com.amazonaws.services.ec2.AmazonEC2)2 DescribeInstancesResult (com.amazonaws.services.ec2.model.DescribeInstancesResult)2 Reservation (com.amazonaws.services.ec2.model.Reservation)2 Volume (com.amazonaws.services.ec2.model.Volume)2 S3ObjectSummary (com.amazonaws.services.s3.model.S3ObjectSummary)2 HashMap (java.util.HashMap)2 TransportAddress (org.elasticsearch.common.transport.TransportAddress)2 AmazonClientException (com.amazonaws.AmazonClientException)1 AutoScalingInstanceDetails (com.amazonaws.services.autoscaling.model.AutoScalingInstanceDetails)1