當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。