Commit 5507552f authored by Tien-Thinh Nguyen's avatar Tien-Thinh Nguyen

add NFDeregister operation

parent 117d3988
......@@ -14,6 +14,7 @@
#include "logger.hpp"
#include "nrf_app.hpp"
#include "nrf_config.hpp"
#include "nrf_profile.hpp"
#include "ProblemDetails.h"
#include "3gpp_29.500.h"
......@@ -36,14 +37,68 @@ NFInstanceIDDocumentApiImpl::NFInstanceIDDocumentApiImpl(
m_address(address) {
}
//------------------------------------------------------------------------------
void NFInstanceIDDocumentApiImpl::deregister_nf_instance(
const std::string &nfInstanceID, Pistache::Http::ResponseWriter &response) {
response.send(Pistache::Http::Code::Ok, "Do some magic\n");
Logger::nrf_sbi().info(
"Got a request to de-register a given NF Instance, Instance ID: %s",
nfInstanceID.c_str());
int http_code = 0;
ProblemDetails problem_details = { };
m_nrf_app->handle_deregister_nf_instance(nfInstanceID, http_code, 1,
problem_details);
nlohmann::json json_data = { };
std::string content_type = "application/json";
if (http_code != HTTP_STATUS_CODE_204_NO_CONTENT) {
to_json(json_data, problem_details);
content_type = "application/problem+json";
//content type
response.headers().add < Pistache::Http::Header::ContentType
> (Pistache::Http::Mime::MediaType(content_type));
response.send(Pistache::Http::Code(http_code), json_data.dump().c_str());
return;
} else {
response.headers().add < Pistache::Http::Header::ContentType
> (Pistache::Http::Mime::MediaType(content_type));
response.send(Pistache::Http::Code(http_code));
}
}
//------------------------------------------------------------------------------
void NFInstanceIDDocumentApiImpl::get_nf_instance(
const std::string &nfInstanceID, Pistache::Http::ResponseWriter &response) {
response.send(Pistache::Http::Code::Ok, "Do some magic\n");
Logger::nrf_sbi().info(
"Got a request to retrieve the profile of a given NF Instance, Instance ID: %s",
nfInstanceID.c_str());
int http_code = 0;
std::shared_ptr<nrf_profile> profile = { };
ProblemDetails problem_details = { };
m_nrf_app->handle_get_nf_instance(nfInstanceID, profile, http_code, 1,
problem_details);
nlohmann::json json_data = { };
std::string content_type = "application/json";
if (http_code != HTTP_STATUS_CODE_200_OK) {
to_json(json_data, problem_details);
content_type = "application/problem+json";
} else {
profile.get()->to_json(json_data);
}
//content type
response.headers().add < Pistache::Http::Header::ContentType
> (Pistache::Http::Mime::MediaType(content_type));
response.send(Pistache::Http::Code(http_code), json_data.dump().c_str());
}
//------------------------------------------------------------------------------
void NFInstanceIDDocumentApiImpl::register_nf_instance(
const std::string &nfInstanceID, const NFProfile &nFProfile,
const Pistache::Optional<Pistache::Http::Header::Raw> &contentEncoding,
......@@ -79,6 +134,8 @@ void NFInstanceIDDocumentApiImpl::register_nf_instance(
+ nfInstanceID);
response.send(Pistache::Http::Code(http_code), json_data.dump().c_str());
}
//------------------------------------------------------------------------------
void NFInstanceIDDocumentApiImpl::update_nf_instance(
const std::string &nfInstanceID, const std::vector<PatchItem> &patchItem,
Pistache::Http::ResponseWriter &response) {
......
......@@ -230,6 +230,64 @@ void nrf_app::handle_get_nf_instances(const std::string &nf_type,
}
}
void nrf_app::handle_get_nf_instance(const std::string &nf_instance_id,
std::shared_ptr<nrf_profile> &profile,
int &http_code, const uint8_t http_version,
ProblemDetails &problem_details) {
Logger::nrf_app().info("Handle Retrieve an NF Instance (HTTP version %d)",
http_version);
//TODO: If the NF Service Consumer is not allowed to retrieve the NF profile of this specific registered NF instance, the
//NRF shall return "403 Forbidden" status code.
profile = find_nf_profile(nf_instance_id);
if (profile.get() == nullptr) {
Logger::nrf_app().debug("Profile with profile ID %s not found",
nf_instance_id.c_str());
http_code = HTTP_STATUS_CODE_404_NOT_FOUND;
problem_details.setCause(
protocol_application_error_e2str[RESOURCE_URI_STRUCTURE_NOT_FOUND]);
return;
} else {
Logger::nrf_app().debug("Profile with profile ID %s",
nf_instance_id.c_str());
profile.get()->display();
http_code = HTTP_STATUS_CODE_200_OK;
return;
}
}
//------------------------------------------------------------------------------
void nrf_app::handle_deregister_nf_instance(const std::string &nf_instance_id,
int &http_code,
const uint8_t http_version,
ProblemDetails &problem_details) {
Logger::nrf_app().info("Handle Deregister an NF Instance (HTTP version %d)",
http_version);
if (is_profile_exist(nf_instance_id)) {
if (remove_nf_profile(nf_instance_id)) {
Logger::nrf_app().debug("Removed NF profile with profile ID %s",
nf_instance_id.c_str());
http_code = HTTP_STATUS_CODE_204_NO_CONTENT;
return;
} else {
http_code = HTTP_STATUS_CODE_500_INTERNAL_SERVER_ERROR;
problem_details.setCause(
protocol_application_error_e2str[SYSTEM_FAILURE]);
return;
}
} else {
Logger::nrf_app().debug("Profile with profile ID %s not found",
nf_instance_id.c_str());
http_code = HTTP_STATUS_CODE_404_NOT_FOUND;
problem_details.setCause(
protocol_application_error_e2str[RESOURCE_URI_STRUCTURE_NOT_FOUND]);
return;
}
}
//------------------------------------------------------------------------------
bool nrf_app::add_nf_profile(const std::string &profile_id,
const std::shared_ptr<nrf_profile> &p) {
......@@ -335,7 +393,7 @@ bool nrf_app::is_profile_exist(const std::string &profile_id) const {
}
//------------------------------------------------------------------------------
bool nrf_app::remove_nf_profile(std::shared_ptr<nrf_profile> &snp) {
bool nrf_app::remove_nf_profile(const std::shared_ptr<nrf_profile> &snp) {
std::string key;
snp.get()->get_nf_instance_id(key);
std::unique_lock lock(m_instance_id2nrf_profile);
......@@ -351,7 +409,7 @@ bool nrf_app::remove_nf_profile(std::shared_ptr<nrf_profile> &snp) {
}
//------------------------------------------------------------------------------
bool nrf_app::remove_nf_profile(std::string &profile_id) {
bool nrf_app::remove_nf_profile(const std::string &profile_id) {
std::unique_lock lock(m_instance_id2nrf_profile);
if (instance_id2nrf_profile.erase(profile_id)) {
Logger::nrf_app().info("Removed NF profile (ID %d) from the list",
......
......@@ -92,6 +92,36 @@ class nrf_app {
const std::vector<PatchItem> &patchItem, int &http_code,
const uint8_t http_version,
ProblemDetails &problem_details);
/*
* Handle a Get NF Instance request
* @param [const std::string &] nf_instance_id: Instance ID
* @param [nrf_profile &] profile: NF profile
* @param [int &] http_code: HTTP code used to return to the consumer
* @param [const uint8_t] http_version: HTTP version
* @param [ProblemDetails &] problem_details: Store details of the error
* @return void
*/
void handle_get_nf_instance(
const std::string &nf_instance_id,
std::shared_ptr < nrf_profile > &profile, int &http_code,
const uint8_t http_version,
ProblemDetails &problem_details);
/*
* Handle De-register a given NF Instance
* @param [const std::string &] nf_instance_id: Instance ID
* @param [int &] http_code: HTTP code used to return to the consumer
* @param [const uint8_t] http_version: HTTP version
* @param [ProblemDetails &] problem_details: Store details of the error
* @return void
*/
void handle_deregister_nf_instance(
const std::string &nf_instance_id,
int &http_code,
const uint8_t http_version,
ProblemDetails &problem_details);
/*
* Insert a nrf profile
* @param [const std::string &] profile_id: Profile ID
......@@ -148,14 +178,14 @@ class nrf_app {
* @param [std::shared_ptr<nrf_profile> &] snp: profile to be removed
* @return true if successful, otherwise, return false
*/
bool remove_nf_profile(std::shared_ptr<nrf_profile> &snp);
bool remove_nf_profile(const std::shared_ptr<nrf_profile> &snp);
/*
* Remove a nf profile from the list
* @param [std::string &] profile_id: ID of the profile to be removed
* @return true if successful, otherwise, return false
*/
bool remove_nf_profile(std::string &profile_id);
bool remove_nf_profile(const std::string &profile_id);
void subscribe_task_tick (uint64_t ms);
void handle_heartbeart_timeout(uint64_t ms);
......
......@@ -41,6 +41,7 @@
#include "nrf.h"
#include "nrf_event.hpp"
#include "logger.hpp"
namespace oai {
namespace nrf {
......@@ -94,7 +95,9 @@ class nrf_profile : public std::enable_shared_from_this<nrf_profile> {
}
nrf_profile(nrf_profile &b) = delete;
virtual ~nrf_profile() {
Logger::nrf_app().debug("Delete instance...");
task_connection.disconnect();
}
......
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