示例#1
0
    def _connect_to_orb(self):
        """Update internal state tracking and close/open an orb connection.

        Wrapper of dubious necessity around orb.close and orb.connect().

        Raises:
            antelope.orb.OrbError: if an orb connection can't be made for any reason
        """

        self.logger.debug("start connection to orb: %s" % (self.orbname))

        # If previous state then we close first and reconnect
        if self.orb["status"]:
            self.close_orb()

        # Now open new connection and save values in object
        self.logger.debug("connect to orb(%s)" % self.orbname)
        self.orb["orb"] = orb.Orb(self.orbname, permissions="w")
        self.orb["orb"].connect()
        self.orb["orb"].stashselect(orb.NO_STASH)

        self.logger.debug("ping orb: %s" % (self.orb["orb"]))

        if not self._test_orb():
            raise Exception("Problems connecting to (%s)" % self.orbname)
示例#2
0
    def _get_orb_data(self):
        """Retrieve data from the orbs.

        Look into every ORB listed on the parameter file
        and get some information from them.
        1) The clients of the ORB (not using this now)
        2) List of sources.

        Then we track the time of every packet type that
        we see for every station.
        """

        self.logger.debug("Updat ORB cache")

        self.logger.debug(self.orbservers)

        for orbname in self.orbservers:
            if not orbname or not isinstance(orbname, str):
                continue
            self.logger.debug("init ORB %s" % (orbname))

            # Expand the object if needed
            if orbname not in self.orbs:
                self.orbs[orbname] = {}
                self.logger.debug("orb.Orb(%s)" % (orbname))
                self.orbs[orbname]["orb"] = orb.Orb(orbname)

            # Clean all local info related to this ORB
            self.orbs[orbname]["clients"] = {}
            self.orbs[orbname]["sources"] = {}
            self.orbs[orbname]["info"] = {
                "status": "offline",
                "last_check": 0,
            }

            try:
                self.logger.debug("connect to orb(%s)" % orbname)
                self.orbs[orbname]["orb"].connect()
                self.orbs[orbname]["orb"].stashselect(orb.NO_STASH)
            except Exception as e:
                raise metadataException("Cannot connect to ORB: %s %s" % (orbname, e))

            # Extract the information
            self._get_orb_sta_latency(orbname)
            self._get_orb_sta_inp(orbname)

            self.orbs[orbname]["orb"].close()
示例#3
0
    def _connect_to_orb(self):
        self.logging.debug("start connection to orb: %s" % (self.orbname))
        if self.orb["status"] and self.orb["orb"] is not None:
            try:
                self.logging.debug("close orb connection %s" % (self.orbname))
                self.orb["orb"].close()
            except Exception:
                self.logging.exception("orb.close(%s) failed" % self.orbname)
                pass

        try:
            self.logging.debug("connect to orb(%s)" % self.orbname)
            self.orb["orb"] = orb.Orb(self.orbname)
            self.orb["orb"].connect()
            self.orb["orb"].stashselect(orb.NO_STASH)
        except Exception as e:
            raise OrbConnectError(self.orbname, e)

        if self.position:
            try:
                self.orb["orb"].position("p%s" % int(self.position))
                self.logging.debug("position orb on pckt: %s" %
                                   (self.position))
            except orb.OrbException:
                self.orb["orb"].position(self.default_orb_read)
                self.logging.debug("default_orb_read: %s" %
                                   (self.default_orb_read))

        if self.orb_select:
            self.logging.debug("orb.select(%s)" % self.orb_select)
            if not self.orb["orb"].select(self.orb_select):
                raise OrbSelectException(self.orb["orb"], self.orb_select)

        if self.orb_reject:
            self.logging.debug("orb.reject(%s)" % self.orb_reject)
            if not self.orb["orb"].reject(self.orb_reject):
                raise OrbRejectException(self.orb["orb"], self.orb_reject)

        self.logging.debug("ping orb: %s" % (self.orb["orb"]))
        try:
            self.logging.debug("orb position: %s" % (self.orb["orb"].tell()))
        except orb.OrbException:
            self.logging.debug("orb position: NONE")
示例#4
0
文件: soh.py 项目: geoffdavis/anfsrc
    def _connect_to_orb(self):
        """Connect or reconnect to a given orbserver."""
        self.logger.debug("start connection to orb: %s" % (self.orbname))
        if self.orb["status"]:
            try:
                self.logger.debug("close orb connection %s" % (self.orbname))
                self.orb["orb"].close()
            except Exception:
                pass

        try:
            self.logger.debug("connect to orb(%s)" % self.orbname)
            self.orb["orb"] = orb.Orb(self.orbname)
            self.orb["orb"].connect()
            self.orb["orb"].stashselect(orb.NO_STASH)
        except Exception as e:
            raise Exception("Cannot connect to ORB: %s %s" % (self.orbname, e))

        # self.logger.info( self.orb['orb'].stat() )

        if self.orb_select:
            self.logger.debug("orb.select(%s)" % self.orb_select)
            if not self.orb["orb"].select(self.orb_select):
                raise Exception("NOTHING LEFT AFTER orb.select(%s)" %
                                self.orb_select)

        if self.orb_reject:
            self.logger.debug("orb.reject(%s)" % self.orb_reject)
            if not self.orb["orb"].reject(self.orb_reject):
                raise Exception("NOTHING LEFT AFTER orb.reject(%s)" %
                                self.orb_reject)

        self.logger.debug("ping orb: %s" % (self.orb["orb"]))

        try:
            if int(self.position) > 0:
                self.logger.info("Go to orb position: %s" % (self.position))
                self.orb["orb"].position("p%d" % int(self.position))
            else:
                raise
        except Exception:
            try:
                self.logger.info("Go to orb default position: %s" %
                                 (self.default_orb_read))
                self.orb["orb"].position(self.default_orb_read)
            except Exception as e:
                self.logger.error("orb.position: %s, %s" % (Exception, e))

        try:
            self.logger.info("orb.tell()")
            self.logger.info(self.orb["orb"].tell())
        except orb.OrbTellError:
            self.logger.info("orb.seek( orb.ORBOLDEST )")
            # self.logger.info( self.orb['orb'].seek( orb.ORBOLDEST ) )
            self.logger.info(self.orb["orb"].after(0))
        except Exception as e:
            self.logger.error("orb.tell() => %s, %s" % (Exception, e))

        # try:
        #    self.logger.debug( "orb position: %s" % (self.orb['orb'].tell()) )
        # except Exception,e:
        #    self.orb['orb'].after(0)
        #    self.orb['orb'].position(self.default_orb_read)
        #    try:
        #        self.logger.debug( "orb position: %s" % (self.orb['orb'].tell()) )
        #    except Exception,e:
        #        self.logger.error( "orb position: %s,%s" % (Exception,e) )

        if not self._test_orb():
            raise Exception("Problems connecting to (%s)" % self.orbname)
示例#5
0
    def _get_orb_data(self, orbname):
        """Read dataloggers from an orb.

        Look into every ORB listed on configuration
        and get list of dataloggers.

        Args:
            orbname (string): name:port of the orbserver to check
        """

        self.logger.debug(orbname)
        self.logger.debug("Read STASH_ONLY on %s" % orbname)

        if not orbname or not isinstance(orbname, str):
            self.logger.warning("Not valid: %s" % (orbname))
            return

        self.logger.debug("%s" % (orbname))

        temp_orb = orb.Orb(orbname)

        try:
            self.logger.debug("connect to orb(%s)" % orbname)
            temp_orb.connect()
            temp_orb.stashselect(orb.STASH_ONLY)

        except Exception as e:
            self.logger.error("Cannot connect to ORB: %s %s" % (orbname, e))
            raise (e)

        temp_orb.select(self.orb_select)
        temp_orb.reject(self.orb_reject)

        self.logger.debug("orb.after(0.0)")
        temp_orb.after(0.0)  # or orb.ORBOLDEST

        try:
            sources = temp_orb.sources()[1]
        except Exception:
            sources = []

        self.logger.debug(sources)

        for source in sources:
            srcname = source["srcname"]
            self.logger.debug("source: %s" % srcname)

            # Get stash for each source
            try:
                pkttime, pktbuf = temp_orb.getstash(srcname)

            except orb.OrbGetStashError:
                self.logger.debug("Couldn't read stash packet from " + srcname)
                pass

            else:
                self._decode_dataloggers_from_pktbuf(srcname, pktbuf)

        try:
            self.logger.debug("close orb(%s)" % orbname)
            temp_orb.close()
        except orb.OrbError:
            pass