def update_mapping(self): ''' :return: updates the internal mapping of the service according to the updated list of SLAS ''' session = Session() if self.mapping is None: raise AttributeError("no mapping found") # get the new merged sla merged_new = self.get_merged_sla(self.slas) # create the service topology from the new merged sla self.topo = ServiceTopoHeuristic( sla=merged_new, vhg_count=self.vhg_count, vcdn_count=self.vcdn_count, hint_node_mappings=self.mapping.node_mappings) # retreive info on the new service. edges_from_new_topo = { (node_1, node_2): bw for node_1, node_2, bw in self.topo.dump_edges() } nodes_from_new_topo = { node: cpu for node, cpu, bw in self.topo.getServiceNodes() } # update edge mapping topology, delete them if they are not present anymore for em in self.mapping.edge_mappings: edge = em.serviceEdge service_edge = (edge.node_1.name, edge.node_2.name) if service_edge in edges_from_new_topo: edge.bandwidth = edges_from_new_topo[service_edge] else: session.delete(em) session.flush() # **don't** update CPU, just remove VHG or VCDN if they are not present anymore. for nm in self.mapping.node_mappings: if nm.service_node.name not in nodes_from_new_topo: session.delete(nm) session.flush() # prune service edges for se in self.serviceEdges: if (se.node_1.name, se.node_2.name) not in edges_from_new_topo: session.delete(se) session.flush() # prune service nodes for sn in self.serviceNodes: if sn.name not in nodes_from_new_topo: session.delete(sn) session.flush() self.mapping.objective_function = self.mapping.get_objective_function()
def __init__(self, topo_instance, slasIDS, serviceSpecFactory=ServiceSpecFactory, vhg_count=1, vcdn_count=1, use_heuristic=True, solve=True): session = Session() self.slas = session.query(Sla).filter(Sla.id.in_(slasIDS)).all() self.vhg_count = vhg_count self.vcdn_count = vcdn_count self.merged_sla = self.get_merged_sla(self.slas) self.serviceSpecFactory = serviceSpecFactory self.topo = topo_instance for node, cpu, bw in self.topo.getServiceNodes(): node = ServiceNode(name=node, cpu=cpu, sla_id=self.merged_sla.id, bw=bw) session.add(node) self.serviceNodes.append(node) for node_1, node_2, bandwidth in self.topo.getServiceEdges(): snode_1 = session.query(ServiceNode).filter( and_(ServiceNode.sla_id == self.merged_sla.id, ServiceNode.service_id == self.id, ServiceNode.name == node_1)).one() snode_2 = session.query(ServiceNode).filter( and_(ServiceNode.sla_id == self.merged_sla.id, ServiceNode.service_id == self.id, ServiceNode.name == node_2)).one() sedge = ServiceEdge(node_1=snode_1, node_2=snode_2, bandwidth=bandwidth, sla_id=self.merged_sla.id) session.add(sedge) self.serviceEdges.append(sedge) session.flush() session.add(self) session.flush() if use_heuristic: # create temp mapping for vhg<->vcdn hints assert self.id is not None self.__solve(path=str(self.id), reopt=False) session.flush() if self.mapping is not None: self.topo = list( ServiceTopoHeuristic(sla=self.merged_sla, vhg_count=vhg_count, vcdn_count=vcdn_count, hint_node_mappings=self.mapping. node_mappings).getTopos())[0] # add the CDN Edges to the graph for sla in [self.merged_sla]: for node_1, node_2, bandwidth in self.topo.getServiceCDNEdges( ): snode_1 = session.query(ServiceNode).filter( and_(ServiceNode.sla_id == sla.id, ServiceNode.service_id == self.id, ServiceNode.name == node_1)).one() snode_2 = session.query(ServiceNode).filter( and_(ServiceNode.sla_id == sla.id, ServiceNode.service_id == self.id, ServiceNode.name == node_2)).one() sedge = ServiceEdge(node_1=snode_1, node_2=snode_2, bandwidth=bandwidth, sla_id=sla.id) session.add(sedge) self.serviceEdges.append(sedge) session.flush() session.delete(self.mapping) session.flush() if solve: #to perf measurements purposes, we should alway solve... self.__solve(path=str(self.id), use_heuristic=use_heuristic, reopt=True) else: self.__solve(path=str(self.id), use_heuristic=use_heuristic, reopt=False) session.flush()