Search in sources :

Example 1 with XodusStore

use of com.bakdata.conquery.io.storage.xodus.stores.XodusStore in project conquery by bakdata.

the class XodusStoreFactory method createStore.

public <KEY, VALUE> Store<KEY, VALUE> createStore(Environment environment, Validator validator, StoreMappings storeId, ObjectMapper objectMapper) {
    final StoreInfo<KEY, VALUE> storeInfo = storeId.storeInfo();
    synchronized (openStoresInEnv) {
        if (openStoresInEnv.get(environment).stream().map(XodusStore::getName).anyMatch(name -> storeInfo.getName().equals(name))) {
            throw new IllegalStateException("Attempted to open an already opened store:" + storeInfo.getName());
        }
        final XodusStore store = new XodusStore(environment, storeInfo.getName(), this::closeStore, this::removeStore);
        openStoresInEnv.put(environment, store);
        return new CachedStore<>(new SerializingStore<>(store, validator, objectMapper, storeInfo.getKeyType(), storeInfo.getValueType(), this.isValidateOnWrite(), this.isRemoveUnreadableFromStore(), this.getUnreadableDataDumpDirectory()));
    }
}
Also used : XodusStore(com.bakdata.conquery.io.storage.xodus.stores.XodusStore) CachedStore(com.bakdata.conquery.io.storage.xodus.stores.CachedStore) WeakCachedStore(com.bakdata.conquery.io.storage.xodus.stores.WeakCachedStore)

Example 2 with XodusStore

use of com.bakdata.conquery.io.storage.xodus.stores.XodusStore in project conquery by bakdata.

the class XodusStoreFactory method removeStore.

private void removeStore(XodusStore store) {
    Environment env = store.getEnvironment();
    synchronized (openStoresInEnv) {
        Collection<XodusStore> stores = openStoresInEnv.get(env);
        stores.remove(store);
        if (!stores.isEmpty()) {
            return;
        }
    }
    removeEnvironment(env);
}
Also used : XodusStore(com.bakdata.conquery.io.storage.xodus.stores.XodusStore) Environment(jetbrains.exodus.env.Environment)

Example 3 with XodusStore

use of com.bakdata.conquery.io.storage.xodus.stores.XodusStore in project conquery by bakdata.

the class TokenStorage method start.

@Override
public void start() {
    String storeName = "api-token";
    File tokenStore = new File(storageDir.toFile(), storeName);
    environment = Environments.newInstance(tokenStore, storeConfig.createConfig());
    final XodusStore data = new XodusStore(environment, "DATA", this::closeStoreHook, this::removeStoreHook);
    dataStore = StoreMappings.cached(new SerializingStore<>(data, validator, objectMapper, ApiTokenHash.class, ApiTokenData.class, true, false, null));
    openStoresInEnv.add(data);
    final XodusStore meta = new XodusStore(environment, "META", this::closeStoreHook, this::removeStoreHook);
    metaDataStore = StoreMappings.cached(new SerializingStore<>(meta, validator, objectMapper, UUID.class, ApiTokenData.MetaData.class, true, false, null));
    openStoresInEnv.add(meta);
}
Also used : XodusStore(com.bakdata.conquery.io.storage.xodus.stores.XodusStore) SerializingStore(com.bakdata.conquery.io.storage.xodus.stores.SerializingStore) File(java.io.File)

Example 4 with XodusStore

use of com.bakdata.conquery.io.storage.xodus.stores.XodusStore in project conquery by bakdata.

the class LocalAuthenticationRealm method onInit.

@Override
protected void onInit() {
    super.onInit();
    // Open/create the database/store
    File passwordStoreFile = new File(storageDir, storeName);
    passwordEnvironment = Environments.newInstance(passwordStoreFile, passwordStoreConfig.createConfig());
    passwordStore = StoreMappings.cached(new SerializingStore<>(new XodusStore(passwordEnvironment, "passwords", store -> store.getEnvironment().close(), store -> {
    }), validator, mapper, UserId.class, PasswordHasher.HashedEntry.class, false, true, null));
}
Also used : EnvironmentClosedException(jetbrains.exodus.env.EnvironmentClosedException) CredentialType(com.bakdata.conquery.apiv1.auth.CredentialType) SneakyThrows(lombok.SneakyThrows) Environments(jetbrains.exodus.env.Environments) UserId(com.bakdata.conquery.models.identifiable.ids.specific.UserId) UserManageable(com.bakdata.conquery.models.auth.UserManageable) AuthenticationToken(org.apache.shiro.authc.AuthenticationToken) StoreMappings(com.bakdata.conquery.io.storage.StoreMappings) PasswordCredential(com.bakdata.conquery.apiv1.auth.PasswordCredential) Duration(io.dropwizard.util.Duration) Environment(jetbrains.exodus.env.Environment) ImmutableList(com.google.common.collect.ImmutableList) JsonIgnore(com.fasterxml.jackson.annotation.JsonIgnore) XodusStore(com.bakdata.conquery.io.storage.xodus.stores.XodusStore) SkippingCredentialsMatcher(com.bakdata.conquery.models.auth.util.SkippingCredentialsMatcher) ExodusException(jetbrains.exodus.ExodusException) Conquery(com.bakdata.conquery.Conquery) MoreCollectors(com.google.common.collect.MoreCollectors) Destroyable(org.apache.shiro.util.Destroyable) XodusConfig(com.bakdata.conquery.models.config.XodusConfig) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Validator(javax.validation.Validator) IOException(java.io.IOException) User(com.bakdata.conquery.models.auth.entities.User) ConqueryTokenRealm(com.bakdata.conquery.models.auth.conquerytoken.ConqueryTokenRealm) File(java.io.File) Store(com.bakdata.conquery.io.storage.Store) ConqueryAuthenticationRealm(com.bakdata.conquery.models.auth.ConqueryAuthenticationRealm) List(java.util.List) Slf4j(lombok.extern.slf4j.Slf4j) AuthenticationException(org.apache.shiro.authc.AuthenticationException) ConqueryAuthenticationInfo(com.bakdata.conquery.models.auth.ConqueryAuthenticationInfo) Optional(java.util.Optional) AuthenticatingRealm(org.apache.shiro.realm.AuthenticatingRealm) MetaStorage(com.bakdata.conquery.io.storage.MetaStorage) SerializingStore(com.bakdata.conquery.io.storage.xodus.stores.SerializingStore) HashedEntry(com.bakdata.conquery.models.auth.basic.PasswordHasher.HashedEntry) XodusStore(com.bakdata.conquery.io.storage.xodus.stores.XodusStore) SerializingStore(com.bakdata.conquery.io.storage.xodus.stores.SerializingStore) File(java.io.File)

Example 5 with XodusStore

use of com.bakdata.conquery.io.storage.xodus.stores.XodusStore in project conquery by bakdata.

the class XodusStoreFactory method closeStore.

private void closeStore(XodusStore store) {
    Environment env = store.getEnvironment();
    synchronized (openStoresInEnv) {
        Collection<XodusStore> stores = openStoresInEnv.get(env);
        stores.remove(store);
        log.info("Closed XodusStore: {}", store);
        if (!stores.isEmpty()) {
            return;
        }
    }
    log.info("Closed last XodusStore in Environment. Closing Environment as well: {}", env.getLocation());
    closeEnvironment(env);
}
Also used : XodusStore(com.bakdata.conquery.io.storage.xodus.stores.XodusStore) Environment(jetbrains.exodus.env.Environment)

Aggregations

XodusStore (com.bakdata.conquery.io.storage.xodus.stores.XodusStore)5 Environment (jetbrains.exodus.env.Environment)3 SerializingStore (com.bakdata.conquery.io.storage.xodus.stores.SerializingStore)2 File (java.io.File)2 Conquery (com.bakdata.conquery.Conquery)1 CredentialType (com.bakdata.conquery.apiv1.auth.CredentialType)1 PasswordCredential (com.bakdata.conquery.apiv1.auth.PasswordCredential)1 MetaStorage (com.bakdata.conquery.io.storage.MetaStorage)1 Store (com.bakdata.conquery.io.storage.Store)1 StoreMappings (com.bakdata.conquery.io.storage.StoreMappings)1 CachedStore (com.bakdata.conquery.io.storage.xodus.stores.CachedStore)1 WeakCachedStore (com.bakdata.conquery.io.storage.xodus.stores.WeakCachedStore)1 ConqueryAuthenticationInfo (com.bakdata.conquery.models.auth.ConqueryAuthenticationInfo)1 ConqueryAuthenticationRealm (com.bakdata.conquery.models.auth.ConqueryAuthenticationRealm)1 UserManageable (com.bakdata.conquery.models.auth.UserManageable)1 HashedEntry (com.bakdata.conquery.models.auth.basic.PasswordHasher.HashedEntry)1 ConqueryTokenRealm (com.bakdata.conquery.models.auth.conquerytoken.ConqueryTokenRealm)1 User (com.bakdata.conquery.models.auth.entities.User)1 SkippingCredentialsMatcher (com.bakdata.conquery.models.auth.util.SkippingCredentialsMatcher)1 XodusConfig (com.bakdata.conquery.models.config.XodusConfig)1