def call_scheduler_api(path, params): host = "127.0.0.1" port = 9000 base_url = "http://%s:%d/api" % (host, port) resp = requests.post( os.path.join(base_url, path), data=json.dumps(params), timeout=60) return json.loads(resp.content)
def call(self, path, params=None, timeout=60): if params is None: params = {} try: resp = requests.post( os.path.join(self.base_url, path), data=json.dumps(params), headers={ "AGENT_AUTH_TOKEN": "+tIs3U\>o@3`@4<-DR:ll'Bu590y(#]ACu2jlr(S.BDiO]]FLVubQcZP+?avBFM" }, timeout=timeout) except requests.exceptions.ConnectionError, requests.exceptions.Timeout: raise ConnectionError
def save(self, **updates): root = self.root path = self.path with root.lock: root.zk_ensure_path(path) if self.schema is not None: # update a copy of our data data = self.data.immutable_update(updates) # make sure the updated copy validates data = self.validate_data(data) # save to zookeeper bdata = bytes(json.dumps(data)) root.zk_set(path, bdata) # save self.data = data return self
def _write_json(self, data): data = json.dumps(data) self.write(data + "\n")