Exemplo n.º 1
0
 def run ():
   core.getLogger("worker").info(
     "Schedule mapping algorithm: %s" % self.strategy.__name__)
   nffg = self.strategy.map(graph=graph, resource=resource)
   # Must use call_as_coop_task because we want to call a function in a
   # coop microtask environment from a separate thread
   call_as_coop_task(self._mapping_finished, mapped_nffg=nffg)
Exemplo n.º 2
0
  def _perform_mapping (self, input_graph, resource_view):
    """
    Orchestrate mapping of given service graph on given virtual resource.

    :param input_graph: Service Graph
    :type input_graph: :any:`NFFG`
    :param resource_view: virtual resource view
    :param resource_view: :any:`AbstractVirtualizer`
    :return: Network Function Forwarding Graph
    :rtype: :any:`NFFG`
    """
    if input_graph is None:
      log.error("Missing service request information! Abort mapping process!")
      return None
    log.debug("Request %s to launch orchestration on SG: %s with View: %s" % (
      self.__class__.__name__, input_graph, resource_view))
    # Steps before mapping (optional)
    log.debug("Request resource info from layer virtualizer...")
    virt_resource = resource_view.get_resource_info()
    if virt_resource is None:
      log.error("Missing resource information! Abort mapping process!")
      return None
    # log a warning if resource is empty --> possibly mapping will be failed
    if virt_resource.is_empty():
      log.warning("Resource information is empty!")
    # Log verbose resource view if it is exist
    log.log(VERBOSE, "Service layer resource graph:\n%s" % virt_resource.dump())
    # resource_view.sanity_check(input_graph)
    # Check if the mapping algorithm is enabled
    if not CONFIG.get_mapping_enabled(LAYER_NAME):
      log.warning(
        "Mapping algorithm in Layer: %s is disabled! Skip mapping step and "
        "forward service request to lower layer..." % LAYER_NAME)
      return input_graph
    # Run actual mapping algorithm
    if self._threaded:
      # Schedule a microtask which run mapping algorithm in a Python thread
      log.info(
        "Schedule mapping algorithm: %s in a worker thread" %
        self.strategy.__name__)
      call_as_coop_task(self._start_mapping, graph=input_graph,
                        resource=virt_resource)
      log.info("SG: %s orchestration is finished by %s" % (
        input_graph, self.__class__.__name__))
      # Return with None
      return None
    else:
      mapped_nffg = self.strategy.map(graph=input_graph, resource=virt_resource)
      # Steps after mapping (optional) if the mapping was not threaded
      if mapped_nffg is None:
        log.error("Mapping process is failed! Abort orchestration process.")
      else:
        log.info("SG: %s orchestration is finished by %s successfully!" % (
          input_graph, self.__class__.__name__))
      return mapped_nffg
Exemplo n.º 3
0
 def update(param=None):
     call_as_coop_task(func=quit_with_code, ret_code=UPDATE_VALUE)
     if param is not None:
         with open(".checkout", 'w') as f:
             f.write(param)
             log.info("Update task scheduled with explicit checkpoint: %s" %
                      param)
             return Response("UPDATE accepted (%s).\n" % param,
                             httplib.ACCEPTED)
     else:
         log.info("Update task scheduled")
         return Response("UPDATE accepted.\n", httplib.ACCEPTED)
Exemplo n.º 4
0
    def _perform_mapping(self, input_graph, resource_view, continued=False):
        """
    Orchestrate mapping of given NF-FG on given global resource.

    :param input_graph: Network Function Forwarding Graph
    :type input_graph: :class:`NFFG`
    :param resource_view: global resource view
    :type resource_view: :any:`DomainVirtualizer`
    :return: mapped Network Function Forwarding Graph
    :rtype: :class:`NFFG`
    """
        if input_graph is None:
            log.error(
                "Missing mapping request information! Abort mapping process!")
            return None
        log.debug(
            "Request %s to launch orchestration on NF-FG: %s with View: "
            "%s, continued remap: %s" %
            (self.__class__.__name__, input_graph, resource_view, continued))
        # Steps before mapping (optional)
        log.debug("Request global resource info...")
        virt_resource = resource_view.get_resource_info()
        if virt_resource is None:
            log.error("Missing resource information! Abort mapping process!")
            return None
        # log a warning if resource is empty --> possibly mapping will be failed
        if virt_resource.is_empty():
            log.warning("Resource information is empty!")
        # Log verbose resource view if it is exist
        log.log(
            VERBOSE,
            "Orchestration Layer resource graph:\n%s" % virt_resource.dump())
        # Check if the mapping algorithm is enabled
        if not CONFIG.get_mapping_enabled(LAYER_NAME):
            log.warning("Mapping algorithm in Layer: %s is disabled! "
                        "Skip mapping step and return service request "
                        "to lower layer..." % LAYER_NAME)
            # virt_resource.id = input_graph.id
            # return virt_resource
            # Send request forward (probably to Remote ESCAPE)
            input_graph.status = NFFG.MAP_STATUS_SKIPPED
            log.debug("Mark NFFG status: %s!" % input_graph.status)
            return input_graph
        # Run actual mapping algorithm
        if self._threaded:
            # Schedule a microtask which run mapping algorithm in a Python thread
            log.info("Schedule mapping algorithm: %s in a worker thread" %
                     self.strategy.__name__)
            call_as_coop_task(self._start_mapping,
                              graph=input_graph,
                              resource=virt_resource)
            log.info("NF-FG: %s orchestration is finished by %s" %
                     (input_graph, self.__class__.__name__))
            # Return with None
            return None
        else:
            state = self.last_mapping_state if continued else None
            mapping_result = self.strategy.map(
                graph=input_graph,
                resource=virt_resource,
                persistent=self.persistent_state,
                pre_state=state)
            if isinstance(mapping_result, tuple or list):
                if len(mapping_result) == 2:
                    mapped_nffg = mapping_result[0]
                    self.persistent_state = mapping_result[1]
                    log.debug("Cache returned persistent state: %s" %
                              self.persistent_state)
                elif len(mapping_result) == 3:
                    mapped_nffg = mapping_result[0]
                    self.persistent_state = mapping_result[1]
                    log.debug("Cache returned persistent state: %s" %
                              self.persistent_state)
                    self.last_mapping_state = mapping_result[2]
                    log.debug("Cache returned mapping state: %s" %
                              self.last_mapping_state)
                else:
                    log.error("Mapping result is invalid: %s" %
                              repr(mapping_result))
                    mapped_nffg = None
            else:
                mapped_nffg = mapping_result
            # Check error result
            if mapped_nffg is None:
                log.error(
                    "Mapping process is failed! Abort orchestration process.")
            else:
                # Steps after mapping (optional)
                log.info(
                    "NF-FG: %s orchestration is finished by %s successfully!" %
                    (input_graph, self.__class__.__name__))
            log.debug("Last mapping state: %s" % self.last_mapping_state)
            if self.last_mapping_state:
                log.debug("Mapping iteration: %s" %
                          self.last_mapping_state.get_number_of_trials()
                          if self.last_mapping_state else None)
            return mapped_nffg
Exemplo n.º 5
0
 def restart():
     call_as_coop_task(func=quit_with_code, ret_code=RESTART_VALUE)
     log.info("Restart task scheduled")
     return Response("RESTART accepted.\n", httplib.ACCEPTED)
Exemplo n.º 6
0
 def stop():
     call_as_coop_task(func=quit_with_code, ret_code=STOP_VALUE)
     log.info("Shutdown task scheduled")
     return Response("SHUTDOWN accepted.\n", httplib.ACCEPTED)
Exemplo n.º 7
0
 def shutdown():
     call_as_coop_task(func=quit_with_ok)
     log.info("Shutdown task scheduled")
     return Response("SHUTDOWN accepted.\n", httplib.ACCEPTED)