Search in sources :

Example 1 with FourLetterWord

use of com.netflix.exhibitor.core.state.FourLetterWord in project exhibitor by soabase.

the class ClusterResource method getFourLetterWord.

@Path("4ltr/{word}")
@GET
@Produces(MediaType.APPLICATION_JSON)
public String getFourLetterWord(@PathParam("word") String word) throws Exception {
    InstanceConfig config = context.getExhibitor().getConfigManager().getConfig();
    String value;
    try {
        FourLetterWord.Word wordEnum = FourLetterWord.Word.valueOf(word.toUpperCase());
        value = new FourLetterWord(wordEnum, config, context.getExhibitor().getConnectionTimeOutMs()).getResponse();
    } catch (IllegalArgumentException e) {
        value = "* unknown *";
    }
    return JsonUtil.writeValueAsString(value);
}
Also used : InstanceConfig(com.netflix.exhibitor.core.config.InstanceConfig) FourLetterWord(com.netflix.exhibitor.core.state.FourLetterWord) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 2 with FourLetterWord

use of com.netflix.exhibitor.core.state.FourLetterWord 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 FourLetterWord

use of com.netflix.exhibitor.core.state.FourLetterWord in project exhibitor by soabase.

the class GetMonitorData method call.

@Override
public Boolean call() throws Exception {
    List<String> lines = new FourLetterWord(FourLetterWord.Word.MNTR, exhibitor.getThisJVMHostname(), exhibitor.getConfigManager().getConfig(), exhibitor.getConnectionTimeOutMs()).getResponseLines();
    doUpdate(lines);
    return true;
}
Also used : FourLetterWord(com.netflix.exhibitor.core.state.FourLetterWord)

Aggregations

FourLetterWord (com.netflix.exhibitor.core.state.FourLetterWord)3 InstanceConfig (com.netflix.exhibitor.core.config.InstanceConfig)2 GET (javax.ws.rs.GET)2 Path (javax.ws.rs.Path)2 Produces (javax.ws.rs.Produces)2 BackupConfigSpec (com.netflix.exhibitor.core.backup.BackupConfigSpec)1 EncodedConfigParser (com.netflix.exhibitor.core.config.EncodedConfigParser)1 IntConfigs (com.netflix.exhibitor.core.config.IntConfigs)1 StringConfigs (com.netflix.exhibitor.core.config.StringConfigs)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 ObjectNode (org.codehaus.jackson.node.ObjectNode)1