AMBARI-21581 - Replace Hard Coded conf-select Structures (jonathanhurley)
[ambari.git] / ambari-server / src / main / resources / common-services / ACCUMULO / 1.6.1.2.2.0 / package / scripts / accumulo_script.py
1 #!/usr/bin/env python
2 """
3 Licensed to the Apache Software Foundation (ASF) under one
4 or more contributor license agreements. See the NOTICE file
5 distributed with this work for additional information
6 regarding copyright ownership. The ASF licenses this file
7 to you under the Apache License, Version 2.0 (the
8 "License"); you may not use this file except in compliance
9 with the License. You may obtain a copy of the License at
10
11 http://www.apache.org/licenses/LICENSE-2.0
12
13 Unless required by applicable law or agreed to in writing, software
14 distributed under the License is distributed on an "AS IS" BASIS,
15 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 See the License for the specific language governing permissions and
17 limitations under the License.
18
19 """
20 from resource_management.core.exceptions import Fail
21 from resource_management.core.logger import Logger
22 from resource_management.libraries.functions import format
23 from resource_management.libraries.functions import check_process_status
24 from resource_management.libraries.functions import stack_select
25 from resource_management.libraries.functions.security_commons import build_expectations
26 from resource_management.libraries.functions.security_commons import cached_kinit_executor
27 from resource_management.libraries.functions.security_commons import get_params_from_filesystem
28 from resource_management.libraries.functions.security_commons import validate_security_config_properties
29 from resource_management.libraries.functions.security_commons import FILE_TYPE_XML
30 from resource_management.libraries.script.script import Script
31 from resource_management.libraries.functions.stack_features import check_stack_feature
32 from resource_management.libraries.functions import StackFeature
33
34 from accumulo_configuration import setup_conf_dir
35 from accumulo_service import accumulo_service
36
37 class AccumuloScript(Script):
38
39 def __init__(self, component):
40 self.component = component
41
42
43 def install(self, env):
44 self.install_packages(env)
45
46
47 def configure(self, env):
48 import params
49 env.set_params(params)
50
51 setup_conf_dir(name=self.component)
52
53
54 def start(self, env, upgrade_type=None):
55 import params
56 env.set_params(params)
57 self.configure(env) # for security
58
59 accumulo_service( self.component, action = 'start')
60
61
62 def stop(self, env, upgrade_type=None):
63 import params
64 env.set_params(params)
65
66 accumulo_service( self.component, action = 'stop')
67
68
69 def status(self, env):
70 import status_params
71 env.set_params(status_params)
72
73 pid_file = self.get_pid_files()[0]
74 check_process_status(pid_file)
75
76
77 def pre_upgrade_restart(self, env, upgrade_type=None):
78 import params
79 env.set_params(params)
80
81 # this function should not execute if the version can't be determined or
82 # the stack does not support rolling upgrade
83 if not (params.stack_version_formatted and check_stack_feature(StackFeature.ROLLING_UPGRADE, params.stack_version_formatted)):
84 return
85
86 stack_component = stack_select.get_package_name()
87
88 Logger.info("Executing Accumulo Upgrade pre-restart for {0}".format(stack_component))
89 stack_select.select_packages(params.version)
90
91 def get_log_folder(self):
92 import params
93 return params.log_dir
94
95 def get_pid_files(self):
96 import status_params
97
98 pid_file = "{pid_dir}/accumulo-{accumulo_user}-{component}.pid".format(
99 pid_dir = status_params.pid_dir,
100 accumulo_user = status_params.accumulo_user,
101 component = self.component)
102 return [pid_file]
103
104 def get_user(self):
105 import params
106 return params.accumulo_user
107
108 if __name__ == "__main__":
109 AccumuloScript().fail_with_error('component unspecified')