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