Exemple #1
0
    def process_request(self, command, data):
        logger.debug("[Master ] [LocalServer  ] Request received in cluster local server: '{0}' - '{1}'".format(command, data))
        data = data.decode()

        if command == 'get_nodes':
            response = {name:data['info'] for name,data in self.server.manager.get_connected_workers().items()}
            cluster_config = read_config()
            response.update({cluster_config['node_name']:{"name": cluster_config['node_name'], "ip": cluster_config['nodes'][0],  "type": "master", "version":__version__}})

            serialized_response = ['json', json.dumps(response)]
            return serialized_response

        elif command == 'get_health':
            _, data = data.split(' ', 1)
            node_list = data if data != 'None' else None
            response = self.server.manager.get_healthcheck(node_list)
            serialized_response = ['json',  json.dumps(response)]
            return serialized_response

        elif command == 'get_config':
            response = self.server.manager.get_configuration()
            serialized_response = ['ok', json.dumps(response)]
            return serialized_response

        elif command == 'dapi':
            return ['json', dapi.distribute_function(json.loads(data.split(' ', 1)[1]))]

        elif command == 'dapi_forward':
            worker_id, node_name, input_json = data.split(' ', 2)
            res_cmd, res = self.server.manager.send_request(worker_name=node_name, command='dapi', data=worker_id + ' ' + input_json).split(' ', 1)
            return res_cmd, res if res_cmd != 'err' else json.dumps({'err': res})

        else:
            return InternalSocketHandler.process_request(self, command, data)
Exemple #2
0
    def process_request(self, command, data):
        logger.debug("[Worker ] [LocalServer  ] Request received in cluster local server: '{0}' - '{1}'".format(command, data))

        if command not in ['get_nodes','get_health','dapi']:  # ToDo: create a list of valid internal socket commands
            response = InternalSocketHandler.process_request(self, command, data.decode())
        else:
            node_response = self.server.manager.handler.send_request(command=command, data=data if data != 'None' else None).split(' ', 1)
            type_response = node_response[0]
            response = node_response[1]
            if type_response == "err":
                response = ["err", json.dumps({"err": response})]
            else:
                response = [type_response, response]

        return response
Exemple #3
0
 def __init__(self, sock, server, asyncore_map, addr):
     InternalSocketHandler.__init__(self,
                                    sock=sock,
                                    server=server,
                                    asyncore_map=asyncore_map,
                                    addr=addr)