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


Java Tag类代码示例

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


Tag类属于com.amazonaws.services.ec2.model包,在下文中一共展示了Tag类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: AmazonEC2Mock

import com.amazonaws.services.ec2.model.Tag; //导入依赖的package包/类
public AmazonEC2Mock(int nodes, List<List<Tag>> tagsList) {
    if (tagsList != null) {
        assert tagsList.size() == nodes;
    }

    for (int node = 1; node < nodes + 1; node++) {
        String instanceId = "node" + node;

        Instance instance = new Instance()
                .withInstanceId(instanceId)
                .withState(new InstanceState().withName(InstanceStateName.Running))
                .withPrivateDnsName(PREFIX_PRIVATE_DNS + instanceId + SUFFIX_PRIVATE_DNS)
                .withPublicDnsName(PREFIX_PUBLIC_DNS + instanceId + SUFFIX_PUBLIC_DNS)
                .withPrivateIpAddress(PREFIX_PRIVATE_IP + node)
                .withPublicIpAddress(PREFIX_PUBLIC_IP + node);

        if (tagsList != null) {
            instance.setTags(tagsList.get(node-1));
        }

        instances.add(instance);
    }

}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:25,代码来源:AmazonEC2Mock.java

示例2: convertInstanceToServer

import com.amazonaws.services.ec2.model.Tag; //导入依赖的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

示例3: setTagsForInstances

import com.amazonaws.services.ec2.model.Tag; //导入依赖的package包/类
/**
 * Update tags for one all more instance
 * @param instanceIds
 * @param tags
 * @throws Exception
 */
@Override
public void setTagsForInstances(List<String> instanceIds, List<Tag> tags) throws Exception {
  Preconditions.checkNotNull(instanceIds);
  Preconditions.checkNotNull(tags);
  awsRateLimiter.acquire();
  OperationStats op = new OperationStats("ec2InstanceStore", "setTagsForInstances");

  try {
    if (tags.size() > 0) {
      CreateTagsRequest req = new CreateTagsRequest(instanceIds, tags);
      defaultClient.createTags(req);
    }
    op.succeed();
  } catch (Exception ex) {
    op.failed();
    throw ex;
  }
}
 
开发者ID:pinterest,项目名称:soundwave,代码行数:25,代码来源:Ec2InstanceStore.java

示例4: getUpdateTags

import com.amazonaws.services.ec2.model.Tag; //导入依赖的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

示例5: processResponse

import com.amazonaws.services.ec2.model.Tag; //导入依赖的package包/类
private List<Instance> processResponse(DescribeInstancesResult response) {
    List<Instance> returnedInstances = new ArrayList<>();

    for (Reservation reservation : response.getReservations()) {
        for (com.amazonaws.services.ec2.model.Instance instance : reservation.getInstances()) {

            // Don't show dead servers or servers not tagged as belonging to Swordfish
            if (instance.getState().getName().equals("terminated") || !instance.getTags().contains(new Tag().withKey("Swordfish").withValue("true"))) {
                continue;
            }

            Instance instanceDetails = getInstanceDetails(instance);
            returnedInstances.add(instanceDetails);
            instanceRepository.save(instanceDetails);
            refreshClient(instanceDetails);
        }
    }

    return returnedInstances;
}
 
开发者ID:peavers,项目名称:swordfish-service,代码行数:21,代码来源:EC2SyncImpl.java

示例6: attachSnapshotTags

import com.amazonaws.services.ec2.model.Tag; //导入依赖的package包/类
void attachSnapshotTags(AmazonEC2Async client, String sourceSnapshotId, String snapshotId) {

		DescribeSnapshotsResult result = client
				.describeSnapshots(new DescribeSnapshotsRequest().withSnapshotIds(sourceSnapshotId));
		List<Snapshot> snapshots = result.getSnapshots();
		if (snapshots.size() != 1) {
			throw new RuntimeException("snapshot can not found. sourceSnapshotId[" + snapshotId + "]");
		}
		List<Tag> sourceSnapshotTags = snapshots.get(0).getTags();

		List<Tag> tags = new ArrayList<Tag>();
		tags.addAll(sourceSnapshotTags);
		tags.add(new Tag("SourceSnapshotId", sourceSnapshotId));
		tags.add(new Tag("BackupType", "copy-snapshot")); // overwrite

		CreateTagsRequest snapshotTagsRequest = new CreateTagsRequest().withResources(snapshotId);
		snapshotTagsRequest.setTags(tags);
		client.createTags(snapshotTagsRequest);
	}
 
开发者ID:uzresk,项目名称:aws-auto-operations-using-lambda,代码行数:20,代码来源:EBSCopySnapshotFunction.java

示例7: createNameTagAsync

import com.amazonaws.services.ec2.model.Tag; //导入依赖的package包/类
public DeferredResult<Void> createNameTagAsync(String resourceId, String name) {
    Tag nameTag = new Tag().withKey(AWS_TAG_NAME).withValue(name);

    CreateTagsRequest request = new CreateTagsRequest()
            .withResources(resourceId)
            .withTags(nameTag);

    String message = "Name tag AWS resource with id [" + resourceId + "] with name ["
            + name + "].";
    AWSDeferredResultAsyncHandler<CreateTagsRequest, CreateTagsResult> handler =
            new AWSDeferredResultAsyncHandler<>(this.service, message);

    this.client.createTagsAsync(request, handler);

    return handler.toDeferredResult()
            .thenApply(result -> (Void) null);
}
 
开发者ID:vmware,项目名称:photon-model,代码行数:18,代码来源:AWSNetworkClient.java

示例8: setResourceTags

import com.amazonaws.services.ec2.model.Tag; //导入依赖的package包/类
private void setResourceTags(ResourceState resourceState, List<Tag> tags) {
    if (tags != null && !tags.isEmpty()) {

        Map<String, String> awsResourceTags = tags.stream().collect(
                Collectors.toMap(tag -> tag.getKey(), tag -> tag.getValue()));

        // The name of the compute state is the value of the AWS_TAG_NAME tag
        String nameTag = awsResourceTags.get(AWSConstants.AWS_TAG_NAME);
        if (nameTag != null) {
            resourceState.name = nameTag;
            awsResourceTags.remove(AWSConstants.AWS_TAG_NAME);
        }
        // add tag links
        setTagLinksToResourceState(resourceState, awsResourceTags, true);
    }
}
 
开发者ID:vmware,项目名称:photon-model,代码行数:17,代码来源:AWSNetworkStateEnumerationAdapterService.java

示例9: tagSpotInstances

import com.amazonaws.services.ec2.model.Tag; //导入依赖的package包/类
/**
 * Tags provisioned Spot instances. Expects that the instances already exists or are in the
 * process of being created.
 *
 * @throws InterruptedException if the operation is interrupted
 */
@VisibleForTesting
@SuppressWarnings("PMD.UselessParentheses")
protected void tagSpotInstances() throws InterruptedException {

  // Pre-compute user-defined tags for efficiency
  List<Tag> userDefinedTags = ec2TagHelper.getUserDefinedTags(template);

  for (SpotAllocationRecord spotAllocationRecord :
      spotAllocationRecordsByVirtualInstanceId.values()) {
    if ((spotAllocationRecord.ec2InstanceId != null) && !spotAllocationRecord.instanceTagged &&
        tagSpotInstance(template, userDefinedTags, spotAllocationRecord.virtualInstanceId,
            spotAllocationRecord.ec2InstanceId)) {
      spotAllocationRecord.instanceTagged = true;
    }
  }
}
 
开发者ID:cloudera,项目名称:director-aws-plugin,代码行数:23,代码来源:EC2Provider.java

示例10: tagSpotInstance

import com.amazonaws.services.ec2.model.Tag; //导入依赖的package包/类
/**
 * Tags an EC2 instance. Expects that the instance already exists or is in the process of
 * being created. This may also tag EBS volumes depending on template configurations.
 *
 * @param template          the instance template
 * @param userDefinedTags   the user-defined tags
 * @param virtualInstanceId the virtual instance id
 * @param ec2InstanceId     the EC2 instance id
 * @return true if the instance was successfully tagged, false otherwise
 * @throws InterruptedException if the operation is interrupted
 */
private boolean tagSpotInstance(EC2InstanceTemplate template, List<Tag> userDefinedTags,
                            String virtualInstanceId, String ec2InstanceId) throws InterruptedException {
  LOG.info(">> Tagging instance {} / {}", ec2InstanceId, virtualInstanceId);

  // We have to individually tag the spot instance and it's associated volumes
  // since AWS doesn't allow specifying tags as part of the launch request for
  // spot instances.

  // Wait for the instance to be started. If it is terminating, skip tagging.
  if (!waitUntilInstanceHasStarted(ec2InstanceId)) {
    return false;
  }

  List<Tag> tags = ec2TagHelper.getInstanceTags(template, virtualInstanceId, userDefinedTags);
  client.createTags(new CreateTagsRequest().withTags(tags).withResources(ec2InstanceId));

  // Tag EBS volumes if they were part of instance launch request
  if (EBSAllocationStrategy.get(template) == EBSAllocationStrategy.AS_INSTANCE_REQUEST) {
    tagSpotEbsVolumes(ec2InstanceId, virtualInstanceId, tags);
  }

  return true;
}
 
开发者ID:cloudera,项目名称:director-aws-plugin,代码行数:35,代码来源:EC2Provider.java

示例11: findInstanceByName

import com.amazonaws.services.ec2.model.Tag; //导入依赖的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

示例12: convert

import com.amazonaws.services.ec2.model.Tag; //导入依赖的package包/类
public static VolumeDto convert(Volume volume) {
    VolumeDto volumeDto = new VolumeDto();
    BeanUtils.copyProperties(volume, volumeDto);
    List<Tag> tags = new ArrayList<>();
    for (Tag tag : volume.getTags()) {
        // check whether volume has Name tag
        if (tag.getKey().equals("Name")) {
            volumeDto.setVolumeName(tag.getValue());
        } else {
            tags.add(tag);
        }
    }
    volumeDto.setTags(tags);
    // check whether volume is attached to instance
    if (volume.getAttachments().size() > 0) {
        volumeDto.setInstanceID(volume.getAttachments().get(0).getInstanceId());
    }
    return volumeDto;
}
 
开发者ID:SungardAS,项目名称:enhanced-snapshots,代码行数:20,代码来源:VolumeDtoConverter.java

示例13: convertVolumeList

import com.amazonaws.services.ec2.model.Tag; //导入依赖的package包/类
@Test
public void convertVolumeList() {
    List<Volume> volumeList = new ArrayList<>();
    //with tags
    volumeList.add(createVolume(VOLUME_ID, SNAPSHOT_ID, CREATE_TIME, AVAILABILITY_ZONE, SIZE, STATE, tags, INSTANCE_ID));

    // without tags
    volumeList.add(createVolume(VOLUME_ID + "_", SNAPSHOT_ID + "_", CREATE_TIME, AVAILABILITY_ZONE + "_",
            SIZE + 1, STATE + "_", new ArrayList<Tag>(), INSTANCE_ID + "_"));

    Set<VolumeDto> volumeDtoList = VolumeDtoConverter.convert(volumeList);
    Assert.assertTrue(volumeDtoList.size() == 2);
    assertVolumeDtoFields((VolumeDto) volumeDtoList.toArray()[0], VOLUME_ID, SNAPSHOT_ID, CREATE_TIME, AVAILABILITY_ZONE, SIZE, STATE, tags, INSTANCE_ID);
    assertVolumeDtoFields((VolumeDto) volumeDtoList.toArray()[1], VOLUME_ID + "_", SNAPSHOT_ID + "_", CREATE_TIME, AVAILABILITY_ZONE + "_",
            SIZE + 1, STATE + "_", new ArrayList<Tag>(), INSTANCE_ID + "_");
}
 
开发者ID:SungardAS,项目名称:enhanced-snapshots,代码行数:17,代码来源:VolumeDtoConverterTest.java

示例14: createVolume

import com.amazonaws.services.ec2.model.Tag; //导入依赖的package包/类
private Volume createVolume(String volId, String snapId, Date createDate, String zone, int size, String state, List<Tag> tags, String instance_id) {
    Volume volume = new Volume();
    volume.setVolumeId(volId);
    volume.setSnapshotId(snapId);
    volume.setCreateTime(createDate);
    volume.setAvailabilityZone(zone);
    volume.setState(state);
    volume.setSize(size);
    volume.setTags(tags);
    if (instance_id != null) {
        List<VolumeAttachment> volumeAttachmentList = new ArrayList();
        VolumeAttachment volumeAttachment = new VolumeAttachment();
        volumeAttachment.setInstanceId(instance_id);
        volumeAttachmentList.add(volumeAttachment);
        volume.setAttachments(volumeAttachmentList);
    }
    return volume;
}
 
开发者ID:SungardAS,项目名称:enhanced-snapshots,代码行数:19,代码来源:VolumeDtoConverterTest.java

示例15: SubnetDTO

import com.amazonaws.services.ec2.model.Tag; //导入依赖的package包/类
public SubnetDTO(final Subnet subnet) {
    this.subnetId = subnet.getSubnetId();
    this.vpcId = subnet.getVpcId();
    this.state = subnet.getState();
    this.availabilityZone = subnet.getAvailabilityZone();
    this.cidrBlock = subnet.getCidrBlock();

    this.tags.addAll(
        subnet.getTags()
            .stream()
            .map(TagDTO::new)
            .collect(Collectors.toList()));

    this.name = subnet.getTags()
        .stream()
        .filter(t -> t.getKey().equals("Name"))
        .findFirst()
        .map(Tag::getValue)
        .orElse("n/a");
}
 
开发者ID:kylesm,项目名称:vpcviewer,代码行数:21,代码来源:SubnetDTO.java


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