Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 94BA8200B49 for ; Wed, 3 Aug 2016 12:32:51 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 935F9160A86; Wed, 3 Aug 2016 10:32:51 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id AFB94160A64 for ; Wed, 3 Aug 2016 12:32:50 +0200 (CEST) Received: (qmail 58705 invoked by uid 500); 3 Aug 2016 10:32:49 -0000 Mailing-List: contact commits-help@ambari.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: ambari-dev@ambari.apache.org Delivered-To: mailing list commits@ambari.apache.org Received: (qmail 58696 invoked by uid 99); 3 Aug 2016 10:32:49 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 03 Aug 2016 10:32:49 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id BB84EE3839; Wed, 3 Aug 2016 10:32:49 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: gnagar@apache.org To: commits@ambari.apache.org Message-Id: X-Mailer: ASF-Git Admin Mailer Subject: ambari git commit: AMBARI-18000. Data can not be migrated from Hive 1.0 to Hive2. (gauravn7) Date: Wed, 3 Aug 2016 10:32:49 +0000 (UTC) archived-at: Wed, 03 Aug 2016 10:32:51 -0000 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 Authored: Wed Aug 3 16:02:12 2016 +0530 Committer: Gaurav Nagar 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 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 @@ 2.0.* + 1 + org.apache.ambari.view.hive2.DataMigrator + org.apache.ambari.view.hive2.PropertyValidator org.apache.ambari.view.hive2.HiveViewImpl