def _is_jdbc_driver_installed(self, properties): """ #Attempt to find the sqljdbc4.jar and sqljdbc_auth.dll by scanning the PATH. :param None :rtype : bool """ paths = "." + os.pathsep + os.environ["PATH"] # Find the jar by attempting to load it as a resource dll driver_path = search_file("sqljdbc4.jar", paths) if not driver_path: return 0 auth_dll_path = search_file("sqljdbc_auth.dll", paths) if not auth_dll_path: return 0 try: driver_path = properties[JDBC_DRIVER_PATH_PROPERTY] if driver_path is None or driver_path is "": return 0 except Exception: # No such attribute set return 0 return 1
def update_krb_jaas_login_properties(): """ Update configuration files :return: int -2 - skipped, -1 - error, 0 - successful """ prev_conf_file = search_file(configDefaults.AMBARI_KRB_JAAS_LOGIN_BACKUP_FILE, get_conf_dir()) conf_file = search_file(AMBARI_KRB_JAAS_LOGIN_FILE, get_conf_dir()) # check if source and target files exists, if not - skip copy action if prev_conf_file is None or conf_file is None: return -2 # if rpmsave file contains invalid keytab, we can skip restoring if not is_jaas_keytab_exists(prev_conf_file): return -2 try: # restore original file, destination arg for rename func shouldn't exists os.remove(conf_file) os.rename(prev_conf_file, conf_file) print_warning_msg("Original file %s kept" % AMBARI_KRB_JAAS_LOGIN_FILE) except OSError as e: print "Couldn't move %s file: %s" % (prev_conf_file, e) return -1 return 0
def update_ambari_properties(): prev_conf_file = search_file(configDefaults.AMBARI_PROPERTIES_BACKUP_FILE, get_conf_dir()) conf_file = search_file(AMBARI_PROPERTIES_FILE, get_conf_dir()) # Previous config file does not exist if (not prev_conf_file) or (prev_conf_file is None): print_warning_msg("Can not find tbds.properties.backup file from previous version, skipping import of settings") return 0 try: old_properties = Properties() old_properties.load(open(prev_conf_file)) except Exception, e: print 'Could not read "%s": %s' % (prev_conf_file, e) return -1
def update_ambari_properties(): prev_conf_file = search_file(configDefaults.AMBARI_PROPERTIES_BACKUP_FILE, get_conf_dir()) conf_file = search_file(AMBARI_PROPERTIES_FILE, get_conf_dir()) # Previous config file does not exist if (not prev_conf_file) or (prev_conf_file is None): print_warning_msg("Can not find ambari.properties.backup file from previous version, skipping import of settings") return 0 try: old_properties = Properties() old_properties.load(open(prev_conf_file)) except Exception, e: print 'Could not read "%s": %s' % (prev_conf_file, e) return -1
def setup_ambari_krb5_jaas(): jaas_conf_file = search_file(SECURITY_KERBEROS_JASS_FILENAME, get_conf_dir()) if os.path.exists(jaas_conf_file): print 'Setting up Ambari kerberos JAAS configuration to access ' + \ 'secured Hadoop daemons...' principal = get_validated_string_input( 'Enter ambari server\'s kerberos ' 'principal name ([email protected]): ', '*****@*****.**', '.*', '', False, False) keytab = get_validated_string_input( 'Enter keytab path for ambari ' 'server\'s kerberos principal: ', '/etc/security/keytabs/ambari.keytab', '.*', False, False, validatorFunction=is_valid_filepath) for line in fileinput.FileInput(jaas_conf_file, inplace=1): line = re.sub('keyTab=.*$', 'keyTab="' + keytab + '"', line) line = re.sub('principal=.*$', 'principal="' + principal + '"', line) print line, else: raise NonFatalException('No jaas config file found at location: ' + jaas_conf_file)
def find_properties_file(): conf_file = search_file(AMBARI_PROPERTIES_FILE, get_conf_dir()) if conf_file is None: err = 'File %s not found in search path $%s: %s' % (AMBARI_PROPERTIES_FILE, AMBARI_CONF_VAR, get_conf_dir()) print err raise FatalException(1, err) else: print_info_msg('Loading properties from ' + conf_file) return conf_file
def find_properties_file(): conf_file = search_file(AMS_PROPERTIES_FILE, get_conf_dir()) if conf_file is None: err = 'File %s not found in search path $%s: %s' % (AMS_PROPERTIES_FILE, AMS_CONF_VAR, get_conf_dir()) print err raise FatalException(1, err) else: print_info_msg('Loading properties from ' + conf_file) return conf_file
def update_ambari_env(): prev_env_file = search_file(configDefaults.AMBARI_ENV_BACKUP_FILE, configDefaults.DEFAULT_VLIBS_DIR) env_file = search_file(AMBARI_ENV_FILE, configDefaults.DEFAULT_VLIBS_DIR) # Previous env file does not exist if (not prev_env_file) or (prev_env_file is None): print_warning_msg("Can not find %s file from previous version, skipping restore of environment settings" % configDefaults.AMBARI_ENV_BACKUP_FILE) return 0 try: if env_file is not None: os.remove(env_file) os.rename(prev_env_file, env_file) print_warning_msg("Original file %s kept" % AMBARI_ENV_FILE) except OSError as e: print "Couldn't move %s file: %s" % (prev_env_file, e) return -1 return 0
def update_ambari_properties(): prev_conf_file = search_file(configDefaults.AMBARI_PROPERTIES_BACKUP_FILE, get_conf_dir()) conf_file = search_file(AMBARI_PROPERTIES_FILE, get_conf_dir()) # Previous config file does not exist if (not prev_conf_file) or (prev_conf_file is None): print_warning_msg("Can not find %s file from previous version, skipping import of settings" % configDefaults.AMBARI_PROPERTIES_BACKUP_FILE) return 0 # ambari.properties file does not exists if conf_file is None: print_error_msg("Can't find %s file" % AMBARI_PROPERTIES_FILE) return -1 with open(prev_conf_file) as hfOld: try: old_properties = Properties() old_properties.load(hfOld) except Exception, e: print 'Could not read "%s": %s' % (prev_conf_file, e) return -1
def update_properties_2(properties, propertyMap): conf_file = search_file(AMBARI_PROPERTIES_FILE, get_conf_dir()) backup_file_in_temp(conf_file) if conf_file is not None: if propertyMap is not None: for key in propertyMap.keys(): properties.removeOldProp(key) properties.process_pair(key, str(propertyMap[key])) pass with open(conf_file, 'w') as file: properties.store_ordered(file) pass pass
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)
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)
def setup_ambari_krb5_jaas(): jaas_conf_file = search_file(SECURITY_KERBEROS_JASS_FILENAME, get_conf_dir()) if os.path.exists(jaas_conf_file): print 'Setting up Ambari kerberos JAAS configuration to access ' + \ 'secured Hadoop daemons...' principal = get_validated_string_input('Enter ambari server\'s kerberos ' 'principal name ([email protected]): ', '*****@*****.**', '.*', '', False, False) keytab = get_validated_string_input('Enter keytab path for ambari ' 'server\'s kerberos principal: ', '/etc/security/keytabs/ambari.keytab', '.*', False, False, validatorFunction=is_valid_filepath) for line in fileinput.FileInput(jaas_conf_file, inplace=1): line = re.sub('keyTab=.*$', 'keyTab="' + keytab + '"', line) line = re.sub('principal=.*$', 'principal="' + principal + '"', line) print line, else: raise NonFatalException('No jaas config file found at location: ' + jaas_conf_file)
def update_properties(propertyMap): conf_file = search_file(AMBARI_PROPERTIES_FILE, get_conf_dir()) backup_file_in_temp(conf_file) if propertyMap is not None and conf_file is not None: properties = Properties() try: with open(conf_file, 'r') as file: properties.load(file) except (Exception), e: print_error_msg('Could not read "%s": %s' % (conf_file, e)) return -1 for key in propertyMap.keys(): properties.removeOldProp(key) properties.process_pair(key, str(propertyMap[key])) for key in properties.keys(): if not propertyMap.has_key(key): properties.removeOldProp(key) with open(conf_file, 'w') as file: properties.store_ordered(file)
def get_is_persisted(properties): keyLocation = get_master_key_location(properties) masterKeyFile = search_file(SECURITY_MASTER_KEY_FILENAME, keyLocation) isPersisted = True if masterKeyFile else False return (isPersisted, masterKeyFile)
while os.path.exists(bootstrap_dir) and del_attempts < 100: time.sleep(50) del_attempts += 1 if not os.path.exists(bootstrap_dir): try: os.makedirs(bootstrap_dir) except Exception, ex: print_warning_msg("Failed recreating the bootstrap directory: {0}".format(str(ex))) pass else: print_warning_msg("Bootstrap directory lingering around after 5s. Unable to complete the cleanup.") pass # Add master key and credential store if exists keyLocation = get_master_key_location(properties) masterKeyFile = search_file(SECURITY_MASTER_KEY_FILENAME, keyLocation) if masterKeyFile: configDefaults.NR_ADJUST_OWNERSHIP_LIST.append((masterKeyFile, configDefaults.MASTER_KEY_FILE_PERMISSIONS, "{0}", False)) credStoreFile = get_credential_store_location(properties) if os.path.exists(credStoreFile): configDefaults.NR_ADJUST_OWNERSHIP_LIST.append((credStoreFile, configDefaults.CREDENTIALS_STORE_FILE_PERMISSIONS, "{0}", False)) trust_store_location = properties[SSL_TRUSTSTORE_PATH_PROPERTY] if trust_store_location: configDefaults.NR_ADJUST_OWNERSHIP_LIST.append((trust_store_location, configDefaults.TRUST_STORE_LOCATION_PERMISSIONS, "{0}", False)) # Update JDK and JCE permissions resources_dir = get_resources_location(properties) jdk_file_name = properties.get_property(JDK_NAME_PROPERTY) jce_file_name = properties.get_property(JCE_NAME_PROPERTY) java_home = properties.get_property(JAVA_HOME_PROPERTY) if jdk_file_name:
def _get_jdbc_driver_path(self): paths = "." + os.pathsep + os.environ["PATH"] # Find the jar in the PATH driver_path = search_file("sqljdbc4.jar", paths) return driver_path