use of com.netflix.exhibitor.core.state.ServerSpec in project exhibitor by soabase.
the class ClusterResource method getClusterAsExhibitor.
@Path("list")
@GET
@Produces(MediaType.APPLICATION_FORM_URLENCODED)
public String getClusterAsExhibitor() throws Exception {
InstanceConfig config = context.getExhibitor().getConfigManager().getConfig();
StringBuilder response = new StringBuilder();
ServerList serverList = new ServerList(config.getString(StringConfigs.SERVERS_SPEC));
response.append("count=").append(serverList.getSpecs().size());
int index = 0;
for (ServerSpec spec : serverList.getSpecs()) {
response.append("&server").append(index++).append("=").append(URLEncoder.encode(spec.getHostname(), "UTF-8"));
}
response.append("&port=").append(config.getInt(IntConfigs.CLIENT_PORT));
return response.toString();
}
use of com.netflix.exhibitor.core.state.ServerSpec 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();
}
use of com.netflix.exhibitor.core.state.ServerSpec in project exhibitor by soabase.
the class ClusterState method buildStatusMap.
Map<ServerSpec, InstanceStateTypes> buildStatusMap() {
ServerList serverList = configuredServerList.get();
ImmutableMap.Builder<ServerSpec, InstanceStateTypes> builder = ImmutableMap.builder();
List<ServerStatus> currentStatuses = statuses.get();
for (ServerStatus status : currentStatuses) {
ServerSpec spec = serverList.getSpec(status.getHostname());
if (spec != null) {
builder.put(spec, status.getInstanceStateType());
} else {
log.error("No configured spec found for hostname: " + status.getHostname());
}
}
return builder.build();
}
use of com.netflix.exhibitor.core.state.ServerSpec in project exhibitor by soabase.
the class FixedEnsembleBuilder method createPotentialServerList.
@Override
public ServerList createPotentialServerList() {
ServerList configuredServerList = clusterState.getConfiguredServerList();
Map<ServerSpec, InstanceStateTypes> statusMap = clusterState.buildStatusMap();
List<ServerSpec> newList = Lists.newArrayList();
for (ServerSpec spec : configuredServerList.getSpecs()) {
if (statusMap.get(spec) != InstanceStateTypes.DOWN) {
newList.add(spec);
}
}
if (newList.size() >= fixedEnsembleSize) {
// no room for us
return configuredServerList;
}
int standardTypeCount = 0;
for (ServerSpec spec : newList) {
if (spec.getServerType() == ServerType.STANDARD) {
++standardTypeCount;
}
}
int observerThreshold = exhibitor.getConfigManager().getConfig().getInt(IntConfigs.OBSERVER_THRESHOLD);
ServerType serverType = ((observerThreshold > 0) && (standardTypeCount >= observerThreshold)) ? ServerType.OBSERVER : ServerType.STANDARD;
int existingMaxId = FlexibleEnsembleBuilder.getExistingMaxId(configuredServerList);
ServerSpec us = new ServerSpec(exhibitor.getThisJVMHostname(), existingMaxId + 1, serverType);
newList.add(us);
return new ServerList(newList);
}
Aggregations