Browse Source

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
Pranesh Pandurangan 4 years ago
parent
commit
68654b7b86
2 changed files with 30 additions and 0 deletions
  1. 10
    0
      entropy/engine.py
  2. 20
    0
      entropy/states.py

+ 10
- 0
entropy/engine.py View File

@@ -31,6 +31,7 @@ import six
31 31
 from stevedore import driver
32 32
 
33 33
 from entropy import exceptions
34
+from entropy import states
34 35
 from entropy import utils
35 36
 import imp
36 37
 LOG = logging.getLogger(__name__)
@@ -80,6 +81,9 @@ class Engine(object):
80 81
         # Serializer related variables
81 82
         self._serializer = None
82 83
 
84
+        # State related variables
85
+        self._state = states.ENABLED
86
+
83 87
         LOG.info('Created engine obj %s', self.name)
84 88
 
85 89
     # TODO(praneshp): Move to utils?
@@ -196,6 +200,7 @@ class Engine(object):
196 200
                     new_additions.append({'time': next_call, 'name': key})
197 201
 
198 202
             new_additions.sort(key=operator.itemgetter('time'))
203
+
199 204
             self.run_queue.extend(new_additions)
200 205
             LOG.info("Run queue till %s is %s", next_iteration, self.run_queue)
201 206
             LOG.info("Repair scripts at %s: %s", next_iteration, self._repairs)
@@ -209,7 +214,12 @@ class Engine(object):
209 214
             self.stop_engine()
210 215
 
211 216
     def stop_engine(self):
217
+        LOG.info("Stopping engine %s", self.name)
218
+        # Set state to stop, which will stop serializers
219
+        LOG.info("Setting %s to state: %s", self.name, states.DISABLED)
220
+        self._state = states.DISABLED
212 221
         # Stop watchdog monitoring
222
+        LOG.info("Stopping watchdog for %s", self.name)
213 223
         self._watchdog_thread.stop()
214 224
 
215 225
     def repair_modified(self):

+ 20
- 0
entropy/states.py View File

@@ -0,0 +1,20 @@
1
+# -*- coding: utf-8 -*-
2
+
3
+#    Copyright (C) 2012-2013 Yahoo! Inc. All Rights Reserved.
4
+#
5
+#    Licensed under the Apache License, Version 2.0 (the "License"); you may
6
+#    not use this file except in compliance with the License. You may obtain
7
+#    a copy of the License at
8
+#
9
+#         http://www.apache.org/licenses/LICENSE-2.0
10
+#
11
+#    Unless required by applicable law or agreed to in writing, software
12
+#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13
+#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14
+#    License for the specific language governing permissions and limitations
15
+#    under the License.
16
+
17
+
18
+# Job states.
19
+ENABLED = 'CLAIMED'
20
+DISABLED = 'COMPLETE'

Loading…
Cancel
Save