Class: FileStore::MultiTenantStoreFactory
- Inherits:
-
BaseFactory
- Object
- BaseFactory
- FileStore::MultiTenantStoreFactory
- Defined in:
- lib/filestore/factory.rb
Overview
MultiTenantFileStore factory class
Class Method Summary collapse
-
.create(base_path, observable = false, logger = StdoutLogger) ⇒ Object
Creates a multi tenant store instance.
-
.recover_tenant_stores(root_path, observable, logger) ⇒ Object
Recovers a multitenant store.
Class Method Details
.create(base_path, observable = false, logger = StdoutLogger) ⇒ Object
Creates a multi tenant store instance
Arguments:
base_path: The directory of the multitenant store
observable (optional): Determines wether this instance should support observation
logger (optional): The logging facility
Returns:
A new instance of MultiTenantStore
75 76 77 78 79 80 81 82 |
# File 'lib/filestore/factory.rb', line 75 def self.create(base_path, observable = false, logger = StdoutLogger) logger.debug "Creating new MultiTenantFileStore" multi_store = super MultiTenantFileStore, base_path, observable, logger multi_store.stores = MultiTenantStoreFactory::recover_tenant_stores(base_path, observable, logger) if File.exists?(base_path) return multi_store end |
.recover_tenant_stores(root_path, observable, logger) ⇒ Object
Recovers a multitenant store
Arguments:
rootPath: The base path of the multitenant store
logger (optional): The logging facility
Returns:
A hashset of file stores (with the user ID as key) recovered
from the given directory
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/filestore/factory.rb', line 95 def self.recover_tenant_stores(root_path, observable, logger) raise FileStoreException, "Root path #{rootPath} isn't a valid multitenant store" if not File.directory?(root_path) stores = {} logger.debug "Trying to recover tenant stores" Dir.glob(File.join(root_path, "*")).each do |e| begin if File.directory?(e) then tenant = File.basename(e) tenant_path = File.absolute_path e logger.debug "Restoring tenant store in directory #{tenant_path}" sfs = SimpleStoreFactory::create tenant_path, observable, logger stores[tenant] = sfs end rescue Exception => e logger.error "Couldn't create store for tenant #{tenant}.\n#{e}" end end return stores end |