def call_dag(self, dname, arg_map, direct_response=False, consistency=NORMAL, output_key=None, client_id=None): ''' Issues a new request to execute the DAG. Returns a CloudburstFuture that dname: The name of the DAG to cexecute. arg_map: A map from function names to lists of arguments for each of the functions in the DAG. direct_response: If True, the response will be synchronously received by the client; otherwise, the result will be stored in the KVS. consistency: The consistency mode to use with this function: either NORMAL or MULTI. output_key: The KVS key in which to store the result of thie DAG. client_id: An optional ID associated with an individual client across requests; this is used for causal metadata. ''' dc = DagCall() dc.name = dname dc.consistency = consistency if output_key: dc.output_key = output_key if client_id: dc.client_id = client_id for fname in arg_map: fname_args = arg_map[fname] if type(fname_args) != list: fname_args = [fname_args] args = [serializer.dump(arg, serialize=False) for arg in fname_args] al = dc.function_args[fname] al.values.extend(args) if direct_response: dc.response_address = self.response_address self.dag_call_sock.send(dc.SerializeToString()) r = GenericResponse() r.ParseFromString(self.dag_call_sock.recv()) if direct_response: try: result = self.response_sock.recv() return serializer.load(result) except zmq.ZMQError as e: if e.errno == zmq.EAGAIN: return None else: raise e else: if r.success: return CloudburstFuture(r.response_id, self.kvs_client, serializer) else: return None
def test_serialize_future(self): ''' Tests that the serializer correctly detects and converts a CloudburstFuture to a CloudburstReference. ''' kvs_client = MockAnnaClient() future = CloudburstFuture('id', kvs_client, self.serializer) serialized = self.serializer.dump(future, serialize=False) self.assertEqual(type(serialized), Value) self.assertEqual(serialized.type, DEFAULT) reference = self.serializer.load(serialized) self.assertEqual(type(reference), CloudburstReference) self.assertEqual(future.obj_id, reference.key)
def __call__(self, *args): obj_id = self._conn.exec_func(self.name, args) if obj_id is None or len(obj_id) == 0: return None return CloudburstFuture(obj_id, self._kvs_client, serializer)