Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
O
OpenXG-NRF
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Metrics
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
OpenXG
OpenXG-NRF
Commits
7014ac3f
Commit
7014ac3f
authored
Nov 12, 2020
by
Mosaical
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
20201112
parent
066804bb
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
116 additions
and
13 deletions
+116
-13
api/.NFInstanceIDDocumentApi.cpp.swo
api/.NFInstanceIDDocumentApi.cpp.swo
+0
-0
api/NFInstanceIDDocumentApi.cpp
api/NFInstanceIDDocumentApi.cpp
+76
-9
impl/.NFInstanceIDDocumentApiImpl.cpp.swp
impl/.NFInstanceIDDocumentApiImpl.cpp.swp
+0
-0
impl/NFInstanceIDDocumentApiImpl.cpp
impl/NFInstanceIDDocumentApiImpl.cpp
+19
-4
zkH/.get2rdNodeMessage.cpp.swp
zkH/.get2rdNodeMessage.cpp.swp
+0
-0
zkH/get2rdNodeMessage.cpp
zkH/get2rdNodeMessage.cpp
+12
-0
zkH/get2rdNodeMessage.h
zkH/get2rdNodeMessage.h
+9
-0
No files found.
api/.NFInstanceIDDocumentApi.cpp.swo
0 → 100644
View file @
7014ac3f
File added
api/NFInstanceIDDocumentApi.cpp
View file @
7014ac3f
...
...
@@ -20,6 +20,10 @@
#include <stdbool.h>
#include <regex>
#include "inforMatch.h"
#include "get2rdNodeMessage.h"
#include <fstream>
#include <iostream>
#include <nlohmann/json.hpp>
namespace
org
{
namespace
openapitools
{
namespace
server
{
...
...
@@ -74,6 +78,7 @@ void NFInstanceIDDocumentApi::deregister_nf_instance_handler(const Pistache::Res
}
void
NFInstanceIDDocumentApi
::
get_nf_instance_handler
(
const
Pistache
::
Rest
::
Request
&
request
,
Pistache
::
Http
::
ResponseWriter
response
)
{
// Getting the path params
try
{
auto
nfInstanceID
=
request
.
param
(
":nfInstanceID"
).
as
<
std
::
string
>
();
std
::
cout
<<
"get_nf_instance_handler启动了"
<<
std
::
endl
;
std
::
cout
<<
"nfInstanceID是: "
<<
nfInstanceID
<<
std
::
endl
;
...
...
@@ -144,25 +149,87 @@ void NFInstanceIDDocumentApi::get_nf_instance_handler(const Pistache::Rest::Requ
std
::
cout
<<
testJ
<<
std
::
endl
;
/*
*
取出某二级节点下的显性信息
*
取出type节点下的信息,包含此type的全部instanceId,用分号间隔
*/
std
::
string
instancePath
=
"/AMF/duklAMF"
;
//可以更改
inforMatch
InforMatch
;
bool
restBool
=
InforMatch
.
ifIsMatching
(
instancePath
,
jsonInformation
);
//判断实例duklAMF是否是要寻找的
if
(
restBool
)
printf
(
"匹配成功!"
);
else
printf
(
"匹配失败!"
);
//先取出2级节点下的全部instanceId信息字符串
get2rdNodeMessage
Get2rdNodeMessage
;
std
::
string
path_NfType
=
"/"
+
targetNfTypeString
;
//要取出的2级节点路径,即NF类型
std
::
string
NFInstanceIdsString
=
Get2rdNodeMessage
.
getNodeMessage
(
path_NfType
);
//取出信息格式为: duklAMF;mxcAMF;
//string转char数组,检验分号";",转化为单个string
int
NodeMessageSize
=
NFInstanceIdsString
.
size
();
//std::cout << "NodeMessageSize is : " << NodeMessageSize << std::endl;
char
NFInstanceIdsChar
[
NodeMessageSize
];
strcpy
(
NFInstanceIdsChar
,
NFInstanceIdsString
.
c_str
());
int
ArraySubscript
=
0
;
std
::
string
OneOfInstanceId
;
std
::
string
responseBodyProfile
;
int
numberFlag
=
0
;
for
(
;
ArraySubscript
<
NodeMessageSize
;
ArraySubscript
++
){
if
(
NFInstanceIdsChar
[
ArraySubscript
]
!=
59
/*分号的ASCLL码为59*/
){
std
::
string
s
(
NFInstanceIdsString
,
ArraySubscript
,
1
);
OneOfInstanceId
=
OneOfInstanceId
+
s
;
}
else
{
//遇到分号了,此时OneOfInstanceId中存的信息是上一个instanceId
/*
* 处理刚刚取出的一个三级节点路径,判断是否匹配
*/
std
::
string
instancePath
=
path_NfType
;
instancePath
=
instancePath
+
"/"
+
OneOfInstanceId
;
inforMatch
InforMatch
;
bool
restBool
=
InforMatch
.
ifIsMatching
(
instancePath
,
jsonInformation
);
if
(
restBool
){
printf
(
"匹配成功!"
);
numberFlag
=
numberFlag
+
1
;
//使用三节节点名称取出对应配置文件
std
::
string
fileName
=
OneOfInstanceId
+
".json"
;
std
::
ifstream
readProfile
(
fileName
);
nlohmann
::
json
thisProfileJson
;
readProfile
>>
thisProfileJson
;
std
::
string
thisProfileString
=
thisProfileJson
.
dump
();
//std::cout << "*****************************************thisProfileJson:::::" << thisProfileJson << std::endl;
//response.send(Pistache::Http::Code::Ok, "Do some magic1\n");
//response.send(Pistache::Http::Code::Ok, thisProfileString);
responseBodyProfile
=
responseBodyProfile
+
thisProfileString
;
//goto endPoint;
OneOfInstanceId
=
""
;
}
else
{
OneOfInstanceId
=
""
;
}
}
}
//endPoint: std::cout << "匹配循环已结束!" << std::endl;
std
::
string
responseBody
=
"{
\"
validityPeriod
\"
:
\"
3600
\"
,
\"
nfInstances
\"
:"
;
//{"validityPeriod":"3600","nfInstances":
if
(
numberFlag
>
1
)
responseBodyProfile
=
"{"
+
responseBodyProfile
+
"}"
;
responseBody
=
responseBody
+
responseBodyProfile
+
"}"
;
// {"validityPeriod":"3600","nfInstances":{responseBodyProfile}}
//response的M部分添加完毕
//searchId,numNfInstComplete,nrfSupportedFeatures三个属性未加
response
.
send
(
Pistache
::
Http
::
Code
::
Ok
,
responseBody
);
std
::
cout
<<
aS
<<
std
::
endl
;
std
::
cout
<<
nFType
.
nfType
<<
std
::
endl
;
}
catch
(
nlohmann
::
detail
::
exception
&
e
)
{
//send a 400 error
response
.
send
(
Pistache
::
Http
::
Code
::
Bad_Request
,
e
.
what
());
return
;
}
catch
(
Pistache
::
Http
::
HttpError
&
e
)
{
response
.
send
(
static_cast
<
Pistache
::
Http
::
Code
>
(
e
.
code
()),
e
.
what
());
return
;
}
catch
(
std
::
exception
&
e
)
{
//send a 500 error
response
.
send
(
Pistache
::
Http
::
Code
::
Internal_Server_Error
,
e
.
what
());
return
;
}
try
{
/* try {
this->get_nf_instance(nfInstanceID, response);
} catch (nlohmann::detail::exception &e) {
//send a 400 error
...
...
@@ -176,7 +243,7 @@ void NFInstanceIDDocumentApi::get_nf_instance_handler(const Pistache::Rest::Requ
response.send(Pistache::Http::Code::Internal_Server_Error, e.what());
return;
}
*/
}
void
NFInstanceIDDocumentApi
::
register_nf_instance_handler
(
const
Pistache
::
Rest
::
Request
&
request
,
Pistache
::
Http
::
ResponseWriter
response
)
{
// Getting the path params
...
...
impl/.NFInstanceIDDocumentApiImpl.cpp.swp
0 → 100644
View file @
7014ac3f
File added
impl/NFInstanceIDDocumentApiImpl.cpp
View file @
7014ac3f
...
...
@@ -57,7 +57,7 @@ void NFInstanceIDDocumentApiImpl::register_nf_instance(const std::string &nfInst
//以上为测试内容
//j.erase("");删除无用标志信息剩余有用信息的json
j
.
erase
(
"nfStatus"
);
//
j.erase("nfStatus");
//将剩余的有用信息化为string
//std::string jS = j.dump();
...
...
@@ -67,10 +67,12 @@ void NFInstanceIDDocumentApiImpl::register_nf_instance(const std::string &nfInst
std
::
string
nfInstanceId
;
j
.
at
(
"nfInstanceId"
).
get_to
(
nfInstanceId
);
std
::
string
pointJson
=
".json"
;
std
::
string
pointTXT
=
".txt"
;
std
::
string
value
;
value
=
nfInstanceId
+
pointJson
;
//Value 文件名
std
::
ofstream
myfile
(
value
);
std
::
string
jString
=
j
.
dump
();
myfile
<<
std
::
setw
(
75
)
<<
j
<<
std
::
endl
;
zookeeperClient
zooK
;
...
...
@@ -110,15 +112,28 @@ void NFInstanceIDDocumentApiImpl::register_nf_instance(const std::string &nfInst
//std::string nfType
;
//std::string nfType
//j.at("nfType").get_to(nfType);
std
::
string
path
;
std
::
string
fullPath
;
path
=
source
+
nfType
;
path
=
source
+
nfType
;
//初始化2级节点
fullPath
=
path
+
"/"
+
nfInstanceId
;
//fullPath是每一个实例的全部路径,包含关键信息
cout
<<
" path: "
<<
path
<<
endl
;
bool
b
;
b
=
Register
.
registerZK
(
"this_is_A_nfType"
,
path
,
zk
);
/*
* 二级节点应该已经初始化完毕
* b = Register.registerZK("/", path, zk);
*
*/
/*初始化二级节点用 b = Register.registerZK("", path, zk); */
/**/
std
::
string
getValue
;
utility
::
zoo_rc
getRet
=
zk
->
get_node
(
path
.
c_str
(),
getValue
,
nullptr
,
true
);
//取出type节点下的信息放在getValue中
getValue
=
getValue
+
nfInstanceId
+
";"
;
utility
::
zoo_rc
setRet
=
zk
->
set_node
(
path
.
c_str
(),
getValue
,
-
1
);
/**/
b
=
Register
.
registerZK
(
InforValue
,
fullPath
,
zk
);
response
.
send
(
Pistache
::
Http
::
Code
::
Ok
,
"Do some magic
\n
"
);
}
...
...
zkH/.get2rdNodeMessage.cpp.swp
0 → 100644
View file @
7014ac3f
File added
zkH/get2rdNodeMessage.cpp
0 → 100644
View file @
7014ac3f
#include "get2rdNodeMessage.h"
#include "zookeeperClient.h"
#include <stdbool.h>
std
::
string
get2rdNodeMessage
::
getNodeMessage
(
std
::
string
path
){
std
::
string
value
;
zookeeperClient
zooK
;
bool
atest
=
zooK
.
connect2ZKServer
(
"192.168.110.129:2181"
);
utility
::
zk_cpp
*
zk
;
zk
=
zooK
.
getZk
();
utility
::
zoo_rc
ret
=
zk
->
get_node
(
path
.
c_str
(),
value
,
nullptr
,
true
);
return
value
;
}
zkH/get2rdNodeMessage.h
0 → 100644
View file @
7014ac3f
#include <stdio.h>
#include <stdbool.h>
#include <string>
#include <iostream>
#include <nlohmann/json.hpp>
class
get2rdNodeMessage
{
public:
std
::
string
getNodeMessage
(
std
::
string
path
);
};
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment