Search in sources :

Example 1 with PhysicalPlanHelper

use of com.twitter.heron.common.utils.misc.PhysicalPlanHelper in project heron by twitter.

the class SpoutInstanceTest method testDoImmediateAcks.

/**
   * Test with the acking immediately
   */
@Test
public void testDoImmediateAcks() throws Exception {
    physicalPlan = UnitTestHelper.getPhysicalPlan(false, -1);
    PhysicalPlanHelper physicalPlanHelper = new PhysicalPlanHelper(physicalPlan, SPOUT_INSTANCE_ID);
    InstanceControlMsg instanceControlMsg = InstanceControlMsg.newBuilder().setNewPhysicalPlanHelper(physicalPlanHelper).build();
    SingletonRegistry.INSTANCE.registerSingleton(Constants.ACK_COUNT, ackCount);
    inControlQueue.offer(instanceControlMsg);
    Runnable task = new Runnable() {

        @Override
        public void run() {
            while (outStreamQueue.size() != 0) {
                HeronTuples.HeronTupleSet set = outStreamQueue.poll();
                Assert.assertTrue(set.isInitialized());
                Assert.assertTrue(set.hasData());
                HeronTuples.HeronDataTupleSet dataTupleSet = set.getData();
                tupleReceived += dataTupleSet.getTuplesCount();
                heronDataTupleList.addAll(dataTupleSet.getTuplesList());
            }
            if (tupleReceived == 10) {
                // We fetch it from SingletonRegistry
                for (int i = 0; i < Constants.RETRY_TIMES; i++) {
                    if (ackCount.intValue() != 0) {
                        break;
                    }
                    SysUtils.sleep(Constants.RETRY_INTERVAL_MS);
                }
                // Wait the bolt's finishing
                SysUtils.sleep(Constants.TEST_WAIT_TIME_MS);
                Assert.assertEquals(10, ackCount.intValue());
                testLooper.exitLoop();
            }
        }
    };
    testLooper.addTasksOnWakeup(task);
    testLooper.loop();
}
Also used : PhysicalPlanHelper(com.twitter.heron.common.utils.misc.PhysicalPlanHelper) InstanceControlMsg(com.twitter.heron.instance.InstanceControlMsg) HeronTuples(com.twitter.heron.proto.system.HeronTuples) Test(org.junit.Test)

Example 2 with PhysicalPlanHelper

use of com.twitter.heron.common.utils.misc.PhysicalPlanHelper in project heron by twitter.

the class SpoutInstanceTest method testAckAndFail.

/**
   * We will receive tuples and then send back the corresponding ack&amp;fail tuples
   */
@Test
public void testAckAndFail() throws Exception {
    physicalPlan = UnitTestHelper.getPhysicalPlan(true, -1);
    PhysicalPlanHelper physicalPlanHelper = new PhysicalPlanHelper(physicalPlan, SPOUT_INSTANCE_ID);
    InstanceControlMsg instanceControlMsg = InstanceControlMsg.newBuilder().setNewPhysicalPlanHelper(physicalPlanHelper).build();
    SingletonRegistry.INSTANCE.registerSingleton(Constants.ACK_COUNT, ackCount);
    SingletonRegistry.INSTANCE.registerSingleton(Constants.FAIL_COUNT, failCount);
    inControlQueue.offer(instanceControlMsg);
    Runnable task = new Runnable() {

        @Override
        public void run() {
            while (outStreamQueue.size() != 0) {
                HeronTuples.HeronTupleSet set = outStreamQueue.poll();
                Assert.assertTrue(set.isInitialized());
                Assert.assertTrue(set.hasData());
                HeronTuples.HeronDataTupleSet dataTupleSet = set.getData();
                tupleReceived += dataTupleSet.getTuplesCount();
                heronDataTupleList.addAll(dataTupleSet.getTuplesList());
            }
            if (tupleReceived == 10) {
                constructAndSendAcks();
                // We fetch it from SingletonRegistry
                for (int i = 0; i < Constants.RETRY_TIMES; i++) {
                    if (ackCount.intValue() != 0 || failCount.intValue() != 0) {
                        break;
                    }
                    SysUtils.sleep(Constants.RETRY_INTERVAL_MS);
                }
                // Wait the bolt's finishing
                SysUtils.sleep(Constants.TEST_WAIT_TIME_MS);
                Assert.assertEquals(5, ackCount.intValue());
                Assert.assertEquals(5, failCount.intValue());
                testLooper.exitLoop();
            }
        }
    };
    testLooper.addTasksOnWakeup(task);
    testLooper.loop();
}
Also used : PhysicalPlanHelper(com.twitter.heron.common.utils.misc.PhysicalPlanHelper) InstanceControlMsg(com.twitter.heron.instance.InstanceControlMsg) HeronTuples(com.twitter.heron.proto.system.HeronTuples) Test(org.junit.Test)

Example 3 with PhysicalPlanHelper

use of com.twitter.heron.common.utils.misc.PhysicalPlanHelper in project heron by twitter.

the class ConnectTest method testStart.

/**
   * Test connection
   */
@Test
public void testStart() 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) {
                nioLooper.exitLoop();
                threadsPool.shutdownNow();
                PhysicalPlanHelper physicalPlanHelper = instanceControlMsg.getNewPhysicalPlanHelper();
                Assert.assertEquals("test-bolt", physicalPlanHelper.getMyComponent());
                Assert.assertEquals(InetAddress.getLocalHost().getHostName(), physicalPlanHelper.getMyHostname());
                Assert.assertEquals(0, physicalPlanHelper.getMyInstanceIndex());
                Assert.assertEquals(1, physicalPlanHelper.getMyTaskId());
                break;
            } else {
                SysUtils.sleep(Constants.RETRY_INTERVAL_MS);
            }
        }
    } 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) PhysicalPlanHelper(com.twitter.heron.common.utils.misc.PhysicalPlanHelper) InetSocketAddress(java.net.InetSocketAddress) REQID(com.twitter.heron.common.network.REQID) ServerSocketChannel(java.nio.channels.ServerSocketChannel) OutgoingPacket(com.twitter.heron.common.network.OutgoingPacket) Test(org.junit.Test)

Example 4 with PhysicalPlanHelper

use of com.twitter.heron.common.utils.misc.PhysicalPlanHelper in project heron by twitter.

the class Slave method handleControlMessage.

private void handleControlMessage() {
    Runnable handleControlMessageTask = new Runnable() {

        @Override
        public void run() {
            while (!inControlQueue.isEmpty()) {
                InstanceControlMsg instanceControlMsg = inControlQueue.poll();
                // Handle New Physical Plan
                if (instanceControlMsg.isNewPhysicalPlanHelper()) {
                    PhysicalPlanHelper newHelper = instanceControlMsg.getNewPhysicalPlanHelper();
                    // Bind the MetricsCollector with topologyContext
                    newHelper.setTopologyContext(metricsCollector);
                    if (helper == null) {
                        handleNewAssignment(newHelper);
                    } else {
                        instance.update(newHelper);
                        // Handle the state changing
                        if (!helper.getTopologyState().equals(newHelper.getTopologyState())) {
                            switch(newHelper.getTopologyState()) {
                                case RUNNING:
                                    if (!isInstanceStarted) {
                                        // Start the instance if it has not yet started
                                        startInstance();
                                    }
                                    instance.activate();
                                    break;
                                case PAUSED:
                                    instance.deactivate();
                                    break;
                                default:
                                    throw new RuntimeException("Unexpected TopologyState is updated for spout: " + newHelper.getTopologyState());
                            }
                        } else {
                            LOG.info("Topology state remains the same in Slave: " + helper.getTopologyState());
                        }
                    }
                    // update the PhysicalPlanHelper in Slave
                    helper = newHelper;
                }
            // TODO:- We might handle more control Message in future
            }
        }
    };
    slaveLooper.addTasksOnWakeup(handleControlMessageTask);
}
Also used : PhysicalPlanHelper(com.twitter.heron.common.utils.misc.PhysicalPlanHelper)

Example 5 with PhysicalPlanHelper

use of com.twitter.heron.common.utils.misc.PhysicalPlanHelper 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)

Aggregations

PhysicalPlanHelper (com.twitter.heron.common.utils.misc.PhysicalPlanHelper)22 InstanceControlMsg (com.twitter.heron.instance.InstanceControlMsg)14 Test (org.junit.Test)14 HeronTuples (com.twitter.heron.proto.system.HeronTuples)5 ByteString (com.google.protobuf.ByteString)4 PhysicalPlans (com.twitter.heron.proto.system.PhysicalPlans)3 OutgoingPacket (com.twitter.heron.common.network.OutgoingPacket)2 REQID (com.twitter.heron.common.network.REQID)2 MetricsCollector (com.twitter.heron.common.utils.metrics.MetricsCollector)2 InetSocketAddress (java.net.InetSocketAddress)2 ClosedChannelException (java.nio.channels.ClosedChannelException)2 ServerSocketChannel (java.nio.channels.ServerSocketChannel)2 SocketChannel (java.nio.channels.SocketChannel)2 Message (com.google.protobuf.Message)1 TopologyAPI (com.twitter.heron.api.generated.TopologyAPI)1 IncomingPacket (com.twitter.heron.common.network.IncomingPacket)1 Metrics (com.twitter.heron.proto.system.Metrics)1 PhysicalPlanUtilTest (com.twitter.heron.simulator.utils.PhysicalPlanUtilTest)1 TopologyManagerTest (com.twitter.heron.simulator.utils.TopologyManagerTest)1 HashSet (java.util.HashSet)1