use of com.netflix.exhibitor.core.config.PropertyBasedInstanceConfig in project exhibitor by soabase.
the class NoneConfigProvider method storeConfig.
@Override
public LoadedInstanceConfig storeConfig(ConfigCollection config, long compareVersion) throws Exception {
File propertiesFile = new File(directory, FILE_NAME);
PropertyBasedInstanceConfig propertyBasedInstanceConfig = new PropertyBasedInstanceConfig(config);
long lastModified = 0;
OutputStream out = new BufferedOutputStream(new FileOutputStream(propertiesFile));
try {
propertyBasedInstanceConfig.getProperties().store(out, "Auto-generated by Exhibitor");
lastModified = propertiesFile.lastModified();
} finally {
CloseableUtils.closeQuietly(out);
}
return new LoadedInstanceConfig(propertyBasedInstanceConfig, lastModified);
}
use of com.netflix.exhibitor.core.config.PropertyBasedInstanceConfig in project exhibitor by soabase.
the class ZookeeperConfigProvider method storeConfig.
@Override
public LoadedInstanceConfig storeConfig(ConfigCollection config, long compareVersion) throws Exception {
PropertyBasedInstanceConfig propertyBasedInstanceConfig = new PropertyBasedInstanceConfig(config);
ByteArrayOutputStream out = new ByteArrayOutputStream();
propertyBasedInstanceConfig.getProperties().store(out, "Auto-generated by Exhibitor " + hostname);
byte[] bytes = out.toByteArray();
int newVersion;
try {
Stat stat = client.setData().withVersion((int) compareVersion).forPath(ZKPaths.makePath(configPath, CONFIG_NODE_NAME), bytes);
newVersion = stat.getVersion();
} catch (KeeperException.BadVersionException e) {
// another process got in first
return null;
} catch (KeeperException.NoNodeException e) {
try {
client.create().creatingParentsIfNeeded().forPath(ZKPaths.makePath(configPath, CONFIG_NODE_NAME), bytes);
newVersion = 0;
} catch (KeeperException.NodeExistsException e1) {
// by implication, another process created the node first
return null;
}
}
return new LoadedInstanceConfig(propertyBasedInstanceConfig, newVersion);
}
use of com.netflix.exhibitor.core.config.PropertyBasedInstanceConfig in project exhibitor by soabase.
the class S3ConfigProvider method storeConfig.
@Override
public LoadedInstanceConfig storeConfig(ConfigCollection config, long compareVersion) throws Exception {
{
ObjectMetadata metadata = getConfigMetadata();
if (metadata != null) {
Date lastModified = metadata.getLastModified();
if (lastModified.getTime() != compareVersion) {
// apparently there's no atomic way to do this with S3 so this will have to do
return null;
}
}
}
PropertyBasedInstanceConfig propertyBasedInstanceConfig = new PropertyBasedInstanceConfig(config);
ByteArrayOutputStream out = new ByteArrayOutputStream();
propertyBasedInstanceConfig.getProperties().store(out, "Auto-generated by Exhibitor " + hostname);
byte[] bytes = out.toByteArray();
ObjectMetadata metadata = S3Utils.simpleUploadFile(s3Client, bytes, arguments.getBucket(), arguments.getKey());
return new LoadedInstanceConfig(propertyBasedInstanceConfig, metadata.getLastModified().getTime());
}
use of com.netflix.exhibitor.core.config.PropertyBasedInstanceConfig in project exhibitor by soabase.
the class ExhibitorCreator method makeDefaultProperties.
private Properties makeDefaultProperties(CommandLine commandLine, BackupProvider backupProvider) throws IOException {
Properties properties = new Properties();
// put in standard defaults first
properties.putAll(DefaultProperties.get(backupProvider));
addInitialConfigFile(commandLine, properties);
return new PropertyBasedInstanceConfig(properties, new Properties()).getProperties();
}
use of com.netflix.exhibitor.core.config.PropertyBasedInstanceConfig in project exhibitor by soabase.
the class TestZookeeperConfigProvider method testConcurrentModification.
@Test
public void testConcurrentModification() throws Exception {
ZookeeperConfigProvider config1 = new ZookeeperConfigProvider(client, "/foo", new Properties(), "foo");
ZookeeperConfigProvider config2 = new ZookeeperConfigProvider(client, "/foo", new Properties(), "foo");
try {
config1.start();
config2.start();
final Semaphore cacheUpdate2 = new Semaphore(0);
config2.getPathChildrenCache().getListenable().addListener(new PathChildrenCacheListener() {
@Override
public void childEvent(CuratorFramework client, PathChildrenCacheEvent event) throws Exception {
cacheUpdate2.release();
}
});
Properties properties = new Properties();
properties.setProperty(PropertyBasedInstanceConfig.toName(StringConfigs.ZOO_CFG_EXTRA, PropertyBasedInstanceConfig.ROOT_PROPERTY_PREFIX), "1,2,3");
LoadedInstanceConfig loaded1 = config1.storeConfig(new PropertyBasedInstanceConfig(properties, new Properties()), -1);
Assert.assertTrue(timing.acquireSemaphore(cacheUpdate2));
timing.sleepABit();
LoadedInstanceConfig loaded2 = config2.loadConfig();
Assert.assertEquals("1,2,3", loaded2.getConfig().getRootConfig().getString(StringConfigs.ZOO_CFG_EXTRA));
properties.setProperty(PropertyBasedInstanceConfig.toName(StringConfigs.ZOO_CFG_EXTRA, PropertyBasedInstanceConfig.ROOT_PROPERTY_PREFIX), "4,5,6");
config2.storeConfig(new PropertyBasedInstanceConfig(properties, new Properties()), loaded2.getVersion());
Assert.assertNull(config1.storeConfig(new PropertyBasedInstanceConfig(properties, new Properties()), loaded1.getVersion()));
LoadedInstanceConfig newLoaded1 = config1.loadConfig();
Assert.assertNotEquals(loaded1.getVersion(), newLoaded1.getVersion());
} finally {
CloseableUtils.closeQuietly(config2);
CloseableUtils.closeQuietly(config1);
}
}
Aggregations