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);
}
}
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();
}
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();
}
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();
}
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();
}
Aggregations