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);
}
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);
}
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();
}
}
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);
}
}
}
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);
}
Aggregations