Progress adjust metadata refactoring
Changed the name of the constant and the yaml key to better reflect the purpose. Now the value is an integer which represents the adjustment value used to compute the percentage completion when applying charts. Cleaned up the code around the usage of the value and computing the percentage. Story: 2007960 Task: 41959 Signed-off-by: Andrei Grosu <andrei.grosu@windriver.com> Change-Id: Ia3b07b83762cdf20f6809222dc687f67c15deee5
This commit is contained in:
parent
7a2a54c2b7
commit
7dcdfaae89
|
@ -1588,7 +1588,8 @@ APP_LIFECYCLE_OPERATION_MTC_ACTION = 'mtc-action'
|
|||
|
||||
# Application metadata constants
|
||||
APP_METADATA_MAINTAIN_USER_OVERRIDES = 'maintain_user_overrides'
|
||||
APP_METADATA_HELM_TOOLKIT_REQUIRED = 'helm_toolkit_required'
|
||||
APP_METADATA_APPLY_PROGRESS_ADJUST = 'apply_progress_adjust'
|
||||
APP_METADATA_APPLY_PROGRESS_ADJUST_DEFAULT_VALUE = 0
|
||||
APP_METADATA_APPS = 'apps'
|
||||
APP_METADATA_BEHAVIOR = 'behavior'
|
||||
APP_METADATA_EVALUATE_REAPPLY = 'evaluate_reapply'
|
||||
|
|
|
@ -1927,6 +1927,10 @@ def find_metadata_file(path, metadata_file):
|
|||
dictionary. If specified the filters are applied
|
||||
to trigger[filter_field] sub-dictionary instead
|
||||
of the root trigger dictionary.
|
||||
apply_progress_adjust: - optional: Positive integer value by which to adjust the
|
||||
percentage calculations for the progress of
|
||||
a monitoring task.
|
||||
Default value is zero (no adjustment)
|
||||
"""
|
||||
app_name = ''
|
||||
app_version = ''
|
||||
|
@ -2061,6 +2065,23 @@ def find_metadata_file(path, metadata_file):
|
|||
except KeyError:
|
||||
pass
|
||||
|
||||
try:
|
||||
apply_progress_adjust_value = doc[constants.APP_METADATA_APPLY_PROGRESS_ADJUST]
|
||||
if not isinstance(apply_progress_adjust_value, six.integer_types):
|
||||
raise exception.SysinvException(_(
|
||||
"Invalid {}: {} should be {}."
|
||||
"".format(metadata_file,
|
||||
constants.APP_METADATA_APPLY_PROGRESS_ADJUST,
|
||||
six.integer_types)))
|
||||
if apply_progress_adjust_value < 0:
|
||||
raise exception.SysinvException(_(
|
||||
"Invalid {}: {} should be greater or equal to zero."
|
||||
"".format(metadata_file,
|
||||
constants.APP_METADATA_APPLY_PROGRESS_ADJUST)))
|
||||
|
||||
except KeyError:
|
||||
pass
|
||||
|
||||
return app_name, app_version, patches
|
||||
|
||||
|
||||
|
|
|
@ -1252,7 +1252,7 @@ class AppOperator(object):
|
|||
except Exception as e:
|
||||
LOG.exception(e)
|
||||
|
||||
def _get_metadata_flag(self, app, flag, default):
|
||||
def _get_metadata_value(self, app, flag, default):
|
||||
# This function gets a boolean
|
||||
# parameter from application metadata
|
||||
flag_result = default
|
||||
|
@ -1363,20 +1363,14 @@ class AppOperator(object):
|
|||
""" Progress monitoring task, to be run in a separate thread """
|
||||
LOG.info("Starting progress monitoring thread for app %s" % app.name)
|
||||
|
||||
def _progress_adjust(app):
|
||||
helm_toolkit_app = \
|
||||
self._get_metadata_flag(app,
|
||||
constants.APP_METADATA_HELM_TOOLKIT_REQUIRED,
|
||||
True)
|
||||
|
||||
if helm_toolkit_app:
|
||||
return 1
|
||||
else:
|
||||
return 0
|
||||
|
||||
try:
|
||||
adjust = self._get_metadata_value(app,
|
||||
constants.APP_METADATA_APPLY_PROGRESS_ADJUST,
|
||||
constants.APP_METADATA_APPLY_PROGRESS_ADJUST_DEFAULT_VALUE)
|
||||
with Timeout(INSTALLATION_TIMEOUT,
|
||||
exception.KubeAppProgressMonitorTimeout()):
|
||||
|
||||
charts_count = len(app.charts)
|
||||
while True:
|
||||
try:
|
||||
monitor_flag.get_nowait()
|
||||
|
@ -1386,19 +1380,27 @@ class AppOperator(object):
|
|||
except queue.Empty:
|
||||
last, num = _get_armada_log_stats(pattern, logfile)
|
||||
if last:
|
||||
if app.system_app:
|
||||
adjust = _progress_adjust(app)
|
||||
percent = \
|
||||
round(float(num) /
|
||||
(len(app.charts) - adjust) * 100)
|
||||
if charts_count == 0:
|
||||
percent = 100
|
||||
else:
|
||||
percent = round(float(num) / len(app.charts) * 100)
|
||||
progress_str = 'processing chart: ' + str(last) +\
|
||||
', overall completion: ' + str(percent) + '%'
|
||||
tadjust = 0
|
||||
if app.system_app:
|
||||
tadjust = adjust
|
||||
if tadjust >= charts_count:
|
||||
LOG.error("Application metadata key '{}'"
|
||||
"has an invalid value {} (too few charts)".
|
||||
format(constants.APP_METADATA_APPLY_PROGRESS_ADJUST,
|
||||
adjust))
|
||||
tadjust = 0
|
||||
|
||||
percent = round((float(num) / (charts_count - tadjust)) * 100)
|
||||
|
||||
progress_str = "processing chart: {}, overall completion: {}%".\
|
||||
format(last, percent)
|
||||
|
||||
if app.progress != progress_str:
|
||||
LOG.info("%s" % progress_str)
|
||||
self._update_app_status(
|
||||
app, new_progress=progress_str)
|
||||
self._update_app_status(app, new_progress=progress_str)
|
||||
greenthread.sleep(1)
|
||||
except Exception as e:
|
||||
# timeout or subprocess error
|
||||
|
@ -2420,9 +2422,9 @@ class AppOperator(object):
|
|||
result = False
|
||||
if operation == constants.APP_APPLY_OP:
|
||||
reuse_overrides = \
|
||||
self._get_metadata_flag(to_app,
|
||||
constants.APP_METADATA_MAINTAIN_USER_OVERRIDES,
|
||||
False)
|
||||
self._get_metadata_value(to_app,
|
||||
constants.APP_METADATA_MAINTAIN_USER_OVERRIDES,
|
||||
False)
|
||||
if reuse_user_overrides is not None:
|
||||
reuse_overrides = reuse_user_overrides
|
||||
|
||||
|
|
Loading…
Reference in New Issue