Search in sources :

Example 1 with EphemeralStore

use of com.zimbra.cs.ephemeral.EphemeralStore 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 EphemeralStore

use of com.zimbra.cs.ephemeral.EphemeralStore 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 EphemeralStore

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

the class MigrateAttributesTest method testMigrationInfo.

@Test
public void testMigrationInfo() throws Exception {
    MigrationInfo info = MigrationInfo.getFactory().getInfo();
    try {
        EphemeralStore destination = EphemeralStore.getFactory().getStore();
        EntrySource source = new DummyEntrySource(acct);
        List<String> attrsToMigrate = new ArrayList<String>();
        MigrationCallback callback = new DummyMigrationCallback(destination);
        AttributeMigration.setCallback(callback);
        AttributeMigration migration = new AttributeMigration("testAttributeMigration", attrsToMigrate, source, null);
        assertEquals(Status.NONE, info.getStatus());
        migration.beginMigration();
        assertEquals(Status.IN_PROGRESS, info.getStatus());
        migration.endMigration();
        assertEquals(Status.COMPLETED, info.getStatus());
    } finally {
        info.clearData();
    }
}
Also used : ArrayList(java.util.ArrayList) MigrationCallback(com.zimbra.cs.ephemeral.migrate.AttributeMigration.MigrationCallback) EphemeralStore(com.zimbra.cs.ephemeral.EphemeralStore) EntrySource(com.zimbra.cs.ephemeral.migrate.AttributeMigration.EntrySource) Test(org.junit.Test)

Example 4 with EphemeralStore

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

the class MigrateAttributesTest method testAttributeMigration.

/*
     * Test end-to-end AttributeMigration
     */
@Test
public void testAttributeMigration() throws Exception {
    EphemeralStore destination = EphemeralStore.getFactory().getStore();
    EntrySource source = new DummyEntrySource(acct);
    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);
    AttributeMigration.setCallback(callback);
    AttributeMigration migration = new AttributeMigration("testAttributeMigration", attrsToMigrate, source, null);
    MigrationInfo info = MigrationInfo.getFactory().getInfo();
    // disable running in separate thread
    // run migration
    migration.migrateAllAccounts();
    EphemeralLocation location = new LdapEntryLocation(acct);
    EphemeralResult result = destination.get(new EphemeralKey(Provisioning.A_zimbraAuthTokens, "1234"), location);
    assertEquals("server_1", result.getValue());
    result = destination.get(new EphemeralKey(Provisioning.A_zimbraAuthTokens, "5678"), location);
    assertEquals("server_2", result.getValue());
    result = destination.get(new EphemeralKey(Provisioning.A_zimbraCsrfTokenData, "crumb1"), location);
    assertEquals("data1", result.getValue());
    result = destination.get(new EphemeralKey(Provisioning.A_zimbraCsrfTokenData, "crumb2"), location);
    assertEquals("data2", result.getValue());
    result = destination.get(new EphemeralKey(Provisioning.A_zimbraLastLogonTimestamp), location);
    assertEquals("currentdate", result.getValue());
    assertTrue(info.getStatus() == Status.COMPLETED);
}
Also used : EphemeralLocation(com.zimbra.cs.ephemeral.EphemeralLocation) MigrationCallback(com.zimbra.cs.ephemeral.migrate.AttributeMigration.MigrationCallback) EphemeralKey(com.zimbra.cs.ephemeral.EphemeralKey) EntrySource(com.zimbra.cs.ephemeral.migrate.AttributeMigration.EntrySource) EphemeralResult(com.zimbra.cs.ephemeral.EphemeralResult) LdapEntryLocation(com.zimbra.cs.ephemeral.LdapEntryLocation) EphemeralStore(com.zimbra.cs.ephemeral.EphemeralStore) Test(org.junit.Test)

Example 5 with EphemeralStore

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

the class AttributeMigration method clearConfigCacheOnAllServers.

public static void clearConfigCacheOnAllServers(boolean includeLocal, boolean registerTokenInPrevStore) {
    ExecutorService executor = newCachedThreadPool(newDaemonThreadFactory("ClearEphemeralConfigCache"));
    List<Server> servers = null;
    List<Server> imapServers = null;
    try {
        servers = Provisioning.getInstance().getAllMailClientServers();
    } catch (ServiceException e) {
        ZimbraLog.account.warn("cannot fetch list of servers");
        return;
    }
    try {
        imapServers = Provisioning.getIMAPDaemonServersForLocalServer();
    } catch (ServiceException e) {
        ZimbraLog.account.warn("cannot fetch list of imapd servers");
    }
    for (Server server : servers) {
        try {
            if (server.isLocalServer() && !includeLocal) {
                // don't need to flush cache on this server
                continue;
            }
        } catch (ServiceException e2) {
            ZimbraLog.ephemeral.warn("error determining if server %s is local server", server.getServiceHostname());
        }
        executor.submit(new Runnable() {

            @Override
            public void run() {
                SoapProvisioning soapProv = new SoapProvisioning();
                try {
                    String adminUrl = URLUtil.getAdminURL(server, AdminConstants.ADMIN_SERVICE_URI, true);
                    soapProv.soapSetURI(adminUrl);
                } catch (ServiceException e1) {
                    ZimbraLog.ephemeral.warn("could not get admin URL for server %s during ephemeral backend change", e1);
                    return;
                }
                try {
                    soapProv.soapZimbraAdminAuthenticate();
                    // don't flush imap daemon cache via FlushCache forwarding, since it will be done below
                    soapProv.flushCache(CacheEntryType.config.name(), null, false, false);
                    ZimbraLog.ephemeral.debug("sent FlushCache request to server %s", server.getServiceHostname());
                } catch (ServiceException e) {
                    ZimbraLog.ephemeral.warn("cannot send FlushCache request to server %s", server.getServiceHostname(), e);
                }
            }
        });
    }
    /* To flush the cache on imapd servers via the X-ZIMBRA-FLUSHCACHE command, in some cases, the auth token needs to be registered
         * with the previous ephemeral backend. This is because the imapd server may still be using the previous backend.
         */
    EphemeralStore.Factory previousEphemeralFactory = null;
    if (imapServers != null && imapServers.size() > 0) {
        if (registerTokenInPrevStore) {
            try {
                previousEphemeralFactory = EphemeralStore.getNewFactory(BackendType.previous);
            } catch (ServiceException e) {
                ZimbraLog.ephemeral.warn("could not instantiate previous EphemeralStore; imapd servers may not recognize auth token", e);
            }
        }
        final EphemeralStore previousEphemeralStore;
        if (previousEphemeralFactory != null) {
            previousEphemeralStore = registerTokenInPrevStore ? previousEphemeralFactory.getStore() : null;
        } else {
            previousEphemeralStore = null;
        }
        for (Server server : imapServers) {
            executor.submit(new Runnable() {

                @Override
                public void run() {
                    try {
                        ZimbraAuthToken token = (ZimbraAuthToken) AuthProvider.getAdminAuthToken();
                        if (registerTokenInPrevStore && previousEphemeralStore != null) {
                            token.registerWithEphemeralStore(previousEphemeralStore);
                        }
                        FlushCache.flushCacheOnImapDaemon(server, "config", null, LC.zimbra_ldap_user.value(), token);
                        ZimbraLog.ephemeral.debug("sent X-ZIMBRA-FLUSHCACHE IMAP request to imapd server %s", server.getServiceHostname());
                    } catch (ServiceException e) {
                        ZimbraLog.ephemeral.error("cannot send X-ZIMBRA-FLUSHCACHE IMAP request to imapd server %s", server.getServiceHostname(), e);
                    }
                }
            });
        }
    }
    executor.shutdown();
    try {
        executor.awaitTermination(10, TimeUnit.SECONDS);
    } catch (InterruptedException e) {
    }
}
Also used : Server(com.zimbra.cs.account.Server) ServiceException(com.zimbra.common.service.ServiceException) SoapProvisioning(com.zimbra.cs.account.soap.SoapProvisioning) ZimbraAuthToken(com.zimbra.cs.account.ZimbraAuthToken) ExecutorService(java.util.concurrent.ExecutorService) EphemeralStore(com.zimbra.cs.ephemeral.EphemeralStore)

Aggregations

EphemeralStore (com.zimbra.cs.ephemeral.EphemeralStore)15 LdapEphemeralStore (com.zimbra.cs.ephemeral.LdapEphemeralStore)11 EphemeralLocation (com.zimbra.cs.ephemeral.EphemeralLocation)9 LdapEntryLocation (com.zimbra.cs.ephemeral.LdapEntryLocation)9 EphemeralKey (com.zimbra.cs.ephemeral.EphemeralKey)5 EphemeralResult (com.zimbra.cs.ephemeral.EphemeralResult)3 EntrySource (com.zimbra.cs.ephemeral.migrate.AttributeMigration.EntrySource)3 MigrationCallback (com.zimbra.cs.ephemeral.migrate.AttributeMigration.MigrationCallback)3 Test (org.junit.Test)3 ServiceException (com.zimbra.common.service.ServiceException)2 Factory (com.zimbra.cs.ephemeral.EphemeralStore.Factory)2 FallbackEphemeralStore (com.zimbra.cs.ephemeral.FallbackEphemeralStore)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 ToZJSONObject (com.zimbra.client.ToZJSONObject)1 ZJSONObject (com.zimbra.client.ZJSONObject)1 Level (com.zimbra.common.util.Log.Level)1 AttributeInfo (com.zimbra.cs.account.AttributeInfo)1 Server (com.zimbra.cs.account.Server)1