Repository: ambari Updated Branches: refs/heads/trunk d64868e72 -> 10ebfde7b
AMBARI-18018 : added upgrade method to update the existing hive view's timestamp from seconds to miliseconds (nitirajrathore) Project: http://git-wip-us.apache.org/repos/asf/ambari/repo Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/10ebfde7 Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/10ebfde7 Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/10ebfde7 Branch: refs/heads/trunk Commit: 10ebfde7ba45ab5018fd93590df4d8771483bdc1 Parents: d64868e Author: Nitiraj Rathore <[email protected]> Authored: Fri Aug 5 00:23:26 2016 +0530 Committer: Nitiraj Rathore <[email protected]> Committed: Fri Aug 5 00:26:04 2016 +0530 ---------------------------------------------------------------------- .../server/upgrade/UpgradeCatalog240.java | 102 ++++++++++++------- .../server/upgrade/UpgradeCatalog240Test.java | 3 + 2 files changed, 70 insertions(+), 35 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ambari/blob/10ebfde7/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog240.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog240.java b/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog240.java index 6c0fb70..2cc66be 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog240.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog240.java @@ -18,30 +18,17 @@ package org.apache.ambari.server.upgrade; -import javax.persistence.EntityManager; -import javax.persistence.Query; -import javax.persistence.TypedQuery; - -import java.io.File; -import java.io.FileReader; -import java.lang.reflect.Type; -import java.sql.Clob; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.sql.Statement; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.UUID; -import java.util.concurrent.atomic.AtomicLong; - +import com.google.common.collect.Lists; +import com.google.common.reflect.TypeToken; +import com.google.gson.Gson; +import com.google.gson.JsonArray; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import com.google.gson.JsonParser; +import com.google.gson.JsonPrimitive; +import com.google.inject.Inject; +import com.google.inject.Injector; +import com.google.inject.persist.Transactional; import org.apache.ambari.server.AmbariException; import org.apache.ambari.server.agent.RecoveryConfigHelper; import org.apache.ambari.server.api.services.AmbariMetaInfo; @@ -109,17 +96,28 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.jdbc.support.JdbcUtils; -import com.google.common.collect.Lists; -import com.google.common.reflect.TypeToken; -import com.google.gson.Gson; -import com.google.gson.JsonArray; -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; -import com.google.gson.JsonParser; -import com.google.gson.JsonPrimitive; -import com.google.inject.Inject; -import com.google.inject.Injector; -import com.google.inject.persist.Transactional; +import javax.persistence.EntityManager; +import javax.persistence.Query; +import javax.persistence.TypedQuery; +import java.io.File; +import java.io.FileReader; +import java.lang.reflect.Type; +import java.sql.Clob; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Statement; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.UUID; +import java.util.concurrent.atomic.AtomicLong; /** * Upgrade catalog for version 2.4.0. @@ -424,6 +422,7 @@ public class UpgradeCatalog240 extends AbstractUpgradeCatalog { updateRecoveryConfigurationDML(); updatePigSmokeTestEntityClass(); updateRangerHbasePluginProperties(); + adjustHiveJobTimestamps(); } /** @@ -530,6 +529,39 @@ public class UpgradeCatalog240 extends AbstractUpgradeCatalog { } } + + /** + * get all entries of viewentity + * find all the table names by parsing class_name + * update jobimpls creation timestamp * 1000 + */ + protected void adjustHiveJobTimestamps() { + LOG.info("updateSequenceForView called."); + EntityManager entityManager = getEntityManagerProvider().get(); + TypedQuery<ViewEntityEntity> viewEntityQuery = entityManager.createQuery("SELECT vee FROM ViewEntityEntity vee where vee.className = 'org.apache.ambari.view.hive.resources.jobs.viewJobs.JobImpl'", ViewEntityEntity.class); + List<ViewEntityEntity> viewEntities = viewEntityQuery.getResultList(); + LOG.info("Received JobImpl view Entities : {}, length : {}", viewEntities, viewEntities.size()); + + String selectIdsFormat = "update %s set ds_datesubmitted = ds_datesubmitted * 1000"; + for (ViewEntityEntity viewEntity : viewEntities) { + LOG.info("Working with JobImpl viewEntity : {} : {} ", viewEntity, viewEntity.getViewName() + ":" + viewEntity.getViewInstanceName() + ":" + viewEntity.getClassName()); + String tableName = getEntityName(viewEntity); + try { + entityManager.getTransaction().begin(); + String updatesQueryString = String.format(selectIdsFormat, tableName).toLowerCase(); + LOG.info("executing update query string for jobimpl {}", updatesQueryString); + Query updateQuery = entityManager.createNativeQuery(updatesQueryString); + int rowsChanged = updateQuery.executeUpdate(); + entityManager.getTransaction().commit(); + LOG.info("executing update on jobimpl resulted in {} row changes.", rowsChanged); + } catch (Exception e) { // when the entity table is not yet created or other exception. + entityManager.getTransaction().rollback(); + LOG.info("Error (can be ignored) {}", e.getMessage()); + LOG.debug("Exception occured while updating : {}",viewEntity.getViewName() + viewEntity.getViewInstance(), e); + } + } + } + private void createExtensionTable() throws SQLException { List<DBColumnInfo> columns = new ArrayList<>(); http://git-wip-us.apache.org/repos/asf/ambari/blob/10ebfde7/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog240Test.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog240Test.java b/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog240Test.java index 25fd423..0a9a8ef 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog240Test.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog240Test.java @@ -559,6 +559,7 @@ public class UpgradeCatalog240Test { Method updateAmsConfigs = UpgradeCatalog240.class.getDeclaredMethod("updateAMSConfigs"); Method updateClusterEnv = UpgradeCatalog240.class.getDeclaredMethod("updateClusterEnv"); Method updateSequenceForView = UpgradeCatalog240.class.getDeclaredMethod("updateSequenceForView"); + Method adjustHiveJobTimestamps = UpgradeCatalog240.class.getDeclaredMethod("adjustHiveJobTimestamps"); Method updateHostRoleCommandTableDML = UpgradeCatalog240.class.getDeclaredMethod("updateHostRoleCommandTableDML"); Method updateKerberosEnv = UpgradeCatalog240.class.getDeclaredMethod("updateKerberosConfigs"); Method updateYarnEnv = UpgradeCatalog240.class.getDeclaredMethod("updateYarnEnv"); @@ -608,6 +609,7 @@ public class UpgradeCatalog240Test { .addMockedMethod(updateAmsConfigs) .addMockedMethod(updateClusterEnv) .addMockedMethod(updateSequenceForView) + .addMockedMethod(adjustHiveJobTimestamps) .addMockedMethod(updateHostRoleCommandTableDML) .addMockedMethod(updateKerberosEnv) .addMockedMethod(updateYarnEnv) @@ -674,6 +676,7 @@ public class UpgradeCatalog240Test { upgradeCatalog240.updateRecoveryConfigurationDML(); upgradeCatalog240.removeAtlasMetaserverAlert(); upgradeCatalog240.updateRangerHbasePluginProperties(); + upgradeCatalog240.adjustHiveJobTimestamps(); replay(upgradeCatalog240, dbAccessor);
