1
# Copyright (c) 2013 Hortonworks, Inc.
3
# Licensed under the Apache License, Version 2.0 (the "License");
4
# you may not use this file except in compliance with the License.
5
# You may obtain a copy of the License at
7
# http://www.apache.org/licenses/LICENSE-2.0
9
# Unless required by applicable law or agreed to in writing, software
10
# distributed under the License is distributed on an "AS IS" BASIS,
11
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
13
# See the License for the specific language governing permissions and
14
# limitations under the License.
16
from sahara import exceptions
17
from sahara.i18n import _
18
from sahara.plugins import provisioning as p
21
class ConfigurationProvider:
22
def __init__(self, config):
24
self.config_mapper = {}
25
self.config_items = []
26
self._initialize(config)
28
def get_config_items(self):
29
return self.config_items
31
def get_applicable_target(self, name):
32
return self.config_mapper.get(name)
34
def _get_target(self, apptarget):
35
if apptarget == 'TODO':
40
def _initialize(self, config):
41
for configuration in self.config['configurations']:
42
for service_property in configuration['properties']:
43
config = p.Config(service_property['name'],
45
service_property['applicable_target']),
46
service_property['scope'],
47
config_type=service_property['config_type'],
48
default_value=service_property
50
is_optional=service_property[
52
description=service_property[
55
setattr(config, 'tag', configuration['tag'].rsplit(".", 1)[0])
56
self.config_items.append(config)
57
# TODO(jspeidel): an assumption is made that property names
58
# are unique across configuration sections which is dangerous
59
property_name = service_property['name']
60
# if property already exists, throw an exception
61
if property_name in self.config_mapper:
63
# ambari-config-resource contains duplicates
64
raise exceptions.InvalidDataException(
65
_('Internal Error. Duplicate property '
66
'name detected: %s') % property_name)
67
self.config_mapper[service_property['name']] = (
69
service_property['applicable_target']))