Beispiel #1
0
    def __init__(self, url, client=None, timeout=20):
        if client is None:
            client = Client()
            client.vk = client.setEntityFromEnviron()
            client.overrideAutoChainTo(True)
        if not isinstance(client, Client):
            raise TypeError(
                "first argument must be bw2python.client.Client or None")
        self.c = client
        self.vk = client.vk
        self.url = url

        responses = self.c.query("{0}/*/s.hod/!meta/lastalive".format(url))
        for resp in responses:
            # get the metadata records from the response
            md_records = filter(
                lambda po: po.type_dotted == ponames.PODFSMetadata,
                resp.payload_objects)
            # get timestamp field from the first metadata record
            last_seen_timestamp = msgpack.unpackb(
                md_records[0].content).get('ts')
            # get how long ago that was
            now = time.time() * 1e9  # nanoseconds
            # convert to microseconds and get the timedelta
            diff = timedelta(microseconds=(now - last_seen_timestamp) / 1e3)
            print "Saw [{0}] HodDB {1}".format(self.url,
                                               pretty_print_timedelta(diff))
            if diff.total_seconds() > timeout:
                raise TimeoutException("HodDB at {0} is too old".format(
                    self.url))
Beispiel #2
0
    def __init__(self, client=None, archivers=None):
        """
        Creates a BW2 Data client

        Arguments:
        [client]: if this is None, we use environment vars to configure a client
                  automatically; else, we use the client provided
        [archivers]: this is a list of base archiver URIs. These can be found by
                  running "pundat scan <namespace>"
        """
        # bw2 client
        if client is None:
            client = Client()
            client.vk = client.setEntityFromEnviron()
            client.overrideAutoChainTo(True)
        if not isinstance(client, Client):
            raise TypeError(
                "first argument must be bw2python.client.Client or None")
        self.c = client
        self.vk = client.vk

        if archivers is None:
            archivers = ["ucberkeley"]  # default archiver
        self.archivers = []
        # scan for archiver liveness
        for archiver in archivers:
            responses = self.c.query(
                "{0}/*/s.giles/!meta/lastalive".format(archiver))
            for resp in responses:
                # get the metadata records from the response
                md_records = filter(
                    lambda po: po.type_dotted == ponames.PODFSMetadata,
                    resp.payload_objects)
                # get timestamp field from the first metadata record
                last_seen_timestamp = msgpack.unpackb(
                    md_records[0].content).get('ts')
                # get how long ago that was
                now = time.time() * 1e9  # nanoseconds
                # convert to microseconds and get the timedelta
                diff = timedelta(microseconds=(now - last_seen_timestamp) /
                                 1e3)
                print "Saw [{0}] archiver {1}".format(
                    archiver, pretty_print_timedelta(diff))
                if diff.total_seconds() < 20:
                    self.archivers.append(archiver)
        if len(self.archivers) == 0:
            self.archivers = archivers
Beispiel #3
0
    def __init__(self, url, client=None, timeout=30):
        """
        Creates an MDAL client.

        Arguments:
        [url]: the BOSSWAVE uri where mdal is hosted
        [client]: if this is None, we use environment vars to configure a client
                  automatically; else, we use the client provided from bw2python
        """
        if client is None:
            client = Client()
            client.vk = client.setEntityFromEnviron()
            client.overrideAutoChainTo(True)
        if not isinstance(client, Client):
            raise TypeError(
                "first argument must be bw2python.client.Client or None")
        self.c = client
        self.vk = client.vk
        self.url = url

        # check liveness
        responses = self.c.query("{0}/*/s.mdal/!meta/lastalive".format(url))
        for resp in responses:
            # get the metadata records from the response
            md_records = filter(
                lambda po: po.type_dotted == ponames.PODFSMetadata,
                resp.payload_objects)
            # get timestamp field from the first metadata record
            last_seen_timestamp = msgpack.unpackb(
                md_records[0].content).get('ts')
            # get how long ago that was
            now = time.time() * 1e9  # nanoseconds
            # convert to microseconds and get the timedelta
            diff = timedelta(microseconds=(now - last_seen_timestamp) / 1e3)
            print "Saw [{0}] MDAL {1}".format(self.url,
                                              pretty_print_timedelta(diff))
            if diff.total_seconds() > timeout:
                raise TimeoutException("MDAL at {0} is too old".format(
                    self.url))