summaryrefslogtreecommitdiff
path: root/cpp/src
diff options
context:
space:
mode:
authorBenoit Foucher <benoit@zeroc.com>2002-09-04 19:23:32 +0000
committerBenoit Foucher <benoit@zeroc.com>2002-09-04 19:23:32 +0000
commitbdeb0007e50f676bf416ca25c493c888548ea7cd (patch)
treef7f25ecd302b273e31d80a420e5667b40900a267 /cpp/src
parentTemporary fix to use binary freeze db (diff)
downloadice-bdeb0007e50f676bf416ca25c493c888548ea7cd.tar.bz2
ice-bdeb0007e50f676bf416ca25c493c888548ea7cd.tar.xz
ice-bdeb0007e50f676bf416ca25c493c888548ea7cd.zip
Added local exceptions ObjectAdapterActiveException and
ObjectAdapterNotRegisteredException. :LocatoRegistry::addAdapter method to setAdapterDirectProxy. Minor IcePack fixes.
Diffstat (limited to 'cpp/src')
-rw-r--r--cpp/src/Ice/Exception.cpp14
-rw-r--r--cpp/src/Ice/ObjectAdapterI.cpp13
-rw-r--r--cpp/src/IcePack/ActivatorI.cpp26
-rw-r--r--cpp/src/IcePack/ApplicationBuilder.cpp11
-rw-r--r--cpp/src/IcePack/ComponentBuilder.cpp4
-rw-r--r--cpp/src/IcePack/Grammar.y5
-rw-r--r--cpp/src/IcePack/LocatorRegistryI.cpp30
-rw-r--r--cpp/src/IcePack/LocatorRegistryI.h2
-rw-r--r--cpp/src/IcePack/Parser.cpp22
-rw-r--r--cpp/src/IcePack/Parser.h1
-rw-r--r--cpp/src/IcePack/Scanner.l4
-rw-r--r--cpp/src/IcePack/ServerAdapterI.cpp5
-rw-r--r--cpp/src/IcePack/ServerBuilder.cpp7
-rw-r--r--cpp/src/IcePack/ServerDeployerI.cpp19
-rw-r--r--cpp/src/IcePack/ServerI.cpp61
15 files changed, 163 insertions, 61 deletions
diff --git a/cpp/src/Ice/Exception.cpp b/cpp/src/Ice/Exception.cpp
index 0f64228c893..baa65868bf0 100644
--- a/cpp/src/Ice/Exception.cpp
+++ b/cpp/src/Ice/Exception.cpp
@@ -75,6 +75,20 @@ Ice::ObjectAdapterDeactivatedException::ice_print(ostream& out) const
}
void
+Ice::ObjectAdapterActiveException::ice_print(ostream& out) const
+{
+ Exception::ice_print(out);
+ out << ":\nobject adapter already active";
+}
+
+void
+Ice::ObjectAdapterNotRegisteredException::ice_print(ostream& out) const
+{
+ Exception::ice_print(out);
+ out << ":\nobject adapter not registered with the locator";
+}
+
+void
Ice::NoEndpointException::ice_print(ostream& out) const
{
Exception::ice_print(out);
diff --git a/cpp/src/Ice/ObjectAdapterI.cpp b/cpp/src/Ice/ObjectAdapterI.cpp
index 932fdb037cb..0089e105b31 100644
--- a/cpp/src/Ice/ObjectAdapterI.cpp
+++ b/cpp/src/Ice/ObjectAdapterI.cpp
@@ -78,7 +78,18 @@ Ice::ObjectAdapterI::activate()
// activate operation instead of a non obvious network
// exception?
//
- _locatorInfo->getLocatorRegistry()->addAdapter(_name, newDirectProxy(ident));
+ try
+ {
+ _locatorInfo->getLocatorRegistry()->setAdapterDirectProxy(_name, newDirectProxy(ident));
+ }
+ catch(const Ice::AdapterNotRegistered&)
+ {
+ throw ObjectAdapterNotRegisteredException(__FILE__, __LINE__);
+ }
+ catch(const Ice::AdapterAlreadyActive&)
+ {
+ throw ObjectAdapterActiveException(__FILE__, __LINE__);
+ }
}
}
diff --git a/cpp/src/IcePack/ActivatorI.cpp b/cpp/src/IcePack/ActivatorI.cpp
index 7628fb8fa7c..3a6fabe53b9 100644
--- a/cpp/src/IcePack/ActivatorI.cpp
+++ b/cpp/src/IcePack/ActivatorI.cpp
@@ -287,12 +287,20 @@ IcePack::ActivatorI::activate(const ServerPtr& server)
void
IcePack::ActivatorI::deactivate(const ServerPtr& server)
{
- pid_t pid = static_cast<pid_t>(server->getPid());
-
+ Ice::Int pid = server->getPid();
+
+ if(pid == 0)
+ {
+ //
+ // Server is already deactivated.
+ //
+ return;
+ }
+
//
// Send a SIGTERM to the process.
//
- if(::kill(pid, SIGTERM))
+ if(::kill(static_cast<pid_t>(pid), SIGTERM))
{
SyscallException ex(__FILE__, __LINE__);
ex.error = getSystemErrno();
@@ -309,12 +317,20 @@ IcePack::ActivatorI::deactivate(const ServerPtr& server)
void
IcePack::ActivatorI::kill(const ServerPtr& server)
{
- pid_t pid = static_cast<pid_t>(server->getPid());
+ Ice::Int pid = server->getPid();
+ if(pid == 0)
+ {
+ //
+ // Server is already deactivated.
+ //
+ return;
+ }
+
//
// Send a SIGKILL to the process.
//
- if(::kill(pid, SIGKILL))
+ if(::kill(static_cast<pid_t>(pid), SIGKILL))
{
SyscallException ex(__FILE__, __LINE__);
ex.error = getSystemErrno();
diff --git a/cpp/src/IcePack/ApplicationBuilder.cpp b/cpp/src/IcePack/ApplicationBuilder.cpp
index 6fae0a27dc2..687a1e11150 100644
--- a/cpp/src/IcePack/ApplicationBuilder.cpp
+++ b/cpp/src/IcePack/ApplicationBuilder.cpp
@@ -20,9 +20,10 @@ class AddServer : public Task
{
public:
- AddServer(const ServerDeployerPrx& deployer, const string& name, const string& descriptor, const string& binpath,
- const string& libpath, const Targets& targets) :
+ AddServer(const ServerDeployerPrx& deployer, const string& node, const string& name, const string& descriptor,
+ const string& binpath, const string& libpath, const Targets& targets) :
_deployer(deployer),
+ _node(node),
_name(name),
_descriptor(descriptor),
_binpath(binpath),
@@ -46,6 +47,7 @@ public:
ServerDeploymentException ex;
ex.server = _name;
ex.reason = os.str();
+ ex.component = _node + "." + _name;
throw ex;
}
}
@@ -65,6 +67,7 @@ public:
ServerDeploymentException ex;
ex.server = _name;
ex.reason = os.str();
+ ex.component = _node + "." + _name;
throw ex;
}
catch(const Ice::LocalException& lex)
@@ -75,6 +78,7 @@ public:
ServerDeploymentException ex;
ex.server = _name;
ex.reason = os.str();
+ ex.component = _node + "." + _name;
throw ex;
}
}
@@ -82,6 +86,7 @@ public:
private:
ServerDeployerPrx _deployer;
+ string _node;
string _name;
string _descriptor;
string _binpath;
@@ -237,7 +242,7 @@ IcePack::ApplicationBuilder::addServer(const string& name,
try
{
ServerDeployerPrx deployer = node->getServerDeployer();
- _tasks.push_back(new AddServer(deployer, name, descriptor, binpath, libpath, _targets));
+ _tasks.push_back(new AddServer(deployer, nodeName, name, descriptor, binpath, libpath, _targets));
}
catch(::Ice::LocalException&)
{
diff --git a/cpp/src/IcePack/ComponentBuilder.cpp b/cpp/src/IcePack/ComponentBuilder.cpp
index b97565f8422..0dd68963fb4 100644
--- a/cpp/src/IcePack/ComponentBuilder.cpp
+++ b/cpp/src/IcePack/ComponentBuilder.cpp
@@ -679,8 +679,8 @@ IcePack::ComponentBuilder::undo()
catch(const DeploymentException& ex)
{
ostringstream os;
- os << "exception while removing component " << _componentPath << ":\n";
- os << ex << ": " << ex.reason;
+ os << "exception while removing component " << (ex.component.empty() ? _componentPath : ex.component);
+ os << ":\n" << ex << ": " << ex.reason;
_communicator->getLogger()->warning(os.str());
}
diff --git a/cpp/src/IcePack/Grammar.y b/cpp/src/IcePack/Grammar.y
index 607bb730964..0b4f6e5a6ad 100644
--- a/cpp/src/IcePack/Grammar.y
+++ b/cpp/src/IcePack/Grammar.y
@@ -49,6 +49,7 @@ yyerror(const char* s)
%token ICE_PACK_STOP
%token ICE_PACK_DESCRIBE
%token ICE_PACK_STATE
+%token ICE_PACK_PID
%token ICE_PACK_ENDPOINTS
%%
@@ -126,6 +127,10 @@ command
{
parser->stateServer($3);
}
+| ICE_PACK_SERVER ICE_PACK_PID strings ';'
+{
+ parser->pidServer($3);
+}
| ICE_PACK_SERVER ICE_PACK_REMOVE strings ';'
{
parser->removeServer($3);
diff --git a/cpp/src/IcePack/LocatorRegistryI.cpp b/cpp/src/IcePack/LocatorRegistryI.cpp
index f1c7abfb9f4..ebe793821c3 100644
--- a/cpp/src/IcePack/LocatorRegistryI.cpp
+++ b/cpp/src/IcePack/LocatorRegistryI.cpp
@@ -22,7 +22,7 @@ IcePack::LocatorRegistryI::LocatorRegistryI(const AdapterRegistryPtr& registry,
}
void
-IcePack::LocatorRegistryI::addAdapter(const string& name, const Ice::ObjectPrx& proxy, const Ice::Current&)
+IcePack::LocatorRegistryI::setAdapterDirectProxy(const string& name, const Ice::ObjectPrx& proxy, const Ice::Current&)
{
while(true)
{
@@ -39,13 +39,7 @@ IcePack::LocatorRegistryI::addAdapter(const string& name, const Ice::ObjectPrx&
}
catch(const AdapterActiveException&)
{
- //
- // TODO: we have to do something here. We can't just let
- // the server try to override the direct proxy of an
- // active adapter without saying anything. We need to
- // throw here to prevent the server from starting.
- //
- return;
+ throw Ice::AdapterAlreadyActive();
}
catch(const Ice::ObjectNotExistException&)
{
@@ -60,7 +54,7 @@ IcePack::LocatorRegistryI::addAdapter(const string& name, const Ice::ObjectPrx&
// is possibly because the IcePack node is down and
// the server is started manually for example. We
// should probably throw here to prevent the server
- // from starting.
+ // from starting?
//
return;
}
@@ -83,14 +77,22 @@ IcePack::LocatorRegistryI::addAdapter(const string& name, const Ice::ObjectPrx&
// didn't previously registered its object adapters (using the
// IcePack deployment mechanism).
//
- AdapterPrx adapter = AdapterPrx::uncheckedCast(_adapter->addWithUUID(new StandaloneAdapterI()));
- try
+ Ice::PropertiesPtr properties = _adapter->getCommunicator()->getProperties();
+ if(properties->getPropertyAsInt("IcePack.Registry.AllowNotRegisteredAdapters") > 0)
{
- _registry->add(name, adapter);
+ AdapterPrx adapter = AdapterPrx::uncheckedCast(_adapter->addWithUUID(new StandaloneAdapterI()));
+ try
+ {
+ _registry->add(name, adapter);
+ }
+ catch(const AdapterExistsException&)
+ {
+ _adapter->remove(adapter->ice_getIdentity());
+ }
}
- catch(const AdapterExistsException&)
+ else
{
- _adapter->remove(adapter->ice_getIdentity());
+ throw Ice::AdapterNotRegistered();
}
}
}
diff --git a/cpp/src/IcePack/LocatorRegistryI.h b/cpp/src/IcePack/LocatorRegistryI.h
index b84b5083bcc..a3a0e484109 100644
--- a/cpp/src/IcePack/LocatorRegistryI.h
+++ b/cpp/src/IcePack/LocatorRegistryI.h
@@ -24,7 +24,7 @@ public:
LocatorRegistryI(const AdapterRegistryPtr&, const Ice::ObjectAdapterPtr&);
- virtual void addAdapter(const ::std::string&, const ::Ice::ObjectPrx&, const ::Ice::Current&);
+ virtual void setAdapterDirectProxy(const ::std::string&, const ::Ice::ObjectPrx&, const ::Ice::Current&);
private:
diff --git a/cpp/src/IcePack/Parser.cpp b/cpp/src/IcePack/Parser.cpp
index 1fba9a89a86..28e2e033597 100644
--- a/cpp/src/IcePack/Parser.cpp
+++ b/cpp/src/IcePack/Parser.cpp
@@ -59,6 +59,7 @@ IcePack::Parser::usage()
" deployed.\n"
"server describe NAME Get server NAME description.\n"
"server state NAME Get server NAME state.\n"
+ "server pid NAME Get server NAME pid.\n"
"server start NAME Starts server NAME.\n"
"server stop NAME Stop server NAME.\n"
"server remove NAME Remove server NAME.\n"
@@ -406,6 +407,27 @@ IcePack::Parser::stateServer(const list<string>& args)
}
void
+IcePack::Parser::pidServer(const list<string>& args)
+{
+ if(args.size() != 1)
+ {
+ error("`server pid' requires exactly one argument\n(`help' for more info)");
+ return;
+ }
+
+ try
+ {
+ cout << _admin->getServerPid(args.front()) << endl;
+ }
+ catch(const Exception& ex)
+ {
+ ostringstream s;
+ s << ex;
+ error(s.str());
+ }
+}
+
+void
IcePack::Parser::listAllServers()
{
try
diff --git a/cpp/src/IcePack/Parser.h b/cpp/src/IcePack/Parser.h
index 45affe567ec..d1ce46e4158 100644
--- a/cpp/src/IcePack/Parser.h
+++ b/cpp/src/IcePack/Parser.h
@@ -79,6 +79,7 @@ public:
void stopServer(const std::list<std::string>&);
void describeServer(const std::list<std::string>&);
void stateServer(const std::list<std::string>&);
+ void pidServer(const std::list<std::string>&);
void removeServer(const std::list<std::string>&);
void listAllServers();
diff --git a/cpp/src/IcePack/Scanner.l b/cpp/src/IcePack/Scanner.l
index 8e296b642da..ee00147b0c6 100644
--- a/cpp/src/IcePack/Scanner.l
+++ b/cpp/src/IcePack/Scanner.l
@@ -132,6 +132,10 @@ NL [\n]
return ICE_PACK_STATE;
}
+"pid" {
+ return ICE_PACK_PID;
+}
+
"endpoints" {
return ICE_PACK_ENDPOINTS;
}
diff --git a/cpp/src/IcePack/ServerAdapterI.cpp b/cpp/src/IcePack/ServerAdapterI.cpp
index 5121a6881c6..cbf747f5d8a 100644
--- a/cpp/src/IcePack/ServerAdapterI.cpp
+++ b/cpp/src/IcePack/ServerAdapterI.cpp
@@ -99,7 +99,10 @@ IcePack::ServerAdapterI::setDirectProxy(const Ice::ObjectPrx& prx, const Ice::Cu
// null. We don't allow to overide an existing proxy by another
// non null proxy.
//
- assert(!(prx && _proxy));
+ if(prx && _proxy)
+ {
+ throw AdapterActiveException();
+ }
_proxy = prx;
_notified = true;
diff --git a/cpp/src/IcePack/ServerBuilder.cpp b/cpp/src/IcePack/ServerBuilder.cpp
index 34fbc342f82..9fbdac41272 100644
--- a/cpp/src/IcePack/ServerBuilder.cpp
+++ b/cpp/src/IcePack/ServerBuilder.cpp
@@ -359,7 +359,12 @@ IcePack::ServerBuilder::parse(const std::string& descriptor)
Ice::PropertiesPtr props = _nodeInfo->getCommunicator()->getProperties();
_properties->setProperty("Ice.ProgramName", _variables["name"]);
- _properties->setProperty("Yellow.Query", props->getProperty("IcePack.Yellow.Query"));
+
+ //
+ // TODO: Shall we really generate yellow configuration here?
+ //
+ _properties->setProperty("Yellow.Query",
+ _nodeInfo->getCommunicator()->proxyToString(_nodeInfo->getYellowQuery()));
//
// TODO: we shouldn't generate this in the configuration. See
diff --git a/cpp/src/IcePack/ServerDeployerI.cpp b/cpp/src/IcePack/ServerDeployerI.cpp
index 0aa48dff273..19d495733bd 100644
--- a/cpp/src/IcePack/ServerDeployerI.cpp
+++ b/cpp/src/IcePack/ServerDeployerI.cpp
@@ -59,6 +59,12 @@ IcePack::ServerDeployerI::remove(const string& name, const Ice::Current&)
{
ServerRegistryPrx registry = _nodeInfo->getServerRegistry();
+ //
+ // Component path is used to identify the component. For example:
+ // node1.server1.service3
+ //
+ string componentPath = _nodeInfo->getNode()->getName() + "." + name;
+
ServerPrx server;
try
{
@@ -69,6 +75,7 @@ IcePack::ServerDeployerI::remove(const string& name, const Ice::Current&)
ServerDeploymentException ex;
ex.server = name;
ex.reason = "server doesn't exist";
+ ex.component = componentPath;
throw ex;
}
@@ -83,6 +90,7 @@ IcePack::ServerDeployerI::remove(const string& name, const Ice::Current&)
ServerDeploymentException ex;
ex.server = name;
ex.reason = "server doesn't exist";
+ ex.component = componentPath;
throw ex;
}
@@ -93,8 +101,9 @@ IcePack::ServerDeployerI::remove(const string& name, const Ice::Current&)
{
ServerDeploymentException ex;
ex.server = name;
- ex.reason = "server is not from this node";
- throw ex;
+ ex.reason = "server is not managed by this node";
+ ex.component = componentPath;
+ throw ex;
}
map<string, string> variables;
@@ -102,12 +111,6 @@ IcePack::ServerDeployerI::remove(const string& name, const Ice::Current&)
variables["binpath"] = desc.path; // Required for parsing to succeed.
variables["libpath"] = "";
- //
- // Component path is used to identify the component. For example:
- // node1.server1.service3
- //
- string componentPath = _nodeInfo->getNode()->getName() + "." + name;
-
ServerBuilder builder(_nodeInfo, variables, componentPath, desc.targets);
//
diff --git a/cpp/src/IcePack/ServerI.cpp b/cpp/src/IcePack/ServerI.cpp
index 435fcb92ab2..b98b7c9a453 100644
--- a/cpp/src/IcePack/ServerI.cpp
+++ b/cpp/src/IcePack/ServerI.cpp
@@ -324,32 +324,43 @@ IcePack::ServerI::stopInternal()
// manager to shutdown the server.
//
bool deactivate = true;
+
+ //
+ // TODO: use the service manager to shutdown icebox servers. The
+ // following code should work once it's possible to set an
+ // activation mode on a per adapter basis -- we really don't want
+ // to activate the icebox in this method if it's already
+ // deactivated.
+ //
- if(description.serviceManager)
- {
- try
- {
- //
- // Set a timeout on the service manager proxy and try to
- // shutdown the icebox.
- //
- IceBox::ServiceManagerPrx serviceManager =
- IceBox::ServiceManagerPrx::uncheckedCast(description.serviceManager->ice_timeout(_waitTime));
-
- serviceManager->shutdown();
-
- deactivate = false;
- }
- catch(const Ice::LocalException& ex)
- {
- if(_traceLevels->server > 1)
- {
- Ice::Trace out(_traceLevels->logger, _traceLevels->serverCat);
- out << "couldn't contact the IceBox `" << description.name << "' service manager:\n";
- out << ex;
- }
- }
- }
+// if(description.serviceManager)
+// {
+// if(_state == Deactivating)
+// {
+// try
+// {
+// //
+// // Set a timeout on the service manager proxy and try to
+// // shutdown the icebox.
+// //
+// IceBox::ServiceManagerPrx serviceManager =
+// IceBox::ServiceManagerPrx::uncheckedCast(description.serviceManager->ice_timeout(_waitTime));
+
+// serviceManager->shutdown();
+
+// deactivate = false;
+// }
+// catch(const Ice::LocalException& ex)
+// {
+// if(_traceLevels->server > 1)
+// {
+// Ice::Trace out(_traceLevels->logger, _traceLevels->serverCat);
+// out << "couldn't contact the IceBox `" << description.name << "' service manager:\n";
+// out << ex;
+// }
+// }
+// }
+// }
if(deactivate)
{