示例#1
0
def a_number_of_equal_attributes_for_the_epl_with_the_data(
        step, attributes_number):
    """
    | attribute_id_prefix | attribute_value_type | attribute_operation | attribute_value |
    | temperature_        | float                | >                   | 1.5             |
    :param step:
    :param number:
    :return:
    """
    # Check there is at las one row
    example = """
      | attribute_id_prefix | attribute_value_type | attribute_operation | attribute_value |
      | temperature_        | float                | >                   | 1.5             |
    """
    assert len(
        step.hashes
    ) == 1, 'The line (only one) attributes data is mandatory in this steps, with the format: \n {example}'.format(
        example=example)
    for i in range(0, int(attributes_number)):
        world.epl_attributes.append({
            'id':
            '{prefix}_{iterator}'.format(
                prefix=step.hashes[0]['attribute_id_prefix'], iterator=i),
            'type':
            step.hashes[0]['attribute_value_type'],
            'operation':
            step.hashes[0]['attribute_operation'],
            'value':
            step.hashes[0]['attribute_value'],
        })
    world.log.debug('Setting the EPL attributes as \n"{attributes}"'.format(
        attributes=pretty(world.epl_attributes)))
示例#2
0
def append_a_new_rule_name_activate(step, name, active):
    world.rules.append(
        world.rules_utils.create_card_rule(name, active, world.cards))
    world.cards = []
    world.log.debug('Creating the visual rule: \n {visual_rule}'.format(
        visual_rule=pretty(world.rules[len(world.rules) - 1])))
    world.resp = world.cep.create_visual_rule(world.rules[len(world.rules) -
                                                          1])
示例#3
0
def create_visual_rules_group1_with_prefix_group2_sensor_cards_and_an_action_card_group3(step, number, prefix, action):
    sensor_types = []
    for hash in step.hashes:
        sensor_types.append(hash['sensorCardType'])
    for i in range(0, int(number)):
        name = prefix + str(i)
        world.rules.append(world.rules_utils.util_create_card_rule_with_some_sensor_types(sensor_types, action, name))
        world.resp = world.cep.create_visual_rule(world.rules[len(world.rules) - 1])
        assert world.resp.status_code == 201, 'There was an error creating the visual rule: \n {visual_rule}'.format(
            visual_rule=pretty(world.rules[len(world.rules) - 1]))
示例#4
0
def create_visual_rules_group1_with_prefix_group2_sensor_cards_and_an_action_card_group3(
        step, number, prefix, action):
    sensor_types = []
    for hash in step.hashes:
        sensor_types.append(hash['sensorCardType'])
    for i in range(0, int(number)):
        name = prefix + str(i)
        world.rules.append(
            world.rules_utils.util_create_card_rule_with_some_sensor_types(
                sensor_types, action, name))
        world.resp = world.cep.create_visual_rule(
            world.rules[len(world.rules) - 1])
        assert world.resp.status_code == 201, 'There was an error creating the visual rule: \n {visual_rule}'.format(
            visual_rule=pretty(world.rules[len(world.rules) - 1]))
示例#5
0
def add_to_the_notification_an_entity_with_id_and_type_with_the_amount_of_equal_attributes_with_the_following_data(
        step, entity_id, entity_type, attributes_number):
    """
    Add an entity with a number of attributes changing the id with a prefix. The attributes data is only one line
          | attribute_id_prefix | attribute_type | attribute_new_value |
          | temperature         | celcius        | 300                 |
    :param step:
    :param entity_id:
    :param entity_type:
    :param attributes_number:
    :return:

    """
    # Check there is at las one row
    example = """
      | attribute_id_prefix | attribute_type | attribute_new_value |
      | temperature         | celcius        | 300                 |
    """
    assert len(
        step.hashes
    ) == 1, 'The line (only one) attributes data is mandatory in this steps, with the format: \n {example}'.format(
        example=example)
    # Create a context element
    context_element = ContextElement(entity_id, entity_type)
    for i in range(0, int(attributes_number)):
        attribute_id = '{prefix}_{iterator}'.format(
            prefix=step.hashes[0]['attribute_id_prefix'], iterator=i)
        world.log.debug(
            'Add attribute to the context element with attribute id "{attribute_id}", attribute type "{attribute_type}" and attirbute new value "{attribute_new_value}"'
            .format(attribute_id=attribute_id,
                    attribute_type=step.hashes[0]['attribute_type'],
                    attribute_new_value=step.hashes[0]['attribute_new_value']))
        context_element.add_attribute(attribute_id,
                                      step.hashes[0]['attribute_type'],
                                      step.hashes[0]['attribute_new_value'])
    world.log.debug(
        'Setting the context element of the notification as \n"{context_elemlent}"'
        .format(
            context_elemlent=pretty(context_element.get_context_element())))
    world.notification.add_context_response(context_element)
示例#6
0
def with_the_epl_generated_and_the_action_append_a_new_rule_in_perseo(
        step, rule_name):
    """
    Generate the plain rule with the action and create it in perseo
    :param step:
    :param rule_name
    :return:
    """
    # Check the name is the same name of the EPL
    if not world.epl_sentence.find(rule_name) >= 0:
        world.log.warning(
            'The rule name is not the same in the rule and in the epl.\n The epl is: {epl_sentence} \n The rule name is "{rule_name}"'
            .format(epl_sentence=world.epl_sentence, rule_name=rule_name))
    # Generate the payload
    plain_rule_payload = world.rules_utils.create_plain_rule_payload(
        rule_name, world.epl_sentence, world.action)
    world.rules.append(plain_rule_payload)
    world.log.debug(
        "Creating a plain rule in cep with the payload: \n {payload}".format(
            payload=pretty(plain_rule_payload)))
    # Crteate the plain rule in perseo
    world.resp = world.cep.create_plain_rule(world.rules[len(world.rules) - 1])
示例#7
0
def the_attributes_for_the_epl(step):
    """
      | attribute_id | attribute_value_type | attribute_operation | attribute_value |
      | temperature  | float                | >                   | 1.5             |
    """
    # Check there is at las one row
    example = """
      | attribute_id | attribute_value_type | attribute_operation | attribute_value |
      | temperature  | float                | >                   | 1.5             |
    """
    assert len(
        step.hashes
    ) >= 1, 'The attributes data are mandatory in this steps, with the format: \n {example}'.format(
        example=example)
    for row in step.hashes:
        world.epl_attributes.append({
            'id': row['attribute_id'],
            'type': row['attribute_value_type'],
            'operation': row['attribute_operation'],
            'value': row['attribute_value']
        })
    world.log.debug('Setting the EPL attributes as \n"{attributes}"'.format(
        attributes=pretty(world.epl_attributes)))
示例#8
0
def the_notification_is_sent_to_perseo_in_xml_format(step):
    payload = world.notification.get_notification_xml_payload()
    world.log.debug(
        'Sent to cep the notification payload: \n {payload}'.format(
            payload=pretty(payload)))
    world.resp = world.cep.notify(payload)
示例#9
0
文件: epl.py 项目: jcanonav/perseo-fe
def a_number_of_equal_attributes_for_the_epl_with_the_data(step, attributes_number):
    """
    | attribute_id_prefix | attribute_value_type | attribute_operation | attribute_value |
    | temperature_        | float                | >                   | 1.5             |
    :param step:
    :param number:
    :return:
    """
    # Check there is at las one row
    example = """
      | attribute_id_prefix | attribute_value_type | attribute_operation | attribute_value |
      | temperature_        | float                | >                   | 1.5             |
    """
    assert len(step.hashes) == 1, 'The line (only one) attributes data is mandatory in this steps, with the format: \n {example}'.format(example=example)
    for i in range(0,int(attributes_number)):
        world.epl_attributes.append({
            'id': '{prefix}_{iterator}'.format(prefix=step.hashes[0]['attribute_id_prefix'], iterator=i),
            'type': step.hashes[0]['attribute_value_type'],
            'operation': step.hashes[0]['attribute_operation'],
            'value': step.hashes[0]['attribute_value'],
        })
    world.log.debug('Setting the EPL attributes as \n"{attributes}"'.format(attributes=pretty(world.epl_attributes)))
示例#10
0
文件: epl.py 项目: jcanonav/perseo-fe
def the_attributes_for_the_epl(step):
    """
      | attribute_id | attribute_value_type | attribute_operation | attribute_value |
      | temperature  | float                | >                   | 1.5             |
    """
    # Check there is at las one row
    example = """
      | attribute_id | attribute_value_type | attribute_operation | attribute_value |
      | temperature  | float                | >                   | 1.5             |
    """
    assert len(step.hashes) >= 1, 'The attributes data are mandatory in this steps, with the format: \n {example}'.format(example=example)
    for row in step.hashes:
        world.epl_attributes.append({
            'id': row['attribute_id'],
            'type': row['attribute_value_type'],
            'operation': row['attribute_operation'],
            'value': row['attribute_value']
        })
    world.log.debug('Setting the EPL attributes as \n"{attributes}"'.format(attributes=pretty(world.epl_attributes)))
示例#11
0
def append_a_new_rule_name_activate(step, name, active):
    world.rules.append(world.rules_utils.create_card_rule(name, active, world.cards))
    world.cards = []
    world.log.debug('Creating the visual rule: \n {visual_rule}'.format(visual_rule=pretty(world.rules[len(world.rules)-1])))
    world.resp = world.cep.create_visual_rule(world.rules[len(world.rules) - 1])
示例#12
0
def with_the_epl_generated_and_the_action_append_a_new_rule_in_perseo(step, rule_name):
    """
    Generate the plain rule with the action and create it in perseo
    :param step:
    :param rule_name
    :return:
    """
    # Check the name is the same name of the EPL
    if not world.epl_sentence.find(rule_name) >= 0:
        world.log.warning('The rule name is not the same in the rule and in the epl.\n The epl is: {epl_sentence} \n The rule name is "{rule_name}"'.format(epl_sentence=world.epl_sentence, rule_name=rule_name))
    # Generate the payload
    plain_rule_payload = world.rules_utils.create_plain_rule_payload(rule_name, world.epl_sentence, world.action)
    world.rules.append(plain_rule_payload)
    world.log.debug("Creating a plain rule in cep with the payload: \n {payload}".format(payload=pretty(plain_rule_payload)))
    # Crteate the plain rule in perseo
    world.resp = world.cep.create_plain_rule(world.rules[len(world.rules) - 1])
示例#13
0
def the_notification_is_sent_to_perseo(step):
    payload = world.notification.get_notification_payload()
    world.log.debug('Sent to cep the notification payload: \n {payload}'.format(payload=pretty(payload)))
    world.resp = world.cep.notify(payload)
示例#14
0
def add_to_the_notification_an_entity_with_id_and_type_with_the_amount_of_equal_attributes_with_the_following_data(step, entity_id, entity_type, attributes_number):
    """
    Add an entity with a number of attributes changing the id with a prefix. The attributes data is only one line
          | attribute_id_prefix | attribute_type | attribute_new_value |
          | temperature         | celcius        | 300                 |
    :param step:
    :param entity_id:
    :param entity_type:
    :param attributes_number:
    :return:

    """
    # Check there is at las one row
    example = """
      | attribute_id_prefix | attribute_type | attribute_new_value |
      | temperature         | celcius        | 300                 |
    """
    assert len(step.hashes) == 1, 'The line (only one) attributes data is mandatory in this steps, with the format: \n {example}'.format(example=example)
    # Create a context element
    context_element = ContextElement(entity_id, entity_type)
    for i in range(0, int(attributes_number)):
        attribute_id = '{prefix}_{iterator}'.format(prefix=step.hashes[0]['attribute_id_prefix'], iterator=i)
        world.log.debug('Add attribute to the context element with attribute id "{attribute_id}", attribute type "{attribute_type}" and attirbute new value "{attribute_new_value}"'.format(attribute_id=attribute_id, attribute_type=step.hashes[0]['attribute_type'], attribute_new_value=step.hashes[0]['attribute_new_value']))
        context_element.add_attribute(attribute_id, step.hashes[0]['attribute_type'], step.hashes[0]['attribute_new_value'])
    world.log.debug('Setting the context element of the notification as \n"{context_elemlent}"'.format(context_elemlent=pretty(context_element.get_context_element())))
    world.notification.add_context_response(context_element)