Search in sources :

Example 1 with BackupConfigSpec

use of com.netflix.exhibitor.core.backup.BackupConfigSpec 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 2 with BackupConfigSpec

use of com.netflix.exhibitor.core.backup.BackupConfigSpec 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 3 with BackupConfigSpec

use of com.netflix.exhibitor.core.backup.BackupConfigSpec in project exhibitor by soabase.

the class DefaultProperties method newDefaultInstanceConfig.

/**
     * Return the standard default properties as an instance config
     *
     * @param provider backup provider or null
     * @return default properties instance
     */
public static InstanceConfig newDefaultInstanceConfig(BackupProvider provider) {
    List<EncodedConfigParser.FieldValue> backupDefaultValues = Lists.newArrayList();
    if (provider != null) {
        for (BackupConfigSpec spec : provider.getConfigs()) {
            backupDefaultValues.add(new EncodedConfigParser.FieldValue(spec.getKey(), spec.getDefaultValue()));
        }
    }
    final String backupExtraValue = new EncodedConfigParser(backupDefaultValues).toEncoded();
    return new InstanceConfig() {

        @Override
        public String getString(StringConfigs config) {
            switch(config) {
                case ZOO_CFG_EXTRA:
                    {
                        return "syncLimit=5&tickTime=2000&initLimit=10";
                    }
                case BACKUP_EXTRA:
                    {
                        return backupExtraValue;
                    }
            }
            return "";
        }

        @Override
        public int getInt(IntConfigs config) {
            switch(config) {
                case CLIENT_PORT:
                    {
                        return 2181;
                    }
                case CONNECT_PORT:
                    {
                        return 2888;
                    }
                case ELECTION_PORT:
                    {
                        return 3888;
                    }
                case CHECK_MS:
                    {
                        return (int) TimeUnit.MILLISECONDS.convert(30, TimeUnit.SECONDS);
                    }
                case CLEANUP_PERIOD_MS:
                    {
                        return (int) TimeUnit.MILLISECONDS.convert(12, TimeUnit.HOURS);
                    }
                case CLEANUP_MAX_FILES:
                    {
                        return 3;
                    }
                case BACKUP_PERIOD_MS:
                    {
                        return (int) TimeUnit.MILLISECONDS.convert(1, TimeUnit.MINUTES);
                    }
                case BACKUP_MAX_STORE_MS:
                    {
                        return (int) TimeUnit.MILLISECONDS.convert(1, TimeUnit.DAYS);
                    }
                case AUTO_MANAGE_INSTANCES_SETTLING_PERIOD_MS:
                    {
                        return (int) TimeUnit.MILLISECONDS.convert(3, TimeUnit.MINUTES);
                    }
                case OBSERVER_THRESHOLD:
                    {
                        return 999;
                    }
                case AUTO_MANAGE_INSTANCES_APPLY_ALL_AT_ONCE:
                    {
                        return 1;
                    }
            }
            return 0;
        }
    };
}
Also used : BackupConfigSpec(com.netflix.exhibitor.core.backup.BackupConfigSpec)

Aggregations

BackupConfigSpec (com.netflix.exhibitor.core.backup.BackupConfigSpec)3 EncodedConfigParser (com.netflix.exhibitor.core.config.EncodedConfigParser)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 InstanceConfig (com.netflix.exhibitor.core.config.InstanceConfig)1 IntConfigs (com.netflix.exhibitor.core.config.IntConfigs)1 StringConfigs (com.netflix.exhibitor.core.config.StringConfigs)1 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 ArrayNode (org.codehaus.jackson.node.ArrayNode)1