[asterisk-scf-commits] asterisk-scf/release/configurator.git branch "master" updated.

Commits to the Asterisk SCF project code repositories asterisk-scf-commits at lists.digium.com
Tue May 8 17:27:10 CDT 2012


branch "master" has been updated
       via  b80771afe98b2413dbdc11592e744b9c60fb18da (commit)
      from  9f8455129af62a03ae9625388da61204ad3c07d6 (commit)

Summary of changes:
 ActivateServiceLocator.py |   76 +++++++++++++++++++++++++++++++++
 Activator.py              |  102 +++++++++++++++++++++++++++++++++++++++++++++
 AsteriskSCF.py            |   11 ++++-
 Configurator.py           |    6 +-
 4 files changed, 191 insertions(+), 4 deletions(-)
 create mode 100644 ActivateServiceLocator.py
 create mode 100644 Activator.py


- Log -----------------------------------------------------------------
commit b80771afe98b2413dbdc11592e744b9c60fb18da
Author: Ken Hunt <ken.hunt at digium.com>
Date:   Tue May 8 11:36:13 2012 -0500

    Changes for new retry logic.

diff --git a/ActivateServiceLocator.py b/ActivateServiceLocator.py
new file mode 100644
index 0000000..0298aa8
--- /dev/null
+++ b/ActivateServiceLocator.py
@@ -0,0 +1,76 @@
+#!/usr/bin/env python
+
+import os
+import sys
+import argparse
+
+sys.path.append('/opt/Ice-3.4.2/python')
+
+import Ice, AsteriskSCF
+
+slice = os.environ["ASTSCF_HOME"] + "/slice/slice"
+AstSCFslice = slice + "/AsteriskSCF/"
+
+Ice.loadSlice("-I\"" + slice + "\" -I\"" + Ice.getSliceDir() + "\" --all \"" + AstSCFslice + "System/Component/ReplicaIf.ice\"")
+Ice.loadSlice("-I\"" + slice + "\" -I\"" + Ice.getSliceDir() + "\" --all \"" + AstSCFslice + "Core/Discovery/ServiceLocatorIf.ice\"")
+
+import AsteriskSCF.Core.Discovery.V1
+import AsteriskSCF.System.Component.V1 
+
+# This is a utiltity for activating the ServiceLocator. Components are typically activated by accessing their 
+# Replica interface from the ServiceLocator and calling the activate() operation. But for the ServiceLocator
+# itself, we use a direct proxy as sort of boot-strap. 
+#
+# Note that the Activator.py script will activate the ServiceLocator (if needed) if you use it to activate some other
+# component, using a similar technique as that below. But if you are running the ServiceLocator in a replica group, and
+# all the other components are in stand-alone mode, you need a way to activate just a ServiceLocator. This is it. 
+#
+class ComponentActivator(Ice.Application):
+    def run(self, args):
+        serviceLocatorReplicaString = 'ServiceLocatorReplica:tcp '
+       
+        argParser = argparse.ArgumentParser(description = 'Place a Service Locator in the \'active\' state.')
+        argParser.add_argument('-sh', '--service_locator_host', 
+            help='(OPTIONAL) Hostname or IP address of the Service Locator. If not specified, localhost is assumed.')
+	argParser.add_argument('-p', '--port', help='(OPTIONAL) Port number to access the Replica interface. (Default=4410)')
+
+        try:
+            args = argParser.parse_args()
+        except:
+            print ''
+            return 2
+
+        # Get a reference to the Service Locator's Replica interface. 
+        if not args.service_locator_host == None:
+            serviceLocatorReplicaString = serviceLocatorReplicaString + ' -h ' + args.service_locator_host
+
+	if not args.port == None:
+            serviceLocatorReplicaString = serviceLocatorReplicaString + ' -p ' + args.port
+        else:
+	    serviceLocatorReplicaString = serviceLocatorReplicaString + ' -p 4410'
+
+        try:
+            serviceLocatorReplica = AsteriskSCF.System.Component.V1.ReplicaPrx.checkedCast(self.communicator().stringToProxy(serviceLocatorReplicaString))
+	except Ice.ObjectNotExistException as e:
+            print >> sys.stderr, "No Replica interface found using: " + serviceLocatorReplicaString
+	    return -1
+
+        if serviceLocatorReplica == None:
+	    print >> sys.stderr, "Invalid Replica proxy using: " + serviceLocatorReplicaString
+	    print >> sys.stderr, "For usage details please run " + sys.argv[0] + " --help"
+            return -1
+
+	# Now make sure the Service Locator is active. 
+        try:
+	    print "Activating Service Locator using proxy: " + serviceLocatorReplicaString
+            result =  serviceLocatorReplica.activate(AsteriskSCF.createContext())
+	    
+        except Ice.Exception as ex:
+            print >> sys.stderr, "Exception trying to activate a Service Locator component: " + ex.what()
+            return -1
+
+
+if __name__ == '__main__':
+    print '' 
+    sys.exit(ComponentActivator().main(sys.argv))
+
diff --git a/Activator.py b/Activator.py
new file mode 100644
index 0000000..2f50e90
--- /dev/null
+++ b/Activator.py
@@ -0,0 +1,102 @@
+#!/usr/bin/env python
+
+import os
+import sys
+import argparse
+
+sys.path.append('/opt/Ice-3.4.2/python')
+
+import Ice, AsteriskSCF
+
+slice = os.environ["ASTSCF_HOME"] + "/slice/slice"
+AstSCFslice = slice + "/AsteriskSCF/"
+
+Ice.loadSlice("-I\"" + slice + "\" -I\"" + Ice.getSliceDir() + "\" --all \"" + AstSCFslice + "System/Component/ReplicaIf.ice\"")
+Ice.loadSlice("-I\"" + slice + "\" -I\"" + Ice.getSliceDir() + "\" --all \"" + AstSCFslice + "Core/Discovery/ServiceLocatorIf.ice\"")
+
+import AsteriskSCF.Core.Discovery.V1
+import AsteriskSCF.System.Component.V1 
+
+class ComponentActivator(Ice.Application):
+    def run(self, args):
+        serviceLocatorReplicaString = 'ServiceLocatorReplica:tcp -p 4410'
+        serviceLocatorString = 'LocatorService:tcp -p 4411'
+
+        argParser = argparse.ArgumentParser(description = 'Place a replica in the \'active\' state.')
+        argParser.add_argument('-c', '--category', required=True, 
+            help='Discovery category for the component\'s replica interface. Typically: ' \
+	    'BridgeService.Replica, RoutingService.Replica, SipSessionManager.Replica, ' \
+            'MediaRTPService.Replica, MediaOperationsCoreComponentService.Replica, MediaFormatGeneric.Replica')
+        argParser.add_argument('-s', '--service_name', required=True,
+            help='The service name property is used when registering a component\'s services with the ServiceLocator, ' \
+                 'and can be located in the component\'s IceBox configuration file. For small or test deployments' \
+	        'the service name is commonly set to \'default\' (i.e. <instance_name>.ServiceName=default)')
+        argParser.add_argument('-i', '--instance_name', required=True,
+            help='In general, configuration properties derive from the IceBox service name of the component in the ' \
+                 'IceBox configuration file. An IceBox service name can be recognized by looking for a string simular ' \
+                 'to this: \'IceBox.Service.<instance name>=<shared lib name>:<shared lib operation>\'.')
+        argParser.add_argument('-sh', '--service_locator_host', 
+            help='(OPTIONAL) Hostname or IP address of the Service Locator. If not specified, localhost is assumed.')
+
+        try:
+            args = argParser.parse_args()
+        except:
+            print ''
+            return 2
+
+        # First we get a reference to the Service Locator's own Replica interface. 
+        # We need the Service Locator active in order to locate the Replica interface 
+	# of the component we're trying activate.
+        if not args.service_locator_host == None:
+            serviceLocatorReplicaString = serviceLocatorReplicaString + ' -h ' + args.service_locator_host
+
+        serviceLocatorReplica = AsteriskSCF.System.Component.V1.ReplicaPrx.checkedCast(self.communicator().stringToProxy(serviceLocatorReplicaString))
+
+        if serviceLocatorReplica == None:
+            print >> sys.stderr, "Invalid Replica proxy specified for Service Locator. For usage details please run " + sys.argv[0] + " --help"
+            return -1
+
+	# Now make sure the Service Locator is active. 
+        try:
+	    if not serviceLocatorReplica.isActive():
+	        print "Activating Service Locator."
+                serviceLocatorReplica.activate(AsteriskSCF.createContext())
+	    
+        except Ice.Exception as ex:
+            print >> sys.stderr, "Exception trying to activate a Service Locator component: " + ex.what()
+            return -1
+
+        # We have an active Service Locator component. Get a proxy to the Service Locator interface so that
+        # we can lookup registered interfaces.
+        if not args.service_locator_host == None:
+            serviceLocatorString = serviceLocatorString + ' -h ' + args.service_locator_host
+
+        serviceLocator = AsteriskSCF.Core.Discovery.V1.ServiceLocatorPrx.checkedCast(self.communicator().stringToProxy(serviceLocatorString))
+
+        if serviceLocator == None:
+            print >> sys.stderr, "Invalid Service Locator proxy specified. For usage details please run " + sys.argv[0] + " --help"
+            return -1
+
+        # Activate the component
+        componentLocatorParams = AsteriskSCF.Core.Discovery.V1.ServiceLocatorParams()
+        componentLocatorParams.category = args.category
+        componentLocatorParams.service = args.service_name
+        componentLocatorParams.id = args.instance_name
+
+        try:
+            componentReplicaObjPrx = serviceLocator.locate(componentLocatorParams)
+        except AsteriskSCF.Core.Discovery.V1.ServiceNotFound:
+            print >> sys.stderr, 'The \'%s\' replica interface was not found by the specified service locator.\n\n %s\n' % (args.category, sys.exc_info())
+            return -1
+
+        componentReplica = AsteriskSCF.System.Component.V1.ReplicaPrx.checkedCast(componentReplicaObjPrx)
+
+	if componentReplica == None:
+	    print >> sys.stderr, "Can't cast object to replica." 
+	    return -1;
+
+        result = componentReplica.activate(AsteriskSCF.createContext())
+
+if __name__ == '__main__':
+    print '' 
+    sys.exit(ComponentActivator().main(sys.argv))
diff --git a/AsteriskSCF.py b/AsteriskSCF.py
index 1086d8b..0d0bec5 100755
--- a/AsteriskSCF.py
+++ b/AsteriskSCF.py
@@ -18,7 +18,7 @@
 
 # Stuff that will probably be moved into an ice-util-py at some point
 
-import os, Ice
+import os, Ice, uuid
 
 def loadSlice(component, sliceFile):
     """Load the given Asterisk SCF slice file. See Ice.loadSlice()
@@ -44,3 +44,12 @@ def loadSlice(component, sliceFile):
         "slice": sliceFile
         }
     Ice.loadSlice(loadSliceCmd)
+
+loadSlice('slice', 'AsteriskSCF/System/OperationsIf.ice')
+import AsteriskSCF.System.V1
+
+def createContext():
+    newContext = AsteriskSCF.System.V1.OperationContext()
+    newContext.id = str(uuid.uuid4()) # Random UUID
+    newContext.transactionId = newContext.id
+    return newContext
diff --git a/Configurator.py b/Configurator.py
index 0cfdedf..bc24cda 100755
--- a/Configurator.py
+++ b/Configurator.py
@@ -22,7 +22,7 @@ import sys
 
 sys.path.append('/opt/Ice-3.4/python')
 
-import ConfigParser, traceback, os, Ice, getopt, AsteriskSCF
+import ConfigParser, traceback, os, Ice, getopt, AsteriskSCF, uuid
 
 def astscfLoadSlice(component, sliceFile):
     """Old name. Moved to AsteriskSCF.loadSlice(). Update usages at your leisure."""
@@ -212,7 +212,7 @@ class ConfiguratorApp(Ice.Application):
                 # components are altering the configuration we are best effort to begin with
                 try:
                     groups = configurationService.getConfigurationGroups()
-                    configurationService.removeConfigurationGroups(groups)
+                    configurationService.removeConfigurationGroups(AsteriskSCF.createContext(), groups)
                 except:
                     print >> sys.stderr, "Configuration could not be wiped - Failed to contact component"
 		    traceback.print_exc()
@@ -222,7 +222,7 @@ class ConfiguratorApp(Ice.Application):
 
             try:
                 # print self.visitor.groups  # <- Handiest debug aid ever.
-                configurationService.setConfiguration(self.visitor.groups)
+                configurationService.setConfiguration(AsteriskSCF.createContext(), self.visitor.groups)
                 print "Configuration applied"
             except:
 		print "Exception calling setConfiguration: ", sys.exc_info()[0]

-----------------------------------------------------------------------


-- 
asterisk-scf/release/configurator.git



More information about the asterisk-scf-commits mailing list