Example #1
0
def handle_request(data):
    global exit_flag
    global exit_flag_name
    global dic
    service = data.service_name
    action = data.action_name
    if action in startaction:
        thread.start_new_thread(Switch, (service, action))
        return 'received the service request '
    elif action in stopaction:
        if action == 'stopall':
            exit_flag = 1
        if action == 'stop':
            exit_flag_name = service + '_exit_flag'
            dic[exit_flag_name] = 1
        url = cloud_service_port + "/cloud_service/" + service + "/" + action
        bridge_client.cloud_service_request(url)
    return 'received the service request'
Example #2
0
def Switch(service, action):
    #if request service start or services startall,encouter to switch circle
    global exit_flag
    global dic
    global exit_flag_name
    global qos_level
    global cloud_ip
    exit_flag_name = service + '_exit_flag'
    dic[exit_flag_name] = 0
    switch_flag = -1
    if service == "stereo_proc":  #在计算服务是stereo_proc时,我们才启动qos监控,updated on 2018-11-20
        thread.start_new_thread(QosMonitor, (cloud_ip, ))
    url = cloud_service_port + "/compute/" + service + "/" + action
    while 1:
        #initial the service
        if switch_flag == -1:
            if qos_level != 4:  #initial cloud service
                switch_flag = 1  # cloud serice start status
                bridge_client.cloud_service_request(
                    url)  #start service or startall services firstly in cloud
            else:
                switch_flag = 0  # local servie start status
                localservice.local_service(
                    service, action
                )  #start service or startall services firstly in local
        #-------SWITCH MECHANISM--------#
        if switch_flag == 1:  # qos mechanism  work when cloud service start
            if qos_level == 4:  #switch to local service
                print 'qos_level:4,switch to local service'
                switch_flag = 0  # local servie start status
                localservice.local_service(service,
                                           action)  #start local service
                time.sleep(1)
        if switch_flag == 0:
            if qos_level != 4:  #switch to cloud service
                print 'switch to cloud service'
                switch_flag = 1
                bridge_client.cloud_service_request(url)
        if exit_flag == 1:
            break
        if dic[exit_flag_name] == 1:
            break
Example #3
0
if "CLOUD_IP" not in os.environ:
    print "Can't find environment variable CLOUD_IP."
    sys.exit(1)

if "ROS_MASTER_URI" not in os.environ:
    print "Can't find environment variable ROS_MASTER_URI."
    sys.exit(1)

cloud_ip = os.environ['CLOUD_IP']
ros_master_uri = os.environ['ROS_MASTER_URI']
cloud_service_port = 'http://'+ cloud_ip + ':5566'


def handle(data):
    service = data.service_name
    action = data.action_name
    bridge_client. cloud_param_set('http://'+cloud_ip+'/cloud_service/set_param', ros_master_uri)
    url = cloud_service_port + '/cloud_service/' + service + '/' + action
    return bridge_client.cloud_service_request(url)


def bridge_server():
    rospy.init_node('bridge_server')
    rospy.Service('bridge_service', call, handle)
    print "bridge_server ready for client."
    rospy.spin()


if __name__ == "__main__":
    bridge_server()
Example #4
0
def handle(data):
    service = data.service_name
    action = data.action_name
    url = cloud_service_port + '/cloud_service/' + service + '/' + action
    return bridge_client.cloud_service_request(url)
Example #5
0
def handle(data):
    number = data.number
    url = cloud_service_port + '/cloud_service/monitor/'+number
    return bridge_client.cloud_service_request(url)
Example #6
0
def handle(data):
    exo_id= data.number
    action=data.action    
    url = "http://"+cloud_service_port + '/storage/'+exo_id+'/'+action
    return bridge_client.cloud_service_request(url)