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
This commit is contained in:
Pranesh Pandurangan 2014-06-12 20:04:23 -07:00
parent 1a860ac47b
commit 68654b7b86
2 changed files with 30 additions and 0 deletions

View File

@ -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):

20
entropy/states.py Normal file
View File

@ -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'