예제 #1
0
class PeerConfigDescription(object):
    def __init__(self,
                 peer_id,
                 experiment_id,
                 config=None,
                 path=None,
                 machine=None,
                 logger=None):
        self.peer_id = peer_id

        self.experiment_id = experiment_id

        self.config = PeerConfig(peer_id)
        self.path = path
        self.machine = machine
        self.public_params = []
        self.logger = logger or logging.getLogger(
            "ObciExperimentConfig.peer_id")
        self.del_after_stop = False

    def __str__(self):
        return self.peer_id

    def ready(self, details=None):
        loc_det = {}
        ready = self.config is not None and \
            self.path is not None and\
            self.machine is not None and\
            self.peer_id is not None

        if not ready:
            return ready
        ready = self.config.config_sources_ready(loc_det) and ready
        ready = self.config.launch_deps_ready(loc_det) and ready
        if details is not None:
            details[self.peer_id] = loc_det
        return ready

    def list_config_sources(self):
        return [
            val for val in self.config.config_sources.values()
            if val in self.config.used_config_sources()
        ]

    def list_launch_deps(self):
        return self.config.launch_deps.values()

    def status(self, peer_status_obj):
        det = {}
        ready = self.ready(det)
        st = launcher_tools.READY_TO_LAUNCH if ready else launcher_tools.NOT_READY

        peer_status_obj.set_status(st, details=det)

    def peer_type(self):
        if self.peer_id.startswith('mx'):
            return 'multiplexer'
        else:
            return 'obci_peer'

    def launch_data(self):
        ser = PeerConfigSerializerCmd()
        args = [self.peer_id]
        peer_parser = peer.peer_config_parser.parser("ini")
        base_config = PeerConfig(self.peer_id)
        conf_path = launcher_tools.default_config_path(self.path)
        if conf_path:

            with codecs.open(conf_path, "r", "utf8") as f:
                self.logger.info("parsing default config for peer %s, %s ",
                                 self.peer_id, conf_path)
                peer_parser.parse(f, base_config)

        ser.serialize_diff(base_config, self.config, args)

        return dict(peer_id=self.peer_id,
                    experiment_id=self.experiment_id,
                    path=self.path,
                    machine=self.machine,
                    args=args,
                    peer_type=self.peer_type())

    def info(self, detailed=False):
        info = dict(peer_id=self.peer_id,
                    path=self.path,
                    machine=self.machine,
                    peer_type=self.peer_type())

        if not self.config:
            return info

        info[CONFIG_SOURCES] = self.config.config_sources
        info[LAUNCH_DEPENDENCIES] = self.config.launch_deps

        if detailed:
            info[LOCAL_PARAMS] = self.config.local_params
            info[EXT_PARAMS] = self.config.ext_param_defs
        return info
예제 #2
0
class PeerConfigDescription(object):

    def __init__(self, peer_id, experiment_id, config=None, path=None, machine=None,
                 logger=None):
        self.peer_id = peer_id

        self.experiment_id = experiment_id

        self.config = PeerConfig(peer_id)
        self.path = path
        self.machine = machine
        self.public_params = []
        self.logger = logger or logging.getLogger("ObciExperimentConfig.peer_id")
        self.del_after_stop = False

    def __str__(self):
        return self.peer_id

    def ready(self, details=None):
        loc_det = {}
        ready = self.config is not None and \
            self.path is not None and\
            self.machine is not None and\
            self.peer_id is not None

        if not ready:
            return ready
        ready = self.config.config_sources_ready(loc_det) and ready
        ready = self.config.launch_deps_ready(loc_det) and ready
        if details is not None:
            details[self.peer_id] = loc_det
        return ready

    def list_config_sources(self):
        return [val for val in self.config.config_sources.values() if
                val in self.config.used_config_sources()]

    def list_launch_deps(self):
        return list(self.config.launch_deps.values())

    def status(self, peer_status_obj):
        det = {}
        ready = self.ready(det)
        st = launcher_tools.READY_TO_LAUNCH if ready else launcher_tools.NOT_READY

        peer_status_obj.set_status(st, details=det)

    def peer_type(self):
        if self.peer_id.startswith('mx'):
            return 'multiplexer'
        else:
            return 'obci_peer'

    def launch_data(self):
        ser = PeerConfigSerializerCmd()
        args = [self.peer_id]
        peer_parser = peer.peer_config_parser.parser("ini")
        base_config = PeerConfig(self.peer_id)
        conf_path = launcher_tools.default_config_path(self.path)
        if conf_path:

            with codecs.open(conf_path, "r", "utf8") as f:
                self.logger.info("parsing default config for peer %s, %s ",
                                 self.peer_id, conf_path)
                peer_parser.parse(f, base_config)

        ser.serialize_diff(base_config, self.config, args)

        return dict(peer_id=self.peer_id, experiment_id=self.experiment_id,
                    path=self.path, machine=self.machine,
                    args=args, peer_type=self.peer_type())

    def info(self, detailed=False):
        info = dict(peer_id=self.peer_id,
                    path=self.path, machine=self.machine, peer_type=self.peer_type()
                    )

        if not self.config:
            return info

        info[CONFIG_SOURCES] = self.config.config_sources
        info[LAUNCH_DEPENDENCIES] = self.config.launch_deps

        if detailed:
            info[LOCAL_PARAMS] = self.config.local_params
            info[EXT_PARAMS] = self.config.ext_param_defs
        return info