Pārlūkot izejas kodu

AMBARI-13618: Add configure / start / stop / status operations for Apache HAWQ's PXF (mithmatt via jaoki)

Jun Aoki 10 gadi atpakaļ
vecāks
revīzija
4763c759cc

+ 19 - 0
ambari-server/src/main/resources/common-services/PXF/3.0.0.0/configuration/pxf-site.xml

@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+   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.
+-->
+<configuration> 
+</configuration>

+ 1 - 1
ambari-server/src/main/resources/common-services/PXF/3.0.0.0/metainfo.xml

@@ -32,7 +32,7 @@
           <category>SLAVE</category>
           <cardinality>1+</cardinality>
           <commandScript>
-            <script>scripts/pxfservice.py</script>
+            <script>scripts/pxf.py</script>
             <scriptType>PYTHON</scriptType>
             <timeout>600</timeout>
           </commandScript>

+ 19 - 18
ambari-server/src/main/resources/common-services/PXF/3.0.0.0/package/scripts/pxfservice.py → ambari-server/src/main/resources/common-services/PXF/3.0.0.0/package/scripts/params.py

@@ -1,6 +1,4 @@
-#!/usr/bin/env python
-
-'''
+"""
 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
@@ -16,26 +14,29 @@ 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.
-'''
+"""
 
 from resource_management import Script
 
-class PxfService(Script):
-  def install(self, env):
-    self.install_packages(env)
-    self.configure(env)
+config = Script.get_config()
+
 
-  def configure(self, env):
-    pass
+pxf_service_name = "pxf-service"
+stack_name = str(config["hostLevelParams"]["stack_name"])
 
-  def start(self, env):
-    pass
+# Users and Groups
+pxf_user = "pxf"
+pxf_group = pxf_user
+hdfs_superuser_group = config["configurations"]["hdfs-site"]["dfs.permissions.superusergroup"]
+user_group = config["configurations"]["cluster-env"]["user_group"]
+tomcat_group = "tomcat"
 
-  def stop(self, env):
-    pass
+# Directories
+pxf_conf_dir = "/etc/pxf/conf"
+pxf_instance_dir = "/var/pxf"
 
-  def status(self, env):
-    pass
+# Java home path
+java_home = config["hostLevelParams"]["java_home"] if "java_home" in config["hostLevelParams"] else None
 
-if __name__ == "__main__":
-  PxfService().execute()
+# Timeouts
+default_exec_timeout = 600

+ 120 - 0
ambari-server/src/main/resources/common-services/PXF/3.0.0.0/package/scripts/pxf.py

@@ -0,0 +1,120 @@
+#!/usr/bin/env python
+
+"""
+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.
+"""
+
+from resource_management import Script
+
+from resource_management.libraries.resources.xml_config import XmlConfig
+from resource_management.core.resources.accounts import User
+from resource_management.core.resources.system import Directory, File, Execute
+from resource_management.core.source import Template
+
+
+
+class Pxf(Script):
+  """
+  Contains the interface definitions for methods like install,
+  start, stop, status, etc. for the PXF
+  """
+
+  def install(self, env):
+    self.install_packages(env)
+    self.configure(env)
+
+
+  def configure(self, env):
+    import params
+    env.set_params(params)
+    self.__setup_user_group()
+    self.__generate_config_files()
+    # pxf-service init exits safely when it is already initialized
+    self.__execute_service_command("init")
+
+
+  def start(self, env):
+    self.configure(env)
+    self.__grant_permissions()
+    self.__execute_service_command("restart")
+
+
+  def stop(self, env):
+    self.__execute_service_command("stop")
+
+
+  def status(self, env):
+    try:
+      self.__execute_service_command("status")
+    except Exception:
+      raise ComponentIsNotRunning()
+
+
+  def __execute_service_command(self, command):
+    import params
+    Execute("service {0} {1}".format(params.pxf_service_name, command),
+              timeout=params.default_exec_timeout,
+              logoutput=True)
+
+
+  def __setup_user_group(self):
+    """
+    Creates PXF user with the required groups and bash as default shell
+    """
+    import params
+    User(params.pxf_user,
+         groups=[params.hdfs_superuser_group, params.user_group, params.tomcat_group],
+         shell="/bin/bash")
+
+
+  def __generate_config_files(self):
+    """
+    Generates pxf-env.sh file from jinja template and sets the classpath for HDP
+    """
+    import params
+    import shutil
+
+    hdp_stack = "HDP"
+
+    # Create file pxf-env.sh from jinja template
+    File("{0}/pxf-env.sh".format(params.pxf_conf_dir),
+         content = Template("pxf-env.j2"))
+
+    # Classpath is set for PHD by default. If stack is HDP, set classpath for HDP
+    if(params.stack_name == hdp_stack):
+      shutil.copy2("{0}/pxf-privatehdp.classpath".format(params.pxf_conf_dir),
+                   "{0}/pxf-private.classpath".format(params.pxf_conf_dir))
+
+    XmlConfig("pxf-site.xml",
+              conf_dir=params.pxf_conf_dir,
+              configurations=params.config['configurations']['pxf-site'],
+              configuration_attributes=params.config['configuration_attributes']['pxf-site'])
+
+
+  def __grant_permissions(self):
+    """
+    Grants permission to pxf:pxf for PXF instance directory
+    """
+    import params
+    Directory(params.pxf_instance_dir,
+              owner=params.pxf_user,
+              group=params.pxf_group,
+              recursive=True)
+
+
+if __name__ == "__main__":
+  Pxf().execute()

+ 34 - 0
ambari-server/src/main/resources/common-services/PXF/3.0.0.0/package/templates/pxf-env.j2

@@ -0,0 +1,34 @@
+#!/bin/sh
+
+#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.
+
+
+# THIS FILE SHOULD MATCH WITH https://github.com/apache/incubator-hawq/blob/master/pxf/pxf-service/src/scripts/pxf-env.sh
+
+# Path to HDFS native libraries
+export LD_LIBRARY_PATH=/usr/lib/hadoop/lib/native:${LD_LIBRARY_PATH}
+
+# Path to JAVA
+export JAVA_HOME={{java_home}}
+
+# Path to Log directory
+export PXF_LOGDIR=/var/log/pxf
+export CATALINA_OUT=${PXF_LOGDIR}/catalina.out
+
+# Path to Run directory
+export PXF_RUNDIR=/var/run/pxf
+