Commit 3416699b authored by legoc's avatar legoc
Browse files

(split) Starter info is used

parent 2324f6f4
......@@ -172,7 +172,6 @@ public:
private:
void initApplication(int argc, char *argv[]);
static std::string getReference();
static State parseState(const std::string& value);
State getState(int id) const;
......@@ -190,7 +189,7 @@ private:
int m_id;
bool m_managed;
std::string m_starterEndpoint;
Endpoint m_starterEndpoint;
std::string m_starterName;
int m_starterId;
......
......@@ -115,15 +115,6 @@ void This::init(int argc, char *argv[]) {
}
}
std::string This::getReference() {
if (m_instance.m_impl != nullptr) {
ostringstream os;
os << getName() << "." << getId() << "@" << getEndpoint();
return os.str();
}
return "";
}
void This::terminate() {
// Test if termination is already done.
......@@ -161,18 +152,7 @@ void This::initApplication(int argc, char *argv[]) {
string info(argv[argc - 1]);
// vector<string> tokens = split(info);
//
// if (tokens.size() < 4) {
// throw InvalidArgumentException(info + " is not a valid argument");
// }
//
// m_url = tokens[0] + ":" + tokens[1];
//
// string port = tokens[2];
// istringstream is(port);
// is >> m_port;
// Get the info object.
json::Object infoObject;
json::parse(infoObject, info);
......@@ -184,55 +164,39 @@ void This::initApplication(int argc, char *argv[]) {
// Retrieve the server version.
Services::retrieveServerVersion();
// string nameId = tokens[3];
//
// int index = nameId.find_last_of('.');
// Get the name.
m_name = infoObject[message::ApplicationIdentity::NAME].GetString();
// // Search for the . character meaning that the application is managed and already has an id.
// if (index != string::npos) {
// Managed apps have the id key.
if (infoObject.HasMember(message::ApplicationIdentity::ID)) {
m_managed = true;
// m_name = nameId.substr(0, index);
// string sid = nameId.substr(index + 1);
// {
// istringstream is(sid);
// is >> m_id;
// }
m_id = infoObject[message::ApplicationIdentity::ID].GetInt();
}
else {
m_managed = false;
// m_name = nameId;
m_id = initUnmanagedApplication();
if (m_id == -1) {
int id = initUnmanagedApplication();
if (id == -1) {
throw UnmanagedApplicationException(string("Maximum number of applications ") + m_name + " reached");
}
m_id = id;
}
// if (tokens.size() >= 7) {
// index = tokens[4].find_last_of('@');
// m_starterEndpoint = tokens[4].substr(index + 1) + ":" + tokens[5] + ":" + tokens[6];
// string starterNameId = tokens[4].substr(0, index);
// index = starterNameId.find_last_of('.');
// m_starterName = starterNameId.substr(0, index);
// string sid = starterNameId.substr(index + 1);
// {
// istringstream is(sid);
// is >> m_starterId;
// }
// }
// Get the starter info if it is present.
if (infoObject.HasMember(message::ApplicationIdentity::STARTER)) {
json::Value& starterValue = infoObject[message::ApplicationIdentity::STARTER];
m_starterEndpoint = Endpoint::parse(starterValue[message::ApplicationIdentity::SERVER].GetString());
m_starterName = starterValue[message::ApplicationIdentity::NAME].GetString();
m_starterId = starterValue[message::ApplicationIdentity::ID].GetInt();
}
// Must be here because the server endpoint is required.
initStatus();
// Create the local server
// Create the local server.
m_server = unique_ptr<Server>(new Server(m_serverEndpoint));
// Create the starter server
if (m_starterEndpoint != "") {
// Create the starter server.
if (m_starterEndpoint.getAddress() != "") {
m_starterServer = unique_ptr<Server>(new Server(m_starterEndpoint));
}
......@@ -250,7 +214,7 @@ void This::initApplication(int argc, char *argv[]) {
cout << "endpoint = " << m_serverEndpoint.toString() << endl;
cout << "name = " << m_name << endl;
cout << "id = " << m_id << endl;
cout << "starterEndpoint = " << m_starterEndpoint << endl;
cout << "starterEndpoint = " << m_starterEndpoint.toString() << endl;
cout << "starterName = " << m_starterName << endl;
cout << "starterId = " << m_starterId << endl;
}
......
......@@ -147,7 +147,7 @@ std::unique_ptr<application::Instance> Server::start(const std::string& name, co
streamSocket = createOutputStreamSocket(name);
}
unique_ptr<zmq::message_t> reply = m_requestSocket->request(m_impl->createStartRequest(name, args, application::This::getReference()));
unique_ptr<zmq::message_t> reply = m_requestSocket->request(m_impl->createStartRequest(name, args, application::This::getName(), application::This::getId(), application::This::getEndpoint().toString()));
// Get the JSON response.
json::Object response;
......
......@@ -105,7 +105,10 @@ Endpoint Endpoint::withPort(int port) const {
}
std::string Endpoint::toString() const {
return m_protocol + "://" + m_address + ":" + to_string(m_port);
if (m_address != "") {
return m_protocol + "://" + m_address + ":" + to_string(m_port);
}
return "";
}
ApplicationIdentity::ApplicationIdentity(const std::string& name, int id, const Endpoint& endpoint) :
......
......@@ -95,7 +95,7 @@ std::string ServicesImpl::createIsAliveRequest(int id) const {
return request.toString();
}
std::string ServicesImpl::createStartRequest(const std::string& name, const std::vector<std::string> & args, const std::string& instanceReference) const {
std::string ServicesImpl::createStartRequest(const std::string& name, const std::vector<std::string> & args, const std::string& thisName, int thisId, const std::string& thisEndpoint) const {
json::StringObject request;
request.pushKey(message::TYPE);
......@@ -111,8 +111,22 @@ std::string ServicesImpl::createStartRequest(const std::string& name, const std:
}
request.endArray();
request.pushKey(message::StartRequest::STARTER);
request.pushString(instanceReference);
if (thisId != -1) {
request.pushKey(message::StartRequest::STARTER);
request.startObject();
request.pushKey(message::ApplicationIdentity::NAME);
request.pushString(thisName);
request.pushKey(message::ApplicationIdentity::ID);
request.pushInt(thisId);
request.pushKey(message::ApplicationIdentity::SERVER);
request.pushString(thisEndpoint);
request.endObject();
}
return request.toString();
}
......
......@@ -37,7 +37,7 @@ public:
std::string createSyncRequest() const;
std::string createSyncStreamRequest(const std::string& name) const;
std::string createVersionRequest() const;
std::string createStartRequest(const std::string& name, const std::vector<std::string> & args, const std::string& instanceReference) const;
std::string createStartRequest(const std::string& name, const std::vector<std::string> & args, const std::string& thisName, int thisId, const std::string& thisEndpoint) const;
std::string createStopRequest(int id) const;
std::string createKillRequest(int id) const;
std::string createConnectRequest(const std::string& name) const;
......
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