예제 #1
0
    def actionexecute(self, env):
        resolve_ambari_config()

        # Parse parameters from command json file.
        config = Script.get_config()

        host_name = socket.gethostname()
        version = default('/roleParams/version', None)

        # These 2 variables are optional
        service_package_folder = default('/roleParams/service_package_folder',
                                         None)
        hooks_folder = default('/roleParams/hooks_folder', None)

        tasks = json.loads(config['roleParams']['tasks'])
        if tasks:
            for t in tasks:
                task = ExecuteTask(t)
                Logger.info(str(task))

                # If a (script, function) exists, it overwrites the command.
                if task.script and task.function and service_package_folder and hooks_folder:
                    file_cache = FileCache(agent_config)
                    command_paths = {
                        "commandParams": {
                            "service_package_folder": service_package_folder,
                            "hooks_folder": hooks_folder
                        }
                    }
                    server_url_prefix = default(
                        '/hostLevelParams/jdk_location', "")
                    base_dir = file_cache.get_service_base_dir(
                        command_paths, server_url_prefix)
                    script_path = os.path.join(base_dir, task.script)
                    if not os.path.exists(script_path):
                        message = "Script %s does not exist" % str(script_path)
                        raise Fail(message)

                    # Notice that the script_path is now the fully qualified path, and the
                    # same command-#.json file is used.
                    # Also, the python wrapper is used, since it sets up the correct environment variables
                    command_params = [
                        "/usr/bin/ambari-python-wrap", script_path,
                        task.function, self.command_data_file, self.basedir,
                        self.stroutfile, self.logging_level,
                        Script.get_tmp_dir()
                    ]

                    task.command = " ".join(command_params)
                    # Replace redundant whitespace to make the unit tests easier to validate
                    task.command = re.sub("\s+", " ", task.command).strip()

                if task.command:
                    task.command = replace_variables(task.command, host_name,
                                                     version)
                    code, out = shell.call(task.command)
                    Logger.info("Command: %s\nCode: %s, Out: %s" %
                                (task.command, str(code), str(out)))
                    if code != 0:
                        raise Fail(out)
예제 #2
0
  def actionexecute(self, env):
    resolve_ambari_config()

    # Parse parameters from command json file.
    config = Script.get_config()

    host_name = socket.gethostname()
    version = default('/roleParams/version', None)

    # These 2 variables are optional
    service_package_folder = default('/roleParams/service_package_folder', None)
    hooks_folder = default('/roleParams/hooks_folder', None)

    tasks = json.loads(config['roleParams']['tasks'])
    if tasks:
      for t in tasks:
        task = ExecuteTask(t)
        Logger.info(str(task))

        # If a (script, function) exists, it overwrites the command.
        if task.script and task.function and service_package_folder and hooks_folder:
          file_cache = FileCache(agent_config)
          command_paths = {"commandParams":
                                 {"service_package_folder": service_package_folder,
                                  "hooks_folder": hooks_folder
                                 }
                              }
          server_url_prefix = default('/hostLevelParams/jdk_location', "")
          base_dir = file_cache.get_service_base_dir(command_paths, server_url_prefix)
          script_path = os.path.join(base_dir, task.script)
          if not os.path.exists(script_path):
            message = "Script %s does not exist" % str(script_path)
            raise Fail(message)

          # Notice that the script_path is now the fully qualified path, and the
          # same command-#.json file is used.
          # Also, the python wrapper is used, since it sets up the correct environment variables
          command_params = ["/usr/bin/ambari-python-wrap",
                            script_path,
                            task.function,
                            self.command_data_file,
                            self.basedir,
                            self.stroutfile,
                            self.logging_level,
                            Script.get_tmp_dir()]

          task.command = " ".join(command_params)
          # Replace redundant whitespace to make the unit tests easier to validate
          task.command = re.sub("\s+", " ", task.command).strip()

        if task.command:
          task.command = replace_variables(task.command, host_name, version)
          code, out = shell.call(task.command)
          Logger.info("Command: %s\nCode: %s, Out: %s" % (task.command, str(code), str(out)))
          if code != 0:
            raise Fail(out)
예제 #3
0
 def test_get_service_base_dir(self, provide_directory_mock):
   provide_directory_mock.return_value = "dummy value"
   fileCache = FileCache(self.config)
   command = {
     'commandParams' : {
       'service_package_folder' : os.path.join('stacks', 'HDP', '2.1.1', 'services', 'ZOOKEEPER', 'package')
     }
   }
   res = fileCache.get_service_base_dir(command, "server_url_pref")
   self.assertEquals(
     pprint.pformat(provide_directory_mock.call_args_list[0][0]),
     "('/var/lib/ambari-agent/cache',\n "
     "{0},\n"
     " 'server_url_pref')".format(pprint.pformat(os.path.join('stacks', 'HDP', '2.1.1', 'services', 'ZOOKEEPER', 'package'))))
   self.assertEquals(res, "dummy value")
예제 #4
0
 def test_get_service_base_dir(self, provide_directory_mock):
   provide_directory_mock.return_value = "dummy value"
   fileCache = FileCache(self.config)
   command = {
     'serviceLevelParams' : {
       'service_package_folder' : os.path.join('stacks', 'HDP', '2.1.1', 'services', 'ZOOKEEPER', 'package')
     }
   }
   res = fileCache.get_service_base_dir(command, "server_url_pref")
   self.assertEquals(
     pprint.pformat(provide_directory_mock.call_args_list[0][0]),
     "('/var/lib/ambari-agent/cache',\n "
     "{0},\n"
     " 'server_url_pref')".format(pprint.pformat(os.path.join('stacks', 'HDP', '2.1.1', 'services', 'ZOOKEEPER', 'package'))))
   self.assertEquals(res, "dummy value")
예제 #5
0
    def actionexecute(self, env):
        resolve_ambari_config()

        # Parse parameters from command json file.
        config = Script.get_config()

        host_name = socket.gethostname()
        version = default('/roleParams/version', None)

        # These 2 variables are optional
        service_package_folder = default(
            '/commandParams/service_package_folder', None)
        if service_package_folder is None:
            service_package_folder = default(
                '/serviceLevelParams/service_package_folder', None)
        hooks_folder = default('/commandParams/hooks_folder', None)

        tasks = json.loads(config['roleParams']['tasks'])
        if tasks:
            for t in tasks:
                task = ExecuteTask(t)
                Logger.info(str(task))

                # If a (script, function) exists, it overwrites the command.
                if task.script and task.function:
                    file_cache = FileCache(agent_config)

                    if service_package_folder and hooks_folder:
                        command_paths = {
                            "commandParams": {
                                "service_package_folder":
                                service_package_folder,
                            },
                            "clusterLevelParams": {
                                "hooks_folder": hooks_folder
                            },
                            "ambariLevelParams": {
                                "jdk_location":
                                default('/ambariLevelParams/jdk_location', "")
                            }
                        }

                        base_dir = file_cache.get_service_base_dir(
                            command_paths)
                    else:
                        base_dir = file_cache.get_custom_actions_base_dir({
                            "ambariLevelParams": {
                                "jdk_location":
                                default('/ambariLevelParams/jdk_location', "")
                            }
                        })

                    script_path = os.path.join(base_dir, task.script)
                    if not os.path.exists(script_path):
                        message = "Script %s does not exist" % str(script_path)
                        raise Fail(message)

                    # Notice that the script_path is now the fully qualified path, and the
                    # same command-#.json file is used.
                    # Also, the python wrapper is used, since it sets up the correct environment variables
                    command_params = [
                        "/usr/bin/ambari-python-wrap", script_path,
                        task.function, self.command_data_file, self.basedir,
                        self.stroutfile, self.logging_level,
                        Script.get_tmp_dir()
                    ]

                    task.command = "source /var/lib/ambari-agent/ambari-env.sh ; " + " ".join(
                        command_params)
                    # Replace redundant whitespace to make the unit tests easier to validate
                    task.command = re.sub("\s+", " ", task.command).strip()

                if task.command:
                    task.command = replace_variables(task.command, host_name,
                                                     version)
                    shell.checked_call(task.command,
                                       logoutput=True,
                                       quiet=True)