Beispiel #1
0
    def register_dag(self, name, functions, connections):
        '''
        Registers a new DAG with the system. This operation will fail if any of
        the functions provided cannot be identified in the system.

        name: A unique name for this DAG.
        functions: A list of names of functions to be included in this DAG.
        connections: A list of ordered pairs of function names that represent
        the edges in this DAG.
        '''

        flist = self._get_func_list()
        for fname in functions:
            if fname not in flist:
                logging.info(
                    'Function %s not registered. Please register before \
                    including it in a DAG.' % (fname))
                return False, None

        dag = Dag()
        dag.name = name
        dag.functions.extend(functions)
        for pair in connections:
            conn = dag.connections.add()
            conn.source = pair[0]
            conn.sink = pair[1]

        self.dag_create_sock.send(dag.SerializeToString())

        r = GenericResponse()
        r.ParseFromString(self.dag_create_sock.recv())

        return r.success, r.error
Beispiel #2
0
def create_linear_dag(functions,
                      fnames,
                      kvs_client,
                      dname,
                      lattice_type=LWWPairLattice):
    dag = Dag()
    dag.name = dname

    prev = None

    for index, fname in enumerate(fnames):
        function = functions[index]
        create_function(function, kvs_client, fname, lattice_type)

        ref = dag.functions.add()
        ref.name = fname

        if prev:
            link = dag.connections.add()
            link.source = prev
            link.sink = fname

        prev = fname

    return dag
Beispiel #3
0
    def register_dag(self, name, functions, connections):
        '''
        Registers a new DAG with the system. This operation will fail if any of
        the functions provided cannot be identified in the system.

        name: A unique name for this DAG.
        functions: A list of names of functions to be included in this DAG.
        connections: A list of ordered pairs of function names that represent
        the edges in this DAG.
        '''

        flist = self._get_func_list()
        for fname in functions:
            if isinstance(fname, tuple):
                fname = fname[0]

            if fname not in flist:
                raise RuntimeError(
                    f'Function {fname} not registered. Please register before '
                    + 'including it in a DAG.')

        dag = Dag()
        dag.name = name
        for function in functions:
            ref = dag.functions.add()

            if type(function) == tuple:
                fname = function[0]
                invalids = function[1]
                ref.type = MULTIEXEC
            else:
                fname = function
                invalids = []

            ref.name = fname
            for invalid in invalids:
                ref.invalid_results.append(serializer.dump(invalid))

        for pair in connections:
            conn = dag.connections.add()
            conn.source = pair[0]
            conn.sink = pair[1]

        self.dag_create_sock.send(dag.SerializeToString())

        r = GenericResponse()
        r.ParseFromString(self.dag_create_sock.recv())

        return r.success, r.error
Beispiel #4
0
    def _construct_dag_with_locations(self, source, sink):
        # Construct a simple, two-function DAG.
        dag = Dag()
        dag.name = 'dag'
        dag.functions.extend([source, sink])
        link = dag.connections.add()
        link.source = source
        link.sink = sink

        # Add the relevant metadata to the policy engine.
        source_address = (self.ip, 1)
        sink_address = (self.ip, 2)
        self.policy.function_locations[source] = {source_address}
        self.policy.function_locations[sink] = {sink_address}

        return dag, source_address, sink_address