Commit 1f17cfcb authored by Tien-Thinh Nguyen's avatar Tien-Thinh Nguyen

add RetrieveCompleteSearch and RetrieveStoredSearch operations

parent 463ea1a6
......@@ -11,6 +11,7 @@
*/
#include "CompleteStoredSearchDocumentApiImpl.h"
#include "3gpp_29.500.h"
namespace oai {
namespace nrf {
......@@ -30,7 +31,33 @@ CompleteStoredSearchDocumentApiImpl::CompleteStoredSearchDocumentApiImpl(
void CompleteStoredSearchDocumentApiImpl::retrieve_complete_search(
const std::string &searchId, Pistache::Http::ResponseWriter &response) {
response.send(Pistache::Http::Code::Ok, "Do some magic\n");
Logger::nrf_sbi().info(
"Got a request to retrieve a complete search with ID %s",
searchId.c_str());
nlohmann::json sr_json = { };
nlohmann::json json_data = { };
json_data["nfInstances"] = nlohmann::json::array();
std::string content_type = "application/json";
std::shared_ptr<nrf_search_result> search_result = { };
m_nrf_app->find_search_result(searchId, search_result);
// convert the profile to Json
if (search_result != nullptr) {
search_result.get()->to_json(sr_json, 0); //with maximum number of NF profiles
json_data["nfInstances"] = sr_json["nfInstances"];
}
Logger::nrf_sbi().debug("Json data: %s", json_data.dump().c_str());
// content type
response.headers().add < Pistache::Http::Header::ContentType
> (Pistache::Http::Mime::MediaType(content_type));
response.send(Pistache::Http::Code(HTTP_STATUS_CODE_200_OK),
json_data.dump().c_str());
}
}
......
......@@ -102,13 +102,22 @@ void DiscNFInstancesStoreApiImpl::search_nf_instances(
Logger::nrf_sbi().debug("\tRequested NF instance id: %s",
requester_nf_instance_id.c_str());
}
uint32_t limit_nfs = 0;
if (!limit.isEmpty()) {
limit_nfs = limit.get();
Logger::nrf_sbi().debug("\tMaximum number of NFProfiles to be returned in the response: %d",
limit_nfs);
}
// TODO: other query parameters
int http_code = 0;
ProblemDetails problem_details = {};
std::string search_id = {};
m_nrf_app->handle_search_nf_instances(target_nf_type, requester_nf_type,
requester_nf_instance_id, search_id,
requester_nf_instance_id, limit_nfs, search_id,
http_code, 1, problem_details);
nlohmann::json json_data = {};
......@@ -122,14 +131,19 @@ void DiscNFInstancesStoreApiImpl::search_nf_instances(
content_type = "application/problem+json";
} else {
// convert the profile to Json
if (search_result != nullptr) search_result.get()->to_json(json_data);
if (search_result != nullptr) search_result.get()->to_json(json_data, limit_nfs);
}
//TODO: applying client restrictions in terms of the number of
//instances to be returned (i.e. "limit" or "max-
//payload-size" query parameters) .
Logger::nrf_sbi().debug("Json data: %s", json_data.dump().c_str());
// content type
response.headers().add<Pistache::Http::Header::ContentType>(
Pistache::Http::Mime::MediaType(content_type));
//TODO: add headers: Cache-Control, ETag
response.send(Pistache::Http::Code(http_code), json_data.dump().c_str());
}
......
......@@ -11,6 +11,7 @@
*/
#include "StoredSearchDocumentApiImpl.h"
#include "3gpp_29.500.h"
namespace oai {
namespace nrf {
......@@ -30,7 +31,34 @@ StoredSearchDocumentApiImpl::StoredSearchDocumentApiImpl(
void StoredSearchDocumentApiImpl::retrieve_stored_search(
const std::string &searchId, Pistache::Http::ResponseWriter &response) {
response.send(Pistache::Http::Code::Ok, "Do some magic\n");
Logger::nrf_sbi().info("Got a request to retrieve a stored search with ID %s",
searchId.c_str());
nlohmann::json sr_json = { };
nlohmann::json json_data = { };
json_data["nfInstances"] = nlohmann::json::array();
std::string content_type = "application/json";
std::shared_ptr<nrf_search_result> search_result = { };
m_nrf_app->find_search_result(searchId, search_result);
// convert the profile to Json
if (search_result != nullptr) {
search_result.get()->to_json(sr_json, search_result.get()->get_limit_nf_instances());
json_data["nfInstances"] = sr_json["nfInstances"];
}
Logger::nrf_sbi().debug("Json data: %s", json_data.dump().c_str());
// content type
response.headers().add < Pistache::Http::Header::ContentType
> (Pistache::Http::Mime::MediaType(content_type));
//TODO: add headers: Cache-Control, ETag
response.send(Pistache::Http::Code(HTTP_STATUS_CODE_200_OK),
json_data.dump().c_str());
}
}
......
This diff is collapsed.
......@@ -179,6 +179,7 @@ class nrf_app {
* @param [const std::string &] requester_nf_type: Requester NF type
* @param [const std::string &] requester_nf_instance_id: Requester NF
* instance id
* @param [uint32_t &] limit_nfs: Maximum number of NFProfiles to be returned in the response:
* @param [std::string &] search_id: Store search result ID
* @param [int &] http_code: HTTP code used to return to the consumer
* @param [const uint8_t] http_version: HTTP version
......@@ -188,7 +189,7 @@ class nrf_app {
void handle_search_nf_instances(const std::string &target_nf_type,
const std::string &requester_nf_type,
const std::string &requester_nf_instance_id,
std::string &search_id,
uint32_t &limit_nfs, std::string &search_id,
int &http_code, const uint8_t http_version,
ProblemDetails &problem_details);
......
......@@ -36,13 +36,19 @@
using namespace oai::nrf::app;
//------------------------------------------------------------------------------
void nrf_search_result::set_search_id(const std::string &id) { search_id = id; }
void nrf_search_result::set_search_id(const std::string &id) {
search_id = id;
}
//------------------------------------------------------------------------------
void nrf_search_result::get_search_id(std::string &id) const { id = search_id; }
void nrf_search_result::get_search_id(std::string &id) const {
id = search_id;
}
//------------------------------------------------------------------------------
std::string nrf_search_result::get_search_id() const { return search_id; }
std::string nrf_search_result::get_search_id() const {
return search_id;
}
//------------------------------------------------------------------------------
void nrf_search_result::set_nf_instances(
......@@ -63,8 +69,7 @@ void nrf_search_result::get_nf_instances(
}
//------------------------------------------------------------------------------
std::vector<std::shared_ptr<nrf_profile>> nrf_search_result::get_nf_instances()
const {
std::vector<std::shared_ptr<nrf_profile>> nrf_search_result::get_nf_instances() const {
return nf_instances;
}
......@@ -83,6 +88,30 @@ uint64_t nrf_search_result::get_validity_period() const {
return validity_period;
}
//------------------------------------------------------------------------------
void nrf_search_result::set_num_nf_inst_complete(const uint32_t &n) {
num_nf_inst_complete = n;
}
//------------------------------------------------------------------------------
void nrf_search_result::get_num_nf_inst_complete(uint32_t &n) const {
n = num_nf_inst_complete;
}
//------------------------------------------------------------------------------
void nrf_search_result::set_limit_nf_instances(const uint32_t &l) {
limit_nf_instances = l;
}
//------------------------------------------------------------------------------
void nrf_search_result::get_limit_nf_instances(uint32_t &l) const {
l = limit_nf_instances;
}
//------------------------------------------------------------------------------
uint32_t nrf_search_result::get_limit_nf_instances() const {
return limit_nf_instances;
}
//------------------------------------------------------------------------------
void nrf_search_result::display() {
Logger::nrf_app().debug("Search result information");
......@@ -97,15 +126,22 @@ void nrf_search_result::display() {
}
//------------------------------------------------------------------------------
void nrf_search_result::to_json(nlohmann::json &data) const {
data = {};
void nrf_search_result::to_json(nlohmann::json &data, const uint32_t &limit_nfs) const {
data = { };
data["validityPeriod"] = validity_period;
data["nfInstances"] = nlohmann::json::array();
uint32_t limit = limit_nfs>0?limit_nfs:nf_instances.size();
int i = 0;
for (auto instance : nf_instances) {
nlohmann::json instance_json = {};
if (i < limit) {
nlohmann::json instance_json = { };
instance.get()->to_json(instance_json);
data["nfInstances"].push_back(instance_json);
} else {
break;
}
i++;
}
data["searchId"] = search_id;
}
......@@ -41,16 +41,17 @@ using namespace std;
class nrf_search_result {
public:
nrf_search_result(){
};
nrf_search_result(nrf_search_result const &) = delete;
nrf_search_result() {
limit_nf_instances = 10; //default value, TODO: to be removed
}
;
nrf_search_result(nrf_search_result const&) = delete;
virtual ~nrf_search_result() {
Logger::nrf_app().debug("Delete NRF Subscription instance...");
}
void operator=(nrf_search_result const &) = delete;
void operator=(nrf_search_result const&) = delete;
/*
* Set the search id
......@@ -128,6 +129,41 @@ class nrf_search_result {
*/
uint64_t get_validity_period() const;
/*
* Set the the total number of NF Instances found by NRF
* @param [const uint32_t &] n: the total number of NF Instances found by NRF
* @return void
*/
void set_num_nf_inst_complete(const uint32_t &n);
/*
* Get the the total number of NF Instances found by NRF
* @param [uint32_t &] n: the total number of NF Instances found by NRF
* @return void
*/
void get_num_nf_inst_complete(uint32_t &n) const;
/*
* Set the maximum number of NFProfiles to be returned in the response
* @param [const uint32_t &] l: the maximum number of NFProfiles to be returned in the response
* @return void
*/
void set_limit_nf_instances(const uint32_t &l);
/*
* Get the maximum number of NFProfiles to be returned in the response
* @param [uint32_t &] l: the maximum number of NFProfiles to be returned in the response
* @return void
*/
void get_limit_nf_instances(uint32_t &l) const;
/*
* Get the maximum number of NFProfiles to be returned in the response
* @param [void]
* @return the maximum number of NFProfiles to be returned in the response
*/
uint32_t get_limit_nf_instances() const;
/*
* Display all the members of a subscription
* @param [void]
......@@ -138,15 +174,18 @@ class nrf_search_result {
/*
* Represent NF profile as json object
* @param [nlohmann::json &] data: Json data
* @param [uint32_t &] limit_nfs: maximum number of NF profiles stored in the json data
* 0, means without any restriction
* @return void
*/
void to_json(nlohmann::json &data) const;
void to_json(nlohmann::json &data, const uint32_t &limit_nfs) const;
private:
std::vector<std::shared_ptr<nrf_profile>> nf_instances;
std::string search_id;
uint64_t validity_period;
uint32_t num_nf_inst_complete;
uint32_t limit_nf_instances;
std::string nrf_supported_features;
};
} // namespace app
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment