Beispiel #1
0
def _create_trigger(trigger_type):
    """
    :param trigger_type: TriggerType db object.
    :type trigger_type: :class:`TriggerTypeDB`
    """
    if hasattr(trigger_type,
               'parameters_schema') and not trigger_type['parameters_schema']:
        trigger_dict = {
            'name': trigger_type.name,
            'pack': trigger_type.pack,
            'type': trigger_type.get_reference().ref
        }

        try:
            return create_or_update_trigger_db(trigger=trigger_dict)
        except:
            LOG.exception('Validation failed for Trigger=%s.', trigger_dict)
            raise TriggerTypeRegistrationException(
                'Unable to create Trigger for TriggerType=%s.' %
                trigger_type.name)
    else:
        LOG.debug(
            'Won\'t create Trigger object as TriggerType %s expects ' +
            'parameters.', trigger_type)
        return None
Beispiel #2
0
def _create_trigger(pack, trigger_type):
    if hasattr(trigger_type,
               'parameters_schema') and not trigger_type['parameters_schema']:
        trigger_db = TriggerService.get_trigger_db({
            'pack': pack,
            'name': trigger_type.name
        })

        if trigger_db is None:
            trigger_dict = {
                'name': trigger_type.name,
                'pack': pack,
                'type': trigger_type.get_reference().ref
            }

            try:
                trigger_db = TriggerService.create_trigger_db(trigger_dict)
            except:
                LOG.exception('Validation failed for Trigger=%s.',
                              trigger_dict)
                raise TriggerTypeRegistrationException(
                    'Unable to create Trigger for TriggerType=%s.' %
                    trigger_type.name)
            else:
                return trigger_db
    else:
        LOG.debug(
            'Won\'t create Trigger object as TriggerType %s expects ' +
            'parameters.', trigger_type)
        return None
Beispiel #3
0
def _create_trigger(trigger_type):
    """
    :param trigger_type: TriggerType db object.
    :type trigger_type: :class:`TriggerTypeDB`
    """
    if (hasattr(trigger_type, "parameters_schema")
            and not trigger_type["parameters_schema"]):
        trigger_dict = {
            "name": trigger_type.name,
            "pack": trigger_type.pack,
            "type": trigger_type.get_reference().ref,
        }

        try:
            return create_or_update_trigger_db(trigger=trigger_dict)
        except:
            LOG.exception("Validation failed for Trigger=%s.", trigger_dict)
            raise TriggerTypeRegistrationException(
                "Unable to create Trigger for TriggerType=%s." %
                trigger_type.name)
    else:
        LOG.debug(
            "Won't create Trigger object as TriggerType %s expects " +
            "parameters.",
            trigger_type,
        )
        return None
Beispiel #4
0
def _create_trigger_type(pack,
                         name,
                         description=None,
                         payload_schema=None,
                         parameters_schema=None):
    triggertypes = TriggerType.query(pack=pack, name=name)
    is_update = False
    if len(triggertypes) > 0:
        trigger_type = triggertypes[0]
        LOG.debug(
            'Found existing trigger id:%s with name:%s. Will update '
            'trigger.', trigger_type.id, name)
        is_update = True
    else:
        trigger_type = TriggerTypeDB()

    trigger_type.pack = pack
    trigger_type.name = name
    trigger_type.description = description
    trigger_type.payload_schema = payload_schema
    trigger_type.parameters_schema = parameters_schema
    try:
        triggertype_db = TriggerType.add_or_update(trigger_type)
    except:
        LOG.exception('Validation failed for TriggerType=%s.', trigger_type)
        raise TriggerTypeRegistrationException('Invalid TriggerType name=%s.' %
                                               name)
    if is_update:
        LOG.audit('TriggerType updated. TriggerType=%s', triggertype_db)
    else:
        LOG.audit('TriggerType created. TriggerType=%s', triggertype_db)
    return triggertype_db
Beispiel #5
0
def _validate_trigger_type(trigger_type):
    """
    XXX: We need validator objects that define the required and optional fields.
    For now, manually check them.
    """
    required_fields = ['name']
    for field in required_fields:
        if field not in trigger_type:
            raise TriggerTypeRegistrationException('Invalid trigger type. Missing field %s' % field)