예제 #1
0
    def flush(self, deep=True):
        if self.is_dirty(deep):
            try:
                # package for storage
                insert_dict = {}
                for k in list(self._dirty):
                    v = getattr(self, k)
                    log.trace('FLUSH: key=%s  v=%s', k, v)
                    if isinstance(v, Dictable):
                        prefix='DICTABLE|{0}:{1}|'.format(v.__module__, v.__class__.__name__)
                        value = prefix + pack(v.dump())
                    elif k == 'brick_tree':
                        if hasattr(self, 'brick_tree') and isinstance(self.brick_tree, RTreeProxy):
                            val = self.brick_tree.serialize()
                            if val != '':
                                insert_dict['brick_tree'] = val
                            continue
                    elif k == 'parameter_metadata':
                        value = pack_parameter_manager_dict(v)
                    else:
                        value = pack(v)

                    insert_dict[k] = value

                    # Update the hash_value in _hmap
                    self._hmap[k] = hash_any(v)

                dirty_spans = self.span_collection.get_dirty_spans()
                if len(dirty_spans) > 0:
                    val = str(self.span_collection)
                    log.trace("Span tuple: %s", val)
                    value = pack(val)
                    insert_dict['span_collection'] = value


                DBFactory.get_db().insert(self.guid, insert_dict, dirty_spans)

                for span in dirty_spans:
                    span.is_dirty = False
                self._dirty.clear()

            except IOError, ex:
                if "unable to create file (File accessability: Unable to open file)" in ex.message:
                    log.info('Issue writing to hdf file during master_manager.flush - this is not likely a huge problem: %s', ex.message)
                else:
                    raise

            super(DbBackedMetadataManager, self).__setattr__('_is_dirty',False)
예제 #2
0
 def getCoverageType(directory, guid):
     cov_type = DBFactory.get_db().get_coverage_type(guid)
     if '' == cov_type:
         return ''
     else:
         cov_type = unpack(cov_type)
         return cov_type
예제 #3
0
    def _load(self):
        try:
            results = DBFactory.get_db().get(self.guid)
            for key in results:
                val = results[key]
                if isinstance(val, basestring) and val.startswith('DICTABLE'):
                    i = val.index('|', 9)
                    smod, sclass = val[9:i].split(':')
                    value = unpack(val[i+1:])
                    module = __import__(smod, fromlist=[sclass])
                    classobj = getattr(module, sclass)
                    value = classobj._fromdict(value)
                elif key in ('root_dir', 'file_path'):
                    # No op - set in constructor
                    continue
                elif key == 'brick_tree':
                    setattr(self, key, RTreeProxy.deserialize(val))
                    continue
                elif key == 'span_collection':
                    unpacked = unpack(val)
                    value = SpanCollectionByFile.from_str(unpacked)
                    log.trace("Reconstructed SpanCollection for %s: %s", self.guid, str(value))
                else:
                    value = unpack(val)

                if isinstance(value, tuple):
                    value = list(value)

                setattr(self, key, value)

        except Exception as e:
            log.error("Caught exception reconstructing metadata for guid %s : %s", self.guid, e.message)
            raise
예제 #4
0
 def getCoverageType(directory, guid):
     if DbBackedMetadataManager.is_persisted_in_db(guid) is True:
         cov_type = DBFactory.get_db().get_coverage_type(guid)
         if '' == cov_type:
             return ''
         else:
             cov_type = unpack(cov_type)
             return cov_type
     else:
         return BaseManager.getCoverageType(directory, guid)
예제 #5
0
 def isPersisted(directory, guid):
     return DBFactory.get_db().is_persisted(guid)
예제 #6
0
 def is_persisted_in_db(guid):
     return DBFactory.get_db().is_persisted(guid)
예제 #7
0
 def find(coverage_id, persistence_dir, db_name=None, limit=-1):
     db = DBFactory.get_db(db_name)
     rows = db.get(coverage_id)
     if len(rows) > 1:
         return AbstractCoverage.load(persistence_dir, persistence_guid=coverage_id, mode='r')
     return None