Search in sources :

Example 1 with TransportException

use of com.baidu.hugegraph.computer.core.common.exception.TransportException in project hugegraph-computer by hugegraph.

the class NettyServerHandler method exceptionCaught.

@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
    TransportException exception;
    Channel channel = ctx.channel();
    if (cause instanceof TransportException) {
        exception = (TransportException) cause;
    } else {
        exception = new TransportException("%s when the server receive data from '%s'", cause, cause.getMessage(), TransportUtil.remoteAddress(channel));
    }
    ConnectionId connectionId = TransportUtil.remoteConnectionId(channel);
    this.handler.exceptionCaught(exception, connectionId);
}
Also used : ConnectionId(com.baidu.hugegraph.computer.core.network.ConnectionId) Channel(io.netty.channel.Channel) SocketChannel(io.netty.channel.socket.SocketChannel) TransportException(com.baidu.hugegraph.computer.core.common.exception.TransportException)

Example 2 with TransportException

use of com.baidu.hugegraph.computer.core.common.exception.TransportException in project hugegraph-computer by hugegraph.

the class NettyClientFactory method doConnect.

/**
 * Connect to the remote server.
 */
protected Channel doConnect(InetSocketAddress address, int connectTimeoutMs) throws TransportException {
    E.checkArgumentNotNull(this.bootstrap, "The NettyClientFactory has not been " + "initialized yet");
    long preConnect = System.nanoTime();
    String formatAddress = TransportUtil.formatAddress(address);
    LOG.debug("ConnectTimeout of address [{}] is [{}]", formatAddress, connectTimeoutMs);
    ChannelFuture future = this.bootstrap.connect(address);
    boolean success = future.awaitUninterruptibly(connectTimeoutMs, TimeUnit.MILLISECONDS);
    if (!future.isDone()) {
        throw new TransportException("Create connection to '%s' timeout!", formatAddress);
    }
    if (future.isCancelled()) {
        throw new TransportException("Create connection to '%s' cancelled by user!", formatAddress);
    }
    if (future.cause() != null) {
        throw new TransportException("Failed to create connection to '%s', caused by: %s", future.cause(), formatAddress, future.cause().getMessage());
    }
    if (!success || !future.isSuccess()) {
        throw new TransportException("Failed to create connection to '%s'", formatAddress);
    }
    long postConnect = System.nanoTime();
    LOG.info("Successfully created connection to '{}' after {} ms", formatAddress, (postConnect - preConnect) / 1000000L);
    return future.channel();
}
Also used : ChannelFuture(io.netty.channel.ChannelFuture) TransportException(com.baidu.hugegraph.computer.core.common.exception.TransportException)

Example 3 with TransportException

use of com.baidu.hugegraph.computer.core.common.exception.TransportException in project hugegraph-computer by hugegraph.

the class NettyClientHandler method exceptionCaught.

@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
    TransportException exception;
    if (cause instanceof TransportException) {
        exception = (TransportException) cause;
    } else {
        exception = new TransportException("%s when the client receive data from '%s'", cause, cause.getMessage(), TransportUtil.remoteAddress(ctx.channel()));
    }
    this.client.clientHandler().exceptionCaught(exception, this.client.connectionId());
}
Also used : TransportException(com.baidu.hugegraph.computer.core.common.exception.TransportException)

Example 4 with TransportException

use of com.baidu.hugegraph.computer.core.common.exception.TransportException in project hugegraph-computer by hugegraph.

the class DataServerManagerTest method test.

@Test
public void test() {
    Config config = UnitTestBase.updateWithRequiredOptions(RpcOptions.RPC_REMOTE_URL, "127.0.0.1:8090", ComputerOptions.JOB_ID, "local_001", ComputerOptions.JOB_WORKERS_COUNT, "1", ComputerOptions.BSP_LOG_INTERVAL, "30000", ComputerOptions.BSP_MAX_SUPER_STEP, "2", ComputerOptions.WORKER_COMPUTATION_CLASS, MockComputation.class.getName(), ComputerOptions.MASTER_COMPUTATION_CLASS, MockMasterComputation.class.getName());
    FileManager fileManager = new FileManager();
    fileManager.init(config);
    SortManager sortManager = new RecvSortManager(context());
    sortManager.init(config);
    MessageRecvManager recvManager = new MessageRecvManager(context(), fileManager, sortManager);
    recvManager.init(config);
    ConnectionManager connManager = new TransportConnectionManager();
    DataServerManager serverManager = new DataServerManager(connManager, recvManager);
    serverManager.init(config);
    Assert.assertEquals(DataServerManager.NAME, serverManager.name());
    InetSocketAddress address = serverManager.address();
    Assert.assertNotEquals(0, address.getPort());
    ConnectionId connectionId = ConnectionId.parseConnectionId(address.getHostName(), address.getPort());
    recvManager.onChannelActive(connectionId);
    recvManager.onChannelInactive(connectionId);
    TransportException e = new TransportException("test transport " + "exception");
    recvManager.exceptionCaught(e, connectionId);
    serverManager.close(config);
    fileManager.close(config);
    sortManager.close(config);
}
Also used : Config(com.baidu.hugegraph.computer.core.config.Config) InetSocketAddress(java.net.InetSocketAddress) MockMasterComputation(com.baidu.hugegraph.computer.core.worker.MockMasterComputation) TransportException(com.baidu.hugegraph.computer.core.common.exception.TransportException) FileManager(com.baidu.hugegraph.computer.core.store.FileManager) RecvSortManager(com.baidu.hugegraph.computer.core.sort.sorting.RecvSortManager) SortManager(com.baidu.hugegraph.computer.core.sort.sorting.SortManager) MessageRecvManager(com.baidu.hugegraph.computer.core.receiver.MessageRecvManager) ConnectionManager(com.baidu.hugegraph.computer.core.network.connection.ConnectionManager) TransportConnectionManager(com.baidu.hugegraph.computer.core.network.connection.TransportConnectionManager) MockComputation(com.baidu.hugegraph.computer.core.worker.MockComputation) RecvSortManager(com.baidu.hugegraph.computer.core.sort.sorting.RecvSortManager) TransportConnectionManager(com.baidu.hugegraph.computer.core.network.connection.TransportConnectionManager) Test(org.junit.Test)

Example 5 with TransportException

use of com.baidu.hugegraph.computer.core.common.exception.TransportException in project hugegraph-computer by hugegraph.

the class SenderIntegrateTest method slowSendFunc.

private void slowSendFunc(WorkerService service) throws TransportException {
    Managers managers = Whitebox.getInternalState(service, "managers");
    DataClientManager clientManager = managers.get(DataClientManager.NAME);
    ConnectionManager connManager = Whitebox.getInternalState(clientManager, "connManager");
    NettyTransportClient client = (NettyTransportClient) connManager.getOrCreateClient("127.0.0.1", 8091);
    ClientSession clientSession = Whitebox.invoke(client.getClass(), "clientSession", client);
    Function<Message, Future<Void>> sendFuncBak = Whitebox.getInternalState(clientSession, "sendFunction");
    Function<Message, Future<Void>> sendFunc = message -> {
        try {
            Thread.sleep(100);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        return sendFuncBak.apply(message);
    };
    Whitebox.setInternalState(clientSession, "sendFunction", sendFunc);
}
Also used : PageRankParams(com.baidu.hugegraph.computer.algorithm.centrality.pagerank.PageRankParams) ComputerOptions(com.baidu.hugegraph.computer.core.config.ComputerOptions) DoubleValue(com.baidu.hugegraph.computer.core.graph.value.DoubleValue) BeforeClass(org.junit.BeforeClass) Managers(com.baidu.hugegraph.computer.core.manager.Managers) RpcOptions(com.baidu.hugegraph.config.RpcOptions) Function(java.util.function.Function) MasterService(com.baidu.hugegraph.computer.core.master.MasterService) ArrayList(java.util.ArrayList) Future(java.util.concurrent.Future) Whitebox(com.baidu.hugegraph.testutil.Whitebox) TransportException(com.baidu.hugegraph.computer.core.common.exception.TransportException) ComputerContextUtil(com.baidu.hugegraph.computer.core.util.ComputerContextUtil) Message(com.baidu.hugegraph.computer.core.network.message.Message) AfterClass(org.junit.AfterClass) Logger(org.slf4j.Logger) ConnectionManager(com.baidu.hugegraph.computer.core.network.connection.ConnectionManager) Test(org.junit.Test) NettyTransportClient(com.baidu.hugegraph.computer.core.network.netty.NettyTransportClient) ClientSession(com.baidu.hugegraph.computer.core.network.session.ClientSession) Config(com.baidu.hugegraph.computer.core.config.Config) DataClientManager(com.baidu.hugegraph.computer.core.network.DataClientManager) List(java.util.List) Log(com.baidu.hugegraph.util.Log) WorkerService(com.baidu.hugegraph.computer.core.worker.WorkerService) Assert(com.baidu.hugegraph.testutil.Assert) ConnectionManager(com.baidu.hugegraph.computer.core.network.connection.ConnectionManager) Message(com.baidu.hugegraph.computer.core.network.message.Message) Managers(com.baidu.hugegraph.computer.core.manager.Managers) DataClientManager(com.baidu.hugegraph.computer.core.network.DataClientManager) NettyTransportClient(com.baidu.hugegraph.computer.core.network.netty.NettyTransportClient) ClientSession(com.baidu.hugegraph.computer.core.network.session.ClientSession) Future(java.util.concurrent.Future)

Aggregations

TransportException (com.baidu.hugegraph.computer.core.common.exception.TransportException)10 ConnectionId (com.baidu.hugegraph.computer.core.network.ConnectionId)3 Config (com.baidu.hugegraph.computer.core.config.Config)2 ConnectionManager (com.baidu.hugegraph.computer.core.network.connection.ConnectionManager)2 ChannelFuture (io.netty.channel.ChannelFuture)2 Test (org.junit.Test)2 PageRankParams (com.baidu.hugegraph.computer.algorithm.centrality.pagerank.PageRankParams)1 ComputerException (com.baidu.hugegraph.computer.core.common.exception.ComputerException)1 ComputerOptions (com.baidu.hugegraph.computer.core.config.ComputerOptions)1 DoubleValue (com.baidu.hugegraph.computer.core.graph.value.DoubleValue)1 Managers (com.baidu.hugegraph.computer.core.manager.Managers)1 MasterService (com.baidu.hugegraph.computer.core.master.MasterService)1 DataClientManager (com.baidu.hugegraph.computer.core.network.DataClientManager)1 NetworkBuffer (com.baidu.hugegraph.computer.core.network.buffer.NetworkBuffer)1 TransportConnectionManager (com.baidu.hugegraph.computer.core.network.connection.TransportConnectionManager)1 Message (com.baidu.hugegraph.computer.core.network.message.Message)1 NettyTransportClient (com.baidu.hugegraph.computer.core.network.netty.NettyTransportClient)1 ClientSession (com.baidu.hugegraph.computer.core.network.session.ClientSession)1 MessageRecvManager (com.baidu.hugegraph.computer.core.receiver.MessageRecvManager)1 RecvSortManager (com.baidu.hugegraph.computer.core.sort.sorting.RecvSortManager)1