本文整理汇总了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);
}
}
}
示例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;
}
示例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;
}