Example #1
0
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)
Example #2
0
    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
Example #3
0
    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
Example #4
0
 def _write_json(self, data):
     data = json.dumps(data)
     self.write(data + "\n")