ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dbhowm...@apache.org
Subject ambari git commit: AMBARI-17691. Rerunning View data migration commands throwing exception.(Gaurav Nagar via dipayanb)
Date Thu, 14 Jul 2016 13:46:36 GMT
Repository: ambari
Updated Branches:
  refs/heads/trunk b515ff95d -> 33e1f301f


AMBARI-17691. Rerunning View data migration commands throwing exception.(Gaurav Nagar via
dipayanb)


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

Branch: refs/heads/trunk
Commit: 33e1f301fc2d5eecd8357c341801ba7a41319948
Parents: b515ff9
Author: Dipayan Bhowmick <dipayan.bhowmick@gmail.com>
Authored: Thu Jul 14 19:15:49 2016 +0530
Committer: Dipayan Bhowmick <dipayan.bhowmick@gmail.com>
Committed: Thu Jul 14 19:16:24 2016 +0530

----------------------------------------------------------------------
 .../view/ViewDataMigrationContextImpl.java      | 24 ++++++++++++++++++--
 .../server/view/ViewDataMigrationUtility.java   | 14 ++----------
 .../view/persistence/DataStoreModule.java       | 21 +++++++++++++++--
 .../src/main/resources/META-INF/persistence.xml | 12 ++++++++++
 4 files changed, 55 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/33e1f301/ambari-server/src/main/java/org/apache/ambari/server/view/ViewDataMigrationContextImpl.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/view/ViewDataMigrationContextImpl.java
b/ambari-server/src/main/java/org/apache/ambari/server/view/ViewDataMigrationContextImpl.java
index 909b3a1..e1734bd 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/view/ViewDataMigrationContextImpl.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/view/ViewDataMigrationContextImpl.java
@@ -18,6 +18,8 @@
 
 package org.apache.ambari.server.view;
 
+import com.google.inject.Binding;
+import com.google.inject.ConfigurationException;
 import com.google.inject.Guice;
 import com.google.inject.Injector;
 import com.google.inject.persist.Transactional;
@@ -37,8 +39,11 @@ import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.springframework.beans.BeanUtils;
 
+import javax.persistence.EntityManagerFactory;
 import java.util.HashMap;
 import java.util.Map;
+import java.util.UUID;
+import java.util.WeakHashMap;
 
 /**
  * View data migration context implementation.
@@ -82,6 +87,8 @@ public class ViewDataMigrationContextImpl implements ViewDataMigrationContext
{
     this.currentInstanceDefinition = currentInstanceDefinition;
   }
 
+  private Map<ViewInstanceEntity, DataStoreModule> dataStoreModules = new WeakHashMap<>();
+
   /**
    * Instantiates the data store associated with the instance.
    *
@@ -89,8 +96,12 @@ public class ViewDataMigrationContextImpl implements ViewDataMigrationContext
{
    * @return the data store object associated with view instance
    */
   protected DataStore getDataStore(ViewInstanceEntity instanceDefinition) {
-    Injector originInjector = Guice.createInjector(new DataStoreModule(instanceDefinition));
-    return originInjector.getInstance(DataStoreImpl.class);
+    if (!dataStoreModules.containsKey(instanceDefinition)) {
+      DataStoreModule module = new DataStoreModule(instanceDefinition,"ambari-view-migration");
+      dataStoreModules.put(instanceDefinition, module);
+    }
+    Injector injector = Guice.createInjector(dataStoreModules.get(instanceDefinition));
+    return injector.getInstance(DataStoreImpl.class);
   }
 
   @Override
@@ -222,6 +233,15 @@ public class ViewDataMigrationContextImpl implements ViewDataMigrationContext
{
     return getInstanceDataByUser(currentInstanceDefinition);
   }
 
+  public void closeMigration() {
+
+    for (DataStoreModule module : dataStoreModules.values()) {
+      module.close();
+    }
+
+    dataStoreModules.clear();
+  }
+
   /**
    * Save an instance data value for the given key owned by given user.
    *

http://git-wip-us.apache.org/repos/asf/ambari/blob/33e1f301/ambari-server/src/main/java/org/apache/ambari/server/view/ViewDataMigrationUtility.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/view/ViewDataMigrationUtility.java
b/ambari-server/src/main/java/org/apache/ambari/server/view/ViewDataMigrationUtility.java
index 15318c0..6f427cc 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/view/ViewDataMigrationUtility.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/view/ViewDataMigrationUtility.java
@@ -55,18 +55,6 @@ public class ViewDataMigrationUtility {
    * Migrates data from source to target instance
    * @param targetInstanceDefinition target instance entity
    * @param sourceInstanceDefinition source instance entity
-   *
-   * @throws ViewDataMigrationException when view does not support migration or an error
during migration occurs.
-   */
-  public void migrateDataOnce(ViewInstanceEntity targetInstanceDefinition, ViewInstanceEntity
sourceInstanceDefinition)
-      throws ViewDataMigrationException {
-    ViewDataMigrationContextImpl migrationContext = getViewDataMigrationContext(targetInstanceDefinition,
sourceInstanceDefinition);
-  }
-
-  /**
-   * Migrates data from source to target instance
-   * @param targetInstanceDefinition target instance entity
-   * @param sourceInstanceDefinition source instance entity
    * @param migrateOnce cancel if previously migrated
    *
    * @throws ViewDataMigrationException when view does not support migration or an error
during migration occurs.
@@ -116,6 +104,8 @@ public class ViewDataMigrationUtility {
     viewRegistry.copyPrivileges(sourceInstanceDefinition, targetInstanceDefinition);
 
     migrationContext.putCurrentInstanceData("upgrade", "upgradedFrom", sourceInstanceDefinition.getViewEntity().getVersion());
+
+    migrationContext.closeMigration();
   }
 
   private boolean isTargetEmpty(ViewDataMigrationContext migrationContext) {

http://git-wip-us.apache.org/repos/asf/ambari/blob/33e1f301/ambari-server/src/main/java/org/apache/ambari/server/view/persistence/DataStoreModule.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/view/persistence/DataStoreModule.java
b/ambari-server/src/main/java/org/apache/ambari/server/view/persistence/DataStoreModule.java
index a995868..488c511 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/view/persistence/DataStoreModule.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/view/persistence/DataStoreModule.java
@@ -18,6 +18,7 @@
 
 package org.apache.ambari.server.view.persistence;
 
+import com.google.common.base.Optional;
 import com.google.inject.Binder;
 import com.google.inject.Module;
 import org.apache.ambari.server.configuration.Configuration;
@@ -67,6 +68,7 @@ public class DataStoreModule implements Module, SchemaManagerFactory {
    * View persistence unit name.
    */
   private static final String VIEWS_PERSISTENCE_UNIT_NAME = "ambari-views";
+  private Optional<String> puName = Optional.absent();
 
 
   // ----- Constructors ------------------------------------------------------
@@ -80,6 +82,16 @@ public class DataStoreModule implements Module, SchemaManagerFactory {
     this.jpaDynamicHelper     = new JPADynamicHelper(entityManagerFactory.createEntityManager());
   }
 
+  public DataStoreModule(ViewInstanceEntity viewInstanceEntity,String puName) {
+    this.puName = Optional.of(puName);
+    ViewEntity view = viewInstanceEntity.getViewEntity();
+
+    this.viewInstanceEntity   = viewInstanceEntity;
+    this.classLoader          = new DynamicClassLoader(view.getClassLoader());
+    this.entityManagerFactory = getEntityManagerFactory(view.getAmbariConfiguration());
+    this.jpaDynamicHelper     = new JPADynamicHelper(entityManagerFactory.createEntityManager());
+  }
+
 
   // ----- Module ------------------------------------------------------------
 
@@ -93,14 +105,18 @@ public class DataStoreModule implements Module, SchemaManagerFactory
{
   }
 
 
+  public void close() {
+    entityManagerFactory.close();
+  }
+
   // ----- SchemaManagerFactory ----------------------------------------------
 
+
   @Override
   public SchemaManager getSchemaManager(DatabaseSession session) {
     return new SchemaManager(session);
   }
 
-
   // ----- helper methods ----------------------------------------------------
 
   // get an entity manager factory for the given class loader and configuration
@@ -113,6 +129,7 @@ public class DataStoreModule implements Module, SchemaManagerFactory {
       persistenceMap.put(PersistenceUnitProperties.CLASSLOADER, classLoader);
       persistenceMap.put(PersistenceUnitProperties.WEAVING, "static");
     }
-    return Persistence.createEntityManagerFactory(VIEWS_PERSISTENCE_UNIT_NAME, persistenceMap);
+
+    return Persistence.createEntityManagerFactory(puName.isPresent()?puName.get():VIEWS_PERSISTENCE_UNIT_NAME,
persistenceMap);
   }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ambari/blob/33e1f301/ambari-server/src/main/resources/META-INF/persistence.xml
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/META-INF/persistence.xml b/ambari-server/src/main/resources/META-INF/persistence.xml
index d44f484..2bc3282 100644
--- a/ambari-server/src/main/resources/META-INF/persistence.xml
+++ b/ambari-server/src/main/resources/META-INF/persistence.xml
@@ -122,4 +122,16 @@
       <property name="eclipselink.logging.level" value="INFO"/>
     </properties>
   </persistence-unit>
+  <persistence-unit name="ambari-view-migration" transaction-type="RESOURCE_LOCAL">
+    <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
+    <exclude-unlisted-classes>false</exclude-unlisted-classes>
+    <properties>
+      <property name="eclipselink.cache.size.default" value="10000" />
+      <property name="eclipselink.jdbc.batch-writing" value="JDBC"/>
+      <property name="eclipselink.weaving" value="static" />
+      <property name="eclipselink.logging.logger" value="org.apache.ambari.server.logging.EclipseLinkLogger"/>
+      <property name="eclipselink.logging.level" value="INFO"/>
+    </properties>
+  </persistence-unit>
+
 </persistence>


Mime
View raw message