Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Cameo
cameo
Commits
3bec52f5
Commit
3bec52f5
authored
Oct 21, 2020
by
legoc
Browse files
(split) Implemented ports request in APIs
parent
5b4a4ec8
Changes
7
Hide whitespace changes
Inline
Side-by-side
include/Application.h
View file @
3bec52f5
...
...
@@ -579,6 +579,26 @@ private:
std
::
string
m_name
;
};
///////////////////////////////////////////////////////////////////////////
// Port
class
Port
{
friend
std
::
ostream
&
operator
<<
(
std
::
ostream
&
,
const
Port
&
);
public:
Port
(
int
port
,
const
std
::
string
&
status
,
const
std
::
string
&
application
);
int
getPort
()
const
;
const
std
::
string
&
getStatus
()
const
;
const
std
::
string
&
getApplication
()
const
;
private:
int
m_port
;
std
::
string
m_status
;
std
::
string
m_application
;
};
std
::
string
toString
(
cameo
::
application
::
State
applicationStates
);
std
::
ostream
&
operator
<<
(
std
::
ostream
&
,
const
cameo
::
application
::
This
&
);
std
::
ostream
&
operator
<<
(
std
::
ostream
&
,
const
cameo
::
application
::
Instance
&
);
...
...
@@ -589,6 +609,7 @@ std::ostream& operator<<(std::ostream&, const cameo::application::Responder&);
std
::
ostream
&
operator
<<
(
std
::
ostream
&
,
const
cameo
::
application
::
Requester
&
);
std
::
ostream
&
operator
<<
(
std
::
ostream
&
,
const
cameo
::
application
::
Configuration
&
);
std
::
ostream
&
operator
<<
(
std
::
ostream
&
,
const
cameo
::
application
::
Info
&
);
std
::
ostream
&
operator
<<
(
std
::
ostream
&
,
const
cameo
::
application
::
Port
&
);
}
}
...
...
include/Server.h
View file @
3bec52f5
...
...
@@ -91,6 +91,11 @@ public:
*/
std
::
vector
<
application
::
Info
>
getApplicationInfos
(
const
std
::
string
&
name
)
const
;
/**
* throws ConnectionTimeout
*/
std
::
vector
<
application
::
Port
>
getApplicationPorts
()
const
;
/**
* throws ConnectionTimeout
*/
...
...
src/Application.cpp
View file @
3bec52f5
...
...
@@ -1249,6 +1249,27 @@ int Info::getPid() const {
return
m_pid
;
}
///////////////////////////////////////////////////////////////////////////
// Port
Port
::
Port
(
int
port
,
const
std
::
string
&
status
,
const
std
::
string
&
application
)
:
m_port
(
port
),
m_status
(
status
),
m_application
(
application
)
{
}
int
Port
::
getPort
()
const
{
return
m_port
;
}
const
std
::
string
&
Port
::
getStatus
()
const
{
return
m_status
;
}
const
std
::
string
&
Port
::
getApplication
()
const
{
return
m_application
;
}
std
::
string
toString
(
cameo
::
application
::
State
applicationStates
)
{
vector
<
string
>
states
;
...
...
@@ -1395,5 +1416,14 @@ std::ostream& operator<<(std::ostream& os, const application::Info& info) {
return
os
;
}
std
::
ostream
&
operator
<<
(
std
::
ostream
&
os
,
const
application
::
Port
&
port
)
{
os
<<
"[port="
<<
port
.
m_port
<<
", status="
<<
port
.
m_status
<<
", application="
<<
port
.
m_application
<<
"]"
;
return
os
;
}
}
}
src/Server.cpp
View file @
3bec52f5
...
...
@@ -384,8 +384,8 @@ std::vector<application::Info> Server::getApplicationInfos() const {
json
::
Object
response
;
json
::
parse
(
response
,
reply
.
get
());
json
::
Value
&
applicationInfo
=
response
[
message
::
ApplicationInfoListResponse
::
APPLICATION_INFO
];
json
::
Value
::
Array
array
=
applicationInfo
.
GetArray
();
json
::
Value
&
applicationInfo
s
=
response
[
message
::
ApplicationInfoListResponse
::
APPLICATION_INFO
];
json
::
Value
::
Array
array
=
applicationInfo
s
.
GetArray
();
size_t
size
=
array
.
Size
();
for
(
int
i
=
0
;
i
<
size
;
++
i
)
{
...
...
@@ -426,6 +426,35 @@ std::vector<application::Info> Server::getApplicationInfos(const std::string& na
return
infos
;
}
std
::
vector
<
application
::
Port
>
Server
::
getApplicationPorts
()
const
{
vector
<
application
::
Port
>
ports
;
unique_ptr
<
zmq
::
message_t
>
reply
=
m_requestSocket
->
request
(
m_impl
->
createPortsRequest
());
// Get the JSON response.
json
::
Object
response
;
json
::
parse
(
response
,
reply
.
get
());
json
::
Value
&
portInfos
=
response
[
message
::
PortInfoListResponse
::
PORT_INFO
];
json
::
Value
::
Array
array
=
portInfos
.
GetArray
();
size_t
size
=
array
.
Size
();
for
(
int
i
=
0
;
i
<
size
;
++
i
)
{
json
::
Value
::
Object
info
=
array
[
i
].
GetObject
();
int
port
=
info
[
message
::
PortInfo
::
PORT
].
GetInt
();
string
status
=
info
[
message
::
PortInfo
::
STATUS
].
GetString
();
string
application
=
info
[
message
::
PortInfo
::
APPLICATION
].
GetString
();
application
::
Port
portInfo
(
port
,
status
,
application
);
ports
.
push_back
(
portInfo
);
}
return
ports
;
}
application
::
State
Server
::
getActualState
(
int
id
)
const
{
unique_ptr
<
zmq
::
message_t
>
reply
=
m_requestSocket
->
request
(
m_impl
->
createGetStatusRequest
(
id
));
...
...
src/impl/ServicesImpl.cpp
View file @
3bec52f5
...
...
@@ -508,6 +508,15 @@ std::string ServicesImpl::createReleasePortRequest(int id, int port) {
return
request
.
toString
();
}
std
::
string
ServicesImpl
::
createPortsRequest
()
const
{
json
::
StringObject
request
;
request
.
pushKey
(
message
::
TYPE
);
request
.
pushInt
(
message
::
PORTS
);
return
request
.
toString
();
}
zmq
::
socket_t
*
ServicesImpl
::
createEventSubscriber
(
const
std
::
string
&
endpoint
,
const
std
::
string
&
cancelEndpoint
)
{
zmq
::
socket_t
*
subscriber
=
new
zmq
::
socket_t
(
m_context
,
ZMQ_SUB
);
...
...
src/impl/ServicesImpl.h
View file @
3bec52f5
...
...
@@ -68,6 +68,7 @@ public:
std
::
string
createRequestPortRequest
(
int
id
);
std
::
string
createPortUnavailableRequest
(
int
id
,
int
port
);
std
::
string
createReleasePortRequest
(
int
id
,
int
port
);
std
::
string
createPortsRequest
()
const
;
zmq
::
socket_t
*
createEventSubscriber
(
const
std
::
string
&
endpoint
,
const
std
::
string
&
cancelEndpoint
);
zmq
::
socket_t
*
createOutputStreamSubscriber
(
const
std
::
string
&
endpoint
,
const
std
::
string
&
cancelEndpoint
);
...
...
src/message/Message.h
View file @
3bec52f5
...
...
@@ -302,7 +302,7 @@ namespace message {
namespace
PortInfo
{
constexpr
const
char
*
PORT
=
"port"
;
// int32
constexpr
const
char
*
STATUS
=
"status"
;
// string
constexpr
const
char
*
APPLICATION
_NAME_ID
=
"application
NameId
"
;
// string
constexpr
const
char
*
APPLICATION
=
"application"
;
// string
}
namespace
PortInfoListResponse
{
...
...
Shervin Nourbakhsh
@nourbakhsh
mentioned in commit
46e44691
·
Apr 23, 2021
mentioned in commit
46e44691
mentioned in commit 46e44691a03808a23a464818487b0dd014a9c57e
Toggle commit list
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