if( !tagsDone ) { CreateTagsRequest createTagsRequest = new CreateTagsRequest(); createTagsRequest.withResources(ids).withTags(new Tag("Name", NAME)); ec2.createTags(createTagsRequest); tagsDone = true;
Tag tag = new Tag() .withKey("Name") .withValue(name);
public Tag unmarshall(StaxUnmarshallerContext context) throws Exception { Tag tag = new Tag(); int originalDepth = context.getCurrentDepth(); int targetDepth = originalDepth + 1; if (context.isStartOfDocument()) targetDepth += 1; while (true) { XMLEvent xmlEvent = context.nextEvent(); if (xmlEvent.isEndDocument()) return tag; if (xmlEvent.isAttribute() || xmlEvent.isStartElement()) { if (context.testExpression("key", targetDepth)) { tag.setKey(StringStaxUnmarshaller.getInstance().unmarshall(context)); continue; } if (context.testExpression("value", targetDepth)) { tag.setValue(StringStaxUnmarshaller.getInstance().unmarshall(context)); continue; } } else if (xmlEvent.isEndElement()) { if (context.getCurrentDepth() < originalDepth) { return tag; } } } }
Tag t = new Tag(); t.setKey( "Name" ); t.setValue( runnerNames );
Tag t = new Tag(); t.setKey( "Name" ); t.setValue( instanceNames );
public Tag unmarshall(StaxUnmarshallerContext context) throws Exception { Tag tag = new Tag(); int originalDepth = context.getCurrentDepth(); int targetDepth = originalDepth + 1; if (context.isStartOfDocument()) targetDepth += 1; while (true) { int xmlEvent = context.nextEvent(); if (xmlEvent == XmlPullParser.END_DOCUMENT) return tag; if (xmlEvent == XmlPullParser.START_TAG) { if (context.testExpression("key", targetDepth)) { tag.setKey(StringStaxUnmarshaller.getInstance().unmarshall(context)); continue; } if (context.testExpression("value", targetDepth)) { tag.setValue(StringStaxUnmarshaller.getInstance().unmarshall(context)); continue; } } else if (xmlEvent == XmlPullParser.END_TAG) { if (context.getCurrentDepth() < originalDepth) { return tag; } } } }
private List<Tag> tags() { List<Tag> tags = new ArrayList<>(); for (Entry<String, String> tag : this.instanceTemplate.getTags().entrySet()) { tags.add(new Tag(tag.getKey(), tag.getValue())); } return tags; }
private Collection<Tag> tags() { List<Tag> tags = new ArrayList<>(); for (Entry<String, String> tag : this.instanceTemplate.getTags().entrySet()) { tags.add(new Tag(tag.getKey(), tag.getValue())); } return tags; }
protected void setInstanceName() { ec2.createTags(new CreateTagsRequest(newArrayList(instanceId), newArrayList(new Tag("Name", hostLabel + " started at " + new Date())))); }
protected void setInstanceName() { ec2.createTags(new CreateTagsRequest(asList(instanceId), asList(new Tag("Name", hostLabel + " started at " + new Date())))); }
protected static List<Tag> getTags(EnvironmentService env) { List<String> list = SpringUtils.getNoneSensitiveListFromCSV(env, TAGS_KEY, NullUtils.NONE); List<Tag> tags = new ArrayList<Tag>(); for (String element : list) { String[] tokens = Str.splitAndTrim(element, "="); Assert.isTrue(tokens.length == 2, "Expected exactly 2 tokens"); String key = tokens[0]; String value = tokens[1]; Tag tag = new Tag(key, value); tags.add(tag); } return ImmutableList.copyOf(tags); }
/** * * @param resourceId * @param clientMap * @param pacTag * @return */ private Boolean setEC2VolumeTag(final String resourceId, final Map<String, Object> clientMap, Map<String, String> pacTag) { AmazonEC2 ec2Client = (AmazonEC2) clientMap.get("client"); CreateTagsRequest createTagsRequest = new CreateTagsRequest(Arrays.asList(resourceId), new ArrayList<>()); createTagsRequest.setTags(pacTag.entrySet().stream().map(t -> new Tag(t.getKey(), t.getValue())) .collect(Collectors.toList())); try { CreateTagsResult createTagsResult = ec2Client.createTags(createTagsRequest); return Boolean.TRUE; } catch (AmazonServiceException ase) { logger.error("error tagging ec2 - > " + resourceId, ase); throw ase; } }
@Override public void execute() throws MojoExecutionException, MojoFailureException { final AwsGatlingRunner runner = new AwsGatlingRunner(this.ec2EndPoint); runner.setInstanceTag(new Tag(this.ec2TagName, this.ec2TagValue)); final Map<String, Instance> instances = runner.findExistingInstances(this.instanceType); runner.terminateInstances(instances.keySet()); } }
/** * * @param instanceId * @param tag * @param value * @param ec2Client */ public void tagInstance(String instanceId, String tag, String value, AmazonEC2 ec2Client) { //quick fix try { Thread.sleep(1000); } catch (InterruptedException e) { // swallow } CreateTagsRequest request = new CreateTagsRequest(); request = request.withResources(instanceId) .withTags(new Tag(tag, value)); ec2Client.createTags(request); }
@Test public void testEc2Instance() throws IOException { Instance instance = new Instance(); instance.setInstanceId("i-123456"); instance.setTags(Lists.newArrayList(new Tag("foo", "bar"), new Tag("fizz", "buzz"))); JsonNode n = new JsonConverter().toJson(instance); Assertions.assertThat(n.path("aws_instanceId").asText()).isEqualTo("i-123456"); Assertions.assertThat(n.path("aws_tag_foo").asText()).isEqualTo("bar"); Assertions.assertThat(n.path("aws_tag_fizz").asText()).isEqualTo("buzz"); logger.info("{}", mapper.writerWithDefaultPrettyPrinter().writeValueAsString(n)); }
protected void clearLiveInstancedata() throws AmazonClientException { Instance inst = getInstance(getInstanceId(), getCloud()); /* Now that we have our instance, we can clear the tags on it */ if (!tags.isEmpty()) { HashSet<Tag> inst_tags = new HashSet<Tag>(); for(EC2Tag t : tags) { inst_tags.add(new Tag(t.getName(), t.getValue())); } DeleteTagsRequest tag_request = new DeleteTagsRequest(); tag_request.withResources(inst.getInstanceId()).setTags(inst_tags); getCloud().connect().deleteTags(tag_request); } }
protected void pushLiveInstancedata() throws AmazonClientException { Instance inst = getInstance(getInstanceId(), getCloud()); /* Now that we have our instance, we can set tags on it */ if (inst != null && tags != null && !tags.isEmpty()) { HashSet<Tag> inst_tags = new HashSet<Tag>(); for(EC2Tag t : tags) { inst_tags.add(new Tag(t.getName(), t.getValue())); } CreateTagsRequest tag_request = new CreateTagsRequest(); tag_request.withResources(inst.getInstanceId()).setTags(inst_tags); getCloud().connect().createTags(tag_request); } }
protected void pushLiveInstancedata() throws AmazonClientException { Instance inst = null; try { inst = CloudHelper.getInstanceWithRetry(getInstanceId(), getCloud()); } catch (InterruptedException e) { // We'll just retry next time we test for idleness. LOGGER.fine("InterruptedException while get " + getInstanceId() + " Exception: " + e); } /* Now that we have our instance, we can set tags on it */ if (inst != null && tags != null && !tags.isEmpty()) { HashSet<Tag> instTags = new HashSet<Tag>(); for (EC2Tag t : tags) { instTags.add(new Tag(t.getName(), t.getValue())); } List<String> resources = getResourcesToTag(inst); CreateTagsRequest tagRequest = new CreateTagsRequest(); tagRequest.withResources(resources).setTags(instTags); getCloud().connect().createTags(tagRequest); } }
@Test public void testIt() throws JsonProcessingException { String account = "123456"; Regions region = Regions.US_WEST_1; VPCScanner scanner = getProjector().createBuilder(AWSScannerBuilder.class).withAccountId(account).withRegion(region).buildVPCScanner(); Vpc vpc = new Vpc(); vpc.setVpcId("vpc-1234"); vpc.setCidrBlock("192.168.100.0/24"); vpc.setTags(Lists.newArrayList(new Tag("fizz","buzz"))); JsonNode n = scanner.convertAwsObject(vpc, Region.getRegion(region)); prettyPrint(n); Assertions.assertThat(n.path("aws_region").asText()).isEqualTo(region.getName()); Assertions.assertThat(n.path("aws_account").asText()).isEqualTo(account); Assertions.assertThat(n.path("aws_arn").asText()).isEqualTo("arn:aws:ec2:us-west-1:123456:vpc/vpc-1234"); Assertions.assertThat(n.path("aws_tag_fizz").asText()).isEqualTo("buzz"); Assertions.assertThat(n.path("aws_cidrBlock").asText()).isEqualTo("192.168.100.0/24"); } }