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


Java NodeMetadata.getPublicAddresses方法代码示例

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


在下文中一共展示了NodeMetadata.getPublicAddresses方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: generateHostsFileForNode

import org.jclouds.compute.domain.NodeMetadata; //导入方法依赖的package包/类
/**
 * Creates a /etc/hosts file for a particular node
 * @param nodeIndex node index
 * @return hosts file
 */
private String generateHostsFileForNode(int nodeIndex) {
	NodeMetadata thisNode = getNodeMetadata().asList().get(nodeIndex);
	StringBuilder hostsFile = new StringBuilder();
	hostsFile.append("127.0.0.1 localhost\n");
	hostsFile.append("127.0.1.1 "+thisNode.getHostname());
	for (NodeMetadata node : getNodeMetadata()) {
		if (!node.equals(thisNode)) {
			for (String address : node.getPublicAddresses()) {
			hostsFile.append("\n"+address+" "+node.getHostname());
			}
		}
	}
	
	return hostsFile.toString();
}
 
开发者ID:jasonrig,项目名称:openstack-queue,代码行数:21,代码来源:ServerCollection.java

示例3: retrievePublicIpAddress

import org.jclouds.compute.domain.NodeMetadata; //导入方法依赖的package包/类
@Override
public String retrievePublicIpAddress( TargetHandlerParameters parameters, String machineId )
throws TargetException {

	ComputeService computeService = jcloudContext( parameters.getTargetProperties());
	NodeMetadata metadata = computeService.getNodeMetadata( machineId );

	String result = null;
	if( metadata != null
			&& metadata.getPublicAddresses() != null
			&& ! metadata.getPublicAddresses().isEmpty())
		result = metadata.getPublicAddresses().iterator().next();

	return result;
}
 
开发者ID:roboconf,项目名称:roboconf-platform,代码行数:16,代码来源:JCloudsHandler.java

示例4: 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.getPublicAddresses方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。