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);
}
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());
}
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();
}
}
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);
}
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) {
}
}
Aggregations