当前位置: 首页>>代码示例>>Java>>正文


Java Instance.getTags方法代码示例

本文整理汇总了Java中com.amazonaws.services.ec2.model.Instance.getTags方法的典型用法代码示例。如果您正苦于以下问题:Java Instance.getTags方法的具体用法?Java Instance.getTags怎么用?Java Instance.getTags使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.amazonaws.services.ec2.model.Instance的用法示例。


在下文中一共展示了Instance.getTags方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: convertInstanceToServer

import com.amazonaws.services.ec2.model.Instance; //导入方法依赖的package包/类
private List<Server> convertInstanceToServer(List<Instance> instances) {
    List<Server> servers = new ArrayList<>();
    for (Instance instance : instances) {
        Server server = new Server(instance.getInstanceId());
        for (Tag tag : instance.getTags()) {
            if (tag != null && tag.getKey() != null
                    && tag.getKey().equals("Name")) {
                server.setName(tag.getValue());
            }
        }
        server.setStatus(instance.getState().getName());
        server.setType(instance.getInstanceType());
        server.setPublicIP(Arrays.asList(instance.getPublicIpAddress()));
        server.setPrivateIP(Arrays.asList(instance.getPrivateIpAddress()));
        servers.add(server);
    }
    return servers;
}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:19,代码来源:EC2Processor.java

示例2: getUpdateTags

import com.amazonaws.services.ec2.model.Instance; //导入方法依赖的package包/类
/**
 * 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;

}
 
开发者ID:pinterest,项目名称:soundwave,代码行数:34,代码来源:UploadTagsGenerator.java

示例3: findInstanceByName

import com.amazonaws.services.ec2.model.Instance; //导入方法依赖的package包/类
/**
 * Search Ec2 Instance by Name tag.
 * 
 * @param ec2
 * @param targetName
 *            Search Keyword for Name tag
 * @return Instance with Name tag equals targetName. If it does't found,
 *         then return null.
 */
public static Instance findInstanceByName(AmazonEC2 ec2, String targetName) {
	DescribeInstancesResult instanceResult = ec2.describeInstances();
	List<Reservation> reservations = instanceResult.getReservations();
	for (Reservation reservation : reservations) {
		List<Instance> instances = reservation.getInstances();
		for (Instance instance : instances) {
			List<Tag> tagList = instance.getTags();
			String name = "";
			for (Tag tag : tagList) {
				String tagKey = tag.getKey();
				String tagValue = tag.getValue();
				if (tagKey.contains("Name")) {
					name = tagValue;
					if (targetName.equals(name)) {
						return instance;
					}
					break;
				}
			}
		}
	}
	return null;
}
 
开发者ID:betahikaru,项目名称:ec2-util,代码行数:33,代码来源:AwsEc2Client.java

示例4: updateTagLinks

import com.amazonaws.services.ec2.model.Instance; //导入方法依赖的package包/类
/**
 * Updates tag links of existing computes using TagsUtil.
 */
private DeferredResult<AWSComputeStateCreationContext> updateTagLinks(
        AWSComputeStateCreationContext context) {
    if (context.request.instancesToBeUpdated == null
            || context.request.instancesToBeUpdated.size() == 0) {
        logFine(() -> "No local compute states to be updated so there are no tags to update.");
        return DeferredResult.completed(context);
    } else {

        List<DeferredResult<Set<String>>> updateCSTagLinksOps = new ArrayList<>();

        for (String instanceId : context.request.instancesToBeUpdated.keySet()) {
            Instance instance = context.request.instancesToBeUpdated.get(instanceId);
            ComputeState existingComputeState = context.request.computeStatesToBeUpdated
                    .get(instanceId);
            Map<String, String> remoteTags = new HashMap<>();
            for (Tag awsInstanceTag : instance.getTags()) {
                if (!awsInstanceTag.getKey().equals(AWSConstants.AWS_TAG_NAME)) {
                    remoteTags.put(awsInstanceTag.getKey(), awsInstanceTag.getValue());
                }
            }
            updateCSTagLinksOps
                    .add(updateLocalTagStates(this, existingComputeState, remoteTags, null));
        }
        return DeferredResult.allOf(updateCSTagLinksOps).thenApply(gnore -> context);
    }
}
 
开发者ID:vmware,项目名称:photon-model,代码行数:30,代码来源:AWSComputeStateCreationAdapterService.java

示例5: shouldDelete

import com.amazonaws.services.ec2.model.Instance; //导入方法依赖的package包/类
private static boolean shouldDelete(Instance instance) {
    for (Tag tag : instance.getTags()) {
        if (tag.getKey().equalsIgnoreCase("name")
                && tag.getValue().equalsIgnoreCase("DoNotDelete")) {
            return false;
        }
    }
    return true;
}
 
开发者ID:vmware,项目名称:photon-model,代码行数:10,代码来源:AWSRemoteCleanup.java

示例6: assertTags

import com.amazonaws.services.ec2.model.Instance; //导入方法依赖的package包/类
private void assertTags(Set<TagState> expectedTagStates, Instance instance,
        String instanceName) {
    Set<Tag> expectedTags = expectedTagStates.stream().map(ts -> new Tag(ts.key, ts.value))
            .collect(Collectors.toSet());

    Set<Tag> actualTags = new HashSet<>(instance.getTags());
    // account for the name tag
    assertEquals(expectedTags.size() + 1, actualTags.size());
    assertTrue(actualTags.containsAll(expectedTags));

    Tag nameTag = new Tag(AWSConstants.AWS_TAG_NAME, instanceName);
    assertTrue(actualTags.contains(nameTag));
}
 
开发者ID:vmware,项目名称:photon-model,代码行数:14,代码来源:TestAWSProvisionTask.java

示例7: getTagValue

import com.amazonaws.services.ec2.model.Instance; //导入方法依赖的package包/类
public static String getTagValue( Instance instance, String tagKey ) {
	String tagValue = "";
	for ( Tag tag : instance.getTags() ) {
		if ( tag.getKey().equals( tagKey ) ) {
			tagValue = tag.getValue();
			break;
		}
	}
	return tagValue;
}
 
开发者ID:CodeArcsInc,项目名称:candlestack,代码行数:11,代码来源:EC2Util.java

示例8: isEc2ProvisionedSlave

import com.amazonaws.services.ec2.model.Instance; //导入方法依赖的package包/类
protected boolean isEc2ProvisionedSlave(Instance i, String ami) {
    // Check if the ami matches
    if (ami == null || StringUtils.equals(ami, i.getImageId())) {
        // Check if there is a ec2slave tag...
        for (Tag tag : i.getTags()) {
            if (StringUtils.equals(tag.getKey(), EC2Tag.TAG_NAME_JENKINS_SLAVE_TYPE)) {
                return true;
            }
        }
        return false;
    }
    return false;
}
 
开发者ID:hudson3-plugins,项目名称:ec2-plugin,代码行数:14,代码来源:EC2Cloud.java

示例9: getAwsTag

import com.amazonaws.services.ec2.model.Instance; //导入方法依赖的package包/类
public static Tag getAwsTag(Instance awsInstance, String tagName) {
  List<Tag> tags = awsInstance.getTags();
  java.util.Optional<Tag> tag =
      tags.stream().filter(t -> StringUtils.equals(t.getKey(), tagName)).findFirst();
  return tag.isPresent() ? tag.get() : null;
}
 
开发者ID:pinterest,项目名称:soundwave,代码行数:7,代码来源:AwsUtilities.java


注:本文中的com.amazonaws.services.ec2.model.Instance.getTags方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。