/// <summary>Startup: start ZK.</summary>
        /// <remarks>
        /// Startup: start ZK. It is only after this that
        /// the binding information is valid.
        /// </remarks>
        /// <exception cref="System.Exception"/>
        protected override void ServiceStart()
        {
            SetupSecurity();
            ZooKeeperServer zkServer = new ZooKeeperServer();
            FileTxnSnapLog  ftxn     = new FileTxnSnapLog(dataDir, dataDir);

            zkServer.SetTxnLogFactory(ftxn);
            zkServer.SetTickTime(tickTime);
            Log.Info("Starting Local Zookeeper service");
            factory = ServerCnxnFactory.CreateFactory();
            factory.Configure(GetAddress(port), -1);
            factory.Startup(zkServer);
            string connectString = GetConnectionString();

            Log.Info("In memory ZK started at {}\n", connectString);
            if (Log.IsDebugEnabled())
            {
                StringWriter sw = new StringWriter();
                PrintWriter  pw = new PrintWriter(sw);
                zkServer.DumpConf(pw);
                pw.Flush();
                Log.Debug(sw.ToString());
            }
            binding = new BindingInformation();
            binding.ensembleProvider = new FixedEnsembleProvider(connectString);
            binding.description      = GetName() + " reachable at \"" + connectString + "\"";
            AddDiagnostics(binding.description);
            // finally: set the binding information in the config
            GetConfig().Set(KeyRegistryZkQuorum, connectString);
        }
 /// <summary>
 /// When the service is stopped, it deletes the data directory
 /// and its contents
 /// </summary>
 /// <exception cref="System.Exception"/>
 protected override void ServiceStop()
 {
     if (factory != null)
     {
         factory.Shutdown();
         factory = null;
     }
     if (dataDir != null)
     {
         FileUtil.FullyDelete(dataDir);
     }
 }
Esempio n. 3
0
 public virtual void TearDown()
 {
     Log.Info("tearDown starting");
     TearDownAll();
     StopServer();
     portNumLockFile.Close();
     portNumFile.Delete();
     if (tmpDir != null)
     {
         Assert.True("delete " + tmpDir.ToString(), RecursiveDelete(tmpDir
                                                                    ));
     }
     // This has to be set to null when the same instance of this class is reused between test cases
     serverFactory = null;
 }
Esempio n. 4
0
        /// <exception cref="System.IO.IOException"/>
        /// <exception cref="System.Exception"/>
        internal static ServerCnxnFactory CreateNewServerInstance(FilePath dataDir, ServerCnxnFactory
                                                                  factory, string hostPort, int maxCnxns)
        {
            ZooKeeperServer zks  = new ZooKeeperServer(dataDir, dataDir, 3000);
            int             Port = GetPort(hostPort);

            if (factory == null)
            {
                factory = ServerCnxnFactory.CreateFactory(Port, maxCnxns);
            }
            factory.Startup(zks);
            Assert.True("waiting for server up", ClientBaseWithFixes.WaitForServerUp
                            ("127.0.0.1:" + Port, ConnectionTimeout));
            return(factory);
        }
Esempio n. 5
0
 internal static void ShutdownServerInstance(ServerCnxnFactory factory, string hostPort
                                             )
 {
     if (factory != null)
     {
         ZKDatabase zkDb;
         {
             ZooKeeperServer zs = GetServer(factory);
             zkDb = zs.GetZKDatabase();
         }
         factory.Shutdown();
         try
         {
             zkDb.Close();
         }
         catch (IOException ie)
         {
             Log.Warn("Error closing logs ", ie);
         }
         int Port = GetPort(hostPort);
         Assert.True("waiting for server down", ClientBaseWithFixes.WaitForServerDown
                         ("127.0.0.1:" + Port, ConnectionTimeout));
     }
 }
Esempio n. 6
0
        protected internal static ZooKeeperServer GetServer(ServerCnxnFactory fac)
        {
            ZooKeeperServer zs = ServerCnxnFactoryAccessor.GetZkServer(fac);

            return(zs);
        }
Esempio n. 7
0
 /// <exception cref="System.Exception"/>
 protected internal virtual void StopServer()
 {
     Log.Info("STOPPING server");
     ShutdownServerInstance(serverFactory, hostPort);
     serverFactory = null;
 }
Esempio n. 8
0
 /// <exception cref="System.Exception"/>
 protected internal virtual void StartServer()
 {
     Log.Info("STARTING server");
     serverFactory = CreateNewServerInstance(tmpDir, serverFactory, hostPort, maxCnxns
                                             );
 }