|
@@ -16,49 +16,35 @@ See the License for the specific language governing permissions and
|
|
|
limitations under the License.
|
|
|
"""
|
|
|
|
|
|
-import os
|
|
|
+from resource_management.core.shell import call
|
|
|
+from resource_management.core.exceptions import ComponentIsNotRunning
|
|
|
|
|
|
-from resource_management import Script
|
|
|
-from resource_management.core.resources.system import File
|
|
|
-from resource_management.core.exceptions import Fail
|
|
|
-
|
|
|
-import utils
|
|
|
import common
|
|
|
import hawq_constants
|
|
|
|
|
|
-
|
|
|
-def get_pid_file():
|
|
|
+PROCESS_INFO = {
|
|
|
+ hawq_constants.MASTER: {
|
|
|
+ 'port_property': 'hawq_master_address_port',
|
|
|
+ 'process_name': 'postgres'
|
|
|
+ },
|
|
|
+ hawq_constants.STANDBY: {
|
|
|
+ 'port_property': 'hawq_master_address_port',
|
|
|
+ 'process_name': 'gpsyncmaster'
|
|
|
+ },
|
|
|
+ hawq_constants.SEGMENT: {
|
|
|
+ 'port_property': 'hawq_segment_address_port',
|
|
|
+ 'process_name': 'postgres'
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+def assert_component_running(component):
|
|
|
"""
|
|
|
- Fetches the pid file, which will be used to get the status of the HAWQ Master, Standby
|
|
|
- or Segments
|
|
|
+ Based on the port and process identifies the status of the component
|
|
|
"""
|
|
|
+ port = common.get_local_hawq_site_property(PROCESS_INFO[component]['port_property'])
|
|
|
+ process = PROCESS_INFO[component]['process_name']
|
|
|
|
|
|
- config = Script.get_config()
|
|
|
-
|
|
|
- component_name = config['componentName']
|
|
|
- component = "master" if component_name in ["HAWQMASTER", "HAWQSTANDBY"] else "segment"
|
|
|
- hawq_pid_file = os.path.join(hawq_constants.hawq_pid_dir, "hawq-{0}.pid".format(component))
|
|
|
-
|
|
|
- File(hawq_pid_file, action='delete')
|
|
|
- utils.create_dir_as_hawq_user(hawq_constants.hawq_pid_dir)
|
|
|
-
|
|
|
- #Get hawq_master_directory or hawq_segment_directory value from hawq-site.xml depending
|
|
|
- #on the component
|
|
|
- hawq_site_directory_property = "hawq_{0}_directory".format(component)
|
|
|
-
|
|
|
- #hawq-site content from Ambari server will not be available when the
|
|
|
- #command type is STATUS_COMMAND. Hence, reading it directly from the local file
|
|
|
- postmaster_pid_file = os.path.join(common.get_local_hawq_site_property(
|
|
|
- hawq_site_directory_property), hawq_constants.postmaster_pid_filename)
|
|
|
-
|
|
|
- pid = ""
|
|
|
- if os.path.exists(postmaster_pid_file):
|
|
|
- with open(postmaster_pid_file, 'r') as fh:
|
|
|
- pid = fh.readline().strip()
|
|
|
-
|
|
|
- if not pid:
|
|
|
- raise Fail("Failed to fetch pid from {0}".format(postmaster_pid_file))
|
|
|
-
|
|
|
- File(hawq_pid_file, content=pid, owner=hawq_constants.hawq_user, group=hawq_constants.hawq_user)
|
|
|
-
|
|
|
- return hawq_pid_file
|
|
|
+ netstat_cmd = "netstat -tupln | egrep ':{0}\s' | egrep {1}".format(port, process)
|
|
|
+ return_code, _ = call(netstat_cmd)
|
|
|
+ if return_code:
|
|
|
+ raise ComponentIsNotRunning()
|