Search in sources :

Example 11 with InstanceConfig

use of com.netflix.exhibitor.core.config.InstanceConfig in project exhibitor by soabase.

the class MonitorRunningInstance method doWork.

@VisibleForTesting
void doWork() throws Exception {
    InstanceConfig config = exhibitor.getConfigManager().getConfig();
    StateAndLeader stateAndLeader = getStateAndLeader();
    InstanceState instanceState = new InstanceState(new ServerList(config.getString(StringConfigs.SERVERS_SPEC)), stateAndLeader.getState(), new RestartSignificantConfig(config));
    currentIsLeader.set(stateAndLeader.isLeader());
    exhibitor.getConfigManager().checkRollingConfig(instanceState);
    InstanceState localCurrentInstanceState = currentInstanceState.get();
    if (instanceState.equals(localCurrentInstanceState)) {
        checkForRestart(config, localCurrentInstanceState);
    } else {
        handleServerListChange(instanceState, localCurrentInstanceState);
    }
}
Also used : InstanceConfig(com.netflix.exhibitor.core.config.InstanceConfig) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 12 with InstanceConfig

use of com.netflix.exhibitor.core.config.InstanceConfig in project exhibitor by soabase.

the class ClusterResource method getClusterStatus.

@Path("status")
@GET
@Produces(MediaType.APPLICATION_JSON)
public Response getClusterStatus() throws Exception {
    InstanceConfig config = context.getExhibitor().getConfigManager().getConfig();
    ServerList serverList = new ServerList(config.getString(StringConfigs.SERVERS_SPEC));
    ClusterStatusTask task = new ClusterStatusTask(context.getExhibitor(), serverList.getSpecs());
    List<ServerStatus> statuses = context.getExhibitor().getForkJoinPool().invoke(task);
    GenericEntity<List<ServerStatus>> entity = new GenericEntity<List<ServerStatus>>(statuses) {
    };
    return Response.ok(entity).build();
}
Also used : InstanceConfig(com.netflix.exhibitor.core.config.InstanceConfig) GenericEntity(javax.ws.rs.core.GenericEntity) ServerStatus(com.netflix.exhibitor.core.entities.ServerStatus) ServerList(com.netflix.exhibitor.core.state.ServerList) ServerList(com.netflix.exhibitor.core.state.ServerList) List(java.util.List) ClusterStatusTask(com.netflix.exhibitor.core.automanage.ClusterStatusTask) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 13 with InstanceConfig

use of com.netflix.exhibitor.core.config.InstanceConfig in project exhibitor by soabase.

the class ConfigResource method setConfigRolling.

@Path("set-rolling")
@POST
@Produces(MediaType.APPLICATION_JSON)
public Response setConfigRolling(String newConfigJson) throws Exception {
    InstanceConfig wrapped = parseToConfig(newConfigJson);
    Result result = null;
    try {
        PseudoLock lock = context.getExhibitor().getConfigManager().newConfigBasedLock();
        try {
            if (// TODO consider making configurable in the future
            lock.lock(context.getExhibitor().getLog(), 10, TimeUnit.SECONDS)) {
                if (context.getExhibitor().getConfigManager().startRollingConfig(wrapped, null)) {
                    result = new Result("OK", true);
                }
            }
        } finally {
            lock.unlock();
        }
        if (result == null) {
            result = new Result("Another process has updated the config.", false);
        }
        context.getExhibitor().resetLocalConnection();
    } catch (Exception e) {
        result = new Result(e);
    }
    return Response.ok(result).build();
}
Also used : InstanceConfig(com.netflix.exhibitor.core.config.InstanceConfig) IOException(java.io.IOException) Result(com.netflix.exhibitor.core.entities.Result) PseudoLock(com.netflix.exhibitor.core.config.PseudoLock) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces)

Example 14 with InstanceConfig

use of com.netflix.exhibitor.core.config.InstanceConfig in project exhibitor by soabase.

the class ConfigResource method setConfig.

@Path("set")
@POST
@Produces(MediaType.APPLICATION_JSON)
public Response setConfig(String newConfigJson) throws Exception {
    InstanceConfig wrapped = parseToConfig(newConfigJson);
    Result result = null;
    try {
        PseudoLock lock = context.getExhibitor().getConfigManager().newConfigBasedLock();
        try {
            if (// TODO consider making configurable in the future
            lock.lock(context.getExhibitor().getLog(), 10, TimeUnit.SECONDS)) {
                if (context.getExhibitor().getConfigManager().updateConfig(wrapped)) {
                    result = new Result("OK", true);
                }
            }
        } finally {
            lock.unlock();
        }
        if (result == null) {
            result = new Result(CANT_UPDATE_CONFIG_MESSAGE, false);
        }
        context.getExhibitor().resetLocalConnection();
    } catch (Exception e) {
        result = new Result(e);
    }
    return Response.ok(result).build();
}
Also used : InstanceConfig(com.netflix.exhibitor.core.config.InstanceConfig) IOException(java.io.IOException) Result(com.netflix.exhibitor.core.entities.Result) PseudoLock(com.netflix.exhibitor.core.config.PseudoLock) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces)

Example 15 with InstanceConfig

use of com.netflix.exhibitor.core.config.InstanceConfig 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)

Aggregations

InstanceConfig (com.netflix.exhibitor.core.config.InstanceConfig)15 IntConfigs (com.netflix.exhibitor.core.config.IntConfigs)7 StringConfigs (com.netflix.exhibitor.core.config.StringConfigs)7 Path (javax.ws.rs.Path)7 Produces (javax.ws.rs.Produces)7 GET (javax.ws.rs.GET)5 ServerList (com.netflix.exhibitor.core.state.ServerList)4 ServerSpec (com.netflix.exhibitor.core.state.ServerSpec)3 VisibleForTesting (com.google.common.annotations.VisibleForTesting)2 Exhibitor (com.netflix.exhibitor.core.Exhibitor)2 ConfigCollection (com.netflix.exhibitor.core.config.ConfigCollection)2 EncodedConfigParser (com.netflix.exhibitor.core.config.EncodedConfigParser)2 LoadedInstanceConfig (com.netflix.exhibitor.core.config.LoadedInstanceConfig)2 PropertyBasedInstanceConfig (com.netflix.exhibitor.core.config.PropertyBasedInstanceConfig)2 PseudoLock (com.netflix.exhibitor.core.config.PseudoLock)2 RollingConfigState (com.netflix.exhibitor.core.config.RollingConfigState)2 Result (com.netflix.exhibitor.core.entities.Result)2 FourLetterWord (com.netflix.exhibitor.core.state.FourLetterWord)2 IOException (java.io.IOException)2 POST (javax.ws.rs.POST)2