Skip to content
Permalink
Browse files

Optimize the number of _daemon_status() calls

* undue doubled call in the svcs_selector codepath
* undue extra call in the "ls" codepath
* add shortcut with no _daemon_status call for exact-match locally installed
object
  • Loading branch information...
cvaroqui committed Jul 22, 2019
1 parent 258ea2a commit 859eccf8ada49c56493d7ccffec3e91f1c2d8920
Showing with 29 additions and 13 deletions.
  1. +4 −0 lib/mgr.py
  2. +17 −6 lib/node.py
  3. +8 −7 lib/rcUtilities.py
@@ -208,6 +208,10 @@ def dispatch(self, argv):
action = self.get_action(argv)
if action in ("create", "deploy"):
expanded_svcs = selector.split(",")
elif action == "ls":
mod = __import__("svcmgr_parser")
parser = getattr(mod, "SvcmgrOptParser")()
yield parser
else:
expanded_svcs = self.node.svcs_selector(selector, namespace)
svc_by_kind = self.dispatch_svcs(expanded_svcs)
@@ -621,6 +621,13 @@ def svcs_selector(self, selector, namespace=None, data=None):
Given a selector string, return a list of service names.
This exposed method only aggregates ORed elements.
"""
# fully qualified name
path = is_service(selector, namespace, data=data, local=data is None)
if path:
self.options.single_service = True
paths = self.filter_ns([path], namespace)
return paths

if data is None or not data.get("retryable"):
try:
data = self._daemon_status(silent=True)["monitor"]
@@ -642,11 +649,12 @@ def svcs_selector(self, selector, namespace=None, data=None):
return paths

# fully qualified name
path = is_service(selector, namespace, data=data)
if path:
self.options.single_service = True
paths = self.filter_ns([path], namespace)
return paths
if data is not None:
path = is_service(selector, namespace, data=data)
if path:
self.options.single_service = True
paths = self.filter_ns([path], namespace)
return paths

# fnmatch on names and service config/status filtering
try:
@@ -658,7 +666,10 @@ def svcs_selector(self, selector, namespace=None, data=None):
return paths

def _svcs_selector(self, selector, data=None, namespace=None):
cluster_data = self._daemon_status()
if data:
cluster_data = {"monitor": data}
else:
cluster_data = self._daemon_status()
if cluster_data:
self.build_services(paths=[s for s in cluster_data.get("monitor", {}).get("services", {})])
elif not want_context():
@@ -1153,7 +1153,7 @@ def daemon_test_lock():
#
#############################################################################

def is_service(f, namespace=None, data=None):
def is_service(f, namespace=None, data=None, local=False):
if f is None:
return
f = re.sub(".conf$", "", f)
@@ -1163,12 +1163,13 @@ def is_service(f, namespace=None, data=None):
except ValueError:
return
path = fmt_path(name, namespace, kind)
try:
data["services"][path]
return path
except Exception:
if want_context():
return
if not local:
try:
data["services"][path]
return path
except Exception:
if want_context():
return
cf = svc_pathcf(path)
if not os.path.exists(cf):
return

0 comments on commit 859eccf

Please sign in to comment.
You can’t perform that action at this time.