ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dmitriu...@apache.org
Subject [2/2] git commit: AMBARI-3994. Create repository install functionality in the base script (Andrew Onischuk via dlysnichenko)
Date Fri, 06 Dec 2013 18:20:03 GMT
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 <dlysnichenko@hortonworks.com>
Authored: Fri Dec 6 20:19:09 2013 +0200
Committer: Lisnichenko Dmitro <dlysnichenko@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


Mime
View raw message