def _install_lzo_support_if_needed(self, params):
    hadoop_classpath_prefix = self._expand_hadoop_classpath_prefix(params.hadoop_classpath_prefix_template, params.config['configurations']['tez-site'])

    hadoop_lzo_dest_path = extract_path_component(hadoop_classpath_prefix, "hadoop-lzo-")
    if hadoop_lzo_dest_path:
      hadoop_lzo_file = os.path.split(hadoop_lzo_dest_path)[1]

      config = Script.get_config()
      file_url = urlparse.urljoin(config['hostLevelParams']['jdk_location'], hadoop_lzo_file)
      hadoop_lzo_dl_path = os.path.join(config["hostLevelParams"]["agentCacheDir"], hadoop_lzo_file)
      download_file(file_url, hadoop_lzo_dl_path)
      #This is for protection against configuration changes. It will infect every new destination with the lzo jar,
      # but since the classpath points to the jar directly we're getting away with it.
      if not os.path.exists(hadoop_lzo_dest_path):
        copy_file(hadoop_lzo_dl_path, hadoop_lzo_dest_path)
def ensure_jdbc_driver_is_in_classpath(dest_dir, cache_location, driver_url, driver_files):
  #Attempt to find the JDBC driver installed locally
  #If not, attempt to download it from the server resources URL
  for driver_file in driver_files:
    dest_path = os.path.join(dest_dir, driver_file)
    Logger.info("JDBC driver file(s) {0}: Attempting to copy from {1} or download from {2} to {3}".format(
      str(driver_files), cache_location, driver_url, dest_dir))
    if not os.path.exists(dest_path):
      search_path = os.environ["PATH"]
      if cache_location:
        search_path += os.pathsep + cache_location  #The locally installed version takes precedence over the cache

      local_path = search_file(driver_file, search_path)
      if not local_path:
        download_file(driver_url + "/" + driver_file, dest_path)
      else:
        copy_file(local_path, dest_path)
Beispiel #3
0
def import_cert_and_key(security_server_keys_dir):
  import_cert_path = get_validated_filepath_input( \
      "Enter path to Certificate: ", \
      "Certificate not found")
  import_key_path  =  get_validated_filepath_input( \
      "Enter path to Private Key: ", "Private Key not found")
  pem_password = get_validated_string_input("Please enter password for Private Key: ", "", None, None, True)

  certInfoDict = get_cert_info(import_cert_path)

  if not certInfoDict:
    print_warning_msg('Unable to get Certificate information')
  else:
    #Validate common name of certificate
    if not is_valid_cert_host(certInfoDict):
      print_warning_msg('Unable to validate Certificate hostname')

    #Validate issue and expirations dates of certificate
    if not is_valid_cert_exp(certInfoDict):
      print_warning_msg('Unable to validate Certificate issue and expiration dates')

  #jetty requires private key files with non-empty key passwords
  retcode = 0
  err = ''
  if not pem_password:
    print 'Generating random password for HTTPS keystore...done.'
    pem_password = generate_random_string()
    retcode, out, err = run_os_command(CHANGE_KEY_PWD_CND.format(
        import_key_path, pem_password))
    import_key_path += '.secured'

  if retcode == 0:
    keystoreFilePath = os.path.join(security_server_keys_dir, \
                                    SSL_KEYSTORE_FILE_NAME)
    keystoreFilePathTmp = os.path.join(tempfile.gettempdir(), \
                                       SSL_KEYSTORE_FILE_NAME)
    passFilePath = os.path.join(security_server_keys_dir, \
                                SSL_KEY_PASSWORD_FILE_NAME)
    passFilePathTmp = os.path.join(tempfile.gettempdir(), \
                                   SSL_KEY_PASSWORD_FILE_NAME)
    passinFilePath = os.path.join(tempfile.gettempdir(), \
                                  SSL_PASSIN_FILE)
    passwordFilePath = os.path.join(tempfile.gettempdir(), \
                                    SSL_PASSWORD_FILE)

    with open(passFilePathTmp, 'w+') as passFile:
      passFile.write(pem_password)
      passFile.close
      pass

    set_file_permissions(passFilePath, "660", read_ambari_user(), False)

    copy_file(passFilePathTmp, passinFilePath)
    copy_file(passFilePathTmp, passwordFilePath)

    retcode, out, err = run_os_command(EXPRT_KSTR_CMD.format(import_cert_path, \
                                                             import_key_path, passwordFilePath, passinFilePath, keystoreFilePathTmp))
  if retcode == 0:
    print 'Importing and saving Certificate...done.'
    import_file_to_keystore(keystoreFilePathTmp, keystoreFilePath)
    import_file_to_keystore(passFilePathTmp, passFilePath)

    import_file_to_keystore(import_cert_path, os.path.join( \
        security_server_keys_dir, SSL_CERT_FILE_NAME))
    import_file_to_keystore(import_key_path, os.path.join( \
        security_server_keys_dir, SSL_KEY_FILE_NAME))

    #Validate keystore
    retcode, out, err = run_os_command(VALIDATE_KEYSTORE_CMD.format(keystoreFilePath, \
                                                                    passwordFilePath, passinFilePath))

    remove_file(passinFilePath)
    remove_file(passwordFilePath)

    if not retcode == 0:
      print 'Error during keystore validation occured!:'
      print err
      return False

    return True
  else:
    print_error_msg('Could not import Certificate and Private Key.')
    print 'SSL error on exporting keystore: ' + err.rstrip() + \
        '.\nPlease ensure that provided Private Key password is correct and ' + \
        're-import Certificate.'

    return False
Beispiel #4
0
def import_cert_and_key(security_server_keys_dir):
  import_cert_path = get_validated_filepath_input( \
      "Enter path to Certificate: ", \
      "Certificate not found")
  import_key_path  =  get_validated_filepath_input( \
      "Enter path to Private Key: ", "Private Key not found")
  pem_password = get_validated_string_input("Please enter password for Private Key: ", "", None, None, True)

  certInfoDict = get_cert_info(import_cert_path)

  if not certInfoDict:
    print_warning_msg('Unable to get Certificate information')
  else:
    #Validate common name of certificate
    if not is_valid_cert_host(certInfoDict):
      print_warning_msg('Unable to validate Certificate hostname')

    #Validate issue and expirations dates of certificate
    if not is_valid_cert_exp(certInfoDict):
      print_warning_msg('Unable to validate Certificate issue and expiration dates')

  #jetty requires private key files with non-empty key passwords
  retcode = 0
  err = ''
  if not pem_password:
    print 'Generating random password for HTTPS keystore...done.'
    pem_password = generate_random_string()
    retcode, out, err = run_os_command(CHANGE_KEY_PWD_CND.format(
        import_key_path, pem_password))
    import_key_path += '.secured'

  if retcode == 0:
    keystoreFilePath = os.path.join(security_server_keys_dir, \
                                    SSL_KEYSTORE_FILE_NAME)
    keystoreFilePathTmp = os.path.join(tempfile.gettempdir(), \
                                       SSL_KEYSTORE_FILE_NAME)
    passFilePath = os.path.join(security_server_keys_dir, \
                                SSL_KEY_PASSWORD_FILE_NAME)
    passFilePathTmp = os.path.join(tempfile.gettempdir(), \
                                   SSL_KEY_PASSWORD_FILE_NAME)
    passinFilePath = os.path.join(tempfile.gettempdir(), \
                                  SSL_PASSIN_FILE)
    passwordFilePath = os.path.join(tempfile.gettempdir(), \
                                    SSL_PASSWORD_FILE)

    with open(passFilePathTmp, 'w+') as passFile:
      passFile.write(pem_password)
      passFile.close
      pass

    set_file_permissions(passFilePath, "660", read_ambari_user(), False)

    copy_file(passFilePathTmp, passinFilePath)
    copy_file(passFilePathTmp, passwordFilePath)

    retcode, out, err = run_os_command(EXPRT_KSTR_CMD.format(import_cert_path, \
                                                             import_key_path, passwordFilePath, passinFilePath, keystoreFilePathTmp))
  if retcode == 0:
    print 'Importing and saving Certificate...done.'
    import_file_to_keystore(keystoreFilePathTmp, keystoreFilePath)
    import_file_to_keystore(passFilePathTmp, passFilePath)

    import_file_to_keystore(import_cert_path, os.path.join( \
        security_server_keys_dir, SSL_CERT_FILE_NAME))
    import_file_to_keystore(import_key_path, os.path.join( \
        security_server_keys_dir, SSL_KEY_FILE_NAME))

    #Validate keystore
    retcode, out, err = run_os_command(VALIDATE_KEYSTORE_CMD.format(keystoreFilePath, \
                                                                    passwordFilePath, passinFilePath))

    remove_file(passinFilePath)
    remove_file(passwordFilePath)

    if not retcode == 0:
      print 'Error during keystore validation occured!:'
      print err
      return False

    return True
  else:
    print_error_msg('Could not import Certificate and Private Key.')
    print 'SSL error on exporting keystore: ' + err.rstrip() + \
        '.\nPlease ensure that provided Private Key password is correct and ' + \
        're-import Certificate.'

    return False