~ubuntu-branches/ubuntu/vivid/sahara/vivid-proposed

« back to all changes in this revision

Viewing changes to sahara/plugins/hdp/configprovider.py

  • Committer: Package Import Robot
  • Author(s): Thomas Goirand
  • Date: 2014-09-24 16:34:46 UTC
  • Revision ID: package-import@ubuntu.com-20140924163446-8gu3zscu5e3n9lr2
Tags: upstream-2014.2~b3
ImportĀ upstreamĀ versionĀ 2014.2~b3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (c) 2013 Hortonworks, Inc.
 
2
#
 
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
 
6
#
 
7
#    http://www.apache.org/licenses/LICENSE-2.0
 
8
#
 
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
 
12
# implied.
 
13
# See the License for the specific language governing permissions and
 
14
# limitations under the License.
 
15
 
 
16
from sahara import exceptions
 
17
from sahara.i18n import _
 
18
from sahara.plugins import provisioning as p
 
19
 
 
20
 
 
21
class ConfigurationProvider:
 
22
    def __init__(self, config):
 
23
        self.config = config
 
24
        self.config_mapper = {}
 
25
        self.config_items = []
 
26
        self._initialize(config)
 
27
 
 
28
    def get_config_items(self):
 
29
        return self.config_items
 
30
 
 
31
    def get_applicable_target(self, name):
 
32
        return self.config_mapper.get(name)
 
33
 
 
34
    def _get_target(self, apptarget):
 
35
        if apptarget == 'TODO':
 
36
            apptarget = 'general'
 
37
 
 
38
        return apptarget
 
39
 
 
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'],
 
44
                                  self._get_target(
 
45
                                      service_property['applicable_target']),
 
46
                                  service_property['scope'],
 
47
                                  config_type=service_property['config_type'],
 
48
                                  default_value=service_property
 
49
                                  ['default_value'],
 
50
                                  is_optional=service_property[
 
51
                                      'is_optional'],
 
52
                                  description=service_property[
 
53
                                      'description'])
 
54
 
 
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:
 
62
                    # internal error
 
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']] = (
 
68
                    self._get_target(
 
69
                        service_property['applicable_target']))