Search in sources :

Example 1 with Factory

use of com.zimbra.cs.ephemeral.EphemeralStore.Factory in project zm-mailbox by Zimbra.

the class MigrateAttributesTest method testFallbackEphemeralStoreWhenMigrating.

@Test
public void testFallbackEphemeralStoreWhenMigrating() throws Exception {
    EphemeralStore destination = EphemeralStore.getFactory().getStore();
    EntrySource source = new DummyEntrySource(acct);
    Multimap<String, Object> deletedAttrs = LinkedListMultimap.create();
    List<String> attrsToMigrate = Arrays.asList(new String[] { Provisioning.A_zimbraAuthTokens, Provisioning.A_zimbraCsrfTokenData, Provisioning.A_zimbraLastLogonTimestamp });
    //DummyMigrationCallback will store attributes in InMemoryEphemeralStore, and track deletions in deletedAttrs map
    MigrationCallback callback = new DummyMigrationCallback(destination, deletedAttrs);
    AttributeMigration migration = new AttributeMigration(attrsToMigrate, source, callback, null);
    migration.beginMigration();
    //set to in-memory backend because fallback won't be enabled with default LDAP backend
    EphemeralStore.setFactory(InMemoryEphemeralStore.Factory.class);
    Factory factory = EphemeralStore.getFactory();
    EphemeralStore store = factory.getStore();
    //in-memory backend will be wrapped in a FallbackEphemeralStore, with LDAP as the fallback
    assertTrue(store instanceof FallbackEphemeralStore);
    FallbackEphemeralStore fallbackStore = (FallbackEphemeralStore) store;
    assertTrue(fallbackStore.getPrimaryStore() instanceof InMemoryEphemeralStore);
    assertTrue(fallbackStore.getSecondaryStore() instanceof LdapEphemeralStore);
    migration.endMigration();
    EphemeralStore.setFactory(InMemoryEphemeralStore.Factory.class);
    //when migration is finished, fallback won't be enabled anymore
    factory = EphemeralStore.getFactory();
    store = factory.getStore();
    assertTrue(store instanceof InMemoryEphemeralStore);
}
Also used : InMemoryEphemeralStore(com.zimbra.cs.ephemeral.InMemoryEphemeralStore) LdapEphemeralStore(com.zimbra.cs.ephemeral.LdapEphemeralStore) Factory(com.zimbra.cs.ephemeral.EphemeralStore.Factory) MigrationCallback(com.zimbra.cs.ephemeral.migrate.AttributeMigration.MigrationCallback) EntrySource(com.zimbra.cs.ephemeral.migrate.AttributeMigration.EntrySource) FallbackEphemeralStore(com.zimbra.cs.ephemeral.FallbackEphemeralStore) FallbackEphemeralStore(com.zimbra.cs.ephemeral.FallbackEphemeralStore) LdapEphemeralStore(com.zimbra.cs.ephemeral.LdapEphemeralStore) EphemeralStore(com.zimbra.cs.ephemeral.EphemeralStore) InMemoryEphemeralStore(com.zimbra.cs.ephemeral.InMemoryEphemeralStore) Test(org.junit.Test)

Example 2 with Factory

use of com.zimbra.cs.ephemeral.EphemeralStore.Factory in project zm-mailbox by Zimbra.

the class AttributeMigrationUtil method initEphemeralBackendExtension.

private static void initEphemeralBackendExtension(String backendName) throws ServiceException {
    Level savedExten = ZimbraLog.extensions.getLevel();
    try {
        if (!ZimbraLog.ephemeral.isDebugEnabled()) {
            // cut down on noise unless enabled debug
            ZimbraLog.extensions.setLevel(Level.error);
        }
        ExtensionUtil.initAllMatching(new EphemeralStore.EphemeralStoreMatcher(backendName));
    } finally {
        ZimbraLog.extensions.setLevel(savedExten);
    }
    Factory factory = EphemeralStore.getFactory(backendName);
    if (factory == null) {
        Zimbra.halt(String.format("no extension class name found for backend '%s', aborting attribute migration", backendName));
        // keep Eclipse happy
        return;
    }
    EphemeralStore store = factory.getStore();
    if (store == null) {
        Zimbra.halt(String.format("no store found for backend '%s', aborting attribute migration", backendName));
        // keep Eclipse happy
        return;
    }
    ZimbraLog.ephemeral.info("Using ephemeral backend %s (%s) for attribute migration", backendName, store.getClass().getName());
}
Also used : Factory(com.zimbra.cs.ephemeral.EphemeralStore.Factory) Level(com.zimbra.common.util.Log.Level) EphemeralStore(com.zimbra.cs.ephemeral.EphemeralStore)

Example 3 with Factory

use of com.zimbra.cs.ephemeral.EphemeralStore.Factory in project zm-mailbox by Zimbra.

the class EphemeralBackendCheck method preModify.

@Override
public void preModify(CallbackContext context, String attrName, Object attrValue, Map attrsToModify, Entry entry) throws ServiceException {
    if (attrName.equalsIgnoreCase(Provisioning.A_zimbraEphemeralBackendURL)) {
        String url = (String) attrValue;
        String[] tokens = url.split(":");
        if (tokens != null && tokens.length > 0) {
            String backend = tokens[0];
            if (backend.equalsIgnoreCase("ldap")) {
                EphemeralStore.clearFactory();
                return;
            }
            Factory factory = EphemeralStore.getFactory(backend);
            if (factory == null) {
                // Probably called from zmprov in LDAP mode, so need to setup any Ephemeral Store extensions
                Level savedEphem = ZimbraLog.ephemeral.getLevel();
                Level savedExten = ZimbraLog.extensions.getLevel();
                try {
                    // suppress logging in zmprov output
                    ZimbraLog.ephemeral.setLevel(Level.error);
                    ZimbraLog.extensions.setLevel(Level.error);
                    ExtensionUtil.initAllMatching(new EphemeralStore.EphemeralStoreMatcher(backend));
                } finally {
                    ZimbraLog.ephemeral.setLevel(savedEphem);
                    ZimbraLog.extensions.setLevel(savedExten);
                }
                factory = EphemeralStore.getFactory(backend);
            }
            if (factory == null) {
                throw ServiceException.FAILURE(String.format("unable to modify %s; no factory found for backend '%s'", attrName, backend), null);
            }
            try {
                factory.test(url);
                EphemeralStore.clearFactory();
            } catch (ServiceException e) {
                throw ServiceException.FAILURE(String.format("cannot set zimbraEphemeralBackendURL to %s", url), e);
            }
        } else {
            throw ServiceException.FAILURE(String.format("unable to modify %s; no ephemeral backend specified", attrName), null);
        }
    }
}
Also used : ServiceException(com.zimbra.common.service.ServiceException) Factory(com.zimbra.cs.ephemeral.EphemeralStore.Factory) Level(com.zimbra.common.util.Log.Level) EphemeralStore(com.zimbra.cs.ephemeral.EphemeralStore)

Aggregations

EphemeralStore (com.zimbra.cs.ephemeral.EphemeralStore)3 Factory (com.zimbra.cs.ephemeral.EphemeralStore.Factory)3 Level (com.zimbra.common.util.Log.Level)2 ServiceException (com.zimbra.common.service.ServiceException)1 FallbackEphemeralStore (com.zimbra.cs.ephemeral.FallbackEphemeralStore)1 InMemoryEphemeralStore (com.zimbra.cs.ephemeral.InMemoryEphemeralStore)1 LdapEphemeralStore (com.zimbra.cs.ephemeral.LdapEphemeralStore)1 EntrySource (com.zimbra.cs.ephemeral.migrate.AttributeMigration.EntrySource)1 MigrationCallback (com.zimbra.cs.ephemeral.migrate.AttributeMigration.MigrationCallback)1 Test (org.junit.Test)1