Пример #1
0
server_helper_impl::server_helper_impl(const server_argv& a) {
#ifdef HAVE_ZOOKEEPER_H
  if (!a.is_standalone()) {
    zk_.reset(common::create_lock_service("zk", a.z, a.timeout, make_logfile_name(a)));
  }
#endif
}
Пример #2
0
void server_helper_impl::prepare_for_start(const server_argv& a, bool use_cht) {
#ifdef HAVE_ZOOKEEPER_H
  if (!a.is_standalone()) {
    common::prepare_jubatus(*zk_, a.type, a.name);
    LOG(INFO) << "joining to the cluster " << a.name;
  }
#endif
}
Пример #3
0
  explicit server_helper(const server_argv& a, bool use_cht = false)
      : impl_(a),
        start_time_(get_clock_time()),
        use_cht_(use_cht) {
    impl_.prepare_for_start(a, use_cht);
    server_.reset(new Server(a, impl_.zk()));

    impl_.get_config_lock(a, 3);

    try {
      server_->set_config(get_conf(a));
    } catch (const core::common::jsonconfig::cast_check_error& e) {
      core::common::config_exception config_error;
      const core::common::jsonconfig::config_error_list& errors = e.errors();
      for (core::common::jsonconfig::config_error_list::const_iterator
          it = errors.begin(), end = errors.end(); it != end; ++it) {
        config_error << core::common::exception::error_message((*it)->what());
      }
      // send error message to caller
      throw JUBATUS_EXCEPTION(config_error);
    } catch (const jubatus::util::lang::parse_error& e) {
      // exit immediately on JSON parse error with exit-code 1
      std::string msg =
          std::string("syntax error in configuration: ") +
          (a.is_standalone() ?
           a.configpath :
           std::string("<zookeeper>")) + ":" +
          jubatus::util::lang::lexical_cast<std::string>(e.lineno()) + ":" +
          jubatus::util::lang::lexical_cast<std::string>(e.pos()) + " " +
          e.msg();

      LOG(ERROR) << msg;
      exit(1);
    }

    try {
      // standalone only, is it desirable?
      if (a.is_standalone() && !a.modelpath.empty()) {
        server_->load_file(a.modelpath);
      }
    } catch (const std::runtime_error& e) {
      exit(1);
    }
  }
Пример #4
0
void server_helper_impl::prepare_for_stop(const server_argv& a) {
  zk_config_lock_.reset();
  zk_.reset();
#ifdef HAVE_ZOOKEEPER_H
  if (!a.is_standalone()) {
    close_lock_service();
    LOG(INFO) << "leaving from the cluster " << a.name;
  }
#endif
}
Пример #5
0
server_helper_impl::server_helper_impl(const server_argv& a) {
  common::prepare_signal_handling();

#ifdef HAVE_ZOOKEEPER_H
  if (!a.is_standalone()) {
    zk_.reset(common::create_lock_service("zk",
                                          a.z, a.zookeeper_timeout,
                                          make_logfile_name(a)));
    zk_->push_cleanup(&jubatus::server::common::shutdown_server);
    register_lock_service(zk_);
  }
#endif
}
Пример #6
0
void server_helper_impl::prepare_for_run(const server_argv& a, bool use_cht) {
#ifdef HAVE_ZOOKEEPER_H
  if (!a.is_standalone()) {
    if (use_cht) {
      common::cht::setup_cht_dir(*zk_, a.type, a.name);
      common::cht ht(zk_, a.type, a.name);
      ht.register_node(a.eth, a.port);
    }

    register_actor(*zk_, a.type, a.name, a.eth, a.port);

    // if regestered actor was deleted, this server should finish
    watch_delete_actor(*zk_, a.type, a.name, a.eth, a.port, term_if_deleted);
    LOG(INFO) << "registered group membership";
  }
#endif
  if (a.daemon) {
    daemonize_process(a.logdir);
  }
}
Пример #7
0
void server_helper_impl::get_config_lock(const server_argv& a, int retry) {
#ifdef HAVE_ZOOKEEPER_H
  if (!a.is_standalone()) {
    string lock_path;
    common::build_config_lock_path(lock_path, a.type, a.name);
    zk_config_lock_ = jubatus::util::lang::shared_ptr<common::try_lockable>(
        new common::lock_service_mutex(*zk_, lock_path));

    while (!zk_config_lock_->try_rlock()) {
      if (retry == 0) {
        throw JUBATUS_EXCEPTION(
          core::common::exception::runtime_error(
            "any user is writing config?"));
      }
      retry--;
      sleep(1);
    }
  }
#endif
}
Пример #8
0
anomaly_serv::anomaly_serv(
    const server_argv& a,
    const jubatus::util::lang::shared_ptr<lock_service>& zk)
    : server_base(a),
      mixer_(create_mixer(a, zk, rw_mutex())) {
#ifdef HAVE_ZOOKEEPER_H
  if (a.is_standalone()) {
#endif
    idgen_.reset(new common::global_id_generator_standalone());
#ifdef HAVE_ZOOKEEPER_H
  } else {
    zk_ = zk;
    common::global_id_generator_zk* idgen_zk =
        new common::global_id_generator_zk();
    idgen_.reset(idgen_zk);

    string counter_path;
    common::build_actor_path(counter_path, a.type, a.name);
    idgen_zk->set_ls(zk_, counter_path);
  }
#endif
}
Пример #9
0
bool server_helper_impl::prepare_for_start(const server_argv& a, bool use_cht) {
#ifdef HAVE_ZOOKEEPER_H
  if (!a.is_standalone()) {
    ls = zk_;
    common::prepare_jubatus(*zk_, a.type, a.name);
    
    if (a.join) { // join to the existing cluster with -j option
      LOG(INFO) << "joining to the cluseter " << a.name;
      LOG(ERROR) << "join is not supported yet :(";
    }
    
    if (use_cht) {
      jubatus::common::cht::setup_cht_dir(*zk_, a.type, a.name);
      jubatus::common::cht ht(zk_, a.type, a.name);
      ht.register_node(a.eth, a.port);
    }
   
    // FIXME(rethink): is this sequence correct?
    register_actor(*zk_, a.type, a.name, a.eth, a.port);
    return true;
  }
#endif
  return false;
}