use of com.zimbra.cs.ephemeral.migrate.AttributeMigration.MigrationCallback 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.migrate.AttributeMigration.MigrationCallback 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.migrate.AttributeMigration.MigrationCallback 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.migrate.AttributeMigration.MigrationCallback in project zm-mailbox by Zimbra.
the class AttributeMigrationUtil method main.
public static void main(String[] args) throws Exception {
CliUtil.toolSetup();
CommandLineParser parser = new GnuParser();
CommandLine cl = parser.parse(OPTIONS, args);
boolean dryRun = cl.hasOption('r');
boolean useNumThreads = cl.hasOption('n');
boolean debug = cl.hasOption('d');
boolean help = cl.hasOption('h');
boolean useAccount = cl.hasOption('a');
boolean showStatus = cl.hasOption('s');
boolean clear = cl.hasOption('c');
List<String> clArgs = cl.getArgList();
if (clArgs.isEmpty() && !help && !clear && !showStatus) {
ZimbraLog.ephemeral.error("must specify URL of destination ephemeral store");
return;
}
if (help || (clear && showStatus)) {
usage();
return;
}
if (debug) {
ZimbraLog.ephemeral.setLevel(Level.debug);
}
if (dryRun && useNumThreads) {
ZimbraLog.ephemeral.error("cannot specify --num-threads with --dry-run option");
return;
}
if (clear && (dryRun || useNumThreads || useAccount || showStatus || !clArgs.isEmpty())) {
ZimbraLog.ephemeral.error("cannot specify --clear with arguments or other options");
return;
}
if (showStatus && (dryRun || useNumThreads || useAccount || clear || !clArgs.isEmpty())) {
ZimbraLog.ephemeral.error("cannot specify --status with arguments or other options");
return;
}
// a null numThreads value causes the migration process to run synchronously
Integer numThreads = null;
if (!dryRun) {
// dry runs are always synchronous
try {
numThreads = Integer.valueOf(cl.getOptionValue('n', "1"));
if (numThreads < 1) {
ZimbraLog.ephemeral.error("invalid num-threads value: '%s'", numThreads);
return;
}
} catch (NumberFormatException e) {
ZimbraLog.ephemeral.error("invalid num-threads value: '%s'", cl.getOptionValue('n'));
return;
}
}
if (showStatus) {
showMigrationInfo();
return;
} else if (clear) {
clearMigrationInfo();
return;
}
String destURL = clArgs.get(0);
List<String> attrsToMigrate;
MigrationCallback callback;
if (clArgs.size() > 1) {
attrsToMigrate = clArgs.subList(1, clArgs.size());
} else {
attrsToMigrate = new ArrayList<String>(AttributeManager.getInstance().getEphemeralAttributeNames());
}
if (!dryRun) {
String backendName = null;
String[] tokens = destURL.split(":");
if (tokens != null && tokens.length > 0) {
backendName = tokens[0];
if (backendName.equalsIgnoreCase("ldap")) {
ZimbraLog.ephemeral.info("migrating to LDAP is not supported");
return;
}
}
if (Provisioning.getInstance().getConfig().getEphemeralBackendURL().equalsIgnoreCase(destURL)) {
ZimbraLog.ephemeral.info("destination URL cannot be the same as the current ephemeral backend URL");
return;
}
ExtensionUtil.initEphemeralBackendExtension(backendName);
try {
callback = new ZimbraMigrationCallback(destURL);
} catch (ServiceException e) {
Zimbra.halt(String.format("unable to connect to ephemeral backend at %s; migration cannot proceed", destURL), e);
return;
}
} else {
callback = new DryRunMigrationCallback();
MigrationInfo.setFactory(InMemoryMigrationInfo.Factory.class);
}
try {
AttributeMigration migration = new AttributeMigration(destURL, attrsToMigrate, numThreads);
AttributeMigration.setCallback(callback);
EntrySource source;
if (useAccount) {
String[] acctValues = cl.getOptionValue('a').split(",");
source = new SomeAccountsSource(acctValues);
} else {
source = new AllAccountsSource();
}
migration.setSource(source);
migration.migrateAllAccounts();
} catch (InvalidAttributeException e) {
Zimbra.halt(String.format("Migration can't proceed: %s", e.getMessage()));
return;
} catch (ServiceException e) {
Zimbra.halt(String.format("error encountered during migration to ephemeral backend at %s; migration cannot proceed", destURL), e);
return;
}
}
Aggregations