コード例 #1
0
    def manage_get_metadata(self, identity, config_name):
        agent_store = self.store.get(identity)
        if agent_store is None:
            raise KeyError(
                'No configuration file "{}" for VIP IDENTIY {}'.format(
                    config_name, identity))

        agent_disk_store = agent_store["store"]
        agent_name_map = agent_store["name_map"]

        config_name = strip_config_name(config_name)
        config_name_lower = config_name.lower()

        if config_name_lower not in agent_name_map:
            raise KeyError(
                'No configuration file "{}" for VIP IDENTIY {}'.format(
                    config_name, identity))

        real_config_name = agent_name_map[config_name_lower]

        real_config = agent_disk_store[real_config_name]

        #Set modified to none if we predate the modified flag.
        if real_config.get("modified") is None:
            real_config["modified"] = None

        return real_config
コード例 #2
0
    def manage_get(self, identity, config_name, raw=True):
        agent_store = self.store.get(identity)
        if agent_store is None:
            raise KeyError(
                'No configuration file "{}" for VIP IDENTIY {}'.format(
                    config_name, identity))

        agent_configs = agent_store["configs"]
        agent_disk_store = agent_store["store"]
        agent_name_map = agent_store["name_map"]

        config_name = strip_config_name(config_name)
        config_name_lower = config_name.lower()

        if config_name_lower not in agent_name_map:
            raise KeyError(
                'No configuration file "{}" for VIP IDENTIY {}'.format(
                    config_name, identity))

        real_config_name = agent_name_map[config_name_lower]

        if raw:
            return agent_disk_store[real_config_name]["data"]

        return agent_configs[real_config_name]
コード例 #3
0
    def delete(self,
               identity,
               config_name,
               trigger_callback=False,
               send_update=True):
        agent_store = self.store.get(identity)
        if agent_store is None:
            raise KeyError(
                'No configuration file "{}" for VIP IDENTIY {}'.format(
                    config_name, identity))

        agent_configs = agent_store["configs"]
        agent_disk_store = agent_store["store"]
        agent_store_lock = agent_store["lock"]
        agent_name_map = agent_store["name_map"]

        config_name = strip_config_name(config_name)
        config_name_lower = config_name.lower()

        if config_name_lower not in agent_name_map:
            raise KeyError(
                'No configuration file "{}" for VIP IDENTIY {}'.format(
                    config_name, identity))

        real_config_name = agent_name_map[config_name_lower]

        agent_configs.pop(real_config_name)
        agent_disk_store.pop(real_config_name)
        agent_name_map.pop(config_name_lower)

        # Sync will delete the file if the store is empty.
        agent_disk_store.async_sync()

        if send_update:
            with agent_store_lock:
                try:
                    self.vip.rpc.call(
                        identity,
                        "config.update",
                        "DELETE",
                        config_name,
                        trigger_callback=trigger_callback).get(timeout=10.0)
                except errors.Unreachable:
                    _log.debug(
                        "Agent {} not currently running. Configuration update not sent."
                        .format(identity))
                except RemoteError as e:
                    _log.error(
                        "Agent {} failure when deleting configuration {}: {}".
                        format(identity, config_name, e))
                except MethodNotFound as e:
                    _log.error(
                        "Agent {} failure when adding/updating configuration {}: {}"
                        .format(identity, config_name, e))

        # If the store is empty (and nothing jumped in and added to it while we
        # were informing the agent) then remove it from the global store.
        if not agent_disk_store:
            self.store.pop(identity, None)
コード例 #4
0
ファイル: store.py プロジェクト: tarvajeh13/volttron
    def _add_config_to_store(self, identity, config_name, raw, parsed,
                             config_type, trigger_callback=False,
                             send_update=True):
        """Adds a processed configuration to the store."""
        agent_store = self.store.get(identity)

        action = "UPDATE"

        if agent_store is None:
            #Initialize a new store.
            store_path = os.path.join(self.store_path, identity+ store_ext)
            store = PersistentDict(filename=store_path, flag='c', format='json')
            agent_store = {"configs": {}, "store": store, "name_map": {}, "lock": Semaphore()}
            self.store[identity] = agent_store

        agent_configs = agent_store["configs"]
        agent_disk_store = agent_store["store"]
        agent_store_lock = agent_store["lock"]
        agent_name_map = agent_store["name_map"]

        config_name = strip_config_name(config_name)
        config_name_lower = config_name.lower()

        if config_name_lower not in agent_name_map:
            action = "NEW"

        if check_for_recursion(config_name, parsed, agent_configs):
            raise ValueError("Recursive configuration references detected.")

        if config_name_lower in agent_name_map:
            old_config_name = agent_name_map[config_name_lower]
            del agent_configs[old_config_name]

        agent_configs[config_name] = parsed
        agent_name_map[config_name_lower] = config_name

        agent_disk_store[config_name] = {"type": config_type,
                                         "modified": format_timestamp(get_aware_utc_now()),
                                         "data": raw}

        agent_disk_store.async_sync()

        _log.debug("Agent {} config {} stored.".format(identity, config_name))

        if send_update:
            with agent_store_lock:
                try:
                    self.vip.rpc.call(identity, "config.update", action, config_name, contents=parsed, trigger_callback=trigger_callback).get(timeout=10.0)
                except errors.Unreachable:
                    _log.debug("Agent {} not currently running. Configuration update not sent.".format(identity))
                except RemoteError as e:
                    _log.error("Agent {} failure when adding/updating configuration {}: {}".format(identity, config_name, e))
                except MethodNotFound as e:
                    _log.error(
                        "Agent {} failure when adding/updating configuration {}: {}".format(identity, config_name, e))
コード例 #5
0
ファイル: store.py プロジェクト: Kisensum/volttron
    def delete(self, identity, config_name, trigger_callback=False, send_update=True):
        agent_store = self.store.get(identity)
        if agent_store is None:
            raise KeyError('No configuration file "{}" for VIP IDENTIY {}'.format(config_name, identity))

        agent_configs = agent_store["configs"]
        agent_disk_store = agent_store["store"]
        agent_store_lock = agent_store["lock"]
        agent_name_map = agent_store["name_map"]

        config_name = strip_config_name(config_name)
        config_name_lower = config_name.lower()

        if config_name_lower not in agent_name_map:
            raise KeyError('No configuration file "{}" for VIP IDENTIY {}'.format(config_name, identity))

        real_config_name = agent_name_map[config_name_lower]

        agent_configs.pop(real_config_name)
        agent_disk_store.pop(real_config_name)
        agent_name_map.pop(config_name_lower)

        # Sync will delete the file if the store is empty.
        agent_disk_store.async_sync()

        if send_update:
            with agent_store_lock:
                try:
                    self.vip.rpc.call(identity, "config.update", "DELETE", config_name, trigger_callback=trigger_callback).get(timeout=10.0)
                except errors.Unreachable:
                    _log.debug("Agent {} not currently running. Configuration update not sent.".format(identity))
                except RemoteError as e:
                    _log.error("Agent {} failure when deleting configuration {}: {}".format(identity, config_name, e))
                except MethodNotFound as e:
                    _log.error(
                        "Agent {} failure when adding/updating configuration {}: {}".format(identity, config_name, e))

        # If the store is empty (and nothing jumped in and added to it while we
        # were informing the agent) then remove it from the global store.
        if not agent_disk_store:
            self.store.pop(identity, None)
コード例 #6
0
ファイル: store.py プロジェクト: Kisensum/volttron
    def manage_get(self, identity, config_name, raw=True):
        agent_store = self.store.get(identity)
        if agent_store is None:
            raise KeyError('No configuration file "{}" for VIP IDENTIY {}'.format(config_name, identity))

        agent_configs = agent_store["configs"]
        agent_disk_store = agent_store["store"]
        agent_name_map = agent_store["name_map"]

        config_name = strip_config_name(config_name)
        config_name_lower = config_name.lower()

        if config_name_lower not in agent_name_map:
            raise KeyError('No configuration file "{}" for VIP IDENTIY {}'.format(config_name, identity))

        real_config_name = agent_name_map[config_name_lower]

        if raw:
            return agent_disk_store[real_config_name]["data"]

        return agent_configs[real_config_name]
コード例 #7
0
ファイル: store.py プロジェクト: Kisensum/volttron
    def manage_get_metadata(self, identity, config_name):
        agent_store = self.store.get(identity)
        if agent_store is None:
            raise KeyError('No configuration file "{}" for VIP IDENTIY {}'.format(config_name, identity))

        agent_disk_store = agent_store["store"]
        agent_name_map = agent_store["name_map"]

        config_name = strip_config_name(config_name)
        config_name_lower = config_name.lower()

        if config_name_lower not in agent_name_map:
            raise KeyError('No configuration file "{}" for VIP IDENTIY {}'.format(config_name, identity))

        real_config_name = agent_name_map[config_name_lower]

        real_config =  agent_disk_store[real_config_name]

        #Set modified to none if we predate the modified flag.
        if real_config.get("modified") is None:
            real_config["modified"] = None

        return real_config