use of com.netflix.exhibitor.core.config.PropertyBasedInstanceConfig in project exhibitor by soabase.
the class TestZookeeperConfigProvider method testBasic.
@Test
public void testBasic() throws Exception {
ZookeeperConfigProvider config = new ZookeeperConfigProvider(client, "/foo", new Properties(), "foo");
try {
config.start();
// make sure there's no exception
config.loadConfig();
Properties properties = new Properties();
properties.setProperty(PropertyBasedInstanceConfig.toName(StringConfigs.ZOO_CFG_EXTRA, PropertyBasedInstanceConfig.ROOT_PROPERTY_PREFIX), "1,2,3");
config.storeConfig(new PropertyBasedInstanceConfig(properties, new Properties()), 0);
timing.sleepABit();
LoadedInstanceConfig instanceConfig = config.loadConfig();
Assert.assertEquals("1,2,3", instanceConfig.getConfig().getRootConfig().getString(StringConfigs.ZOO_CFG_EXTRA));
} finally {
CloseableUtils.closeQuietly(config);
}
}
use of com.netflix.exhibitor.core.config.PropertyBasedInstanceConfig in project exhibitor by soabase.
the class FileSystemConfigProvider method storeConfig.
@Override
public LoadedInstanceConfig storeConfig(ConfigCollection config, long compareVersion) throws Exception {
File propertiesFile = new File(propertiesDirectory, propertyFileName);
if (propertiesFile.lastModified() != compareVersion) {
return null;
}
PropertyBasedInstanceConfig propertyBasedInstanceConfig = new PropertyBasedInstanceConfig(config);
long lastModified = 0;
FileOutputStream fileStream = new FileOutputStream(propertiesFile);
OutputStream out = new BufferedOutputStream(fileStream);
try {
FileLock lock = fileStream.getChannel().lock();
try {
propertyBasedInstanceConfig.getProperties().store(out, "Auto-generated by Exhibitor");
lastModified = propertiesFile.lastModified();
} finally {
lock.release();
}
} finally {
CloseableUtils.closeQuietly(out);
}
return new LoadedInstanceConfig(propertyBasedInstanceConfig, lastModified);
}
use of com.netflix.exhibitor.core.config.PropertyBasedInstanceConfig in project exhibitor by soabase.
the class FileSystemConfigProvider method loadConfig.
@Override
public LoadedInstanceConfig loadConfig() throws Exception {
File propertiesFile = new File(propertiesDirectory, propertyFileName);
Properties properties = new Properties();
if (propertiesFile.exists()) {
RandomAccessFile raf = new RandomAccessFile(propertiesFile, "rw");
try {
FileLock lock = raf.getChannel().lock();
try {
properties.load(Channels.newInputStream(raf.getChannel()));
} finally {
lock.release();
}
} finally {
CloseableUtils.closeQuietly(raf);
}
}
PropertyBasedInstanceConfig config = new PropertyBasedInstanceConfig(properties, defaults);
return new LoadedInstanceConfig(config, propertiesFile.lastModified());
}
use of com.netflix.exhibitor.core.config.PropertyBasedInstanceConfig in project exhibitor by soabase.
the class NoneConfigProvider method loadConfig.
@Override
public LoadedInstanceConfig loadConfig() throws Exception {
File propertiesFile = new File(directory, FILE_NAME);
Properties properties = new Properties();
if (propertiesFile.exists()) {
BufferedInputStream in = new BufferedInputStream(new FileInputStream(propertiesFile));
try {
properties.load(in);
} finally {
CloseableUtils.closeQuietly(in);
}
}
PropertyBasedInstanceConfig config = new PropertyBasedInstanceConfig(properties, defaultProperties);
return new LoadedInstanceConfig(config, propertiesFile.lastModified());
}
use of com.netflix.exhibitor.core.config.PropertyBasedInstanceConfig in project exhibitor by soabase.
the class S3ConfigProvider method loadConfig.
@Override
public LoadedInstanceConfig loadConfig() throws Exception {
Date lastModified;
Properties properties = new Properties();
S3Object object = getConfigObject();
if (object != null) {
try {
lastModified = object.getObjectMetadata().getLastModified();
properties.load(object.getObjectContent());
} finally {
CloseableUtils.closeQuietly(object.getObjectContent());
}
} else {
lastModified = new Date(0L);
}
PropertyBasedInstanceConfig config = new PropertyBasedInstanceConfig(properties, defaults);
return new LoadedInstanceConfig(config, lastModified.getTime());
}
Aggregations