use of com.netflix.exhibitor.core.config.LoadedInstanceConfig in project exhibitor by soabase.
the class TestFlexibleAutoInstanceManagement method testAdditionWithConfigContention.
@Test
public void testAdditionWithConfigContention() throws Exception {
MockExhibitorInstance mockExhibitorInstance = new MockExhibitorInstance("new");
mockExhibitorInstance.getMockConfigProvider().setConfig(StringConfigs.SERVERS_SPEC, "1:a,2:b,3:c");
mockExhibitorInstance.getMockConfigProvider().setConfig(IntConfigs.AUTO_MANAGE_INSTANCES, 1);
mockExhibitorInstance.getMockConfigProvider().setConfig(IntConfigs.AUTO_MANAGE_INSTANCES_SETTLING_PERIOD_MS, 0);
mockExhibitorInstance.getMockConfigProvider().setConfig(IntConfigs.AUTO_MANAGE_INSTANCES_FIXED_ENSEMBLE_SIZE, 0);
List<ServerStatus> statuses = Lists.newArrayList();
statuses.add(new ServerStatus("a", InstanceStateTypes.SERVING.getCode(), "", true));
statuses.add(new ServerStatus("b", InstanceStateTypes.SERVING.getCode(), "", false));
statuses.add(new ServerStatus("c", InstanceStateTypes.SERVING.getCode(), "", false));
Mockito.when(mockExhibitorInstance.getMockForkJoinPool().invoke(Mockito.isA(ClusterStatusTask.class))).thenReturn(statuses);
AutomaticInstanceManagement management = new AutomaticInstanceManagement(mockExhibitorInstance.getMockExhibitor());
LoadedInstanceConfig loadedInstanceConfig = mockExhibitorInstance.getMockExhibitor().getConfigManager().getLoadedInstanceConfig();
LoadedInstanceConfig changedCoadedInstanceConfig = new LoadedInstanceConfig(loadedInstanceConfig.getConfig(), loadedInstanceConfig.getVersion() + 1);
mockExhibitorInstance.getMockExhibitor().getConfigManager().testingSetLoadedInstanceConfig(changedCoadedInstanceConfig);
management.call();
// instance addition should have failed
Assert.assertEquals(mockExhibitorInstance.getMockExhibitor().getConfigManager().getConfig().getString(StringConfigs.SERVERS_SPEC), "1:a,2:b,3:c");
}
use of com.netflix.exhibitor.core.config.LoadedInstanceConfig 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.LoadedInstanceConfig 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.LoadedInstanceConfig 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.LoadedInstanceConfig 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