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


Java NodeMetadata.getPrivateAddresses方法代码示例

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


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

示例1: sanityCheckSuccessfulNodes

import org.jclouds.compute.domain.NodeMetadata; //导入方法依赖的package包/类
private void sanityCheckSuccessfulNodes(Set<NodeMetadata> successfulNodes,
    Map<NodeMetadata, Throwable> lostNodes) {
  logger.info(String.format("Sanity check on successful nodes... "));
  List<NodeMetadata> tmpNodes = new ArrayList<>();
  tmpNodes.addAll(successfulNodes);
  successfulNodes.clear();
  for (int i = 0; i < tmpNodes.size(); i++) {
    NodeMetadata nm = tmpNodes.get(i);
    if (nm == null) {
      logger.info("for some reason one of the nodes is null, we removed it from the successfull nodes");
    } else if (nm.getPublicAddresses() == null || nm.getPublicAddresses().isEmpty()) {
      logger.info("Ec2 hasn't assined public-ip address to a node, we remove it from successfull nodes");
      lostNodes.put(nm, new KaramelException("No public-ip assigned"));
    } else if (nm.getPrivateAddresses() == null || nm.getPrivateAddresses().isEmpty()) {
      logger.info("Ec2 hasn't assined private-ip address to a node, we remove it from successfull nodes");
      lostNodes.put(nm, new KaramelException("No private-ip assigned"));
    } else {
      successfulNodes.add(nm);
    }
  }
}
 
开发者ID:karamelchef,项目名称:karamel,代码行数:22,代码来源:Ec2Launcher.java

示例2: associateAddresses

import org.jclouds.compute.domain.NodeMetadata; //导入方法依赖的package包/类
@Override
public synchronized List<String> associateAddresses(NodeMetadata node) {
    IaasProvider iaasInfo = getIaasProvider();
    ComputeServiceContext context = iaasInfo.getComputeService().getContext();
    ElasticIPAddressApi elasticIPAddressApi = context.unwrapApi(AWSEC2Api.class).getElasticIPAddressApi().get();
    String region = ComputeServiceBuilderUtil.extractRegion(iaasInfo);
    String ip = null;

    // first try to find an unassigned IP.
    ArrayList<PublicIpInstanceIdPair> unassignedIps = Lists.newArrayList(Iterables
            .filter(elasticIPAddressApi.describeAddressesInRegion(region), new Predicate<PublicIpInstanceIdPair>() {

                @Override
                public boolean apply(PublicIpInstanceIdPair arg0) {
                    return arg0.getInstanceId() == null;
                }

            }));

    if (!unassignedIps.isEmpty()) {
        // try to prevent multiple parallel launches from choosing the same
        // ip.
        Collections.shuffle(unassignedIps);
        ip = Iterables.getLast(unassignedIps).getPublicIp();
    }

    // if no unassigned IP is available, we'll try to allocate an IP.
    if (ip == null || ip.isEmpty()) {
        try {
            ip = elasticIPAddressApi.allocateAddressInRegion(region);
            log.info("Allocated ip [" + ip + "]");

        } catch (Exception e) {
            String msg = "Failed to allocate an IP address. All IP addresses are in use.";
            log.error(msg, e);
            throw new CloudControllerException(msg, e);
        }
    }

    String id = node.getProviderId();

    // wait till the fixed IP address gets assigned - this is needed before
    // we associate a
    // public IP

    while (node.getPrivateAddresses() == null) {
        CloudControllerUtil.sleep(1000);
    }

    int retries = 0;
    while (retries < 12 && !associatePublicIp(elasticIPAddressApi, region, ip, id)) {

        // wait for 5s
        CloudControllerUtil.sleep(5000);
        retries++;
    }

    log.debug("Successfully associated an IP address " + ip + " for node with id: " + node.getId());

    List<String> associatedIPs = new ArrayList<String>();
    associatedIPs.add(ip);
    return associatedIPs;

}
 
开发者ID:apache,项目名称:stratos,代码行数:65,代码来源:EC2Iaas.java

示例3: associateAddresses

import org.jclouds.compute.domain.NodeMetadata; //导入方法依赖的package包/类
@Override
public List<String> associateAddresses(NodeMetadata node) {

    ComputeServiceContext context = iaasProvider.getComputeService().getContext();
    String region = ComputeServiceBuilderUtil.extractRegion(iaasProvider);

    if (StringUtils.isEmpty(region)) {
        throw new RuntimeException("Could not find region in iaas provider: " + iaasProvider.getName());
    }

    NovaApi novaApi = context.unwrapApi(NovaApi.class);
    FloatingIPApi floatingIPApi = novaApi.getFloatingIPExtensionForZone(region).get();

    String ip = null;
    // first try to find an unassigned IP.
    FluentIterable<FloatingIP> floatingIPs = floatingIPApi.list();
    ArrayList<FloatingIP> unassignedIps = Lists.newArrayList(Iterables.filter(floatingIPs,
            new Predicate<FloatingIP>() {
                @Override
                public boolean apply(FloatingIP floatingIP) {
                    return floatingIP.getInstanceId() == null;
                }
            }));

    if (!unassignedIps.isEmpty()) {
        // try to prevent multiple parallel launches from choosing the same ip.
        Collections.shuffle(unassignedIps);
        ip = Iterables.getLast(unassignedIps).getIp();
    }

    // if no unassigned IP is available, we'll try to allocate an IP.
    if (StringUtils.isEmpty(ip)) {
        String floatingIpPool = iaasProvider.getProperty(CloudControllerConstants.DEFAULT_FLOATING_IP_POOL);
        FloatingIP allocatedFloatingIP;
        if (StringUtils.isEmpty(floatingIpPool)) {
            allocatedFloatingIP = floatingIPApi.create();
        } else {
            log.debug(String.format("Trying to allocate a floating IP address from IP pool %s", floatingIpPool));
            allocatedFloatingIP = floatingIPApi.allocateFromPool(floatingIpPool);
        }
        if (allocatedFloatingIP == null) {
            String msg = String.format("Floating IP API did not return a floating IP address from IP pool %s",
                    floatingIpPool);
            log.error(msg);
            throw new CloudControllerException(msg);
        }
        ip = allocatedFloatingIP.getIp();
    }

    // wait till the fixed IP address gets assigned - this is needed before
    // we associate a public IP
    log.info(String.format("Waiting for private IP addresses get allocated: [node-id] %s", node.getId()));
    while (node.getPrivateAddresses() == null) {
        CloudControllerUtil.sleep(1000);
    }
    log.info(String.format("Private IP addresses allocated: %s", node.getPrivateAddresses()));

    if ((node.getPublicAddresses() != null) && (node.getPublicAddresses().iterator().hasNext())) {
        log.info("Public IP address "
                + node.getPublicAddresses().iterator().next()
                + " is already allocated to the instance: [node-id]  "
                + node.getId());
        return null;
    }

    int retries = 0;
    int retryCount = Integer.getInteger("stratos.public.ip.association.retry.count", 5);
    while ((retries < retryCount) && (!associateIp(floatingIPApi, ip, node.getProviderId()))) {
        // wait for 5s
        CloudControllerUtil.sleep(5000);
        retries++;
    }

    log.info(String.format("Successfully associated an IP address: [node-id] %s [ip] %s", node.getId(), ip));

    List<String> allocatedIPAddresses = new ArrayList<String>();
    allocatedIPAddresses.add(ip);
    return allocatedIPAddresses;
}
 
开发者ID:apache,项目名称:stratos,代码行数:80,代码来源:NovaNetworkingApi.java


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