Exemple #1
0
      elif "server.os_type" == prop_key:
        new_properties.process_pair(OS_TYPE_PROPERTY, OS_FAMILY + OS_VERSION)
      else:
        new_properties.process_pair(prop_key, prop_value)

    # Adding custom user name property if it is absent
    # In previous versions without custom user support server was started as
    # "root" anyway so it's a reasonable default
    if NR_USER_PROPERTY not in new_properties.keys():
      new_properties.process_pair(NR_USER_PROPERTY, "root")

    if OS_FAMILY_PROPERTY not in new_properties.keys():
      new_properties.process_pair(OS_FAMILY_PROPERTY, OS_FAMILY + OS_VERSION)

    with open(conf_file, 'w') as hfW:
      new_properties.store(hfW)

  except Exception, e:
    print 'Could not write "%s": %s' % (conf_file, e)
    return -1

  timestamp = datetime.datetime.now()
  fmt = '%Y%m%d%H%M%S'
  new_conf_file = prev_conf_file + '.' + timestamp.strftime(fmt)
  try:
    os.rename(prev_conf_file, new_conf_file)
  except Exception, e:
    print 'Could not rename "%s" to "%s": %s' % (prev_conf_file, new_conf_file, e)
    #Not critical, move on

  return 0
      elif "server.os_type" == prop_key:
        new_properties.process_pair(OS_TYPE_PROPERTY, OS_FAMILY + OS_VERSION)
      else:
        new_properties.process_pair(prop_key, prop_value)

    # Adding custom user name property if it is absent
    # In previous versions without custom user support server was started as
    # "root" anyway so it's a reasonable default
    if NR_USER_PROPERTY not in new_properties.keys():
      new_properties.process_pair(NR_USER_PROPERTY, "root")

    if OS_FAMILY_PROPERTY not in new_properties.keys():
      new_properties.process_pair(OS_FAMILY_PROPERTY, OS_FAMILY + OS_VERSION)

    with open(conf_file, 'w') as hfW:
      new_properties.store(hfW)

  except Exception, e:
    print 'Could not write "%s": %s' % (conf_file, e)
    return -1

  timestamp = datetime.datetime.now()
  fmt = '%Y%m%d%H%M%S'
  new_conf_file = prev_conf_file + '.' + timestamp.strftime(fmt)
  try:
    os.rename(prev_conf_file, new_conf_file)
  except Exception, e:
    print 'Could not rename "%s" to "%s": %s' % (prev_conf_file, new_conf_file, e)
    #Not critical, move on

  return 0
                new_properties.process_pair(OS_TYPE_PROPERTY,
                                            OS_FAMILY + OS_VERSION)
            else:
                new_properties.process_pair(prop_key, prop_value)

        # Adding custom user name property if it is absent
        # In previous versions without custom user support server was started as
        # "root" anyway so it's a reasonable default
        if NR_USER_PROPERTY not in new_properties.keys():
            new_properties.process_pair(NR_USER_PROPERTY, "root")

        if OS_FAMILY_PROPERTY not in new_properties.keys():
            new_properties.process_pair(OS_FAMILY_PROPERTY,
                                        OS_FAMILY + OS_VERSION)

        new_properties.store(open(conf_file, 'w'))

    except Exception, e:
        print 'Could not write "%s": %s' % (conf_file, e)
        return -1

    timestamp = datetime.datetime.now()
    fmt = '%Y%m%d%H%M%S'
    os.rename(prev_conf_file, prev_conf_file + '.' + timestamp.strftime(fmt))

    return 0


# update properties in a section-less properties file
# Cannot use ConfigParser due to bugs in version 2.6
def update_properties(propertyMap):
    # In previous versions without custom user support server was started as
    # "root" anyway so it's a reasonable default
    if not NR_USER_PROPERTY in new_properties.keys():
      new_properties.process_pair(NR_USER_PROPERTY, "root")

    isJDK16Installed = new_properties.get_property(JAVA_HOME_PROPERTY) == DEFAULT_JDK16_LOCATION
    if not JDK_NAME_PROPERTY in new_properties.keys() and isJDK16Installed:
      new_properties.process_pair(JDK_NAME_PROPERTY, JDK_NAMES[1])

    if not JCE_NAME_PROPERTY in new_properties.keys() and isJDK16Installed:
      new_properties.process_pair(JCE_NAME_PROPERTY, JCE_POLICY_FILENAMES[1])

    if not OS_FAMILY_PROPERTY in new_properties.keys():
      new_properties.process_pair(OS_FAMILY_PROPERTY, OS_FAMILY + OS_VERSION)

    new_properties.store(open(conf_file, 'w'))

  except Exception, e:
    print 'Could not write "%s": %s' % (conf_file, e)
    return -1

  timestamp = datetime.datetime.now()
  format = '%Y%m%d%H%M%S'
  os.rename(prev_conf_file, prev_conf_file + '.' + timestamp.strftime(format))

  return 0

# update properties in a section-less properties file
# Cannot use ConfigParser due to bugs in version 2.6
def update_properties(propertyMap):
  conf_file = search_file(AMBARI_PROPERTIES_FILE, get_conf_dir())