msmith - in flumotion/branches/manager-cleanup-1: . flumotion/manager

flumotion-commit at lists.fluendo.com flumotion-commit at lists.fluendo.com
Fri May 25 16:42:20 CEST 2007


Author: msmith
Date: Fri May 25 16:42:17 2007
New Revision: 5039

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:
          Continue cleanup; removing arbitrary splits in functionality;
          trying to get this code readable.



Modified: flumotion/branches/manager-cleanup-1/ChangeLog
==============================================================================
--- flumotion/branches/manager-cleanup-1/ChangeLog	(original)
+++ flumotion/branches/manager-cleanup-1/ChangeLog	Fri May 25 16:42:17 2007
@@ -2,6 +2,13 @@
 
 	* flumotion/manager/component.py:
 	* flumotion/manager/manager.py:
+	  Continue cleanup; removing arbitrary splits in functionality;
+	  trying to get this code readable.
+
+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.

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 16:42:17 2007
@@ -66,7 +66,7 @@
         # doc in base class
         base.ManagerAvatar.__init__(self, *args, **kwargs)
         
-        self.componentState = None # set by the vishnu by componentAttached
+        self.componentState = None
         self.jobState = None # set by the vishnu by componentAttached
 
         # these flags say when this component is in the middle of doing stuff
@@ -159,7 +159,8 @@
 
         def gotConfigAndState(res):
             (_success1, conf), (_success2, jobState) = res
-            self.vishnu.componentAttached(self, conf, jobState)
+            self.componentState = self.vishnu.componentAttached(
+                self, conf, jobState)
         
         d = defer.DeferredList([self.mindCallRemote('getConfig'),
                                 self.mindCallRemote('getState')],
@@ -175,20 +176,32 @@
                 self._happydefers = []
 
         d.addCallback(checkInitialMood)
+        # TODO: like everything else in this file touching the depgraph, this is
+        # messy!
         # listen to the mood so we can tell the depgraph
         d.addCallback(lambda _: self.jobState.addListener(self,
                                                           set=self.stateSet))
-        # make heaven register component
-        d.addCallback(lambda _: self.heaven.registerComponent(self))
         d.addCallback(lambda _: self.vishnu.registerComponent(self))
         return d
 
     def mindDetached(self, mind):
-        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, but after we've cleared the job state. 
-        # Also, don't ever remove 'sad' here. If we shut down due to an 
+        self.info('component "%s" logged out' % self.avatarId)
+
+        # 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 = []
+
+        conf = self.componentState.get('config')
+        if conf['clock-master'] == self.avatarId:
+            self.heaven.removeMasterClock(self)
+
+        self.vishnu.componentDetached(self)
+
+        # Now, we're detached: set our state to sleeping (or lost), but
+        # 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)
@@ -200,16 +213,8 @@
                 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)
+        # We're done with the componentState; release it.
+        self.componentState = None
 
         base.ManagerAvatar.mindDetached(self, mind)
  
@@ -995,32 +1000,6 @@
  
     setupComponent = defer_generator_method(_setupComponent)
         
-    def registerComponent(self, componentAvatar):
-        """
-        This function registers a component in the heaven.
-        It is triggered when the mind is attached.
-
-        @param componentAvatar: the component to register
-        @type  componentAvatar: L{flumotion.manager.component.ComponentAvatar}
-        """
-        self.debug('heaven registering component %r' % componentAvatar)
-        # nothing to do
-
-    def unregisterComponent(self, componentAvatar):
-        """
-        This function unregisters a component in the heaven.
-        It is triggered when the mind is detached.
-
-        @param componentAvatar: the component to unregister
-        @type  componentAvatar: L{flumotion.manager.component.ComponentAvatar}
-        """
-        componentAvatar.debug('unregistering component')
-
-        conf = componentAvatar.componentState.get('config')
-        if conf['clock-master'] == componentAvatar.avatarId:
-            # houston, we have a master clock
-            self.removeMasterClock(componentAvatar)
-
     def provideMasterClock(self, componentAvatar):
         """
         Tell the given component to provide a master clock.

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 16:42:17 2007
@@ -837,6 +837,8 @@
         #  (2) we don't know anything about this component, but since it
         #      logged in, we will deal with it, at least allowing the
         #      admin to control it.
+        # Returns the componentState (either the existing one, or a newly 
+        # created one)
 
         def verifyExistingComponentState(jobState, state):
             # condition (1)
@@ -925,11 +927,12 @@
         m = self.getComponentMapper(avatar.avatarId)
         m.avatar = avatar
         self._componentMappers[m.avatar] = m
-        avatar.componentState = m.state
         avatar.jobState = jobState
         m.jobState = jobState
         self._componentMappers[jobState] = m
 
+        return m.state
+
     def registerComponent(self, componentAvatar):
         # called when the jobstate is retrieved
         self.debug('vishnu registering component %r' % componentAvatar)
@@ -985,8 +988,8 @@
 
         self._depgraph.setJobStopped(componentAvatar.componentState)
 
-        # detach componentstate fom avatar
-        componentAvatar.componentState = None
+        # detach the job state
+        componentAvatar.componentState.clearJobState()
         componentAvatar.jobState = None
         
     def getComponentStates(self):


More information about the flumotion-commit mailing list