Merge "Refactor mistral workflow handle_signal"
This commit is contained in:
commit
75e945a851
|
@ -11,6 +11,8 @@
|
||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
|
import copy
|
||||||
|
|
||||||
from oslo_serialization import jsonutils
|
from oslo_serialization import jsonutils
|
||||||
import six
|
import six
|
||||||
import yaml
|
import yaml
|
||||||
|
@ -366,25 +368,24 @@ class Workflow(signal_responder.SignalResponder,
|
||||||
params = data.get(self.SIGNAL_DATA_PARAMS)
|
params = data.get(self.SIGNAL_DATA_PARAMS)
|
||||||
return inputs, params
|
return inputs, params
|
||||||
|
|
||||||
def _validate_signal_data(self, data):
|
def _validate_signal_data(self, inputs, params):
|
||||||
input_value, params_value = self._get_inputs_and_params(data)
|
if inputs is not None:
|
||||||
if input_value is not None:
|
if not isinstance(inputs, dict):
|
||||||
if not isinstance(input_value, dict):
|
|
||||||
message = (_('Input in signal data must be a map, '
|
message = (_('Input in signal data must be a map, '
|
||||||
'find a %s') % type(input_value))
|
'find a %s') % type(inputs))
|
||||||
raise exception.StackValidationFailed(
|
raise exception.StackValidationFailed(
|
||||||
error=_('Signal data error'),
|
error=_('Signal data error'),
|
||||||
message=message)
|
message=message)
|
||||||
for key in six.iterkeys(input_value):
|
for key in six.iterkeys(inputs):
|
||||||
if (self.properties.get(self.INPUT) is None
|
if (self.properties.get(self.INPUT) is None or
|
||||||
or key not in self.properties.get(self.INPUT)):
|
key not in self.properties.get(self.INPUT)):
|
||||||
message = _('Unknown input %s') % key
|
message = _('Unknown input %s') % key
|
||||||
raise exception.StackValidationFailed(
|
raise exception.StackValidationFailed(
|
||||||
error=_('Signal data error'),
|
error=_('Signal data error'),
|
||||||
message=message)
|
message=message)
|
||||||
if params_value is not None and not isinstance(params_value, dict):
|
if params is not None and not isinstance(params, dict):
|
||||||
message = (_('Params must be a map, find a '
|
message = (_('Params must be a map, find a '
|
||||||
'%s') % type(params_value))
|
'%s') % type(params))
|
||||||
raise exception.StackValidationFailed(
|
raise exception.StackValidationFailed(
|
||||||
error=_('Signal data error'),
|
error=_('Signal data error'),
|
||||||
message=message)
|
message=message)
|
||||||
|
@ -513,34 +514,24 @@ class Workflow(signal_responder.SignalResponder,
|
||||||
self.resource_id_set(workflow[0].name)
|
self.resource_id_set(workflow[0].name)
|
||||||
|
|
||||||
def handle_signal(self, details=None):
|
def handle_signal(self, details=None):
|
||||||
self._validate_signal_data(details)
|
|
||||||
|
|
||||||
result_input = {}
|
|
||||||
result_params = {}
|
|
||||||
inputs, params = self._get_inputs_and_params(details)
|
inputs, params = self._get_inputs_and_params(details)
|
||||||
if inputs is not None:
|
self._validate_signal_data(inputs, params)
|
||||||
# NOTE(prazumovsky): Signal can contains some data, interesting
|
|
||||||
# for workflow, e.g. inputs. So, if signal data contains input
|
|
||||||
# we update override inputs, other leaved defined in template.
|
|
||||||
for key, value in six.iteritems(
|
|
||||||
self.properties.get(self.INPUT)):
|
|
||||||
result_input.update(
|
|
||||||
{key: inputs.get(key) or value})
|
|
||||||
if params is not None:
|
|
||||||
if self.properties.get(self.PARAMS) is not None:
|
|
||||||
result_params.update(self.properties.get(self.PARAMS))
|
|
||||||
result_params.update(params)
|
|
||||||
|
|
||||||
if not result_input and self.properties.get(self.INPUT):
|
inputs_result = copy.deepcopy(self.properties[self.INPUT])
|
||||||
result_input.update(self.properties.get(self.INPUT))
|
params_result = copy.deepcopy(self.properties[self.PARAMS]) or {}
|
||||||
if not result_params and self.properties.get(self.PARAMS):
|
# NOTE(prazumovsky): Signal can contains some data, interesting
|
||||||
result_params.update(self.properties.get(self.PARAMS))
|
# for workflow, e.g. inputs. So, if signal data contains input
|
||||||
|
# we update override inputs, other leaved defined in template.
|
||||||
|
if inputs:
|
||||||
|
inputs_result.update(inputs)
|
||||||
|
if params:
|
||||||
|
params_result.update(params)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
execution = self.client().executions.create(
|
execution = self.client().executions.create(
|
||||||
self._workflow_name(),
|
self._workflow_name(),
|
||||||
jsonutils.dumps(result_input),
|
jsonutils.dumps(inputs_result),
|
||||||
**result_params)
|
**params_result)
|
||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
raise exception.ResourceFailure(ex, self)
|
raise exception.ResourceFailure(ex, self)
|
||||||
executions = [execution.id]
|
executions = [execution.id]
|
||||||
|
|
Loading…
Reference in New Issue