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 _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
def router(): """ Gateway for inter-cluster connections. """ xml.SubElement(cluster_xml, "router", attrib={"id": "rou_{}".format(cluster_idx)})
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
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)
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
def config_zone(): """ Define node and proc config properties. """ return xml.SubElement(main_zone_xml, "zone", attrib={ "id": "config", "routing": "None" })
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
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
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
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
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
def main_zone(): """ Contains master zone and all clusters. """ return xml.SubElement(platform_xml, "zone", attrib={ "id": "main", "routing": "Full" })
def master_host(): """ Executes the scheduling algorithms. """ xml.SubElement(master_zone_xml, "host", attrib={ "id": "master_host", "speed": "1Gf" })
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)
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 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 })
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)})
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 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()
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" })
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()
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)
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
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