Package org.apache.s4.comm.zk

Examples of org.apache.s4.comm.zk.ZkTaskSetup


        List<Cluster> clusterStatus = new ArrayList<Cluster>();
        List<Stream> streamStatus = new ArrayList<Stream>();

        try {
            ZkClient zkClient = new ZkClient(statusArgs.zkConnectionString, statusArgs.timeout);
            zkClient.setZkSerializer(new ZNRecordSerializer());

            List<String> clusters = statusArgs.clusters;
            if (clusters == null) {
                // Load all subclusters
                clusters = zkClient.getChildren("/s4/clusters");
View Full Code Here


    }

    @Override
    protected void onCreate() {
        if (zk == null) {
            zk = new ZkClient("localhost:" + 2181);
        }

    }
View Full Code Here

    }

    public static CountDownLatch getConsumerReadySignal(String streamName) {
        final CountDownLatch signalAppReady = new CountDownLatch(1);

        ZkClient zkClient = new ZkClient("localhost:" + CoreTestUtils.ZK_PORT);
        // TODO check a proper app state variable. This is hacky
        zkClient.subscribeChildChanges("/s4/streams/" + streamName + "/consumers", new IZkChildListener() {

            @Override
            public void handleChildChange(String parentPath, List<String> currentChilds) throws Exception {
                if (currentChilds.size() == 1) {
                    signalAppReady.countDown();
View Full Code Here

        List<Cluster> clusterStatus = new ArrayList<Cluster>();
        List<Stream> streamStatus = new ArrayList<Stream>();

        try {
            ZkClient zkClient = new ZkClient(statusArgs.zkConnectionString, statusArgs.timeout);
            zkClient.setZkSerializer(new ZNRecordSerializer());

            List<String> clusters = statusArgs.clusters;
            if (clusters == null) {
                // Load all subclusters
                clusters = zkClient.getChildren("/s4/clusters");
            }

            Set<String> app = null;
            Set<String> requiredAppCluster = new HashSet<String>();
            if (statusArgs.apps != null) {
                app = new HashSet<String>(statusArgs.apps);
            }

            for (String clusterName : clusters) {
                try {
                    if (zkClient.exists("/s4/clusters/" + clusterName)) {
                        Cluster cluster = new Cluster(clusterName, zkClient);
                        if (app == null || app.contains(cluster.app.name)) {
                            clusterStatus.add(cluster);
                            requiredAppCluster.add(cluster.clusterName);
                        }
                    } else {
                        logger.error("/s4/clusters/" + clusterName + " doesn't exist");
                    }
                } catch (Exception e) {
                    logger.error("Cannot get the status of " + clusterName, e);
                }
            }

            List<String> streams = statusArgs.streams;
            if (streams == null) {
                // Load all streams published
                streams = zkClient.getChildren("/s4/streams");
            }

            for (String streamName : streams) {
                try {
                    if (zkClient.exists("/s4/streams/" + streamName)) {
                        Stream stream = new Stream(streamName, zkClient);
                        if (app == null) {
                            streamStatus.add(stream);
                        } else {
                            for (String cluster : requiredAppCluster) {
View Full Code Here

        };
        // setup
        ZooKeeper zk = new ZooKeeper(address, 30000, watcher);
        String root = "/tasksetup_app_test";
        ZkTaskSetup zkSetup = new ZkTaskSetup(address, root, ClusterType.S4);
        Map<String, String> task1 = new HashMap<String, String>();
        task1.put("name", "task-1");

        Map<String, String> task2 = new HashMap<String, String>();
        task2.put("name", "task-2");
        String tasksListRoot = root + "/tasks";
        zkSetup.cleanUp();
        Stat exists = zk.exists(tasksListRoot, false);
        myassert(exists == null);
        Object[] data = new Object[] { task1, task2 };
        zkSetup.setUpTasks(data);

        // verify that tasks are created
        exists = zk.exists(tasksListRoot, false);
        myassert(exists != null);
        List<String> children = zk.getChildren(tasksListRoot, false);
        myassert(children.size() == data.length);
        boolean[] matched = new boolean[data.length];
        for (String child : children) {
            System.out.println(child);
            String childPath = tasksListRoot + "/" + child;
            Stat sTemp = zk.exists(childPath, false);
            byte[] tempData = zk.getData(tasksListRoot + "/" + child,
                                         false,
                                         sTemp);
            Map<String, Object> map = (Map<String, Object>) JSONUtil.getMapFromJson(new String(tempData));
            // check if it matches any of the data
            for (int i = 0; i < data.length; i++) {
                Map<String, Object> newData = (Map<String, Object>) data[i];
                if (!matched[i] && CommUtil.compareMaps(newData, map)) {
                    matched[i] = true;
                    break;
                }
            }
        }
        for (int i = 0; i < matched.length; i++) {
            myassert(matched[i]);
        }

        // try running again and make verify new node is not created
        Stat oldStat = zk.exists(tasksListRoot, false);
        System.out.println("oldStat=" + oldStat);
        zkSetup.setUpTasks(data);
        Stat newStat = zk.exists(tasksListRoot, false);
        System.out.println("newstat=" + newStat);
        myassert(oldStat.getMtime() == newStat.getMtime());

        // make change to task config and try running again and verify new
        // config is uploaded
        oldStat = zk.exists(tasksListRoot, false);
        System.out.println("oldStat=" + oldStat.getVersion());
        ((Map<String, String>) data[data.length - 1]).put("name", "changedname");
        zkSetup.setUpTasks(data);
        newStat = zk.exists(tasksListRoot, false);
        System.out.println("newstat=" + newStat.getVersion());
        System.out.println();
        myassert(oldStat.getMtime() != newStat.getMtime());

        // ensure version change is working
        zkSetup.setUpTasks("1.0.0.0", data);
    }
View Full Code Here

    private static void testZkTaskManager(String[] args) {
        System.out.println("Here");
        String address = args[0];
        address = "localhost:2181";
        String processName = args[1];
        ZkTaskSetup taskSetup = new ZkTaskSetup(address,
                                                      "/taskmanagerTest",
                                                      ClusterType.S4);
        taskSetup.cleanUp();
        taskSetup.setUpTasks("1.0.0.0", new String[] { "task0", "task1" });
        Object obj;
        System.out.println(processName + " Going to Wait for a task");
        HashMap<String, String> map = new HashMap<String, String>();
        ZkTaskManager taskManager = new ZkTaskManager(address,
                                                      "/taskmanagerTest",
View Full Code Here

    private static void testZkProcessMonitor(String[] args) {
        System.out.println("Hereh");
        String address = args[0];
        address = "localhost:2181";
        String processName = args[1];
        ZkTaskSetup zkTaskSetup = new ZkTaskSetup(address,
                                                        "/taskmanagerTest",
                                                        ClusterType.S4);
        zkTaskSetup.cleanUp();
        zkTaskSetup.setUpTasks("1.0.0.", new String[] { "task0", "task1" });
        Object obj;
        System.out.println(processName + " Going to Wait for a task");
        HashMap<String, String> map = new HashMap<String, String>();
        ZkTaskManager taskManager = new ZkTaskManager(address,
                                                      "/taskmanagerTest",
View Full Code Here

        }
    }

    private static void processCluster(boolean clean, String zkAddress, Cluster cluster, String version) {
        List<Map<String,String>> clusterInfo = ConfigUtils.readConfig(cluster, cluster.getName(), cluster.getType(), false);
        ZkTaskSetup zkSetup = new ZkTaskSetup(zkAddress, cluster.getName(), cluster.getType());
        if (clean) {
            zkSetup.cleanUp();
        }
       
        zkSetup.setUpTasks(version, clusterInfo.toArray());
    }
View Full Code Here

            } catch (IOException e) {
                throw new DeploymentFailedException("Cannot deploy application [" + appName + "] from URI ["
                        + uri.toString() + "] ", e);
            }
            // install locally
            App loaded = server.loadApp(localS4RFileCopy, appName);
            if (loaded != null) {
                logger.info("Successfully installed application {}", appName);
                // TODO sync with other nodes? (e.g. wait for other apps deployed before starting?
                server.startApp(loaded, appName, clusterName);
            } else {
View Full Code Here

    // }

    @Before
    public void prepareEmitter() throws IOException {
        injector = Guice.createInjector(new DefaultCommModule(Resources.getResource("default.s4.comm.properties")
                .openStream(), "cluster1"), new DefaultCoreModule(Resources.getResource("default.s4.core.properties")
                .openStream()));

        emitter = injector.getInstance(TCPEmitter.class);

    }
View Full Code Here

TOP

Related Classes of org.apache.s4.comm.zk.ZkTaskSetup

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.