You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by gn...@apache.org on 2016/08/03 10:32:49 UTC
ambari git commit: AMBARI-18000. Data can not be migrated from Hive
1.0 to Hive2. (gauravn7)
Repository: ambari
Updated Branches:
refs/heads/branch-2.4 bd5a5c58d -> 8c6813c26
AMBARI-18000. Data can not be migrated from Hive 1.0 to Hive2. (gauravn7)
Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/8c6813c2
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/8c6813c2
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/8c6813c2
Branch: refs/heads/branch-2.4
Commit: 8c6813c264f19351fac77385cf2da54dc6b175e1
Parents: bd5a5c5
Author: Gaurav Nagar <gn...@hortonworks.com>
Authored: Wed Aug 3 16:02:12 2016 +0530
Committer: Gaurav Nagar <gn...@hortonworks.com>
Committed: Wed Aug 3 16:02:12 2016 +0530
----------------------------------------------------------------------
.../server/view/ViewDataMigrationUtility.java | 3 +
.../apache/ambari/view/hive2/DataMigrator.java | 101 +++++++++++++++++++
.../views/hive-next/src/main/resources/view.xml | 3 +
3 files changed, 107 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ambari/blob/8c6813c2/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 6f427cc..2906100 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
@@ -207,6 +207,9 @@ public class ViewDataMigrationUtility {
@Override
public void migrateEntity(Class originEntityClass, Class currentEntityClass)
throws ViewDataMigrationException {
+ if (currentEntityClass == null) {
+ return;
+ }
migrationContext.copyAllObjects(originEntityClass, currentEntityClass);
}
http://git-wip-us.apache.org/repos/asf/ambari/blob/8c6813c2/contrib/views/hive-next/src/main/java/org/apache/ambari/view/hive2/DataMigrator.java
----------------------------------------------------------------------
diff --git a/contrib/views/hive-next/src/main/java/org/apache/ambari/view/hive2/DataMigrator.java b/contrib/views/hive-next/src/main/java/org/apache/ambari/view/hive2/DataMigrator.java
new file mode 100644
index 0000000..b33df65
--- /dev/null
+++ b/contrib/views/hive-next/src/main/java/org/apache/ambari/view/hive2/DataMigrator.java
@@ -0,0 +1,101 @@
+/**
+ * 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.ambari.view.hive2;
+
+import org.apache.ambari.view.ViewContext;
+import org.apache.ambari.view.migration.ViewDataMigrationContext;
+import org.apache.ambari.view.migration.ViewDataMigrationException;
+import org.apache.ambari.view.migration.ViewDataMigrator;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.inject.Inject;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Data migrator that maps persistence entities names
+ * from Hive 1 to entities of Hive 2.
+ */
+public class DataMigrator implements ViewDataMigrator {
+ private final static Logger LOG =
+ LoggerFactory.getLogger(DataMigrator.class);
+
+ /**
+ * The view context of target migration instance.
+ */
+ @Inject
+ private ViewContext viewContext;
+
+ /**
+ * The migration context.
+ */
+ @Inject
+ private ViewDataMigrationContext migrationContext;
+
+ private static final Map<String, Class> hive1EntitiesMapping;
+ static
+ {
+ hive1EntitiesMapping = new HashMap<>();
+ hive1EntitiesMapping.put("org.apache.ambari.view.hive.resources.jobs.viewJobs.JobImpl",
+ org.apache.ambari.view.hive2.resources.jobs.viewJobs.JobImpl.class);
+ hive1EntitiesMapping.put("org.apache.ambari.view.hive.resources.savedQueries.SavedQuery",
+ org.apache.ambari.view.hive2.resources.savedQueries.SavedQuery.class);
+ hive1EntitiesMapping.put("org.apache.ambari.view.hive.resources.udfs.UDF",
+ org.apache.ambari.view.hive2.resources.udfs.UDF.class);
+ hive1EntitiesMapping.put("org.apache.ambari.view.hive.resources.resources.FileResourceItem",
+ org.apache.ambari.view.hive2.resources.resources.FileResourceItem.class);
+ hive1EntitiesMapping.put("org.apache.ambari.view.hive.TestBean",
+ org.apache.ambari.view.hive2.TestBean.class);
+ }
+
+ @Override
+ public boolean beforeMigration() throws ViewDataMigrationException {
+ return isHive1();
+ }
+
+ @Override
+ public void afterMigration() throws ViewDataMigrationException {
+ }
+
+ @Override
+ public void migrateEntity(Class originEntityClass, Class currentEntityClass) throws ViewDataMigrationException {
+ if (isHive1()) {
+ currentEntityClass = hive1EntitiesMapping.get(originEntityClass.getCanonicalName());
+ if (currentEntityClass == null) {
+ LOG.debug("Mapping was not found for class " + originEntityClass.getCanonicalName());
+ return;
+ }
+
+ migrationContext.copyAllObjects(originEntityClass, currentEntityClass);
+
+ } else {
+ LOG.warn("Unknown migration policy for class");
+ }
+ }
+
+ @Override
+ public void migrateInstanceData() throws ViewDataMigrationException {
+ migrationContext.copyAllInstanceData();
+ }
+
+ private boolean isHive1() {
+ return migrationContext.getOriginDataVersion() < 1;
+ }
+}
http://git-wip-us.apache.org/repos/asf/ambari/blob/8c6813c2/contrib/views/hive-next/src/main/resources/view.xml
----------------------------------------------------------------------
diff --git a/contrib/views/hive-next/src/main/resources/view.xml b/contrib/views/hive-next/src/main/resources/view.xml
index 52fe3ec..1754686 100644
--- a/contrib/views/hive-next/src/main/resources/view.xml
+++ b/contrib/views/hive-next/src/main/resources/view.xml
@@ -22,6 +22,9 @@
<min-ambari-version>2.0.*</min-ambari-version>
+ <data-version>1</data-version>
+ <data-migrator-class>org.apache.ambari.view.hive2.DataMigrator</data-migrator-class>
+
<validator-class>org.apache.ambari.view.hive2.PropertyValidator</validator-class>
<view-class>org.apache.ambari.view.hive2.HiveViewImpl</view-class>