Exemplo n.º 1
0
    def test_server_with_path(self):
        client_with_custom_path = ipc.HTTPTransceiver('apache.org', 80,
                                                      '/service/article')
        self.assertEqual('/service/article',
                         client_with_custom_path.req_resource)

        client_with_default_path = ipc.HTTPTransceiver('apache.org', 80)
        self.assertEqual('/', client_with_default_path.req_resource)
Exemplo n.º 2
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.º 3
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.º 4
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.º 5
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.º 6
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.º 7
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.º 8
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.º 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_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.º 11
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.º 12
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.º 13
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.º 14
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.º 15
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.º 16
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.º 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():
    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.º 19
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.º 20
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.º 21
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.º 22
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.º 23
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()
Exemplo n.º 24
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.º 25
0
def make_requestor(server_host, server_port, protocol):
    client = ipc.HTTPTransceiver(SERVER_HOST, SERVER_PORT)
    return ipc.Requestor(protocol, client)
Exemplo n.º 26
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.º 27
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.º 28
0
                "name": row[1],
                "email": row[2]
            }
        if "lists" not in users_and_lists[customerid]:
            users_and_lists[customerid]["lists"] = {}
        users_and_lists[customerid]["lists"][listid] = {
            "listid": listid,
            "listname": row[4],
            "listdatecreated": row[5].strftime("%Y-%m-%d %H:%M")
        }

    splice_host = get_key_from_configservice(key="/helix-aws/splice-host")
    splice_port = get_key_from_configservice(key="/helix-aws/splice-port")
    splice_path = get_key_from_configservice(key="/helix-aws/splice-path")
    # client code - attach to the server and send a message
    client = ipc.HTTPTransceiver(str(splice_host), int(splice_port),
                                 str(splice_path))
    requester = ipc.Requestor(PROTOCOL, client)

    new_customers_title = "New Customers in the last 24 hours"
    new_lists_title = "New Lists uploaded in the last 24 hours"

    new_customers_table = "%s\nCustomer Id\tCustomer Name\tEmail\tDate Created\tTerms Acceptance\tEmail Verified\n" % new_customers_title
    new_customers_table += "-" * len(new_customers_table)
    new_customers_table += "\n"
    new_lists_table = "%s\nCustomer Id\tCustomer Name\tEmail\tList Id\tList name\tDate Created\tNumber of Records\n\n" % new_lists_title
    new_lists_table += "-" * len(new_lists_table)
    new_lists_table += "\n"

    new_customers_table_html = "<table><tr><th colspan=6>%s</th></tr><tr><th>Customer Id</th><th>Customer Name</th><th>Email</th><th>Date Created</th><th>Terms Acceptance</th><th>Email Verified</th></tr>" % new_customers_title
    new_lists_table_html = "<table><tr><th colspan=7>%s</th></tr><tr><th>Customer Id</th><th>Customer Name</th><th>Email</th><th>List Id</th><th>List name</th><th>Date Created</th><th>Number of Records</th></tr>" % new_lists_title
Exemplo n.º 29
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)
#!/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()