use of com.zimbra.cs.ephemeral.migrate.AttributeMigration.AllAccountsSource 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