Search in sources :

Example 1 with NetworkOrganizer

use of org.nd4j.parameterserver.distributed.util.NetworkOrganizer in project nd4j by deeplearning4j.

the class VoidParameterServer method getRole.

/**
 * This method checks for designated role, according to local IP addresses and configuration passed into method
 *
 * @param voidConfiguration
 * @param localIPs
 * @return
 */
protected Pair<NodeRole, String> getRole(@NonNull VoidConfiguration voidConfiguration, @NonNull Collection<String> localIPs) {
    NodeRole result = NodeRole.CLIENT;
    for (String ip : voidConfiguration.getShardAddresses()) {
        String cleansed = ip.replaceAll(":.*", "");
        if (localIPs.contains(cleansed))
            return Pair.create(NodeRole.SHARD, ip);
    }
    if (voidConfiguration.getBackupAddresses() != null)
        for (String ip : voidConfiguration.getBackupAddresses()) {
            String cleansed = ip.replaceAll(":.*", "");
            if (localIPs.contains(cleansed))
                return Pair.create(NodeRole.BACKUP, ip);
        }
    String sparkIp = null;
    if (sparkIp == null && voidConfiguration.getNetworkMask() != null) {
        NetworkOrganizer organizer = new NetworkOrganizer(voidConfiguration.getNetworkMask());
        sparkIp = organizer.getMatchingAddress();
    }
    // last resort here...
    if (sparkIp == null)
        sparkIp = System.getenv("DL4J_VOID_IP");
    log.info("Got [{}] as sparkIp", sparkIp);
    if (sparkIp == null)
        throw new ND4JIllegalStateException("Can't get IP address for UDP communcation");
    // local IP from pair is used for shard only, so we don't care
    return Pair.create(result, sparkIp + ":" + voidConfiguration.getUnicastPort());
}
Also used : NodeRole(org.nd4j.parameterserver.distributed.enums.NodeRole) NetworkOrganizer(org.nd4j.parameterserver.distributed.util.NetworkOrganizer) ND4JIllegalStateException(org.nd4j.linalg.exception.ND4JIllegalStateException)

Aggregations

ND4JIllegalStateException (org.nd4j.linalg.exception.ND4JIllegalStateException)1 NodeRole (org.nd4j.parameterserver.distributed.enums.NodeRole)1 NetworkOrganizer (org.nd4j.parameterserver.distributed.util.NetworkOrganizer)1