Author: tmckay
Date: 2013-01-18 23:19:32 +0000 (Fri, 18 Jan 2013)
New Revision: 5662
Modified:
branches/tmckay/sage/python/sage/aviary/aviaryoperations.py
Log:
Move boiler plate for server list into _init_server_list
Modified: branches/tmckay/sage/python/sage/aviary/aviaryoperations.py
===================================================================
--- branches/tmckay/sage/python/sage/aviary/aviaryoperations.py 2013-01-18 22:41:44 UTC
(rev 5661)
+++ branches/tmckay/sage/python/sage/aviary/aviaryoperations.py 2013-01-18 23:19:32 UTC
(rev 5662)
@@ -346,12 +346,10 @@
self.Owner = owner
class _AviaryCommon(object):
- def __init__(self, transports, servers, wsdl, resource, subtype):
+ def __init__(self, transports, wsdl):
+ self.servers = None
self.transports = transports
- self.servers = servers
- self.resource = resource
- self.subtype = subtype
self.client_pool = ClientPool(wsdl, None)
# Things in Aviary that were born as swap-ins/analogs for
@@ -361,6 +359,24 @@
# to wrap results this way. Let it be controlled.
self.use_MethodResult_for_sync_calls = True
+ def _init_servers_list(self,
+ locator,
+ urls,
+ def_port,
+ def_service,
+ resource, subtype):
+
+ self.resource = resource
+ self.subtype = subtype
+ if locator:
+ self.servers = ServerList(locator, resource, subtype)
+ elif urls and type(urls) == str:
+ self.servers = FixedServerList(urls,
+ def_port,
+ def_service,
+ resource,
+ subtype)
+
def get_hosts(self, resource, subtype):
if resource == "ANY" or \
(resource == self.resource and \
@@ -485,29 +501,18 @@
class _AviaryJobMethods(_AviaryCommon):
def __init__(self, locator, transports, datadir, job_servers):
- resource = "SCHEDULER"
- subtype = "JOB"
- if locator:
- servers = ServerList(locator,
- resource, subtype)
- elif job_servers and type(job_servers) == str:
- servers = FixedServerList(job_servers,
- "9090",
- "/services/job/",
- resource,
- subtype)
- else:
- servers = None
-
wsdl = "file:" + os.path.join(get_datadir(datadir, "job"),
"aviary-job.wsdl")
- super(_AviaryJobMethods, self).__init__(transports,
- servers,
- wsdl,
- resource,
- subtype)
+ super(_AviaryJobMethods, self).__init__(transports, wsdl)
+ self._init_servers_list(locator,
+ job_servers,
+ "9090",
+ "/services/job/",
+ "SCHEDULER",
+ "JOB")
+
def set_job_attribute(self, scheduler, job_id, name, value, callback, submission):
assert callable(callback)
@@ -685,29 +690,19 @@
class _AviaryQueryMethods(_AviaryCommon):
def __init__(self, locator, transports, datadir, query_servers):
- resource = "CUSTOM"
- subtype = "QUERY_SERVER"
- if locator:
- servers = ServerList(locator,
- resource, subtype)
- elif query_servers and type(query_servers) == str:
- servers = FixedServerList(query_servers,
- "9091",
- "/services/query/",
- resource,
- subtype)
- else:
- servers = None
-
wsdl = "file:" + os.path.join(get_datadir(datadir,"query"),
"aviary-query.wsdl")
+
+ super(_AviaryQueryMethods, self).__init__(transports, wsdl)
- super(_AviaryQueryMethods, self).__init__(transports,
- servers,
- wsdl,
- resource,
- subtype)
+ self._init_servers_list(locator,
+ query_servers,
+ "9091",
+ "/services/query/",
+ "CUSTOM",
+ "QUERY_SERVER")
+
def fetch_job_data(self, job_server, job_id, ftype, file, start, end,
scheduler_name, submission, *args, **kwargs):
'''
@@ -1017,29 +1012,18 @@
class _AviaryHadoopMethods(_AviaryCommon):
def __init__(self, locator, transports, datadir, hadoop_servers):
-
- resource = "SCHEDULER"
- subtype = "HADOOP"
- if locator:
- servers = ServerList(locator,
- resource, subtype)
- elif hadoop_servers and type(hadoop_servers) == str:
- servers = FixedServerList(hadoop_servers,
- "9090",
- "/services/hadoop/",
- resource,
- subtype)
- else:
- servers = None
-
+
wsdl = "file:" + os.path.join(get_datadir(datadir,
"hadoop"),
"aviary-hadoop.wsdl")
+
+ super(_AviaryHadoopMethods, self).__init__(transports, wsdl)
- super(_AviaryHadoopMethods, self).__init__(transports,
- servers,
- wsdl,
- resource,
- subtype)
+ self._init_servers_list(locator,
+ hadoop_servers,
+ "9090",
+ "/services/hadoop/",
+ "SCHEDULER",
+ "HADOOP")
# Equivalence? We don't want no stinking QMF structural equivalence!
self.use_MethodResult_for_sync_calls = False
@@ -1232,29 +1216,19 @@
class _AviaryCollectorMethods(_AviaryCommon):
def __init__(self, locator, transports, datadir, collector_servers):
- resource = "COLLECTOR"
- subtype = ""
- if locator:
- servers = ServerList(locator,
- resource, subtype)
- elif collector_servers and type(collector_servers) == str:
- servers = FixedServerList(collector_servers,
- "9000",
- "/services/collector/",
- resource,
- subtype)
- else:
- servers = None
-
wsdl = "file:" + os.path.join(get_datadir(datadir,
"collector"),
"aviary-collector.wsdl")
+
+ super(_AviaryCollectorMethods, self).__init__(transports, wsdl)
- super(_AviaryCollectorMethods, self).__init__(transports,
- servers,
- wsdl,
- resource,
- subtype)
+ self._init_servers_list(locator,
+ collector_servers,
+ "9000",
+ "/services/collector/",
+ "COLLECTOR",
+ "")
+
# Equivalence? We don't want no stinking QMF structural equivalence!
self.use_MethodResult_for_sync_calls = False