Search in sources :

Example 1 with EncodedConfigParser

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();
        }
    };
}
Also used : InstanceConfig(com.netflix.exhibitor.core.config.InstanceConfig) EncodedConfigParser(com.netflix.exhibitor.core.config.EncodedConfigParser) IntConfigs(com.netflix.exhibitor.core.config.IntConfigs) JsonNode(org.codehaus.jackson.JsonNode) StringConfigs(com.netflix.exhibitor.core.config.StringConfigs) ObjectMapper(org.codehaus.jackson.map.ObjectMapper)

Example 2 with EncodedConfigParser

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);
}
Also used : EncodedConfigParser(com.netflix.exhibitor.core.config.EncodedConfigParser)

Example 3 with EncodedConfigParser

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);
}
Also used : ObjectNode(org.codehaus.jackson.node.ObjectNode) EncodedConfigParser(com.netflix.exhibitor.core.config.EncodedConfigParser) BackupConfigSpec(com.netflix.exhibitor.core.backup.BackupConfigSpec) ArrayNode(org.codehaus.jackson.node.ArrayNode) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 4 with EncodedConfigParser

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();
}
Also used : ServerSpec(com.netflix.exhibitor.core.state.ServerSpec) ObjectNode(org.codehaus.jackson.node.ObjectNode) IntConfigs(com.netflix.exhibitor.core.config.IntConfigs) Response(javax.ws.rs.core.Response) InstanceConfig(com.netflix.exhibitor.core.config.InstanceConfig) EncodedConfigParser(com.netflix.exhibitor.core.config.EncodedConfigParser) FourLetterWord(com.netflix.exhibitor.core.state.FourLetterWord) BackupConfigSpec(com.netflix.exhibitor.core.backup.BackupConfigSpec) ServerList(com.netflix.exhibitor.core.state.ServerList) EntityTag(javax.ws.rs.core.EntityTag) StringConfigs(com.netflix.exhibitor.core.config.StringConfigs) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 5 with EncodedConfigParser

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();
}
Also used : EncodedConfigParser(com.netflix.exhibitor.core.config.EncodedConfigParser)

Aggregations

EncodedConfigParser (com.netflix.exhibitor.core.config.EncodedConfigParser)5 BackupConfigSpec (com.netflix.exhibitor.core.backup.BackupConfigSpec)2 InstanceConfig (com.netflix.exhibitor.core.config.InstanceConfig)2 IntConfigs (com.netflix.exhibitor.core.config.IntConfigs)2 StringConfigs (com.netflix.exhibitor.core.config.StringConfigs)2 GET (javax.ws.rs.GET)2 Path (javax.ws.rs.Path)2 Produces (javax.ws.rs.Produces)2 ObjectNode (org.codehaus.jackson.node.ObjectNode)2 FourLetterWord (com.netflix.exhibitor.core.state.FourLetterWord)1 ServerList (com.netflix.exhibitor.core.state.ServerList)1 ServerSpec (com.netflix.exhibitor.core.state.ServerSpec)1 EntityTag (javax.ws.rs.core.EntityTag)1 Response (javax.ws.rs.core.Response)1 JsonNode (org.codehaus.jackson.JsonNode)1 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)1 ArrayNode (org.codehaus.jackson.node.ArrayNode)1