Пример #1
0
def _prepare_mapreduce_tarball():
    """
  Prepares the mapreduce tarball by including the native LZO libraries if necessary. If LZO is
  not enabled or has not been opted-in, then this will do nothing and return the original
  tarball to upload to HDFS.
  :return:  the full path of the newly created mapreduce tarball to use or the original path
  if no changes were made
  """
    # get the mapreduce tarball to crack open and add LZO libraries to
    _, mapreduce_source_file, _, _ = get_tarball_paths("mapreduce")

    if not lzo_utils.should_install_lzo():
        return mapreduce_source_file

    Logger.info("Preparing the mapreduce tarball with native LZO libraries...")

    temp_dir = Script.get_tmp_dir()

    # create the temp staging directories ensuring that non-root agents using tarfile can work with them
    mapreduce_temp_dir = tempfile.mkdtemp(prefix="mapreduce-tarball-",
                                          dir=temp_dir)
    sudo.chmod(mapreduce_temp_dir, 0777)

    # calculate the source directory for LZO
    hadoop_lib_native_source_dir = os.path.join(
        os.path.dirname(mapreduce_source_file), "lib", "native")
    if not sudo.path_exists(hadoop_lib_native_source_dir):
        raise Fail(
            "Unable to seed the mapreduce tarball with native LZO libraries since the source Hadoop native lib directory {0} does not exist"
            .format(hadoop_lib_native_source_dir))

    Logger.info("Extracting {0} to {1}".format(mapreduce_source_file,
                                               mapreduce_temp_dir))
    tar_archive.extract_archive(mapreduce_source_file, mapreduce_temp_dir)

    mapreduce_lib_dir = os.path.join(mapreduce_temp_dir, "hadoop", "lib")

    # copy native libraries from source hadoop to target
    Execute(("cp", "-af", hadoop_lib_native_source_dir, mapreduce_lib_dir),
            sudo=True)

    # ensure that the hadoop/lib/native directory is readable by non-root (which it typically is not)
    Directory(mapreduce_lib_dir,
              mode=0755,
              cd_access='a',
              recursive_ownership=True)

    # create the staging directory so that non-root agents can write to it
    mapreduce_native_tarball_staging_dir = os.path.join(
        temp_dir, "mapreduce-native-tarball-staging")
    if not os.path.exists(mapreduce_native_tarball_staging_dir):
        Directory(mapreduce_native_tarball_staging_dir,
                  mode=0777,
                  cd_access='a',
                  create_parents=True,
                  recursive_ownership=True)

    mapreduce_tarball_with_native_lib = os.path.join(
        mapreduce_native_tarball_staging_dir, "mapreduce-native.tar.gz")
    Logger.info("Creating a new mapreduce tarball at {0}".format(
        mapreduce_tarball_with_native_lib))

    # tar up mapreduce, making sure to specify nothing for the arcname so that it does not include an absolute path
    with closing(tarfile.open(mapreduce_tarball_with_native_lib,
                              "w:gz")) as new_tarball:
        new_tarball.add(mapreduce_temp_dir, arcname=os.path.sep)

    # ensure that the tarball can be read and uploaded
    sudo.chmod(mapreduce_tarball_with_native_lib, 0744)

    # cleanup
    sudo.rmtree(mapreduce_temp_dir)

    return mapreduce_tarball_with_native_lib
Пример #2
0
def _prepare_tez_tarball():
    """
  Prepares the Tez tarball by adding the Hadoop native libraries found in the mapreduce tarball.
  It's very important to use the version of mapreduce which matches tez here.
  Additionally, this will also copy native LZO to the tez tarball if LZO is enabled and the
  GPL license has been accepted.
  :return:  the full path of the newly created tez tarball to use
  """
    import tempfile

    Logger.info("Preparing the Tez tarball...")

    # get the mapreduce tarball which matches the version of tez
    # tez installs the mapreduce tar, so it should always be present
    _, mapreduce_source_file, _, _ = get_tarball_paths("mapreduce")
    _, tez_source_file, _, _ = get_tarball_paths("tez")

    temp_dir = Script.get_tmp_dir()

    # create the temp staging directories ensuring that non-root agents using tarfile can work with them
    mapreduce_temp_dir = tempfile.mkdtemp(prefix="mapreduce-tarball-",
                                          dir=temp_dir)
    tez_temp_dir = tempfile.mkdtemp(prefix="tez-tarball-", dir=temp_dir)
    sudo.chmod(mapreduce_temp_dir, 0777)
    sudo.chmod(tez_temp_dir, 0777)

    Logger.info("Extracting {0} to {1}".format(mapreduce_source_file,
                                               mapreduce_temp_dir))
    tar_archive.extract_archive(mapreduce_source_file, mapreduce_temp_dir)

    Logger.info("Extracting {0} to {1}".format(tez_source_file, tez_temp_dir))
    tar_archive.untar_archive(tez_source_file, tez_temp_dir)

    hadoop_lib_native_dir = os.path.join(mapreduce_temp_dir, "hadoop", "lib",
                                         "native")
    tez_lib_dir = os.path.join(tez_temp_dir, "lib")

    if not os.path.exists(hadoop_lib_native_dir):
        raise Fail(
            "Unable to seed the Tez tarball with native libraries since the source Hadoop native lib directory {0} does not exist"
            .format(hadoop_lib_native_dir))

    if not os.path.exists(tez_lib_dir):
        raise Fail(
            "Unable to seed the Tez tarball with native libraries since the target Tez lib directory {0} does not exist"
            .format(tez_lib_dir))

    # copy native libraries from hadoop to tez
    Execute(("cp", "-a", hadoop_lib_native_dir, tez_lib_dir), sudo=True)

    # if enabled, LZO GPL libraries must be copied as well
    if lzo_utils.should_install_lzo():
        stack_root = Script.get_stack_root()
        service_version = component_version.get_component_repository_version(
            service_name="TEZ")

        # some installations might not have Tez, but MapReduce2 should be a fallback to get the LZO libraries from
        if service_version is None:
            Logger.warning(
                "Tez does not appear to be installed, using the MapReduce version to get the LZO libraries"
            )
            service_version = component_version.get_component_repository_version(
                service_name="MAPREDUCE2")

        hadoop_lib_native_lzo_dir = os.path.join(stack_root, service_version,
                                                 "hadoop", "lib", "native")

        if not sudo.path_isdir(hadoop_lib_native_lzo_dir):
            Logger.warning(
                "Unable to located native LZO libraries at {0}, falling back to hadoop home"
                .format(hadoop_lib_native_lzo_dir))
            hadoop_lib_native_lzo_dir = os.path.join(stack_root, "current",
                                                     "hadoop-client", "lib",
                                                     "native")

        if not sudo.path_isdir(hadoop_lib_native_lzo_dir):
            raise Fail(
                "Unable to seed the Tez tarball with native libraries since LZO is enabled but the native LZO libraries could not be found at {0}"
                .format(hadoop_lib_native_lzo_dir))

        Execute(("cp", "-a", hadoop_lib_native_lzo_dir, tez_lib_dir),
                sudo=True)

    # ensure that the tez/lib directory is readable by non-root (which it typically is not)
    Directory(tez_lib_dir, mode=0755, cd_access='a', recursive_ownership=True)

    # create the staging directory so that non-root agents can write to it
    tez_native_tarball_staging_dir = os.path.join(
        temp_dir, "tez-native-tarball-staging")
    if not os.path.exists(tez_native_tarball_staging_dir):
        Directory(tez_native_tarball_staging_dir,
                  mode=0777,
                  cd_access='a',
                  create_parents=True,
                  recursive_ownership=True)

    tez_tarball_with_native_lib = os.path.join(tez_native_tarball_staging_dir,
                                               "tez-native.tar.gz")
    Logger.info("Creating a new Tez tarball at {0}".format(
        tez_tarball_with_native_lib))

    # tar up Tez, making sure to specify nothing for the arcname so that it does not include an absolute path
    with closing(tarfile.open(tez_tarball_with_native_lib,
                              "w:gz")) as new_tez_tarball:
        new_tez_tarball.add(tez_temp_dir, arcname=os.path.sep)

    # ensure that the tarball can be read and uploaded
    sudo.chmod(tez_tarball_with_native_lib, 0744)

    # cleanup
    sudo.rmtree(mapreduce_temp_dir)
    sudo.rmtree(tez_temp_dir)

    return tez_tarball_with_native_lib
Пример #3
0
ams_collector_hosts = default("/clusterHostInfo/metrics_collector_hosts", [])
has_metric_collector = not len(ams_collector_hosts) == 0

if has_metric_collector:
    metric_emitter_type = "ambari-metrics"
    if 'cluster-env' in config['configurations'] and \
                    'metrics_collector_vip_host' in config['configurations']['cluster-env']:
        metric_collector_host = config['configurations']['cluster-env']['metrics_collector_vip_host']
    else:
        metric_collector_host = ams_collector_hosts[0]
    if 'cluster-env' in config['configurations'] and \
                    'metrics_collector_vip_port' in config['configurations']['cluster-env']:
        metric_collector_port = config['configurations']['cluster-env']['metrics_collector_vip_port']
    else:
        metric_collector_web_address = default("/configurations/ams-site/timeline.metrics.service.webapp.address", "localhost:6188")
        if metric_collector_web_address.find(':') != -1:
            metric_collector_port = metric_collector_web_address.split(':')[1]
        else:
            metric_collector_port = '6188'
    if default("/configurations/ams-site/timeline.metrics.service.http.policy", "HTTP_ONLY") == "HTTPS_ONLY":
        metric_collector_protocol = 'https'
    else:
        metric_collector_protocol = 'http'
    pass

# Create current Hadoop Clients  Libs
stack_version_unformatted = str(config['clusterLevelParams']['stack_version'])
io_compression_codecs = default("/configurations/core-site/io.compression.codecs", None)
lzo_enabled = should_install_lzo()
hadoop_lib_home = stack_root + '/' + stack_version + '/hadoop/lib'