コード例 #1
0
    def touch(rt, name, fqdn, gps):
        rcount = 0
        while True:
            time.sleep(settings.UPDATE_INTERVAL)
            try:
                (lat, lon) = gps.query()
                if lat and lon:
                    n.location.latitude = lat
                    n.location.longitude = lon
                    rt.flush()
                s.touch()

            except (ConnectionError, TimeoutError) as exp:
                #import traceback
                #traceback.print_exc()
                log.error(
                    "Could not update node/service resources: {}".format(exp))
                if rcount >= settings.RETRY_COUNT:
                    slock.acquire()
                    rt.delete(s)
                    do_register(rt, name, fqdn)
                    slock.release()
                    rcount = 0
                else:
                    rcount = rcount + 1
コード例 #2
0
 def _do_post(self, url, data):
     try:
         headers = {"Content-Type": "application/perfsonar+json"}
         requests.post(url, headers=headers, data=data)
     except Exception as e:
         log.error("Could not update node at {}: {}".format(url, e))
         raise e
コード例 #3
0
    def __init__(self, service, local_unis, wdir=UPLOAD_DIR):
        self.wdir = wdir

        try:
            self.observer = Observer()
            self.event_handler = Handler(service, local_unis)
            self.observer.schedule(self.event_handler,
                                   self.wdir,
                                   recursive=True)
            self.observer.start()
        except Exception as e:
            log.error("Could not start upload watcher: {} [{}]".format(
                e, self.wdir))
コード例 #4
0
def local_download(sess, exnodes):
    for f in exnodes:
        if not len(f.extents):
            continue
        fpath = os.path.join(DOWNLOAD_DIR, f.name)
        if os.path.exists(fpath) and os.path.getsize(fpath) == f.size:
            log.debug("File exists: {}, skipping!".format(f.name))
            continue
        log.info("Downloading: {} ({} bytes)".format(f.name, f.size))
        try:
            result = sess.download(f.selfRef, fpath)
            res, diff, dsize = result.exnode, result.time, result.t_size
        except Exception as e:
            log.error("Could not download file: {}".format(e))
            continue
        if dsize != res.size:
            log.warn("WARNING: {}: transferred {} of {} bytes \
            (check depot file)".format(res.name, dsize, res.size))
        else:
            log.info("{0} ({1} {2:.2f} MB/s) {3}".format(
                res.name, res.size, res.size / 1e6 / diff, res.selfRef))