Commit 1851b81b authored by Mosaical's avatar Mosaical

20210527

parent 4a80bc71
......@@ -35,6 +35,8 @@ include_directories(/usr/local/include/librdkafka)
#include_directories(json-include/json)
#link_libraries(/home/root/nrf2/lib/lib_json.lib)
add_subdirectory(json-include)
file(GLOB SRCS
${CMAKE_CURRENT_SOURCE_DIR}/api/*.cpp
${CMAKE_CURRENT_SOURCE_DIR}/impl/*.cpp
......@@ -43,6 +45,8 @@ file(GLOB SRCS
${CMAKE_CURRENT_SOURCE_DIR}/*.cpp
)
add_executable(${PROJECT_NAME} ${SRCS} )
#add_dependencies(${PROJECT_NAME} PISTACHE NLOHMANN)
target_link_libraries(${PROJECT_NAME} pistache pthread zookeeper_mt jsoncpp rdkafka)
target_link_libraries(${PROJECT_NAME} pistache zookeeper_mt jsoncpp rdkafka pthread)
......@@ -188,9 +188,17 @@ try{
std::ifstream readProfile(fileName);
nlohmann::json thisProfileJson;
readProfile>> thisProfileJson;
std::string thisProfileString = thisProfileJson.dump();
responseBodyProfile = responseBodyProfile + thisProfileString;
OneOfInstanceId = "";
//在这里要进行一个判断,nfStatus的
std::string profileFlag = thisProfileJson.at("nfStatus").dump();
std::cout << "profileFlag is :" << profileFlag << std::endl;
if(profileFlag == "\"REGISTERED\""){
std::string thisProfileString = thisProfileJson.dump();
responseBodyProfile = responseBodyProfile + thisProfileString;
OneOfInstanceId = "";
}
else{
//配置文件不可被发现状态的不发送
}
}
else {
OneOfInstanceId = "";
......@@ -328,9 +336,14 @@ void NFInstanceIDDocumentApi::update_nf_instance_handler(const Pistache::Rest::R
auto contentEncoding = request.headers().tryGetRaw("Content-Encoding");
auto acceptEncoding = request.headers().tryGetRaw("Accept-Encoding");
std::cout << "PATCH启动了!" << std::endl;
std::string requestBodyString = request.body().c_str();
nlohmann::json j0 = nlohmann::json::parse(requestBodyString);
std::cout << "requestBodyString is : " << j0 << std::endl;
try {
nlohmann::json::parse(request.body()).get_to(patchItem);
this->update_nf_instance(nfInstanceID, patchItem, contentEncoding, acceptEncoding, response);
this->update_nf_instance(nfInstanceID, patchItem, contentEncoding, acceptEncoding, response, j0);
} catch (nlohmann::detail::exception &e) {
//send a 400 error
response.send(Pistache::Http::Code::Bad_Request, e.what());
......
......@@ -97,7 +97,7 @@ private:
/// <param name="patchItem"></param>
/// <param name="contentEncoding">Content-Encoding, described in IETF RFC 7231 (optional, default to &quot;&quot;)</param>
/// <param name="acceptEncoding">Accept-Encoding, described in IETF RFC 7231 (optional, default to &quot;&quot;)</param>
virtual void update_nf_instance(const std::string &nfInstanceID, const std::vector<PatchItem> &patchItem, const Pistache::Optional<Pistache::Http::Header::Raw> &contentEncoding, const Pistache::Optional<Pistache::Http::Header::Raw> &acceptEncoding, Pistache::Http::ResponseWriter &response) = 0;
virtual void update_nf_instance(const std::string &nfInstanceID, const std::vector<PatchItem> &patchItem, const Pistache::Optional<Pistache::Http::Header::Raw> &contentEncoding, const Pistache::Optional<Pistache::Http::Header::Raw> &acceptEncoding, Pistache::Http::ResponseWriter &response, nlohmann::json &j0) = 0;
};
......
......@@ -264,6 +264,14 @@ CMAKE_GENERATOR:INTERNAL=Unix Makefiles
CMAKE_GENERATOR_PLATFORM:INTERNAL=
//Name of generator toolset.
CMAKE_GENERATOR_TOOLSET:INTERNAL=
//Have symbol pthread_create
CMAKE_HAVE_LIBC_CREATE:INTERNAL=
//Have library pthreads
CMAKE_HAVE_PTHREADS_CREATE:INTERNAL=
//Have library pthread
CMAKE_HAVE_PTHREAD_CREATE:INTERNAL=1
//Have include pthread.h
CMAKE_HAVE_PTHREAD_H:INTERNAL=1
//Source directory with the top level CMakeLists.txt file for this
// project
CMAKE_HOME_DIRECTORY:INTERNAL=/home/root/nrf2
......@@ -327,4 +335,6 @@ CMAKE_STRIP-ADVANCED:INTERNAL=1
CMAKE_UNAME:INTERNAL=/bin/uname
//ADVANCED property for variable: CMAKE_VERBOSE_MAKEFILE
CMAKE_VERBOSE_MAKEFILE-ADVANCED:INTERNAL=1
//Details about finding Threads
FIND_PACKAGE_MESSAGE_DETAILS_Threads:INTERNAL=[TRUE][v()]
Determining if the pthread_create exist failed with the following output:
Change Dir: /home/root/nrf2/build/CMakeFiles/CMakeTmp
Run Build Command:"/usr/bin/make" "cmTC_7fb74/fast"
make[1]: Entering directory '/home/root/nrf2/build/CMakeFiles/CMakeTmp'
/usr/bin/make -f CMakeFiles/cmTC_7fb74.dir/build.make CMakeFiles/cmTC_7fb74.dir/build
make[2]: Entering directory '/home/root/nrf2/build/CMakeFiles/CMakeTmp'
Building C object CMakeFiles/cmTC_7fb74.dir/CheckSymbolExists.c.o
/usr/bin/cc -o CMakeFiles/cmTC_7fb74.dir/CheckSymbolExists.c.o -c /home/root/nrf2/build/CMakeFiles/CMakeTmp/CheckSymbolExists.c
Linking C executable cmTC_7fb74
/usr/bin/cmake -E cmake_link_script CMakeFiles/cmTC_7fb74.dir/link.txt --verbose=1
/usr/bin/cc -rdynamic CMakeFiles/cmTC_7fb74.dir/CheckSymbolExists.c.o -o cmTC_7fb74
CMakeFiles/cmTC_7fb74.dir/CheckSymbolExists.c.o: In function `main':
CheckSymbolExists.c:(.text+0x1b): undefined reference to `pthread_create'
collect2: error: ld returned 1 exit status
CMakeFiles/cmTC_7fb74.dir/build.make:97: recipe for target 'cmTC_7fb74' failed
make[2]: *** [cmTC_7fb74] Error 1
make[2]: Leaving directory '/home/root/nrf2/build/CMakeFiles/CMakeTmp'
Makefile:126: recipe for target 'cmTC_7fb74/fast' failed
make[1]: *** [cmTC_7fb74/fast] Error 2
make[1]: Leaving directory '/home/root/nrf2/build/CMakeFiles/CMakeTmp'
File /home/root/nrf2/build/CMakeFiles/CMakeTmp/CheckSymbolExists.c:
/* */
#include <pthread.h>
int main(int argc, char** argv)
{
(void)argv;
#ifndef pthread_create
return ((int*)(&pthread_create))[argc];
#else
(void)argc;
return 0;
#endif
}
Determining if the function pthread_create exists in the pthreads failed with the following output:
Change Dir: /home/root/nrf2/build/CMakeFiles/CMakeTmp
Run Build Command:"/usr/bin/make" "cmTC_0f90d/fast"
make[1]: Entering directory '/home/root/nrf2/build/CMakeFiles/CMakeTmp'
/usr/bin/make -f CMakeFiles/cmTC_0f90d.dir/build.make CMakeFiles/cmTC_0f90d.dir/build
make[2]: Entering directory '/home/root/nrf2/build/CMakeFiles/CMakeTmp'
Building C object CMakeFiles/cmTC_0f90d.dir/CheckFunctionExists.c.o
/usr/bin/cc -DCHECK_FUNCTION_EXISTS=pthread_create -o CMakeFiles/cmTC_0f90d.dir/CheckFunctionExists.c.o -c /usr/share/cmake-3.10/Modules/CheckFunctionExists.c
Linking C executable cmTC_0f90d
/usr/bin/cmake -E cmake_link_script CMakeFiles/cmTC_0f90d.dir/link.txt --verbose=1
/usr/bin/cc -DCHECK_FUNCTION_EXISTS=pthread_create -rdynamic CMakeFiles/cmTC_0f90d.dir/CheckFunctionExists.c.o -o cmTC_0f90d -lpthreads
/usr/bin/ld: cannot find -lpthreads
collect2: error: ld returned 1 exit status
CMakeFiles/cmTC_0f90d.dir/build.make:97: recipe for target 'cmTC_0f90d' failed
make[2]: *** [cmTC_0f90d] Error 1
make[2]: Leaving directory '/home/root/nrf2/build/CMakeFiles/CMakeTmp'
Makefile:126: recipe for target 'cmTC_0f90d/fast' failed
make[1]: *** [cmTC_0f90d/fast] Error 2
make[1]: Leaving directory '/home/root/nrf2/build/CMakeFiles/CMakeTmp'
......@@ -631,3 +631,35 @@ make[1]: Leaving directory '/home/root/nrf2/build/CMakeFiles/CMakeTmp'
Feature record: CXX_FEATURE:0cxx_variable_templates
Feature record: CXX_FEATURE:0cxx_variadic_macros
Feature record: CXX_FEATURE:0cxx_variadic_templates
Determining if the include file pthread.h exists passed with the following output:
Change Dir: /home/root/nrf2/build/CMakeFiles/CMakeTmp
Run Build Command:"/usr/bin/make" "cmTC_93670/fast"
make[1]: Entering directory '/home/root/nrf2/build/CMakeFiles/CMakeTmp'
/usr/bin/make -f CMakeFiles/cmTC_93670.dir/build.make CMakeFiles/cmTC_93670.dir/build
make[2]: Entering directory '/home/root/nrf2/build/CMakeFiles/CMakeTmp'
Building C object CMakeFiles/cmTC_93670.dir/CheckIncludeFile.c.o
/usr/bin/cc -o CMakeFiles/cmTC_93670.dir/CheckIncludeFile.c.o -c /home/root/nrf2/build/CMakeFiles/CMakeTmp/CheckIncludeFile.c
Linking C executable cmTC_93670
/usr/bin/cmake -E cmake_link_script CMakeFiles/cmTC_93670.dir/link.txt --verbose=1
/usr/bin/cc -rdynamic CMakeFiles/cmTC_93670.dir/CheckIncludeFile.c.o -o cmTC_93670
make[2]: Leaving directory '/home/root/nrf2/build/CMakeFiles/CMakeTmp'
make[1]: Leaving directory '/home/root/nrf2/build/CMakeFiles/CMakeTmp'
Determining if the function pthread_create exists in the pthread passed with the following output:
Change Dir: /home/root/nrf2/build/CMakeFiles/CMakeTmp
Run Build Command:"/usr/bin/make" "cmTC_cd385/fast"
make[1]: Entering directory '/home/root/nrf2/build/CMakeFiles/CMakeTmp'
/usr/bin/make -f CMakeFiles/cmTC_cd385.dir/build.make CMakeFiles/cmTC_cd385.dir/build
make[2]: Entering directory '/home/root/nrf2/build/CMakeFiles/CMakeTmp'
Building C object CMakeFiles/cmTC_cd385.dir/CheckFunctionExists.c.o
/usr/bin/cc -DCHECK_FUNCTION_EXISTS=pthread_create -o CMakeFiles/cmTC_cd385.dir/CheckFunctionExists.c.o -c /usr/share/cmake-3.10/Modules/CheckFunctionExists.c
Linking C executable cmTC_cd385
/usr/bin/cmake -E cmake_link_script CMakeFiles/cmTC_cd385.dir/link.txt --verbose=1
/usr/bin/cc -DCHECK_FUNCTION_EXISTS=pthread_create -rdynamic CMakeFiles/cmTC_cd385.dir/CheckFunctionExists.c.o -o cmTC_cd385 -lpthread
make[2]: Leaving directory '/home/root/nrf2/build/CMakeFiles/CMakeTmp'
make[1]: Leaving directory '/home/root/nrf2/build/CMakeFiles/CMakeTmp'
......@@ -101,10 +101,18 @@ string
-
vector
-
discoverInformation.h
../impl/discoverInformation.h
pthread.h
-
iostream
-
fstream
-
iomanip
-
myNotify.h
../impl/myNotify.h
get2rdNodeMessage.h
../impl/get2rdNodeMessage.h
../impl/NFInstancesStoreApiImpl.h
pistache/endpoint.h
......@@ -1005,6 +1013,8 @@ iostream
-
nlohmann/json.hpp
-
zookeeperClient.h
../zkH/zookeeperClient.h
../zkH/inforMatch.h
stdio.h
......@@ -1017,8 +1027,6 @@ iostream
-
nlohmann/json.hpp
-
zookeeperClient.h
../zkH/zookeeperClient.h
regex
-
......@@ -1039,8 +1047,6 @@ string
-
stdbool.h
-
zookeeperClient.h
../zkH/zookeeperClient.h
../zkH/zk_cpp.h
stdint.h
......@@ -1243,8 +1249,6 @@ iomanip
-
NFInstanceIDDocumentApiImpl.h
/home/root/nrf2/impl/NFInstanceIDDocumentApiImpl.h
zookeeperClient.h
/home/root/nrf2/impl/zookeeperClient.h
Register.h
/home/root/nrf2/impl/Register.h
regex
......@@ -1253,6 +1257,8 @@ NFService.h
/home/root/nrf2/impl/NFService.h
vector
-
discoverInformation.h
/home/root/nrf2/impl/discoverInformation.h
/home/root/nrf2/impl/NFInstanceIDDocumentApiImpl.h
pistache/endpoint.h
......@@ -1277,10 +1283,18 @@ string
-
vector
-
discoverInformation.h
/home/root/nrf2/impl/discoverInformation.h
pthread.h
-
iostream
-
fstream
-
iomanip
-
myNotify.h
/home/root/nrf2/impl/myNotify.h
get2rdNodeMessage.h
/home/root/nrf2/impl/get2rdNodeMessage.h
/home/root/nrf2/impl/NFInstancesStoreApiImpl.cpp
NFInstancesStoreApiImpl.h
......@@ -2849,8 +2863,6 @@ stdbool.h
/home/root/nrf2/zkH/get2rdNodeMessage.cpp
get2rdNodeMessage.h
/home/root/nrf2/zkH/get2rdNodeMessage.h
zookeeperClient.h
/home/root/nrf2/zkH/zookeeperClient.h
stdbool.h
-
......@@ -2865,10 +2877,14 @@ iostream
-
nlohmann/json.hpp
-
zookeeperClient.h
/home/root/nrf2/zkH/zookeeperClient.h
/home/root/nrf2/zkH/inforMatch.cpp
inforMatch.h
/home/root/nrf2/zkH/inforMatch.h
zookeeperClient.h
/home/root/nrf2/zkH/zookeeperClient.h
/home/root/nrf2/zkH/inforMatch.h
stdio.h
......@@ -2881,8 +2897,6 @@ iostream
-
nlohmann/json.hpp
-
zookeeperClient.h
/home/root/nrf2/zkH/zookeeperClient.h
regex
-
......@@ -2893,8 +2907,6 @@ stdio.h
-
iostream
-
zookeeperClient.h
/home/root/nrf2/zkH/zookeeperClient.h
get2rdNodeMessage.h
/home/root/nrf2/zkH/get2rdNodeMessage.h
HttpRequest.h
......@@ -2937,14 +2949,14 @@ iostream
/home/root/nrf2/zkH/subscribeNode.cpp
subscribeNode.h
/home/root/nrf2/zkH/subscribeNode.h
zookeeperClient.h
/home/root/nrf2/zkH/zookeeperClient.h
/home/root/nrf2/zkH/subscribeNode.h
string
-
stdbool.h
-
zookeeperClient.h
/home/root/nrf2/zkH/zookeeperClient.h
/home/root/nrf2/zkH/zk_cpp.cpp
zk_cpp.h
......
......@@ -214,6 +214,7 @@ CMakeFiles/api-server.dir/impl/NFInstanceIDDocumentApiImpl.cpp.o
../model/WAgfInfo.h
../zkH/Register.h
../zkH/discoverInformation.h
../zkH/get2rdNodeMessage.h
../zkH/myNotify.h
../zkH/zk_cpp.h
../zkH/zookeeperClient.h
......@@ -254,8 +255,6 @@ CMakeFiles/api-server.dir/impl/SubscriptionsCollectionApiImpl.cpp.o
../model/Snssai.h
../model/SubscriptionData.h
../zkH/subscribeNode.h
../zkH/zk_cpp.h
../zkH/zookeeperClient.h
/home/root/nrf2/impl/SubscriptionsCollectionApiImpl.cpp
/home/root/nrf2/impl/SubscriptionsCollectionApiImpl.h
CMakeFiles/api-server.dir/main-api-server.cpp.o
......@@ -350,7 +349,7 @@ CMakeFiles/api-server.dir/main-api-server.cpp.o
../model/UriScheme.h
../model/VendorSpecificFeature.h
../model/WAgfInfo.h
../zkH/discoverInformation.h
../zkH/get2rdNodeMessage.h
../zkH/myNotify.h
../zkH/subscribeNode.h
../zkH/zk_cpp.h
......
......@@ -213,6 +213,7 @@ CMakeFiles/api-server.dir/impl/NFInstanceIDDocumentApiImpl.cpp.o: ../model/Vendo
CMakeFiles/api-server.dir/impl/NFInstanceIDDocumentApiImpl.cpp.o: ../model/WAgfInfo.h
CMakeFiles/api-server.dir/impl/NFInstanceIDDocumentApiImpl.cpp.o: ../zkH/Register.h
CMakeFiles/api-server.dir/impl/NFInstanceIDDocumentApiImpl.cpp.o: ../zkH/discoverInformation.h
CMakeFiles/api-server.dir/impl/NFInstanceIDDocumentApiImpl.cpp.o: ../zkH/get2rdNodeMessage.h
CMakeFiles/api-server.dir/impl/NFInstanceIDDocumentApiImpl.cpp.o: ../zkH/myNotify.h
CMakeFiles/api-server.dir/impl/NFInstanceIDDocumentApiImpl.cpp.o: ../zkH/zk_cpp.h
CMakeFiles/api-server.dir/impl/NFInstanceIDDocumentApiImpl.cpp.o: ../zkH/zookeeperClient.h
......@@ -253,8 +254,6 @@ CMakeFiles/api-server.dir/impl/SubscriptionsCollectionApiImpl.cpp.o: ../model/Pr
CMakeFiles/api-server.dir/impl/SubscriptionsCollectionApiImpl.cpp.o: ../model/Snssai.h
CMakeFiles/api-server.dir/impl/SubscriptionsCollectionApiImpl.cpp.o: ../model/SubscriptionData.h
CMakeFiles/api-server.dir/impl/SubscriptionsCollectionApiImpl.cpp.o: ../zkH/subscribeNode.h
CMakeFiles/api-server.dir/impl/SubscriptionsCollectionApiImpl.cpp.o: ../zkH/zk_cpp.h
CMakeFiles/api-server.dir/impl/SubscriptionsCollectionApiImpl.cpp.o: ../zkH/zookeeperClient.h
CMakeFiles/api-server.dir/impl/SubscriptionsCollectionApiImpl.cpp.o: ../impl/SubscriptionsCollectionApiImpl.cpp
CMakeFiles/api-server.dir/impl/SubscriptionsCollectionApiImpl.cpp.o: ../impl/SubscriptionsCollectionApiImpl.h
......@@ -349,7 +348,7 @@ CMakeFiles/api-server.dir/main-api-server.cpp.o: ../model/UpfInfo.h
CMakeFiles/api-server.dir/main-api-server.cpp.o: ../model/UriScheme.h
CMakeFiles/api-server.dir/main-api-server.cpp.o: ../model/VendorSpecificFeature.h
CMakeFiles/api-server.dir/main-api-server.cpp.o: ../model/WAgfInfo.h
CMakeFiles/api-server.dir/main-api-server.cpp.o: ../zkH/discoverInformation.h
CMakeFiles/api-server.dir/main-api-server.cpp.o: ../zkH/get2rdNodeMessage.h
CMakeFiles/api-server.dir/main-api-server.cpp.o: ../zkH/myNotify.h
CMakeFiles/api-server.dir/main-api-server.cpp.o: ../zkH/subscribeNode.h
CMakeFiles/api-server.dir/main-api-server.cpp.o: ../zkH/zk_cpp.h
......
This diff is collapsed.
No preview for this file type
No preview for this file type
{
"ipv4Addresses": [
"192.168.211.67:8080"
],
"nfInstanceId": "liuyuSMF",
"nfStatus": "REGISTERED",
"nfType": "SMF"
}
{
"ipv4Addresses": [
"192.168.211.67:8080"
],
"nfInstanceId": "liuyuSMF10",
"nfStatus": "REGISTERED",
"nfType": "SMF"
}
{
"ipv4Addresses": [
"192.168.211.67:8080"
],
"nfInstanceId": "liuyuSMF11",
"nfStatus": "REGISTERED",
"nfType": "SMF"
}
{
"ipv4Addresses": [
"192.168.211.67:8080"
],
"nfInstanceId": "liuyuSMF12",
"nfStatus": "REGISTERED",
"nfType": "SMF"
}
{
"ipv4Addresses": [
"192.168.211.67:8080"
],
"nfInstanceId": "liuyuSMF13",
"nfStatus": "REGISTERED",
"nfType": "SMF"
}
{
"ipv4Addresses": [
"192.168.211.67:8080"
],
"nfInstanceId": "liuyuSMF14",
"nfStatus": "REGISTERED",
"nfType": "SMF"
}
{
"ipv4Addresses": [
"192.168.211.67:8080"
],
"nfInstanceId": "liuyuSMF15",
"nfStatus": "REGISTERED",
"nfType": "SMF"
}
{
"ipv4Addresses": [
"192.168.211.67:8080"
],
"nfInstanceId": "liuyuSMF16",
"nfStatus": "REGISTERED",
"nfType": "SMF"
}
{
"ipv4Addresses": [
"192.168.211.67:8080"
],
"nfInstanceId": "liuyuSMF17",
"nfStatus": "SUSPENDED",
"nfType": "SMF"
}
{
"ipv4Addresses": [
"192.168.211.67:8080"
],
"nfInstanceId": "liuyuSMF2",
"nfStatus": "REGISTERED",
"nfType": "SMF"
}
{
"ipv4Addresses": [
"192.168.211.67:8080"
],
"nfInstanceId": "liuyuSMF3",
"nfStatus": "REGISTERED",
"nfType": "SMF"
}
{
"ipv4Addresses": [
"192.168.211.67:8080"
],
"nfInstanceId": "liuyuSMF4",
"nfStatus": "REGISTERED",
"nfType": "SMF"
}
{
"ipv4Addresses": [
"192.168.211.67:8080"
],
"nfInstanceId": "liuyuSMF5",
"nfStatus": "REGISTERED",
"nfType": "SMF"
}
{
"ipv4Addresses": [
"192.168.211.67:8080"
],
"nfInstanceId": "liuyuSMF6",
"nfStatus": "REGISTERED",
"nfType": "SMF"
}
{
"ipv4Addresses": [
"192.168.211.67:8080"
],
"nfInstanceId": "liuyuSMF7",
"nfStatus": "REGISTERED",
"nfType": "SMF"
}
{
"ipv4Addresses": [
"192.168.211.67:8080"
],
"nfInstanceId": "liuyuSMF8",
"nfStatus": "REGISTERED",
"nfType": "SMF"
}
{
"ipv4Addresses": [
"192.168.211.67:8080"
],
"nfInstanceId": "liuyuSMF9",
"nfStatus": "REGISTERED",
"nfType": "SMF"
}
{
"ipv4Address": "192.168.0.0",
"ipv4Addresses": [
"192.168.0.0"
],
"nfInstanceId": "mxcAMF",
"nfServices": [
{
......
......@@ -14,13 +14,12 @@
#include <fstream>
#include <iomanip>
#include "NFInstanceIDDocumentApiImpl.h"
#include "zookeeperClient.h"
#include "Register.h"
#include <regex>
#include "NFService.h"
#include <vector>
//#include "myProducer.h"
#include "discoverInformation.h"
namespace org {
namespace openapitools {
namespace server {
......@@ -219,6 +218,30 @@ void NFInstanceIDDocumentApiImpl::register_nf_instance(const std::string &nfInst
std::string bufString = "I AM NF_REGISTERED!";
int produceFlag = MyProducer->produceMessage(bufString);
free(MyProducer);*/
//开启异步线程监听/HeartBeat的值
//std::thread t(thread_function);
std::cout << "main thread\n";
// t.join();
//t.detach();
int nfInstanceIdLength = nfInstanceId.length();
char threadData[nfInstanceIdLength+1];
for(int i = 0; i < nfInstanceIdLength; i++){
threadData[i] = nfInstanceId[i];
}
threadData[nfInstanceIdLength] = '\0';
pthread_t thread_id;
//pthread_create( &thread_id, NULL, print_message, NULL );
pthread_create( &thread_id, NULL, print_message, &threadData );
pthread_detach(thread_id);
//sleep(1);
printf("Leave main thread!\n");
//pthread_exit("end");
// 一个线程默认的状态是joinable
}
//getValue = getValue + nfInstanceId + ";";
......@@ -228,8 +251,44 @@ void NFInstanceIDDocumentApiImpl::register_nf_instance(const std::string &nfInst
//b = Register.registerZK(InforValue, fullPath, zk);
response.send(Pistache::Http::Code::Ok, "Do some magic\n");
}
void NFInstanceIDDocumentApiImpl::update_nf_instance(const std::string &nfInstanceID, const std::vector<PatchItem> &patchItem, const Pistache::Optional<Pistache::Http::Header::Raw> &contentEncoding, const Pistache::Optional<Pistache::Http::Header::Raw> &acceptEncoding, Pistache::Http::ResponseWriter &response) {
response.send(Pistache::Http::Code::Ok, "Do some magic\n");
void NFInstanceIDDocumentApiImpl::update_nf_instance(const std::string &nfInstanceID, const std::vector<PatchItem> &patchItem, const Pistache::Optional<Pistache::Http::Header::Raw> &contentEncoding, const Pistache::Optional<Pistache::Http::Header::Raw> &acceptEncoding, Pistache::Http::ResponseWriter &response, nlohmann::json &j0) {
std::cout << "requestBodyString is : " << j0 << std::endl;
//请求体输进来后不判断op是否为replace了
std::string statusString ;
std::string j0String = j0.dump();
std::string trueJ0String = j0String.substr(1, j0String.length()-2);
std::cout << "trueJ0String is : " << trueJ0String << std::endl;
nlohmann::json statusJson = nlohmann::json::parse(trueJ0String);
statusString = statusJson.at("value").dump();
//此时把心跳连接Patch中的关于nfStatus的部分解析出来存储到了statusString中
std::string heartBeatNfInstanceId = nfInstanceID;
//心跳复位
std::string fileName = heartBeatNfInstanceId + ".json";
std::ifstream readProfile(fileName);
nlohmann::json thisProfileJson;
readProfile >> thisProfileJson;
thisProfileJson["nfStatus"] = "REGISTERED";
std::ofstream myfile(fileName);
myfile << std::setw(75) << thisProfileJson << std::endl;
//将解析出来的heartbeat信息存进zookeeper里
std::string value;
zookeeperClient zooK;
bool flag1,flag2,flag3;
bool atest = zooK.connect2ZKServer("192.168.211.128:2181");
utility::zk_cpp* zk;
zk = zooK.getZk();//连接zookeeper完毕
std::string heartBeatPath = "/HeartBeat";
value = heartBeatNfInstanceId;
utility::zoo_rc setSubscribeURI = zk->set_node(heartBeatPath.c_str(), value, -1);
response.send(Pistache::Http::Code::Ok, "Do some magic\n");
}
}
......
......@@ -34,8 +34,12 @@
#include "ProblemDetails.h"
#include <string>
#include <vector>
#include "discoverInformation.h"
#include <pthread.h>
#include <iostream>
#include <fstream>
#include <iomanip>
#include "myNotify.h"
#include "get2rdNodeMessage.h"
namespace org {
namespace openapitools {
namespace server {
......@@ -51,7 +55,87 @@ public:
void deregister_nf_instance(const std::string &nfInstanceID, Pistache::Http::ResponseWriter &response);
void get_nf_instance(const std::string &nfInstanceID, Pistache::Http::ResponseWriter &response);
void register_nf_instance(const std::string &nfInstanceID, const NFProfile &nFProfile, const Pistache::Optional<Pistache::Http::Header::Raw> &contentEncoding, const Pistache::Optional<Pistache::Http::Header::Raw> &acceptEncoding, Pistache::Http::ResponseWriter &response, nlohmann::json &j0, std::string URI);
void update_nf_instance(const std::string &nfInstanceID, const std::vector<PatchItem> &patchItem, const Pistache::Optional<Pistache::Http::Header::Raw> &contentEncoding, const Pistache::Optional<Pistache::Http::Header::Raw> &acceptEncoding, Pistache::Http::ResponseWriter &response);
static void* print_message( void* data )
{
//pthread_detach(pthread_self());
//pthread_detach(pthread_self()),将状态改为unjoinable状态,确保资源的释放
//static int g;
//int flag = 0;
//while(flag < 20){
// flag++;
// printf("%d\n", g++);
// sleep(100);
// }
// pthread_exit(0) ;//pthread_exit时自动会被释放
int flag = 1;
std::string dataString = (char*)data;
//std::cout << "data is :" << dataString <<std::endl;(已成功取出)
while (1)
{
get2rdNodeMessage *Get2rdNodeMessage = new get2rdNodeMessage;
std::string path = "/HeartBeat";
std::string heartBeatString = Get2rdNodeMessage->getNodeMessage(path);
free(Get2rdNodeMessage);
if(heartBeatString == dataString){
//将心跳zookeeper归零
zookeeperClient zooK;
bool atest = zooK.connect2ZKServer("192.168.211.128:2181");
utility::zk_cpp* zk;
zk = zooK.getZk();//连接zookeeper完毕
std::string heartBeatPath = "/HeartBeat";
std::string value = "";
utility::zoo_rc setSubscribeURI = zk->set_node(heartBeatPath.c_str(), value, -1);
//delete zooK;
free(zk);
flag = 0;
usleep(1000 * 1000);
printf("thread1 running...!\n");
}else{
usleep(1000 * 1000);
printf("thread1 running...!\n");
flag++;
if(flag>=6) break;
}
}
//标记sus
get2rdNodeMessage *Get2rdNodeMessage2 = new get2rdNodeMessage;
//心跳停止的nf的注册节点地址
std::cout << "心跳已停止" << std::endl;
std::string fullPath = Get2rdNodeMessage2->getFullPath(dataString);
//std::cout << "full Path is : " << fullPath << std::endl;成功取出type+ID的节点地址
free(Get2rdNodeMessage2);
//连接zookeeper
//zookeeperClient zooK;
//bool atest = zooK.connect2ZKServer("192.168.211.128:2181");
//utility::zk_cpp* zk;
//zk = zooK.getZk();//连接zookeeper完毕
//std::string stopHeartValue;//取出停止心跳的实例的profile
//utility::zoo_rc ret = zk->get_node(fullPath.c_str(), stopHeartValue, nullptr, true);
//std::cout << "停止心跳的profile" << stopHeartValue << std::endl;
//通过profile.json更改nfstatus
std::string fileName = dataString + ".json";
std::ifstream readProfile(fileName);
nlohmann::json thisProfileJson;
readProfile>> thisProfileJson;
//std::cout << "profile is :" << thisProfileJson << std::endl;
thisProfileJson["nfStatus"] = "SUSPENDED";
std::ofstream myfile(fileName);
//std::string thisProfileString = thisProfileJson.dump();
myfile << std::setw(75) << thisProfileJson << std::endl;
//通知订阅者
printf("Leave thread1!\n");
return NULL;
}
void update_nf_instance(const std::string &nfInstanceID, const std::vector<PatchItem> &patchItem, const Pistache::Optional<Pistache::Http::Header::Raw> &contentEncoding, const Pistache::Optional<Pistache::Http::Header::Raw> &acceptEncoding, Pistache::Http::ResponseWriter &response, nlohmann::json &j0);
};
......
......@@ -61,7 +61,6 @@ static void setUpUnixSignals(std::vector<int> quitSignals) {
#endif
using namespace org::openapitools::server::api;
int main() {
#ifdef __linux__
std::vector<int> sigs{SIGQUIT, SIGINT, SIGTERM, SIGHUP};
......
#include "get2rdNodeMessage.h"
#include "zookeeperClient.h"
#include <stdbool.h>
std::string get2rdNodeMessage::getNodeMessage(std::string path){
std::string value;
......@@ -10,3 +9,56 @@ std::string get2rdNodeMessage::getNodeMessage(std::string path){
utility::zoo_rc ret = zk->get_node(path.c_str(), value, nullptr, true);
return value;
}
bool get2rdNodeMessage::setSubscribeURI(std::string URI, std::string leafPath){
zookeeperClient zooK;
std::string testFullPath;
std::string returnFullPath;
bool a = zooK.connect2ZKServer("192.168.211.128:2181");
utility::zk_cpp* zk;
zk = zooK.getZk();
utility::zoo_rc ret = utility::z_ok;
//初始化zookeeper
std::string getValue;
leafPath = "/Subscribes" + leafPath;
utility::zoo_rc getRet = zk->get_node(leafPath.c_str(), getValue, nullptr, true);
std::string setValue = getValue + URI + ";";
std::cout << "leafPath is : " << leafPath << std::endl;
utility::zoo_rc setRet = zk->set_node(leafPath.c_str(), setValue, -1);
std::cout << "set完毕" << std::endl;
return 1;
}
std::string get2rdNodeMessage::getFullPath(std::string leafPath){
zookeeperClient zooK;
std::string testFullPath;
std::string returnFullPath;
bool a = zooK.connect2ZKServer("192.168.211.128:2181");
utility::zk_cpp* zk;
zk = zooK.getZk();
utility::zoo_rc ret = utility::z_ok;
//鍒濆鍖杬ookeeper缁撴潫
testFullPath = "/AMF/" + leafPath;
//std::cout << "testFullPath is : " << testFullPath << std::endl;
ret = zk->exists_node(testFullPath.c_str(), nullptr, true);
if(ret == utility::z_ok){
returnFullPath = testFullPath;
//delete zooK;
return returnFullPath;
}
testFullPath = "/SMF/" + leafPath;
//std::cout << "testFullPath is : " << testFullPath << std::endl;
ret = zk->exists_node(testFullPath.c_str(), nullptr, true);
if(ret == utility::z_ok){
returnFullPath = testFullPath;
//delete zooK;
return returnFullPath;
}
returnFullPath = "NO SUCH NFTYPE!";
std::cout << "testFullPath is :" << testFullPath << std::endl;
//delete zooK;
return returnFullPath;
}
......@@ -3,7 +3,11 @@
#include <string>
#include <iostream>
#include <nlohmann/json.hpp>
#include "zookeeperClient.h"
class get2rdNodeMessage{
public:
std::string getNodeMessage(std::string path);
bool setSubscribeURI(std::string URI, std::string leafPath);
std::string getFullPath(std::string leafPath);
};
#include "inforMatch.h"
#include "zookeeperClient.h"
bool inforMatch::ifIsMatching(std::string instancePath, nlohmann::json jsonInformation){
std::string value;
zookeeperClient zooK;
......
......@@ -3,7 +3,6 @@
#include <string>
#include <iostream>
#include <nlohmann/json.hpp>
#include "zookeeperClient.h"
#include <regex>
class inforMatch{
public:
......
......@@ -2,7 +2,6 @@
#include "myNotify.h"
#include <stdio.h>
#include <iostream>
#include "zookeeperClient.h"
#include "get2rdNodeMessage.h"
#include "HttpRequest.h"
#include <nlohmann/json.hpp>
......
#include "subscribeNode.h"
#include "zookeeperClient.h"
bool subscribeNode::setSubscribeURI(std::string URI, std::string leafPath){
zookeeperClient zooK;
......
#include <string>
#include <stdbool.h>
#include "zookeeperClient.h"
class subscribeNode{
public:
......
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