From aeb66fa4096efb10fbad57fe35fe7c6c6268f02a Mon Sep 17 00:00:00 2001 From: Amnon Heiman Date: Wed, 8 Apr 2015 13:33:00 +0300 Subject: [PATCH] API: Adding the stroage service stub The storage service API will hold the equivelent information of the StorageServiceMBean. This adds the API with one stubed method the get local hostid. After the patch the storage_service doc will be available at: http://localhost:10000/api-doc/storage_service/ And the stubed local host id will be under: http://localhost:10000/storage_service/local_hostid and will return an empty string Signed-off-by: Amnon Heiman --- api/api-doc/storage_service.json | 29 +++++++++++++++++++++++++++++ api/api.cc | 9 ++++++++- api/storage_service.cc | 18 ++++++++++++++++++ api/storage_service.hh | 16 ++++++++++++++++ configure.py | 2 ++ 5 files changed, 73 insertions(+), 1 deletion(-) create mode 100644 api/api-doc/storage_service.json create mode 100644 api/storage_service.cc create mode 100644 api/storage_service.hh diff --git a/api/api-doc/storage_service.json b/api/api-doc/storage_service.json new file mode 100644 index 0000000000..e45d6de89c --- /dev/null +++ b/api/api-doc/storage_service.json @@ -0,0 +1,29 @@ +{ + "apiVersion":"0.0.1", + "swaggerVersion":"1.2", + "basePath":"{{Protocol}}://{{Host}}", + "resourcePath":"/storage_service", + "produces":[ + "application/json" + ], + "apis":[ + { + "path":"/storage_service/hostid/local", + "operations":[ + { + "method":"GET", + "summary":"Returns the local host id", + "type":"string", + "nickname":"local_hostid", + "produces":[ + "application/json" + ], + "parameters":[ + { + } + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/api/api.cc b/api/api.cc index d3495b487f..40f5022816 100644 --- a/api/api.cc +++ b/api/api.cc @@ -4,13 +4,20 @@ #include "api.hh" #include "http/api_docs.hh" +#include "storage_service.hh" namespace api { future<> set_server(http_context& ctx) { auto rb = std::make_shared < api_registry_builder > ("api/api-doc/"); - return ctx.http_server.set_routes(rb->set_api_doc()); + return ctx.http_server.set_routes(rb->set_api_doc()).then([&ctx, rb] { + ctx.http_server.set_routes(rb->register_function("storage_service", + "The storage service API")) + .then([&ctx] { + return set_storage_service(ctx); + }); + }); } } diff --git a/api/storage_service.cc b/api/storage_service.cc new file mode 100644 index 0000000000..86b6a26e1a --- /dev/null +++ b/api/storage_service.cc @@ -0,0 +1,18 @@ +/* + * Copyright 2015 Cloudius Systems + */ + +#include "storage_service.hh" +#include "api/api-doc/storage_service.json.hh" + +namespace api { + +future<> set_storage_service(http_context& ctx) { + return ctx.http_server.set_routes([] (routes& r) { + httpd::storage_service_json::local_hostid.set(r, [](const_req req) { + return ""; + }); + }); +} + +} diff --git a/api/storage_service.hh b/api/storage_service.hh new file mode 100644 index 0000000000..d17d679e27 --- /dev/null +++ b/api/storage_service.hh @@ -0,0 +1,16 @@ +/* + * Copyright 2015 Cloudius Systems + */ + +#ifndef API_STORAGE_SERVICE_HH_ +#define API_STORAGE_SERVICE_HH_ + +#include "api.hh" + +namespace api { + +future<> set_storage_service(http_context& ctx); + +} + +#endif /* API_APP_HH_ */ diff --git a/configure.py b/configure.py index 2f81052f23..8ed5bbb2a9 100755 --- a/configure.py +++ b/configure.py @@ -261,6 +261,8 @@ http = ['http/transformers.cc', ] api = ['api/api.cc', + 'api/api-doc/storage_service.json', + 'api/storage_service.cc', ] defines = [] libs = '-laio -lboost_program_options -lboost_system -lstdc++ -lm -lboost_unit_test_framework -lboost_thread -lcryptopp -lrt'