Exemplo n.º 1
0
    def start_agent(self, asset_id='', arguments=None):
        asset_obj = self._validate_resource_id("asset_id", asset_id, RT.Instrument)
        if not asset_obj.agent_info:
            raise BadRequest("Cannot find agent information")

        agent_info = asset_obj.agent_info[0]
        agent_cfg = agent_info.get("config") or {}
        if arguments and type(arguments) is dict:
            dict_merge(agent_cfg, arguments, inplace=True)

        dataset_info = self.get_asset_data(asset_id, data_filter=dict(get_info=True, include_data=False))
        dataset_id = dataset_info["dataset_id"]
        agent_cfg["dataset_id"] = dataset_id
        agent_cfg["dataset_info"] = {}
        log.info("Start agent for %s with dataset %s", asset_id, dataset_id)
        if dataset_info and dataset_info["info"]:
            log.info("Agent RESTART %s. Dataset exists, last sample date: %s", asset_id, dataset_info["info"]["ts_last_str"])
            agent_cfg["dataset_info"] = dataset_info["info"]
        log.info("Using agent_info: %s", agent_info)
        agent_ctl = AgentControl()
        agent_pid = agent_ctl.launch_agent(asset_id, agent_info["agent_type"], agent_cfg)

        asset_obj.agent_state = {}  # We assume only 1 agent per asset
        asset_obj.agent_state[agent_pid] = dict(start_ts=get_ion_ts())
        self.rr.update(asset_obj)

        log.info("Agent started for %s with pid=%s", asset_id, agent_pid)

        return agent_pid
Exemplo n.º 2
0
    def start_agent(self, asset_id='', arguments=None):
        asset_obj = self._validate_resource_id("asset_id", asset_id,
                                               RT.Instrument)
        if not asset_obj.agent_info:
            raise BadRequest("Cannot find agent information")

        agent_info = asset_obj.agent_info[0]
        agent_cfg = agent_info.get("config") or {}
        if arguments and type(arguments) is dict:
            dict_merge(agent_cfg, arguments, inplace=True)

        dataset_info = self.get_asset_data(asset_id,
                                           data_filter=dict(
                                               get_info=True,
                                               include_data=False))
        dataset_id = dataset_info["dataset_id"]
        agent_cfg["dataset_id"] = dataset_id
        agent_cfg["dataset_info"] = {}
        log.info("Start agent for %s with dataset %s", asset_id, dataset_id)
        if dataset_info and dataset_info["info"]:
            log.info("Agent RESTART %s. Dataset exists, last sample date: %s",
                     asset_id, dataset_info["info"]["ts_last_str"])
            agent_cfg["dataset_info"] = dataset_info["info"]
        log.info("Using agent_info: %s", agent_info)
        agent_ctl = AgentControl()
        agent_pid = agent_ctl.launch_agent(asset_id, agent_info["agent_type"],
                                           agent_cfg)

        asset_obj.agent_state = {}  # We assume only 1 agent per asset
        asset_obj.agent_state[agent_pid] = dict(start_ts=get_ion_ts())
        self.rr.update(asset_obj)

        log.info("Agent started for %s with pid=%s", asset_id, agent_pid)

        return agent_pid
Exemplo n.º 3
0
 def _load_resource_Dataset(self, action_cfg):
     if action_cfg[KEY_ID] in self.resource_ids:
         return
     schema_def = {}
     if "schema_def" in action_cfg:
         schema_def = DataSchemaParser.parse_schema_ref(action_cfg["schema_def"])
     if "schema_override" in action_cfg:
         dict_merge(schema_def, action_cfg["schema_override"], inplace=True)
     res_id = self.basic_resource_create(action_cfg, RT.Dataset, "resource_registry", "create", support_bulk=True,
                                         set_attributes=dict(schema_definition=schema_def))
     self.basic_associations_create(action_cfg, action_cfg[KEY_ID], support_bulk=True)