Ejemplo n.º 1
0
                        def core_properties():
                            """
                            Defines node type and power consumption properties.
                            """

                            xml.SubElement(core_xml,
                                           "prop",
                                           attrib={
                                               "id": "node_type",
                                               "value": node["type"]
                                           })
                            for prop in proc_template["core_properties"]:
                                xml.SubElement(core_xml, "prop", attrib=prop)
Ejemplo n.º 2
0
    def _add_test_xml(self, name):
        """Create a XML sub element of 'test_run' with the tag'testcase' and with the attribute 'name' which contains
        the test case name

        :return: (ElementTree) the element which has been created"""
        parent = et.SubElement(self.xml, "testcase", {"name": name})
        return parent
Ejemplo n.º 3
0
            def router():
                """
                Gateway for inter-cluster connections.
                """

                xml.SubElement(cluster_xml,
                               "router",
                               attrib={"id": "rou_{}".format(cluster_idx)})
Ejemplo n.º 4
0
def _add_step_error(error):
    """Add a error sub element with it's value to the given step
    :type error: (ElementTree)

    :return: (ElementTree) the element which has been added
    """
    element = et.SubElement(error, "error")
    return element
Ejemplo n.º 5
0
            def backbone():
                """
                Intra-cluster connections.
                """

                _backbone_attrs = {"id": "bbo_{}".format(cluster_idx)}
                _backbone_attrs.update(
                    network_types[cluster["cluster_network"]])
                xml.SubElement(cluster_xml, "backbone", attrib=_backbone_attrs)
Ejemplo n.º 6
0
def _add_step_xml(parent, step_order):
    """Add a step sub element with an attribute order to the given parent
    :type parent: (ElementTree)
    :type step_order: (int)

    :return: (ElementTree) the element which has been added
    """
    element = et.SubElement(parent, "step", {"order": str(step_order)})
    return element
Ejemplo n.º 7
0
 def config_zone():
     """
     Define node and proc config properties.
     """
     return xml.SubElement(main_zone_xml,
                           "zone",
                           attrib={
                               "id": "config",
                               "routing": "None"
                           })
Ejemplo n.º 8
0
def _add_error_function(error, func):
    """Add a error sub element with it's value to the given step
       :type error: (ElementTree)
       :type func: (String)

       :return: (ElementTree) the element which has been added
       """
    element = et.SubElement(error, "function")
    element.text = func
    return element
Ejemplo n.º 9
0
def _add_step_status(step, status):
    """Add a status sub element with it's value to the given step
    :type step: (ElementTree)
    :type status: (String)

    :return: (ElementTree) the element which has been added
    """
    element = et.SubElement(step, "status")
    element.text = status
    return element
Ejemplo n.º 10
0
def _add_step_description(step, description):
    """Add a description sub element with it's value to the given step
    :type step: (ElementTree)
    :type description: (String)

    :return: (ElementTree) the element which has been added
    """
    element = et.SubElement(step, "description")
    element.text = description
    return element
Ejemplo n.º 11
0
def _add_step_time_xml(step, time):
    """Add a time sub element with it's value to the given step
    :type step: (ElementTree)
    :type time: (String)

    :return: (ElementTree) the element which has been added
    """
    element = et.SubElement(step, "time")
    element.text = time
    return element
Ejemplo n.º 12
0
def _add_error_message(error, message):
    """Add a error sub element with it's value to the given step
       :type error: (ElementTree)
       :type message: (String)

       :return: (ElementTree) the element which has been added
       """
    element = et.SubElement(error, "message")
    element.text = message
    return element
Ejemplo n.º 13
0
        def main_zone():
            """
            Contains master zone and all clusters.
            """

            return xml.SubElement(platform_xml,
                                  "zone",
                                  attrib={
                                      "id": "main",
                                      "routing": "Full"
                                  })
Ejemplo n.º 14
0
            def master_host():
                """
                Executes the scheduling algorithms.
                """

                xml.SubElement(master_zone_xml,
                               "host",
                               attrib={
                                   "id": "master_host",
                                   "speed": "1Gf"
                               })
Ejemplo n.º 15
0
        def global_links():
            """
            Links from clusters to the master zone.
            """

            for cluster_idx in range(len(platform["clusters"])):
                _global_link_attrs = {"id": "tomh_clu_{}".format(cluster_idx)}
                _global_link_attrs.update(
                    network_types[platform["dc_network"]])
                xml.SubElement(main_zone_xml,
                               "link",
                               attrib=_global_link_attrs)
Ejemplo n.º 16
0
                def record_node_type():
                    """
                    Inserts the node type in the already configured ones.
                    """

                    if node["type"] not in recorded_nodes:
                        config_node_type_xml = xml.SubElement(config_node_xml,
                                                              "zone",
                                                              attrib={
                                                                  "id":
                                                                  node["type"],
                                                                  "routing":
                                                                  "None"
                                                              })
                        xml.SubElement(config_node_type_xml,
                                       "prop",
                                       attrib={
                                           "id": "memory",
                                           "value": node_template["memory_gib"]
                                       })
                        recorded_nodes[node["type"]] = True
Ejemplo n.º 17
0
                        def link_association():
                            """
                            Associates up / down link with the core.
                            """

                            xml.SubElement(cluster_xml,
                                           "host_link",
                                           attrib={
                                               "id": core_id,
                                               "up": udlink_id,
                                               "down": udlink_id
                                           })
Ejemplo n.º 18
0
        def routes():
            """
            Routes over global links.
            """

            for cluster_idx in range(len(platform["clusters"])):
                route_xml = xml.SubElement(main_zone_xml,
                                           "zoneRoute",
                                           attrib={
                                               "src":
                                               "clu_{}".format(cluster_idx),
                                               "dst":
                                               "master",
                                               "gw_src":
                                               "rou_{}".format(cluster_idx),
                                               "gw_dst":
                                               "master_host"
                                           })
                xml.SubElement(
                    route_xml,
                    "link_ctn",
                    attrib={"id": "tomh_clu_{}".format(cluster_idx)})
Ejemplo n.º 19
0
                def udlink():
                    """
                    Link between the node and the backbone.
                    """

                    udlink_id = "udl_{}".format(node_id)
                    _udlink_attrs = {
                        "id": udlink_id,
                        "sharing_policy": "SHARED"
                    }
                    _udlink_attrs.update(
                        network_types[cluster["cluster_network"]])
                    xml.SubElement(cluster_xml, "link", attrib=_udlink_attrs)
                    return udlink_id
Ejemplo n.º 20
0
                    def cores():
                        """
                        Individual computing units inside a processor.
                        """
                        def core_properties():
                            """
                            Defines node type and power consumption properties.
                            """

                            xml.SubElement(core_xml,
                                           "prop",
                                           attrib={
                                               "id": "node_type",
                                               "value": node["type"]
                                           })
                            for prop in proc_template["core_properties"]:
                                xml.SubElement(core_xml, "prop", attrib=prop)

                        def link_association():
                            """
                            Associates up / down link with the core.
                            """

                            xml.SubElement(cluster_xml,
                                           "host_link",
                                           attrib={
                                               "id": core_id,
                                               "up": udlink_id,
                                               "down": udlink_id
                                           })

                        for core_idx in range(int(proc_template["nb_cores"])):
                            core_id = "cor_{}_{}".format(core_idx, proc_id)
                            _core_attrs = {"id": core_id}
                            _core_attrs.update(
                                proc_template["core_attributes"])
                            core_xml = xml.SubElement(cluster_xml,
                                                      "host",
                                                      attrib=_core_attrs)
                            core_properties()
                            link_association()
Ejemplo n.º 21
0
        def config_node():
            """
            Holds user defined properties concerning node types.
            """
            def config_zone():
                """
                Define node and proc config properties.
                """
                return xml.SubElement(main_zone_xml,
                                      "zone",
                                      attrib={
                                          "id": "config",
                                          "routing": "None"
                                      })

            return xml.SubElement(config_zone(),
                                  "zone",
                                  attrib={
                                      "id": "node",
                                      "routing": "None"
                                  })
Ejemplo n.º 22
0
        def master_zone():
            """
            Hosts the master node which schedules jobs onto resources.
            """
            def master_host():
                """
                Executes the scheduling algorithms.
                """

                xml.SubElement(master_zone_xml,
                               "host",
                               attrib={
                                   "id": "master_host",
                                   "speed": "1Gf"
                               })

            master_zone_xml = xml.SubElement(main_zone_xml,
                                             "zone",
                                             attrib={
                                                 "id": "master",
                                                 "routing": "None"
                                             })
            master_host()
Ejemplo n.º 23
0
def make_sub_element(parent, tag, nsmap=None):
    """Wrapper for etree.SubElement, that takes care of unsupported nsmap option."""
    if use_lxml:
        return etree.SubElement(parent, tag, nsmap=nsmap)
    return etree.SubElement(parent, tag)
Ejemplo n.º 24
0
    def _go_across(self, obj, serialize_default=False):
        self.register_eobject_epackage(obj)
        eclass = obj.eClass
        if not obj.eContainmentFeature():  # obj is the root
            epackage = eclass.ePackage
            nsURI = epackage.nsURI
            tag = etree.QName(nsURI, eclass.name) if nsURI else eclass.name
            node = etree.Element(tag)
        else:
            node = etree.Element(obj.eContainmentFeature().name)
            if obj.eContainmentFeature().eType != eclass:
                self._add_explicit_type(node, obj)

        if self.use_uuid:
            self._assign_uuid(obj)
            xmi_id = '{{{0}}}id'.format(XMI_URL)
            node.attrib[xmi_id] = obj._internal_id

        for feat in obj._isset:
            if feat.derived or feat.transient:
                continue
            feat_name = feat.name
            value = obj.__getattribute__(feat_name)
            if hasattr(feat.eType, 'eType') and feat.eType.eType is dict:
                for key, val in value.items():
                    entry = etree.Element(feat_name)
                    entry.attrib['key'] = key
                    entry.attrib['value'] = val
                    node.append(entry)
            elif isinstance(feat, Ecore.EAttribute):
                etype = feat.eType
                if feat.many and value:
                    to_str = etype.to_string
                    has_special_char = False
                    result_list = []
                    for v in value:
                        string = to_str(v)
                        if any(x.isspace() for x in string):
                            has_special_char = True
                        result_list.append(string)
                    if has_special_char:
                        for v in result_list:
                            sub = etree.SubElement(node, feat_name)
                            sub.text = v
                    else:
                        node.attrib[feat_name] = ' '.join(result_list)
                    continue
                default_value = feat.get_default_value()
                if value != default_value or serialize_default:
                    if value is None:
                        node.append(self._build_none_node(feat_name))
                    else:
                        node.attrib[feat_name] = etype.to_string(value)
                continue

            elif isinstance(feat, Ecore.EReference) and \
                    feat.eOpposite and feat.eOpposite.containment:
                continue
            elif isinstance(feat, Ecore.EReference) \
                    and not feat.containment:
                if not value:
                    if serialize_default and value is None:
                        node.append(self._build_none_node(feat_name))
                    continue
                if feat.many:
                    results = [self._build_path_from(x) for x in value]
                    embedded = []
                    crossref = []
                    for i, result in enumerate(results):
                        frag, cref = result
                        if cref:
                            crossref.append((i, frag))
                        else:
                            embedded.append(frag)
                    if embedded:
                        result = ' '.join(embedded)
                        node.attrib[feat_name] = result
                    for i, ref in crossref:
                        sub = etree.SubElement(node, feat_name)
                        sub.attrib['href'] = ref
                        self._add_explicit_type(sub, value[i])
                else:
                    frag, is_crossref = self._build_path_from(value)
                    if is_crossref:
                        sub = etree.SubElement(node, feat_name)
                        sub.attrib['href'] = frag
                        self._add_explicit_type(sub, value)
                    else:
                        node.attrib[feat_name] = frag

            if isinstance(feat, Ecore.EReference) and feat.containment:
                children = obj.__getattribute__(feat_name)
                children = children if feat.many else [children]
                for child in children:
                    node.append(self._go_across(child, serialize_default))
        return node
Ejemplo n.º 25
0
        def clusters():
            """
            Groups of nodes inside the data centre.
            """
            def nodes():
                """
                Systems available in the data centre, contain processors and other resources (v. gr. memory).
                They are connected to a common cluster backbone by up / down links.
                """
                def record_node_type():
                    """
                    Inserts the node type in the already configured ones.
                    """

                    if node["type"] not in recorded_nodes:
                        config_node_type_xml = xml.SubElement(config_node_xml,
                                                              "zone",
                                                              attrib={
                                                                  "id":
                                                                  node["type"],
                                                                  "routing":
                                                                  "None"
                                                              })
                        xml.SubElement(config_node_type_xml,
                                       "prop",
                                       attrib={
                                           "id": "memory",
                                           "value": node_template["memory_gib"]
                                       })
                        recorded_nodes[node["type"]] = True

                def udlink():
                    """
                    Link between the node and the backbone.
                    """

                    udlink_id = "udl_{}".format(node_id)
                    _udlink_attrs = {
                        "id": udlink_id,
                        "sharing_policy": "SHARED"
                    }
                    _udlink_attrs.update(
                        network_types[cluster["cluster_network"]])
                    xml.SubElement(cluster_xml, "link", attrib=_udlink_attrs)
                    return udlink_id

                def procs():
                    """
                    Computing resources available in the data centre. These can be CPUs, GPUs, MICs, ...
                    They have a set of cores and power consumption properties.
                    """
                    def cores():
                        """
                        Individual computing units inside a processor.
                        """
                        def core_properties():
                            """
                            Defines node type and power consumption properties.
                            """

                            xml.SubElement(core_xml,
                                           "prop",
                                           attrib={
                                               "id": "node_type",
                                               "value": node["type"]
                                           })
                            for prop in proc_template["core_properties"]:
                                xml.SubElement(core_xml, "prop", attrib=prop)

                        def link_association():
                            """
                            Associates up / down link with the core.
                            """

                            xml.SubElement(cluster_xml,
                                           "host_link",
                                           attrib={
                                               "id": core_id,
                                               "up": udlink_id,
                                               "down": udlink_id
                                           })

                        for core_idx in range(int(proc_template["nb_cores"])):
                            core_id = "cor_{}_{}".format(core_idx, proc_id)
                            _core_attrs = {"id": core_id}
                            _core_attrs.update(
                                proc_template["core_attributes"])
                            core_xml = xml.SubElement(cluster_xml,
                                                      "host",
                                                      attrib=_core_attrs)
                            core_properties()
                            link_association()

                    for proc in node_template["processors"]:
                        proc_template = processor_types[proc["type"]][
                            proc["model"]]
                        for proc_idx in range(int(proc_template["nb_cores"])):
                            proc_id = "{}_{}_{}".format(
                                proc_template["id"], proc_idx, node_id)
                            cores()

                for node in cluster["nodes"]:
                    node_template = node_types[node["type"]]
                    record_node_type()
                    for node_idx in range(int(node["number"])):
                        node_id = "{}_{}_{}".format(node_template["id"],
                                                    node_idx, cluster_id)
                        udlink_id = udlink()
                        procs()

            def router():
                """
                Gateway for inter-cluster connections.
                """

                xml.SubElement(cluster_xml,
                               "router",
                               attrib={"id": "rou_{}".format(cluster_idx)})

            def backbone():
                """
                Intra-cluster connections.
                """

                _backbone_attrs = {"id": "bbo_{}".format(cluster_idx)}
                _backbone_attrs.update(
                    network_types[cluster["cluster_network"]])
                xml.SubElement(cluster_xml, "backbone", attrib=_backbone_attrs)

            cluster_idx = 0
            recorded_nodes = {}
            for cluster in platform["clusters"]:
                cluster_id = "clu_{}".format(cluster_idx)
                cluster_xml = xml.SubElement(main_zone_xml,
                                             "zone",
                                             attrib={
                                                 "id": cluster_id,
                                                 "routing": "Cluster"
                                             })
                nodes()
                router()
                backbone()
                cluster_idx += 1