You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by dm...@apache.org on 2013/12/06 19:20:02 UTC

[1/2] git commit: AMBARI-3993. RMF Remove resource inheritance and enable same name for the resources (Andrew Onischuk via dlysnichenko)

Updated Branches:
  refs/heads/trunk 0a94a0f43 -> 48e2184fe


AMBARI-3993. RMF Remove resource inheritance and enable same name for the resources (Andrew Onischuk via dlysnichenko)


Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/fc3024c5
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/fc3024c5
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/fc3024c5

Branch: refs/heads/trunk
Commit: fc3024c514279f311d6b62d696b9e28227185739
Parents: 0a94a0f
Author: Lisnichenko Dmitro <dl...@hortonworks.com>
Authored: Fri Dec 6 20:17:56 2013 +0200
Committer: Lisnichenko Dmitro <dl...@hortonworks.com>
Committed: Fri Dec 6 20:18:31 2013 +0200

----------------------------------------------------------------------
 .../python/resource_management/core/base.py     | 37 +++-----------------
 1 file changed, 5 insertions(+), 32 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/fc3024c5/ambari-agent/src/main/python/resource_management/core/base.py
----------------------------------------------------------------------
diff --git a/ambari-agent/src/main/python/resource_management/core/base.py b/ambari-agent/src/main/python/resource_management/core/base.py
index 90ce86e..610533c 100644
--- a/ambari-agent/src/main/python/resource_management/core/base.py
+++ b/ambari-agent/src/main/python/resource_management/core/base.py
@@ -28,14 +28,13 @@ from resource_management.core.exceptions import Fail, InvalidArgument
 from resource_management.core.environment import Environment
 
 class ResourceArgument(object):
-  def __init__(self, default=None, required=False, allow_override=False):
+  def __init__(self, default=None, required=False):
     self.required = False # Prevents the initial validate from failing
     if hasattr(default, '__call__'):
       self.default = default
     else:
       self.default = self.validate(default)
     self.required = required
-    self.allow_override = allow_override
 
   def validate(self, value):
     if self.required and value is None:
@@ -117,18 +116,10 @@ class Resource(object):
     r_type = cls.__name__
     if r_type not in env.resources:
       env.resources[r_type] = {}
-    if name not in env.resources[r_type]:
-      obj = super(Resource, cls).__new__(cls)
-      env.resources[r_type][name] = obj
-      env.resource_list.append(obj)
-      return obj
-
-    obj = env.resources[r_type][name]
-    if obj.provider != provider:
-      raise Fail("Duplicate resource %r with a different provider %r != %r" % (
-      obj, provider, obj.provider))
-
-    obj.override(**kwargs)
+
+    obj = super(Resource, cls).__new__(cls)
+    env.resources[r_type][name] = obj
+    env.resource_list.append(obj)
     return obj
 
   def __init__(self, name, env=None, provider=None, **kwargs):
@@ -163,24 +154,6 @@ class Resource(object):
   def validate(self):
     pass
 
-  def override(self, **kwargs):
-    for key, value in kwargs.items():
-      try:
-        arg = self._arguments[key]
-      except KeyError:
-        raise Fail("%s received unsupported argument %s" % (self, key))
-      else:
-        if value != self.arguments.get(key):
-          if not arg.allow_override:
-            raise Fail(
-              "%s doesn't allow overriding argument '%s'" % (self, key))
-
-          try:
-            self.arguments[key] = arg.validate(value)
-          except InvalidArgument, exc:
-            raise InvalidArgument("%s %s" % (self, exc))
-    self.validate()
-
   def __repr__(self):
     return "%s['%s']" % (self.__class__.__name__, self.name)
 


[2/2] git commit: AMBARI-3994. Create repository install functionality in the base script (Andrew Onischuk via dlysnichenko)

Posted by dm...@apache.org.
AMBARI-3994. Create repository install functionality in the base script (Andrew Onischuk via dlysnichenko)


Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/48e2184f
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/48e2184f
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/48e2184f

Branch: refs/heads/trunk
Commit: 48e2184fe1e5b0f543d41551d50d2f0be41b58fe
Parents: fc3024c
Author: Lisnichenko Dmitro <dl...@hortonworks.com>
Authored: Fri Dec 6 20:19:09 2013 +0200
Committer: Lisnichenko Dmitro <dl...@hortonworks.com>
Committed: Fri Dec 6 20:19:09 2013 +0200

----------------------------------------------------------------------
 .../libraries/providers/__init__.py             |  3 +-
 .../libraries/providers/repository.py           | 53 +++++++++++++++++
 .../libraries/resources/__init__.py             |  3 +-
 .../libraries/resources/repository.py           | 34 +++++++++++
 .../libraries/script/config_dictionary.py       | 59 +++++++++++++++++++
 .../libraries/script/repo_installer.py          | 60 ++++++++++++++++++++
 .../libraries/script/script.py                  | 47 +++------------
 7 files changed, 217 insertions(+), 42 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/48e2184f/ambari-agent/src/main/python/resource_management/libraries/providers/__init__.py
----------------------------------------------------------------------
diff --git a/ambari-agent/src/main/python/resource_management/libraries/providers/__init__.py b/ambari-agent/src/main/python/resource_management/libraries/providers/__init__.py
index 89a31e9..65bbb49 100644
--- a/ambari-agent/src/main/python/resource_management/libraries/providers/__init__.py
+++ b/ambari-agent/src/main/python/resource_management/libraries/providers/__init__.py
@@ -35,6 +35,7 @@ PROVIDERS = dict(
     ExecuteHadoop="resource_management.libraries.providers.execute_hadoop.ExecuteHadoopProvider",
     TemplateConfig="resource_management.libraries.providers.template_config.TemplateConfigProvider",
     XmlConfig="resource_management.libraries.providers.xml_config.XmlConfigProvider",
-    MonitorWebserver="resource_management.libraries.providers.monitor_webserver.MonitorWebserverProvider"
+    MonitorWebserver="resource_management.libraries.providers.monitor_webserver.MonitorWebserverProvider",
+    Repository="resource_management.libraries.providers.repository.RepositoryProvider"
   ),
 )

http://git-wip-us.apache.org/repos/asf/ambari/blob/48e2184f/ambari-agent/src/main/python/resource_management/libraries/providers/repository.py
----------------------------------------------------------------------
diff --git a/ambari-agent/src/main/python/resource_management/libraries/providers/repository.py b/ambari-agent/src/main/python/resource_management/libraries/providers/repository.py
new file mode 100644
index 0000000..70ecdb7
--- /dev/null
+++ b/ambari-agent/src/main/python/resource_management/libraries/providers/repository.py
@@ -0,0 +1,53 @@
+#!/usr/bin/env python2.6
+"""
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements.  See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership.  The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License.  You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+
+Ambari Agent
+
+"""
+
+from resource_management import *
+
+class RepositoryProvider(Provider):
+  def action_create(self):
+    with Environment.get_instance_copy() as env:
+      repo_file_name = self.resource.repo_file_name
+      repo_dir = repos_dirs[env.system.platform]
+      
+      File(format("{repo_dir}/{repo_file_name}.repo"),
+        content = InlineTemplate("""[{{repo_id}}]
+name={{repo_file_name}}
+{% if mirror_list %}mirrorlist={{mirror_list}}{% else %}baseurl={{base_url}}{% endif %}
+path=/
+enabled=1
+gpgcheck=0""", repo_id=self.resource.repo_id, repo_file_name=self.resource.repo_file_name, base_url=self.resource.base_url, mirror_list=self.resource.mirror_list)
+      )
+  
+  def action_remove(self):
+    with Environment.get_instance_copy() as env:
+      repo_file_name = self.resource.repo_file_name
+      repo_dir = repos_dirs[env.system.platform]
+        
+      File(format("{repo_dir}/{repo_file_name}.repo"),
+           action = "delete")
+    
+  
+repos_dirs = {
+  'centos': '/etc/yum.repos.d',
+  'redhat': '/etc/yum.repos.d',
+  'suse': '/etc/zypp/repos.d'
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ambari/blob/48e2184f/ambari-agent/src/main/python/resource_management/libraries/resources/__init__.py
----------------------------------------------------------------------
diff --git a/ambari-agent/src/main/python/resource_management/libraries/resources/__init__.py b/ambari-agent/src/main/python/resource_management/libraries/resources/__init__.py
index 38f731b..11de524 100644
--- a/ambari-agent/src/main/python/resource_management/libraries/resources/__init__.py
+++ b/ambari-agent/src/main/python/resource_management/libraries/resources/__init__.py
@@ -22,4 +22,5 @@ Ambari Agent
 
 from resource_management.libraries.resources.execute_hadoop import *
 from resource_management.libraries.resources.template_config import *
-from resource_management.libraries.resources.xml_config import *
\ No newline at end of file
+from resource_management.libraries.resources.xml_config import *
+from resource_management.libraries.resources.repository import *
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ambari/blob/48e2184f/ambari-agent/src/main/python/resource_management/libraries/resources/repository.py
----------------------------------------------------------------------
diff --git a/ambari-agent/src/main/python/resource_management/libraries/resources/repository.py b/ambari-agent/src/main/python/resource_management/libraries/resources/repository.py
new file mode 100644
index 0000000..139fef4
--- /dev/null
+++ b/ambari-agent/src/main/python/resource_management/libraries/resources/repository.py
@@ -0,0 +1,34 @@
+#!/usr/bin/env python2.6
+"""
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements.  See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership.  The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License.  You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+
+Ambari Agent
+
+"""
+
+_all__ = ["Repository"]
+
+from resource_management.core.base import Resource, ForcedListArgument, ResourceArgument, BooleanArgument
+
+class Repository(Resource):
+  action = ForcedListArgument(default="create")
+  repo_id = ResourceArgument(default=lambda obj: obj.name)
+  base_url = ResourceArgument()
+  mirror_list = ResourceArgument()
+  repo_file_name = ResourceArgument()
+
+  actions = Resource.actions + ["create","remove"]
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ambari/blob/48e2184f/ambari-agent/src/main/python/resource_management/libraries/script/config_dictionary.py
----------------------------------------------------------------------
diff --git a/ambari-agent/src/main/python/resource_management/libraries/script/config_dictionary.py b/ambari-agent/src/main/python/resource_management/libraries/script/config_dictionary.py
new file mode 100644
index 0000000..577f78b
--- /dev/null
+++ b/ambari-agent/src/main/python/resource_management/libraries/script/config_dictionary.py
@@ -0,0 +1,59 @@
+#!/usr/bin/env python2.6
+
+'''
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements.  See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership.  The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License.  You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+'''
+from resource_management.core.exceptions import Fail
+
+class ConfigDictionary(dict):
+  """
+  Immutable config dictionary
+  """
+  
+  def __init__(self, dictionary):
+    """
+    Recursively turn dict to ConfigDictionary
+    """
+    for k, v in dictionary.iteritems():
+      if isinstance(v, dict):
+        dictionary[k] = ConfigDictionary(v)
+        
+    super(ConfigDictionary, self).__init__(dictionary)
+
+  def __setitem__(self, name, value):
+    raise Fail("Configuration dictionary is immutable!")
+
+  def __getitem__(self, name):
+    """
+    Use Python types
+    """
+    value = super(ConfigDictionary, self).__getitem__(name)
+    
+    if value == "true":
+      value = True
+    elif value == "false":
+      value = False
+    else: 
+      try:
+        value = int(value)
+      except (ValueError, TypeError):
+        try:
+          value =  float(value)
+        except (ValueError, TypeError):
+          pass
+    
+    return value
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ambari/blob/48e2184f/ambari-agent/src/main/python/resource_management/libraries/script/repo_installer.py
----------------------------------------------------------------------
diff --git a/ambari-agent/src/main/python/resource_management/libraries/script/repo_installer.py b/ambari-agent/src/main/python/resource_management/libraries/script/repo_installer.py
new file mode 100644
index 0000000..8471ed7
--- /dev/null
+++ b/ambari-agent/src/main/python/resource_management/libraries/script/repo_installer.py
@@ -0,0 +1,60 @@
+#!/usr/bin/env python2.6
+
+'''
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements.  See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership.  The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License.  You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+'''
+import json
+from resource_management.libraries.resources.repository import Repository
+
+class RepoInstaller():    
+  @classmethod
+  def install_repos(cls, config):
+    cls._alter_repo("create", config['hostLevelParams']['repo_info'])
+    
+    if 'service_repo_info' in config['hostLevelParams']:
+      cls._alter_repo("create", config['hostLevelParams']['service_repo_info'])
+      
+  @classmethod
+  def remove_repos(cls, config):
+    cls._alter_repo("remove", config['hostLevelParams']['repo_info'])
+    
+    if 'service_repo_info' in config['hostLevelParams']:
+      cls._alter_repo("remove", config['hostLevelParams']['service_repo_info'])
+      
+  @staticmethod
+  def _alter_repo(action, repo_string):
+    """
+    @param action: "delete" or "create"
+    @param repo_string: e.g. "[{\"baseUrl\":\"http://public-repo-1.hortonworks.com/HDP/centos6/2.x/updates/2.0.6.0\",\"osType\":\"centos6\",\"repoId\":\"HDP-2.0._\",\"repoName\":\"HDP\",\"defaultBaseUrl\":\"http://public-repo-1.hortonworks.com/HDP/centos6/2.x/updates/2.0.6.0\"}]"
+    """
+    print repo_string
+    repo_dicts = json.loads(repo_string)
+    
+    if not isinstance(repo_dicts, list):
+      repo_dicts = [repo_dicts]
+      
+    for repo in repo_dicts:   
+      if not 'baseUrl' in repo:
+        repo['baseUrl'] = None
+      if not 'mirrorsList' in repo:
+        repo['mirrorsList'] = None
+      
+      Repository(repo['repoId'],
+                 action = action,
+                 base_url = repo['baseUrl'],
+                 mirror_list = repo['mirrorsList'],
+                 repo_file_name = repo['repoName'])
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ambari/blob/48e2184f/ambari-agent/src/main/python/resource_management/libraries/script/script.py
----------------------------------------------------------------------
diff --git a/ambari-agent/src/main/python/resource_management/libraries/script/script.py b/ambari-agent/src/main/python/resource_management/libraries/script/script.py
index d75808e..2f3717a 100644
--- a/ambari-agent/src/main/python/resource_management/libraries/script/script.py
+++ b/ambari-agent/src/main/python/resource_management/libraries/script/script.py
@@ -27,6 +27,8 @@ import logging
 from resource_management.core.environment import Environment
 from resource_management.core.exceptions import Fail
 from resource_management.core.resources.packaging import Package
+from resource_management.libraries.script.config_dictionary import ConfigDictionary
+from resource_management.libraries.script.repo_installer import RepoInstaller
 
 class Script():
   """
@@ -120,6 +122,8 @@ class Script():
     from this list
     """
     config = self.get_config()
+    RepoInstaller.install_repos(config)
+    
     try:
       package_list_str = config['hostLevelParams']['package_list']
       if isinstance(package_list_str,basestring) and len(package_list_str) > 0:
@@ -129,6 +133,8 @@ class Script():
           Package(name)
     except KeyError:
       pass # No reason to worry
+    
+    RepoInstaller.remove_repos(config)
 
 
 
@@ -138,43 +144,4 @@ class Script():
     """
     print("Error: " + message)
     sys.stderr.write("Error: " + message)
-    sys.exit(1)
-
-class ConfigDictionary(dict):
-  """
-  Immutable config dictionary
-  """
-  
-  def __init__(self, dictionary):
-    """
-    Recursively turn dict to ConfigDictionary
-    """
-    for k, v in dictionary.iteritems():
-      if isinstance(v, dict):
-        dictionary[k] = ConfigDictionary(v)
-        
-    super(ConfigDictionary, self).__init__(dictionary)
-
-  def __setitem__(self, name, value):
-    raise Fail("Configuration dictionary is immutable!")
-
-  def __getitem__(self, name):
-    """
-    Use Python types
-    """
-    value = super(ConfigDictionary, self).__getitem__(name)
-    
-    if value == "true":
-      value = True
-    elif value == "false":
-      value = False
-    else: 
-      try:
-        value = int(value)
-      except (ValueError, TypeError):
-        try:
-          value =  float(value)
-        except (ValueError, TypeError):
-          pass
-    
-    return value
+    sys.exit(1)
\ No newline at end of file