From 68654b7b863b00a31f59953b63c5e528e99f118e Mon Sep 17 00:00:00 2001 From: Pranesh Pandurangan Date: Thu, 12 Jun 2014 20:04:23 -0700 Subject: [PATCH] Introduce engine states Introduce two states, ENABLED and DISABLED, in a new states.py file, and set engine to disabled when stopped, and enabled when running Change-Id: I1d4c89b453ac04cd5dce09c5faafe3241cd2dc43 --- entropy/engine.py | 10 ++++++++++ entropy/states.py | 20 ++++++++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 entropy/states.py diff --git a/entropy/engine.py b/entropy/engine.py index cb571cc..36470e3 100644 --- a/entropy/engine.py +++ b/entropy/engine.py @@ -31,6 +31,7 @@ import six from stevedore import driver from entropy import exceptions +from entropy import states from entropy import utils import imp LOG = logging.getLogger(__name__) @@ -80,6 +81,9 @@ class Engine(object): # Serializer related variables self._serializer = None + # State related variables + self._state = states.ENABLED + LOG.info('Created engine obj %s', self.name) # TODO(praneshp): Move to utils? @@ -196,6 +200,7 @@ class Engine(object): new_additions.append({'time': next_call, 'name': key}) new_additions.sort(key=operator.itemgetter('time')) + self.run_queue.extend(new_additions) LOG.info("Run queue till %s is %s", next_iteration, self.run_queue) LOG.info("Repair scripts at %s: %s", next_iteration, self._repairs) @@ -209,7 +214,12 @@ class Engine(object): self.stop_engine() def stop_engine(self): + LOG.info("Stopping engine %s", self.name) + # Set state to stop, which will stop serializers + LOG.info("Setting %s to state: %s", self.name, states.DISABLED) + self._state = states.DISABLED # Stop watchdog monitoring + LOG.info("Stopping watchdog for %s", self.name) self._watchdog_thread.stop() def repair_modified(self): diff --git a/entropy/states.py b/entropy/states.py new file mode 100644 index 0000000..e0fc598 --- /dev/null +++ b/entropy/states.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- + +# Copyright (C) 2012-2013 Yahoo! Inc. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + + +# Job states. +ENABLED = 'CLAIMED' +DISABLED = 'COMPLETE'