AMBARI-21581 - Replace Hard Coded conf-select Structures (jonathanhurley)
[ambari.git] / ambari-server / src / main / resources / common-services / HDFS / 2.1.0.2.0 / package / scripts / journalnode.py
1 """
2 Licensed to the Apache Software Foundation (ASF) under one
3 or more contributor license agreements. See the NOTICE file
4 distributed with this work for additional information
5 regarding copyright ownership. The ASF licenses this file
6 to you under the Apache License, Version 2.0 (the
7 "License"); you may not use this file except in compliance
8 with the License. You may obtain a copy of the License at
9
10 http://www.apache.org/licenses/LICENSE-2.0
11
12 Unless required by applicable law or agreed to in writing, software
13 distributed under the License is distributed on an "AS IS" BASIS,
14 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 See the License for the specific language governing permissions and
16 limitations under the License.
17
18 """
19 from ambari_commons.constants import UPGRADE_TYPE_NON_ROLLING
20
21 from resource_management.libraries.script.script import Script
22 from resource_management.libraries.functions import stack_select
23 from resource_management.libraries.functions.constants import StackFeature
24 from resource_management.libraries.functions.stack_features import check_stack_feature
25 from resource_management.libraries.functions.check_process_status import check_process_status
26 from resource_management.libraries.functions.security_commons import build_expectations, \
27 cached_kinit_executor, get_params_from_filesystem, validate_security_config_properties, \
28 FILE_TYPE_XML
29 from resource_management.core.logger import Logger
30 from resource_management.core.resources.system import Directory
31 from utils import service
32 from hdfs import hdfs
33 import journalnode_upgrade
34 from ambari_commons.os_family_impl import OsFamilyImpl
35 from ambari_commons import OSConst
36
37 class JournalNode(Script):
38 def install(self, env):
39 import params
40 env.set_params(params)
41 self.install_packages(env)
42
43 @OsFamilyImpl(os_family=OsFamilyImpl.DEFAULT)
44 class JournalNodeDefault(JournalNode):
45
46 def pre_upgrade_restart(self, env, upgrade_type=None):
47 Logger.info("Executing Stack Upgrade pre-restart")
48 import params
49 env.set_params(params)
50
51 if params.version and check_stack_feature(StackFeature.ROLLING_UPGRADE, params.version):
52 stack_select.select_packages(params.version)
53
54 def start(self, env, upgrade_type=None):
55 import params
56
57 env.set_params(params)
58 self.configure(env)
59 service(
60 action="start", name="journalnode", user=params.hdfs_user,
61 create_pid_dir=True,
62 create_log_dir=True
63 )
64
65 def post_upgrade_restart(self, env, upgrade_type=None):
66 # express upgrade cannot determine if the JN quorum is established
67 if upgrade_type == UPGRADE_TYPE_NON_ROLLING:
68 return
69
70 Logger.info("Executing Stack Upgrade post-restart")
71 import params
72 env.set_params(params)
73 journalnode_upgrade.post_upgrade_check()
74
75 def stop(self, env, upgrade_type=None):
76 import params
77
78 env.set_params(params)
79 service(
80 action="stop", name="journalnode", user=params.hdfs_user,
81 create_pid_dir=True,
82 create_log_dir=True
83 )
84
85 def configure(self, env):
86 import params
87
88 Directory(params.jn_edits_dir,
89 create_parents = True,
90 cd_access="a",
91 owner=params.hdfs_user,
92 group=params.user_group
93 )
94 env.set_params(params)
95 hdfs()
96 pass
97
98 def status(self, env):
99 import status_params
100
101 env.set_params(status_params)
102 check_process_status(status_params.journalnode_pid_file)
103
104 def get_log_folder(self):
105 import params
106 return params.hdfs_log_dir
107
108 def get_user(self):
109 import params
110 return params.hdfs_user
111
112 def get_pid_files(self):
113 import status_params
114 return [status_params.journalnode_pid_file]
115
116 @OsFamilyImpl(os_family=OSConst.WINSRV_FAMILY)
117 class JournalNodeWindows(JournalNode):
118 def install(self, env):
119 import install_params
120 self.install_packages(env)
121
122 def start(self, env):
123 import params
124 self.configure(env)
125 Service(params.journalnode_win_service_name, action="start")
126
127 def stop(self, env):
128 import params
129 Service(params.journalnode_win_service_name, action="stop")
130
131 def configure(self, env):
132 import params
133 env.set_params(params)
134 hdfs("journalnode")
135 pass
136
137 def status(self, env):
138 import status_params
139 env.set_params(status_params)
140 check_windows_service_status(status_params.journalnode_win_service_name)
141
142 if __name__ == "__main__":
143 JournalNode().execute()