Exemplo n.º 1
0
    def _stop_server(node, expr):
        """Instruct single server to stop.

        Send stop command and then terminate process. Add port back to those available to new servers.

        """
        root, path = lib.expr_split(expr)
        try:
            RemoteProcedureCall._send_to_server(node, root, 'stop')
            time.sleep(0.1)
            server_dict[expr]["process"].terminate()
            port_number_lock.acquire()
            allocated_port_number.append(server_dict[expr]["port"])
            port_number_lock.release()
            node.print_info(TAG, "Server stopped with expr: %s" % expr)
        except Exception as e:
            node.print_error(
                TAG,
                "Error occured with 'stop' command for expression '%s': %s" %
                (expr, e))
            raise lib.RemoteProcedureCallError(data={
                'exception': str(e),
                'node_id': str(node.node_id),
                'expr': str(expr)
            },
                                               code='-32603')
Exemplo n.º 2
0
    def _start_new_server(node, expr):
        """Create a single (new) server.

        Use next available port to start server process. Store server process and port.

        """
        root, path = lib.expr_split(expr)
        try:
            try:
                port_number_lock.acquire()
                port = allocated_port_number.popleft()
                port_number_lock.release()
            except IndexError:
                node.print_error(TAG, "No ports remaining in allocation, cannot start new server.")
                return False
            process = multiprocessing.Process(target=server.Server, args=(node, root, port))
            process.daemon = True
            process.start()
            server_dict[expr] = {"process": process, "port": port}
            node.print_info(TAG, "New server started with expr: %s on node %s" % (expr, node.node_id))
        ##            node.print_info(TAG, "New server started with expr: %s" %expr)
        except Exception as e:
            node.print_error(TAG, "Error occured with 'start' (new server) for expression '%s': %s" % (expr, e))
            raise lib.RemoteProcedureCallError(
                data={"exception": str(e), "node_id": str(node.node_id), "expr": str(expr)}, code="-32603"
            )
Exemplo n.º 3
0
    def _start_new_server(node, expr):
        """Create a single (new) server.

        Use next available port to start server process. Store server process and port.

        """
        root, path = lib.expr_split(expr)
        try:
            try:
                port_number_lock.acquire()
                port = allocated_port_number.popleft()
                port_number_lock.release()
            except IndexError:
                node.print_error(
                    TAG,
                    "No ports remaining in allocation, cannot start new server."
                )
                return False
            process = multiprocessing.Process(target=server.Server,
                                              args=(node, root, port))
            process.daemon = True
            process.start()
            server_dict[expr] = {"process": process, "port": port}
            node.print_info(TAG, "New server started with expr: %s" % expr)
        except Exception as e:
            node.print_error(
                TAG,
                "Error occured with 'start' (new server) for expression '%s': %s"
                % (expr, e))
            raise lib.RemoteProcedureCallError(data={
                'exception': str(e),
                'node_id': str(node.node_id),
                'expr': str(expr)
            },
                                               code='-32603')
 def _stat_server(node, expr):
     """Instruct single server to return statistics to controller."""
     root, path = lib.expr_split(expr)
     try:
         RemoteProcedureCall._send_to_server(node, root, 'stat')
         node.print_info(TAG, "Server stat'ed with expr: %s" %expr)
     except Exception as e:
         node.print_error(TAG, "Error occured with 'stat' command for expression '%s': %s" % (expr, e))
         raise lib.RemoteProcedureCallError(data={'exception' : str(e), 'node_id' : str(node.node_id), 'expr' : str(expr)}, code='-32603')
 def _seed_server(node, expr, transaction):
     root, path = lib.expr_split(expr)
     object_dict[expr] = transaction
     try:
         key = hashlib.sha224(path).hexdigest()
         path = node.config["cache_path"] + 'shared/' + transaction
         node.database.create({'key' : key, 'path' : path})
         node.print_info(TAG, "Server seeded with expression: %s" %expr)
     except Exception as e:
         node.print_error(TAG, "Error occured with 'seed' command for expression '%s': %s" % (expr, e))
         raise lib.RemoteProcedureCallError(data={'exception' : str(e), 'node_id' : str(node.node_id), 'expr' : str(expr)}, code='-32603')
Exemplo n.º 6
0
 def _pause_server(node, expr):
     """Instruct single server to pause."""
     root, path = lib.expr_split(expr)
     try:
         RemoteProcedureCall._send_to_server(node, root, "pause")
         node.print_info(TAG, "Server paused with expr: %s" % expr)
     except Exception as e:
         node.print_error(TAG, "Error occured with 'pause' command for expression '%s': %s" % (expr, e))
         raise lib.RemoteProcedureCallError(
             data={"exception": str(e), "node_id": str(node.node_id), "expr": str(expr)}, code="-32603"
         )
Exemplo n.º 7
0
 def _start_server(node, expr):
     """Instruct a single (existing) server to start."""
     root, path = lib.expr_split(expr)
     try:
         RemoteProcedureCall._send_to_server(node, root, "start")
         node.print_info(TAG, "Existing server started with expr: %s" % expr)
     except Exception as e:
         node.print_error(TAG, "Error occured with 'start' command for expression '%s': %s" % (expr, e))
         raise lib.RemoteProcedureCallError(
             data={"exception": str(e), "node_id": str(node.node_id), "expr": str(expr)}, code="-32603"
         )
 def _fetch_object(node, params):
     root, path = lib.expr_split(params['expr'])
     transaction = RemoteProcedureCall._find_transaction(params['expr'])
     object_path =  node.config["cache_path"] + 'shared/' + transaction
     connection = httplib.HTTPConnection(root)
     connection.request("GET", path)
     response = connection.getresponse()
     read_payload = response.read()
     connection.close()
     f = open(object_path, 'w')
     f.write(read_payload)
     f.close()
     object_dict[params['expr']] = transaction
     RemoteProcedureCall.seed(node, params)
Exemplo n.º 9
0
 def _fetch_object(node, params):
     root, path = lib.expr_split(params['expr'])
     transaction = RemoteProcedureCall._find_transaction(params['expr'])
     object_path = node.config["cache_path"] + 'shared/' + transaction
     connection = httplib.HTTPConnection(root)
     connection.request("GET", path)
     response = connection.getresponse()
     read_payload = response.read()
     connection.close()
     f = open(object_path, 'w')
     f.write(read_payload)
     f.close()
     object_dict[params['expr']] = transaction
     RemoteProcedureCall.seed(node, params)
Exemplo n.º 10
0
 def _seed_server(node, expr, transaction, state=False):
     root, path = lib.expr_split(expr)
     if state:
         path = "/" + path
     object_dict[expr] = transaction
     try:
         key = hashlib.sha224(path).hexdigest()
         path = node.config["cache_path"] + "shared/" + transaction
         node.database.create({"key": key, "path": path})
         node.print_info(TAG, "Server seeded with expression: %s" % expr)
     except Exception as e:
         node.print_error(TAG, "Error occured with 'seed' command for expression '%s': %s" % (expr, e))
         raise lib.RemoteProcedureCallError(
             data={"exception": str(e), "node_id": str(node.node_id), "expr": str(expr)}, code="-32603"
         )
Exemplo n.º 11
0
 def _stat_server(node, expr):
     """Instruct single server to return statistics to controller."""
     root, path = lib.expr_split(expr)
     try:
         RemoteProcedureCall._send_to_server(node, root, 'stat')
         node.print_info(TAG, "Server stat'ed with expr: %s" % expr)
     except Exception as e:
         node.print_error(
             TAG,
             "Error occured with 'stat' command for expression '%s': %s" %
             (expr, e))
         raise lib.RemoteProcedureCallError(data={
             'exception': str(e),
             'node_id': str(node.node_id),
             'expr': str(expr)
         },
                                            code='-32603')
    def _stop_server(node, expr):
        """Instruct single server to stop.

        Send stop command and then terminate process. Add port back to those available to new servers.

        """
        root, path = lib.expr_split(expr)
        try:
            RemoteProcedureCall._send_to_server(node, root, 'stop')
            time.sleep(0.1)
            server_dict[expr]["process"].terminate()
            port_number_lock.acquire()
            allocated_port_number.append(server_dict[expr]["port"])
            port_number_lock.release()
            node.print_info(TAG, "Server stopped with expr: %s" %expr)
        except Exception as e:
            node.print_error(TAG, "Error occured with 'stop' command for expression '%s': %s" % (expr, e))
            raise lib.RemoteProcedureCallError(data={'exception' : str(e), 'node_id' : str(node.node_id), 'expr' : str(expr)}, code='-32603')
Exemplo n.º 13
0
 def _seed_server(node, expr, transaction):
     root, path = lib.expr_split(expr)
     object_dict[expr] = transaction
     try:
         key = hashlib.sha224(path).hexdigest()
         path = node.config["cache_path"] + 'shared/' + transaction
         node.database.create({'key': key, 'path': path})
         node.print_info(TAG, "Server seeded with expression: %s" % expr)
     except Exception as e:
         node.print_error(
             TAG,
             "Error occured with 'seed' command for expression '%s': %s" %
             (expr, e))
         raise lib.RemoteProcedureCallError(data={
             'exception': str(e),
             'node_id': str(node.node_id),
             'expr': str(expr)
         },
                                            code='-32603')
Exemplo n.º 14
0
    def _fetch_object(node, params):
        root, path = lib.expr_split(params["expr"])
        transaction = RemoteProcedureCall._find_transaction(params["expr"])
        object_path = node.config["cache_path"] + "shared/" + transaction
        connection = httplib.HTTPConnection(root)
        ###	Fetch hiba javítása:
        node.print_info(TAG, "---- root: %s path: %s trans: %s" % (root, path, transaction))
        node.print_info(TAG, "---- params: %s" % params)
        #####	Ez valószínűleg sajna csak a letöltéshez tesz / jelet
        path = "/" + path
        node.print_info(TAG, "---- Javitott path: %s" % path)

        connection.request("GET", path)
        response = connection.getresponse()
        read_payload = response.read()
        connection.close()
        f = open(object_path, "w")
        f.write(read_payload)
        f.close()
        object_dict[params["expr"]] = transaction
        RemoteProcedureCall.seed(node, params, True)
Exemplo n.º 15
0
def test_expr_split():
    root, path = lib.expr_split('127.0.0.1/path/to/object')
    assert root == '127.0.0.1'
    assert path == 'path/to/object'
Exemplo n.º 16
0
def test_expr_split():
    root, path = lib.expr_split('127.0.0.1/path/to/object')
    assert root == '127.0.0.1'
    assert path == 'path/to/object'