Ejemplo n.º 1
0
 def thread_main(self):
     try:
         with self.lock:
             self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
             self.should_close = True            
         ciel.log("Connecting %s:%s" % (self.otherend_hostname, self.ref.socket_port), "TCP_FETCH", logging.INFO)
         subscribe_remote_output_nopost(self.ref.id, self)
         self.sock.connect((self.otherend_hostname, self.ref.socket_port))
         self.sock.sendall("%s %s %d\n" % (self.ref.id, get_own_netloc(), self.chunk_size))
         ciel.log("%s:%s connected: requesting %s (chunk size %d)" % (self.otherend_hostname, self.ref.socket_port, self.ref.id, self.chunk_size), "TCP_FETCH", logging.INFO)
         fp = self.sock.makefile("r", bufsize=0)
         response = fp.readline().strip()
         fp.close()
         with self.lock:
             self.should_close = False
             if response.find("GO") != -1:
                 ciel.log("TCP-fetch %s: transfer started" % self.ref.id, "TCP_FETCH", logging.INFO)
                 new_fd = os.dup(self.sock.fileno())
                 self.sock.close()
                 self.fetch_ctx.set_fd(new_fd, True)
             else:
                 ciel.log("TCP-fetch %s: request failed: other end said '%s'" % (self.ref.id, response), "TCP_FETCH", logging.WARNING)
                 unsubscribe_remote_output_nopost(self.ref.id)
                 self.done = True
                 self.sock.close()
                 self.fetch_ctx.result(False)
     except Exception as e:
         unsubscribe_remote_output_nopost(self.ref.id)
         ciel.log("TCP-fetch %s: failed due to exception %s" % (self.ref.id, repr(e)), "TCP_FETCH", logging.ERROR)
         with self.lock:
             if self.should_close:
                 self.sock.close()
             self.done = True
             self.should_close = False
         self.fetch_ctx.result(False)
Ejemplo n.º 2
0
 def result(self, success):
     self.completed = True
     del active_http_transfers[self.ref.id]
     if success:
         ref = SW2_ConcreteReference(self.ref.id, self.last_progress, [get_own_netloc()])
         self.bs_ctx.commit()
     else:
         ref = None
     for l in self.listeners:
         l.result(success, ref)
Ejemplo n.º 3
0
def fetch_ref_async(ref, result_callback, reset_callback, start_filename_callback, 
                    start_fd_callback=None, string_callback=None, progress_callback=None, 
                    chunk_size=67108864, may_pipe=False, sole_consumer=False,
                    must_block=False, task_record=None):

    if isinstance(ref, SWErrorReference):
        raise RuntimeSkywritingError()
    if isinstance(ref, SW2_FixedReference):
        assert ref.fixed_netloc == get_own_netloc()

    new_client = FetchInProgress(ref, result_callback, reset_callback, 
                                 start_filename_callback, start_fd_callback, 
                                 string_callback, progress_callback, chunk_size,
                                 may_pipe, sole_consumer, must_block, task_record)
    new_client.start_fetch()
    return new_client
Ejemplo n.º 4
0
 def get_stream_ref(self):
     if skywriting.runtime.tcp_server.tcp_server_active():
         return SW2_SocketStreamReference(self.refid, get_own_netloc(), skywriting.runtime.tcp_server.aux_listen_port)
     else:
         return SW2_StreamReference(self.refid, location_hints=[get_own_netloc()])
Ejemplo n.º 5
0
 def get_completed_ref(self):
     if not self.closed:
         raise Exception("FileOutputContext for ref %s must be closed before it is realised as a concrete reference" % self.refid)
     if self.direct_write_filename is not None or self.direct_write_fd is not None:
         return SW2_CompletedReference(self.refid)
     completed_file = producer_filename(self.refid)
     if self.current_size < 1024:
         with open(completed_file, "r") as fp:
             return SWDataValue(self.refid, encode_datavalue(fp.read()))
     else:
         return SW2_ConcreteReference(self.refid, size_hint=self.current_size, location_hints=[get_own_netloc()])
Ejemplo n.º 6
0
def unsubscribe_remote_output(refid):
    unsubscribe_remote_output_nopost(refid)
    netloc = get_own_netloc()
    post_data = simplejson.dumps({"netloc": netloc})
    post_string_noreturn("http://%s/control/streamstat/%s/unsubscribe" 
                          % (netloc, refid), post_data)
Ejemplo n.º 7
0
def subscribe_remote_output(refid, remote_netloc, chunk_size, subscriber):
    subscribe_remote_output_nopost(refid, subscriber)
    post_data = simplejson.dumps({"netloc": get_own_netloc(), "chunk_size": chunk_size})
    post_string_noreturn("http://%s/control/streamstat/%s/subscribe" % (remote_netloc, refid), post_data, result_callback=(lambda success, url: subscribe_result(refid, success, url)))