• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java Address类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: getAllUnusedEIPs

import com.amazonaws.services.ec2.model.Address; //导入依赖的package包/类
/**
 * This method returns all unused EIPs
 * @return returns all unused EIPs
 */
public List<Address> getAllUnusedEIPs(List<Address> allEIPs) {
    
    List<Address> allUnusedEIPs = new ArrayList<>();
    
    if ( allEIPs != null || allEIPs.size() >0 ) {
        for(Address address: allEIPs) {
            if (address.getInstanceId() == null) {
                allUnusedEIPs.add(address);
            }
        }
    }
    
    System.out.println("INFO : Number of Unused EIPs : " + allUnusedEIPs.size());
    List<String> EIPs = allUnusedEIPs.stream().map( e -> e.getPublicIp()).collect(Collectors.toList());
    System.out.println("INFO : Unused EIPs : " + EIPs);
    
    return allUnusedEIPs;
    
}
 
开发者ID:code4innerpeace,项目名称:AWSConfig,代码行数:24,代码来源:EC2UtilsImpl.java


示例2: createEvaluations

import com.amazonaws.services.ec2.model.Address; //导入依赖的package包/类
/**
 * This method returns list of Evaluation objects.
 * @param allUnusedEIPs
 * @return List<Evaluation> returns list of Evaluation objects.
 */
private List<Evaluation> createEvaluations(List<Address> allUnusedEIPs) {
    
    List<Evaluation> evaluations = new ArrayList<>();
    
    if ( allUnusedEIPs == null || allUnusedEIPs.size() > 0 ) {
        
        for(Address address: allUnusedEIPs) {
            
            String EIP = address.getPublicIp();
            Evaluation evaluation = new Evaluation();
            evaluation.setComplianceResourceId(EIP);
            evaluation.setComplianceResourceType(COMPLIANCE_RESOURCE_TYPE);
            evaluation.setComplianceType(ComplianceType.NON_COMPLIANT);
            evaluation.setOrderingTimestamp(new Date());
            evaluations.add(evaluation);
        }
    }
    
    System.out.println("INFO : Number of evaluations : " + evaluations.size());
    return evaluations;
}
 
开发者ID:code4innerpeace,项目名称:AWSConfig,代码行数:27,代码来源:EIPsUnused.java


示例3: main

import com.amazonaws.services.ec2.model.Address; //导入依赖的package包/类
public static void main(String[] args)
{
    final AmazonEC2 ec2 = AmazonEC2ClientBuilder.defaultClient();

    DescribeAddressesResult response = ec2.describeAddresses();

    for(Address address : response.getAddresses()) {
        System.out.printf(
                "Found address with public IP %s, " +
                "domain %s, " +
                "allocation id %s " +
                "and NIC id %s",
                address.getPublicIp(),
                address.getDomain(),
                address.getAllocationId(),
                address.getNetworkInterfaceId());
    }
}
 
开发者ID:awsdocs,项目名称:aws-doc-sdk-examples,代码行数:19,代码来源:DescribeAddresses.java


示例4: itShouldStartAnEC2InstanceFromAnAMI

import com.amazonaws.services.ec2.model.Address; //导入依赖的package包/类
@Test
public void itShouldStartAnEC2InstanceFromAnAMI()
		throws ServiceBrokerException {

	when(
			ec2Client.runInstances(awsRqst(r -> r.getImageId().equals(
					"test_image")))).thenReturn(runInstanceResult);

	when(ec2Client.describeAddresses()).thenReturn(
			new DescribeAddressesResult().withAddresses(Collections
					.singleton(new Address().withPublicIp("10.10.10.10"))));

	when(ec2Client.describeInstanceStatus(any())).thenReturn(
			new DescribeInstanceStatusResult()
					.withInstanceStatuses(Collections
							.singleton(new InstanceStatus()
									.withInstanceState(new InstanceState()
											.withName("running")))));

	when(hostUtils.waitForBoot(anyString(), anyInt())).thenReturn(true);
	assertThat(aws.startEC2Instance("test_image"),
			is(equalTo("test_instance")));
}
 
开发者ID:krujos,项目名称:data-lifecycle-service-broker,代码行数:24,代码来源:AWSHelperTest.java


示例5: checkAssociatedAddress

import com.amazonaws.services.ec2.model.Address; //导入依赖的package包/类
public Address checkAssociatedAddress(AwsProcessClient awsProcessClient, Long instanceNo, Long addressNo) {
    AwsAddress awsAddress = awsAddressDao.read(addressNo);
    String publicIp = awsAddress.getPublicIp();
    String instanceId = awsAddress.getInstanceId();

    // アドレスが関連付けられているかどうかのチェック
    Address address = awsCommonProcess.describeAddress(awsProcessClient, publicIp);

    if (StringUtils.isEmpty(address.getInstanceId())) {
        // アドレスがどのインスタンスにも関連付けられていない場合
        throw new AutoException("EPROCESS-000120", publicIp, instanceId);

    } else if (!StringUtils.equals(instanceId, address.getInstanceId())) {
        // アドレスが他インスタンスに関連付けられている場合
        throw new AutoException("EPROCESS-000121", publicIp, instanceId, address.getInstanceId());
    }

    return address;
}
 
开发者ID:primecloud-controller-org,项目名称:primecloud-controller,代码行数:20,代码来源:AwsAddressProcess.java


示例6: describeAddress

import com.amazonaws.services.ec2.model.Address; //导入依赖的package包/类
public Address describeAddress(AwsProcessClient awsProcessClient, String publicIp) {
    // 単一アドレスの参照
    DescribeAddressesRequest request = new DescribeAddressesRequest();
    request.withPublicIps(publicIp);
    DescribeAddressesResult result = awsProcessClient.getEc2Client().describeAddresses(request);
    List<Address> addresses = result.getAddresses();

    // API実行結果チェック
    if (addresses.size() == 0) {
        // アドレスが存在しない場合
        throw new AutoException("EPROCESS-000117", publicIp);

    } else if (addresses.size() > 1) {
        // アドレスを複数参照できた場合
        AutoException exception = new AutoException("EPROCESS-000118", publicIp);
        exception.addDetailInfo("result=" + addresses);
        throw exception;
    }

    return addresses.get(0);
}
 
开发者ID:primecloud-controller-org,项目名称:primecloud-controller,代码行数:22,代码来源:AwsCommonProcess.java


示例7: releaseReservedIp

import com.amazonaws.services.ec2.model.Address; //导入依赖的package包/类
private void releaseReservedIp(AmazonEC2Client client, List<CloudResource> resources) {
    CloudResource elasticIpResource = getReservedIp(resources);
    if (elasticIpResource != null && elasticIpResource.getName() != null) {
        Address address;
        try {
            DescribeAddressesResult describeResult = client.describeAddresses(
                    new DescribeAddressesRequest().withAllocationIds(elasticIpResource.getName()));
            address = describeResult.getAddresses().get(0);
        } catch (AmazonServiceException e) {
            if (e.getErrorMessage().equals("The allocation ID '" + elasticIpResource.getName() + "' does not exist")) {
                LOGGER.warn("Elastic IP with allocation ID '{}' not found. Ignoring IP release.", elasticIpResource.getName());
                return;
            } else {
                throw e;
            }
        }
        if (address.getAssociationId() != null) {
            client.disassociateAddress(new DisassociateAddressRequest().withAssociationId(elasticIpResource.getName()));
        }
        client.releaseAddress(new ReleaseAddressRequest().withAllocationId(elasticIpResource.getName()));
    }
}
 
开发者ID:hortonworks,项目名称:cloudbreak,代码行数:23,代码来源:AwsResourceConnector.java


示例8: testGetAllUnusedEIPs

import com.amazonaws.services.ec2.model.Address; //导入依赖的package包/类
@Test
public void testGetAllUnusedEIPs() {
    
    EC2UtilsImpl ec2UtilsImpl = new EC2UtilsImpl();
    List<Address> allUnusedEIPs = ec2UtilsImpl.getAllUnusedEIPs(allEIPs);
    assertEquals(2, allUnusedEIPs.size());
}
 
开发者ID:code4innerpeace,项目名称:AWSConfig,代码行数:8,代码来源:EC2UtilsImplTest.java


示例9: itShouldReturnAFreeElasticIp

import com.amazonaws.services.ec2.model.Address; //导入依赖的package包/类
@Test
public void itShouldReturnAFreeElasticIp() throws ServiceBrokerException {
	when(ec2Client.describeAddresses()).thenReturn(
			new DescribeAddressesResult().withAddresses(Collections
					.singleton(new Address().withPublicIp("10.10.10.10"))));
	assertThat("10.10.10.10", is(aws.getAvaliableElasticIp()));
}
 
开发者ID:krujos,项目名称:data-lifecycle-service-broker,代码行数:8,代码来源:AWSHelperTest.java


示例10: itShouldReturnOnlyOneFreeElasticIp

import com.amazonaws.services.ec2.model.Address; //导入依赖的package包/类
@Test
public void itShouldReturnOnlyOneFreeElasticIp()
		throws ServiceBrokerException {
	when(ec2Client.describeAddresses()).thenReturn(
			new DescribeAddressesResult().withAddresses(Arrays.asList(
					new Address().withPublicIp("10.10.10.10")
							.withInstanceId(null),
					new Address().withPublicIp("10.10.10.11")
							.withInstanceId(null))));
	assertThat("10.10.10.10", is(aws.getAvaliableElasticIp()));
}
 
开发者ID:krujos,项目名称:data-lifecycle-service-broker,代码行数:12,代码来源:AWSHelperTest.java


示例11: itShouldFilterOutAttachedElasticIPs

import com.amazonaws.services.ec2.model.Address; //导入依赖的package包/类
@Test
public void itShouldFilterOutAttachedElasticIPs()
		throws ServiceBrokerException {
	when(ec2Client.describeAddresses()).thenReturn(
			new DescribeAddressesResult().withAddresses(Arrays.asList(
					new Address().withPublicIp("10.10.10.10")
							.withInstanceId("the-instance"),
					new Address().withPublicIp("10.10.10.11")
							.withInstanceId(null))));
	assertThat("10.10.10.11", is(aws.getAvaliableElasticIp()));
}
 
开发者ID:krujos,项目名称:data-lifecycle-service-broker,代码行数:12,代码来源:AWSHelperTest.java


示例12: checkExistsAddress

import com.amazonaws.services.ec2.model.Address; //导入依赖的package包/类
public static Address checkExistsAddress(AmazonEC2 ec2, String targetIp) {
	DescribeAddressesRequest addressRequest = new DescribeAddressesRequest().withPublicIps(targetIp);
	DescribeAddressesResult addressResult = ec2.describeAddresses(addressRequest);
	List<Address> addresses = addressResult.getAddresses();
	for (Address address : addresses) {
		String publicIp = address.getPublicIp();
		if (targetIp.equals(publicIp)) {
			return address;
		}
		break;
	}
	return null;
}
 
开发者ID:betahikaru,项目名称:ec2-util,代码行数:14,代码来源:AwsEc2Client.java


示例13: allocateAddress

import com.amazonaws.services.ec2.model.Address; //导入依赖的package包/类
public static Address allocateAddress(AmazonEC2 ec2, DomainType domainType) {
	AllocateAddressRequest addressRequest = new AllocateAddressRequest().withDomain(domainType);
	AllocateAddressResult addressResult = ec2.allocateAddress(addressRequest);
	Address address = new Address().withAllocationId(addressResult.getAllocationId())
			.withDomain(addressResult.getDomain()).withPublicIp(addressResult.getPublicIp());
	return address;
}
 
开发者ID:betahikaru,项目名称:ec2-util,代码行数:8,代码来源:AwsEc2Client.java


示例14: associateAddress

import com.amazonaws.services.ec2.model.Address; //导入依赖的package包/类
public static String associateAddress(AmazonEC2 ec2, Address address, String instanceId) {
	AssociateAddressRequest addressRequest = new AssociateAddressRequest()
			.withAllocationId(address.getAllocationId()).withInstanceId(instanceId);
	AssociateAddressResult addressResult = ec2.associateAddress(addressRequest);
	String associationId = addressResult.getAssociationId();
	return associationId;
}
 
开发者ID:betahikaru,项目名称:ec2-util,代码行数:8,代码来源:AwsEc2Client.java


示例15: execute

import com.amazonaws.services.ec2.model.Address; //导入依赖的package包/类
/**
 * Stop Ec2 Instance. Realease EIP for Ec2 Instance. Disassociate EIP.
 */
public int execute(Ec2CommandOptions options) throws FileNotFoundException {
	System.out.println(getClass().getName());
	String name = options.getName();
	InputStream inputStream = new FileInputStream(new File(options.getCredentialsPath()));
	ConfigProvider.loadConfigure(inputStream);
	AmazonEC2 ec2 = AwsEc2Client.getEc2();

	// Check Exists Instance
	Instance instance = AwsEc2Client.findInstanceByName(ec2, name);
	if (instance == null) {
		System.err.println("Not exists instance (name = " + name + ").");
		return 2;
	}
	String instanceId = instance.getInstanceId();
	String publicIp = instance.getPublicIpAddress();
	System.out.println("Exists instance (id = " + instanceId + ")");

	// Stop Ec2 Instance
	InstanceStateChange stateChange = AwsEc2Client.stopInstance(ec2, instanceId);
	AwsEc2Client.showStateChange(stateChange, "Stopping Instance");

	// Disassociate and Release Address
	if (publicIp != null) {
		Address address = AwsEc2Client.checkExistsAddress(ec2, publicIp);
		if (address != null) {
			AwsEc2Client.disassociateAddress(ec2, address);
			System.out.println("Disassociated Address (" + publicIp + ")");
			AwsEc2Client.releaseAddress(ec2, address);
			System.out.println("Released Address (" + publicIp + ")");
		}
	} else {
		System.out.println("No EIP.");
	}
	return 0;
}
 
开发者ID:betahikaru,项目名称:ec2-util,代码行数:39,代码来源:Ec2StopCommand.java


示例16: releaseEIP

import com.amazonaws.services.ec2.model.Address; //导入依赖的package包/类
public void releaseEIP(List<String> instanceIds) {
    logger.info("release EIP for instances, instanceIds={}", instanceIds);

    DescribeAddressesResult result = ec2.describeAddresses(new DescribeAddressesRequest().withFilters(new Filter("instance-id").withValues(instanceIds)));
    for (Address address : result.getAddresses()) {
        logger.info("release EIP, ip={}, instanceId={}", address.getPublicIp(), address.getInstanceId());
        ec2.disassociateAddress(new DisassociateAddressRequest().withAssociationId(address.getAssociationId()));
        ec2.releaseAddress(new ReleaseAddressRequest().withAllocationId(address.getAllocationId()));
    }
}
 
开发者ID:neowu,项目名称:cmn-project,代码行数:11,代码来源:EC2VPC.java


示例17: createNATGateway

import com.amazonaws.services.ec2.model.Address; //导入依赖的package包/类
public NatGateway createNATGateway(String subnetId, String ip) {
    logger.info("create nat gateway, subnetId={}, ip={}", subnetId, ip);

    List<Address> addresses = AWS.vpc.ec2.describeAddresses(new DescribeAddressesRequest().withPublicIps(ip)).getAddresses();
    if (addresses.isEmpty()) throw new Error("cannot find eip, ip=" + ip);
    Address address = addresses.get(0);
    if (address.getAssociationId() != null) throw new Error("eip must not associated with other resource, ip=" + ip);

    CreateNatGatewayRequest request = new CreateNatGatewayRequest()
        .withSubnetId(subnetId)
        .withAllocationId(address.getAllocationId());
    String gatewayId = ec2.createNatGateway(request).getNatGateway().getNatGatewayId();

    NatGateway gateway;
    while (true) {
        Threads.sleepRoughly(Duration.ofSeconds(30));
        gateway = describeNATGateway(gatewayId);
        String state = gateway.getState();
        if ("pending".equals(state)) continue;
        if ("available".equals(state)) {
            break;
        } else {
            throw new Error("failed to create nat gateway, gatewayId=" + gatewayId + ", state=" + state);
        }
    }
    return gateway;
}
 
开发者ID:neowu,项目名称:cmn-project,代码行数:28,代码来源:EC2VPC.java


示例18: convertObject

import com.amazonaws.services.ec2.model.Address; //导入依赖的package包/类
@Override
protected Address convertObject(AddressInfo from) {
    Address to = new Address();

    to.setInstanceId(from.getInstanceId());
    to.setPublicIp(from.getPublicIp());

    return to;
}
 
开发者ID:primecloud-controller-org,项目名称:primecloud-controller,代码行数:10,代码来源:AddressConverter.java


示例19: startAddress

import com.amazonaws.services.ec2.model.Address; //导入依赖的package包/类
/**
 * TODO: メソッドコメント
 * 
 * @param awsProcessClient
 * @param instanceNo
 */
public void startAddress(AwsProcessClient awsProcessClient, Long instanceNo) {
    // アドレス情報の取得
    List<AwsAddress> awsAddresses = awsAddressDao.readByInstanceNo(instanceNo);

    if (awsAddresses.size() > 1) {
        // アドレス情報が複数ある場合
        AutoException exception = new AutoException("EPROCESS-000202", instanceNo);
        exception.addDetailInfo("result=" + awsAddresses);
        throw exception;
    }

    if (awsAddresses.isEmpty()) {
        // アドレス情報がない場合は終了
        return;
    }

    AwsAddress awsAddress = awsAddresses.get(0);

    // インスタンスIDがない場合、インスタンスに関連付ける
    if (StringUtils.isEmpty(awsAddress.getInstanceId())) {
        // アドレスのステータスチェック
        Address address = checkAvailableAddress(awsProcessClient, instanceNo, awsAddress.getAddressNo());

        // アドレスの関連付け
        associateAddress(awsProcessClient, instanceNo, awsAddress.getAddressNo(), address);

        // インスタンスのアドレス情報を更新
        updateInstanceAddress(awsProcessClient, instanceNo, awsAddress.getAddressNo());
    }
}
 
开发者ID:primecloud-controller-org,项目名称:primecloud-controller,代码行数:37,代码来源:AwsAddressProcess.java


示例20: checkAvailableAddress

import com.amazonaws.services.ec2.model.Address; //导入依赖的package包/类
public Address checkAvailableAddress(AwsProcessClient awsProcessClient, Long instanceNo, Long addressNo) {
    AwsAddress awsAddress = awsAddressDao.read(addressNo);
    String publicIp = awsAddress.getPublicIp();

    Address address = awsCommonProcess.describeAddress(awsProcessClient, publicIp);

    if (!StringUtils.isEmpty(address.getInstanceId())) {
        // アドレスが何らかのインスタンスに関連付けられている場合
        throw new AutoException("EPROCESS-000119", publicIp, address.getInstanceId());
    }

    return address;
}
 
开发者ID:primecloud-controller-org,项目名称:primecloud-controller,代码行数:14,代码来源:AwsAddressProcess.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java KerberosKeyFactory类代码示例发布时间:2022-05-22
下一篇:
Java GetContainerStatusesResponse类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap