Skip to content

Commit

Permalink
add add_bulk API
Browse files Browse the repository at this point in the history
  • Loading branch information
TkrUdagawa committed Dec 8, 2017
1 parent f1b3c72 commit 2cf96c3
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 9 deletions.
4 changes: 4 additions & 0 deletions jubatus/server/server/anomaly.idl
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ service anomaly {
#@random #@nolock #@pass
id_with_score add(0: datum row)

#- add points.
#@random #@nolock #@pass
list<string> add_bulk(0: list<datum> data)

#- update a point.
#@cht #@update #@pass
float update(0: string id, 1: datum row)
Expand Down
8 changes: 7 additions & 1 deletion jubatus/server/server/anomaly_client.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// This file is auto-generated from anomaly.idl(0.9.0-26-g051b301) with jenerator version 0.9.4-42-g70f7539/develop
// This file is auto-generated from anomaly.idl with jenerator version 0.9.4-42-g70f7539/remotes/origin/feature/1100
// *** DO NOT EDIT ***

#ifndef JUBATUS_SERVER_SERVER_ANOMALY_CLIENT_HPP_
Expand Down Expand Up @@ -31,6 +31,12 @@ class anomaly : public jubatus::client::common::client {
return f.get<id_with_score>();
}

std::vector<std::string> add_bulk(
const std::vector<jubatus::core::fv_converter::datum>& data) {
msgpack::rpc::future f = c_.call("add_bulk", name_, data);
return f.get<std::vector<std::string> >();
}

float update(const std::string& id,
const jubatus::core::fv_converter::datum& row) {
msgpack::rpc::future f = c_.call("update", name_, id, row);
Expand Down
12 changes: 11 additions & 1 deletion jubatus/server/server/anomaly_impl.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// This file is auto-generated from anomaly.idl(0.9.0-26-g051b301) with jenerator version 0.9.4-42-g70f7539/develop
// This file is auto-generated from anomaly.idl with jenerator version 0.9.4-42-g70f7539/remotes/origin/feature/1100
// *** DO NOT EDIT ***

#include <map>
Expand All @@ -25,6 +25,10 @@ class anomaly_impl : public jubatus::server::common::mprpc::rpc_server {
rpc_server::add<id_with_score(std::string,
jubatus::core::fv_converter::datum)>("add", jubatus::util::lang::bind(
&anomaly_impl::add, this, jubatus::util::lang::_2));
rpc_server::add<std::vector<std::string>(std::string,
std::vector<jubatus::core::fv_converter::datum>)>("add_bulk",
jubatus::util::lang::bind(&anomaly_impl::add_bulk, this,
jubatus::util::lang::_2));
rpc_server::add<float(std::string, std::string,
jubatus::core::fv_converter::datum)>("update",
jubatus::util::lang::bind(&anomaly_impl::update, this,
Expand Down Expand Up @@ -64,6 +68,12 @@ class anomaly_impl : public jubatus::server::common::mprpc::rpc_server {
return get_p()->add(row);
}

std::vector<std::string> add_bulk(
const std::vector<jubatus::core::fv_converter::datum>& data) {
NOLOCK_(p_);
return get_p()->add_bulk(data);
}

float update(const std::string& id,
const jubatus::core::fv_converter::datum& row) {
JWLOCK_(p_);
Expand Down
4 changes: 3 additions & 1 deletion jubatus/server/server/anomaly_proxy.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// This file is auto-generated from anomaly.idl(0.9.0-26-g051b301) with jenerator version 0.9.4-42-g70f7539/develop
// This file is auto-generated from anomaly.idl with jenerator version 0.9.4-42-g70f7539/remotes/origin/feature/1100
// *** DO NOT EDIT ***

#include <map>
Expand All @@ -23,6 +23,8 @@ int run_proxy(int argc, char* argv[]) {
&jubatus::server::framework::all_and));
k.register_async_random<id_with_score, jubatus::core::fv_converter::datum>(
"add");
k.register_async_random<std::vector<std::string>,
std::vector<jubatus::core::fv_converter::datum> >("add_bulk");
k.register_async_cht<2, float, jubatus::core::fv_converter::datum>("update",
jubatus::util::lang::function<float(float, float)>(
&jubatus::server::framework::pass<float>));
Expand Down
25 changes: 20 additions & 5 deletions jubatus/server/server/anomaly_serv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ namespace server {
namespace {

struct anomaly_serv_config {
std::string method;
string method;
// TODO(oda): we should use optional<jsonconfig::config> instead of
// jsonconfig::config ?
core::common::jsonconfig::config parameter;
Expand Down Expand Up @@ -108,7 +108,7 @@ uint64_t anomaly_serv::user_data_version() const {
return 1; // should be inclemented when model data is modified
}

void anomaly_serv::set_config(const std::string& config) {
void anomaly_serv::set_config(const string& config) {
core::common::jsonconfig::config conf_root(lexical_cast<json>(config));
anomaly_serv_config conf =
core::common::jsonconfig::config_cast_check<anomaly_serv_config>(conf_root);
Expand All @@ -125,7 +125,7 @@ void anomaly_serv::set_config(const std::string& config) {
}
#endif

std::string my_id;
string my_id;
#ifdef HAVE_ZOOKEEPER_H
my_id = common::build_loc_str(argv().eth, argv().port);
#endif
Expand Down Expand Up @@ -174,6 +174,21 @@ id_with_score anomaly_serv::add(const datum& data) {
#endif
}

vector<string> anomaly_serv::add_bulk(
const vector<datum>& data) /* nolock!! */ {
check_set_config();
vector<pair<string, datum> > points;
vector<datum>::const_iterator iter = data.begin();
for (; iter < data.end(); ++iter) {
uint64_t id = idgen_->generate();
string id_str = lexical_cast<string>(id);
points.push_back(make_pair(id_str, *iter));
}
jubatus::util::concurrent::scoped_wlock lk(rw_mutex());
event_model_updated();
return anomaly_->add_bulk(points);
}

id_with_score anomaly_serv::add_zk(const string&id_str, const datum& d) {
vector<pair<string, int> > nodes;
float score = 0;
Expand Down Expand Up @@ -295,15 +310,15 @@ float anomaly_serv::selective_update(
}
}

bool anomaly_serv::load(const std::string& id) {
bool anomaly_serv::load(const string& id) {
if (server_base::load(id)) {
reset_id_generator();
return true;
}
return false;
}

void anomaly_serv::load_file(const std::string& path) {
void anomaly_serv::load_file(const string& path) {
server_base::load_file(path);
reset_id_generator();
}
Expand Down
3 changes: 3 additions & 0 deletions jubatus/server/server/anomaly_serv.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ class anomaly_serv : public framework::server_base {
bool clear_row(const std::string& id);

id_with_score add(const core::fv_converter::datum& d);
std::vector<std::string> add_bulk(
const std::vector<jubatus::core::fv_converter::datum>& data) /* nolock!! */;

float update(const std::string& id, const core::fv_converter::datum& d);
float overwrite(const std::string& id, const core::fv_converter::datum& d);

Expand Down
2 changes: 1 addition & 1 deletion jubatus/server/server/anomaly_types.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// This file is auto-generated from anomaly.idl(0.9.0-26-g051b301) with jenerator version 0.9.4-42-g70f7539/develop
// This file is auto-generated from anomaly.idl with jenerator version 0.9.4-42-g70f7539/remotes/origin/feature/1100
// *** DO NOT EDIT ***

#ifndef JUBATUS_SERVER_SERVER_ANOMALY_TYPES_HPP_
Expand Down

0 comments on commit 2cf96c3

Please sign in to comment.