com.amazonaws.services.ec2.model.Tag Java Examples

The following examples show how to use com.amazonaws.services.ec2.model.Tag. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: EC2Connector.java    From jenkins-deployment-dashboard-plugin with MIT License 6 votes vote down vote up
public List<ServerEnvironment> getEnvironmentsByTag(Region region, String searchTag) {
    LOGGER.info("getEnvironmentsByTag " + region + " tag: " + searchTag);
    List<ServerEnvironment> environments = new ArrayList<ServerEnvironment>();

    ec2.setRegion(region);
    DescribeInstancesResult instances = ec2.describeInstances();
    for (Reservation reservation : instances.getReservations()) {
        for (Instance instance : reservation.getInstances()) {
            for (Tag tag : instance.getTags()) {
                if (tag.getValue().equalsIgnoreCase(searchTag)) {
                    environments.add(getEnvironmentFromInstance(instance));
                }
            }
        }
    }
    return environments;
}
 
Example #2
Source File: UploadTagsGenerator.java    From soundwave with Apache License 2.0 6 votes vote down vote up
/**
 * Return a list of tags that need to be updated to the Ec2Instance.
 * The tags are either not in Ec2Instance tags or having different
 * values
 * @param ec2Instance
 * @param esInstance
 * @return A list of tags
 */
public List<Tag> getUpdateTags(Instance ec2Instance, EsInstance esInstance) {
  Preconditions.checkNotNull(ec2Instance);
  Preconditions.checkNotNull(esInstance);
  List<Tag> updateTags = new ArrayList<>();

  List<Tag> currentEc2Tag = ec2Instance.getTags();
  List<Tag> esUploadTags = getUpdateTags(esInstance);

  for (Tag tag : esUploadTags) {
    boolean shouldUpdate = true;
    for (Tag ec2Tag : currentEc2Tag) {
      if (ec2Tag.getKey().equals(tag.getKey()) && ec2Tag.getValue().equals(tag.getValue())) {
        shouldUpdate = false;
        break;
      }
    }

    if (shouldUpdate) {
      updateTags.add(tag);
    }
  }

  return updateTags;

}
 
Example #3
Source File: Ec2NetworkTest.java    From aws-mock with MIT License 6 votes vote down vote up
/**
 * Test delete Tags.
 */
@Test(timeout = TIMEOUT_LEVEL1)
public final void describerTagsTest() {
    log.info("Describe Tags test");
    createTagsTest();
    
    List<TagDescription> tagsDesc = getTags();
    Assert.assertNotNull("tag Desc should not be null", tagsDesc);
    
    Collection<String> resources = new ArrayList<String>();
    Collection<Tag> tags = new ArrayList<Tag>();
    
    for(TagDescription tagDesc : tagsDesc)
    {
        Tag tag = new Tag();
        tag.setKey(tagDesc.getKey());
        tag.setValue(tagDesc.getValue());
        tags.add(tag);
        
        resources.add(tagDesc.getResourceId());
    }
    
    Assert.assertTrue("Tags should be created.", deleteTags(resources, tags));
}
 
Example #4
Source File: Ec2LookupServiceTest.java    From Gatekeeper with Apache License 2.0 6 votes vote down vote up
private Reservation fakeInstance(String instanceID, String instanceIP, String instanceName, String instanceApplication, String platform) {
    Reservation container = new Reservation();
    List<Instance> instances = new ArrayList<>();
    Instance i = new Instance();
    List<Tag> tags = new ArrayList<>();
    i.setInstanceId(instanceID);
    i.setPrivateIpAddress(instanceIP);
    Tag nameTag = new Tag();
    nameTag.setKey("Name");
    nameTag.setValue(instanceName);
    Tag applicationTag = new Tag();
    applicationTag.setKey("Application");
    applicationTag.setValue(instanceApplication);
    tags.add(applicationTag);
    tags.add(nameTag);
    i.setTags(tags);
    i.setPlatform(platform);
    instances.add(i);
    container.setInstances(instances);

    return container;
}
 
Example #5
Source File: ResourceTaggingManager.java    From pacbot with Apache License 2.0 6 votes vote down vote up
/**
 * get the value of pacman tag from app elb
 * @param resourceId
 * @param clientMap
 * @return
 */
private String getAppElbPacManTagValue(String resourceId, Map<String, Object> clientMap) {

    try{
        AmazonElasticLoadBalancingClient client = (AmazonElasticLoadBalancingClient) clientMap.get(PacmanSdkConstants.CLIENT);
        com.amazonaws.services.elasticloadbalancingv2.model.DescribeTagsRequest describeTagsRequest =   new com.amazonaws.services.elasticloadbalancingv2.model.DescribeTagsRequest();
        describeTagsRequest.withResourceArns(resourceId);
        com.amazonaws.services.elasticloadbalancingv2.model.DescribeTagsResult describeTagsResult = client.describeTags(describeTagsRequest);
        List<com.amazonaws.services.elasticloadbalancingv2.model.TagDescription> descriptions = describeTagsResult.getTagDescriptions();
        com.amazonaws.services.elasticloadbalancingv2.model.Tag tag=null;
        Optional<com.amazonaws.services.elasticloadbalancingv2.model.Tag> optional=null;;
        if(descriptions!=null && descriptions.size()>0){
             optional = descriptions.get(0).getTags().stream()
            .filter(obj -> obj.getKey().equals(CommonUtils.getPropValue(PacmanSdkConstants.PACMAN_AUTO_FIX_TAG_NAME))).findAny();
        }
        if (optional.isPresent()) {
            tag = optional.get();
        } else {
            return null;
        }
        return tag.getValue();
    }catch (Exception e) {
        logger.error("error whiel getting pacman tag valye for " + resourceId,e);
        return null;
    }
}
 
Example #6
Source File: Ec2NetworkTest.java    From aws-mock with MIT License 6 votes vote down vote up
/**
 * Test create Tags.
 */
@Test(timeout = TIMEOUT_LEVEL1)
public final void createTagsTest() {
    log.info("Start create Tags test");
    Collection<String> resources = new ArrayList<String>();
    resources.add("resource1");
    resources.add("resource2");
    
    Collection<Tag> tags = new ArrayList<Tag>();
    Tag tag1 = new Tag();
    tag1.setKey("tag1");
    tag1.setValue("value1");
    tags.add(tag1);
    
    Tag tag2 = new Tag();
    tag2.setKey("tag2");
    tag2.setValue("value2");
    tags.add(tag2);
    
    Assert.assertTrue("Tags should be created.",createTags(resources, tags));
   
}
 
Example #7
Source File: ResourceTaggingManager.java    From pacbot with Apache License 2.0 6 votes vote down vote up
/**
*
* @param resourceId
* @param clientMap
* @param pacTag
* @return
*/
   private Boolean setElasticSearchTag(final String resourceId, final Map<String, Object> clientMap,
           Map<String, String> pacTag) {
       AWSElasticsearch elasticsearch = (AWSElasticsearch) clientMap.get("client");

      com.amazonaws.services.elasticsearch.model.Tag tag = new com.amazonaws.services.elasticsearch.model.Tag();
       for(Map.Entry<String, String> tags : pacTag.entrySet()){
       tag.setKey(tags.getKey());
       tag.setValue(tags.getValue());
       }

       AddTagsRequest request = new AddTagsRequest().withARN(resourceId);
       request.setTagList(Arrays.asList(tag));
       try {
           AddTagsResult response = elasticsearch.addTags(request);
           return Boolean.TRUE;
       } catch (AmazonServiceException ase) {
           logger.error("error tagging Elastic Search - > " + resourceId, ase);
           throw ase;
       }
   }
 
Example #8
Source File: AWSProvider.java    From testgrid with Apache License 2.0 6 votes vote down vote up
@Override
public Optional<String> getInstanceName(String region, String instanceId) {
    final AmazonEC2 amazonEC2 = AmazonEC2ClientBuilder.standard()
            .withCredentials(new PropertiesFileCredentialsProvider(configFilePath.toString()))
            .withRegion(region)
            .build();

    List<String> instanceIds = new ArrayList<>();
    instanceIds.add(instanceId);

    DescribeInstancesRequest request = new DescribeInstancesRequest();
    request.setInstanceIds(instanceIds);

    DescribeInstancesResult result = amazonEC2.describeInstances(request);
    Optional<String> tagOptional = result.getReservations()
            .stream()
            .flatMap(reservation -> reservation.getInstances().stream())
            .flatMap(instance -> instance.getTags().stream())
            .filter(tag -> NAME_ENTRY.equals(tag.getKey()))
            .findFirst()
            .map(Tag::getValue);
    return tagOptional;
}
 
Example #9
Source File: AwsTaggingService.java    From cloudbreak with Apache License 2.0 5 votes vote down vote up
public void tagRootVolumes(AuthenticatedContext ac, AmazonEC2Client ec2Client, List<CloudResource> instanceResources, Map<String, String> userDefinedTags) {
    String stackName = ac.getCloudContext().getName();
    LOGGER.debug("Fetch AWS instances to collect all root volume ids for stack: {}", stackName);
    List<String> instanceIds = instanceResources.stream().map(CloudResource::getInstanceId).collect(Collectors.toList());
    DescribeInstancesResult describeInstancesResult = ec2Client.describeInstances(new DescribeInstancesRequest().withInstanceIds(instanceIds));

    List<Instance> instances = describeInstancesResult.getReservations().stream().flatMap(res -> res.getInstances().stream()).collect(Collectors.toList());
    List<String> rootVolumeIds = instances.stream()
            .map(this::getRootVolumeId)
            .filter(Optional::isPresent)
            .map(blockDeviceMapping -> blockDeviceMapping.get().getEbs().getVolumeId())
            .collect(Collectors.toList());

    int instanceCount = instances.size();
    int volumeCount = rootVolumeIds.size();
    if (instanceCount != volumeCount) {
        LOGGER.debug("Did not find all root volumes, instanceResources: {}, found root volumes: {} for stack: {}", instanceCount, volumeCount, stackName);
    } else {
        LOGGER.debug("Found all ({}) root volumes for stack: {}", volumeCount, stackName);
    }

    AtomicInteger counter = new AtomicInteger();
    Collection<List<String>> volumeIdChunks = rootVolumeIds.stream()
            .collect(Collectors.groupingBy(it -> counter.getAndIncrement() / MAX_RESOURCE_PER_REQUEST)).values();

    Collection<Tag> tags = prepareEc2Tags(ac, userDefinedTags);
    for (List<String> volumeIds : volumeIdChunks) {
        LOGGER.debug("Tag {} root volumes for stack: {}", volumeIds.size(), stackName);
        ec2Client.createTags(new CreateTagsRequest().withResources(volumeIds).withTags(tags));
    }
}
 
Example #10
Source File: AwsTaggingService.java    From cloudbreak with Apache License 2.0 5 votes vote down vote up
public Collection<com.amazonaws.services.cloudformation.model.Tag> prepareCloudformationTags(AuthenticatedContext ac, Map<String, String> userDefinedTags) {
    Collection<com.amazonaws.services.cloudformation.model.Tag> tags = new ArrayList<>();
    tags.addAll(userDefinedTags.entrySet().stream()
            .map(entry -> prepareCloudformationTag(entry.getKey(), entry.getValue()))
            .collect(Collectors.toList()));
    return tags;
}
 
Example #11
Source File: DhcpOptionsImpl.java    From aws-sdk-java-resources with Apache License 2.0 5 votes vote down vote up
@Override
public List<com.amazonaws.resources.ec2.Tag> createTags(CreateTagsRequest
        request, ResultCapture<Void> extractor) {

    ActionResult result = resource.performAction("CreateTags", request,
            extractor);

    if (result == null) return null;
    return CodecUtils.transform(result.getResources(), TagImpl.CODEC);
}
 
Example #12
Source File: ResourceTaggingManager.java    From pacbot with Apache License 2.0 5 votes vote down vote up
/**
*
* @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 {
           ec2Client.createTags(createTagsRequest);
           return Boolean.TRUE;
       } catch (AmazonServiceException ase) {
           logger.error("error tagging ec2 - > " + resourceId, ase);
           throw ase;
       }
   }
 
Example #13
Source File: RouteTableImpl.java    From aws-sdk-java-resources with Apache License 2.0 5 votes vote down vote up
@Override
public List<com.amazonaws.resources.ec2.Tag> createTags(CreateTagsRequest
        request, ResultCapture<Void> extractor) {

    ActionResult result = resource.performAction("CreateTags", request,
            extractor);

    if (result == null) return null;
    return CodecUtils.transform(result.getResources(), TagImpl.CODEC);
}
 
Example #14
Source File: EC2Connector.java    From jenkins-deployment-dashboard-plugin with MIT License 5 votes vote down vote up
private ServerEnvironment getEnvironmentFromInstance(Instance instance) {
    ServerEnvironment env = new ServerEnvironment(instance.getInstanceId(), instance.getInstanceType());

    List<EnvironmentTag> tags = new ArrayList<EnvironmentTag>();
    for (Tag tag : instance.getTags()) {
        EnvironmentTag envTag = new EnvironmentTag(tag.getKey(), tag.getValue());
        tags.add(envTag);
        if (tag.getKey().equalsIgnoreCase(DEFAULT_INSTANCE_NAME_TAG)) {
            env.setEnvironmentTag(tag.getValue());
            if (tag.getValue().contains(PROD_VALUE)) {
                env.setType(ENVIRONMENT_TYPES.PRODUCTION);
            } else if (tag.getValue().contains(STAGING_VALUE)) {
                env.setType(ENVIRONMENT_TYPES.STAGING);
            } else if (tag.getValue().contains(JENKINS_VALUE)) {
                env.setType(ENVIRONMENT_TYPES.JENKINS);
            }
        }
        if (tag.getKey().equalsIgnoreCase(VERSION_TAG)) {
            env.setVersion(tag.getValue());
        }
    }
    env.setState(instance.getState());
    env.setLaunchTime(instance.getLaunchTime());
    env.setPublicIpAddress(instance.getPublicIpAddress());
    env.setTags(tags);
    return env;
}
 
Example #15
Source File: RouteTableImpl.java    From aws-sdk-java-resources with Apache License 2.0 5 votes vote down vote up
@Override
public List<com.amazonaws.resources.ec2.Tag> createTags(List<Tag> tags,
        ResultCapture<Void> extractor) {

    CreateTagsRequest request = new CreateTagsRequest()
        .withTags(tags);
    return createTags(request, extractor);
}
 
Example #16
Source File: NetworkInterfaceImpl.java    From aws-sdk-java-resources with Apache License 2.0 5 votes vote down vote up
@Override
public List<com.amazonaws.resources.ec2.Tag> createTags(List<Tag> tags,
        ResultCapture<Void> extractor) {

    CreateTagsRequest request = new CreateTagsRequest()
        .withTags(tags);
    return createTags(request, extractor);
}
 
Example #17
Source File: InternetGatewayImpl.java    From aws-sdk-java-resources with Apache License 2.0 5 votes vote down vote up
@Override
public List<com.amazonaws.resources.ec2.Tag> createTags(CreateTagsRequest
        request, ResultCapture<Void> extractor) {

    ActionResult result = resource.performAction("CreateTags", request,
            extractor);

    if (result == null) return null;
    return CodecUtils.transform(result.getResources(), TagImpl.CODEC);
}
 
Example #18
Source File: AWSProviderTest.java    From testgrid with Apache License 2.0 5 votes vote down vote up
private List<Reservation> getMockReservations () {
    List<Tag> tags = new ArrayList<>();
    Tag dummyTag1 = new Tag().withKey("aws:cloudformation:stack-name").withValue(mockStackName);
    Tag dummyTag2 = new Tag().withKey("Name").withValue("DummyInstance");
    tags.add(dummyTag1);
    tags.add(dummyTag2);

    Instance dummyInstance = new Instance().withInstanceId("i-04e164e155f4a95a3").withTags(tags);
    Reservation reservation = new Reservation().withInstances(Collections.singletonList(dummyInstance));
    return Collections.singletonList(reservation);
}
 
Example #19
Source File: InstanceLookupTable.java    From graylog-plugin-aws with Apache License 2.0 5 votes vote down vote up
private String getNameOfInstance(Instance x) {
    for (Tag tag : x.getTags()) {
        if("Name".equals(tag.getKey())) {
            return tag.getValue();
        }
    }

    return null;
}
 
Example #20
Source File: Ec2MachineConfigurator.java    From roboconf-platform with Apache License 2.0 5 votes vote down vote up
/**
 * Tags the specified resource, eg. a VM or volume (basically, it gives it a name).
 * @param resourceId The ID of the resource to tag
 * @param tagName The resource's name
 * @return true if the tag was done, false otherwise
 */
private boolean tagResource(String resourceId, String tagName) {
	boolean result = false;
	if(! Utils.isEmptyOrWhitespaces(tagName)) {
		Tag tag = new Tag( "Name", tagName );
		CreateTagsRequest ctr = new CreateTagsRequest(Collections.singletonList(resourceId), Arrays.asList( tag ));
		try {
			this.ec2Api.createTags( ctr );
		} catch(Exception e) {
			this.logger.warning("Error tagging resource " + resourceId + " with name=" + tagName + ": " + e);
		}
		result = true;
	}
	return result;
}
 
Example #21
Source File: AwsVolumeProcess.java    From primecloud-controller with GNU General Public License v2.0 5 votes vote down vote up
public void createTag(AwsProcessClient awsProcessClient, Long volumeNo) {
    // Eucalyptusの場合はタグを付けない
    PlatformAws platformAws = awsProcessClient.getPlatformAws();
    if (BooleanUtils.isTrue(platformAws.getEuca())) {
        return;
    }

    AwsVolume awsVolume = awsVolumeDao.read(volumeNo);
    Component component = componentDao.read(awsVolume.getComponentNo());
    Instance instance = instanceDao.read(awsVolume.getInstanceNo());
    User user = userDao.read(awsProcessClient.getUserNo());
    Farm farm = farmDao.read(instance.getFarmNo());

    // タグを追加する
    List<Tag> tags = new ArrayList<Tag>();
    if (component != null) {
        tags.add(new Tag("Name", instance.getFqdn() + "_" + component.getComponentName()));
    } else {
        String deviceName = awsVolume.getDevice().substring(awsVolume.getDevice().lastIndexOf("/") + 1);
        tags.add(new Tag("Name", instance.getFqdn() + "_" + deviceName));
    }
    tags.add(new Tag("UserName", user.getUsername()));
    tags.add(new Tag("CloudName", farm.getDomainName()));
    tags.add(new Tag("ServerName", instance.getFqdn()));
    if (component != null) {
        tags.add(new Tag("ServiceName", component.getComponentName()));
    }
    awsCommonProcess.createTag(awsProcessClient, awsVolume.getVolumeId(), tags);
}
 
Example #22
Source File: ReconcileWithAwsJob.java    From soundwave with Apache License 2.0 5 votes vote down vote up
public void computeUploadTags(List<Instance> ec2Instances, Map<String, EsInstance>
    currentRunningInstances, ReconcileUpdateSet updateSet) {
  UploadTagsGenerator tagsGenerator = AwsServiceTagUpdater.getInstance().getTagsGenerator();
  for (Instance inst : ec2Instances) {
    EsInstance esInstance = currentRunningInstances.get(inst.getInstanceId());
    if (esInstance != null) {
      List<Tag> updateTags = tagsGenerator.getUpdateTags(inst, esInstance);
      if (updateTags.size() > 0) {
        updateSet.getUploadEc2Tags().add(new ImmutablePair<>(esInstance.getId(), updateTags));
      }
    }
  }
}
 
Example #23
Source File: EC2ConnectorTest.java    From jenkins-deployment-dashboard-plugin with MIT License 5 votes vote down vote up
@Test
public void testGetEnvironmentFromInstanceVersion() throws Exception {
    final Instance instance = new Instance().withInstanceId("instance").withInstanceType(InstanceType.C1Xlarge).withTags(new Tag(EC2Connector.VERSION_TAG, "1.2.3"));
    ServerEnvironment serverEnv = Whitebox.<ServerEnvironment> invokeMethod(env, "getEnvironmentFromInstance", instance);
    assertThat(serverEnv, notNullValue());
    assertThat(serverEnv.getVersion(), is("1.2.3"));
}
 
Example #24
Source File: EC2ConnectorTest.java    From jenkins-deployment-dashboard-plugin with MIT License 5 votes vote down vote up
@Test
public void testGetEnvironmentFromInstanceTest() throws Exception {
    final Instance instance = new Instance().withInstanceId("instance").withInstanceType(InstanceType.C1Xlarge).withTags(new Tag(EC2Connector.DEFAULT_INSTANCE_NAME_TAG, EC2Connector.TEST_VALUE));
    ServerEnvironment serverEnv = Whitebox.<ServerEnvironment> invokeMethod(env, "getEnvironmentFromInstance", instance);
    assertThat(serverEnv, notNullValue());
    assertThat(serverEnv.getType(), is(ENVIRONMENT_TYPES.TEST));
}
 
Example #25
Source File: RouteTableProviderTest.java    From aws-athena-query-federation with Apache License 2.0 5 votes vote down vote up
private RouteTable makeRouteTable(String id)
{
    RouteTable routeTable = new RouteTable();
    routeTable.withRouteTableId(id)
            .withOwnerId("owner")
            .withVpcId("vpc")
            .withAssociations(new RouteTableAssociation().withSubnetId("subnet").withRouteTableId("route_table_id"))
            .withTags(new Tag("key", "value"))
            .withPropagatingVgws(new PropagatingVgw().withGatewayId("gateway_id"))
            .withRoutes(new Route()
                    .withDestinationCidrBlock("dst_cidr")
                    .withDestinationIpv6CidrBlock("dst_cidr_v6")
                    .withDestinationPrefixListId("dst_prefix_list")
                    .withEgressOnlyInternetGatewayId("egress_igw")
                    .withGatewayId("gateway")
                    .withInstanceId("instance_id")
                    .withInstanceOwnerId("instance_owner")
                    .withNatGatewayId("nat_gateway")
                    .withNetworkInterfaceId("interface")
                    .withOrigin("origin")
                    .withState("state")
                    .withTransitGatewayId("transit_gateway")
                    .withVpcPeeringConnectionId("vpc_peering_con")
            );

    return routeTable;
}
 
Example #26
Source File: EC2ConnectorTest.java    From jenkins-deployment-dashboard-plugin with MIT License 5 votes vote down vote up
@Test
public void testGetEnvironmentFromInstanceJenkins() throws Exception {
    final Instance instance = new Instance().withInstanceId("instance").withInstanceType(InstanceType.C1Xlarge)
            .withTags(new Tag(EC2Connector.DEFAULT_INSTANCE_NAME_TAG, EC2Connector.JENKINS_VALUE));
    ServerEnvironment serverEnv = Whitebox.<ServerEnvironment> invokeMethod(env, "getEnvironmentFromInstance", instance);
    assertThat(serverEnv, notNullValue());
    assertThat(serverEnv.getType(), is(ENVIRONMENT_TYPES.JENKINS));
}
 
Example #27
Source File: NetworkAclImpl.java    From aws-sdk-java-resources with Apache License 2.0 5 votes vote down vote up
@Override
public List<com.amazonaws.resources.ec2.Tag> createTags(CreateTagsRequest
        request, ResultCapture<Void> extractor) {

    ActionResult result = resource.performAction("CreateTags", request,
            extractor);

    if (result == null) return null;
    return CodecUtils.transform(result.getResources(), TagImpl.CODEC);
}
 
Example #28
Source File: EC2Instance.java    From billow with Apache License 2.0 4 votes vote down vote up
public EC2Instance(Instance instance) {
    this.id = instance.getInstanceId();
    this.type = instance.getInstanceType();
    this.lifecycle = instance.getInstanceLifecycle();
    this.hypervisor = instance.getHypervisor();
    this.az = instance.getPlacement().getAvailabilityZone();
    this.group = instance.getPlacement().getGroupName();
    this.tenancy = instance.getPlacement().getTenancy();
    this.vpc = instance.getVpcId();
    this.platform = instance.getPlatform();
    this.kernel = instance.getKernelId();
    this.key = instance.getKeyName();
    this.image = instance.getImageId();
    this.privateIP = instance.getPrivateIpAddress();
    this.publicIP = instance.getPublicIpAddress();
    this.publicHostname = instance.getPublicDnsName();
    this.privateHostname = instance.getPrivateDnsName();
    this.architecture = instance.getArchitecture();
    this.state = instance.getState().getName();
    this.ramdisk = instance.getRamdiskId();
    this.subnet = instance.getSubnetId();
    this.rootDeviceName = instance.getRootDeviceName();
    this.rootDeviceType = instance.getRootDeviceType();
    this.stateTransitionReason = instance.getStateTransitionReason();
    this.spotInstanceRequest = instance.getSpotInstanceRequestId();
    this.virtualizationType = instance.getVirtualizationType();
    this.sourceDestCheck = instance.getSourceDestCheck();
    this.launchTime = new DateTime(instance.getLaunchTime());

    if (instance.getIamInstanceProfile() != null) {
        this.iamInstanceProfile = instance.getIamInstanceProfile().getArn().toString();
    } else {
        this.iamInstanceProfile = null;
    }

    final StateReason stateReason = instance.getStateReason();
    if (stateReason != null)
        this.stateReason = stateReason.getMessage();
    else
        this.stateReason = null;

    this.securityGroups = new ArrayList<>();
    for (GroupIdentifier identifier : instance.getSecurityGroups()) {
        this.securityGroups.add(new SecurityGroup(identifier));
    }

    this.tags = new HashMap<>();
    for (Tag tag : instance.getTags()) {
        this.tags.put(tag.getKey(), tag.getValue());
    }
}
 
Example #29
Source File: AwsTaggingService.java    From cloudbreak with Apache License 2.0 4 votes vote down vote up
private com.amazonaws.services.cloudformation.model.Tag prepareCloudformationTag(String key, String value) {
    return new com.amazonaws.services.cloudformation.model.Tag().withKey(key).withValue(value);
}
 
Example #30
Source File: VpcImpl.java    From aws-sdk-java-resources with Apache License 2.0 4 votes vote down vote up
@Override
public List<Tag> getTags() {
    return (List<Tag>) resource.getAttribute("Tags");
}