Search in sources :

Example 6 with InstanceControlMsg

use of com.twitter.heron.instance.InstanceControlMsg in project heron by twitter.

the class ConnectTest method before.

@Before
public void before() throws Exception {
    UnitTestHelper.addSystemConfigToSingleton();
    nioLooper = new NIOLooper();
    slaveLooper = new SlaveLooper();
    inStreamQueue = new Communicator<HeronTuples.HeronTupleSet>(nioLooper, slaveLooper);
    inStreamQueue.init(Constants.QUEUE_BUFFER_SIZE, Constants.QUEUE_BUFFER_SIZE, 0.5);
    outStreamQueue = new Communicator<HeronTuples.HeronTupleSet>(slaveLooper, nioLooper);
    outStreamQueue.init(Constants.QUEUE_BUFFER_SIZE, Constants.QUEUE_BUFFER_SIZE, 0.5);
    inControlQueue = new Communicator<InstanceControlMsg>(nioLooper, slaveLooper);
    gatewayMetrics = new GatewayMetrics();
    threadsPool = Executors.newSingleThreadExecutor();
    // Get an available port
    serverPort = SysUtils.getFreePort();
}
Also used : InstanceControlMsg(com.twitter.heron.instance.InstanceControlMsg) SlaveLooper(com.twitter.heron.common.basics.SlaveLooper) NIOLooper(com.twitter.heron.common.basics.NIOLooper) GatewayMetrics(com.twitter.heron.metrics.GatewayMetrics) Before(org.junit.Before)

Example 7 with InstanceControlMsg

use of com.twitter.heron.instance.InstanceControlMsg in project heron by twitter.

the class HandleReadTest method before.

@Before
public void before() throws Exception {
    UnitTestHelper.addSystemConfigToSingleton();
    nioLooper = new NIOLooper();
    slaveLooper = new SlaveLooper();
    inStreamQueue = new Communicator<HeronTuples.HeronTupleSet>(nioLooper, slaveLooper);
    inStreamQueue.init(Constants.QUEUE_BUFFER_SIZE, Constants.QUEUE_BUFFER_SIZE, 0.5);
    outStreamQueue = new Communicator<HeronTuples.HeronTupleSet>(slaveLooper, nioLooper);
    outStreamQueue.init(Constants.QUEUE_BUFFER_SIZE, Constants.QUEUE_BUFFER_SIZE, 0.5);
    inControlQueue = new Communicator<InstanceControlMsg>(nioLooper, slaveLooper);
    gatewayMetrics = new GatewayMetrics();
    threadsPool = Executors.newSingleThreadExecutor();
    // Get an available port
    serverPort = SysUtils.getFreePort();
}
Also used : InstanceControlMsg(com.twitter.heron.instance.InstanceControlMsg) SlaveLooper(com.twitter.heron.common.basics.SlaveLooper) NIOLooper(com.twitter.heron.common.basics.NIOLooper) GatewayMetrics(com.twitter.heron.metrics.GatewayMetrics) Before(org.junit.Before)

Example 8 with InstanceControlMsg

use of com.twitter.heron.instance.InstanceControlMsg in project heron by twitter.

the class StreamManagerClient method handleAssignmentMessage.

private void handleAssignmentMessage(PhysicalPlans.PhysicalPlan pplan) {
    LOG.fine("Physical Plan: " + pplan);
    PhysicalPlanHelper newHelper = new PhysicalPlanHelper(pplan, instance.getInstanceId());
    if (helper != null && (!helper.getMyComponent().equals(newHelper.getMyComponent()) || helper.getMyTaskId() != newHelper.getMyTaskId())) {
        // we will get the new assignment
        throw new RuntimeException("Our Assignment has changed. We will die to pick it");
    }
    if (helper == null) {
        LOG.info("We received a new Physical Plan.");
    } else {
        LOG.info("We received a new Physical Plan with same assignment. Should be state changes.");
        LOG.info(String.format("Old state: %s; new sate: %s.", helper.getTopologyState(), newHelper.getTopologyState()));
    }
    helper = newHelper;
    LOG.info("Push to Slave");
    InstanceControlMsg instanceControlMsg = InstanceControlMsg.newBuilder().setNewPhysicalPlanHelper(helper).build();
    inControlQueue.offer(instanceControlMsg);
}
Also used : PhysicalPlanHelper(com.twitter.heron.common.utils.misc.PhysicalPlanHelper) InstanceControlMsg(com.twitter.heron.instance.InstanceControlMsg)

Example 9 with InstanceControlMsg

use of com.twitter.heron.instance.InstanceControlMsg in project heron by twitter.

the class BoltInstanceTest method before.

@Before
public void before() throws Exception {
    UnitTestHelper.addSystemConfigToSingleton();
    ackCount = new AtomicInteger(0);
    failCount = new AtomicInteger(0);
    tupleExecutedCount = new AtomicInteger(0);
    receivedStrings = new StringBuilder();
    testLooper = new SlaveLooper();
    slaveLooper = new SlaveLooper();
    outStreamQueue = new Communicator<HeronTuples.HeronTupleSet>(slaveLooper, testLooper);
    outStreamQueue.init(Constants.QUEUE_BUFFER_SIZE, Constants.QUEUE_BUFFER_SIZE, 0.5);
    inStreamQueue = new Communicator<HeronTuples.HeronTupleSet>(testLooper, slaveLooper);
    inStreamQueue.init(Constants.QUEUE_BUFFER_SIZE, Constants.QUEUE_BUFFER_SIZE, 0.5);
    inControlQueue = new Communicator<InstanceControlMsg>(testLooper, slaveLooper);
    slaveMetricsOut = new Communicator<Metrics.MetricPublisherPublishMessage>(slaveLooper, testLooper);
    slaveMetricsOut.init(Constants.QUEUE_BUFFER_SIZE, Constants.QUEUE_BUFFER_SIZE, 0.5);
    slave = new Slave(slaveLooper, inStreamQueue, outStreamQueue, inControlQueue, slaveMetricsOut);
    threadsPool = Executors.newSingleThreadExecutor();
    threadsPool.execute(slave);
}
Also used : Slave(com.twitter.heron.instance.Slave) InstanceControlMsg(com.twitter.heron.instance.InstanceControlMsg) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) SlaveLooper(com.twitter.heron.common.basics.SlaveLooper) Before(org.junit.Before)

Example 10 with InstanceControlMsg

use of com.twitter.heron.instance.InstanceControlMsg in project heron by twitter.

the class HandleWriteTest method testHandleWrite.

/**
   * Test write into network
   */
@Test
public void testHandleWrite() throws Exception {
    ServerSocketChannel serverSocketChannel = ServerSocketChannel.open();
    serverSocketChannel.socket().bind(new InetSocketAddress(HOST, serverPort));
    SocketChannel socketChannel = null;
    try {
        runStreamManagerClient();
        socketChannel = serverSocketChannel.accept();
        configure(socketChannel);
        socketChannel.configureBlocking(false);
        close(serverSocketChannel);
        // Receive request
        IncomingPacket incomingPacket = new IncomingPacket();
        while (incomingPacket.readFromChannel(socketChannel) != 0) {
            // 1ms sleep to mitigate busy looping
            SysUtils.sleep(1);
        }
        // Send back response
        // Though we do not use typeName, we need to unpack it first,
        // since the order is required
        String typeName = incomingPacket.unpackString();
        REQID rid = incomingPacket.unpackREQID();
        OutgoingPacket outgoingPacket = new OutgoingPacket(rid, UnitTestHelper.getRegisterInstanceResponse());
        outgoingPacket.writeToChannel(socketChannel);
        for (int i = 0; i < Constants.RETRY_TIMES; i++) {
            InstanceControlMsg instanceControlMsg = inControlQueue.poll();
            if (instanceControlMsg != null) {
                break;
            } else {
                SysUtils.sleep(Constants.RETRY_INTERVAL_MS);
            }
        }
        for (int i = 0; i < 10; i++) {
            // We randomly choose some messages writing to stream mgr
            streamManagerClient.sendMessage(UnitTestHelper.getRegisterInstanceResponse());
        }
        for (int i = 0; i < 10; i++) {
            incomingPacket = new IncomingPacket();
            while (incomingPacket.readFromChannel(socketChannel) != 0) {
                // 1ms sleep to mitigate busy looping
                SysUtils.sleep(1);
            }
            typeName = incomingPacket.unpackString();
            rid = incomingPacket.unpackREQID();
            StreamManager.RegisterInstanceResponse.Builder builder = StreamManager.RegisterInstanceResponse.newBuilder();
            incomingPacket.unpackMessage(builder);
            StreamManager.RegisterInstanceResponse response = builder.build();
            Assert.assertNotNull(response);
            Assert.assertTrue(response.isInitialized());
            Assert.assertEquals(Common.StatusCode.OK, response.getStatus().getStatus());
            Assert.assertEquals(1, response.getPplan().getStmgrsCount());
            Assert.assertEquals(2, response.getPplan().getInstancesCount());
            Assert.assertEquals(1, response.getPplan().getTopology().getBoltsCount());
            Assert.assertEquals(1, response.getPplan().getTopology().getSpoutsCount());
            Assert.assertEquals(TopologyAPI.TopologyState.RUNNING, response.getPplan().getTopology().getState());
        }
        nioLooper.exitLoop();
    } catch (ClosedChannelException ignored) {
    } finally {
        close(socketChannel);
    }
}
Also used : SocketChannel(java.nio.channels.SocketChannel) ServerSocketChannel(java.nio.channels.ServerSocketChannel) ClosedChannelException(java.nio.channels.ClosedChannelException) IncomingPacket(com.twitter.heron.common.network.IncomingPacket) InstanceControlMsg(com.twitter.heron.instance.InstanceControlMsg) InetSocketAddress(java.net.InetSocketAddress) StreamManager(com.twitter.heron.proto.stmgr.StreamManager) REQID(com.twitter.heron.common.network.REQID) ServerSocketChannel(java.nio.channels.ServerSocketChannel) OutgoingPacket(com.twitter.heron.common.network.OutgoingPacket) Test(org.junit.Test)

Aggregations

InstanceControlMsg (com.twitter.heron.instance.InstanceControlMsg)19 Test (org.junit.Test)11 PhysicalPlanHelper (com.twitter.heron.common.utils.misc.PhysicalPlanHelper)10 SlaveLooper (com.twitter.heron.common.basics.SlaveLooper)7 Before (org.junit.Before)7 HeronTuples (com.twitter.heron.proto.system.HeronTuples)5 ByteString (com.google.protobuf.ByteString)4 Slave (com.twitter.heron.instance.Slave)4 NIOLooper (com.twitter.heron.common.basics.NIOLooper)3 IncomingPacket (com.twitter.heron.common.network.IncomingPacket)3 OutgoingPacket (com.twitter.heron.common.network.OutgoingPacket)3 REQID (com.twitter.heron.common.network.REQID)3 GatewayMetrics (com.twitter.heron.metrics.GatewayMetrics)3 InetSocketAddress (java.net.InetSocketAddress)3 ClosedChannelException (java.nio.channels.ClosedChannelException)3 ServerSocketChannel (java.nio.channels.ServerSocketChannel)3 SocketChannel (java.nio.channels.SocketChannel)3 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)3 StreamManager (com.twitter.heron.proto.stmgr.StreamManager)1 Metrics (com.twitter.heron.proto.system.Metrics)1