def __getitem__(self, item): if item == '.arvados#collection': if self.collection_record_file is None: self.collection_record_file = FuncToJSONFile( self.inode, self.collection_record) self.inodes.add_entry(self.collection_record_file) return self.collection_record_file return super(TmpCollectionDirectory, self).__getitem__(item)
class TmpCollectionDirectory(CollectionDirectoryBase): """A directory backed by an Arvados collection that never gets saved. This supports using Keep as scratch space. A userspace program can read the .arvados#collection file to get a current manifest in order to save a snapshot of the scratch data or use it as a crunch job output. """ class UnsaveableCollection(arvados.collection.Collection): def save(self): pass def save_new(self): pass def __init__(self, parent_inode, inodes, api_client, num_retries): collection = self.UnsaveableCollection( api_client=api_client, keep_client=api_client.keep, num_retries=num_retries) super(TmpCollectionDirectory, self).__init__( parent_inode, inodes, collection) self.collection_record_file = None self.populate(self.mtime()) def on_event(self, *args, **kwargs): super(TmpCollectionDirectory, self).on_event(*args, **kwargs) if self.collection_record_file: with llfuse.lock: self.collection_record_file.invalidate() self.inodes.invalidate_inode(self.collection_record_file) _logger.debug("%s invalidated collection record", self) def collection_record(self): with llfuse.lock_released: return { "uuid": None, "manifest_text": self.collection.manifest_text(), "portable_data_hash": self.collection.portable_data_hash(), } def __contains__(self, k): return (k == '.arvados#collection' or super(TmpCollectionDirectory, self).__contains__(k)) @use_counter def __getitem__(self, item): if item == '.arvados#collection': if self.collection_record_file is None: self.collection_record_file = FuncToJSONFile( self.inode, self.collection_record) self.inodes.add_entry(self.collection_record_file) return self.collection_record_file return super(TmpCollectionDirectory, self).__getitem__(item) def persisted(self): return False def writable(self): return True def want_event_subscribe(self): return False def finalize(self): self.collection.stop_threads() def invalidate(self): if self.collection_record_file: self.collection_record_file.invalidate() super(TmpCollectionDirectory, self).invalidate()