msmith - in flumotion/branches/manager-cleanup-1: .
flumotion/manager
flumotion-commit at lists.fluendo.com
flumotion-commit at lists.fluendo.com
Fri May 25 15:53:43 CEST 2007
Author: msmith
Date: Fri May 25 15:53:40 2007
New Revision: 5038
Modified:
flumotion/branches/manager-cleanup-1/ChangeLog
flumotion/branches/manager-cleanup-1/flumotion/manager/component.py
flumotion/branches/manager-cleanup-1/flumotion/manager/manager.py
Log:
* flumotion/manager/component.py:
* flumotion/manager/manager.py:
Start removing/merging functions to clean up internals that make no
sense.
Fix workerport management in ComponentAvatars.
Modified: flumotion/branches/manager-cleanup-1/ChangeLog
==============================================================================
--- flumotion/branches/manager-cleanup-1/ChangeLog (original)
+++ flumotion/branches/manager-cleanup-1/ChangeLog Fri May 25 15:53:40 2007
@@ -1,5 +1,13 @@
2007-05-25 Michael Smith <msmith at fluendo.com>
+ * flumotion/manager/component.py:
+ * flumotion/manager/manager.py:
+ Start removing/merging functions to clean up internals that make no
+ sense.
+ Fix workerport management in ComponentAvatars.
+
+2007-05-25 Michael Smith <msmith at fluendo.com>
+
* flumotion/manager/admin.py:
* flumotion/manager/base.py:
* flumotion/manager/component.py:
Modified: flumotion/branches/manager-cleanup-1/flumotion/manager/component.py
==============================================================================
--- flumotion/branches/manager-cleanup-1/flumotion/manager/component.py (original)
+++ flumotion/branches/manager-cleanup-1/flumotion/manager/component.py Fri May 25 15:53:40 2007
@@ -75,7 +75,7 @@
self._beingSetup = False
self._providingClock = False
- self._ports = {}
+ self._ports = []
self._shutdown_requested = False
@@ -94,18 +94,6 @@
self.avatarId, mood)
### ComponentAvatar methods
- def cleanup(self):
- """
- Clean up when detaching.
- """
- if self._ports:
- # FIXME: doesn't seem to ever be possible
- self.vishnu.releasePortsOnWorker(self.getWorkerName(),
- self._ports.values())
-
- self._ports = {}
-
- self.jobState = None
def _setMood(self, mood):
if not self.componentState:
@@ -130,6 +118,19 @@
self.componentState.append('messages', message)
+ def reservePortsOnWorker(self, workerName, numberOfPorts):
+ ports = self.heaven.vishnu.reservePortsOnWorker(workerName,
+ numberOfPorts)
+ self._ports.extend(ports)
+ self.debug("Reserved ports: %r on worker %s", ports, workerName)
+ return ports
+
+ def releasePortsOnWorker(self, workerName, ports):
+ self.debug("Releasing ports %r from known %r", ports, self._ports)
+ for p in ports:
+ self._ports.remove(p)
+ self.heaven.vishnu.releasePortsOnWorker(workerName, ports)
+
# general fallback for unhandled errors so we detect them
# FIXME: we can't use this since we want a PropertyError to fall through
# after going through the PropertyErrback.
@@ -183,20 +184,14 @@
return d
def mindDetached(self, mind):
- # doc in base class
- self.vishnu.unregisterComponent(self)
- self.heaven.unregisterComponent(self)
-
- self.info('component "%s" logged out' % self.avatarId)
-
self.componentState.clearJobState()
-
# Now, we're detached: set our state to sleeping (or lost).
# Do this before vishnu.componentDetached() severs our association
- # with our componentState. Also, don't ever remove 'sad' here.
- # If we shut down due to an explicit manager request, go to sleeping.
- # Otherwise, go to lost, because it got disconnected for an unknown
- # reason (probably network related)
+ # with our componentState, but after we've cleared the job state.
+ # Also, don't ever remove 'sad' here. If we shut down due to an
+ # explicit manager request, go to sleeping. Otherwise, go to lost,
+ # because it got disconnected for an unknown reason (probably network
+ # related)
if not self._getMoodValue() == moods.sad.value:
if self._shutdown_requested:
self.debug("Shutdown was requested, component now sleeping")
@@ -205,10 +200,18 @@
self.debug("Shutdown was NOT requested, component now lost")
self._setMood(moods.lost)
+ # Release ports. This will include the clock-master port (if any), and
+ # any ports requested by the component.
+ if self._ports:
+ self.vishnu.releasePortsOnWorker(self.getWorkerName(),
+ self._ports)
+ self._ports = []
+
+ self.heaven.unregisterComponent(self)
+ self.info('component "%s" logged out' % self.avatarId)
self.vishnu.componentDetached(self)
- base.ManagerAvatar.mindDetached(self, mind)
- self.cleanup() # callback done at end
+ base.ManagerAvatar.mindDetached(self, mind)
# IStateListener methods
def stateSet(self, state, key, value):
@@ -626,7 +629,7 @@
def perspective_reservePortsOnWorker(self, workerName, numberOfPorts):
"""
- Request reservation a number of ports on a particular worker.
+ Request reservation of a number of ports on a particular worker.
This can be called from a job if it needs some ports itself.
@param workerName: name of the worker to reserve ports on
@@ -634,9 +637,7 @@
@param numberOfPorts: the number of ports to reserve
@type numberOfPorts: int
"""
- ports = self.heaven.vishnu.reservePortsOnWorker(workerName,
- numberOfPorts)
- return ports
+ return self.reservePortsOnWorker(workerName, numberofPorts)
class ComponentHeaven(base.ManagerHeaven):
"""
@@ -1060,7 +1061,7 @@
d.callback(result)
workerName = componentAvatar.getWorkerName()
- port = self.vishnu.reservePortsOnWorker(workerName, 1)[0]
+ port = componentAvatar.reservePortsOnWorker(workerName, 1)[0]
def failedToProvideMasterClock(failure):
# check if we actually did provide master clock and failed
@@ -1072,7 +1073,7 @@
else:
self.warning('Failed to provide master clock itself')
self.debug('Going to release port')
- self.vishnu.releasePortsOnWorker(workerName, [port])
+ componentAvatar.releasePortsOnWorker(workerName, [port])
self.warning(failure.getErrorMessage())
if avatarId in self._masterClockInfo:
@@ -1106,14 +1107,7 @@
d.errback(errors.ComponentStartError(
'clock master component start cancelled'))
- # release our clock port
if avatarId in self._masterClockInfo:
- info = self._masterClockInfo[avatarId]
- if info:
- port = info[1]
- self.vishnu.releasePortsOnWorker(workerName, [port])
- else:
- self.debug('avatarId %r has None masterClockInfo' % avatarId)
del self._masterClockInfo[avatarId]
else:
self.warning('component %s has no master clock info'
Modified: flumotion/branches/manager-cleanup-1/flumotion/manager/manager.py
==============================================================================
--- flumotion/branches/manager-cleanup-1/flumotion/manager/manager.py (original)
+++ flumotion/branches/manager-cleanup-1/flumotion/manager/manager.py Fri May 25 15:53:40 2007
@@ -115,8 +115,8 @@
# uses these kwargs to set its own info. so don't change
# these args or their order or you will break your test
# suite.
- def cleanup(avatarId=avatarId, mind=mind):
- self.removeAvatar(avatarId, mind)
+ def cleanup(avatar=avatar, mind=mind):
+ self.removeAvatar(avatar, mind)
return (pb.IPerspective, avatar, cleanup)
def got_error(failure):
# If we failed for some reason, we want to drop the connection.
@@ -134,13 +134,14 @@
### our methods
- def removeAvatar(self, avatarId, mind):
+ def removeAvatar(self, avatar, mind):
"""
Remove an avatar because it logged out of the manager.
This function is registered by requestAvatar.
"""
- heaven.removeAvatar(avatarId, mind)
+ heaven = avatar.heaven
+ heaven.removeAvatar(avatar.avatarId, mind)
def createAvatarFor(self, avatarId, keycard, remoteHost, ifaces, mind):
"""
@@ -929,16 +930,6 @@
m.jobState = jobState
self._componentMappers[jobState] = m
- def componentDetached(self, componentAvatar):
- # called when the component has detached
- self.debug("%s component detached", componentAvatar.avatarId)
- self._depgraph.setJobStopped(componentAvatar.componentState)
- componentAvatar.componentState.set('moodPending', None)
-
- # detach componentstate fom avatar
- componentAvatar.componentState = None
- componentAvatar.jobState = None
-
def registerComponent(self, componentAvatar):
# called when the jobstate is retrieved
self.debug('vishnu registering component %r' % componentAvatar)
@@ -963,7 +954,7 @@
self.debug('vishnu registered component %r' % componentAvatar)
self.componentHeaven._tryWhatCanBeStarted()
- def unregisterComponent(self, componentAvatar):
+ def componentDetached(self, componentAvatar):
# called when the component is logging out
# clear up jobState and avatar
self.debug('unregisterComponent(%r): cleaning up state' %
@@ -991,6 +982,12 @@
# unmap avatar
del self._componentMappers[m.avatar]
m.avatar = None
+
+ self._depgraph.setJobStopped(componentAvatar.componentState)
+
+ # detach componentstate fom avatar
+ componentAvatar.componentState = None
+ componentAvatar.jobState = None
def getComponentStates(self):
cList = self.state.getComponents()
More information about the flumotion-commit
mailing list