incubator-ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From odiache...@apache.org
Subject git commit: AMBARI-3530. Backend support to perform database connectivity testing for Hive/Oozie DB Config/Reconfig.(Vitaly Brodetskyi via odiachenko)
Date Wed, 23 Oct 2013 12:12:09 GMT
Updated Branches:
  refs/heads/trunk bc0bbbf9b -> 859ba4b49


AMBARI-3530. Backend support to perform database connectivity testing for Hive/Oozie DB Config/Reconfig.(Vitaly
Brodetskyi via odiachenko)


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

Branch: refs/heads/trunk
Commit: 859ba4b499fecb286b81f14c79ce81a390f90f90
Parents: bc0bbbf
Author: Oleksandr Diachenko <odiachenko@hortonworks.com>
Authored: Wed Oct 23 15:10:33 2013 +0300
Committer: Oleksandr Diachenko <odiachenko@hortonworks.com>
Committed: Wed Oct 23 15:10:47 2013 +0300

----------------------------------------------------------------------
 .../puppet/modules/hdp-hive/manifests/init.pp   |  9 +++-
 .../puppet/modules/hdp-hive/manifests/params.pp |  1 +
 .../modules/hdp-hive/manifests/service.pp       | 22 ++++++++--
 .../puppet/modules/hdp-oozie/manifests/init.pp  |  7 ++++
 .../modules/hdp-oozie/manifests/params.pp       |  5 +++
 .../modules/hdp-oozie/manifests/service.pp      | 19 ++++++++-
 .../main/puppet/modules/hdp/manifests/params.pp |  3 ++
 ambari-server/pom.xml                           | 19 +++++++++
 .../ambari/server/DBConnectionVerification.java | 43 ++++++++++++++++++++
 9 files changed, 121 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/859ba4b4/ambari-agent/src/main/puppet/modules/hdp-hive/manifests/init.pp
----------------------------------------------------------------------
diff --git a/ambari-agent/src/main/puppet/modules/hdp-hive/manifests/init.pp b/ambari-agent/src/main/puppet/modules/hdp-hive/manifests/init.pp
index 3c8bde3..0d5aead 100644
--- a/ambari-agent/src/main/puppet/modules/hdp-hive/manifests/init.pp
+++ b/ambari-agent/src/main/puppet/modules/hdp-hive/manifests/init.pp
@@ -54,7 +54,14 @@ class hdp-hive(
   }
 
   anchor { 'hdp-hive::begin': }
-  anchor { 'hdp-hive::end': } 
+  anchor { 'hdp-hive::end': }
+
+  if ($service_state == 'installed_and_configured' and ($hive_jdbc_driver == "com.mysql.jdbc.Driver"
or $hive_jdbc_driver == "oracle.jdbc.driver.OracleDriver")) {
+    hdp::exec { "download DBConnectorVerification.jar" :
+      command => "/bin/sh -c 'cd /usr/lib/ambari-agent/ && curl -s -o ${hdp::params::check_db_connection_jar_name}
${hdp::params::jdk_location}${hdp::params::check_db_connection_jar_name}'",
+      unless  => "[ -f ${check_db_connection_jar} ]"
+    }
+  }
 
   if ($service_state == 'uninstalled') {
     hdp::package { 'hive' : 

http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/859ba4b4/ambari-agent/src/main/puppet/modules/hdp-hive/manifests/params.pp
----------------------------------------------------------------------
diff --git a/ambari-agent/src/main/puppet/modules/hdp-hive/manifests/params.pp b/ambari-agent/src/main/puppet/modules/hdp-hive/manifests/params.pp
index 4fb7c41..4fec035 100644
--- a/ambari-agent/src/main/puppet/modules/hdp-hive/manifests/params.pp
+++ b/ambari-agent/src/main/puppet/modules/hdp-hive/manifests/params.pp
@@ -25,6 +25,7 @@ class hdp-hive::params() inherits hdp::params
   $hive_metastore_user_name = hdp_default("hive-site/javax.jdo.option.ConnectionUserName","dbusername")
   $hive_metastore_user_passwd = hdp_default("hive-site/javax.jdo.option.ConnectionPassword","dbpassword")
   $hive_server_conf_dir = hdp_default("hive_server_conf_dir", "/etc/hive/conf.server")
+  $hive_jdbc_connection_url = hdp_default("hive_jdbc_connection_url", "")
 
   ### users
   $hive_user = $hdp::params::hive_user

http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/859ba4b4/ambari-agent/src/main/puppet/modules/hdp-hive/manifests/service.pp
----------------------------------------------------------------------
diff --git a/ambari-agent/src/main/puppet/modules/hdp-hive/manifests/service.pp b/ambari-agent/src/main/puppet/modules/hdp-hive/manifests/service.pp
index a67b8b1..33f924d 100644
--- a/ambari-agent/src/main/puppet/modules/hdp-hive/manifests/service.pp
+++ b/ambari-agent/src/main/puppet/modules/hdp-hive/manifests/service.pp
@@ -94,12 +94,26 @@ class hdp-hive::service(
       }
     }
 
+    file { $pid_file:
+      ensure => $pid_file_state
+    }
 
-  file { $pid_file:
-    ensure => $pid_file_state
-  }
+    if ($ensure == 'running' and ($hive_jdbc_driver == "com.mysql.jdbc.Driver" or $hive_jdbc_driver
== "oracle.jdbc.driver.OracleDriver")) {
+      $db_connection_check_command = "java -cp ${hdp::params::check_db_connection_jar}:/usr/share/java/${hdp-hive::params::jdbc_jar_name}
org.apache.ambari.server.DBConnectionVerification ${hdp-hive::params::hive_jdbc_connection_url}
${hdp-hive::params::hive_metastore_user_name} ${hdp-hive::params::hive_metastore_user_passwd}
${hdp-hive::params::hive_jdbc_driver}"
+    } else {
+      $db_connection_check_command = undef
+    }
 
-    Hdp-hive::Service::Directory<||> -> File[ $start_metastore_path]-> File[
$start_hiveserver2_path]-> Hdp::Exec[$daemon_cmd] -> File[$pid_file] -> Anchor['hdp-hive::service::end']
+    if ($db_connection_check_command != undef) {
+      hdp::exec { "DB connection check $db_connection_check_command" :
+        command => $db_connection_check_command,
+        path    => '/usr/sbin:/sbin:/usr/local/bin:/bin:/usr/bin'
+      }
+
+      Hdp-hive::Service::Directory<||> -> Hdp::Exec["DB connection check $db_connection_check_command"]
-> File[ $start_metastore_path]-> File[ $start_hiveserver2_path]-> Hdp::Exec[$daemon_cmd]
-> File[$pid_file] -> Anchor['hdp-hive::service::end']
+    } else {
+      Hdp-hive::Service::Directory<||> -> File[ $start_metastore_path]-> File[
$start_hiveserver2_path]-> Hdp::Exec[$daemon_cmd] -> File[$pid_file] -> Anchor['hdp-hive::service::end']
+    }
   }
 }
 

http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/859ba4b4/ambari-agent/src/main/puppet/modules/hdp-oozie/manifests/init.pp
----------------------------------------------------------------------
diff --git a/ambari-agent/src/main/puppet/modules/hdp-oozie/manifests/init.pp b/ambari-agent/src/main/puppet/modules/hdp-oozie/manifests/init.pp
index 01929e5..7c535e5 100644
--- a/ambari-agent/src/main/puppet/modules/hdp-oozie/manifests/init.pp
+++ b/ambari-agent/src/main/puppet/modules/hdp-oozie/manifests/init.pp
@@ -89,6 +89,13 @@ class hdp-oozie(
 
      if ($service_state == 'installed_and_configured') {
        hdp-oozie::configfile { 'oozie-log4j.properties': }
+
+       if ($hdp::params::oozie_jdbc_driver == "com.mysql.jdbc.Driver" or $hdp::params::oozie_jdbc_driver
== "oracle.jdbc.driver.OracleDriver") {
+         hdp::exec { "download DBConnectorVerification.jar" :
+           command => "/bin/sh -c 'cd /usr/lib/ambari-agent/ && curl -s -o ${hdp::params::check_db_connection_jar_name}
${hdp::params::jdk_location}${hdp::params::check_db_connection_jar_name}'",
+           unless  => "[ -f ${check_db_connection_jar} ]"
+         }
+       }
      }
 
      hdp-oozie::ownership { 'ownership': }

http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/859ba4b4/ambari-agent/src/main/puppet/modules/hdp-oozie/manifests/params.pp
----------------------------------------------------------------------
diff --git a/ambari-agent/src/main/puppet/modules/hdp-oozie/manifests/params.pp b/ambari-agent/src/main/puppet/modules/hdp-oozie/manifests/params.pp
index b74cf7c..4854c25 100644
--- a/ambari-agent/src/main/puppet/modules/hdp-oozie/manifests/params.pp
+++ b/ambari-agent/src/main/puppet/modules/hdp-oozie/manifests/params.pp
@@ -27,6 +27,11 @@ class hdp-oozie::params() inherits hdp::params
   $ext_zip_url = "${download_url}/ext-2.2.zip"
   $ext_zip_name = hdp_default("ext_zip_name","ext-2.2.zip")
 
+  ###oozie jdbc
+  $oozie_metastore_user_name = hdp_default("oozie_metastore_user_name","oozie")
+  $oozie_metastore_user_passwd = hdp_default("oozie_metastore_user_passwd","")
+  $oozie_jdbc_connection_url = hdp_default("oozie_jdbc_connection_url", "")
+
   ### oozie-env
   $conf_dir = $hdp::params::oozie_conf_dir
   $hadoop_prefix = hdp_default("hadoop_prefix","/usr")

http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/859ba4b4/ambari-agent/src/main/puppet/modules/hdp-oozie/manifests/service.pp
----------------------------------------------------------------------
diff --git a/ambari-agent/src/main/puppet/modules/hdp-oozie/manifests/service.pp b/ambari-agent/src/main/puppet/modules/hdp-oozie/manifests/service.pp
index 1413d6d..80a38c2 100644
--- a/ambari-agent/src/main/puppet/modules/hdp-oozie/manifests/service.pp
+++ b/ambari-agent/src/main/puppet/modules/hdp-oozie/manifests/service.pp
@@ -54,7 +54,7 @@ class hdp-oozie::service(
   $driver_curl_target = "${java_share_dir}/${oracle_driver_jar_name}"
   $curl_cmd = "curl -kf --retry 10 ${driver_location}${oracle_driver_jar_name} -o ${driver_curl_target}"
   
-  $jdbc_driver_name = $configuration['oozie-site']['oozie.service.JPAService.jdbc.driver']
+  $jdbc_driver_name = $hdp::params::oozie_jdbc_driver
   if ($jdbc_driver_name == "com.mysql.jdbc.Driver"){
     $jdbc_driver_jar = "/usr/share/java/mysql-connector-java.jar"
   } elsif($jdbc_driver_name == "oracle.jdbc.driver.OracleDriver") {
@@ -128,6 +128,11 @@ class hdp-oozie::service(
     $user_cmds_on_run = [$cmd5]   
     $start_cmd = "su - ${user} -c  'cd ${oozie_tmp} && /usr/lib/oozie/bin/oozie-start.sh'"
     $no_op_test = "ls ${pid_file} >/dev/null 2>&1 && ps `cat ${pid_file}`
>/dev/null 2>&1"
+    if ($jdbc_driver_name == "com.mysql.jdbc.Driver" or $jdbc_driver_name == "oracle.jdbc.driver.OracleDriver")
{
+      $db_connection_check_command = "java -cp ${hdp::params::check_db_connection_jar}:${jdbc_driver_jar}
org.apache.ambari.server.DBConnectionVerification ${hdp-oozie::params::oozie_jdbc_connection_url}
${hdp-oozie::params::oozie_metastore_user_name} ${hdp-oozie::params::oozie_metastore_user_passwd}
${jdbc_driver_name}"
+    } else {
+      $db_connection_check_command = undef
+    }
   } elsif ($ensure == 'stopped') {
     $stop_cmd  = "su - ${user} -c  'cd ${oozie_tmp} && /usr/lib/oozie/bin/oozie-stop.sh'
&& rm -f ${pid_file}"
     $no_op_test = "ls ${pid_file} >/dev/null 2>&1 && ps `cat ${pid_file}`
>/dev/null 2>&1"
@@ -160,7 +165,17 @@ class hdp-oozie::service(
       initial_wait => $initial_wait,
       require => Exec["exec $cmd6"]
     }
-    Hdp-oozie::Service::Directory<||> -> Hdp-oozie::Service::Exec_user[$cmd5] ->
Hdp::Exec["exec $cmd6"] -> Hdp::Exec["exec $start_cmd"] -> Anchor['hdp-oozie::service::end']
+
+    if ($db_connection_check_command != undef) {
+      hdp::exec { "DB connection check $db_connection_check_command" :
+        command => $db_connection_check_command,
+        path    => '/usr/sbin:/sbin:/usr/local/bin:/bin:/usr/bin'
+      }
+
+      Hdp-oozie::Service::Directory<||> -> Hdp::Exec["DB connection check $db_connection_check_command"]
-> Hdp-oozie::Service::Exec_user[$cmd5] -> Hdp::Exec["exec $cmd6"] -> Hdp::Exec["exec
$start_cmd"] -> Anchor['hdp-oozie::service::end']
+    } else {
+      Hdp-oozie::Service::Directory<||> -> Hdp-oozie::Service::Exec_user[$cmd5]
-> Hdp::Exec["exec $cmd6"] -> Hdp::Exec["exec $start_cmd"] -> Anchor['hdp-oozie::service::end']
+    }
   } elsif ($ensure == 'stopped') {
     hdp::exec { "exec $stop_cmd":
       command => $stop_cmd,

http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/859ba4b4/ambari-agent/src/main/puppet/modules/hdp/manifests/params.pp
----------------------------------------------------------------------
diff --git a/ambari-agent/src/main/puppet/modules/hdp/manifests/params.pp b/ambari-agent/src/main/puppet/modules/hdp/manifests/params.pp
index 881fb18..c86b6e9 100644
--- a/ambari-agent/src/main/puppet/modules/hdp/manifests/params.pp
+++ b/ambari-agent/src/main/puppet/modules/hdp/manifests/params.pp
@@ -279,6 +279,9 @@ class hdp::params()
   $oracle_jdbc_url = hdp_default("oracle_jdbc_url", "")
   $mysql_jdbc_url = hdp_default("mysql_jdbc_url", "")
   $db_driver_file = hdp_default("db_driver_filename", "")
+  $check_db_connection_jar_name = "DBConnectionVerification.jar"
+  $check_db_connection_jar = "/usr/lib/ambari-agent/${check_db_connection_jar_name}"
+  $oozie_jdbc_driver = hdp_default("oozie-site/oozie.service.JPAService.jdbc.driver", "")
 
   #####
   $hadoop_home = hdp_default("hadoop_home","/usr")

http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/859ba4b4/ambari-server/pom.xml
----------------------------------------------------------------------
diff --git a/ambari-server/pom.xml b/ambari-server/pom.xml
index f5cd967..9f43afa 100644
--- a/ambari-server/pom.xml
+++ b/ambari-server/pom.xml
@@ -315,6 +315,9 @@
                   <location>src/main/resources/hive-schema-0.10.0.oracle.sql</location>
                 </source>
                 <source>
+                  <location>${project.build.directory}/DBConnectionVerification.jar</location>
+                </source> 
+                <source>
                   <!-- This file is also included into agent rpm-->
                   <location>src/main/resources/role_command_order.json</location>
                 </source>
@@ -524,6 +527,22 @@
               </target>
             </configuration>
           </execution>
+          <execution>
+            <phase>package</phase>
+            <configuration>
+              <tasks>
+                <jar destfile="target/DBConnectionVerification.jar">
+                     <fileset dir="${basedir}/target/classes/" includes="**/DBConnectionVerification.class"
/>
+		     <manifest>
+		      <attribute name="Main-Class" value="org.apache.ambari.server.DBConnectionVerification"/>
+		     </manifest>
+		</jar>
+              </tasks>
+            </configuration>
+            <goals>
+              <goal>run</goal>
+            </goals>
+          </execution>
         </executions>
       </plugin>
     </plugins>

http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/859ba4b4/ambari-server/src/main/java/org/apache/ambari/server/DBConnectionVerification.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/DBConnectionVerification.java
b/ambari-server/src/main/java/org/apache/ambari/server/DBConnectionVerification.java
new file mode 100644
index 0000000..7c053f3
--- /dev/null
+++ b/ambari-server/src/main/java/org/apache/ambari/server/DBConnectionVerification.java
@@ -0,0 +1,43 @@
+/**
+ * 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.server;
+
+import java.sql.*;
+
+public class DBConnectionVerification {
+  public static void main(String[] args) throws Exception {
+    String url = args[0];
+    String username = args[1];
+    String password = args[2];
+    String driver = args[3];
+ 
+    Connection conn = null;
+    try {
+       Class.forName(driver);
+       conn = DriverManager.getConnection(url, username, password);
+       System.out.println("Connected to DB Successfully!");
+    } catch (Exception e) {
+       System.out.println("ERROR: Unable to connect to the DB. Please check DB connection
properties.");
+       System.out.println(e);
+       System.exit(1);
+    } finally {
+       conn.close();
+    }
+  }
+}


Mime
View raw message