Exemplo n.º 1
0
def send_request(bytestr1, bytestr2, mode1, mode2, tag=''):
    """
        This function sends data to next layer. It will pop an available
        next layer device IP address defined at IP table, and send data
        to that IP. After, it will put the available IP back.

        Args:
            bytestr1: The encoded byte string for frames.
            bytestr2: The encoded byte string for optical frames.
            mode1: Specify next layer option.
            mode2: Specify next layer option.
    """
    init = Initializer.create_init()

    queue1 = init.ip[mode1]
    queue2 = init.ip[mode2]
    addr1 = queue1.get()
    addr2 = queue2.get()
    """"""
    client1 = ipc.HTTPTransceiver(addr1, 12345)
    requestor1 = ipc.Requestor(PROTOCOL, client1)

    data = dict()
    data['input'] = bytestr1
    data['next'] = mode1
    data['tag'] = tag

    start = time.time()
    requestor1.request('forward', data)
    print 'sending data to spatial'
    end = time.time()

    init.node_timer(mode1, end - start)

    client1.close()
    queue1.put(addr1)
    """"""
    client2 = ipc.HTTPTransceiver(addr2, 12345)
    requestor2 = ipc.Requestor(PROTOCOL, client2)

    data['input'] = bytestr2
    data['next'] = mode2
    data['tag'] = tag

    start = time.time()
    requestor2.request('forward', data)
    print 'sending data to temporal'
    end = time.time()

    init.node_timer(mode2, end - start)

    client2.close()
    queue2.put(addr2)
Exemplo n.º 2
0
  def testEchoService(self):
    """Tests client-side of the Echo service."""
    self.StartEchoServer()
    try:
      (server_host, server_port) = self._server.server_address

      transceiver = ipc.HTTPTransceiver(host=server_host, port=server_port)
      requestor = ipc.Requestor(
          local_protocol=ECHO_PROTOCOL,
          transceiver=transceiver,
      )
      response = requestor.Request(
          message_name='ping',
          request_datum={'ping': {'timestamp': 31415, 'text': 'hello ping'}},
      )
      logging.info('Received echo response: %s', response)

      response = requestor.Request(
          message_name='ping',
          request_datum={'ping': {'timestamp': 123456, 'text': 'hello again'}},
      )
      logging.info('Received echo response: %s', response)

      transceiver.Close()

    finally:
      self.StopEchoServer()
Exemplo n.º 3
0
def send_request(cap):
    client = ipc.HTTPTransceiver(SERVER_ADDR[0], SERVER_ADDR[1])
    requestor = ipc.Requestor(PROTOCOL, client)

    ret, image = cap.read()
    image_h, image_w, _ = image.shape
    data = preprocess_input(image, net_h, net_w)

    packet = dict()
    packet['input'] = [data.tobytes()]

    start = time.time()
    array = requestor.request('forward', packet)
    print 'Latency: %.3f sec' % (time.time() - start)

    results = []
    results.append(
        np.fromstring(array[0], np.float32).reshape([1, 10, 10, 255]))
    results.append(
        np.fromstring(array[1], np.float32).reshape([1, 20, 20, 255]))
    results.append(
        np.fromstring(array[2], np.float32).reshape([1, 40, 40, 255]))

    boxes = []
    for i in range(len(results)):
        boxes += decode_netout(results[i][0], anchors[i], obj_thresh,
                               nms_thresh, net_h, net_w)

    correct_yolo_boxes(boxes, image_h, image_w, net_h, net_w)
    do_nms(boxes, nms_thresh)
    boxes = trim_box(boxes)
    draw_boxes(image, boxes, labels, obj_thresh)
    client.close()

    cv2.imshow('Detected image', image)
Exemplo n.º 4
0
def send_request(frame):
    """
        This function sends data to next layer. It will pop an available
        next layer device IP address defined at IP table, and send data
        to that IP. After, it will put the available IP back.
        Args:
            bytestr: The encoded byte string for image.
            mode: Specify next layer option.
    """
    init = Initializer.create()
    queue = init.queue

    addr = queue.get()
    client = ipc.HTTPTransceiver(addr, 12345)
    requestor = ipc.Requestor(PROTOCOL, client)

    data = dict()
    tmp = [str(entry) for entry in frame.shape]
    data['shape'] = ' '.join(tmp)
    data['input'] = frame.astype(np.uint8).tobytes()
    data['type'] = 8
    requestor.request('forward', data)

    client.close()
    queue.put(addr)
Exemplo n.º 5
0
def send_request(bytestr, mode, tag=''):
    """
        This function sends data to next layer. It will pop an available
        next layer device IP address defined at IP table, and send data
        to that IP. After, it will put the available IP back.

        Args:
            bytestr: The encoded byte string for image.
            mode: Specify next layer option.
    """
    init = Initializer.create_init()
    queue = init.queue

    addr = queue.get()
    client = ipc.HTTPTransceiver(addr, 12345)
    requestor = ipc.Requestor(PROTOCOL, client)

    data = dict()
    data['input'] = bytestr
    data['next'] = mode
    data['tag'] = tag

    start = time.time()
    requestor.request('forward', data)
    end = time.time()

    init.node_timer(mode, end - start)

    client.close()
    queue.put(addr)
Exemplo n.º 6
0
    def send(self, X, name, tag):
        """
            Send data to other devices. The data packet contains data and models name.
            Ip address of next device pop from Queue of a ip list.

            Args:
                 X: numpy array
                 name: next device models name
                 tag: mark the current layer label
        """
        node = Node.create()
        queue = node.ip[name]
        address = queue.get()

        # initializer use port 9999 to receive data
        port = 9999 if name == 'initial' else 12345
        client = ipc.HTTPTransceiver(address, port)
        requestor = ipc.Requestor(PROTOCOL, client)

        node.name = name

        data = dict()
        data['input'] = X.tostring()
        data['next'] = name
        data['tag'] = tag
        node.log('finish assembly')
        start = time.time()
        requestor.request('forward', data)
        end = time.time()
        node.timer(end - start)

        node.log('node gets request back')
        client.close()
        queue.put(address)
Exemplo n.º 7
0
    def send(self, output, id):
        client = ipc.HTTPTransceiver('192.168.1.16', 12345)
        requestor = ipc.Requestor(PROTOCOL, client)

        data = dict()
        data['input'] = output.astype(np.float32).tobytes()
        data['identifier'] = id

        requestor.request('forward', data)
Exemplo n.º 8
0
def send_request(frame, id):
    client = ipc.HTTPTransceiver('192.168.1.14', 12345)
    requestor = ipc.Requestor(PROTOCOL, client)

    data = dict()
    data['input'] = frame.astype(np.float32).tobytes()
    data['identifier'] = id

    requestor.request('forward', data)
    client.close()
Exemplo n.º 9
0
def get_tweets(handle):
    """ Return a list of tweets from a specific user """
    client = ipc.HTTPTransceiver(server_addr[0], server_addr[1])
    requestor = ipc.Requestor(PROTOCOL, client)
    user = create_user(handle)
    params = dict()
    params['user'] = user
    result = requestor.request('tweets', params)
    client.close()
    return result
Exemplo n.º 10
0
def send_tweet(handle="anonymous", message="had nothing to say"):
    """ Send a tweet as a user """
    client = ipc.HTTPTransceiver(server_addr[0], server_addr[1])
    requestor = ipc.Requestor(PROTOCOL, client)
    author = create_user(handle)
    tweet = create_tweet(author, message)
    params = dict()
    params['tweet'] = tweet
    result = requestor.request('send', params)
    client.close()
    return result
Exemplo n.º 11
0
    def send(self, output, id, ip):
        client = ipc.HTTPTransceiver(ip, 12345)
        requestor = ipc.Requestor(PROTOCOL, client)

        data = dict()
        data['input'] = output.astype(np.float32).tobytes()
        data['identifier'] = id

        result = requestor.request('forward', data)
        if result:
            self.switch()
Exemplo n.º 12
0
def test2():
    client = ipc.HTTPTransceiver(server_addr[0], server_addr[1])
    requestor = ipc.Requestor(PROTOCOL, client)

    params = dict(x=1.0)
    try:
        msg = requestor.request('runOPCDA#com.splunk.opc.Test', params)
    except Exception as ex:
        print ex

    print("OK Result %s" % msg)
Exemplo n.º 13
0
    def send(self, name, params):
        if self.useSSL:
            client = ipc.HTTPSTransceiver(self.host,
                                          self.port,
                                          req_resource=self.req_resource)
        else:
            client = ipc.HTTPTransceiver(self.host,
                                         self.port,
                                         req_resource=self.req_resource)
        self.requestor = ipc.Requestor(self.protocol, client)

        return self.requestor.request(name, params)
Exemplo n.º 14
0
 def make_connection(self, retry=2):
     """Establishes the underlying connection to HBase."""
     while retry:
         retry -= 1
         try:
             self.client = ipc.HTTPTransceiver(self.host, self.port)
             self.requestor = ipc.Requestor(PROTOCOL, self.client)
             return
         except:
             pass
     exceptionType, exception, tracebackInfo = sys.exc_info()
     raise exception
Exemplo n.º 15
0
def sendData(command, data):
    client = ipc.HTTPTransceiver(server_addr[0], server_addr[1])
    requestor = ipc.Requestor(PROTOCOL, client)

    message = dict()
    message['command'] = command
    message['data'] = data

    params = dict()
    params['message'] = message
    print("Result: " + requestor.request('send', params))

    client.close()
Exemplo n.º 16
0
def send():
    client = ipc.HTTPTransceiver(server_addr[0], serrver_addr[1])
    requestor = ipc.Requestor(PROTOCOL, client)

    while True:
        # Wait for 1 second worth of events.
        while buffer.qsize() < baud_rate:
            buffer.put(signal.get())

        # Create an RPC
        events = []
        for x in range(0, baud_rate):
            events.append(buffer.get())
        message = {'events': events}
        requestor.request('send', {'message': message})
Exemplo n.º 17
0
    def send(self, X):
        ip = self.ip.get()

        client = ipc.HTTPTransceiver(ip, 12345)
        requestor = ipc.Requestor(PROTOCOL, client)

        data = dict()
        tmp = [str(entry) for entry in np.shape(X[0])]
        data['shape'] = ' '.join(tmp)
        data['input'] = X.tobytes()
        data['type'] = 32
        requestor.request('forward', data)

        client.close()
        self.ip.put(ip)
Exemplo n.º 18
0
def send_request():
    client = ipc.HTTPTransceiver(SERVER_ADDR[0], SERVER_ADDR[1])
    requestor = ipc.Requestor(PROTOCOL, client)

    data1 = np.random.random_sample([1, 20, 20, 512])
    data1 = data1.astype(np.float32)

    data2 = np.random.random_sample([1, 20, 20, 512])
    data2 = data2.astype(np.float32)

    data3 = np.random.random_sample([1, 40, 40, 256])
    data3 = data3.astype(np.float32)

    packet = dict()
    packet['input'] = [data1.tobytes(), data2.tobytes(), data3.tobytes()]

    requestor.request('forward', packet)
    client.close()
Exemplo n.º 19
0
def test1():
    client = ipc.HTTPTransceiver(server_addr[0], server_addr[1])
    requestor = ipc.Requestor(PROTOCOL, client)

    xArray = [1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7, 8.8, 9.2]
    yArray = [1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0]
    biasCorrected = True

    params = dict()
    params['xArray'] = xArray
    params['yArray'] = yArray
    params['biasCorrected'] = biasCorrected

    msg = requestor.request('covariance#com.splunk.rpc.Covariance', params)

    print("Result: %s" % msg)

    # cleanup
    client.close()
Exemplo n.º 20
0
    def send(self, X, name, tag):
        """
            Send data to other devices. The data packet contains data and models name.
            Ip address of next device pop from Queue of a ip list.
            Args:
                 X: numpy array
                 name: next device models name
                 tag: mark the current layer label
        """
        node = Node.create()
        queue = node.ip[name]
        address = queue.get()

        # initializer use port 9999 to receive data
        port = 9999 if name == 'initial' else 12345
        client = ipc.HTTPTransceiver(address, port)
        requestor = ipc.Requestor(PROTOCOL, client)

        node.name = name

        data = dict()
        data['input'] = X.tostring()
        data['next'] = name
        data['tag'] = tag
        node.log('finish assembly')
        start = time.time()
        try:
            requestor.request('forward', data)
        except Exception, e:
            # node.log('Error', e.message)
            # The interrupt node's ip is the address above
            print address
            """Remove the IP address of the interrupted node from the available ip"""
            available_ip = read_ip(get_file(node.num_devices))
            available_ip = del_ip(available_ip, address)

            node.num_devices = node.num_devices - 1
            """Update new IP configuration based on available ip"""
            update_ip(get_file(node.num_devices), available_ip)

            """Reload the new ip configuration file"""
            load_ip(node)
Exemplo n.º 21
0
        def avro_decorated(*args, **argv):
            # find the rpc port from inputs config.
            port = 9998

            if hasattr(avro_decorated, "_sessionKey_"):
                import splunk.entity as en
                ent = en.getEntity("/configs/conf-inputs",
                                   "rpcstart://default",
                                   namespace="splunk-demo-opcda",
                                   sessionKey=avro_decorated._sessionKey_,
                                   owner="nobody")
                port = ent["port"]
                logger.debug("ent=%s" % ent)

            server_addr = ("localhost", port)
            # server_addr = load_server_addr(argv, f._sessionKey_)
            client = ipc.HTTPTransceiver(server_addr[0], server_addr[1])

            requestor = ipc.Requestor(load_protocol(), client)

            def call(*argus):
                sn, val = schema.items()[0]

                params = {}
                reqs = val["request"]
                for i in range(len(reqs)):
                    k = reqs[i]["name"]
                    if len(argus) > i:
                        params[k] = argus[i]

                logger.debug("sn=%s, parameters = %s" % (sn, params))

                ret = requestor.request(sn, params)

                return ret

            avro_decorated.call = call
            avro_decorated.__name__ = f.__name__

            return f(*args, **argv)
Exemplo n.º 22
0
def send_request():
    print 'Connecting ... %s:%s' % (SERVER_ADDR[0], SERVER_ADDR[1])
    client = ipc.HTTPTransceiver(SERVER_ADDR[0], SERVER_ADDR[1])
    requestor = ipc.Requestor(PROTOCOL, client)

    image = cv2.imread(image_path)
    image_h, image_w, _ = image.shape
    data = preprocess_input(image, net_h, net_w)

    packet = dict()
    packet['input'] = [data.tobytes()]

    start = time.time()
    array = requestor.request('forward', packet)
    print 'Latency: %.3f sec' % (time.time() - start)

    results = []
    results.append(np.fromstring(array[0], np.float32).reshape([1, 10, 10, 255]))
    results.append(np.fromstring(array[1], np.float32).reshape([1, 20, 20, 255]))
    results.append(np.fromstring(array[2], np.float32).reshape([1, 40, 40, 255]))

    boxes = []
    for i in range(len(results)):
        boxes += decode_netout(results[i][0], anchors[i], obj_thresh, nms_thresh, net_h, net_w)

    correct_yolo_boxes(boxes, image_h, image_w, net_h, net_w)
    do_nms(boxes, nms_thresh)
    boxes = trim_box(boxes)
    draw_boxes(image, boxes, labels, obj_thresh)
    client.close()

    cv2.imshow('Detected image', image)
    while True:
        key = cv2.waitKey(1) & 0xFF
        if key == ord('q') or key == ord('\r') or key == ord('\n'):
            break
        time.sleep(0.01)
    cv2.destroyAllWindows()
#!/usr/bin/python

import avro.ipc as ipc
import avro.protocol as protocol

avroProtocol = protocol.parse(open("tweetWithAvr.avr").read())

java_rpc_server_address = ("localhost", 9090)

if __name__ == "__main__":

    client = ipc.HTTPTransceiver(java_rpc_server_address[0],
                                 java_rpc_server_address[1])
    requestor = ipc.Requestor(avroProtocol, client)

    tweet = {
        "tweetId": 1,
        "username": "******",
        "text": "This is a tweet from python"
    }

    params = {"tweet": tweet}
    requestor.request("sendTweet", params)
    client.close()
Exemplo n.º 24
0
 def _request(self, msg, args):
     transceiver = ipc.HTTPTransceiver(self._host, self._port)
     requestor = ipc.Requestor(_PROTO, transceiver)
     response = requestor.request(msg, args)
     transceiver.close()
     return response
Exemplo n.º 25
0
    def send(self, X, name, tag):
        """
            Send data to other devices. The data packet contains data and models name.
            Ip address of next device pop from Queue of a ip list.

            Args:
                 X: numpy array
                 name: next device models name
                 tag: mark the current layer label
        """
        node = Node.create()
        queue = node.ip[name]
        backupq = node.ip['backup']
        backup_used = False

        address = queue.get()

        # initializer use port 9999 to receive data
        port = 9999 if name == 'initial' else 12345

        # Fault Tolerance Strategy 1: check if node not available, then send to backup node
        # Fault Tolerance Straregy 2: check if node recieved, but failed to forward to next
        # Fault Tolerance Strategy 3: check if initial doesn't recieve input within some time, then resend

        response = os.system("ping -c 3 " + address)

        #and then check the response...
        if self.check_ip(address):
            msg = address + ' is up! sending'
            print colored(msg, 'green')
        else:
            oldaddress = address
            address = backupq.get()
            backup_used = True
            msg = oldaddress + ' is down! sending to backup node ' + address
            print colored(msg, 'red')

        client = ipc.HTTPTransceiver(address, port)
        requestor = ipc.Requestor(PROTOCOL, client)

        node.name = name

        data = dict()
        data['input'] = X.tostring()
        data['next'] = name
        data['tag'] = tag
        node.log('finish assembly')
        start = time.time()

        #raw_input("Press Enter to send to next block...")
        requestor.request('forward', data)

        end = time.time()
        node.timer(end - start)

        node.log('node gets request back')
        client.close()

        if backup_used:
            queue.put(oldaddress)
            backupq.put(address)
        else:
            queue.put(address)
Exemplo n.º 26
0
PROTOCOL = protocol.parse(open("../../avro/example/mail.avpr").read())

server_addr = ('127.0.0.1', 9090)

class UsageError(Exception):
    def __init__(self, value):
        self.value = value
    def __str__(self):
        return repr(self.value)

if __name__ == '__main__':
    if len(sys.argv) != 4:
        raise UsageError("Usage: <to> <from> <body>")

    # client code - attach to the server and send a message
    client = ipc.HTTPTransceiver(server_addr[0], server_addr[1])
    requestor = ipc.Requestor(PROTOCOL, client)
    
    # fill in the Message record and send it
    message = dict()
    message['to'] = sys.argv[1]
    message['from'] = sys.argv[2]
    message['body'] = sys.argv[3]

    params = dict()
    params['message'] = message
    print("Result: " + requestor.request('send', params))

    # cleanup
    client.close()
Exemplo n.º 27
0
def make_requestor(server_host, server_port, protocol):
    client = ipc.HTTPTransceiver(SERVER_HOST, SERVER_PORT)
    return ipc.Requestor(protocol, client)
Exemplo n.º 28
0
def send_message(uri, proto, msg, datum):
    url_obj = urlparse.urlparse(uri)
    client = ipc.HTTPTransceiver(url_obj.hostname, url_obj.port)
    proto_json = file(proto, 'r').read()
    requestor = ipc.Requestor(protocol.parse(proto_json), client)
    print requestor.request(msg, datum)
Exemplo n.º 29
0
 def request(self, *args, **param):
     transciever = ipc.HTTPTransceiver(self.server, self.port)
     requestor = ipc.Requestor(self.protocol, transciever)
     return requestor.request(*args, **param)
Exemplo n.º 30
0
def get_client(host='127.0.0.1', port=9170):
    schema = os.path.join(root, 'interface/avro', 'cassandra.avpr')
    proto = protocol.parse(open(schema).read())
    client = ipc.HTTPTransceiver(host, port)
    return ipc.Requestor(proto, client)