summaryrefslogtreecommitdiff
path: root/cpp
diff options
context:
space:
mode:
Diffstat (limited to 'cpp')
-rw-r--r--cpp/slice/IceGrid/Exception.ice11
-rw-r--r--cpp/slice/IceGrid/Observer.ice53
-rw-r--r--cpp/src/IceGrid/Database.cpp13
-rw-r--r--cpp/src/IceGrid/Database.h2
-rw-r--r--cpp/src/IceGrid/ObserverSessionI.cpp17
-rw-r--r--cpp/src/IceGrid/ObserverSessionI.h2
-rw-r--r--cpp/test/IceGrid/session/AllTests.cpp41
7 files changed, 64 insertions, 75 deletions
diff --git a/cpp/slice/IceGrid/Exception.ice b/cpp/slice/IceGrid/Exception.ice
index ef0ca08930c..d5bb0ffcd91 100644
--- a/cpp/slice/IceGrid/Exception.ice
+++ b/cpp/slice/IceGrid/Exception.ice
@@ -124,6 +124,17 @@ exception PatchException
string reason;
};
+/**
+ *
+ * This exception is raised if an operation can't be performed because
+ * the regitry lock wasn't acquired or is already acquired by a session.
+ *
+ **/
+exception AccessDeniedException
+{
+ string lockUserId;
+};
+
};
#endif
diff --git a/cpp/slice/IceGrid/Observer.ice b/cpp/slice/IceGrid/Observer.ice
index 68758557e71..c925120e1a5 100644
--- a/cpp/slice/IceGrid/Observer.ice
+++ b/cpp/slice/IceGrid/Observer.ice
@@ -63,26 +63,6 @@ interface RegistryObserver
void applicationUpdated(int serial, ApplicationUpdateDescriptor desc);
};
-/**
- *
- * This exception is raised if the cache is out of date.
- *
- **/
-exception CacheOutOfDate
-{
-};
-
-/**
- *
- * This exception is raised if an operation can't be performed because
- * the regitry lock wasn't acquired or is already acquired by a session.
- *
- **/
-exception AccessDenied
-{
- string lockUserId;
-};
-
interface Session extends Glacier2::Session
{
/**
@@ -126,80 +106,75 @@ interface Session extends Glacier2::Session
* Acquires to registry exclusive lock to start updating the
* registry applications.
*
- * @param cacheSerialSession The client cache serial number.
+ * @return The current serial.
*
- * @throws CacheOutOfDate Raised if the cache serial number
- * provided by the client is inferior to the current registry
- * serial number. The client should refresh its cache and try
- * again.
- *
- * @throws AccessDenied Raised if the exclusive lock can't be
+ * @throws AccessDeniedException Raised if the exclusive lock can't be
* acquired. This might be because it's already acquired by
* another session.
*
**/
- void startUpdate(int cacheSerialSession)
- throws CacheOutOfDate, AccessDenied;
+ int startUpdate()
+ throws AccessDeniedException;
/**
*
* Add an application. This method must be called to update the
* registry applications using the lock mechanism.
*
- * @throws AccessDenied Raised if the session doesn't hold the
+ * @throws AccessDeniedException Raised if the session doesn't hold the
* exclusive lock.
*
**/
void addApplication(ApplicationDescriptor application)
- throws AccessDenied, DeploymentException;
+ throws AccessDeniedException, DeploymentException;
/**
*
* Update an application. This method must be called to update the
* registry applications using the lock mechanism.
*
- * @throws AccessDenied Raised if the session doesn't hold the
+ * @throws AccessDeniedException Raised if the session doesn't hold the
* exclusive lock.
*
**/
void syncApplication(ApplicationDescriptor app)
- throws AccessDenied, DeploymentException, ApplicationNotExistException;
+ throws AccessDeniedException, DeploymentException, ApplicationNotExistException;
/**
*
* Update an application. This method must be called to update the
* registry applications using the lock mechanism.
*
- * @throws AccessDenied Raised if the session doesn't hold the
+ * @throws AccessDeniedException Raised if the session doesn't hold the
* exclusive lock.
*
**/
void updateApplication(ApplicationUpdateDescriptor update)
- throws AccessDenied, DeploymentException, ApplicationNotExistException;
+ throws AccessDeniedException, DeploymentException, ApplicationNotExistException;
/**
*
* Update an application. This method must be called to update the
* registry applications using the lock mechanism.
*
- * @throws AccessDenied Raised if the session doesn't hold the
+ * @throws AccessDeniedException Raised if the session doesn't hold the
* exclusive lock.
*
**/
void removeApplication(string name)
- throws AccessDenied, ApplicationNotExistException;
+ throws AccessDeniedException, ApplicationNotExistException;
/**
*
* Finish to update the registry and release the exclusive
* lock.
*
- * @throws AccessDenied Raised if the session doesn't hold the
+ * @throws AccessDeniedException Raised if the session doesn't hold the
* exclusive lock.
*
**/
void finishUpdate()
- throws AccessDenied;
+ throws AccessDeniedException;
};
interface SessionManager extends Glacier2::SessionManager
diff --git a/cpp/src/IceGrid/Database.cpp b/cpp/src/IceGrid/Database.cpp
index 88b6f2fb9ea..9e05c898c84 100644
--- a/cpp/src/IceGrid/Database.cpp
+++ b/cpp/src/IceGrid/Database.cpp
@@ -209,25 +209,22 @@ Database::checkSessionLock(ObserverSessionI* session)
{
if(_lock != 0 && session != _lock)
{
- AccessDenied ex;
+ AccessDeniedException ex;
ex.lockUserId = _lockUserId;
throw ex;
}
}
-void
-Database::lock(int serial, ObserverSessionI* session, const string& userId)
+int
+Database::lock(ObserverSessionI* session, const string& userId)
{
Lock sync(*this);
checkSessionLock(session);
- if(serial != _serial)
- {
- throw CacheOutOfDate();
- }
-
_lock = session;
_lockUserId = userId;
+
+ return _serial;
}
void
diff --git a/cpp/src/IceGrid/Database.h b/cpp/src/IceGrid/Database.h
index 0ac7bcc6358..588b4cf1e2c 100644
--- a/cpp/src/IceGrid/Database.h
+++ b/cpp/src/IceGrid/Database.h
@@ -49,7 +49,7 @@ public:
void setObservers(const RegistryObserverPrx&, const NodeObserverPrx&);
- void lock(int serial, ObserverSessionI*, const std::string&);
+ int lock(ObserverSessionI*, const std::string&);
void unlock(ObserverSessionI*);
void addApplicationDescriptor(ObserverSessionI*, const ApplicationDescriptor&);
diff --git a/cpp/src/IceGrid/ObserverSessionI.cpp b/cpp/src/IceGrid/ObserverSessionI.cpp
index 98b16e032a8..df59d636a8d 100644
--- a/cpp/src/IceGrid/ObserverSessionI.cpp
+++ b/cpp/src/IceGrid/ObserverSessionI.cpp
@@ -73,8 +73,8 @@ ObserverSessionI::setObserversByIdentity(const Ice::Identity& registryObserver,
_nodeObserverTopic.subscribe(_nodeObserver);
}
-void
-ObserverSessionI::startUpdate(int serial, const Ice::Current& current)
+int
+ObserverSessionI::startUpdate(const Ice::Current& current)
{
Lock sync(*this);
if(_destroyed)
@@ -84,8 +84,9 @@ ObserverSessionI::startUpdate(int serial, const Ice::Current& current)
throw ex;
}
- _database->lock(serial, this, _userId);
+ int serial = _database->lock(this, _userId);
_updating = true;
+ return serial;
}
void
@@ -101,7 +102,7 @@ ObserverSessionI::addApplication(const ApplicationDescriptor& app, const Ice::Cu
if(!_updating)
{
- throw AccessDenied();
+ throw AccessDeniedException();
}
_database->addApplicationDescriptor(this, app);
}
@@ -119,7 +120,7 @@ ObserverSessionI::updateApplication(const ApplicationUpdateDescriptor& update, c
if(!_updating)
{
- throw AccessDenied();
+ throw AccessDeniedException();
}
_database->updateApplicationDescriptor(this, update);
}
@@ -137,7 +138,7 @@ ObserverSessionI::syncApplication(const ApplicationDescriptor& app, const Ice::C
if(!_updating)
{
- throw AccessDenied();
+ throw AccessDeniedException();
}
_database->syncApplicationDescriptor(this, app);
}
@@ -155,7 +156,7 @@ ObserverSessionI::removeApplication(const string& name, const Ice::Current& curr
if(!_updating)
{
- throw AccessDenied();
+ throw AccessDeniedException();
}
_database->removeApplicationDescriptor(this, name);
}
@@ -173,7 +174,7 @@ ObserverSessionI::finishUpdate(const Ice::Current& current)
if(!_updating)
{
- throw AccessDenied();
+ throw AccessDeniedException();
}
_database->unlock(this);
_updating = false;
diff --git a/cpp/src/IceGrid/ObserverSessionI.h b/cpp/src/IceGrid/ObserverSessionI.h
index bb3943a30f9..5509e74f3d1 100644
--- a/cpp/src/IceGrid/ObserverSessionI.h
+++ b/cpp/src/IceGrid/ObserverSessionI.h
@@ -31,7 +31,7 @@ public:
virtual void setObservers(const RegistryObserverPrx&, const NodeObserverPrx&, const Ice::Current&);
virtual void setObserversByIdentity(const Ice::Identity&, const Ice::Identity&, const Ice::Current&);
- virtual void startUpdate(int, const Ice::Current&);
+ virtual int startUpdate(const Ice::Current&);
virtual void addApplication(const ApplicationDescriptor&, const Ice::Current&);
virtual void syncApplication(const ApplicationDescriptor&, const Ice::Current&);
virtual void updateApplication(const ApplicationUpdateDescriptor&, const Ice::Current&);
diff --git a/cpp/test/IceGrid/session/AllTests.cpp b/cpp/test/IceGrid/session/AllTests.cpp
index e676ca80dc5..13a3930c0ed 100644
--- a/cpp/test/IceGrid/session/AllTests.cpp
+++ b/cpp/test/IceGrid/session/AllTests.cpp
@@ -333,20 +333,18 @@ allTests(const Ice::CommunicatorPtr& communicator)
try
{
- session1->startUpdate(serial + 1);
- test(false);
- }
- catch(const CacheOutOfDate&)
- {
+ int s = session1->startUpdate();
+ test(s != serial + 1);
}
- catch(const AccessDenied&)
+ catch(const AccessDeniedException&)
{
test(false);
}
try
{
- session1->startUpdate(serial);
+ int s = session1->startUpdate();
+ test(s == serial);
}
catch(const Ice::UserException&)
{
@@ -355,10 +353,10 @@ allTests(const Ice::CommunicatorPtr& communicator)
try
{
- session2->startUpdate(regObs2->serial);
+ session2->startUpdate();
test(false);
}
- catch(const AccessDenied& ex)
+ catch(const AccessDeniedException& ex)
{
test(ex.lockUserId == "Observer1");
}
@@ -374,7 +372,8 @@ allTests(const Ice::CommunicatorPtr& communicator)
try
{
- session2->startUpdate(regObs2->serial);
+ int s = session2->startUpdate();
+ test(s == regObs2->serial);
}
catch(const Ice::UserException&)
{
@@ -397,7 +396,7 @@ allTests(const Ice::CommunicatorPtr& communicator)
session1->addApplication(ApplicationDescriptor());
test(false);
}
- catch(const AccessDenied&)
+ catch(const AccessDeniedException&)
{
}
@@ -419,7 +418,8 @@ allTests(const Ice::CommunicatorPtr& communicator)
try
{
- session1->startUpdate(serial);
+ int s = session1->startUpdate();
+ test(s == serial);
ApplicationUpdateDescriptor update;
update.name = "Application";
update.variables.insert(make_pair(string("test"), string("test")));
@@ -446,13 +446,14 @@ allTests(const Ice::CommunicatorPtr& communicator)
session1->updateApplication(update);
test(false);
}
- catch(const AccessDenied&)
+ catch(const AccessDeniedException&)
{
}
try
{
- session2->startUpdate(serial);
+ int s = session2->startUpdate();
+ test(s == serial);
session2->removeApplication("Application");
session2->finishUpdate();
}
@@ -470,7 +471,8 @@ allTests(const Ice::CommunicatorPtr& communicator)
try
{
- session1->startUpdate(serial);
+ int s = session1->startUpdate();
+ test(s == serial);
}
catch(const Ice::UserException&)
{
@@ -480,7 +482,8 @@ allTests(const Ice::CommunicatorPtr& communicator)
try
{
- session2->startUpdate(serial);
+ int s = session2->startUpdate();
+ test(s == serial);
session2->finishUpdate();
}
catch(const Ice::UserException&)
@@ -527,7 +530,8 @@ allTests(const Ice::CommunicatorPtr& communicator)
{
ApplicationDescriptor app;
app.name = "Application";
- session1->startUpdate(serial);
+ int s = session1->startUpdate();
+ test(s == serial);
session1->addApplication(app);
regObs1->waitForUpdate(__FILE__, __LINE__);
test(regObs1->applications.find("Application") != regObs1->applications.end());
@@ -619,7 +623,8 @@ allTests(const Ice::CommunicatorPtr& communicator)
try
{
- session1->startUpdate(serial);
+ int s = session1->startUpdate();
+ test(s == serial);
session1->addApplication(nodeApp);
regObs1->waitForUpdate(__FILE__, __LINE__);
test(regObs1->applications.find("NodeApp") != regObs1->applications.end());