diff options
author | 2017-07-11 15:12:35 -0400 | |
---|---|---|
committer | 2017-07-11 15:47:46 -0400 | |
commit | 7602a54309adbe5c5346ee6befecc2e596976504 (patch) | |
tree | 60f15026780db30b0b8842ba1a1e2cc021e22625 /docker/storperf-master/storperf/utilities/thread_gate.py | |
parent | fc09b37e95c19f820ec60db19d98c0dc3d670829 (diff) |
Change all paths
Changes the paths of all source code so that it exists under the dockerfile location
for each container. This way we can use COPY instead of git clone, as well as use the
existing JJB.
Change-Id: I883b2957d89659c164fff0a1ebc4d677c534796d
JIRA: STORPERF-188
Signed-off-by: mbeierl <mark.beierl@dell.com>
Diffstat (limited to 'docker/storperf-master/storperf/utilities/thread_gate.py')
-rw-r--r-- | docker/storperf-master/storperf/utilities/thread_gate.py | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/docker/storperf-master/storperf/utilities/thread_gate.py b/docker/storperf-master/storperf/utilities/thread_gate.py new file mode 100644 index 0000000..38acbb1 --- /dev/null +++ b/docker/storperf-master/storperf/utilities/thread_gate.py @@ -0,0 +1,67 @@ +############################################################################## +# Copyright (c) 2016 Dell EMC and others. +# +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Apache License, Version 2.0 +# which accompanies this distribution, and is available at +# http://www.apache.org/licenses/LICENSE-2.0 +############################################################################## +""" +Creates a gate object that allows synchronization between an arbitrary +number of callers. +""" +import logging +import time +from threading import Lock + + +class FailureToReportException(Exception): + pass + + +class ThreadGate(object): + + def __init__(self, size, timeout=60): + self.logger = logging.getLogger(__name__) + self._gate_size = size + self._timeout = timeout + self._registrants = {} + self._creation_time = time.time() + self._lock = Lock() + + """ + Calling this method returns a true or false, indicating that enough + of the other registrants have reported in + """ + + def report(self, gate_id): + with self._lock: + now = time.time() + self._registrants[gate_id] = now + ready = True + self.logger.debug("Gate report for %s", gate_id) + + total_missing = self._gate_size - len(self._registrants) + if total_missing > 0: + self.logger.debug("Not all registrants have reported in") + time_since_creation = now - self._creation_time + if (time_since_creation > (self._timeout * 2)): + self.logger.error( + "%s registrant(s) have never reported in", + total_missing) + raise FailureToReportException + return False + + for k, v in self._registrants.items(): + time_since_last_report = now - v + if time_since_last_report > self._timeout: + self.logger.debug("Registrant %s last reported %s ago", + k, time_since_last_report) + ready = False + + self.logger.debug("Gate pass? %s", ready) + + if ready: + self._registrants.clear() + + return ready |