use of com.netflix.exhibitor.core.config.StringConfigs in project exhibitor by soabase.
the class TestMonitorRunningInstance method testTempDownInstance.
@Test
public void testTempDownInstance() throws Exception {
final AtomicInteger checkMs = new AtomicInteger(10000);
InstanceConfig config = new InstanceConfig() {
@Override
public String getString(StringConfigs config) {
switch(config) {
case SERVERS_SPEC:
{
return "1:foo,2:bar";
}
case ZOOKEEPER_DATA_DIRECTORY:
case ZOOKEEPER_INSTALL_DIRECTORY:
{
return "/";
}
}
return null;
}
@Override
public int getInt(IntConfigs config) {
switch(config) {
case CHECK_MS:
{
return checkMs.get();
}
}
return 0;
}
};
Exhibitor mockExhibitor = makeMockExhibitor(config, "foo");
final Semaphore semaphore = new Semaphore(0);
MonitorRunningInstance monitor = new MonitorRunningInstance(mockExhibitor) {
@Override
protected void restartZooKeeper(InstanceState currentInstanceState) throws Exception {
semaphore.release();
}
};
monitor.doWork();
Assert.assertTrue(semaphore.tryAcquire(10, TimeUnit.SECONDS));
monitor.doWork();
// no instance state change, should not try restart
Assert.assertFalse(semaphore.tryAcquire(3, TimeUnit.SECONDS));
checkMs.set(1);
// should do restart now as 10 times checkMs has elapsed
monitor.doWork();
Assert.assertTrue(semaphore.tryAcquire(10, TimeUnit.SECONDS));
}
use of com.netflix.exhibitor.core.config.StringConfigs 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.config.StringConfigs in project exhibitor by soabase.
the class ExhibitorCLI method printHelp.
public void printHelp() {
ManifestVersion manifestVersion = new ManifestVersion();
System.out.println("Exhibitor " + manifestVersion.getVersion());
HelpFormatter formatter = new HelpFormatter() {
@Override
public void printUsage(PrintWriter pw, int width, String cmdLineSyntax) {
}
@Override
public void printUsage(PrintWriter pw, int width, String app, Options options) {
}
};
formatter.printHelp("ExhibitorMain", generalOptions);
for (OptionSection section : sections) {
formatter.printHelp(" ", "\n== " + section.sectionName + " ==", section.options, null);
}
System.out.println();
System.out.println("== Default Property Names ==");
for (StringConfigs config : StringConfigs.values()) {
System.out.println("\t" + PropertyBasedInstanceConfig.toName(config, ""));
}
for (IntConfigs config : IntConfigs.values()) {
System.out.println("\t" + PropertyBasedInstanceConfig.toName(config, ""));
}
}
use of com.netflix.exhibitor.core.config.StringConfigs in project exhibitor by soabase.
the class ExhibitorCreator method addInitialConfigFile.
private void addInitialConfigFile(CommandLine commandLine, Properties properties) throws IOException {
Properties defaultProperties = new Properties();
String defaultConfigFile = commandLine.getOptionValue(INITIAL_CONFIG_FILE);
if (defaultConfigFile == null) {
return;
}
InputStream in = new BufferedInputStream(new FileInputStream(defaultConfigFile));
try {
defaultProperties.load(in);
} finally {
CloseableUtils.closeQuietly(in);
}
Set<String> propertyNames = Sets.newHashSet();
for (StringConfigs config : StringConfigs.values()) {
propertyNames.add(PropertyBasedInstanceConfig.toName(config, ""));
}
for (IntConfigs config : IntConfigs.values()) {
propertyNames.add(PropertyBasedInstanceConfig.toName(config, ""));
}
for (String name : defaultProperties.stringPropertyNames()) {
if (propertyNames.contains(name)) {
String value = defaultProperties.getProperty(name);
properties.setProperty(PropertyBasedInstanceConfig.ROOT_PROPERTY_PREFIX + name, value);
} else {
log.warn("Ignoring unknown config: " + name);
}
}
}
Aggregations