Initializes the context of this flow.

def InitializeContext(self, args):
    """Initializes the context of this flow."""
    if args is None:
      args = rdf_flow_runner.FlowRunnerArgs()

    output_plugins_states = []
    for plugin_descriptor in args.output_plugins:
      if not args.client_id:
        self.Log(
            "Not initializing output plugin %s as flow does not run on "
            "the client.", plugin_descriptor.plugin_name)
        continue

      plugin_class = plugin_descriptor.GetPluginClass()
      try:
        plugin, plugin_state = plugin_class.CreatePluginAndDefaultState(
            source_urn=self.flow_obj.output_urn,
            args=plugin_descriptor.plugin_args,
            token=self.token)
        # TODO(amoser): Those do not need to be inside the state, they
        # could be part of the plugin descriptor.
        plugin_state["logs"] = []
        plugin_state["errors"] = []

        output_plugins_states.append(
            rdf_flow_runner.OutputPluginState(
                plugin_state=plugin_state, plugin_descriptor=plugin_descriptor))
      except Exception as e:  # pylint: disable=broad-except
        logging.exception("Plugin %s failed to initialize (%s), ignoring it.",
                          plugin, e)

    parent_creator = None
    if self.parent_runner:
      parent_creator = self.parent_runner.context.creator

    context = rdf_flow_runner.FlowContext(
        create_time=rdfvalue.RDFDatetime.Now(),
        creator=parent_creator or self.token.username,
        current_state="Start",
        output_plugins_states=output_plugins_states,
        state=rdf_flow_runner.FlowContext.State.RUNNING,
    )

    return context