usergrid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdun...@apache.org
Subject [44/44] usergrid git commit: In progress, not working
Date Sat, 26 Sep 2015 01:42:49 GMT
In progress, not working


Project: http://git-wip-us.apache.org/repos/asf/usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/usergrid/commit/a5185f2e
Tree: http://git-wip-us.apache.org/repos/asf/usergrid/tree/a5185f2e
Diff: http://git-wip-us.apache.org/repos/asf/usergrid/diff/a5185f2e

Branch: refs/heads/USERGRID-933
Commit: a5185f2e72a3be91a8eac35f1b96a2cc1f72e8f8
Parents: 5ead5fd
Author: Mike Dunker <mdunker@apache.org>
Authored: Fri Sep 25 18:30:04 2015 -0700
Committer: Mike Dunker <mdunker@apache.org>
Committed: Fri Sep 25 18:30:04 2015 -0700

----------------------------------------------------------------------
 .../usergrid/corepersistence/CoreModule.java    |   6 +-
 .../corepersistence/CpEntityManagerFactory.java |  14 +-
 .../ManagementOrganizationDataMigration.java    | 155 +++++++++++++++++++
 .../corepersistence/util/CpNamingUtils.java     |  32 +++-
 .../persistence/EntityManagerFactory.java       |   2 +
 .../persistence/cassandra/CassandraService.java |   1 +
 .../usergrid/management/OrganizationConfig.java |   5 +
 .../cassandra/ManagementServiceImpl.java        |   6 +-
 .../migration/AppInfoMigrationPluginTest.java   |   2 +-
 9 files changed, 204 insertions(+), 19 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/usergrid/blob/a5185f2e/stack/core/src/main/java/org/apache/usergrid/corepersistence/CoreModule.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CoreModule.java
b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CoreModule.java
index 486aa6f..8e4e58f 100644
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CoreModule.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CoreModule.java
@@ -16,6 +16,7 @@
 package org.apache.usergrid.corepersistence;
 
 
+import org.apache.usergrid.corepersistence.migration.*;
 import org.safehaus.guicyfig.GuicyFigModule;
 
 import org.apache.usergrid.corepersistence.asyncevents.AsyncEventService;
@@ -31,10 +32,6 @@ import org.apache.usergrid.corepersistence.index.IndexService;
 import org.apache.usergrid.corepersistence.index.IndexServiceImpl;
 import org.apache.usergrid.corepersistence.index.ReIndexService;
 import org.apache.usergrid.corepersistence.index.ReIndexServiceImpl;
-import org.apache.usergrid.corepersistence.migration.CoreMigration;
-import org.apache.usergrid.corepersistence.migration.CoreMigrationPlugin;
-import org.apache.usergrid.corepersistence.migration.DeDupConnectionDataMigration;
-import org.apache.usergrid.corepersistence.migration.MigrationModuleVersionPlugin;
 import org.apache.usergrid.corepersistence.pipeline.PipelineModule;
 import org.apache.usergrid.corepersistence.rx.impl.AllApplicationsObservable;
 import org.apache.usergrid.corepersistence.rx.impl.AllApplicationsObservableImpl;
@@ -131,6 +128,7 @@ public class CoreModule  extends AbstractModule {
 
 
         dataMigrationMultibinder.addBinding().to( DeDupConnectionDataMigration.class );
+        dataMigrationMultibinder.addBinding().to( ManagementOrganizationDataMigration.class
);
 
 
         //wire up the collection migration plugin

http://git-wip-us.apache.org/repos/asf/usergrid/blob/a5185f2e/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 4bdade5..8985f3d 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
@@ -71,6 +71,7 @@ import org.apache.usergrid.persistence.model.entity.Id;
 import org.apache.usergrid.persistence.model.entity.SimpleId;
 import org.apache.usergrid.persistence.model.util.UUIDGenerator;
 import org.apache.usergrid.utils.UUIDUtils;
+import org.apache.usergrid.corepersistence.util.CpNamingUtils;
 
 import com.google.common.base.Optional;
 import com.google.common.cache.CacheBuilder;
@@ -166,7 +167,7 @@ public class CpEntityManagerFactory implements EntityManagerFactory, Application
             if ( em.getApplication() == null ) {
                 logger.info("Creating management application");
                 Map mgmtAppProps = new HashMap<String, Object>();
-                mgmtAppProps.put(PROPERTY_NAME, "systemapp");
+                mgmtAppProps.put(PROPERTY_NAME, CassandraService.MANAGEMENT_APPLICATION);
                 em.create( getManagementAppId(), TYPE_APPLICATION, mgmtAppProps);
                 em.getApplication();
             }
@@ -448,7 +449,7 @@ public class CpEntityManagerFactory implements EntityManagerFactory, Application
 
     @Override
     public Map<String, UUID> getApplications() throws Exception {
-        return getApplications( CpNamingUtils.getEdgeTypeFromCollectionName( CpNamingUtils.APPLICATION_INFOS
) );
+        return getApplications(CpNamingUtils.getEdgeTypeFromCollectionName( CpNamingUtils.APPLICATION_INFOS
) );
     }
 
 
@@ -504,7 +505,7 @@ public class CpEntityManagerFactory implements EntityManagerFactory, Application
                             final String applicationName = ( String ) entityData.getField(
PROPERTY_NAME ).getValue();
 
                             appMap.put( applicationName , applicationId );
-                        } ).toBlocking().last();
+                    } ).toBlocking().last();
     }
 
 
@@ -578,7 +579,7 @@ public class CpEntityManagerFactory implements EntityManagerFactory, Application
 
         // intentionally going only one-level deep into fields and treating all
         // values as strings because that is all we need for service properties
-        for ( String key : properties.keySet() ) {
+        for ( String key : properties.keySet()) {
             propsEntity.setProperty(key, properties.get(key).toString());
         }
 
@@ -669,6 +670,11 @@ public class CpEntityManagerFactory implements EntityManagerFactory,
Application
     }
 
     @Override
+    public UUID getManagementOrgId() {
+        return CpNamingUtils.MANAGEMENT_ORGANIZATION_ID;
+    }
+
+    @Override
     public EntityManager getManagementEntityManager() {
         return getEntityManager(CpNamingUtils.MANAGEMENT_APPLICATION_ID);
     }

http://git-wip-us.apache.org/repos/asf/usergrid/blob/a5185f2e/stack/core/src/main/java/org/apache/usergrid/corepersistence/migration/ManagementOrganizationDataMigration.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/migration/ManagementOrganizationDataMigration.java
b/stack/core/src/main/java/org/apache/usergrid/corepersistence/migration/ManagementOrganizationDataMigration.java
new file mode 100644
index 0000000..66f4b71
--- /dev/null
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/migration/ManagementOrganizationDataMigration.java
@@ -0,0 +1,155 @@
+/*
+ * 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.
+ */
+
+package org.apache.usergrid.corepersistence.migration;
+
+
+import com.google.inject.Inject;
+import com.google.inject.Singleton;
+import org.apache.usergrid.corepersistence.util.CpNamingUtils;
+import org.apache.usergrid.persistence.*;
+import org.apache.usergrid.persistence.cassandra.CassandraService;
+import org.apache.usergrid.persistence.core.migration.data.DataMigration;
+import org.apache.usergrid.persistence.core.migration.data.ProgressObserver;
+import org.apache.usergrid.persistence.entities.Application;
+import org.apache.usergrid.persistence.entities.Group;
+import static org.apache.usergrid.persistence.Schema.*;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.UUID;
+
+
+@Singleton
+public class ManagementOrganizationDataMigration implements DataMigration {
+
+    private static final Logger logger = LoggerFactory.getLogger(ManagementOrganizationDataMigration.class);
+
+    private final EntityManagerFactory entityManagerFactory;
+    private final ManagementService managementService;
+
+    @Inject
+    public ManagementOrganizationDataMigration(final EntityManagerFactory entityManagerFactory,
final ManagementService managementService) {
+        this.entityManagerFactory = entityManagerFactory;
+        this.managementService = managementService;
+    }
+
+
+    @Override
+    public int migrate( final int currentVersion, final ProgressObserver observer ) {
+
+        final int migrationVersion = getMaxVersion();
+
+        observer.start();
+
+        EntityManager em = entityManagerFactory.getEntityManager(CpNamingUtils.MANAGEMENT_APPLICATION_ID);
+
+        UUID managementAppId = entityManagerFactory.getManagementAppId();
+        UUID managementOrgId = entityManagerFactory.getManagementOrgId();
+        String managementAppName = CassandraService.MANAGEMENT_APPLICATION;
+        String managementOrgName = CassandraService.DEFAULT_ORGANIZATION;
+        String managementOrgPlusAppName = CassandraService.MANAGEMENT_ORGPLUSAPP;
+        Application app = null;
+
+        // make sure management app exists
+        try {
+            app = em.getApplication();
+            if (app == null) {
+                // create the management application
+                entityManagerFactory.createApplicationV2(managementOrgName, managementAppName,
+                        managementAppId, null);
+                app = em.getApplication();
+            } else if (!managementAppName.equals(app.getName())) {
+                logger.info(String.format("Management application name is %s, should be %s",
app.getName(), managementOrgPlusAppName));
+                observer.update(migrationVersion, String.format("Management application name
is %s, should be %s", app.getName(), managementOrgPlusAppName));
+            }
+        } catch (Exception e) {
+            // should never happen -- abort
+            logger.error("MANAGEMENT APPLICATION ERROR", e);
+            observer.failed(migrationVersion, String.format("MANAGEMENT APPLICATION ERROR:
%s", e.getMessage()));
+            return currentVersion;
+        }
+
+        // check for existence of management org, and create if necessary
+        boolean createdOrg = false;
+        try {
+            if (!em.isPropertyValueUniqueForEntity(Group.ENTITY_TYPE, PROPERTY_PATH, managementOrgName))
{
+                // organization already exists
+                logger.info(String.format("Organization with name %s already exists", managementOrgName));
+                observer.update(migrationVersion, String.format("Management organization
%s already exists", managementOrgName));
+            } else if (!em.isPropertyValueUniqueForEntity(Group.ENTITY_TYPE, PROPERTY_UUID,
managementOrgId)) {
+                // organization does not have correct UUID
+                logger.error("Organization that has management organization UUID does not
have correct organization name");
+                observer.failed(migrationVersion, "Organization that has management organization
UUID does not have correct organization name");
+                return migrationVersion;
+            } else {
+                // create management org
+                Group organizationEntity = new Group();
+                organizationEntity.setPath(managementOrgName);
+                em.create(managementOrgId, Group.ENTITY_TYPE, organizationEntity.getProperties());
+                logger.info("Management org created");
+                createdOrg = true;
+            }
+        } catch (Exception e) {
+            // error with management org
+            logger.error("MANAGEMENT ORGANIZATION ERROR", e);
+            observer.update(migrationVersion, String.format("MANAGEMENT ORGANIZATION ERROR:
%s", e.getMessage()));
+        }
+
+        // add org property to app
+        if (createdOrg && app != null && !managementOrgName.equals(app.getProperty("org")))
{
+            try {
+                app.setProperty("org", managementOrgName);
+                em.update(app);
+                logger.info("Management app updated with management org");
+            } catch (Exception e) {
+                // error linking management app to management org
+                logger.error("ERROR ADDING MANAGEMENT ORG TO MANAGEMENT APP", e);
+                observer.update(migrationVersion, String.format("ERROR ADDING MANAGEMENT
ORG TO MANAGEMENT APP: %s", e.getMessage()));
+            }
+        }
+
+        // add connection
+        if (app != null) {
+            if (managementService)
+            Results r = em.getSourceEntities(new SimpleEntityRef(CpNamingUtils.APPLICATION_INFO,
managementAppId),
+                    ORG_APP_RELATIONSHIP, Group.ENTITY_TYPE, Query.Level.ALL_PROPERTIES);
+            Entity entity = r.getEntity();
+            if (entity == null) {
+                // add the connection
+            }
+        }
+
+
+        observer.complete();
+
+        return migrationVersion;
+
+    }
+
+
+    @Override
+    public boolean supports( final int currentVersion ) {
+        return currentVersion == getMaxVersion() - 1;
+    }
+
+
+    @Override
+    public int getMaxVersion() {
+        return 3;
+    }
+}

http://git-wip-us.apache.org/repos/asf/usergrid/blob/a5185f2e/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 55bc49a..b7e90fe 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
@@ -21,6 +21,7 @@ package org.apache.usergrid.corepersistence.util;
 
 import java.util.UUID;
 
+import org.apache.usergrid.persistence.cassandra.CassandraService;
 import org.apache.usergrid.persistence.core.scope.ApplicationScope;
 import org.apache.usergrid.persistence.core.scope.ApplicationScopeImpl;
 import org.apache.usergrid.persistence.entities.Application;
@@ -65,8 +66,9 @@ public class CpNamingUtils {
      */
     private static final int EDGE_CONN_PREFIX_LENGTH = EDGE_CONN_PREFIX.length()+1;
 
-    /** App where we store management info */
+    /** App/org where we store management info */
     public static final UUID MANAGEMENT_APPLICATION_ID = UUID.fromString( "b6768a08-b5d5-11e3-a495-11ddb1de66c8"
);
+    public static final UUID MANAGEMENT_ORGANIZATION_ID = UUID.fromString( "d090d165-7dd8-4132-8aa2-7e0ec5484c7f"
);
 
     /**
      * Information about applications is stored in the management app using these types
@@ -103,7 +105,7 @@ public class CpNamingUtils {
      * @return
      */
     public static String getConnectionNameFromEdgeName(final String edgeName){
-        return edgeName.substring( EDGE_CONN_PREFIX_LENGTH );
+        return edgeName.substring(EDGE_CONN_PREFIX_LENGTH);
     }
 
     /**
@@ -121,7 +123,7 @@ public class CpNamingUtils {
        * @return
        */
       public static String getCollectionNameFromEdgeName(final String edgeName){
-          return edgeName.substring( EDGE_COLL_PREFIX_LENGTH );
+          return edgeName.substring(EDGE_COLL_PREFIX_LENGTH);
       }
 
 
@@ -177,7 +179,7 @@ public class CpNamingUtils {
      * TODO move sourceId to ApplicationScope
      */
     public static Edge createCollectionEdge( final Id sourceId, final String collectionName,
final Id entityId ) {
-        final String edgeType = CpNamingUtils.getEdgeTypeFromCollectionName( collectionName
);
+        final String edgeType = CpNamingUtils.getEdgeTypeFromCollectionName(collectionName);
 
 
         // create graph edge connection from head entity to member entity
@@ -270,12 +272,22 @@ public class CpNamingUtils {
 
 
     /**
+     * Generate an entity Id from the given UUID
+     *
+     * @param entityId the entity's UUID
+     */
+    protected static Id generateEntityId( UUID entityId ) {
+        return new SimpleId( entityId, Application.ENTITY_TYPE );
+    }
+
+
+    /**
      * Generate an applicationId from the given UUID
      *
      * @param applicationId the applicationId
      */
     public static Id generateApplicationId( UUID applicationId ) {
-        return new SimpleId( applicationId, Application.ENTITY_TYPE );
+        return generateEntityId( applicationId );
     }
 
 
@@ -283,7 +295,15 @@ public class CpNamingUtils {
      * Generate an application scope for the management application
      */
     public static Id getManagementApplicationId() {
-        return generateApplicationId( MANAGEMENT_APPLICATION_ID );
+        return generateEntityId(MANAGEMENT_APPLICATION_ID);
+    }
+
+
+    /**
+     * Generate an id for the management organization
+     */
+    public static Id getManagementOrganizationId() {
+        return generateEntityId(MANAGEMENT_ORGANIZATION_ID);
     }
 
 

http://git-wip-us.apache.org/repos/asf/usergrid/blob/a5185f2e/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..befcc83 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
@@ -166,6 +166,8 @@ public interface EntityManagerFactory {
 
     public UUID getManagementAppId();
 
+    public UUID getManagementOrgId();
+
     public IndexRefreshCommand.IndexRefreshCommandInfo refreshIndex(UUID applicationId);
 
     /**

http://git-wip-us.apache.org/repos/asf/usergrid/blob/a5185f2e/stack/core/src/main/java/org/apache/usergrid/persistence/cassandra/CassandraService.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/persistence/cassandra/CassandraService.java
b/stack/core/src/main/java/org/apache/usergrid/persistence/cassandra/CassandraService.java
index a08c543..85fcd7f 100644
--- a/stack/core/src/main/java/org/apache/usergrid/persistence/cassandra/CassandraService.java
+++ b/stack/core/src/main/java/org/apache/usergrid/persistence/cassandra/CassandraService.java
@@ -79,6 +79,7 @@ public class CassandraService {
     public static final String DEFAULT_APPLICATION = "default-app";
     public static final String DEFAULT_ORGANIZATION = "usergrid";
     public static final String MANAGEMENT_APPLICATION = "management";
+    public static final String MANAGEMENT_ORGPLUSAPP = "usergrid/management";
 
     private static final Logger logger = LoggerFactory.getLogger( CassandraService.class
);
 

http://git-wip-us.apache.org/repos/asf/usergrid/blob/a5185f2e/stack/services/src/main/java/org/apache/usergrid/management/OrganizationConfig.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/management/OrganizationConfig.java
b/stack/services/src/main/java/org/apache/usergrid/management/OrganizationConfig.java
index bc22dad..276bad8 100644
--- a/stack/services/src/main/java/org/apache/usergrid/management/OrganizationConfig.java
+++ b/stack/services/src/main/java/org/apache/usergrid/management/OrganizationConfig.java
@@ -69,6 +69,11 @@ public class OrganizationConfig {
     private OrganizationConfig() {
     }
 
+    public OrganizationConfig(OrganizationConfigProps configFileProperties) {
+        setDefaultProperties(configFileProperties);
+        // will add id and name once default org exists
+    }
+
     public OrganizationConfig(OrganizationConfigProps configFileProperties, UUID id, String
name) {
         setDefaultProperties(configFileProperties);
         this.id = id;

http://git-wip-us.apache.org/repos/asf/usergrid/blob/a5185f2e/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 329f0d2..198798b 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
@@ -3214,12 +3214,10 @@ public class ManagementServiceImpl implements ManagementService {
         if ( entity != null ) {
             Map entityProperties = em.getDictionaryAsMap(entity, ORGANIZATION_CONFIG_DICTIONARY);
             return new OrganizationConfig(orgConfigProperties, entity.getUuid(), entity.getName(),
entityProperties);
-        } else {
-            // return the defaults
-            return new OrganizationConfig(orgConfigProperties)
         }
 
-        return null;
+        // return the defaults
+        return new OrganizationConfig(orgConfigProperties);
     }
 
 

http://git-wip-us.apache.org/repos/asf/usergrid/blob/a5185f2e/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..cad9cca 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,
CassandraService.MANAGEMENT_APPLICATION, null);
 
         EntityManager systemAppEm = setup.getEmf().getEntityManager( AppInfoMigrationPlugin.SYSTEM_APP_ID
);
 


Mime
View raw message