Search in sources :

Example 1 with PropertyBasedInstanceConfig

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);
}
Also used : PropertyBasedInstanceConfig(com.netflix.exhibitor.core.config.PropertyBasedInstanceConfig) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) BufferedOutputStream(java.io.BufferedOutputStream) FileOutputStream(java.io.FileOutputStream) File(java.io.File) BufferedOutputStream(java.io.BufferedOutputStream) LoadedInstanceConfig(com.netflix.exhibitor.core.config.LoadedInstanceConfig)

Example 2 with PropertyBasedInstanceConfig

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);
}
Also used : Stat(org.apache.zookeeper.data.Stat) PropertyBasedInstanceConfig(com.netflix.exhibitor.core.config.PropertyBasedInstanceConfig) ByteArrayOutputStream(java.io.ByteArrayOutputStream) KeeperException(org.apache.zookeeper.KeeperException) LoadedInstanceConfig(com.netflix.exhibitor.core.config.LoadedInstanceConfig)

Example 3 with PropertyBasedInstanceConfig

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());
}
Also used : PropertyBasedInstanceConfig(com.netflix.exhibitor.core.config.PropertyBasedInstanceConfig) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ObjectMetadata(com.amazonaws.services.s3.model.ObjectMetadata) Date(java.util.Date) LoadedInstanceConfig(com.netflix.exhibitor.core.config.LoadedInstanceConfig)

Example 4 with PropertyBasedInstanceConfig

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();
}
Also used : PropertyBasedInstanceConfig(com.netflix.exhibitor.core.config.PropertyBasedInstanceConfig) DefaultProperties(com.netflix.exhibitor.core.config.DefaultProperties) Properties(java.util.Properties)

Example 5 with PropertyBasedInstanceConfig

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);
    }
}
Also used : CuratorFramework(org.apache.curator.framework.CuratorFramework) PathChildrenCacheListener(org.apache.curator.framework.recipes.cache.PathChildrenCacheListener) PathChildrenCacheEvent(org.apache.curator.framework.recipes.cache.PathChildrenCacheEvent) PropertyBasedInstanceConfig(com.netflix.exhibitor.core.config.PropertyBasedInstanceConfig) Semaphore(java.util.concurrent.Semaphore) Properties(java.util.Properties) LoadedInstanceConfig(com.netflix.exhibitor.core.config.LoadedInstanceConfig) Test(org.testng.annotations.Test)

Aggregations

PropertyBasedInstanceConfig (com.netflix.exhibitor.core.config.PropertyBasedInstanceConfig)12 LoadedInstanceConfig (com.netflix.exhibitor.core.config.LoadedInstanceConfig)11 Properties (java.util.Properties)8 File (java.io.File)4 BufferedOutputStream (java.io.BufferedOutputStream)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 FileOutputStream (java.io.FileOutputStream)2 OutputStream (java.io.OutputStream)2 RandomAccessFile (java.io.RandomAccessFile)2 FileLock (java.nio.channels.FileLock)2 Date (java.util.Date)2 Test (org.testng.annotations.Test)2 ObjectMetadata (com.amazonaws.services.s3.model.ObjectMetadata)1 S3Object (com.amazonaws.services.s3.model.S3Object)1 DefaultProperties (com.netflix.exhibitor.core.config.DefaultProperties)1 SessionInfo (com.orbitz.consul.model.session.SessionInfo)1 BufferedInputStream (java.io.BufferedInputStream)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 FileInputStream (java.io.FileInputStream)1 Semaphore (java.util.concurrent.Semaphore)1