Java Code Examples for org.jclouds.compute.domain.NodeMetadata#getPublicAddresses()

The following examples show how to use org.jclouds.compute.domain.NodeMetadata#getPublicAddresses() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Ec2Launcher.java    From karamel with Apache License 2.0 6 votes vote down vote up
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);
    }
  }
}
 
Example 2
Source File: JcloudsSshMachineLocation.java    From brooklyn-server with Apache License 2.0 6 votes vote down vote up
protected void setNode(NodeMetadata node) {
    this.node = null;
    config().removeKey("node");
    nodeId = node.getId();
    imageId = node.getImageId();
    publicAddresses = node.getPublicAddresses();
    _node = Optional.of(node);

    Boolean useMachinePublicAddressAsPrivateAddress = config().get(USE_MACHINE_PUBLIC_ADDRESS_AS_PRIVATE_ADDRESS);
    if(useMachinePublicAddressAsPrivateAddress) {
        LOG.debug("Overriding private address ["+node.getPrivateAddresses()+"] as public address ["+node.getPublicAddresses()+"] as config "+ USE_MACHINE_PUBLIC_ADDRESS_AS_PRIVATE_ADDRESS +" is set to true");
        privateAddresses = node.getPublicAddresses();
    } else {
        privateAddresses = node.getPrivateAddresses();
    }
}
 
Example 3
Source File: DefaultConnectivityResolver.java    From brooklyn-server with Apache License 2.0 6 votes vote down vote up
protected Iterable<String> getResolvableAddressesWithMode(NodeMetadata node) {
    Iterable<String> base;
    switch (getNetworkMode()) {
    case ONLY_PRIVATE:
        base = node.getPrivateAddresses();
        break;
    case ONLY_PUBLIC:
        base = node.getPublicAddresses();
        break;
    case PREFER_PRIVATE:
        base = Iterables.concat(node.getPrivateAddresses(), node.getPublicAddresses());
        break;
    case PREFER_PUBLIC:
    default:
        base = Iterables.concat(node.getPublicAddresses(), node.getPrivateAddresses());
    }
    return FluentIterable.from(base)
            .filter(new AddressResolvable());
}
 
Example 4
Source File: JcloudsWinRmMachineLocation.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
protected void setNode(NodeMetadata node) {
    this.node = null;
    nodeId = node.getId();
    imageId = node.getImageId();
    privateAddresses = node.getPrivateAddresses();
    publicAddresses = node.getPublicAddresses();
    hostname = node.getHostname();
    _node = Optional.of(node);
}
 
Example 5
Source File: JCloudsHandler.java    From roboconf-platform with Apache License 2.0 5 votes vote down vote up
@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;
}
 
Example 6
Source File: CloudDistributedTLCJob.java    From tlaplus with MIT License 4 votes vote down vote up
public WrapperNodeMetadata(final NodeMetadata m, final LoginCredentials credentials) {
	super(m.getProviderId(), m.getName(), m.getId(), m.getLocation(), m.getUri(), m.getUserMetadata(),
			m.getTags(), m.getGroup(), m.getHardware(), m.getImageId(), m.getOperatingSystem(), m.getStatus(),
			m.getBackendStatus(), m.getLoginPort(), m.getPublicAddresses(), m.getPrivateAddresses(),
			credentials, m.getHostname());
}
 
Example 7
Source File: NovaNetworkingApi.java    From attic-stratos with Apache License 2.0 4 votes vote down vote up
@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;
}