func (s *StorageSuite) SetUpTest(c *gc.C) { s.BaseSuite.SetUpTest(c) s.MgoSuite.SetUpTest(c) rs := blobstore.NewGridFS("blobstore", testUUID, s.Session) db := s.Session.DB("juju") s.managedStorage = blobstore.NewManagedStorage(db, rs) s.storage = storage.NewStorage(testUUID, s.Session) }
// ToolsStorage returns a new toolstorage.StorageCloser // that stores tools metadata in the "juju" database'' // "toolsmetadata" collection. // // TODO(axw) remove this, add a constructor function in toolstorage. func (st *State) ToolsStorage() (toolstorage.StorageCloser, error) { uuid := st.EnvironUUID() session := st.db.Session.Copy() txnRunner := st.txnRunner(session) rs := blobstore.NewGridFS(blobstoreDB, uuid, session) db := st.db.With(session) managedStorage := blobstore.NewManagedStorage(db, rs) metadataCollection := st.db.With(session).C(toolsmetadataC) storage := toolstorageNewStorage(uuid, managedStorage, metadataCollection, txnRunner) return &toolsStorageCloser{storage, session}, nil }
// ToolsStorage returns a new toolstorage.StorageCloser // that stores tools metadata in the "juju" database'' // "toolsmetadata" collection. // // TODO(axw) remove this, add a constructor function in toolstorage. func (st *State) ToolsStorage() (toolstorage.StorageCloser, error) { uuid := st.EnvironUUID() session := st.session.Copy() rs := blobstore.NewGridFS(blobstoreDB, uuid, session) db := session.DB(jujuDB) metadataCollection := db.C(toolsmetadataC) txnRunner := jujutxn.NewRunner(jujutxn.RunnerParams{Database: db}) managedStorage := blobstore.NewManagedStorage(db, rs) storage := toolstorageNewStorage(uuid, managedStorage, metadataCollection, txnRunner) return &toolsStorageCloser{storage, session}, nil }
func (s *managedStorageSuite) SetUpTest(c *gc.C) { s.IsolationSuite.SetUpTest(c) s.MgoSuite.SetUpTest(c) s.db = s.Session.DB("blobstore") s.resourceStorage = blobstore.NewGridFS("storage", "test", s.Session) s.managedStorage = blobstore.NewManagedStorage(s.db, s.resourceStorage) // For testing, we need to ensure there's a single txnRunner for all operations. s.txnRunner = jujutxn.NewRunner(jujutxn.RunnerParams{Database: s.db}) txnRunnerFunc := func(db *mgo.Database) jujutxn.Runner { return s.txnRunner } s.PatchValue(blobstore.TxnRunner, txnRunnerFunc) }
func (s *ToolsSuite) SetUpTest(c *gc.C) { s.BaseSuite.SetUpTest(c) s.mongo = &gitjujutesting.MgoInstance{} s.mongo.Start(nil) var err error s.session, err = s.mongo.Dial() c.Assert(err, jc.ErrorIsNil) rs := blobstore.NewGridFS("blobstore", "my-uuid", s.session) catalogue := s.session.DB("catalogue") s.managedStorage = blobstore.NewManagedStorage(catalogue, rs) s.metadataCollection = catalogue.C("toolsmetadata") s.txnRunner = jujutxn.NewRunner(jujutxn.RunnerParams{Database: catalogue}) s.storage = toolstorage.NewStorage("my-uuid", s.managedStorage, s.metadataCollection, s.txnRunner) }
func (s stateStorage) blobstore() (*mgo.Session, blobstore.ManagedStorage) { session := s.session.Copy() rs := blobstore.NewGridFS(blobstoreDB, s.envUUID, session) db := session.DB(metadataDB) return session, blobstore.NewManagedStorage(db, rs) }
) Storage { blobDb := session.DB(ImagesDB) metadataCollection := blobDb.C(imagemetadataC) return &imageStorage{ envUUID, metadataCollection, blobDb, } } // Override for testing. var getManagedStorage = func(session *mgo.Session) blobstore.ManagedStorage { rs := blobstore.NewGridFS(ImagesDB, ImagesDB, session) db := session.DB(ImagesDB) metadataDb := db.With(session) return blobstore.NewManagedStorage(metadataDb, rs) } func (s *imageStorage) getManagedStorage(session *mgo.Session) blobstore.ManagedStorage { return getManagedStorage(session) } func (s *imageStorage) txnRunner(session *mgo.Session) jujutxn.Runner { db := s.metadataCollection.Database runnerDb := db.With(session) return txnRunner(runnerDb) } // Override for testing. var txnRunner = func(db *mgo.Database) jujutxn.Runner { return jujutxn.NewRunner(jujutxn.RunnerParams{Database: db})
// blobStorage returns a ManagedStorage matching the env storage and the blobDB. func (b *storageDBWrapper) blobStorage(blobDB string) blobstore.ManagedStorage { dataStore := blobstore.NewGridFS(blobDB, b.envUUID, b.session) return blobstore.NewManagedStorage(b.db, dataStore) }
// ManagedStorage returns the managedStorage attribute for the storage. func ManagedStorage(s Storage, session *mgo.Session) blobstore.ManagedStorage { return s.(*imageStorage).getManagedStorage(session) } // MetadataCollection returns the metadataCollection attribute for the storage. func MetadataCollection(s Storage) *mgo.Collection { return s.(*imageStorage).metadataCollection } // RemoveFailsManagedStorage returns a patched managedStorage, // which fails when Remove is called. var RemoveFailsManagedStorage = func(session *mgo.Session) blobstore.ManagedStorage { rs := blobstore.NewGridFS(ImagesDB, ImagesDB, session) db := session.DB(ImagesDB) metadataDb := db.With(session) return removeFailsManagedStorage{blobstore.NewManagedStorage(metadataDb, rs)} } type removeFailsManagedStorage struct { blobstore.ManagedStorage } func (removeFailsManagedStorage) RemoveForEnvironment(uuid, path string) error { return errors.Errorf("cannot remove %s:%s", uuid, path) } var TxnRunner = &txnRunner var GetManagedStorage = &getManagedStorage
// getManagedStorage returns a blobstore.ManagedStorage, and an associated // mgo.Session that must be closed when the user is finished with the // ManagedStorage. func (st *State) getManagedStorage(uuid string, session *mgo.Session) blobstore.ManagedStorage { rs := blobstore.NewGridFS(blobstoreDB, uuid, session) db := st.db.With(session) return blobstore.NewManagedStorage(db, rs) }