Exemplo n.º 1
0
 def UpdateTaskStateInfo(self):
     job_id_list = []
     try:
         jobs_manager_client = Rpc(T=Client).GetProxy(jobs_manager_endpoint)
         job_id_list = jobs_manager_client.GetJobId()
     except TTransportException, e:
         return False
Exemplo n.º 2
0
def HeartbeatThread():
    while True:
	heartbeat_app_info = HeartbeatAppInfo()
        heartbeat_app_info.app_id = 1
        heartbeat_app_info.state = AppState.APP_ONLINE
	try :
		worker_client = Rpc(T = Client).GetProxy("192.168.120.249:9090")
                worker_client.sendheartbeat(heartbeat_app_info)
                #client.sendheartbeat(heartbeat_app_info)
        	print "yes_txh"
	except TTransportException, e:
		continue
	time.sleep(10)
Exemplo n.º 3
0
    def processrequest(self, data):
        """
		Forward the received message to the requestScanner
		and returns its reply

		@type  data: string
		@param data: The message received from the client socket
		@rtype: string
		@return: The serialized XML reply to be sent back to the Netconf Manager
		"""

        self.netconfLock.acquire()

        try:
            # try to build the DOM, checking well-formness
            # http://madynes.loria.fr is there to avoid a warning...
            doc = NonvalidatingReader.parseString(data,
                                                  'http://madynes.loria.fr')

            # XML Schema validation
            #self.valid = util.validate(data,[C.NETCONF_SCHEMA_URI])

            mainNode = doc.documentElement
            if mainNode.tagName == C.RPC:
                rpcRequest = Rpc(mainNode, self.session)
                response = rpcRequest.execute()
            elif mainNode.tagName == C.HELLO:
                response = ''
            else:
                moduleReply = ModuleReply(
                    error_type=ModuleReply.PROTOCOL,
                    error_tag=ModuleReply.UNKNOWN_ELEMENT,
                    error_severity=ModuleReply.ERROR,
                    error_message=
                    "An element is not known. It should be an rpc or hello tag."
                )
                moduleReply.addErrorInfo("bad-element", mainNode.tagName)
                nodeReply = moduleReply.getXMLNodeReply()
                response = util.convertNodeToString(nodeReply)

        except Exception, exp:
            moduleReply = ModuleReply(
                error_type=ModuleReply.PROTOCOL,
                error_tag=ModuleReply.UNKNOWN_ELEMENT,
                error_severity=ModuleReply.ERROR,
                error_message="The Netconf message is not well-formed." +
                str(exp))
            nodeReply = moduleReply.getXMLNodeReply()
            response = util.convertNodeToString(nodeReply)
Exemplo n.º 4
0
def main():
    if len(argv) != 2:
        print "usage: ./server.py MY_IP_AS_VISIBLE_FROM_SWITCH"
        return -1
    host = argv[1]

    print "!! ipc is extremely insecure but it's only listening on 127.0.0.1 !!"

    print "running webserver on http://{}:{}/".format(host, webserver_port)
    print "running sockserver on {}:{}".format(host, socket_port)
    print "running ipc server on 127.0.0.1:{}".format(ipc_port)

    rpc = Rpc(host, socket_port)

    t = threading.Thread(target=sockserver,
                         kwargs=dict(host=host, port=socket_port, rpc=rpc))
    t.daemon = True
    t.start()

    t2 = threading.Thread(target=webserver,
                          kwargs=dict(host=host, port=webserver_port, rpc=rpc))
    t2.daemon = True
    t2.start()

    ipcserver(ipc_port, rpc)
Exemplo n.º 5
0
 def do_POST(self):
     content_length = int(self.headers['Content-Length'])
     post_data = self.rfile.read(content_length)
     data = Rpc().handle(post_data.decode('utf-8'))
     response = self.handle_request(data)
     self._set_response()
     self.wfile.write(
         json.dumps(response, indent=4, sort_keys=True).encode('utf-8'))
	def processrequest(self, data):
		"""
		Forward the received message to the requestScanner
		and returns its reply

		@type  data: string
		@param data: The message received from the client socket
		@rtype: string
		@return: The serialized XML reply to be sent back to the Netconf Manager
		"""
		
		self.netconfLock.acquire()

		try:
			# try to build the DOM, checking well-formness
			# http://madynes.loria.fr is there to avoid a warning...
			doc = NonvalidatingReader.parseString(data, 'http://madynes.loria.fr')
			
			# XML Schema validation
			#self.valid = util.validate(data,[C.NETCONF_SCHEMA_URI])

			mainNode = doc.documentElement
			if mainNode.tagName == C.RPC:
				rpcRequest = Rpc(mainNode, self.session)
				response = rpcRequest.execute()
			elif mainNode.tagName == C.HELLO:
				response =''
			else:
				moduleReply = ModuleReply(
				error_type=ModuleReply.PROTOCOL,
				error_tag=ModuleReply.UNKNOWN_ELEMENT,
				error_severity=ModuleReply.ERROR,
				error_message = "An element is not known. It should be an rpc or hello tag.")
				moduleReply.addErrorInfo("bad-element",mainNode.tagName)
				nodeReply = moduleReply.getXMLNodeReply()
				response = util.convertNodeToString(nodeReply)

		except Exception,exp:
			moduleReply = ModuleReply(
			error_type=ModuleReply.PROTOCOL,
			error_tag=ModuleReply.UNKNOWN_ELEMENT,
			error_severity=ModuleReply.ERROR,
			error_message="The Netconf message is not well-formed."+str(exp))
			nodeReply = moduleReply.getXMLNodeReply()
			response = util.convertNodeToString(nodeReply)
Exemplo n.º 7
0
def HeartbeatThread():
    while True:
	#print "yes world"
	vm_app = VMWorkerApp()
	hb_app_info = VM_HbAppInfo()
	hb_app_info = vm_app.GetHbAppState()
	if hb_app_info.state == AppState.APP_ONLINE:
		app_running = True
	else:
		app_running = False
	
	job_id_str = VMWorkerConfigI.Instance().Get('job_id')
	task_id_str = VMWorkerConfigI.Instance().Get('task_id')
	job_id = string.atoi(job_id_str)
	task_id = string.atoi(task_id_str)
	
	interface = VMWorkerConfigI.Instance().Get('interface')
	worker_endpoint = VMWorkerConfigI.Instance().Get('worker_endpoint')
	hb_interval_str = VMWorkerConfigI.Instance().Get('heartbeat_interval')
	hb_interval = string.atoi(hb_interval_str)
	
	hb_vm_info = VM_HbVMInfo()
	hb_vm_info.job_id = job_id
	hb_vm_info.task_id = task_id
        tool = Tool()
        hb_vm_info.cpu_usage = tool.GetCpuUsage()
        hb_vm_info.memory_usage = tool.GetMemoryUsage()
	hb_vm_info.bytes_in = tool.GetInNetUsage(interface) 
	hb_vm_info.bytes_out = tool.GetOutNetUsage(interface) 
        hb_vm_info.state = VMState.VM_SERVICE_ONLINE
        hb_vm_info.app_running = app_running 
	hb_vm_info.hb_app_info = hb_app_info
	try :
		worker_client = Rpc(T = Client).GetProxy(worker_endpoint) 
                worker_client.sendheartbeat(hb_vm_info)
	except TTransportException, e:
		logger.error(e)
		time.sleep(2)
		continue
	time.sleep(hb_interval)
Exemplo n.º 8
0
def main():
    global rust_bindings
    global rpc

    random.seed()  # WARNING: seed based on time. Not crypto secure.

    args = parse_args()

    rust_bindings = RustBindings(args.lib_dir)
    rpc = Rpc(rust_bindings, host2ip(args.host), args.rpc_port, args.team_id,
              args.token)

    if args.action == 'run':
        run(args)
    elif args.action == 'train':
        train(args)
    elif args.action == 'flags':
        show_flags(args)
Exemplo n.º 9
0
    def rpc_call(self, environment):
        if self.get_configuration().get_entry("core.debug") == True:
            self.environment = environment

        if environment.has_key("HTTP_COOKIE"):
            session_manager = self.get_session_manager()
            session_manager.set_current_session(
                session_manager.get_session(environment['HTTP_COOKIE']))

        try:
            request_body_size = int(environment.get('CONTENT_LENGTH', 0))
        except (ValueError):
            request_body_size = 0
        request_body = environment['wsgi.input'].read(request_body_size)

        rpc = Rpc(self)
        rpc(request_body)

        return {"body": self.response_body, "header": self.response_header}
Exemplo n.º 10
0
 def do_rpc_call(self, args):
     rpc = Rpc()
     ret = rpc.call_rpc(int(args))
Exemplo n.º 11
0
 def do_rpc_server_start(self, args):
     rpc = Rpc()
     rpc.start_server()
Exemplo n.º 12
0
def job_add(request):
    form = JobSubmit()
    dic = {'form': form}
    if request.method == "POST":
        form = JobSubmit(request.POST, request.FILES)
        if form.is_valid():
            cpunum = form.cleaned_data["cpunum"]
            mem = form.cleaned_data["mem"]
            priority = form.cleaned_data["medium"]
            way = form.cleaned_data["way"]
            appname = form.cleaned_data["appname"]
            imgsize = form.cleaned_data["imglar"]
            system = form.cleaned_data["system"]
            timeout = form.cleaned_data["timeout"]

            repla_file = "./xml_file/submit_job_model.xml"
            temp = os.path.splitext(repla_file)[0] + ".tmp"
            #return HttpResponse('hello')
            fi = open(repla_file, "r")
            fo = open(temp, "w")
            s = fi.read()
            s = string.replace(s, "T_CPU", cpunum)
            s = string.replace(s, "T_MEMORY", mem)
            s = string.replace(s, "APP_NAME", appname)
            s = string.replace(s, "T_PRIORITY", priority)
            s = string.replace(s, "T_SCHED_MODEL", way)
            img_name = system + ".qcow2"
            s = string.replace(s, "T_IMG", img_name)
            s = string.replace(s, "T_TIME", timeout)
            fo.write(s)
            fi.close()
            fo.close()

            f_tmp = open(temp, "a")
            f = request.FILES['content']
            de_name = f.name.encode('UTF-8')
            file_name = str(de_name)
            lines = f.readlines()
            task_str = "<tasks>\n"
            for line in lines:
                if line == '\n':
                    continue
                line = string.replace(line, "\n", "")
                task_str = task_str + "<task>\n"
                task_str = task_str + "<exe_path>" + line + "</exe_path>\n"
                task_str = task_str + "<task_num>1</task_num>\n"
                task_str = task_str + "</task>\n"
            task_str = task_str + "</tasks>\n</job>"
            f_tmp.write(task_str)
            f_tmp.close()

            file_obj = open(temp, "r")
            file_string = file_obj.read()
            file_obj.close()
            result = SubmitJobResult()
            try:
                jobs_manager_client = Rpc(
                    T=Client).GetProxy(jobs_manager_endpoint)
                result = jobs_manager_client.SubmitJob(file_string)
            except TTransportException, e:
                logger.error(e)
                return HttpResponse('submit job error')
            return HttpResponseRedirect(
                reverse("service.views.task_state_info_list"))
Exemplo n.º 13
0
class Server():
    def __init__(self):
        pass

    def Task_test(self):
        global task_state_info_list
        task_state_info_list = []
        task1 = TaskStateInfo()
        task1.job_id = 0
        task1.task_id = 0
        task1.state = "测试"
        task1.machine_ip = "0.0.0.0"
        task1.restart_times = 0
        task1.timeout_times = 0
        task_state_info_list.append(task1)

        task2 = TaskStateInfo()
        task2.job_id = 0
        task2.task_id = 1
        task2.state = "测试"
        task2.machine_ip = "0.0.0.0"
        task2.restart_times = 0
        task2.timeout_times = 0
        task_state_info_list.append(task2)
        return True

    # task state info update
    def UpdateTaskStateInfo(self):
        job_id_list = []
        try:
            jobs_manager_client = Rpc(T=Client).GetProxy(jobs_manager_endpoint)
            job_id_list = jobs_manager_client.GetJobId()
        except TTransportException, e:
            return False
        global task_state_info_list
        task_state_info_list = []
        for job_id in job_id_list:
            try:
                jobs_manager_client = Rpc(
                    T=Client).GetProxy(jobs_manager_endpoint)
                task_state_info = jobs_manager_client.GetTaskStateInfo(job_id)
            except TTransportException, e:
                return False
            for task in task_state_info:
                if task.state == 0:
                    str(task.state)
                    task.state = "排队"
                elif task.state == 1:
                    str(task.state)
                    task.state = "启动中"
                elif task.state == 2:
                    str(task.state)
                    task.state = "运行"
                elif task.state == 3:
                    str(task.state)
                    task.state = "完成"
                elif task.state == 4:
                    str(task.state)
                    task.state = "失败"
                elif task.state == 5:
                    str(task.state)
                    task.state = "失联"
                else:
                    str(task.state)
                    task.state = "未发现"

                task_state_info_list.append(task)
Exemplo n.º 14
0
    def handle_request(self, data):
        response = Rpc().dead()
        if "error" not in data:
            if data["method"] == "blockchain.address.bake":
                if len(data["params"]) == 2 and data["params"][1].isnumeric():
                    response = Rpc().create(
                        Seed(data["params"][0], int(data["params"][1])).new(),
                        data["id"])

            if data["method"] == "blockchain.address.hash":
                if len(data["params"]) == 2 and data["params"][1].isnumeric():
                    response = Rpc().create(
                        Seed(data["params"][0], int(data["params"][1])).hash(),
                        data["id"])

            elif data["method"] == "blockchain.transaction.create":
                result = {}
                if len(data["params"]) >= 3 and len(
                        data["params"][0]) in (51, 52) and len(
                            data["params"][1]) == 34 and is_float(
                                data["params"][2]):
                    outputs = [(data["params"][1], float(data["params"][2]))]
                    tx_fee = to_satoshis(float(data["params"][3])) if len(
                        data["params"]) == 4 and is_float(
                            data["params"][3]) else 1000

                    try:
                        key = Key(data["params"][0])
                    except Exception as e:
                        result["error"] = str(e)

                    if "error" not in result:
                        try:
                            result = key.new_tx(outputs,
                                                fee=tx_fee,
                                                absolute_fee=True)
                        except Exception as e:
                            result["error"] = str(e)

                    response = Rpc().create(result, data["id"])

            elif data["method"] == "blockchain.transaction.batch":
                result = {}
                if len(data["params"]) >= 3 and len(
                        data["params"][0]) in (51, 52):
                    addresses = data["params"][1].split(',')
                    amounts = data["params"][2].split(',')

                    if len(addresses) == len(amounts):
                        outputs = []
                        for index, address in enumerate(addresses):
                            if len(address) == 34 and is_float(amounts[index]):
                                outputs.append(
                                    (address, float(amounts[index])))
                            else:
                                result["error"] = "Invalid address or amount"

                        if "error" not in result:
                            tx_fee = to_satoshis(float(
                                data["params"][3])) if len(
                                    data["params"]) == 4 and is_float(
                                        data["params"][3]) else 10000

                            try:
                                key = Key(data["params"][0])
                            except Exception as e:
                                result["error"] = str(e)

                            if "error" not in result:
                                try:
                                    result = key.new_tx(outputs,
                                                        fee=tx_fee,
                                                        absolute_fee=True)
                                except Exception as e:
                                    result["error"] = str(e)

                    else:
                        result["error"] = "Addresses and amounts must match"

                    response = Rpc().create(result, data["id"])

        return response
Exemplo n.º 15
0
        if not CALLBACK_WHITELIST:
            print("Error found in .env: invalid CALLBACK_WHITELIST config")
    except:
        print("Error found in .env: invalid CALLBACK_WHITELIST config")
        sys.exit(0)
DEBUG_MODE = True if int(os.getenv('DEBUG', 1)) != 0 else False

CALLBACK_TOKEN = os.getenv("CALLBACK_TOKEN", '')
if len(CALLBACK_TOKEN) != 43:
    print("Error found in .env: CALLBACK_TOKEN is missing or invalid, you can use 'python3 rai_wallet_server.py -t' to generate a secure token")
    sys.exit(0)

CHECK_CF_CONNECTING_IP = True if int(os.getenv('USE_CLOUDFLARE', 0)) == 1 else False

LOOP = asyncio.get_event_loop()
RPC = Rpc(NODE_URL)
UTIL = Util(CHECK_CF_CONNECTING_IP)
    
def websocket_rate_limit(r : web.Request, ws : web.WebSocketResponse):
    if LIMIT == 0:
        return False
    burst_max = LIMIT * 100
    pps = LIMIT
    ip = UTIL.get_request_ip(r)
    now = int(time.time())
    if ip not in r.app['limit']:
        r.app['limit'][ip] = {'count':burst_max, 'ts':now}
    else:
        if r.app['limit'][ip]['ts'] < now:
            r.app['limit'][ip]['count'] += (now - r.app['limit'][ip]['ts']) * pps
            r.app['limit'][ip]['ts'] = now
Exemplo n.º 16
0
 def rpc(self):
     from rpc import Rpc
     return Rpc(self)
Exemplo n.º 17
0
 def do_GET(self):
     data = Rpc().handle(parse.urlparse(self.path).query)
     response = self.handle_request(data)
     self._set_response()
     self.wfile.write(
         json.dumps(response, indent=4, sort_keys=True).encode('utf-8'))