Github user michaelarusso commented on a diff in the pull request:
https://github.com/apache/usergrid/pull/418#discussion_r43532670
--- Diff: stack/scripts/multitenant_migrate.py ---
@@ -0,0 +1,701 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+#
+# To migrate multiple tenants within one cluster.
+#
+# STEP 1 - SETUP TENANT ONE TOMCAT RUNNING 2.1 NOT IN SERVICE AND INIT
MIGRATION
+#
+# Login to the Tomcat instance and run this command, specifying both
superuser and tenant organization admin creds:
+#
+# python migrate_entity_data.py --org <org1name> --super
<user>:<pass> --admin <user>:<pass> --init
+#
+# This command will setup and bootstrap the database, setup the
migration system and update index mappings:
+# - /system/database/setup
+# - /system/database/bootstrap
+# - /system/migrate/run/migration-system
+# - /system/migrate/run/index_mapping_migration
+#
+# Then it will migrate appinfos, re-index the management app and then
for each of the specified org's apps
+# it will de-dup connections and re-index the app.
+#
+# Write down the 'Re-index start' timestamp when this is finished.
+#
+# STEP 2 - PUT TENANT ONE TOMCATS IN SERVICE AND DO DELTA MIGRATION
+#
+# On the same Tomcat instance and run this command with the --date
timestamp you noted in the previous step:
+#
+# python migrate_entity_data.py --org <org1name> --super
<user>:<pass> --admin <user>:<pass> --date <timestamp>
+#
+# Then it will migrate appinfos, re-index the management app and then
for each of the specified org's apps
+# it will de-dup connections and re-index the app with a start-date
specified so only data modified since
+# STEP 1 will be re-indexed.
+#
+# STEP 3 - SETUP TENANT TWO TOMCAT RUNNING 2.1 NOT IN SERVICE
+#
+# Login to the Tomcat instance and run this command, specifying both
superuser and tenant organization admin creds:
+#
+# python migrate_entity_data.py --org <org2name> --super
<user>:<pass> --admin <user>:<pass>
+#
+# This command will migrate appinfos, re-index the management app and
then for each of the specified org's apps
+# it will de-dup connections and re-index the app.
+#
+# Write down the 'Re-index start' timestamp when this is finished.
+
+# STEP 4 - PUT TENANT TWO TOMCATS IN SERVICE AND DO DELTA MIGRATION
+#
+# On the same Tomcat instance and run this command with the --date
timestamp you noted in the previous step:
+#
+# python migrate_entity_data.py --org <org2name> --super
<user>:<pass> --admin <user>:<pass> --date <timestamp>
+#
+# Then it will migrate appinfos, re-index the management app and then
for each of the specified org's apps
+# it will de-dup connections and re-index the app with a start-date
specified so only data modified since
+# STEP 1 will be re-indexed.
+#
+# STEP 5 - FULL DATA MIGRATION
+#
+# Login to any Tomcat instance in the cluster and run this command
(admin user creds must be specificed but will be ignored):
+#
+# python migrate_entity_data.py --super <user>:<pass> --admin
<user>:<pass> --full
+#
+# This command will run the full data migration.
+#
+
+import sys
+import logging
+from logging.handlers import RotatingFileHandler
+import argparse
+import time
+import requests
+import json
+
+
+# Version expected in status response post-migration for entity and
app-info data
+TARGET_APPINFO_VERSION=2
+TARGET_ENTITY_DATA_VERSION=2
+TARGET_CORE_DATA_VERSION=2
+TARGET_MIGRATION_SYSTEM_VERSION = 1
+TARGET_INDEX_MAPPING_VERSION = 2
+
+# Set an interval (in seconds) for checking if re-index and/or migration
has finished
+STATUS_INTERVAL_SECONDS = 2
+
+# Set plugin names
+PLUGIN_MIGRATION_SYSTEM = 'migration-system'
+PLUGIN_APPINFO = 'appinfo-migration'
+PLUGIN_ENTITYDATA = 'collections-entity-data'
+PLUGIN_INDEX_MAPPING = 'index_mapping_migration'
+PLUGIN_CORE_DATA = 'core-data'
+
+MANAGEMENT_APP_ID = 'b6768a08-b5d5-11e3-a495-11ddb1de66c8'
+
+
+
+def parse_args():
+ parser = argparse.ArgumentParser(description='Usergrid Migration Tool')
+
+ parser.add_argument('--endpoint',
+ help='The endpoint to use for making API
requests.',
+ type=str,
+ default='http://localhost:8080')
+
+ parser.add_argument('--super',
+ help='Superuser username and creds <user:pass>',
+ type=str,
+ required=True)
+
+ parser.add_argument('--admin',
+ help='Organization admin creds <user:pass>',
+ type=str,
+ required=True)
+
+ parser.add_argument('--init',
+ help='Init system and start first migration.',
+ action='store_true',
+ default=False)
+
+ parser.add_argument('--org',
+ help='Name of organization on which to run
migration.',
+ type=str,
+ required=False)
+
+ parser.add_argument('--date',
+ help='A date from which to start the migration',
+ type=str)
+
+ parser.add_argument('--full',
+ help='Run full data migration (last step in
cluster migration).',
+ action='store_true',
+ default=False)
+
+ my_args = parser.parse_args(sys.argv[1:])
+
+ arg_vars = vars(my_args)
+
+ creds = arg_vars['super'].split(':')
+ if len(creds) != 2:
+ print('Superuser credentials not properly specified. Must be "-u
<user:pass>". Exiting...')
+ exit_on_error()
+ else:
+ arg_vars['superuser'] = creds[0]
+ arg_vars['superpass'] = creds[1]
+
+ creds = arg_vars['super'].split(':')
+ if len(creds) != 2:
+ print('Org admin credentials not properly specified. Must be "-u
<user:pass>". Exiting...')
+ exit_on_error()
+ else:
+ arg_vars['adminuser'] = creds[0]
+ arg_vars['adminpass'] = creds[1]
+
+ return arg_vars
+
+
+
+class Migrate:
+ def __init__(self):
+ self.args = parse_args()
+ self.start_date = self.args['date']
+ self.endpoint = self.args['endpoint']
+ self.metrics = {'reindex_start': '',
+ 'reindex_end': '',
+ 'appinfo_migration_start': '',
+ 'appinfo_migration_end': '',
+ 'full_data_migration_start': '',
+ 'full_data_migration_end': ''}
+ self.logger = init_logging(self.__class__.__name__)
+ self.super_user = self.args['superuser']
+ self.super_pass = self.args['superpass']
+ self.admin_user = self.args['adminuser']
+ self.admin_pass = self.args['adminpass']
+ self.org = self.args['org']
+ self.init = self.args['init']
+ self.full = self.args['full']
+
+ def run(self):
+ self.logger.info('Initializing...')
+
+ if not self.is_endpoint_available():
+ exit_on_error('Endpoint is not available, aborting')
+
+ if self.start_date is not None:
+ self.logger.info("Date Provided. Re-index will run from
date=[%s]", self.start_date)
+
+ try:
+
+ if self.full:
+
+ # Do full data migration and exit
+
+ self.start_fulldata_migration()
+
+ self.metrics['full_data_migration_start'] =
get_current_time()
+ self.logger.info("Full Data Migration Started")
+ is_migrated = False
+ while not is_migrated:
+ time.sleep(STATUS_INTERVAL_SECONDS)
+ is_migrated = self.is_data_migrated()
+ if is_migrated:
+ break
+
+ self.metrics['full_data_migration_end'] =
get_current_time()
+ self.logger.info("Full Data Migration completed")
+
+ self.log_metrics()
+ self.logger.info("Finished...")
+
+ return
+
+
+ if self.init:
+
+ # Init the migration system as this is the first migration
done on the cluster
+
+ self.run_database_setup()
--- End diff --
I think if you've already ran it manually at least once, then you're fine.
It sets up the default usergrid org, superuser acct, and the test org/account
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---