ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d...@apache.org
Subject git commit: AMBARI-5965 Usability: .repo file template should be part of a Stack definition (aonishuk via dsen)
Date Fri, 30 May 2014 18:05:47 GMT
Repository: ambari
Updated Branches:
  refs/heads/trunk c8de2f181 -> aff11a3b5


AMBARI-5965 Usability: .repo file template should be part of a Stack definition (aonishuk
via dsen)


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

Branch: refs/heads/trunk
Commit: aff11a3b5315cbadd35df61a41764522e7b742fb
Parents: c8de2f1
Author: Dmitry Sen <dsen@hortonworks.com>
Authored: Fri May 30 21:05:37 2014 +0300
Committer: Dmitry Sen <dsen@hortonworks.com>
Committed: Fri May 30 21:05:37 2014 +0300

----------------------------------------------------------------------
 .../libraries/providers/repository.py           | 13 ++--
 .../libraries/resources/repository.py           |  1 +
 .../libraries/script/repo_installer.py          | 63 -----------------
 .../libraries/script/script.py                  |  4 +-
 .../TestRepositoryResource.py                   | 74 ++++++++++++++------
 .../python/resource_management/TestScript.py    |  6 +-
 .../1.3.2/hooks/before-INSTALL/scripts/hook.py  |  2 +
 .../hooks/before-INSTALL/scripts/params.py      |  7 +-
 .../scripts/repo_initialization.py              | 55 +++++++++++++++
 .../before-INSTALL/templates/repo_debian.j2     |  1 +
 .../before-INSTALL/templates/repo_suse_rhel.j2  |  7 ++
 .../2.0.6/hooks/before-INSTALL/scripts/hook.py  |  3 +-
 .../hooks/before-INSTALL/scripts/params.py      |  4 ++
 .../scripts/repo_initialization.py              | 54 ++++++++++++++
 .../before-INSTALL/templates/repo_debian.j2     |  1 +
 .../before-INSTALL/templates/repo_suse_rhel.j2  |  7 ++
 .../hooks/before-INSTALL/test_before_install.py |  8 +++
 .../python/stacks/2.0.6/configs/default.json    |  3 +-
 .../hooks/before-INSTALL/test_before_install.py |  8 +++
 19 files changed, 220 insertions(+), 101 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/aff11a3b/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
index 32fa75b..330395e 100644
--- a/ambari-agent/src/main/python/resource_management/libraries/providers/repository.py
+++ b/ambari-agent/src/main/python/resource_management/libraries/providers/repository.py
@@ -31,21 +31,16 @@ class RhelSuseRepositoryProvider(Provider):
     with Environment.get_instance_copy() as env:
       repo_file_name = self.resource.repo_file_name
       repo_dir = repos_dirs[env.system.os_family]
-      
+      repo_template = self.resource.repo_template
       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)
+        content = Template(repo_template, 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.os_family]
-        
+
       File(format("{repo_dir}/{repo_file_name}.repo"),
            action = "delete")
     
@@ -65,7 +60,7 @@ class DebianRepositoryProvider(Provider):
     with Environment.get_instance_copy() as env:
       with tempfile.NamedTemporaryFile() as tmpf:
         File(tmpf.name,
-          content = InlineTemplate("{{package_type}} {{base_url}} {{components}}", 
+          content = Template(self.resource.repo_template,
               package_type=self.package_type, base_url=self.resource.base_url, components='
'.join(self.resource.components))
         )
         

http://git-wip-us.apache.org/repos/asf/ambari/blob/aff11a3b/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
index ad6c919..48a347a 100644
--- a/ambari-agent/src/main/python/resource_management/libraries/resources/repository.py
+++ b/ambari-agent/src/main/python/resource_management/libraries/resources/repository.py
@@ -30,6 +30,7 @@ class Repository(Resource):
   base_url = ResourceArgument()
   mirror_list = ResourceArgument()
   repo_file_name = ResourceArgument()
+  repo_template = ResourceArgument()
   components = ForcedListArgument(default=[]) # ubuntu specific
 
   actions = Resource.actions + ["create","remove"]
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ambari/blob/aff11a3b/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
deleted file mode 100644
index 082aaea..0000000
--- a/ambari-agent/src/main/python/resource_management/libraries/script/repo_installer.py
+++ /dev/null
@@ -1,63 +0,0 @@
-#!/usr/bin/env python
-
-'''
-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
-
-UBUNTU_REPO_COMPONENTS = ["HDP", "main"]
-
-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\"}]"
-    """
-    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'],
-                 components = UBUNTU_REPO_COMPONENTS, # ubuntu specific
-      )

http://git-wip-us.apache.org/repos/asf/ambari/blob/aff11a3b/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 3fbb067..69e7493 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
@@ -29,7 +29,6 @@ from resource_management.core.environment import Environment
 from resource_management.core.exceptions import Fail, ClientComponentHasNoStatus, ComponentIsNotRunning
 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
 
 USAGE = """Usage: {0} <COMMAND> <JSON_CONFIG> <BASEDIR> <STROUTPUT>
<LOGGING_LEVEL>
 
@@ -152,12 +151,11 @@ class Script(object):
 
   def install_packages(self, env, exclude_packages=[]):
     """
-    List of packages that are required by service is received from the server
+    List of packages that are required< by service is received from the server
     as a command parameter. The method installs all packages
     from this list
     """
     config = self.get_config()
-    RepoInstaller.install_repos(config)
     
     try:
       package_list_str = config['hostLevelParams']['package_list']

http://git-wip-us.apache.org/repos/asf/ambari/blob/aff11a3b/ambari-agent/src/test/python/resource_management/TestRepositoryResource.py
----------------------------------------------------------------------
diff --git a/ambari-agent/src/test/python/resource_management/TestRepositoryResource.py b/ambari-agent/src/test/python/resource_management/TestRepositoryResource.py
index 529a887..db44f77 100644
--- a/ambari-agent/src/test/python/resource_management/TestRepositoryResource.py
+++ b/ambari-agent/src/test/python/resource_management/TestRepositoryResource.py
@@ -16,12 +16,40 @@ See the License for the specific language governing permissions and
 limitations under the License.
 '''
 
-import os
+import os, sys
 import tempfile
 from unittest import TestCase
 from mock.mock import patch, MagicMock
 
 from resource_management import *
+from resource_management.libraries.providers import repository
+
+
+class DummyTemplate(object):
+
+  def __init__(self, name, extra_imports=[], **kwargs):
+    self._template = InlineTemplate(DummyTemplate._inline_text, extra_imports, **kwargs)
+    self.context = self._template.context
+    self.name = name
+
+  def get_content(self):
+    self.content = self._template.get_content()
+    return self.content
+
+  @classmethod
+  def create(cls, text):
+    cls._inline_text = text
+    return cls
+
+DEBIAN_DEFAUTL_TEMPLATE = "{{package_type}} {{base_url}} {{components}}\n"
+RHEL_SUSE_DEFAULT_TEMPLATE ="""[{{repo_id}}]
+name={{repo_file_name}}
+{% if mirror_list %}mirrorlist={{mirror_list}}{% else %}baseurl={{base_url}}{% endif %}
+
+path=/
+enabled=1
+gpgcheck=0
+"""
 
 
 class TestRepositoryResource(TestCase):
@@ -29,14 +57,20 @@ class TestRepositoryResource(TestCase):
     @patch("resource_management.libraries.providers.repository.File")
     def test_create_repo_redhat(self, file_mock):
         with Environment('/') as env:
+          with patch.object(repository,"Template", new=DummyTemplate.create(RHEL_SUSE_DEFAULT_TEMPLATE)):
             Repository('hadoop',
                        base_url='http://download.base_url.org/rpm/',
                        mirror_list='https://mirrors.base_url.org/?repo=Repository&arch=$basearch',
-                       repo_file_name='Repository')
+                       repo_file_name='Repository',
+                       repo_template='dummy.j2')
 
             self.assertTrue('hadoop' in env.resources['Repository'])
             defined_arguments = env.resources['Repository']['hadoop'].arguments
-            expected_arguments = {'base_url': 'http://download.base_url.org/rpm/',
+            expected_arguments = {'repo_template': 'dummy.j2',
+                                  'base_url': 'http://download.base_url.org/rpm/',
+                                  'mirror_list': 'https://mirrors.base_url.org/?repo=Repository&arch=$basearch',
+                                  'repo_file_name': 'Repository'}
+            expected_template_arguments = {'base_url': 'http://download.base_url.org/rpm/',
                                   'mirror_list': 'https://mirrors.base_url.org/?repo=Repository&arch=$basearch',
                                   'repo_file_name': 'Repository'}
 
@@ -45,30 +79,31 @@ class TestRepositoryResource(TestCase):
 
             template_item = file_mock.call_args[1]['content']
             template = str(template_item.name)
-            expected_arguments.update({'repo_id': 'hadoop'})
+            expected_template_arguments.update({'repo_id': 'hadoop'})
 
-            self.assertEqual(expected_arguments, template_item.context._dict)
-            self.assertEqual("""[{{repo_id}}]
-name={{repo_file_name}}
-{% if mirror_list %}mirrorlist={{mirror_list}}{% else %}baseurl={{base_url}}{% endif %}
-path=/
-enabled=1
-gpgcheck=0""", template)
+            self.assertEqual(expected_template_arguments, template_item.context._dict)
+            self.assertEqual('dummy.j2', template)
 
 
     @patch.object(System, "os_family", new='suse')
     @patch("resource_management.libraries.providers.repository.File")
     def test_create_repo_suse(self, file_mock):
         with Environment('/') as env:
+          with patch.object(repository,"Template", new=DummyTemplate.create(RHEL_SUSE_DEFAULT_TEMPLATE)):
             Repository('hadoop',
                        base_url='http://download.base_url.org/rpm/',
                        mirror_list='https://mirrors.base_url.org/?repo=Repository&arch=$basearch',
+                       repo_template = "dummy.j2",
                        repo_file_name='Repository')
 
             self.assertTrue('hadoop' in env.resources['Repository'])
             defined_arguments = env.resources['Repository']['hadoop'].arguments
-            expected_arguments = {'base_url': 'http://download.base_url.org/rpm/',
+            expected_arguments = {'repo_template': 'dummy.j2',
                                   'mirror_list': 'https://mirrors.base_url.org/?repo=Repository&arch=$basearch',
+                                  'base_url': 'http://download.base_url.org/rpm/',
+                                  'repo_file_name': 'Repository'}
+            expected_template_arguments = {'mirror_list': 'https://mirrors.base_url.org/?repo=Repository&arch=$basearch',
+                                  'base_url': 'http://download.base_url.org/rpm/',
                                   'repo_file_name': 'Repository'}
 
             self.assertEqual(defined_arguments, expected_arguments)
@@ -76,15 +111,10 @@ gpgcheck=0""", template)
 
             template_item = file_mock.call_args[1]['content']
             template = str(template_item.name)
-            expected_arguments.update({'repo_id': 'hadoop'})
+            expected_template_arguments.update({'repo_id': 'hadoop'})
 
-            self.assertEqual(expected_arguments, template_item.context._dict)
-            self.assertEqual("""[{{repo_id}}]
-name={{repo_file_name}}
-{% if mirror_list %}mirrorlist={{mirror_list}}{% else %}baseurl={{base_url}}{% endif %}
-path=/
-enabled=1
-gpgcheck=0""", template)   
+            self.assertEqual(expected_template_arguments, template_item.context._dict)
+            self.assertEqual('dummy.j2', template)
     
     
     @patch.object(tempfile, "NamedTemporaryFile")
@@ -99,9 +129,11 @@ gpgcheck=0""", template)
       tempfile_mock.return_value.__enter__.return_value.name = "/tmp/1.txt"
       
       with Environment('/') as env:
+        with patch.object(repository,"Template", new=DummyTemplate.create(DEBIAN_DEFAUTL_TEMPLATE)):
           Repository('HDP',
                      base_url='http://download.base_url.org/rpm/',
                      repo_file_name='HDP',
+                     repo_template = "dummy.j2",
                      components = ['a','b','c']
           )
       
@@ -130,9 +162,11 @@ gpgcheck=0""", template)
       tempfile_mock.return_value.__enter__.return_value.name = "/tmp/1.txt"
       
       with Environment('/') as env:
+        with patch.object(repository,"Template", new=DummyTemplate.create(DEBIAN_DEFAUTL_TEMPLATE)):
           Repository('HDP',
                      base_url='http://download.base_url.org/rpm/',
                      repo_file_name='HDP',
+                     repo_template = "dummy.j2",
                      components = ['a','b','c']
           )
       

http://git-wip-us.apache.org/repos/asf/ambari/blob/aff11a3b/ambari-agent/src/test/python/resource_management/TestScript.py
----------------------------------------------------------------------
diff --git a/ambari-agent/src/test/python/resource_management/TestScript.py b/ambari-agent/src/test/python/resource_management/TestScript.py
index 23bbef1..bff04b4 100644
--- a/ambari-agent/src/test/python/resource_management/TestScript.py
+++ b/ambari-agent/src/test/python/resource_management/TestScript.py
@@ -73,7 +73,7 @@ class TestScript(TestCase):
       Script.config = no_packages_config
       script.install_packages(env)
     resource_dump = pprint.pformat(env.resource_list)
-    self.assertEquals(resource_dump, "[Repository['HDP-2.0._']]")
+    self.assertEquals(resource_dump, "[]")
 
     # Testing empty package list
     with Environment(".", test_mode=True) as env:
@@ -81,14 +81,14 @@ class TestScript(TestCase):
       Script.config = empty_config
       script.install_packages(env)
     resource_dump = pprint.pformat(env.resource_list)
-    self.assertEquals(resource_dump, "[Repository['HDP-2.0._']]")
+    self.assertEquals(resource_dump, "[]")
 
     # Testing installing of a list of packages
     with Environment(".", test_mode=True) as env:
       Script.config = dummy_config
       script.install_packages("env")
     resource_dump = pprint.pformat(env.resource_list)
-    self.assertEqual(resource_dump, "[Repository['HDP-2.0._'],\n Repository['HDP-2.0._'],\n
Package['hbase'],\n Package['yet-another-package']]")
+    self.assertEqual(resource_dump, "[Package['hbase'], Package['yet-another-package']]")
 
   @patch("__builtin__.open")
   def test_structured_out(self, open_mock):

http://git-wip-us.apache.org/repos/asf/ambari/blob/aff11a3b/ambari-server/src/main/resources/stacks/HDP/1.3.2/hooks/before-INSTALL/scripts/hook.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/stacks/HDP/1.3.2/hooks/before-INSTALL/scripts/hook.py
b/ambari-server/src/main/resources/stacks/HDP/1.3.2/hooks/before-INSTALL/scripts/hook.py
index 9b200af..626b199 100644
--- a/ambari-server/src/main/resources/stacks/HDP/1.3.2/hooks/before-INSTALL/scripts/hook.py
+++ b/ambari-server/src/main/resources/stacks/HDP/1.3.2/hooks/before-INSTALL/scripts/hook.py
@@ -20,6 +20,7 @@ limitations under the License.
 import sys
 from resource_management import *
 from shared_initialization import *
+from repo_initialization import install_repos
 
 #TODO this must be "CONFIGURE" hook when CONFIGURE command will be implemented
 class BeforeConfigureHook(Hook):
@@ -28,6 +29,7 @@ class BeforeConfigureHook(Hook):
     import params
 
     env.set_params(params)
+    install_repos()
     setup_java()
     setup_users()
     install_packages()

http://git-wip-us.apache.org/repos/asf/ambari/blob/aff11a3b/ambari-server/src/main/resources/stacks/HDP/1.3.2/hooks/before-INSTALL/scripts/params.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/stacks/HDP/1.3.2/hooks/before-INSTALL/scripts/params.py
b/ambari-server/src/main/resources/stacks/HDP/1.3.2/hooks/before-INSTALL/scripts/params.py
index 49a01cf..e7a0d47 100644
--- a/ambari-server/src/main/resources/stacks/HDP/1.3.2/hooks/before-INSTALL/scripts/params.py
+++ b/ambari-server/src/main/resources/stacks/HDP/1.3.2/hooks/before-INSTALL/scripts/params.py
@@ -123,4 +123,9 @@ if has_ganglia_server:
   ganglia_server_host = ganglia_server_hosts[0]
 
 hbase_tmp_dir = config['configurations']['hbase-site']['hbase.tmp.dir']
-ignore_groupsusers_create = default("ignore_groupsusers_create", False)
\ No newline at end of file
+ignore_groupsusers_create = default("ignore_groupsusers_create", False)
+
+
+#repo params
+repo_info = config['hostLevelParams']['repo_info']
+service_repo_info = default("/hostLevelParams/service_repo_info",None)
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ambari/blob/aff11a3b/ambari-server/src/main/resources/stacks/HDP/1.3.2/hooks/before-INSTALL/scripts/repo_initialization.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/stacks/HDP/1.3.2/hooks/before-INSTALL/scripts/repo_initialization.py
b/ambari-server/src/main/resources/stacks/HDP/1.3.2/hooks/before-INSTALL/scripts/repo_initialization.py
new file mode 100644
index 0000000..f3943ed
--- /dev/null
+++ b/ambari-server/src/main/resources/stacks/HDP/1.3.2/hooks/before-INSTALL/scripts/repo_initialization.py
@@ -0,0 +1,55 @@
+"""
+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 import *
+import json
+from resource_management.core.system import System
+
+_UBUNTU_REPO_COMPONENTS = ["HDP", "main"]
+
+def _alter_repo(action, repo_string, repo_template):
+  """
+  @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\"}]"
+  """
+  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'],
+               repo_template = repo_template,
+               components = _UBUNTU_REPO_COMPONENTS, # ubuntu specific
+    )
+
+def install_repos():
+  import params
+  template = "repo_suse_rhel.j2" if System.get_instance().os_family in ["suse", "redhat"]
else "repo_debian.j2"
+  _alter_repo("create", params.repo_info, template)
+  if params.service_repo_info:
+    _alter_repo("create", params.service_repo_info, template)

http://git-wip-us.apache.org/repos/asf/ambari/blob/aff11a3b/ambari-server/src/main/resources/stacks/HDP/1.3.2/hooks/before-INSTALL/templates/repo_debian.j2
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/stacks/HDP/1.3.2/hooks/before-INSTALL/templates/repo_debian.j2
b/ambari-server/src/main/resources/stacks/HDP/1.3.2/hooks/before-INSTALL/templates/repo_debian.j2
new file mode 100644
index 0000000..52d4c9a
--- /dev/null
+++ b/ambari-server/src/main/resources/stacks/HDP/1.3.2/hooks/before-INSTALL/templates/repo_debian.j2
@@ -0,0 +1 @@
+{{package_type}} {{base_url}} {{components}}

http://git-wip-us.apache.org/repos/asf/ambari/blob/aff11a3b/ambari-server/src/main/resources/stacks/HDP/1.3.2/hooks/before-INSTALL/templates/repo_suse_rhel.j2
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/stacks/HDP/1.3.2/hooks/before-INSTALL/templates/repo_suse_rhel.j2
b/ambari-server/src/main/resources/stacks/HDP/1.3.2/hooks/before-INSTALL/templates/repo_suse_rhel.j2
new file mode 100644
index 0000000..d486f89
--- /dev/null
+++ b/ambari-server/src/main/resources/stacks/HDP/1.3.2/hooks/before-INSTALL/templates/repo_suse_rhel.j2
@@ -0,0 +1,7 @@
+[{{repo_id}}]
+name={{repo_file_name}}
+{% if mirror_list %}mirrorlist={{mirror_list}}{% else %}baseurl={{base_url}}{% endif %}
+
+path=/
+enabled=1
+gpgcheck=0

http://git-wip-us.apache.org/repos/asf/ambari/blob/aff11a3b/ambari-server/src/main/resources/stacks/HDP/2.0.6/hooks/before-INSTALL/scripts/hook.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/stacks/HDP/2.0.6/hooks/before-INSTALL/scripts/hook.py
b/ambari-server/src/main/resources/stacks/HDP/2.0.6/hooks/before-INSTALL/scripts/hook.py
index bb68560..6904e9d 100644
--- a/ambari-server/src/main/resources/stacks/HDP/2.0.6/hooks/before-INSTALL/scripts/hook.py
+++ b/ambari-server/src/main/resources/stacks/HDP/2.0.6/hooks/before-INSTALL/scripts/hook.py
@@ -20,7 +20,7 @@ limitations under the License.
 import sys
 from resource_management import *
 from shared_initialization import *
-
+from repo_initialization import *
 #TODO this must be "CONFIGURE" hook when CONFIGURE command will be implemented
 class BeforeConfigureHook(Hook):
 
@@ -28,6 +28,7 @@ class BeforeConfigureHook(Hook):
     import params
 
     env.set_params(params)
+    install_repos()
     install_packages()
     setup_java()
     setup_users()

http://git-wip-us.apache.org/repos/asf/ambari/blob/aff11a3b/ambari-server/src/main/resources/stacks/HDP/2.0.6/hooks/before-INSTALL/scripts/params.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/stacks/HDP/2.0.6/hooks/before-INSTALL/scripts/params.py
b/ambari-server/src/main/resources/stacks/HDP/2.0.6/hooks/before-INSTALL/scripts/params.py
index 852a439..f55bc2d 100644
--- a/ambari-server/src/main/resources/stacks/HDP/2.0.6/hooks/before-INSTALL/scripts/params.py
+++ b/ambari-server/src/main/resources/stacks/HDP/2.0.6/hooks/before-INSTALL/scripts/params.py
@@ -101,3 +101,7 @@ jce_policy_zip = default("/hostLevelParams/jce_name", None) # None when
jdk is a
 jce_location = config['hostLevelParams']['jdk_location']
 jdk_location = config['hostLevelParams']['jdk_location']
 ignore_groupsusers_create = default("ignore_groupsusers_create", False)
+
+#repo params
+repo_info = config['hostLevelParams']['repo_info']
+service_repo_info = default("/hostLevelParams/service_repo_info",None)

http://git-wip-us.apache.org/repos/asf/ambari/blob/aff11a3b/ambari-server/src/main/resources/stacks/HDP/2.0.6/hooks/before-INSTALL/scripts/repo_initialization.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/stacks/HDP/2.0.6/hooks/before-INSTALL/scripts/repo_initialization.py
b/ambari-server/src/main/resources/stacks/HDP/2.0.6/hooks/before-INSTALL/scripts/repo_initialization.py
new file mode 100644
index 0000000..d3bdc70
--- /dev/null
+++ b/ambari-server/src/main/resources/stacks/HDP/2.0.6/hooks/before-INSTALL/scripts/repo_initialization.py
@@ -0,0 +1,54 @@
+"""
+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 import *
+import json
+
+_UBUNTU_REPO_COMPONENTS = ["HDP", "main"]
+
+def _alter_repo(action, repo_string, repo_template):
+  """
+  @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\"}]"
+  """
+  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'],
+               repo_template = repo_template,
+               components = _UBUNTU_REPO_COMPONENTS, # ubuntu specific
+    )
+
+def install_repos():
+  import params
+  template = "repo_suse_rhel.j2" if System.get_instance().os_family in ["suse", "redhat"]
else "repo_debian.j2"
+  _alter_repo("create", params.repo_info, template)
+  if params.service_repo_info:
+    _alter_repo("create", params.service_repo_info, template)

http://git-wip-us.apache.org/repos/asf/ambari/blob/aff11a3b/ambari-server/src/main/resources/stacks/HDP/2.0.6/hooks/before-INSTALL/templates/repo_debian.j2
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/stacks/HDP/2.0.6/hooks/before-INSTALL/templates/repo_debian.j2
b/ambari-server/src/main/resources/stacks/HDP/2.0.6/hooks/before-INSTALL/templates/repo_debian.j2
new file mode 100644
index 0000000..52d4c9a
--- /dev/null
+++ b/ambari-server/src/main/resources/stacks/HDP/2.0.6/hooks/before-INSTALL/templates/repo_debian.j2
@@ -0,0 +1 @@
+{{package_type}} {{base_url}} {{components}}

http://git-wip-us.apache.org/repos/asf/ambari/blob/aff11a3b/ambari-server/src/main/resources/stacks/HDP/2.0.6/hooks/before-INSTALL/templates/repo_suse_rhel.j2
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/stacks/HDP/2.0.6/hooks/before-INSTALL/templates/repo_suse_rhel.j2
b/ambari-server/src/main/resources/stacks/HDP/2.0.6/hooks/before-INSTALL/templates/repo_suse_rhel.j2
new file mode 100644
index 0000000..d486f89
--- /dev/null
+++ b/ambari-server/src/main/resources/stacks/HDP/2.0.6/hooks/before-INSTALL/templates/repo_suse_rhel.j2
@@ -0,0 +1,7 @@
+[{{repo_id}}]
+name={{repo_file_name}}
+{% if mirror_list %}mirrorlist={{mirror_list}}{% else %}baseurl={{base_url}}{% endif %}
+
+path=/
+enabled=1
+gpgcheck=0

http://git-wip-us.apache.org/repos/asf/ambari/blob/aff11a3b/ambari-server/src/test/python/stacks/1.3.2/hooks/before-INSTALL/test_before_install.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/python/stacks/1.3.2/hooks/before-INSTALL/test_before_install.py
b/ambari-server/src/test/python/stacks/1.3.2/hooks/before-INSTALL/test_before_install.py
index e7b8678..58084d0 100644
--- a/ambari-server/src/test/python/stacks/1.3.2/hooks/before-INSTALL/test_before_install.py
+++ b/ambari-server/src/test/python/stacks/1.3.2/hooks/before-INSTALL/test_before_install.py
@@ -28,6 +28,14 @@ class TestHookBeforeInstall(RMFTestCase):
                        command="hook",
                        config_file="default.json"
     )
+    self.assertResourceCalled('Repository', 'HDP-1.3.4',
+        action=['create'],
+        base_url='http://public-repo-1.hortonworks.com/HDP/centos6/1.x/updates/1.3.3.0',
+        components=['HDP', 'main'],
+        mirror_list=None,
+        repo_file_name='HDP',
+        repo_template='repo_suse_rhel.j2'
+    )
     self.assertResourceCalled('Execute', 'mkdir -p /tmp/HDP-artifacts/ ; curl -kf --retry
10 http://c6401.ambari.apache.org:8080/resources//jdk-7u45-linux-x64.tar.gz -o /tmp/HDP-artifacts//jdk-7u45-linux-x64.tar.gz',
         not_if = 'test -e /usr/jdk64/jdk1.7.0_45/bin/java',
         path = ['/bin', '/usr/bin/'],

http://git-wip-us.apache.org/repos/asf/ambari/blob/aff11a3b/ambari-server/src/test/python/stacks/2.0.6/configs/default.json
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/python/stacks/2.0.6/configs/default.json b/ambari-server/src/test/python/stacks/2.0.6/configs/default.json
index 8f6d64b..099984f 100644
--- a/ambari-server/src/test/python/stacks/2.0.6/configs/default.json
+++ b/ambari-server/src/test/python/stacks/2.0.6/configs/default.json
@@ -5,7 +5,8 @@
     "hostLevelParams": {
         "jdk_location": "http://c6401.ambari.apache.org:8080/resources/", 
         "ambari_db_rca_password": "mapred", 
-        "ambari_db_rca_url": "jdbc:postgresql://c6401.ambari.apache.org/ambarirca", 
+        "ambari_db_rca_url": "jdbc:postgresql://c6401.ambari.apache.org/ambarirca",
+        "repo_info": "[{\"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\"}]",
         "jce_name": "UnlimitedJCEPolicyJDK7.zip", 
         "stack_version": "2.0",
         "stack_name": "HDP", 

http://git-wip-us.apache.org/repos/asf/ambari/blob/aff11a3b/ambari-server/src/test/python/stacks/2.0.6/hooks/before-INSTALL/test_before_install.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/python/stacks/2.0.6/hooks/before-INSTALL/test_before_install.py
b/ambari-server/src/test/python/stacks/2.0.6/hooks/before-INSTALL/test_before_install.py
index e15ec8b..92eed49 100644
--- a/ambari-server/src/test/python/stacks/2.0.6/hooks/before-INSTALL/test_before_install.py
+++ b/ambari-server/src/test/python/stacks/2.0.6/hooks/before-INSTALL/test_before_install.py
@@ -28,6 +28,14 @@ class TestHookBeforeInstall(RMFTestCase):
                        command="hook",
                        config_file="default.json"
     )
+    self.assertResourceCalled('Repository', 'HDP-2.0._',
+        action=['create'],
+        base_url='http://public-repo-1.hortonworks.com/HDP/centos6/2.x/updates/2.0.6.0',
+        components=['HDP', 'main'],
+        mirror_list=None,
+        repo_file_name='HDP',
+        repo_template='repo_suse_rhel.j2'
+    )
     self.assertResourceCalled('Package', 'unzip',)
     self.assertResourceCalled('Package', 'curl',)
     self.assertResourceCalled('Execute', 'mkdir -p /tmp/HDP-artifacts/ ;   curl -kf   --retry
10 http://c6401.ambari.apache.org:8080/resources//jdk-7u45-linux-x64.tar.gz -o /tmp/HDP-artifacts//jdk-7u45-linux-x64.tar.gz',


Mime
View raw message