Example #1
0
def write_chronos_cluster_settings(filename, cluster_view, current_server):
    current_or_joining = [constants.JOINING_ACKNOWLEDGED_CHANGE,
                          constants.JOINING_CONFIG_CHANGED,
                          constants.NORMAL_ACKNOWLEDGED_CHANGE,
                          constants.NORMAL_CONFIG_CHANGED,
                          constants.NORMAL]
    leaving = [constants.LEAVING_ACKNOWLEDGED_CHANGE,
               constants.LEAVING_CONFIG_CHANGED]

    staying_servers = ([k for k, v in cluster_view.iteritems()
                        if v in current_or_joining])
    leaving_servers = ([k for k, v in cluster_view.iteritems()
                        if v in leaving])

    contents = dedent('''\
        {}
        [cluster]
        localhost = {}
        ''').format(WARNING_HEADER, current_server)

    for node in staying_servers:
        contents += 'node = {}\n'.format(node)
    for node in leaving_servers:
        contents += 'leaving = {}\n'.format(node)

    safely_write(filename, contents)
def write_memcached_cluster_settings(filename, cluster_view):
    """Writes out the memcached cluster_settings file"""
    valid_servers_states = [constants.LEAVING_ACKNOWLEDGED_CHANGE,
                            constants.LEAVING_CONFIG_CHANGED,
                            constants.NORMAL_ACKNOWLEDGED_CHANGE,
                            constants.NORMAL_CONFIG_CHANGED,
                            constants.NORMAL]
    valid_new_servers_states = [constants.NORMAL,
                                constants.NORMAL_ACKNOWLEDGED_CHANGE,
                                constants.NORMAL_CONFIG_CHANGED,
                                constants.JOINING_ACKNOWLEDGED_CHANGE,
                                constants.JOINING_CONFIG_CHANGED]
    servers_ips = sorted([combine_ip_port(k, 11211)
                          for k, v in cluster_view.iteritems()
                          if v in valid_servers_states])

    new_servers_ips = sorted([combine_ip_port(k, 11211)
                              for k, v in cluster_view.iteritems()
                              if v in valid_new_servers_states])

    new_file_contents = WARNING_HEADER + "\n"

    if new_servers_ips == servers_ips:
        new_file_contents += "servers={}\n".format(",".join(servers_ips))
    else:
        new_file_contents += "servers={}\nnew_servers={}\n".format(
            ",".join(servers_ips),
            ",".join(new_servers_ips))

    safely_write(filename, new_file_contents)
Example #3
0
    def on_config_changed(self, value, alarm):
        _log.info("Updating {}".format(self._file))

        safely_write(self._file, value)

        run_command("service sprout reload")

        alarm.update_file(self._file)