Ejemplo n.º 1
0
    def __init__(self, config):

        if config['secure']:
            raise Exception(
                "NYI - Monitor does not support secure mode yet. Use builtin monitor in combiner mode"
            )
        self.name = config['name']
        channel = grpc.insecure_channel(config['host'] + ":" +
                                        str(config['port']))
        self.connection = rpc.ConnectorStub(channel)
        print("Client: {} connected to {}:{}".format(self.name, config['host'],
                                                     config['port']),
              flush=True)

        # Connect to MongoDB
        try:
            self.mdb = connect_to_mongodb()
            self.collection = self.mdb['status']
        except Exception as e:
            print("FAILED TO CONNECT TO MONGO, {}".format(e), flush=True)
            self.collection = None
            raise

        threading.Thread(target=self.__listen_to_status_stream,
                         daemon=True).start()
Ejemplo n.º 2
0
 def __init__(self):
     try:
         self.mdb = connect_to_mongodb()
         self.collection = self.mdb['status']
     except Exception as e:
         print("FAILED TO CONNECT TO MONGO, {}".format(e), flush=True)
         self.collection = None
         raise
Ejemplo n.º 3
0
 def __init__(self):
     try:
         self.mdb = connect_to_mongodb()
         self.state = self.mdb['state']
         self.models = self.mdb['models']
         self.latest_model = self.mdb['latest_model']
     except Exception as e:
         print("FAILED TO CONNECT TO MONGO, {}".format(e), flush=True)
         self.state = None
         self.models = None
         self.latest_model = None
         raise
Ejemplo n.º 4
0
    def __init__(self, statestore):
        try:
            statestore_config = statestore.get_config()
            self.mdb = connect_to_mongodb(statestore_config['mongo_config'],
                                          statestore_config['network_id'])
            self.status = self.mdb['control.status']
            self.round_time = self.mdb["control.round_time"]
            self.combiner_round_time = self.mdb["control.combiner_round_time"]
            self.psutil_usage = self.mdb["control.psutil_monitoring"]

        except Exception as e:
            print("FAILED TO CONNECT TO MONGO, {}".format(e), flush=True)
            self.collection = None
            raise
Ejemplo n.º 5
0
 def __init__(self,mongo_config,network_id):
     try:
         self.mdb = connect_to_mongodb(mongo_config,network_id)
         self.status = self.mdb['control.status']
         self.round_time = self.mdb['control.round_time']
         self.psutil_monitoring = self.mdb['control.psutil_monitoring']
         self.model_trail = self.mdb['control.model_trail']
         self.latest_model = self.mdb['control.latest_model']
         self.combiner_round_time = self.mdb['control.combiner_round_time']
         #self.combiner_queue_length = self.mdb['control.combiner_queue_length']
         self.round = self.mdb['control.round']
     except Exception as e:
         print("FAILED TO CONNECT TO MONGO, {}".format(e), flush=True)
         self.status = None
         raise
Ejemplo n.º 6
0
    def __init__(self, defaults=None):
        self.__inited = False
        try:
            self.mdb = connect_to_mongodb()
            self.state = self.mdb['state']
            self.models = self.mdb['models']
            self.latest_model = self.mdb['latest_model']
            self.compute_context = self.mdb['compute_context']
            self.compute_context_trail = self.mdb['compute_context_trail']
            self.__inited = True
        except Exception as e:
            print("FAILED TO CONNECT TO MONGO, {}".format(e), flush=True)
            self.state = None
            self.models = None
            self.latest_model = None
            self.compute_context = None
            self.compute_context_trail = None
            raise

        import yaml
        if defaults:
            with open(defaults, 'r') as file:
                try:
                    settings = dict(yaml.safe_load(file))
                    print(settings, flush=True)
                    self.transition(str(settings['state']))
                    if not self.get_latest():
                        self.set_latest(str(settings['model']))
                    else:
                        print(
                            "Model trail already exist - delete the entire trail if you want to reseed the system.",
                            flush=True)
                    print("Setting filepath to {}".format(settings['context']),
                          flush=True)
                    # self.set_compute_context(str())
                    # TODO Fix the ugly latering of indirection due to a bug in secure_filename returning an object with filename as attribute
                    # TODO fix with unboxing of value before storing and where consuming.
                    self.compute_context.update({'key': 'package'}, {
                        '$set': {
                            'filename': {
                                'filename': settings['context']
                            }
                        }
                    }, True)
                    self.__inited = True
                except yaml.YamlError as e:
                    print(e)
Ejemplo n.º 7
0
    def __init__(self, network_id, config, defaults=None):
        self.__inited = False
        try:
            self.config = config
            self.network_id = network_id
            self.mdb = connect_to_mongodb(self.config, self.network_id)

            # FEDn network
            self.network = self.mdb['network']
            self.reducer = self.network['reducer']
            self.combiners = self.network['combiners']
            self.clients = self.network['clients']
            self.storage = self.network['storage']
            self.certificates = self.network['certificates']
            # Control 
            self.control = self.mdb['control']
            self.control_config = self.control['config']
            self.state = self.control['state']
            self.model = self.control['model']
            self.round = self.control["round"]

            # Logging and dashboards
            self.status = self.control["status"]
            self.round_time = self.control["round_time"]
            self.psutil_monitoring = self.control["psutil_monitoring"]
            self.combiner_round_time = self.control['combiner_round_time']



            self.__inited = True
        except Exception as e:
            print("FAILED TO CONNECT TO MONGO, {}".format(e), flush=True)
            self.state = None
            self.model = None
            self.control = None
            self.network = None
            self.combiners = None
            self.clients = None
            raise

        import yaml
        if defaults:
            with open(defaults, 'r') as file:
                try:
                    settings = dict(yaml.safe_load(file))
                    print(settings, flush=True)

                    # Control settings
                    if "control" in settings and settings["control"]:
                        control = settings['control']
                        try:
                            self.transition(str(control['state']))
                        except KeyError:
                            self.transition("idle")

                        if "model" in control:
                            if not self.get_latest():
                                self.set_latest(str(control['model']))
                            else:
                                print("Model trail already initialized - refusing to overwrite from config. Purge model trail if you want to reseed the system.",flush=True)
                    
                        if "context" in control:
                            print("Setting filepath to {}".format(control['context']), flush=True)
                            # TODO Fix the ugly latering of indirection due to a bug in secure_filename returning an object with filename as attribute
                            # TODO fix with unboxing of value before storing and where consuming.
                            self.control.config.update({'key': 'package'},
                                                        {'$set': {'filename': {'filename': control['context']}}}, True)
                        if "helper" in control:
                            self.set_framework(control['helper'])

                        round_config = {'timeout':180, 'validate':True}
                        try:
                            round_config['timeout'] = control['timeout']
                        except:
                            pass

                        try:
                            round_config['validate'] = control['validate']
                        except:
                            pass
  

                    # Storage settings
                    self.set_storage_backend(settings['storage'])


                    self.__inited = True
                except yaml.YAMLError as e:
                    print(e)