Only reset roles and application secrets if the create application request is not for a migration.
Project: http://git-wip-us.apache.org/repos/asf/usergrid/repo Commit: http://git-wip-us.apache.org/repos/asf/usergrid/commit/f9028b24 Tree: http://git-wip-us.apache.org/repos/asf/usergrid/tree/f9028b24 Diff: http://git-wip-us.apache.org/repos/asf/usergrid/diff/f9028b24 Branch: refs/heads/USERGRID-1047 Commit: f9028b24aa9dfb4092a8957d205aeec26b5ff11b Parents: e03354f Author: Michael Russo <michaelaru...@gmail.com> Authored: Tue Jan 19 15:40:01 2016 -0800 Committer: Michael Russo <michaelaru...@gmail.com> Committed: Tue Jan 19 15:40:01 2016 -0800 ---------------------------------------------------------------------- .../corepersistence/CpEntityManagerFactory.java | 18 +++++++++++------- .../apache/usergrid/corepersistence/CpSetup.java | 14 ++------------ .../persistence/EntityManagerFactory.java | 8 +++----- .../management/AppInfoMigrationPlugin.java | 3 +-- .../usergrid/management/ManagementService.java | 4 ++-- .../cassandra/ManagementServiceImpl.java | 12 ++++++------ .../migration/AppInfoMigrationPluginTest.java | 2 +- 7 files changed, 26 insertions(+), 35 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/usergrid/blob/f9028b24/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManagerFactory.java ---------------------------------------------------------------------- diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManagerFactory.java b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManagerFactory.java index c75a025..8b6feed 100644 --- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManagerFactory.java +++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManagerFactory.java @@ -207,17 +207,16 @@ public class CpEntityManagerFactory implements EntityManagerFactory, Application @Override public Entity createApplicationV2(String organizationName, String name) throws Exception { - return createApplicationV2( organizationName, name, null, null ); + return createApplicationV2( organizationName, name, null, null, false); } @Override public Entity createApplicationV2( - String orgName, String name, UUID applicationId, Map<String, Object> properties) throws Exception { + String orgName, String name, UUID applicationId, Map<String, Object> properties, boolean forMigration) throws Exception { String appName = buildAppName( orgName, name ); - final Optional<UUID> appId = applicationIdCache.getApplicationId( appName ); if ( appId.isPresent()) { @@ -229,7 +228,7 @@ public class CpEntityManagerFactory implements EntityManagerFactory, Application logger.debug( "New application orgName {} orgAppName {} id {} ", new Object[] { orgName, name, applicationId.toString() } ); - return initializeApplicationV2( orgName, applicationId, appName, properties ); + return initializeApplicationV2( orgName, applicationId, appName, properties, forMigration); } @@ -243,8 +242,8 @@ public class CpEntityManagerFactory implements EntityManagerFactory, Application * @return UUID of newly created Entity of type application_info */ @Override - public Entity initializeApplicationV2( String organizationName, final UUID applicationId, String name, - Map<String, Object> properties ) throws Exception { + public Entity initializeApplicationV2(String organizationName, final UUID applicationId, String name, + Map<String, Object> properties, boolean forMigration) throws Exception { // Ensure our management system exists before creating our application init(); @@ -268,7 +267,12 @@ public class CpEntityManagerFactory implements EntityManagerFactory, Application } properties.put( PROPERTY_NAME, appName ); appEm.create(applicationId, TYPE_APPLICATION, properties); - appEm.resetRoles(); + + // only reset roles if this application isn't being migrated (meaning dictionary and role data already exists) + if(!forMigration){ + appEm.resetRoles(); + } + // create application info entity in the management app http://git-wip-us.apache.org/repos/asf/usergrid/blob/f9028b24/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpSetup.java ---------------------------------------------------------------------- diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpSetup.java b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpSetup.java index 71db120..035518e 100644 --- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpSetup.java +++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpSetup.java @@ -19,15 +19,6 @@ package org.apache.usergrid.corepersistence; import java.util.UUID; -import com.google.inject.Binding; -import org.apache.usergrid.corepersistence.index.IndexLocationStrategyFactory; -import org.apache.usergrid.corepersistence.util.CpNamingUtils; -import org.apache.usergrid.persistence.core.scope.ApplicationScope; -import org.apache.usergrid.persistence.core.scope.ApplicationScopeImpl; -import org.apache.usergrid.persistence.index.EntityIndex; -import org.apache.usergrid.persistence.index.EntityIndexFactory; -import org.apache.usergrid.persistence.index.IndexLocationStrategy; -import org.apache.usergrid.persistence.model.entity.SimpleId; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -49,14 +40,12 @@ import me.prettyprint.hector.api.ddl.ComparatorType; import static me.prettyprint.hector.api.factory.HFactory.createColumnFamilyDefinition; import static org.apache.usergrid.persistence.cassandra.CassandraPersistenceUtils.getCfDefs; import static org.apache.usergrid.persistence.cassandra.CassandraService.APPLICATIONS_CF; -import static org.apache.usergrid.persistence.cassandra.CassandraService.DEFAULT_APPLICATION; import static org.apache.usergrid.persistence.cassandra.CassandraService.DEFAULT_ORGANIZATION; import static org.apache.usergrid.persistence.cassandra.CassandraService.MANAGEMENT_APPLICATION; import static org.apache.usergrid.persistence.cassandra.CassandraService.PRINCIPAL_TOKEN_CF; import static org.apache.usergrid.persistence.cassandra.CassandraService.PROPERTIES_CF; import static org.apache.usergrid.persistence.cassandra.CassandraService.TOKENS_CF; import static org.apache.usergrid.persistence.cassandra.CassandraService.getApplicationKeyspace; -import static org.apache.usergrid.persistence.cassandra.CassandraService.keyspaceForApplication; /** @@ -109,7 +98,8 @@ public class CpSetup implements Setup { injector.getInstance( DataMigrationManager.class ).migrate(); try { - emf.initializeApplicationV2( DEFAULT_ORGANIZATION, emf.getManagementAppId(), MANAGEMENT_APPLICATION, null ); + emf.initializeApplicationV2( DEFAULT_ORGANIZATION, emf.getManagementAppId(), + MANAGEMENT_APPLICATION, null, false); } catch ( ApplicationAlreadyExistsException ex ) { logger.warn( "Application {}/{} already exists", DEFAULT_ORGANIZATION, MANAGEMENT_APPLICATION ); http://git-wip-us.apache.org/repos/asf/usergrid/blob/f9028b24/stack/core/src/main/java/org/apache/usergrid/persistence/EntityManagerFactory.java ---------------------------------------------------------------------- diff --git a/stack/core/src/main/java/org/apache/usergrid/persistence/EntityManagerFactory.java b/stack/core/src/main/java/org/apache/usergrid/persistence/EntityManagerFactory.java index bde1bd2..2bd1ccb 100644 --- a/stack/core/src/main/java/org/apache/usergrid/persistence/EntityManagerFactory.java +++ b/stack/core/src/main/java/org/apache/usergrid/persistence/EntityManagerFactory.java @@ -17,16 +17,13 @@ package org.apache.usergrid.persistence; -import java.util.List; import java.util.Map; import java.util.UUID; import com.google.common.base.Optional; -import org.apache.usergrid.corepersistence.index.ReIndexService; import org.apache.usergrid.persistence.core.util.Health; import org.apache.usergrid.persistence.index.IndexRefreshCommand; -import rx.Observable; /** @@ -72,12 +69,13 @@ public interface EntityManagerFactory { * @param name the name of the application to create. * @param properties property values to create in the new entity or null. * + * @param forMigration * @return Entity of type application_info that represents the newly created Application * * @throws Exception the exception */ Entity createApplicationV2( - String organizationName, String name, UUID applicationId, Map<String, Object> properties ) throws Exception; + String organizationName, String name, UUID applicationId, Map<String, Object> properties, boolean forMigration) throws Exception; /** @@ -160,7 +158,7 @@ public interface EntityManagerFactory { * @return Entity of type application_info that represents the newly created application. */ public Entity initializeApplicationV2( - String orgName, UUID appId, String appName, Map<String, Object> props) throws Exception; + String orgName, UUID appId, String appName, Map<String, Object> props, boolean forMigration) throws Exception; http://git-wip-us.apache.org/repos/asf/usergrid/blob/f9028b24/stack/services/src/main/java/org/apache/usergrid/management/AppInfoMigrationPlugin.java ---------------------------------------------------------------------- diff --git a/stack/services/src/main/java/org/apache/usergrid/management/AppInfoMigrationPlugin.java b/stack/services/src/main/java/org/apache/usergrid/management/AppInfoMigrationPlugin.java index 6e84601..d05aa91 100644 --- a/stack/services/src/main/java/org/apache/usergrid/management/AppInfoMigrationPlugin.java +++ b/stack/services/src/main/java/org/apache/usergrid/management/AppInfoMigrationPlugin.java @@ -44,7 +44,6 @@ import org.apache.usergrid.persistence.core.migration.data.ProgressObserver; import org.apache.usergrid.persistence.core.scope.ApplicationScope; import org.apache.usergrid.persistence.entities.Group; import org.apache.usergrid.persistence.exceptions.ApplicationAlreadyExistsException; -import org.apache.usergrid.persistence.graph.Edge; import org.apache.usergrid.persistence.graph.GraphManager; import org.apache.usergrid.persistence.graph.GraphManagerFactory; import org.apache.usergrid.persistence.graph.MarkedEdge; @@ -203,7 +202,7 @@ public class AppInfoMigrationPlugin implements MigrationPlugin { } // create and connect new APPLICATION_INFO oldAppInfo to Organization - managementService.createApplication( orgRef.getUuid(), name, applicationId, null ); + managementService.createApplication( orgRef.getUuid(), name, applicationId, null, true); observer.update( getMaxVersion(), "Created application_info for " + appName ); } http://git-wip-us.apache.org/repos/asf/usergrid/blob/f9028b24/stack/services/src/main/java/org/apache/usergrid/management/ManagementService.java ---------------------------------------------------------------------- diff --git a/stack/services/src/main/java/org/apache/usergrid/management/ManagementService.java b/stack/services/src/main/java/org/apache/usergrid/management/ManagementService.java index cf2924b..e0afb46 100644 --- a/stack/services/src/main/java/org/apache/usergrid/management/ManagementService.java +++ b/stack/services/src/main/java/org/apache/usergrid/management/ManagementService.java @@ -71,8 +71,8 @@ public interface ManagementService { public ApplicationInfo createApplication( UUID organizationId, String applicationName ) throws Exception; public ApplicationInfo createApplication( UUID organizationId, String applicationName, Map<String, Object> properties ) throws Exception; - public ApplicationInfo createApplication( UUID organizationId, String applicationName, UUID applicationId, - Map<String, Object> properties ) throws Exception; + public ApplicationInfo createApplication(UUID organizationId, String applicationName, UUID applicationId, + Map<String, Object> properties, boolean forMigration) throws Exception; public OrganizationInfo createOrganization(String organizationName, UserInfo user, boolean activated) throws Exception; http://git-wip-us.apache.org/repos/asf/usergrid/blob/f9028b24/stack/services/src/main/java/org/apache/usergrid/management/cassandra/ManagementServiceImpl.java ---------------------------------------------------------------------- diff --git a/stack/services/src/main/java/org/apache/usergrid/management/cassandra/ManagementServiceImpl.java b/stack/services/src/main/java/org/apache/usergrid/management/cassandra/ManagementServiceImpl.java index f252705..7e1622a 100644 --- a/stack/services/src/main/java/org/apache/usergrid/management/cassandra/ManagementServiceImpl.java +++ b/stack/services/src/main/java/org/apache/usergrid/management/cassandra/ManagementServiceImpl.java @@ -1619,12 +1619,12 @@ public class ManagementServiceImpl implements ManagementService { @Override public ApplicationInfo createApplication( UUID organizationId, String applicationName, Map<String, Object> properties ) throws Exception { - return createApplication(organizationId, applicationName, null, properties); + return createApplication(organizationId, applicationName, null, properties, false); } @Override - public ApplicationInfo createApplication( UUID organizationId, String applicationName, UUID applicationId, - Map<String, Object> properties ) throws Exception { + public ApplicationInfo createApplication(UUID organizationId, String applicationName, UUID applicationId, + Map<String, Object> properties, boolean forMigration) throws Exception { if ( ( organizationId == null ) || ( applicationName == null ) ) { return null; @@ -1636,10 +1636,10 @@ public class ManagementServiceImpl implements ManagementService { OrganizationInfo organizationInfo = getOrganizationByUuid( organizationId ); Entity appInfo = emf.createApplicationV2( - organizationInfo.getName(), applicationName, applicationId ,properties); + organizationInfo.getName(), applicationName, applicationId ,properties, forMigration); - // only generate a client secret on app creation when you're creating an app that doesn't already exist - if( applicationId == null ){ + // only generate a client secret on app creation when the app is not being created during appinfo migration + if( !forMigration ){ writeUserToken( smf.getManagementAppId(), appInfo, encryptionService.plainTextCredentials( http://git-wip-us.apache.org/repos/asf/usergrid/blob/f9028b24/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 ef97188..aa3ba70 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 @@ -120,7 +120,7 @@ public class AppInfoMigrationPluginTest { List<Entity> deletedApps = new ArrayList<>(); setup.getEmf().initializeApplicationV2( - CassandraService.DEFAULT_ORGANIZATION, AppInfoMigrationPlugin.SYSTEM_APP_ID, "systemapp", null); + CassandraService.DEFAULT_ORGANIZATION, AppInfoMigrationPlugin.SYSTEM_APP_ID, "systemapp", null, false); EntityManager systemAppEm = setup.getEmf().getEntityManager( AppInfoMigrationPlugin.SYSTEM_APP_ID );