Skip to content

Commit

Permalink
add support for server_info command
Browse files Browse the repository at this point in the history
  • Loading branch information
argv0 committed Jul 26, 2011
1 parent 70489c2 commit 49a3941
Show file tree
Hide file tree
Showing 9 changed files with 67 additions and 4 deletions.
1 change: 1 addition & 0 deletions Makefile.am
Expand Up @@ -28,6 +28,7 @@ nobase_include_HEADERS = riak_client/cxx/riak_client.hpp \
riak_client/cxx/basic/bucket_properties.hpp \
riak_client/cxx/basic/riak_result.hpp \
riak_client/cxx/basic/response.hpp \
riak_client/cxx/basic/server_info.hpp \
riak_client/cxx/basic/store_params.hpp \
riak_client/cxx/client.hpp \
riak_client/cxx/client/client.hpp \
Expand Down
1 change: 1 addition & 0 deletions Makefile.in
Expand Up @@ -288,6 +288,7 @@ nobase_include_HEADERS = riak_client/cxx/riak_client.hpp \
riak_client/cxx/basic/bucket_properties.hpp \
riak_client/cxx/basic/riak_result.hpp \
riak_client/cxx/basic/response.hpp \
riak_client/cxx/basic/server_info.hpp \
riak_client/cxx/basic/store_params.hpp \
riak_client/cxx/client.hpp \
riak_client/cxx/client/client.hpp \
Expand Down
1 change: 1 addition & 0 deletions riak_client/cxx/basic.hpp
Expand Up @@ -23,6 +23,7 @@
#include <riak_client/cxx/basic/riak_result.hpp>
#include <riak_client/cxx/basic/quorum.hpp>
#include <riak_client/cxx/basic/response.hpp>
#include <riak_client/cxx/basic/server_info.hpp>
#include <riak_client/cxx/basic/store_params.hpp>

#endif // include guard
2 changes: 2 additions & 0 deletions riak_client/cxx/basic/basic_client.hpp
Expand Up @@ -21,6 +21,7 @@
#include <riak_client/cxx/basic/riak_result.hpp>
#include <riak_client/cxx/basic/response.hpp>
#include <riak_client/cxx/basic/bucket_properties.hpp>
#include <riak_client/cxx/basic/server_info.hpp>
#include <riak_client/cxx/basic/store_params.hpp>
#include <riak_client/cxx/object.hpp>
#include <cstddef>
Expand All @@ -34,6 +35,7 @@ class RIAKC_API basic_client
{
public:
virtual response<bool> ping() = 0;
virtual response<server_info> get_server_info() = 0;
virtual response<riak_result> fetch(const std::string& bucket,
const std::string& key, int r, int pr) =0;
virtual response<bool> del(const std::string& bucket,
Expand Down
42 changes: 42 additions & 0 deletions riak_client/cxx/basic/server_info.hpp
@@ -0,0 +1,42 @@
/*
Copyright 2011 Basho Technologies, Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

#ifndef RIAKCXX_SERVER_INFO_HPP_
#define RIAKCXX_SERVER_INFO_HPP_

#include <riak_client/cxx/riak_client_fwd.hpp>

namespace riak {

class RIAKC_API server_info
{
public: // constructors
explicit server_info() { }
server_info(const std::string& node, const std::string& version)
: node_(node), version_(version) { }
public:
const std::string& node() const { return node_; }
const std::string& version() const { return version_; }
public:
std::string node_;
std::string version_;
};

} // ::riak

#endif // include guard


11 changes: 11 additions & 0 deletions src/cxx/pbc_client.cpp
Expand Up @@ -135,6 +135,17 @@ pbc_client::ping()
return true;
}

response<server_info>
pbc_client::get_server_info()
{
ops::get_server_info operation;
riak_error error = execute(connection_, operation);
if (error) return error;
server_info s(operation.response().node(),
operation.response().server_version());
return s;
}

response<bool>
pbc_client::del(const string& bucket, const string& key, int dw)
{
Expand Down
2 changes: 1 addition & 1 deletion src/cxx/pbc_client.hpp
Expand Up @@ -31,7 +31,7 @@ class pbc_client : public riak::basic_client
virtual ~pbc_client();
public:
response<bool> ping();

response<server_info> get_server_info();
response<bool> del(const std::string& bucket, const std::string& key,
int dw);
response<bool> set_bucket(const std::string& bucket,
Expand Down
4 changes: 4 additions & 0 deletions src/cxx/pbc_operations.hpp
Expand Up @@ -63,6 +63,9 @@ typedef pbc_message<GET_RESP, RpbGetResp> get_resp;
typedef pbc_message<SET_CLIENT_ID, RpbSetClientIdReq> set_client_id_req;
typedef pbc_message<SET_CLIENT_ID_RESP> set_client_id_resp;

typedef pbc_message<GET_SERVER_INFO> get_server_info_req;
typedef pbc_message<GET_SERVER_INFO_RESP, RpbGetServerInfoResp> get_server_info_resp;

typedef pbc_message<LIST_BUCKETS> list_buckets_req;
typedef pbc_message<LIST_BUCKETS_RESP, RpbListBucketsResp> list_buckets_resp;

Expand All @@ -77,6 +80,7 @@ typedef pbc_message<SET_BUCKET_RESP> set_bucket_resp;

namespace ops {
typedef operation<ping_req, ping_resp> ping;
typedef operation<get_server_info_req, get_server_info_resp> get_server_info;
typedef operation<del_req, del_resp> del;
typedef operation<put_req, put_resp> put;
typedef operation<get_client_id_req, get_client_id_resp> get_client_id;
Expand Down
7 changes: 4 additions & 3 deletions test/test_basic.cpp
Expand Up @@ -34,6 +34,7 @@ bool test_pbc_client()
assert(c->ping());
c->client_id(42);
assert(c->client_id() == 42);
riak::server_info info = c->get_server_info();
return true;
}

Expand Down Expand Up @@ -76,7 +77,7 @@ bool test_set_bucket()
riak::client_ptr c = riak::new_client("127.0.0.1", "8087");
riak::bucket_properties properties;
properties.allow_mult(true);
properties.n_val(669);
properties.n_val(3);
return c->set_bucket(TEST_BUCKET, properties);
}

Expand All @@ -86,7 +87,7 @@ bool test_fetch_bucket()
riak::client_ptr c = riak::new_client("127.0.0.1", "8087");
riak::bucket_properties result = c->fetch_bucket(TEST_BUCKET);
assert(result.allow_mult() == true);
assert(result.n_val() == 669);
assert(result.n_val() == 3);
return true;

}
Expand Down Expand Up @@ -147,7 +148,7 @@ bool test_client()

int main(int argc, char *argv[]) {
if (
// test_client() &&
// test_client() &&
test_pbc_client() &&
test_set_bucket() &&
test_fetch_bucket() &&
Expand Down

0 comments on commit 49a3941

Please sign in to comment.