Search in sources :

Example 1 with NetworkInfo

use of edu.iu.dsc.tws.common.net.NetworkInfo in project twister2 by DSC-SPIDAL.

the class TWSTCPChannel method createChannel.

/**
 * Start the TCP servers here
 *
 * @param cfg the configuration
 * @param workerId worker id
 */
private static TCPChannel createChannel(Config cfg, String workerIP, int workerPort, int workerId) {
    NetworkInfo netInfo = new NetworkInfo(workerId);
    netInfo.addProperty(TCPContext.NETWORK_HOSTNAME, workerIP);
    netInfo.addProperty(TCPContext.NETWORK_PORT, workerPort);
    return new TCPChannel(cfg, netInfo);
}
Also used : NetworkInfo(edu.iu.dsc.tws.common.net.NetworkInfo) TCPChannel(edu.iu.dsc.tws.common.net.tcp.TCPChannel)

Example 2 with NetworkInfo

use of edu.iu.dsc.tws.common.net.NetworkInfo in project twister2 by DSC-SPIDAL.

the class TCPChannelExample method setUp.

public void setUp() throws Exception {
    cfg = Config.newBuilder().build();
    NetworkInfo selfInfo = new NetworkInfo(workerID);
    selfInfo.addProperty(TCPContext.NETWORK_PORT, 10010 + workerID);
    selfInfo.addProperty(TCPContext.NETWORK_HOSTNAME, "localhost");
    channel = new TCPChannel(cfg, selfInfo);
    channel.startListening();
    // network info of all workers except the self
    networkInfos = new ArrayList<>();
    for (int i = 0; i < numberOfWorkers; i++) {
        NetworkInfo info = new NetworkInfo(i);
        info.addProperty(TCPContext.NETWORK_PORT, 10010 + i);
        info.addProperty(TCPContext.NETWORK_HOSTNAME, "localhost");
        networkInfos.add(info);
    }
    // wait for all workers to start their tcp servers
    Thread.sleep(3000);
    // connect to all workers
    channel.startConnections(networkInfos);
    channel.waitForConnections(10000);
    LOG.info("all connected...");
    // wait for all to all connections to be established
    Thread.sleep(5000);
    if (workerID == 0) {
        throw new RuntimeException("killing intentionally");
    }
    // wait for worker 0 to die
    Thread.sleep(5000);
}
Also used : NetworkInfo(edu.iu.dsc.tws.common.net.NetworkInfo) TCPChannel(edu.iu.dsc.tws.common.net.tcp.TCPChannel)

Example 3 with NetworkInfo

use of edu.iu.dsc.tws.common.net.NetworkInfo in project twister2 by DSC-SPIDAL.

the class TwoChannelTest method setUp.

@Before
public void setUp() throws Exception {
    cfg = Config.newBuilder().build();
    channels = new ArrayList<>();
    networkInfos = new ArrayList<>();
    for (int i = 0; i < NO_OF_CHANNELS; i++) {
        NetworkInfo info = new NetworkInfo(i);
        info.addProperty(TCPContext.NETWORK_PORT, 10025 + i);
        info.addProperty(TCPContext.NETWORK_HOSTNAME, "localhost");
        TCPChannel channel = new TCPChannel(cfg, info);
        channel.startListening();
        channels.add(channel);
        networkInfos.add(info);
    }
    // we use only one buffer
    for (int i = 0; i < NO_OF_CHANNELS; i++) {
        ByteBuffer b = ByteBuffer.allocate(1024);
        buffers.add(b);
    }
    for (int i = 0; i < NO_OF_CHANNELS; i++) {
        final int j = i;
        Thread t = new Thread(new Runnable() {

            @Override
            public void run() {
                TCPChannel channel = channels.get(j);
                channel.startConnections(networkInfos);
                channel.waitForConnections(10000);
            }
        });
        t.start();
        threads.add(t);
    }
    // lets wait for the connections to be made
    for (int i = 0; i < NO_OF_CHANNELS; i++) {
        Thread t = threads.get(i);
        t.join();
    }
}
Also used : NetworkInfo(edu.iu.dsc.tws.common.net.NetworkInfo) TCPChannel(edu.iu.dsc.tws.common.net.tcp.TCPChannel) ByteBuffer(java.nio.ByteBuffer) Before(org.junit.Before)

Example 4 with NetworkInfo

use of edu.iu.dsc.tws.common.net.NetworkInfo in project twister2 by DSC-SPIDAL.

the class TCPChannel method startConnections.

/**
 * Start the connections to the servers
 * @param workerInfos information about all the workers
 */
public void startConnections(List<NetworkInfo> workerInfos) {
    for (NetworkInfo ni : workerInfos) {
        networkInfoMap.put(ni.getProcId(), ni);
        helloSendByteBuffers.add(ByteBuffer.allocate(4));
        helloReceiveByteBuffers.add(ByteBuffer.allocate(4));
        helloSendByteBuffers.add(ByteBuffer.allocate(4));
        helloReceiveByteBuffers.add(ByteBuffer.allocate(4));
    }
    // after sync we need to connect to all the servers
    for (NetworkInfo info : workerInfos) {
        if (info.getProcId() == thisInfo.getProcId()) {
            continue;
        }
        try {
            String remoteHost = TCPContext.getHostName(info);
            int remotePort = TCPContext.getPort(info);
            Client client = new Client(remoteHost, remotePort, config, looper, new ClientChannelHandler());
            client.connect();
            clients.put(info.getProcId(), client);
            clientChannels.put(info.getProcId(), client.getSocketChannel());
        } catch (UnresolvedAddressException e) {
            throw new RuntimeException("Failed to create client", e);
        }
    }
}
Also used : Twister2RuntimeException(edu.iu.dsc.tws.api.exceptions.Twister2RuntimeException) NetworkInfo(edu.iu.dsc.tws.common.net.NetworkInfo) UnresolvedAddressException(java.nio.channels.UnresolvedAddressException)

Example 5 with NetworkInfo

use of edu.iu.dsc.tws.common.net.NetworkInfo in project twister2 by DSC-SPIDAL.

the class TWSTCPChannel method reInit.

@Override
public void reInit(List<JobMasterAPI.WorkerInfo> restartedWorkers) {
    // close previous connections
    for (JobMasterAPI.WorkerInfo wInfo : restartedWorkers) {
        channel.closeConnection(wInfo.getWorkerID());
    }
    // wait for everyone to start the job master
    try {
        workerController.waitOnBarrier();
    } catch (TimeoutException timeoutException) {
        LOG.log(Level.SEVERE, timeoutException.getMessage(), timeoutException);
        throw new Twister2RuntimeException(timeoutException);
    }
    // lets start the client connections now
    List<NetworkInfo> nInfos = new ArrayList<>();
    for (JobMasterAPI.WorkerInfo w : restartedWorkers) {
        NetworkInfo networkInfo = new NetworkInfo(w.getWorkerID());
        networkInfo.addProperty(TCPContext.NETWORK_PORT, w.getPort());
        networkInfo.addProperty(TCPContext.NETWORK_HOSTNAME, w.getWorkerIP());
        nInfos.add(networkInfo);
    }
    // start the connections
    channel.startConnections(nInfos);
    // now lets wait for connections to be established
    channel.waitForConnections(maxConnEstTime);
}
Also used : JobMasterAPI(edu.iu.dsc.tws.proto.jobmaster.JobMasterAPI) Twister2RuntimeException(edu.iu.dsc.tws.api.exceptions.Twister2RuntimeException) NetworkInfo(edu.iu.dsc.tws.common.net.NetworkInfo) ArrayList(java.util.ArrayList) TimeoutException(edu.iu.dsc.tws.api.exceptions.TimeoutException)

Aggregations

NetworkInfo (edu.iu.dsc.tws.common.net.NetworkInfo)5 TCPChannel (edu.iu.dsc.tws.common.net.tcp.TCPChannel)3 Twister2RuntimeException (edu.iu.dsc.tws.api.exceptions.Twister2RuntimeException)2 TimeoutException (edu.iu.dsc.tws.api.exceptions.TimeoutException)1 JobMasterAPI (edu.iu.dsc.tws.proto.jobmaster.JobMasterAPI)1 ByteBuffer (java.nio.ByteBuffer)1 UnresolvedAddressException (java.nio.channels.UnresolvedAddressException)1 ArrayList (java.util.ArrayList)1 Before (org.junit.Before)1