use of com.netflix.exhibitor.core.config.EncodedConfigParser in project exhibitor by soabase.
the class ConfigResource method parseToConfig.
private InstanceConfig parseToConfig(String newConfigJson) throws IOException {
ObjectMapper mapper = new ObjectMapper();
final JsonNode tree = mapper.readTree(mapper.getJsonFactory().createJsonParser(newConfigJson));
String backupExtraValue = "";
if (tree.get("backupExtra") != null) {
List<EncodedConfigParser.FieldValue> values = Lists.newArrayList();
JsonNode backupExtra = tree.get("backupExtra");
Iterator<String> fieldNames = backupExtra.getFieldNames();
while (fieldNames.hasNext()) {
String name = fieldNames.next();
String value = backupExtra.get(name).getTextValue();
values.add(new EncodedConfigParser.FieldValue(name, value));
}
backupExtraValue = new EncodedConfigParser(values).toEncoded();
}
List<EncodedConfigParser.FieldValue> zooCfgValues = Lists.newArrayList();
JsonNode zooCfgExtra = tree.get("zooCfgExtra");
Iterator<String> fieldNames = zooCfgExtra.getFieldNames();
while (fieldNames.hasNext()) {
String name = fieldNames.next();
String value = zooCfgExtra.get(name).getTextValue();
zooCfgValues.add(new EncodedConfigParser.FieldValue(name, value));
}
final String zooCfgExtraValue = new EncodedConfigParser(zooCfgValues).toEncoded();
final String finalBackupExtraValue = backupExtraValue;
return new InstanceConfig() {
@Override
public String getString(StringConfigs config) {
switch(config) {
case BACKUP_EXTRA:
{
return finalBackupExtraValue;
}
case ZOO_CFG_EXTRA:
{
return zooCfgExtraValue;
}
default:
{
// NOP
break;
}
}
JsonNode node = tree.get(fixName(config));
if (node == null) {
return "";
}
return node.asText();
}
@Override
public int getInt(IntConfigs config) {
JsonNode node = tree.get(fixName(config));
if (node == null) {
return 0;
}
return node.asInt();
}
};
}
use of com.netflix.exhibitor.core.config.EncodedConfigParser in project exhibitor by soabase.
the class MonitorRunningInstance method getDownInstanceRestartMs.
private int getDownInstanceRestartMs(InstanceConfig config) {
EncodedConfigParser parser = new EncodedConfigParser(exhibitor.getConfigManager().getConfig().getString(StringConfigs.ZOO_CFG_EXTRA));
int tickTime = parseInt(parser.getValue("tickTime"));
int initLimit = parseInt(parser.getValue("initLimit"));
int syncLimit = parseInt(parser.getValue("syncLimit"));
if ((tickTime > 0) && ((initLimit > 0) || (syncLimit > 0))) {
// ZK should sync or fail within the initLimit/syncLimit
return 2 * tickTime * Math.max(initLimit, syncLimit);
}
return (config.getInt(IntConfigs.CHECK_MS) * DOWN_RECHECK_FACTOR);
}
use of com.netflix.exhibitor.core.config.EncodedConfigParser in project exhibitor by soabase.
the class UIResource method getBackupConfig.
@Path("backup-config")
@GET
@Produces(MediaType.APPLICATION_JSON)
public String getBackupConfig() throws Exception {
ArrayNode node = JsonNodeFactory.instance.arrayNode();
if (context.getExhibitor().getBackupManager().isActive()) {
EncodedConfigParser parser = context.getExhibitor().getBackupManager().getBackupConfigParser();
List<BackupConfigSpec> configs = context.getExhibitor().getBackupManager().getConfigSpecs();
for (BackupConfigSpec c : configs) {
ObjectNode n = JsonNodeFactory.instance.objectNode();
String value = parser.getValue(c.getKey());
n.put("key", c.getKey());
n.put("name", c.getDisplayName());
n.put("help", c.getHelpText());
n.put("value", (value != null) ? value : "");
n.put("type", c.getType().name().toLowerCase().substring(0, 1));
node.add(n);
}
}
return JsonUtil.writeValueAsString(node);
}
use of com.netflix.exhibitor.core.config.EncodedConfigParser in project exhibitor by soabase.
the class ConfigResource method getSystemState.
@Path("get-state")
@GET
@Produces(MediaType.APPLICATION_JSON)
public Response getSystemState(@Context Request request) throws Exception {
InstanceConfig config = context.getExhibitor().getConfigManager().getConfig();
String response = new FourLetterWord(FourLetterWord.Word.RUOK, config, context.getExhibitor().getConnectionTimeOutMs()).getResponse();
ServerList serverList = new ServerList(config.getString(StringConfigs.SERVERS_SPEC));
ServerSpec us = UsState.findUs(context.getExhibitor(), serverList.getSpecs());
ObjectNode mainNode = JsonNodeFactory.instance.objectNode();
ObjectNode configNode = JsonNodeFactory.instance.objectNode();
ObjectNode controlPanelNode = JsonNodeFactory.instance.objectNode();
mainNode.put("version", context.getExhibitor().getVersion());
mainNode.put("running", "imok".equals(response));
mainNode.put("backupActive", context.getExhibitor().getBackupManager().isActive());
mainNode.put("standaloneMode", context.getExhibitor().getConfigManager().isStandaloneMode());
mainNode.put("extraHeadingText", context.getExhibitor().getExtraHeadingText());
mainNode.put("nodeMutationsAllowed", context.getExhibitor().nodeMutationsAllowed());
configNode.put("rollInProgress", context.getExhibitor().getConfigManager().isRolling());
configNode.put("rollStatus", context.getExhibitor().getConfigManager().getRollingConfigState().getRollingStatus());
configNode.put("rollPercentDone", context.getExhibitor().getConfigManager().getRollingConfigState().getRollingPercentDone());
configNode.put("hostname", context.getExhibitor().getThisJVMHostname());
configNode.put("serverId", (us != null) ? us.getServerId() : -1);
for (StringConfigs c : StringConfigs.values()) {
configNode.put(fixName(c), config.getString(c));
}
for (IntConfigs c : IntConfigs.values()) {
String fixedName = fixName(c);
int value = config.getInt(c);
configNode.put(fixedName, value);
}
EncodedConfigParser zooCfgParser = new EncodedConfigParser(config.getString(StringConfigs.ZOO_CFG_EXTRA));
ObjectNode zooCfgNode = JsonNodeFactory.instance.objectNode();
for (EncodedConfigParser.FieldValue fv : zooCfgParser.getFieldValues()) {
zooCfgNode.put(fv.getField(), fv.getValue());
}
configNode.put("zooCfgExtra", zooCfgNode);
if (context.getExhibitor().getBackupManager().isActive()) {
ObjectNode backupExtraNode = JsonNodeFactory.instance.objectNode();
EncodedConfigParser parser = context.getExhibitor().getBackupManager().getBackupConfigParser();
List<BackupConfigSpec> configs = context.getExhibitor().getBackupManager().getConfigSpecs();
for (BackupConfigSpec c : configs) {
String value = parser.getValue(c.getKey());
backupExtraNode.put(c.getKey(), (value != null) ? value : "");
}
configNode.put("backupExtra", backupExtraNode);
}
configNode.put("controlPanel", controlPanelNode);
mainNode.put("config", configNode);
String json = JsonUtil.writeValueAsString(mainNode);
EntityTag tag = new EntityTag(Hashing.sha1().hashString(json, Charsets.UTF_8).toString());
Response.ResponseBuilder builder = request.evaluatePreconditions(tag);
if (builder == null) {
builder = Response.ok(json).tag(tag);
}
return builder.build();
}
use of com.netflix.exhibitor.core.config.EncodedConfigParser in project exhibitor by soabase.
the class BackupManager method getBackupConfig.
private Map<String, String> getBackupConfig() {
String backupExtra = exhibitor.getConfigManager().getConfig().getString(StringConfigs.BACKUP_EXTRA);
EncodedConfigParser encodedConfigParser = new EncodedConfigParser(backupExtra);
return encodedConfigParser.getSortedMap();
}
Aggregations