incubator-ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From maha...@apache.org
Subject svn commit: r1358472 - in /incubator/ambari/trunk: ./ hmc/db/ hmc/package/rpm/SPECS/ hmc/php/db/ hmc/php/upgrade/ hmc/php/upgrade/dbupgrade/ hmc/tests/php/db/
Date Fri, 06 Jul 2012 23:56:22 GMT
Author: mahadev
Date: Fri Jul  6 23:56:21 2012
New Revision: 1358472

URL: http://svn.apache.org/viewvc?rev=1358472&view=rev
Log:
AMBARI-612. Allow upgrading the database and add versions for ambari and hadoop stacks. (mahadev)

Added:
    incubator/ambari/trunk/hmc/php/upgrade/
    incubator/ambari/trunk/hmc/php/upgrade/dbupgrade/
    incubator/ambari/trunk/hmc/php/upgrade/dbupgrade/upgrade_1.0.dump
    incubator/ambari/trunk/hmc/php/upgrade/upgradeDB.php
    incubator/ambari/trunk/hmc/tests/php/db/hmcAccessForVersionTest.php
Removed:
    incubator/ambari/trunk/hmc/db/hdp_upgrade_to_1.0.1.php
Modified:
    incubator/ambari/trunk/CHANGES.txt
    incubator/ambari/trunk/hmc/db/schema.dump
    incubator/ambari/trunk/hmc/package/rpm/SPECS/ambari.spec
    incubator/ambari/trunk/hmc/php/db/HMCDBAccessor.php

Modified: incubator/ambari/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/CHANGES.txt?rev=1358472&r1=1358471&r2=1358472&view=diff
==============================================================================
--- incubator/ambari/trunk/CHANGES.txt (original)
+++ incubator/ambari/trunk/CHANGES.txt Fri Jul  6 23:56:21 2012
@@ -6,6 +6,9 @@ characters wide.
 
 Release 1.0.0 - unreleased
 
+  AMBARI-612. Allow upgrading the database and add versions for ambari and
+  hadoop stacks. (mahadev)
+
   AMBARI-607. Increase puppet timeouts to handle single-node installs timing out
   (hitesh)
 

Modified: incubator/ambari/trunk/hmc/db/schema.dump
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/hmc/db/schema.dump?rev=1358472&r1=1358471&r2=1358472&view=diff
==============================================================================
--- incubator/ambari/trunk/hmc/db/schema.dump (original)
+++ incubator/ambari/trunk/hmc/db/schema.dump Fri Jul  6 23:56:21 2012
@@ -17,6 +17,34 @@
 --  */
 BEGIN TRANSACTION;
 
+CREATE TABLE "AmbariConfig" (
+  key_name TEXT, -- the key for cluster wide version
+  tag_name TEXT, -- tag name current/previous
+  version TEXT,  -- the cluster wide version
+  PRIMARY KEY (key_name, tag_name)
+);
+
+INSERT OR REPLACE INTO "AmbariConfig" (key_name, tag_name, version) VALUES 
+  ("Ambari", "Current", "1.0.2");
+INSERT OR REPLACE INTO "AmbariConfig" (key_name, tag_name, version) VALUES
+  ("Ambari", "Previous", "");
+INSERT OR REPLACE INTO "AmbariConfig" (key_name, tag_name, version) VALUES
+  ("HDPStack", "Latest", "1.0.1");
+
+CREATE TABLE "AmbariConfig" (
+  key_name TEXT, -- the key for cluster wide version
+  tag_name TEXT, -- tag name current/previous
+  version TEXT,  -- the cluster wide version
+  PRIMARY KEY (key_name, tag_name)
+);
+
+INSERT OR REPLACE INTO "AmbariConfig" (key_name, tag_name, version) VALUES 
+  ("Ambari", "Current", "1.0.2");
+INSERT OR REPLACE INTO "AmbariConfig" (key_name, tag_name, version) VALUES
+  ("Ambari", "Previous", "");
+INSERT OR REPLACE INTO "AmbariConfig" (key_name, tag_name, version) VALUES
+  ("HDPStack", "Latest", "1.0.1");
+
 CREATE TABLE  "Clusters" (
   cluster_name TEXT, -- Cluster name
   version TEXT, -- version of the hadoop stack installed

Modified: incubator/ambari/trunk/hmc/package/rpm/SPECS/ambari.spec
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/hmc/package/rpm/SPECS/ambari.spec?rev=1358472&r1=1358471&r2=1358472&view=diff
==============================================================================
--- incubator/ambari/trunk/hmc/package/rpm/SPECS/ambari.spec (original)
+++ incubator/ambari/trunk/hmc/package/rpm/SPECS/ambari.spec Fri Jul  6 23:56:21 2012
@@ -66,7 +66,7 @@ This package provides a Management Conso
 # Make a backup of existing database before installing new package
 if [ -f /var/db/hmc/data/data.db ]; then
   DATE=`date +%d-%m-%y-%H%M`
-  mv /var/db/hmc/data/data.db /var/db/hmc/data/data.db.$DATE
+  cp /var/db/hmc/data/data.db /var/db/hmc/data/data.db.$DATE
 fi
 
 
@@ -113,7 +113,13 @@ if test X"$RPM_INSTALL_PREFIX0" = X"" ; 
 fi
 
 echo "Alias /hdp $RPM_INSTALL_PREFIX0/share/hdp" > /etc/httpd/conf.d/hdp_mon_dashboard.conf
-php $RPM_INSTALL_PREFIX0/share/hmc/php/frontend/initializeHMC.php /var/db/hmc/data/data.db
$RPM_INSTALL_PREFIX0/share/hmc/db/schema.dump
+if [ -f /var/db/hmc/data/data.db ]; then
+  DATE=`date +%d-%m-%y-%H%M`
+  php $RPM_INSTALL_PREFIX0/share/hmc/php/upgrade/upgradeDB.php /var/db/hmc/data/data.db $RPM_INSTALL_PREFIX0/share/hmc/php/upgrade/dbupgrade
+else
+  php $RPM_INSTALL_PREFIX0/share/hmc/php/frontend/initializeHMC.php /var/db/hmc/data/data.db
$RPM_INSTALL_PREFIX0/share/hmc/db/schema.dump
+fi
+
 sed -i 's/User\ apache/User\ puppet/g' /etc/httpd/conf/httpd.conf
 chmod 666 /var/db/hmc/data/data.db
 chown -R puppet:apache /var/db/hmc/

Modified: incubator/ambari/trunk/hmc/php/db/HMCDBAccessor.php
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/hmc/php/db/HMCDBAccessor.php?rev=1358472&r1=1358471&r2=1358472&view=diff
==============================================================================
--- incubator/ambari/trunk/hmc/php/db/HMCDBAccessor.php (original)
+++ incubator/ambari/trunk/hmc/php/db/HMCDBAccessor.php Fri Jul  6 23:56:21 2012
@@ -99,6 +99,134 @@ class HMCDBAccessor {
     LockRelease(); return $response;
   }
 
+ /**
+   * Get version of Ambari that is running.
+   * @return mixed
+   *   array ( "version" => $ambariVersion,
+   *           "result" => 0,
+   *           "error" => "");
+   */
+  public function getCurrentAmbariVersion () {
+    LockAcquire();
+    $query = "SELECT version FROM AmbariConfig WHERE key_name = \"Ambari\" AND
+    tag_name = \"Current\"";
+    $response = array ( "result" => 0, "error" => "");
+    $this->logger->log_trace("Running query: $query");
+    $pdoStmt = $this->dbHandle->query($query);
+    if ($pdoStmt === FALSE) {
+      $error = $this->getLastDBErrorAsString();
+      $this->logger->log_error("Error when executing query"
+          . ", query=".$query
+          . ", error=".$error);
+      $response["result"] = 1;
+      $response["error"] = $error;
+      LockRelease(); return $response;
+    }
+    $result = $pdoStmt->fetchAll(PDO::FETCH_BOTH);
+    if (isset($result) && is_array($result) && count($result) == 1) {
+      $response["version"] = $result[0]["version"];
+      LockRelease(); return $response;
+    }
+    LockRelease(); return $response;
+  }
+
+ /**
+   * Get version of Ambari that was running.
+   * @return mixed
+   *   array ( "version" => $ambariVersion,
+   *           "result" => 0,
+   *           "error" => "");
+   */
+  public function getPreviousAmbariVersion () {
+    LockAcquire();
+    $query = "SELECT version FROM AmbariConfig WHERE key_name = \"Ambari\" AND
+    tag_name = \"Previous\"";
+    $response = array ( "result" => 0, "error" => "");
+    $this->logger->log_trace("Running query: $query");
+    $pdoStmt = $this->dbHandle->query($query);
+    if ($pdoStmt === FALSE) {
+      $error = $this->getLastDBErrorAsString();
+      $this->logger->log_error("Error when executing query"
+          . ", query=".$query
+          . ", error=".$error);
+      $response["result"] = 1;
+      $response["error"] = $error;
+      LockRelease(); return $response;
+    }
+    $result = $pdoStmt->fetchAll(PDO::FETCH_BOTH);
+    if (isset($result) && is_array($result) && count($result) == 1) {
+      $response["version"] = $result[0]["version"];
+      LockRelease(); return $response;
+    }
+    LockRelease(); return $response;
+  }
+
+ /**
+   * Get latest version of Stack that Ambari supports.
+   * @return mixed
+   *   array ( "version" => $stackVersion,
+   *           "result" => 0,
+   *           "error" => "");
+   */
+  public function getLatestStackVersion () {
+    LockAcquire();
+    $query = "SELECT version FROM AmbariConfig WHERE key_name = \"HDPStack\" AND
+    tag_name = \"Latest\"";
+    $response = array ( "result" => 0, "error" => "");
+    $this->logger->log_trace("Running query: $query");
+    $pdoStmt = $this->dbHandle->query($query);
+    if ($pdoStmt === FALSE) {
+      $error = $this->getLastDBErrorAsString();
+      $this->logger->log_error("Error when executing query"
+          . ", query=".$query
+          . ", error=".$error);
+      $response["result"] = 1;
+      $response["error"] = $error;
+      LockRelease(); return $response;
+    }
+    $result = $pdoStmt->fetchAll(PDO::FETCH_BOTH);
+    if (isset($result) && is_array($result) && count($result) == 1) {
+      $response["version"] = $result[0]["version"];
+      LockRelease(); return $response;
+    }
+    LockRelease(); return $response;
+  }
+
+
+  /**
+   * Get the version of the stack running on a cluster
+   * @param string $clusterName Cluster Name
+   * @return mixed
+   *   array ( "version" => $stackVersion,
+   *           "result" => 0,
+   *           "error" => "");
+   */
+
+  public function getCurrentClusterStackVersion ($clusterName) {
+    LockAcquire();
+    $query = "SELECT version FROM Clusters WHERE cluster_name = "
+        . $this->dbHandle->quote($clusterName);
+    $response = array ( "result" => 0, "error" => "");
+    $this->logger->log_trace("Running query: $query");
+    $pdoStmt = $this->dbHandle->query($query);
+    if ($pdoStmt === FALSE) {
+      $error = $this->getLastDBErrorAsString();
+      $this->logger->log_error("Error when executing query"
+          . ", query=".$query
+          . ", error=".$error);
+      $response["result"] = 1;
+      $response["error"] = $error;
+      LockRelease(); return $response;
+    }
+    $result = $pdoStmt->fetchAll(PDO::FETCH_BOTH);
+    if (isset($result) && is_array($result) && count($result) == 1) {
+      $response["version"] = $result[0]["version"];
+      LockRelease(); return $response;
+    }
+
+    LockRelease(); return $response;
+  }
+
   /**
    * Update cluster state for a given clusterName
    * @param string $clusterName Cluster Name

Added: incubator/ambari/trunk/hmc/php/upgrade/dbupgrade/upgrade_1.0.dump
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/hmc/php/upgrade/dbupgrade/upgrade_1.0.dump?rev=1358472&view=auto
==============================================================================
--- incubator/ambari/trunk/hmc/php/upgrade/dbupgrade/upgrade_1.0.dump (added)
+++ incubator/ambari/trunk/hmc/php/upgrade/dbupgrade/upgrade_1.0.dump Fri Jul  6 23:56:21
2012
@@ -0,0 +1,78 @@
+-- /*
+--  * 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.
+--  */
+
+BEGIN TRANSACTION;
+
+CREATE TABLE "AmbariConfig" (
+  key_name TEXT, -- the key for cluster wide version
+  tag_name TEXT, -- tag name current/previous
+  version TEXT,  -- the cluster wide version
+  PRIMARY KEY (key_name, tag_name)
+);
+
+INSERT OR REPLACE INTO "AmbariConfig" (key_name, tag_name, version) VALUES 
+  ("Ambari", "Current", "1.0.2");
+INSERT OR REPLACE INTO "AmbariConfig" (key_name, tag_name, version) VALUES
+  ("Ambari", "Previous", "1.0.0");
+INSERT OR REPLACE INTO "AmbariConfig" (key_name, tag_name, version) VALUES
+  ("HDPStack", "Current", "");
+INSERT OR REPLACE INTO "AmbariConfig" (key_name, tag_name, version) VALUES
+  ("HDPStack", "Latest", "1.0.1");
+INSERT OR REPLACE INTO "AmbariConfig" (key_name, tag_name, version) VALUES
+  ("HDPStack", "Previous", ""); 
+
+
+
+-- maps to hstore_compactionthreshold
+INSERT OR REPLACE INTO "ConfigProperties" ( key, default_value, display_name, description,
service_name, display_type, display_attributes ) VALUES ( "hstore_compactionthreshold", "3",
"HBase HStore compaction threshold", "If more than this number of HStoreFiles in any one HStore
then a compaction is run to rewrite all HStoreFiles files as one.", "HBASE" , "", '{ "isPassword":
false, "noDisplay": false, "reconfigurable": true, "displayType": "text", "unit":"int" }'
);
+
+-- maps to hfile_blockcache_size
+INSERT OR REPLACE INTO "ConfigProperties" ( key, default_value, display_name, description,
service_name, display_type, display_attributes ) VALUES ( "hfile_blockcache_size", "0.25",
"HFile block cache size ", "Percentage of maximum heap (-Xmx setting) to allocate to block
cache used by HFile/StoreFile. Set to 0 to disable but it's not recommended.", "HBASE" , "",
'{ "isPassword": false, "noDisplay": false, "reconfigurable": true, "displayType": "text",
"unit":"int" }' );
+
+-- maps to hstorefile_maxsize.
+INSERT OR REPLACE INTO "ConfigProperties" ( key, default_value, display_name, description,
service_name, display_type, display_attributes ) VALUES ( "hstorefile_maxsize", "1073741824",
"Maximum HStoreFile Size", "If any one of a column families' HStoreFiles has grown to exceed
this value, the hosting HRegion is split in two.", "HBASE" , "", '{ "isPassword": false, "noDisplay":
false, "reconfigurable": true, "displayType": "text", "unit":"bytes" }' );
+
+-- maps to regionserver_handlers.
+INSERT OR REPLACE INTO "ConfigProperties" ( key, default_value, display_name, description,
service_name, display_type, display_attributes ) VALUES ( "regionserver_handlers", "30", "HBase
Region Server Handler", "Count of RPC Listener instances spun up on RegionServers", "HBASE"
, "", '{ "isPassword": false, "noDisplay": false, "reconfigurable": true, "displayType": "text",
"unit":"int" }' );
+
+-- maps to hregion_majorcompaction.
+INSERT OR REPLACE INTO "ConfigProperties" ( key, default_value, display_name, description,
service_name, display_type, display_attributes ) VALUES ( "hregion_majorcompaction", "86400000",
"HBase Region Major Compaction", "The time between major compactions of all HStoreFiles in
a region. Set to 0 to disable automated major compactions.", "HBASE" , "", '{ "isPassword":
false, "noDisplay": false, "reconfigurable": true, "displayType": "text", "unit":"ms" }' );
+
+-- maps to hregion_blockmultiplier.
+INSERT OR REPLACE INTO "ConfigProperties" ( key, default_value, display_name, description,
service_name, display_type, display_attributes ) VALUES ( "hregion_blockmultiplier", "2",
"HBase Region Block Multiplier", "Block updates if memstore has ""Multiplier * HBase Region
Memstore Flush Size"" bytes. Useful preventing runaway memstore during spikes in update traffic",
"HBASE" , "", '{ "isPassword": false, "noDisplay": false, "reconfigurable": true, "displayType":
"text", "unit":"int" }' );
+
+-- maps to hregion_memstoreflushsize.
+INSERT OR REPLACE INTO "ConfigProperties" ( key, default_value, display_name, description,
service_name, display_type, display_attributes ) VALUES ( "hregion_memstoreflushsize", "134217728",
"HBase Region Memstore Flush Size", "Memstore will be flushed to disk if size of the memstore
exceeds this number of bytes.", "HBASE" , "", '{ "isPassword": false, "noDisplay": false,
"reconfigurable": true, "displayType": "text", "unit":"bytes" }' );
+
+-- maps to client_scannercaching.
+INSERT OR REPLACE INTO "ConfigProperties" ( key, default_value, display_name, description,
service_name, display_type, display_attributes ) VALUES ( "client_scannercaching", "100",
"HBase Client Scanner Caching", "Number of rows that will be fetched when calling next on
a scanner if it is not served from (local, client) memory. Do not set this value such that
the time between invocations is greater than the scanner timeout", "HBASE" , "", '{ "isPassword":
false, "noDisplay": false, "reconfigurable": true, "displayType": "text", "unit":"int" }'
);
+
+-- maps to zookeeper_sessiontimeout.
+INSERT OR REPLACE INTO "ConfigProperties" ( key, default_value, display_name, description,
service_name, display_type, display_attributes ) VALUES ( "zookeeper_sessiontimeout", "60000",
"Zookeeper timeout for HBase Session", "HBase passes this to the zk quorum as suggested maximum
time for a session", "HBASE" , "", '{ "isPassword": false, "noDisplay": false, "reconfigurable":
true, "displayType": "text", "unit":"ms" }' );
+
+-- maps to hfile_max_keyvalue_size.
+INSERT OR REPLACE INTO "ConfigProperties" ( key, default_value, display_name, description,
service_name, display_type, display_attributes ) VALUES ( "hfile_max_keyvalue_size", "10485760",
"HBase Client Maximum key-value Size", "Specifies the combined maximum allowed size of a KeyValue
instance. It should be set to a fraction of the maximum region size.", "HBASE" , "", '{ "isPassword":
false, "noDisplay": false, "reconfigurable": true, "displayType": "text", "unit":"bytes" }'
);
+
+
+-- changes the display on UI from "HIVE SERVER to HIVE METASTORE"
+
+UPDATE ServiceComponents SET display_name = 'Hive Metastore' WHERE service_name = 'HIVE'
AND component_name = 'HIVE_SERVER';
+
+UPDATE Clusters SET version = '1.0.0';
+
+COMMIT;

Added: incubator/ambari/trunk/hmc/php/upgrade/upgradeDB.php
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/hmc/php/upgrade/upgradeDB.php?rev=1358472&view=auto
==============================================================================
--- incubator/ambari/trunk/hmc/php/upgrade/upgradeDB.php (added)
+++ incubator/ambari/trunk/hmc/php/upgrade/upgradeDB.php Fri Jul  6 23:56:21 2012
@@ -0,0 +1,38 @@
+<?php
+/*
+ *
+ * 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.
+ *
+ */
+
+
+$db = new PDO("sqlite:".$argv[1]);
+$upgradeDir = $argv[2];
+if ($handle = opendir($upgradeDir)) {
+  while (false !== ($entry = readdir($handle))) {
+    if ($entry != "." && $entry != "..") { 
+      $absolutePath = $upgradeDir."/".$entry;
+      print_r("DB file path is $absolutePath");
+      $sql = file_get_contents($absolutePath);
+      $db->exec($sql) or die(print_r($db->errorInfo(), true));
+    }
+  }
+  closedir($handle);
+}
+
+?>

Added: incubator/ambari/trunk/hmc/tests/php/db/hmcAccessForVersionTest.php
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/hmc/tests/php/db/hmcAccessForVersionTest.php?rev=1358472&view=auto
==============================================================================
--- incubator/ambari/trunk/hmc/tests/php/db/hmcAccessForVersionTest.php (added)
+++ incubator/ambari/trunk/hmc/tests/php/db/hmcAccessForVersionTest.php Fri Jul  6 23:56:21
2012
@@ -0,0 +1,42 @@
+<?php
+/*
+ *
+ * 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.
+ *
+*/
+
+
+include_once '../../../php/util/Logger.php';
+include_once '../../../php/conf/Config.inc';
+include_once "../../../php/util/lock.php";
+include_once '../../../php/db/HMCDBAccessor.php';
+
+$GLOBALS["HMC_LOG_LEVEL"] = HMCLogger::DEBUG;
+$GLOBALS["HMC_LOG_FILE"] = "./hmc.log";
+
+system("rm -rf ./hmc.log");
+
+assert_options(ASSERT_BAIL, 1);
+
+$db = new HMCDBAccessor("data.db");
+
+$result = $db->getCurrentAmbariVersion();
+print_r($result);
+$result = $db->getCurrentClusterStackVersion("pptest");
+
+?>



Mime
View raw message