當前位置: 首頁>>代碼示例>>Java>>正文


Java Tag.setValue方法代碼示例

本文整理匯總了Java中com.amazonaws.services.ec2.model.Tag.setValue方法的典型用法代碼示例。如果您正苦於以下問題:Java Tag.setValue方法的具體用法?Java Tag.setValue怎麽用?Java Tag.setValue使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.amazonaws.services.ec2.model.Tag的用法示例。


在下文中一共展示了Tag.setValue方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: addTag

import com.amazonaws.services.ec2.model.Tag; //導入方法依賴的package包/類
private void addTag(AmazonEC2Client amazonEC2Client, CloudInstance cloudInstance, Instance instance) {
    String tagName = awsClient.getCbName(cloudInstance.getTemplate().getGroupName(), cloudInstance.getTemplate().getPrivateId());
    Tag t = new Tag();
    t.setKey(TAG_NAME);
    t.setValue(tagName);
    CreateTagsRequest ctr = new CreateTagsRequest();
    ctr.setTags(Collections.singletonList(t));
    ctr.withResources(instance.getInstanceId());
    amazonEC2Client.createTags(ctr);
}
 
開發者ID:hortonworks,項目名稱:cloudbreak,代碼行數:11,代碼來源:AwsMetadataCollector.java

示例2: collectAlreadyTaggedOneGroup

import com.amazonaws.services.ec2.model.Tag; //導入方法依賴的package包/類
@Test
public void collectAlreadyTaggedOneGroup() {
    List<CloudInstance> vms = new ArrayList<>();
    List<Volume> volumes = new ArrayList<>();
    InstanceAuthentication instanceAuthentication = new InstanceAuthentication("sshkey", "", "cloudbreak");
    vms.add(new CloudInstance("i-1",
            new InstanceTemplate("fla", "cbgateway", 5L, volumes, InstanceStatus.CREATED, null, 0L),
            instanceAuthentication));


    when(awsClient.createCloudFormationClient(any(AwsCredentialView.class), eq("region"))).thenReturn(amazonCFClient);
    when(awsClient.createAutoScalingClient(any(AwsCredentialView.class), eq("region"))).thenReturn(amazonASClient);
    when(awsClient.createAccess(any(AwsCredentialView.class), eq("region"))).thenReturn(amazonEC2Client);

    when(cloudFormationStackUtil.getAutoscalingGroupName(any(AuthenticatedContext.class), any(AmazonCloudFormationClient.class), eq("cbgateway")))
            .thenReturn("cbgateway-AAA");

    List<String> gatewayIds = Collections.singletonList("i-1");
    when(cloudFormationStackUtil.getInstanceIds(any(AmazonAutoScalingClient.class), eq("cbgateway-AAA")))
            .thenReturn(gatewayIds);

    when(cloudFormationStackUtil.createDescribeInstancesRequest(eq(gatewayIds))).thenReturn(describeInstancesRequestGw);

    when(amazonEC2Client.describeInstances(describeInstancesRequestGw)).thenReturn(describeInstancesResultGw);

    Instance instance = Mockito.mock(Instance.class);
    when(instance.getInstanceId()).thenReturn("i-1");
    when(instance.getPrivateIpAddress()).thenReturn("privateIp");
    when(instance.getPublicIpAddress()).thenReturn("publicIp");
    Tag tag = new Tag();
    tag.setKey("cbname");
    tag.setValue("somevalue");
    when(instance.getTags()).thenReturn(Collections.singletonList(tag));

    List<Reservation> gatewayReservations = Collections.singletonList(getReservation(instance));

    when(describeInstancesResultGw.getReservations()).thenReturn(gatewayReservations);

    AuthenticatedContext ac = authenticatedContext();
    List<CloudVmMetaDataStatus> statuses = awsMetadataCollector.collect(ac, null, vms);

    verify(amazonEC2Client, never()).createTags(any(CreateTagsRequest.class));
    Assert.assertEquals(1, statuses.size());
    Assert.assertEquals("i-1", statuses.get(0).getCloudVmInstanceStatus().getCloudInstance().getInstanceId());
    Assert.assertEquals("privateIp", statuses.get(0).getMetaData().getPrivateIp());
    Assert.assertEquals("publicIp", statuses.get(0).getMetaData().getPublicIp());
}
 
開發者ID:hortonworks,項目名稱:cloudbreak,代碼行數:48,代碼來源:AwsMetaDataCollectorTest.java

示例3: collectNewOldIsTagged

import com.amazonaws.services.ec2.model.Tag; //導入方法依賴的package包/類
@Test
public void collectNewOldIsTagged() {
    List<CloudInstance> vms = new ArrayList<>();
    List<Volume> volumes = new ArrayList<>();
    InstanceAuthentication instanceAuthentication = new InstanceAuthentication("sshkey", "", "cloudbreak");
    vms.add(new CloudInstance(null,
            new InstanceTemplate("fla", "cbgateway", 5L, volumes, InstanceStatus.CREATED, null, 0L),
            instanceAuthentication));

    when(awsClient.createCloudFormationClient(any(AwsCredentialView.class), eq("region"))).thenReturn(amazonCFClient);
    when(awsClient.createAutoScalingClient(any(AwsCredentialView.class), eq("region"))).thenReturn(amazonASClient);
    when(awsClient.createAccess(any(AwsCredentialView.class), eq("region"))).thenReturn(amazonEC2Client);

    when(cloudFormationStackUtil.getAutoscalingGroupName(any(AuthenticatedContext.class), any(AmazonCloudFormationClient.class), eq("cbgateway")))
            .thenReturn("cbgateway-AAA");

    List<String> gatewayIds = Arrays.asList("i-1", "i-new");
    when(cloudFormationStackUtil.getInstanceIds(any(AmazonAutoScalingClient.class), eq("cbgateway-AAA")))
            .thenReturn(gatewayIds);

    when(cloudFormationStackUtil.createDescribeInstancesRequest(eq(gatewayIds))).thenReturn(describeInstancesRequestGw);

    when(amazonEC2Client.describeInstances(describeInstancesRequestGw)).thenReturn(describeInstancesResultGw);

    Instance instance1 = Mockito.mock(Instance.class);
    when(instance1.getInstanceId()).thenReturn("i-1");
    when(instance1.getPrivateIpAddress()).thenReturn("privateIp1");
    when(instance1.getPublicIpAddress()).thenReturn("publicIp1");
    Tag tag = new Tag();
    tag.setKey("cbname");
    tag.setValue("somevalue");
    when(instance1.getTags()).thenReturn(Collections.singletonList(tag));

    Instance instance2 = Mockito.mock(Instance.class);
    when(instance2.getInstanceId()).thenReturn("i-new");
    when(instance2.getPrivateIpAddress()).thenReturn("privateIp2");
    when(instance2.getPublicIpAddress()).thenReturn("publicIp2");

    List<Reservation> gatewayReservations = Collections.singletonList(getReservation(instance1, instance2));

    when(describeInstancesResultGw.getReservations()).thenReturn(gatewayReservations);

    AuthenticatedContext ac = authenticatedContext();
    List<CloudVmMetaDataStatus> statuses = awsMetadataCollector.collect(ac, null, vms);

    verify(amazonEC2Client, times(1)).createTags(any(CreateTagsRequest.class));
    Assert.assertEquals(1, statuses.size());
    Assert.assertEquals("i-new", statuses.get(0).getCloudVmInstanceStatus().getCloudInstance().getInstanceId());
    Assert.assertEquals("privateIp2", statuses.get(0).getMetaData().getPrivateIp());
    Assert.assertEquals("publicIp2", statuses.get(0).getMetaData().getPublicIp());
}
 
開發者ID:hortonworks,項目名稱:cloudbreak,代碼行數:52,代碼來源:AwsMetaDataCollectorTest.java


注:本文中的com.amazonaws.services.ec2.model.Tag.setValue方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。