use of com.netflix.exhibitor.core.config.StringConfigs in project exhibitor by soabase.
the class AutomaticInstanceManagement method adjustConfig.
@VisibleForTesting
void adjustConfig(final String newSpec, String leaderHostname) throws Exception {
final InstanceConfig currentConfig = exhibitor.getConfigManager().getConfig();
InstanceConfig newConfig = new InstanceConfig() {
@Override
public String getString(StringConfigs config) {
if (config == StringConfigs.SERVERS_SPEC) {
return newSpec;
}
return currentConfig.getString(config);
}
@Override
public int getInt(IntConfigs config) {
return currentConfig.getInt(config);
}
};
boolean success;
if (applyAllAtOnce()) {
success = exhibitor.getConfigManager().updateConfig(newConfig);
} else {
success = exhibitor.getConfigManager().startRollingConfig(newConfig, leaderHostname);
}
if (success) {
clusterState.clear();
} else {
exhibitor.getLog().add(ActivityLog.Type.INFO, "Could not initiate Automatic Instance Management config change. Another process is already making a config change.");
}
}
use of com.netflix.exhibitor.core.config.StringConfigs in project exhibitor by soabase.
the class ConfigResource method parseToConfig.
private InstanceConfig parseToConfig(String newConfigJson) throws IOException {
ObjectMapper mapper = new ObjectMapper();
final JsonNode tree = mapper.readTree(mapper.getJsonFactory().createJsonParser(newConfigJson));
String backupExtraValue = "";
if (tree.get("backupExtra") != null) {
List<EncodedConfigParser.FieldValue> values = Lists.newArrayList();
JsonNode backupExtra = tree.get("backupExtra");
Iterator<String> fieldNames = backupExtra.getFieldNames();
while (fieldNames.hasNext()) {
String name = fieldNames.next();
String value = backupExtra.get(name).getTextValue();
values.add(new EncodedConfigParser.FieldValue(name, value));
}
backupExtraValue = new EncodedConfigParser(values).toEncoded();
}
List<EncodedConfigParser.FieldValue> zooCfgValues = Lists.newArrayList();
JsonNode zooCfgExtra = tree.get("zooCfgExtra");
Iterator<String> fieldNames = zooCfgExtra.getFieldNames();
while (fieldNames.hasNext()) {
String name = fieldNames.next();
String value = zooCfgExtra.get(name).getTextValue();
zooCfgValues.add(new EncodedConfigParser.FieldValue(name, value));
}
final String zooCfgExtraValue = new EncodedConfigParser(zooCfgValues).toEncoded();
final String finalBackupExtraValue = backupExtraValue;
return new InstanceConfig() {
@Override
public String getString(StringConfigs config) {
switch(config) {
case BACKUP_EXTRA:
{
return finalBackupExtraValue;
}
case ZOO_CFG_EXTRA:
{
return zooCfgExtraValue;
}
default:
{
// NOP
break;
}
}
JsonNode node = tree.get(fixName(config));
if (node == null) {
return "";
}
return node.asText();
}
@Override
public int getInt(IntConfigs config) {
JsonNode node = tree.get(fixName(config));
if (node == null) {
return 0;
}
return node.asInt();
}
};
}
use of com.netflix.exhibitor.core.config.StringConfigs in project exhibitor by soabase.
the class MockConfigProvider method setConfig.
void setConfig(final IntConfigs type, final int value) {
final InstanceConfig config = collection.getRootConfig();
final InstanceConfig newConfig = new InstanceConfig() {
@Override
public String getString(StringConfigs configType) {
return config.getString(configType);
}
@Override
public int getInt(IntConfigs configType) {
if (configType == type) {
return value;
}
return config.getInt(configType);
}
};
collection = new ConfigCollection() {
@Override
public InstanceConfig getConfigForThisInstance(String hostname) {
return getRootConfig();
}
@Override
public InstanceConfig getRootConfig() {
return newConfig;
}
@Override
public InstanceConfig getRollingConfig() {
return null;
}
@Override
public boolean isRolling() {
return false;
}
@Override
public RollingConfigState getRollingConfigState() {
return null;
}
};
}
use of com.netflix.exhibitor.core.config.StringConfigs in project exhibitor by soabase.
the class MockConfigProvider method setConfig.
void setConfig(final StringConfigs type, final String value) {
final InstanceConfig config = collection.getRootConfig();
final InstanceConfig newConfig = new InstanceConfig() {
@Override
public String getString(StringConfigs configType) {
if (configType == type) {
return value;
}
return config.getString(configType);
}
@Override
public int getInt(IntConfigs configType) {
return config.getInt(configType);
}
};
collection = new ConfigCollection() {
@Override
public InstanceConfig getConfigForThisInstance(String hostname) {
return getRootConfig();
}
@Override
public InstanceConfig getRootConfig() {
return newConfig;
}
@Override
public InstanceConfig getRollingConfig() {
return null;
}
@Override
public boolean isRolling() {
return false;
}
@Override
public RollingConfigState getRollingConfigState() {
return null;
}
};
}
use of com.netflix.exhibitor.core.config.StringConfigs in project exhibitor by soabase.
the class TestMonitorRunningInstance method testServerListHasChanged.
@Test
public void testServerListHasChanged() throws Exception {
InstanceConfig config = new InstanceConfig() {
@Override
public String getString(StringConfigs config) {
switch(config) {
case SERVERS_SPEC:
{
return "S:1:foo,S:2:bar";
}
}
return null;
}
@Override
public int getInt(IntConfigs config) {
return 0;
}
};
Exhibitor mockExhibitor = makeMockExhibitor(config, "foo");
MonitorRunningInstance monitor = new MonitorRunningInstance(mockExhibitor);
StateAndLeader stateAndLeader = monitor.getStateAndLeader();
InstanceState localCurrentInstanceState = new InstanceState(new ServerList(config.getString(StringConfigs.SERVERS_SPEC)), stateAndLeader.getState(), new RestartSignificantConfig(config));
InstanceConfig newConfig = new InstanceConfig() {
@Override
public String getString(StringConfigs config) {
switch(config) {
case SERVERS_SPEC:
{
// observer added
return "S:1:foo,S:2:bar,O:3:snafu";
}
}
return null;
}
@Override
public int getInt(IntConfigs config) {
return 0;
}
};
InstanceState instanceState = new InstanceState(new ServerList(newConfig.getString(StringConfigs.SERVERS_SPEC)), stateAndLeader.getState(), new RestartSignificantConfig(newConfig));
Assert.assertFalse(monitor.serverListHasChanged(instanceState, localCurrentInstanceState));
newConfig = new InstanceConfig() {
@Override
public String getString(StringConfigs config) {
switch(config) {
case SERVERS_SPEC:
{
// standard added
return "S:1:foo,S:2:bar,S:3:snafu";
}
}
return null;
}
@Override
public int getInt(IntConfigs config) {
return 0;
}
};
instanceState = new InstanceState(new ServerList(newConfig.getString(StringConfigs.SERVERS_SPEC)), stateAndLeader.getState(), new RestartSignificantConfig(newConfig));
Assert.assertTrue(monitor.serverListHasChanged(instanceState, localCurrentInstanceState));
newConfig = new InstanceConfig() {
@Override
public String getString(StringConfigs config) {
switch(config) {
case SERVERS_SPEC:
{
// "us" changed to observer
return "O:1:foo,S:2:bar";
}
}
return null;
}
@Override
public int getInt(IntConfigs config) {
return 0;
}
};
instanceState = new InstanceState(new ServerList(newConfig.getString(StringConfigs.SERVERS_SPEC)), stateAndLeader.getState(), new RestartSignificantConfig(newConfig));
Assert.assertTrue(monitor.serverListHasChanged(instanceState, localCurrentInstanceState));
newConfig = new InstanceConfig() {
@Override
public String getString(StringConfigs config) {
switch(config) {
case SERVERS_SPEC:
{
// not-us changed to observer
return "S:1:foo,O:2:bar";
}
}
return null;
}
@Override
public int getInt(IntConfigs config) {
return 0;
}
};
instanceState = new InstanceState(new ServerList(newConfig.getString(StringConfigs.SERVERS_SPEC)), stateAndLeader.getState(), new RestartSignificantConfig(newConfig));
Assert.assertTrue(monitor.serverListHasChanged(instanceState, localCurrentInstanceState));
}
Aggregations