Need to look for old appinfos in the (old and now deprecated) Sytem App, not the Management App.
Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/f4f17d68 Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/f4f17d68 Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/f4f17d68 Branch: refs/heads/USERGRID-509 Commit: f4f17d68d350d15565e9eccdfeb745cf27eeb96b Parents: 50cb3bf Author: Dave Johnson <[email protected]> Authored: Fri Mar 13 09:59:38 2015 -0400 Committer: Dave Johnson <[email protected]> Committed: Fri Mar 13 09:59:38 2015 -0400 ---------------------------------------------------------------------- .../migration/AppInfoMigrationPlugin.java | 11 ++++--- .../corepersistence/util/CpNamingUtils.java | 4 +++ .../org/apache/usergrid/ServiceITSetup.java | 3 ++ .../org/apache/usergrid/ServiceITSetupImpl.java | 34 ++++++++++++++------ .../migration/AppInfoMigrationPluginTest.java | 24 ++++++++------ .../src/test/resources/log4j.properties | 6 ++-- .../setup/ConcurrentProcessSingleton.java | 20 ++++++++---- 7 files changed, 71 insertions(+), 31 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/f4f17d68/stack/core/src/main/java/org/apache/usergrid/corepersistence/migration/AppInfoMigrationPlugin.java ---------------------------------------------------------------------- diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/migration/AppInfoMigrationPlugin.java b/stack/core/src/main/java/org/apache/usergrid/corepersistence/migration/AppInfoMigrationPlugin.java index 59fafd5..3d386d9 100644 --- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/migration/AppInfoMigrationPlugin.java +++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/migration/AppInfoMigrationPlugin.java @@ -52,7 +52,7 @@ public class AppInfoMigrationPlugin implements MigrationPlugin { public static String PLUGIN_NAME = "appinfo-migration"; @Inject - private MigrationInfoSerialization migrationInfoSerialization; + protected MigrationInfoSerialization migrationInfoSerialization; @Inject protected EntityManagerFactory emf; // protected for test purposes only @@ -74,12 +74,13 @@ public class AppInfoMigrationPlugin implements MigrationPlugin { observer.start(); - EntityManager em = emf.getEntityManager( CpNamingUtils.MANAGEMENT_APPLICATION_ID); + // Search the old and now deprecated System App for appinfo entities + EntityManager systemAppEm = emf.getEntityManager( CpNamingUtils.SYSTEM_APP_ID ); Query q = Query.fromQL("select *"); Results results; try { - results = em.searchCollection(em.getApplicationRef(), "appinfos", q); + results = systemAppEm.searchCollection(systemAppEm.getApplicationRef(), "appinfos", q); } catch (Exception e) { logger.error("Error reading old appinfos collection, not migrating", e); return; @@ -87,10 +88,10 @@ public class AppInfoMigrationPlugin implements MigrationPlugin { if ( !results.isEmpty() ) { - // applications still found in old appinfos collection, migrate them. + // we found appinfos, let's migrate them to application_infos in the Management App + EntityManager em = emf.getEntityManager( emf.getManagementAppId()); String currentAppName = null; - try { logger.info("Migrating old appinfos"); http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/f4f17d68/stack/core/src/main/java/org/apache/usergrid/corepersistence/util/CpNamingUtils.java ---------------------------------------------------------------------- diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/util/CpNamingUtils.java b/stack/core/src/main/java/org/apache/usergrid/corepersistence/util/CpNamingUtils.java index 356367b..7fa6bea 100644 --- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/util/CpNamingUtils.java +++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/util/CpNamingUtils.java @@ -49,6 +49,10 @@ public class CpNamingUtils { public static final UUID MANAGEMENT_APPLICATION_ID = UUID.fromString("b6768a08-b5d5-11e3-a495-11ddb1de66c8"); + /** Old and deprecated SYSTEM_APP */ + public static final UUID SYSTEM_APP_ID = + UUID.fromString("b6768a08-b5d5-11e3-a495-10ddb1de66c3"); + /** * Information about applications is stored in the management app using these types */ http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/f4f17d68/stack/services/src/test/java/org/apache/usergrid/ServiceITSetup.java ---------------------------------------------------------------------- diff --git a/stack/services/src/test/java/org/apache/usergrid/ServiceITSetup.java b/stack/services/src/test/java/org/apache/usergrid/ServiceITSetup.java index 2a04c52..b4d43b4 100644 --- a/stack/services/src/test/java/org/apache/usergrid/ServiceITSetup.java +++ b/stack/services/src/test/java/org/apache/usergrid/ServiceITSetup.java @@ -17,6 +17,7 @@ package org.apache.usergrid; +import org.apache.usergrid.corepersistence.migration.AppInfoMigrationPlugin; import org.apache.usergrid.management.ApplicationCreator; import org.apache.usergrid.management.ManagementService; import org.apache.usergrid.management.export.ExportService; @@ -63,4 +64,6 @@ public interface ServiceITSetup extends CoreITSetup { String get( String key ); SignInProviderFactory getProviderFactory(); + + AppInfoMigrationPlugin getAppInfoMigrationPlugin(); } http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/f4f17d68/stack/services/src/test/java/org/apache/usergrid/ServiceITSetupImpl.java ---------------------------------------------------------------------- diff --git a/stack/services/src/test/java/org/apache/usergrid/ServiceITSetupImpl.java b/stack/services/src/test/java/org/apache/usergrid/ServiceITSetupImpl.java index cb7040b..04f1e49 100644 --- a/stack/services/src/test/java/org/apache/usergrid/ServiceITSetupImpl.java +++ b/stack/services/src/test/java/org/apache/usergrid/ServiceITSetupImpl.java @@ -19,6 +19,8 @@ package org.apache.usergrid; import java.util.Properties; +import org.apache.usergrid.corepersistence.GuiceFactory; +import org.apache.usergrid.corepersistence.migration.AppInfoMigrationPlugin; import org.junit.runner.Description; import org.junit.runners.model.Statement; import org.slf4j.Logger; @@ -45,7 +47,7 @@ import java.util.Properties; /** A {@link org.junit.rules.TestRule} that sets up services. */ public class ServiceITSetupImpl extends CoreITSetupImpl implements ServiceITSetup { - private static final Logger LOG = LoggerFactory.getLogger( ServiceITSetupImpl.class ); + private static final Logger logger = LoggerFactory.getLogger( ServiceITSetupImpl.class ); private ServiceManagerFactory smf; private ManagementService managementService; @@ -55,18 +57,27 @@ public class ServiceITSetupImpl extends CoreITSetupImpl implements ServiceITSetu private Properties properties; private ExportService exportService; private ImportService importService; + private AppInfoMigrationPlugin appInfoMigrationPlugin; public ServiceITSetupImpl() { super(); - managementService = springResource.getBean( ManagementService.class ); + + managementService = springResource.getBean( ManagementService.class ); applicationCreator = springResource.getBean( ApplicationCreator.class ); - tokenService = springResource.getBean( TokenService.class ); - providerFactory = springResource.getBean( SignInProviderFactory.class ); - properties = springResource.getBean( "properties", Properties.class ); - smf = springResource.getBean( ServiceManagerFactory.class ); - exportService = springResource.getBean( ExportService.class ); - importService = springResource.getBean( ImportService.class ); + tokenService = springResource.getBean( TokenService.class ); + providerFactory = springResource.getBean( SignInProviderFactory.class ); + properties = springResource.getBean( "properties", Properties.class ); + smf = springResource.getBean( ServiceManagerFactory.class ); + exportService = springResource.getBean( ExportService.class ); + importService = springResource.getBean( ImportService.class ); + + try { + appInfoMigrationPlugin = springResource.getBean(GuiceFactory.class) + .getObject().getInstance(AppInfoMigrationPlugin.class); + } catch ( Exception e ) { + logger.error("Unable to instantiate AppInfoMigrationPlugin", e); + } //set our security manager for shiro SecurityUtils.setSecurityManager(springResource.getBean( org.apache.shiro.mgt.SecurityManager.class )); @@ -75,7 +86,7 @@ public class ServiceITSetupImpl extends CoreITSetupImpl implements ServiceITSetu protected void after( Description description ) { super.after( description ); - LOG.info( "Test {}: finish with application", description.getDisplayName() ); + logger.info( "Test {}: finish with application", description.getDisplayName() ); } @@ -163,4 +174,9 @@ public class ServiceITSetupImpl extends CoreITSetupImpl implements ServiceITSetu public SignInProviderFactory getProviderFactory() { return providerFactory; } + + @Override + public AppInfoMigrationPlugin getAppInfoMigrationPlugin() { + return appInfoMigrationPlugin; + } } http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/f4f17d68/stack/services/src/test/java/org/apache/usergrid/corepersistence/migration/AppInfoMigrationPluginTest.java ---------------------------------------------------------------------- diff --git a/stack/services/src/test/java/org/apache/usergrid/corepersistence/migration/AppInfoMigrationPluginTest.java b/stack/services/src/test/java/org/apache/usergrid/corepersistence/migration/AppInfoMigrationPluginTest.java index 30b7a3c..d0fa848 100644 --- a/stack/services/src/test/java/org/apache/usergrid/corepersistence/migration/AppInfoMigrationPluginTest.java +++ b/stack/services/src/test/java/org/apache/usergrid/corepersistence/migration/AppInfoMigrationPluginTest.java @@ -23,8 +23,10 @@ import org.apache.usergrid.NewOrgAppAdminRule; import org.apache.usergrid.ServiceITSetup; import org.apache.usergrid.ServiceITSetupImpl; import org.apache.usergrid.cassandra.ClearShiroSubject; +import org.apache.usergrid.corepersistence.util.CpNamingUtils; import org.apache.usergrid.management.OrganizationOwnerInfo; import org.apache.usergrid.persistence.*; +import org.apache.usergrid.persistence.cassandra.CassandraService; import org.apache.usergrid.persistence.core.migration.data.ProgressObserver; import org.apache.usergrid.persistence.entities.Application; import org.apache.usergrid.persistence.index.query.Query; @@ -35,11 +37,12 @@ import org.mockito.Mockito; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.util.*; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.UUID; -import static org.apache.usergrid.TestHelper.uniqueEmail; -import static org.apache.usergrid.TestHelper.uniqueOrg; -import static org.apache.usergrid.TestHelper.uniqueUsername; +import static org.apache.usergrid.TestHelper.*; import static org.junit.Assert.*; @@ -100,6 +103,11 @@ public class AppInfoMigrationPluginTest { List<Entity> deletedApps = new ArrayList<>(); + setup.getEmf().initializeApplicationV2( + CassandraService.DEFAULT_ORGANIZATION, CpNamingUtils.SYSTEM_APP_ID, "systemapp", null); + + EntityManager systemAppEm = setup.getEmf().getEntityManager( CpNamingUtils.SYSTEM_APP_ID ); + int count = 0; for ( UUID appId : appIds ) { @@ -108,7 +116,7 @@ public class AppInfoMigrationPluginTest { final String appName = applicationInfo.getName(); final String finalOrgId = organization.getOrganization().getUuid().toString(); final String finalAppId = applicationInfo.getProperty( Schema.PROPERTY_APPLICATION_ID ).toString(); - rootEm.create("appinfo", new HashMap<String, Object>() {{ + systemAppEm.create("appinfo", new HashMap<String, Object>() {{ put("name", appName ); put("organizationUuid", finalOrgId ); put("applicationUuid", finalAppId ); @@ -130,16 +138,14 @@ public class AppInfoMigrationPluginTest { // test that applications are now broken - checkApplicationsBroken( orgName, deletedApps ); + checkApplicationsBroken(orgName, deletedApps); // run the migration, which should restore the application_info entities logger.debug("\n\nRun the migration\n"); ProgressObserver po = Mockito.mock(ProgressObserver.class); - AppInfoMigrationPlugin plugin = new AppInfoMigrationPlugin(); - plugin.emf = setup.getEmf(); - plugin.run( po ); + setup.getAppInfoMigrationPlugin().run(po); logger.debug("\n\nVerify migration results\n"); http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/f4f17d68/stack/services/src/test/resources/log4j.properties ---------------------------------------------------------------------- diff --git a/stack/services/src/test/resources/log4j.properties b/stack/services/src/test/resources/log4j.properties index e1c378f..07e2dde 100644 --- a/stack/services/src/test/resources/log4j.properties +++ b/stack/services/src/test/resources/log4j.properties @@ -26,7 +26,7 @@ log4j.appender.stdout=org.apache.log4j.ConsoleAppender log4j.appender.stdout.layout=org.apache.log4j.PatternLayout log4j.appender.stdout.layout.ConversionPattern=%d %p (%t) %c{1} - %m%n -log4j.logger.org.apache.usergrid=WARN +log4j.logger.org.apache.usergrid=INFO log4j.logger.org.apache.usergrid.persistence.cassandra.DB=WARN, stdout log4j.logger.org.apache.usergrid.persistence.cassandra.BATCH=WARN, stdout @@ -55,10 +55,12 @@ log4j.logger.org.apache.usergrid.locking.singlenode.SingleNodeLockManagerImpl=DE #log4j.logger.org.apache.cassandra.service.StorageProxy=DEBUG, stdout #log4j.logger.org.apache.usergrid.corepersistence=DEBUG - #log4j.logger.org.apache.usergrid.persistence.index=DEBUG #log4j.logger.org.apache.usergrid.batch=DEBUG #log4j.logger.org.apache.usergrid.management.export=DEBUG #log4j.logger.org.apache.usergrid.management.importer=DEBUG +log4j.logger.org.apache.usergrid.corepersistence.migration=DEBUG +log4j.logger.org.apache.usergrid.persistence.core.migration.data=DEBUG + http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/f4f17d68/stack/test-utils/src/main/java/org/apache/usergrid/setup/ConcurrentProcessSingleton.java ---------------------------------------------------------------------- diff --git a/stack/test-utils/src/main/java/org/apache/usergrid/setup/ConcurrentProcessSingleton.java b/stack/test-utils/src/main/java/org/apache/usergrid/setup/ConcurrentProcessSingleton.java index e8c5ace..66e5d12 100644 --- a/stack/test-utils/src/main/java/org/apache/usergrid/setup/ConcurrentProcessSingleton.java +++ b/stack/test-utils/src/main/java/org/apache/usergrid/setup/ConcurrentProcessSingleton.java @@ -28,6 +28,9 @@ import org.apache.usergrid.cassandra.SpringResource; import org.apache.usergrid.lock.MultiProcessBarrier; import org.apache.usergrid.lock.MultiProcessLocalLock; +import java.io.IOException; +import java.util.concurrent.TimeoutException; + /** * A singleton that starts cassandra and configures it once per JVM @@ -75,6 +78,7 @@ public class ConcurrentProcessSingleton { try { logger.info( "Trying to get a lock to setup system" ); + //we have a lock, so init the system if ( lock.tryLock() ) { @@ -96,18 +100,22 @@ public class ConcurrentProcessSingleton { logger.info("Populating database"); schemaManager.populateBaseData(); - //signal to other processes we've migrated, and they can proceed barrier.proceed(); - } + logger.info( "Waiting for setup to complete" ); + barrier.await( ONE_MINUTE ); + logger.info( "Setup to complete" ); - logger.info( "Waiting for setup to complete" ); - barrier.await( ONE_MINUTE ); - logger.info( "Setup to complete" ); + lock.maybeReleaseLock(); + + } else { + throw new RuntimeException( "Unable to initialize system: could not get lock." + +" Some other process must be binding to port " + LOCK_PORT ); + } - lock.maybeReleaseLock(); } + catch ( Exception e ) { throw new RuntimeException( "Unable to initialize system", e ); }
