Package org.apache.s4.comm.topology

Examples of org.apache.s4.comm.topology.ZkClient


        bootstrap.setOption("readWriteFair", true);

        Channel c = bootstrap.bind(new InetSocketAddress(node.getPort()));
        channels.add(c);

        zkClient = new ZkClient("localhost:2181");
    }
View Full Code Here


    // generic array due to varargs generates a warning.
    @Override
    protected void onInit() {
        System.out.println("Initing CounterApp...");

        ZkClient zkClient = new ZkClient("localhost:2181");

        zkClient.setZkSerializer(new ZNRecordSerializer());
        ZNRecord record = new ZNRecord(Thread.currentThread().getContextClassLoader().getClass().getName());
        zkClient.create("/s4/classLoader", record, CreateMode.PERSISTENT);

        producerPE = createPE(ProducerPE.class, "producer");
        producerPE.setStreams(createOutputStream("tickStream"));

    }
View Full Code Here

    }

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

    }
View Full Code Here

    @Test
    public void testDeployment() throws Exception {
        TestAutomaticDeployment.createS4RFiles();

        ZkClient zkClient = new ZkClient("localhost:" + CommTestUtils.ZK_PORT);
        zkClient.setZkSerializer(new ZNRecordSerializer());

        TestAutomaticDeployment.checkNoAppAlreadyDeployed(zkClient);

        forkedNode = CoreTestUtils.forkS4Node(new String[] { "-cluster=cluster1" }, zkClient, 10, "cluster1");

        // deploy app

        Assert.assertFalse(zkClient.exists(AppConstants.INITIALIZED_ZNODE_1));

        File tmpDir = Files.createTempDir();

        File s4rToDeploy = new File(tmpDir, String.valueOf(System.currentTimeMillis()));

        Assert.assertTrue(ByteStreams.copy(Files.newInputStreamSupplier(new File(TestAutomaticDeployment.s4rDir,
                "simpleApp-0.0.0-SNAPSHOT.s4r")), Files.newOutputStreamSupplier(s4rToDeploy)) > 0);

        s4rHttpServer = new S4RHttpServer(8080, tmpDir);
        s4rHttpServer.start();

        Deploy.main(new String[] { "-s4r", "http://localhost:8080/s4/" + s4rToDeploy.getName(), "-c", "cluster1",
                "-appName", "toto", "-testMode" });

        TestAutomaticDeployment.assertDeployment("http://localhost:8080/s4/" + s4rToDeploy.getName(), zkClient, false);

        // check resource loading (we use a zkclient without custom serializer)
        ZkClient client2 = new ZkClient("localhost:" + CommTestUtils.ZK_PORT);
        Assert.assertEquals("Salut!", client2.readData("/resourceData"));

    }
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

                "localhost:2181");
        // recovering and making sure checkpointing still works

        // 1. instantiate remote S4 app

        forkedS4App = CoreTestUtils.forkS4Node(new String[] { "-c", "cluster1" }, new ZkClient("localhost:2181"), 10,
                "cluster1");

        Assert.assertTrue(signalConsumerReady.await(20, TimeUnit.SECONDS));

        CountDownLatch signalValue1Set = new CountDownLatch(1);
        CoreTestUtils.watchAndSignalCreation("/value1Set", signalValue1Set, zk);
        final CountDownLatch signalCheckpointed = new CountDownLatch(1);
        CoreTestUtils.watchAndSignalCreation("/checkpointed", signalCheckpointed, zk);

        Injector injector = CoreTestUtils.createInjectorWithNonFailFastZKClients();

        TCPEmitter emitter = injector.getInstance(TCPEmitter.class);

        Event event = new Event();
        event.put("command", String.class, "setValue1");
        event.put("value", String.class, "message1");
        event.setStreamId("inputStream");
        emitter.send(
                0,
                injector.getInstance(SerializerDeserializerFactory.class)
                        .createSerializerDeserializer(Thread.currentThread().getContextClassLoader()).serialize(event));

        if (manualCheckpointing) {
            insertCheckpointInstruction(injector, emitter);
        }

        Assert.assertTrue(signalCheckpointed.await(10, TimeUnit.SECONDS));

        forkedS4App.destroy();

        zk.delete("/data", -1);

        signalConsumerReady = getConsumerReadySignal("inputStream");
        DeploymentUtils.initAppConfig(
                new AppConfig.Builder()
                        .appClassName(S4AppWithManualCheckpointing.class.getName())
                        .namedParameters(
                                ImmutableMap.of("s4.checkpointing.filesystem.storageRootPath",
                                        CommTestUtils.DEFAULT_STORAGE_DIR.getAbsolutePath()))
                        .customModulesNames(ImmutableList.of(backendModuleClass.getName())).build(), "cluster1", true,
                "localhost:2181");

        forkedS4App = CoreTestUtils.forkS4Node(new String[] { "-c", "cluster1" }, new ZkClient("localhost:2181"), 10,
                "cluster1");

        Assert.assertTrue(signalConsumerReady.await(20, TimeUnit.SECONDS));
        // // trigger recovery by sending application event to set value 2
        CountDownLatch signalValue2Set = new CountDownLatch(1);
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

public class TaskSetup {

    private ZkClient zkclient;

    public TaskSetup(String zookeeperAddress) {
        zkclient = new ZkClient(zookeeperAddress);
        zkclient.setZkSerializer(new ZNRecordSerializer());
        zkclient.waitUntilConnected();
    }
View Full Code Here

     *            deletes previous configuration if it existed
     * @param zkString
     *            ZooKeeper connection string (connection to the cluster manager)
     */
    public static void initAppConfig(AppConfig appConfig, String clusterName, boolean deleteIfExists, String zkString) {
        ZkClient zk = new ZkClient(zkString);
        ZkSerializer serializer = new ZNRecordSerializer();
        zk.setZkSerializer(serializer);

        if (zk.exists("/s4/clusters/" + clusterName + "/app/s4App")) {
            if (deleteIfExists) {
                zk.delete("/s4/clusters/" + clusterName + "/app/s4App");
            }
        }
        try {
            zk.create("/s4/clusters/" + clusterName + "/app/s4App", appConfig.asZNRecord("app"), CreateMode.PERSISTENT);
        } catch (ZkNodeExistsException e) {
            if (!deleteIfExists) {
                logger.warn("Node {} already exists, will not overwrite", "/s4/clusters/" + clusterName + "/app/s4App");
            } else {
                throw new RuntimeException("Node should have been deleted");
            }
        }
        zk.close();
    }
View Full Code Here

    @Inject
    public ZkClientProvider(@Named("s4.cluster.zk_address") String zookeeperAddress,
            @Named("s4.cluster.zk_session_timeout") int sessionTimeout,
            @Named("s4.cluster.zk_connection_timeout") int connectionTimeout) {
        zkClient = new ZkClient(zookeeperAddress, sessionTimeout, connectionTimeout);
        ZkSerializer serializer = new ZNRecordSerializer();
        zkClient.setZkSerializer(serializer);
    }
View Full Code Here

TOP

Related Classes of org.apache.s4.comm.topology.ZkClient

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.