From 771f818ed0506971be66c985f15474dc22cf0395 Mon Sep 17 00:00:00 2001 From: Amnon Heiman Date: Thu, 2 Jul 2015 09:25:50 +0300 Subject: [PATCH 1/4] Adding the compaction_manager Swagger definition file This adds the Swagger definition file for the compaction_manager. It is based on the CompactionManagerMBean and contains the following command: get_compactions get_compaction_summary force_user_defined_compaction stop_compaction Signed-off-by: Amnon Heiman --- api/api-doc/compaction_manager.json | 126 ++++++++++++++++++++++++++++ configure.py | 1 + 2 files changed, 127 insertions(+) create mode 100644 api/api-doc/compaction_manager.json diff --git a/api/api-doc/compaction_manager.json b/api/api-doc/compaction_manager.json new file mode 100644 index 0000000000..42759733f2 --- /dev/null +++ b/api/api-doc/compaction_manager.json @@ -0,0 +1,126 @@ +{ + "apiVersion":"0.0.1", + "swaggerVersion":"1.2", + "basePath":"{{Protocol}}://{{Host}}", + "resourcePath":"/compaction_manager", + "produces":[ + "application/json" + ], + "apis":[ + { + "path":"/compaction_manager/compactions", + "operations":[ + { + "method":"GET", + "summary":"get List of running compactions", + "type":"array", + "items":{ + "type":"jsonmap" + }, + "nickname":"get_compactions", + "produces":[ + "application/json" + ], + "parameters":[ + ] + } + ] + }, + { + "path":"/compaction_manager/compaction_summary", + "operations":[ + { + "method":"GET", + "summary":"get compaction summary", + "type":"array", + "items":{ + "type":"string" + }, + "nickname":"get_compaction_summary", + "produces":[ + "application/json" + ], + "parameters":[ + ] + } + ] + }, + { + "path":"/compaction_manager/force_user_defined_compaction", + "operations":[ + { + "method":"POST", + "summary":"Triggers the compaction of user specified sstables. You can specify files from various keyspaces and columnfamilies. If you do so, user defined compaction is performed several times to the groups of files in the same keyspace/columnfamily. must contain keyspace and columnfamily name in path(for 2.1+) or file name itself.", + "type":"void", + "nickname":"force_user_defined_compaction", + "produces":[ + "application/json" + ], + "parameters":[ + { + "name":"data_files", + "description":"a comma separated list of sstable file to compact. must contain keyspace and columnfamily name in path(for 2.1+) or file name itself", + "required":true, + "allowMultiple":false, + "type":"string", + "paramType":"query" + } + ] + } + ] + }, + { + "path":"/compaction_manager/stop_compaction", + "operations":[ + { + "method":"POST", + "summary":"Stop all running compaction-like tasks having the provided type", + "type":"void", + "nickname":"stop_compaction", + "produces":[ + "application/json" + ], + "parameters":[ + { + "name":"type", + "description":"the type of compaction to stop. Can be one of: - COMPACTION - VALIDATION - CLEANUP - SCRUB - INDEX_BUILD", + "required":true, + "allowMultiple":false, + "type":"string", + "paramType":"string" + } + ] + } + ] + } + ], + "models":{ + "mapper":{ + "id":"mapper", + "description":"A key value mapping", + "properties":{ + "key":{ + "type":"string", + "description":"The key" + }, + "value":{ + "type":"string", + "description":"The value" + } + } + }, + "jsonmap":{ + "id":"jsonmap", + "description":"A json representation of a map as a list of key value", + "properties":{ + "value":{ + "type":"array", + "items":{ + "type":"mapper" + }, + "description":"A list of key, value mapping" + } + } + } + } +} \ No newline at end of file diff --git a/configure.py b/configure.py index 575ea2aee2..9f5ea1ce74 100755 --- a/configure.py +++ b/configure.py @@ -338,6 +338,7 @@ api = ['api/api.cc', 'api/cache_service.cc', 'api/api-doc/collectd.json', 'api/collectd.cc', + 'api/api-doc/compaction_manager.json', ] boost_test_lib = [ From 2d04668de58873b2ec281094c68e932640b5f13a Mon Sep 17 00:00:00 2001 From: Amnon Heiman Date: Thu, 2 Jul 2015 09:28:21 +0300 Subject: [PATCH 2/4] API: Adding the compaction_manager API stub implementation This adds a stub implementation for the compaction_manager API. The methods return the right types but with a stub value. After this patch the following url will be available: /compaction_manager/compactions /compaction_manager/compaction_summary /compaction_manager/force_user_defined_compaction /compaction_manager/stop_compaction Signed-off-by: Amnon Heiman --- api/api.cc | 4 ++++ api/compaction_manager.cc | 41 +++++++++++++++++++++++++++++++++++++++ api/compaction_manager.hh | 18 +++++++++++++++++ configure.py | 1 + 4 files changed, 64 insertions(+) create mode 100644 api/compaction_manager.cc create mode 100644 api/compaction_manager.hh diff --git a/api/api.cc b/api/api.cc index 9577d63372..c35be1c306 100644 --- a/api/api.cc +++ b/api/api.cc @@ -15,6 +15,7 @@ #include "storage_proxy.hh" #include "cache_service.hh" #include "collectd.hh" +#include "compaction_manager.hh" namespace api { future<> set_server(http_context& ctx) { @@ -55,6 +56,9 @@ future<> set_server(http_context& ctx) { rb->register_function(r, "collectd", "The collectd API"); set_collectd(ctx, r); + rb->register_function(r, "compaction_manager", + "The Compaction manager API"); + set_compaction_manager(ctx, r); }); } diff --git a/api/compaction_manager.cc b/api/compaction_manager.cc new file mode 100644 index 0000000000..2e77e5fcd7 --- /dev/null +++ b/api/compaction_manager.cc @@ -0,0 +1,41 @@ +/* + * Copyright 2015 Cloudius Systems + */ + +#include "compaction_manager.hh" +#include "api/api-doc/compaction_manager.json.hh" + +namespace api { + +using namespace scollectd; +namespace cm = httpd::compaction_manager_json; + + + +void set_compaction_manager(http_context& ctx, routes& r) { + cm::get_compactions.set(r, [] (std::unique_ptr req) { + //TBD + std::vector map; + return make_ready_future(map); + }); + + cm::get_compaction_summary.set(r, [] (std::unique_ptr req) { + //TBD + std::vector res; + return make_ready_future(res); + }); + + cm::force_user_defined_compaction.set(r, [] (std::unique_ptr req) { + //TBD + return make_ready_future(""); + }); + + cm::stop_compaction.set(r, [] (std::unique_ptr req) { + //TBD + return make_ready_future(""); + }); + +} + +} + diff --git a/api/compaction_manager.hh b/api/compaction_manager.hh new file mode 100644 index 0000000000..4bfdafbb19 --- /dev/null +++ b/api/compaction_manager.hh @@ -0,0 +1,18 @@ +/* + * Copyright 2015 Cloudius Systems + */ + +#ifndef API_COMPACTION_MANAGER_HH_ +#define API_COMPACTION_MANAGER_HH_ + +#include "api.hh" + +namespace api { + +void set_compaction_manager(http_context& ctx, routes& r); + +} + + + +#endif /* API_COMPACTION_MANAGER_HH_ */ diff --git a/configure.py b/configure.py index 9f5ea1ce74..b4235de891 100755 --- a/configure.py +++ b/configure.py @@ -339,6 +339,7 @@ api = ['api/api.cc', 'api/api-doc/collectd.json', 'api/collectd.cc', 'api/api-doc/compaction_manager.json', + 'api/compaction_manager.cc', ] boost_test_lib = [ From acb56ab133e9229ab4cebe9de84d296bb2efba52 Mon Sep 17 00:00:00 2001 From: Amnon Heiman Date: Thu, 2 Jul 2015 09:53:34 +0300 Subject: [PATCH 3/4] API: Adding the metrics to the compaction_manager This adds the metrics definition to the compaction_manager, it is based on the CompactionMetrics definition. The following command were added: get_pending_tasks get_completed_tasks get_total_compactions_completed get_bytes_compacted Signed-off-by: Amnon Heiman --- api/api-doc/compaction_manager.json | 62 ++++++++++++++++++++++++++++- 1 file changed, 61 insertions(+), 1 deletion(-) diff --git a/api/api-doc/compaction_manager.json b/api/api-doc/compaction_manager.json index 42759733f2..cf12776ebf 100644 --- a/api/api-doc/compaction_manager.json +++ b/api/api-doc/compaction_manager.json @@ -92,7 +92,67 @@ ] } ] - } + }, + { + "path": "/compaction_manager/metrics/pending_tasks", + "operations": [ + { + "method": "GET", + "summary": "Get pending tasks", + "type": "int", + "nickname": "get_pending_tasks", + "produces": [ + "application/json" + ], + "parameters": [] + } + ] + }, + { + "path": "/compaction_manager/metrics/completed_tasks", + "operations": [ + { + "method": "GET", + "summary": "Get completed tasks", + "type": "long", + "nickname": "get_completed_tasks", + "produces": [ + "application/json" + ], + "parameters": [] + } + ] + }, + { + "path": "/compaction_manager/metrics/total_compactions_completed", + "operations": [ + { + "method": "GET", + "summary": "Get total compactions completed", + "type": "long", + "nickname": "get_total_compactions_completed", + "produces": [ + "application/json" + ], + "parameters": [] + } + ] + }, + { + "path": "/compaction_manager/metrics/bytes_compacted", + "operations": [ + { + "method": "GET", + "summary": "Get bytes compacted", + "type": "int", + "nickname": "get_bytes_compacted", + "produces": [ + "application/json" + ], + "parameters": [] + } + ] + } ], "models":{ "mapper":{ From 477d06aa96ea1cc202b3e927b230eef275dcf37e Mon Sep 17 00:00:00 2001 From: Amnon Heiman Date: Thu, 2 Jul 2015 09:55:37 +0300 Subject: [PATCH 4/4] API: Adding the metrics stub to the compaction_manager This adds a stub implementation to the compaction_manager. The API would return the currect type but with stub values. After this patch the following url will be available: /compaction_manager/metrics/pending_tasks /compaction_manager/metrics/completed_tasks /compaction_manager/metrics/total_compactions_completed /compaction_manager/metrics/bytes_compacted Signed-off-by: Amnon Heiman --- api/compaction_manager.cc | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/api/compaction_manager.cc b/api/compaction_manager.cc index 2e77e5fcd7..1f198b0ceb 100644 --- a/api/compaction_manager.cc +++ b/api/compaction_manager.cc @@ -35,6 +35,28 @@ void set_compaction_manager(http_context& ctx, routes& r) { return make_ready_future(""); }); + cm::get_pending_tasks.set(r, [] (std::unique_ptr req) { + //TBD + return make_ready_future(0); + }); + + cm::get_completed_tasks.set(r, [] (std::unique_ptr req) { + //TBD + return make_ready_future(0); + }); + + cm::get_total_compactions_completed.set(r, [] (std::unique_ptr req) { + //TBD + return make_ready_future(0); + }); + + cm::get_bytes_compacted.set(r, [] (std::unique_ptr req) { + //TBD + return make_ready_future(0); + }); + + + } }