def reset(self): """ tailf:action reset handling """ print("reset") when_value = self.params[0].v res = str(when_value) + "-result" result = [make_tag_value(ns.hash, ns.config_time, res)] dp.action_reply_values(self.uinfo, result)
def kick_me(self): """ tailf:action kick_me handling """ print("::: kick_me :::") sys.stdout.flush() params = self.params uinfo = self.uinfo result = [] dp.action_reply_values(self.uinfo, result)
def local_me(self): """ tailf:action local_me handling """ print("::: local_me :::") sys.stdout.flush() params = self.params uinfo = self.uinfo keypath = self.keypath print("location:", keypath) sys.stdout.flush() result = [] dp.action_reply_values(self.uinfo, result)
def exec_totals(self, uinfo): print('exec totals') key = get_thread_key(uinfo) print('[thr# ' + key + '] watch thread for abort request') thr = self.thread_map[key] # import pdb; pdb.set_trace() # open own MAAPI connection for reading values msock = socket.socket() maapi.connect(msock, CONFD_ADDR, _confd.CONFD_PORT) th = maapi.start_trans2(msock, _confd.RUNNING, _confd.READ, uinfo.usid) path = "/model:dm/proc" mc = maapi.init_cursor(msock, th, path) # gather data from ConfD cpu_sum = 0 cpu_cnt = 0 keys = maapi.get_next(mc) while not thr.stop_flag and keys is not False: cpu = maapi.get_elem(msock, th, path + '{' + str(keys[0]) + '}/cpu') cpu_sum += int(cpu) cpu_cnt += 1 keys = maapi.get_next(mc) # clean the used MAAPI session maapi.destroy_cursor(mc) maapi.close(msock) # and dispatch result to ConfD result = [ make_tag_value(ns.hash, ns.model_num_procs, int(cpu_cnt), _confd.C_UINT32), make_tag_value(ns.hash, ns.model_total_cpu, int(cpu_sum), _confd.C_UINT32) ] dp.action_reply_values(uinfo, result) return _confd.OK
def iter_me(self): """ tailf:action iter_me handling """ print("::: iter_me :::") sys.stdout.flush() params = self.params uinfo = self.uinfo # params[0] is mode id_value = str(params[0].v) path_value = str(params[1].v) tid_value = int(params[2].v) s = connect_maapi() maapi.attach2(s, 0, 0, tid_value) iterator = DiffIterator() maapi.diff_iterate(s, tid_value, iterator, 0) maapi.detach2(s, tid_value) result = [] dp.action_reply_values(uinfo, result)
def restart(self): """ tailf:action restart handling """ print("restart") params = self.params uinfo = self.uinfo # params[0] is mode mode_value = str(params[0].v) # if we get mode_value == error1, we reply with generic error if mode_value == "error1": return _confd.CONFD_ERR # if we get mode_value == error2, we reply with specific error if mode_value == "error2": dp.action_seterr(uinfo, "myfail") return _confd.CONFD_ERR # otherwise, we create a result string with mode-result-... res = mode_value + "-result" k = 1 n = len(params) while k < n: print("k:", k, "tag:", params[k].tag) if params[k].tag == ns.config_debug: res = res + "-debug" if params[k].tag == ns.config_foo: res = res + "-foo" if k + 1 < n: if params[k + 1].tag == ns.config_debug: res = res + "-debug" k += 1 k += 1 result = [make_tag_value(ns.hash, ns.config_time, res)] dp.action_reply_values(uinfo, result)
def exec_sleep(self, uinfo, params): print('exec sleep') key = get_thread_key(uinfo) print('[thr# ' + key + '] watch thread for abort request') if key in self.thread_map: thr = self.thread_map[key] else: print('Didn\'t find running thread info!') return _confd.ERR # params[0] is sleep time sleeptime = int(params[0].v) start = time.time() # set timeout to expected sleepy time + mini backup dp.action_set_timeout(uinfo, sleeptime + 3) slept = 0 while (not thr.stop_flag) and (slept < sleeptime): time.sleep(1) slept += 1 if thr.stop_flag: print('got interrupted after ' + str(slept) + " seconds") else: print('finished whole job') stop = time.time() result = [ make_tag_value(ns.hash, ns.model_slept, stop - start, _confd.C_UINT32) ] dp.action_reply_values(uinfo, result) return _confd.OK