Exemplo n.º 1
0
void clustering_serv::set_config(const std::string& config) {
  core::common::jsonconfig::config config_root(
      lexical_cast<jubatus::util::text::json::json>(config));
  clustering_serv_config conf =
      core::common::jsonconfig::config_cast_check<clustering_serv_config>(
          config_root);

  config_ = config;
  shared_ptr<core::fv_converter::datum_to_fv_converter> converter =
    core::fv_converter::make_fv_converter(conf.converter, &so_loader_);

  core::common::jsonconfig::config param;
  if (conf.parameter) {
    param = *conf.parameter;
  }

  const std::string name = get_server_identifier(argv());
  core::clustering::clustering_config cluster_conf =
      core::common::jsonconfig::config_cast_check<
          core::clustering::clustering_config>(param);
  clustering_.reset(new core::driver::clustering(
                        shared_ptr<core::clustering::clustering>(
                            new core::clustering::clustering(
                                name,
                                conf.method,
                                cluster_conf)),
                        converter));
  mixer_->set_driver(clustering_.get());

  LOG(INFO) << "config loaded: " << config;
}
Exemplo n.º 2
0
std::map<std::string, std::string> server_base::save(const std::string& id) {
  if (id == "") {
    throw JUBATUS_EXCEPTION(
        core::common::exception::runtime_error("empty id is not allowed"));
  }

  const std::string path = build_local_path(argv_, argv_.type, id);
  LOG(INFO) << "starting save to " << path;

  fp_holder fp(fopen(path.c_str(), "wb"));
  if (fp.get() == 0) {
    throw JUBATUS_EXCEPTION(
      core::common::exception::runtime_error("cannot open output file")
      << core::common::exception::error_file_name(path)
      << core::common::exception::error_errno(errno));
  }

  int fd = fileno(fp.get());
  if (flock(fd, LOCK_EX | LOCK_NB) < 0) {  // try exclusive lock
    throw
      JUBATUS_EXCEPTION(core::common::exception::runtime_error(
          "cannot get the lock of file; any RPC is saving to same file?")
        << core::common::exception::error_file_name(path)
        << core::common::exception::error_errno(errno));
  }

  try {
    framework::save_server(fp.get(), *this, id);
    if (fp.close()) {
      goto write_failure;
    }
  } catch (const std::ios_base::failure&) {
    goto write_failure;
  }
  // putting error handling code here is to prevent skipping variable
  // initialization. skipping variable declaration causes undefined behavior.
  if (0) {
   write_failure:
    int tmperrno = errno;
    if (remove(path.c_str()) < 0) {
      LOG(WARNING) << "failed to cleanup dirty model file: " << path << ": "
        << jubatus::util::system::syscall::get_error_msg(errno);
    }
    throw JUBATUS_EXCEPTION(
      core::common::exception::runtime_error("cannot write output file")
      << core::common::exception::error_file_name(path)
      << core::common::exception::error_errno(tmperrno));
  }

  update_saved_status(path);
  LOG(INFO) << "saved to " << path;

  std::map<std::string, std::string> ret;
  ret.insert(std::make_pair(get_server_identifier(argv_), path));
  return ret;
}
Exemplo n.º 3
0
std::map<std::string, std::map<std::string,std::string> > graph_serv::get_status()const
{
  std::map<std::string,std::string> ret0;

  g_.get_model()->get_status(ret0);

  std::map<std::string, std::map<std::string,std::string> > ret =
    jubatus_serv::get_status();

  ret[get_server_identifier()].insert(ret0.begin(), ret0.end());
  return ret;
}
Exemplo n.º 4
0
std::map<std::string, std::map<std::string,std::string> > regression_serv::get_status(){
  std::map<std::string,std::string> ret0;

  gresser_.get_model()->get_status(ret0); //FIXME
  ret0["storage"] = gresser_.get_model()->type();

  std::map<std::string, std::map<std::string,std::string> > ret =
    jubatus_serv::get_status();

  ret[get_server_identifier()].insert(ret0.begin(), ret0.end());
  return ret;
}
Exemplo n.º 5
0
std::map<std::string, std::map<std::string,std::string> > classifier_serv::get_status(){
  std::map<std::string,std::string> ret0;

  clsfer_.get_model()->get_status(ret0);
  ret0["storage"] = clsfer_.get_model()->type();

  std::map<std::string, std::map<std::string,std::string> > ret =
    jubatus_serv::get_status();

  ret[get_server_identifier()].insert(ret0.begin(), ret0.end());
  return ret;
}
Exemplo n.º 6
0
std::map<std::string, std::map<std::string, std::string> > recommender_serv::get_status()
{
  std::map<std::string, std::string> ret0;

  ret0["clear_row_cnt"] = pfi::lang::lexical_cast<std::string>(clear_row_cnt_);
  ret0["update_row_cnt"] = pfi::lang::lexical_cast<std::string>(update_row_cnt_);
  ret0["build_cnt"] = pfi::lang::lexical_cast<std::string>(build_cnt_);
  ret0["mix_cnt"] = pfi::lang::lexical_cast<std::string>(mix_cnt_);

  std::map<std::string, std::map<std::string,std::string> > ret = jubatus_serv::get_status();

  ret[get_server_identifier()].insert(ret0.begin(), ret0.end());
  return ret;
}
Exemplo n.º 7
0
  std::map<std::string, status_t> get_status() const {
    std::map<std::string, status_t> status;
    const server_argv& a = server_->argv();
    status_t& data = status[get_server_identifier(a)];

    const clock_time ct = get_clock_time();
    data["clock_time"] =
       jubatus::util::lang::lexical_cast<std::string>(ct.sec);
    data["start_time"] =
       jubatus::util::lang::lexical_cast<std::string>(start_time_.sec);
    data["uptime"] =
       jubatus::util::lang::lexical_cast<std::string>((ct - start_time_).sec);

    common::machine_status_t mt;
    common::get_machine_status(mt);
    data["VIRT"] =
        jubatus::util::lang::lexical_cast<std::string>(mt.vm_size);
    data["RSS"] =
        jubatus::util::lang::lexical_cast<std::string>(mt.vm_resident);
    data["SHR"] =
        jubatus::util::lang::lexical_cast<std::string>(mt.vm_share);

    data["timeout"] = jubatus::util::lang::lexical_cast<std::string>(a.timeout);
    data["threadnum"] =
        jubatus::util::lang::lexical_cast<std::string>(a.threadnum);
    data["datadir"] = a.datadir;
    data["is_standalone"] = jubatus::util::lang::lexical_cast<std::string>(
        a.is_standalone());
    data["VERSION"] = JUBATUS_VERSION;
    data["PROGNAME"] = a.program_name;
    data["type"] = a.type;
    data["logdir"] = a.logdir;
    data["log_config"] = a.log_config;

    std::string configpath;
    if (a.is_standalone()) {
      configpath = a.configpath;
    } else {
#ifdef HAVE_ZOOKEEPER_H
      // return zookeeper node name
      jubatus::server::common::build_config_path(configpath, a.type, a.name);
#endif
    }
    data["configpath"] = configpath;

    data["pid"] =
        jubatus::util::lang::lexical_cast<std::string>(getpid());
    data["user"] = jubatus::server::common::get_user_name();

    data["update_count"] = jubatus::util::lang::lexical_cast<std::string>(
        server_->update_count());

    data["last_saved"] =
        jubatus::util::lang::lexical_cast<std::string>
        (server_->last_saved_sec());
    data["last_saved_path"] = server_->last_saved_path();
    data["last_loaded"] =
        jubatus::util::lang::lexical_cast<std::string>
        (server_->last_loaded_sec());
    data["last_loaded_path"] = server_->last_loaded_path();

    server_->get_status(data);

    // distributed mode only
    if (!a.is_standalone()) {
      data["zk"] = a.z;
      data["name"] = a.name;
      data["interval_sec"] =
          jubatus::util::lang::lexical_cast<std::string>(a.interval_sec);
      data["interval_count"] = jubatus::util::lang::lexical_cast<std::string>(
          a.interval_count);
      data["zookeeper_timeout"] =
          jubatus::util::lang::lexical_cast<std::string>(a.zookeeper_timeout);
      data["interconnect_timeout"] =
          jubatus::util::lang::lexical_cast<std::string>
          (a.interconnect_timeout);
      data["connected_zookeeper"] = impl_.zk()->get_connected_host_and_port();
      data["use_cht"] = jubatus::util::lang::lexical_cast<std::string>(
          use_cht_);

      data["mixer"] = a.mixer;
      server_->get_mixer()->get_status(data);
    }

    return status;
  }