From 3d21f125768ba16e2fdda8caee648bec33c96901 Mon Sep 17 00:00:00 2001 From: doantungbk Date: Thu, 9 Feb 2017 21:43:33 -0800 Subject: [PATCH] Add monitoring node in tosca-parser This patch will focus on: 1. Defining a monitoring node as an EXPERIMENTAL feature 2. Enhancing trigger to further support monitoring policy 3. Validating trigger policy Change-Id: Idd5268b7ff0a19b57ea927f23c76db24220c462d --- toscaparser/elements/TOSCA_definition_1_0.yaml | 5 +++++ toscaparser/triggers.py | 17 +++++++++++++++-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/toscaparser/elements/TOSCA_definition_1_0.yaml b/toscaparser/elements/TOSCA_definition_1_0.yaml index b42c036..aa208a4 100644 --- a/toscaparser/elements/TOSCA_definition_1_0.yaml +++ b/toscaparser/elements/TOSCA_definition_1_0.yaml @@ -918,6 +918,11 @@ policy_types: description: The TOSCA Policy Type definition that is used to govern scaling of TOSCA nodes or groups of nodes. + tosca.policies.Monitoring: + derived_from: tosca.policies.Root + description: The TOSCA Policy Type definition that is used to govern + monitoring of TOSCA nodes or groups of nodes. + tosca.policies.Update: derived_from: tosca.policies.Root description: The TOSCA Policy Type definition that is used to govern diff --git a/toscaparser/triggers.py b/toscaparser/triggers.py index 9edeef4..bdbcb71 100644 --- a/toscaparser/triggers.py +++ b/toscaparser/triggers.py @@ -16,12 +16,15 @@ import logging from toscaparser.common.exception import ExceptionCollector from toscaparser.common.exception import UnknownFieldError from toscaparser.entity_template import EntityTemplate +from toscaparser.utils import validateutils SECTIONS = (DESCRIPTION, EVENT, SCHEDULE, TARGET_FILTER, CONDITION, ACTION) = \ ('description', 'event_type', 'schedule', 'target_filter', 'condition', 'action') -CONDITION_KEYNAMES = (CONTRAINT, PERIOD, EVALUATIONS, METHOD) = \ - ('constraint', 'period', 'evaluations', 'method') +CONDITION_KEYNAMES = (METER_NAME, CONSTRAINT, PERIOD, EVALUATIONS, METHOD, + THRESHOLD, COMPARISON_OPERATOR) = \ + ('meter_name', 'constraint', 'period', 'evaluations', + 'method', 'threshold', 'comparison_operator') log = logging.getLogger('tosca') @@ -34,6 +37,7 @@ class Triggers(EntityTemplate): self.trigger_tpl = trigger_tpl self._validate_keys() self._validate_condition() + self._validate_input() def get_description(self): return self.trigger_tpl['description'] @@ -66,3 +70,12 @@ class Triggers(EntityTemplate): ExceptionCollector.appendException( UnknownFieldError(what='Triggers "%s"' % self.name, field=key)) + + def _validate_input(self): + for key, value in self.get_condition().items(): + if key in [PERIOD, EVALUATIONS]: + validateutils.validate_integer(value) + elif key == THRESHOLD: + validateutils.validate_numeric(value) + elif key in [METER_NAME, METHOD]: + validateutils.validate_string(value)