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