Commit 3bec52f5 authored by legoc's avatar legoc
Browse files

(split) Implemented ports request in APIs

parent 5b4a4ec8
......@@ -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&);
}
}
......
......@@ -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
*/
......
......@@ -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;
}
}
}
......@@ -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& applicationInfos = response[message::ApplicationInfoListResponse::APPLICATION_INFO];
json::Value::Array array = applicationInfos.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));
......
......@@ -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);
......
......@@ -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);
......
......@@ -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 = "applicationNameId"; // string
constexpr const char* APPLICATION = "application"; // string
}
namespace PortInfoListResponse {
......
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