Search in sources :

Example 6 with PropertyBasedInstanceConfig

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

Example 7 with PropertyBasedInstanceConfig

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

Example 8 with PropertyBasedInstanceConfig

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());
}
Also used : RandomAccessFile(java.io.RandomAccessFile) PropertyBasedInstanceConfig(com.netflix.exhibitor.core.config.PropertyBasedInstanceConfig) FileLock(java.nio.channels.FileLock) Properties(java.util.Properties) RandomAccessFile(java.io.RandomAccessFile) File(java.io.File) LoadedInstanceConfig(com.netflix.exhibitor.core.config.LoadedInstanceConfig)

Example 9 with PropertyBasedInstanceConfig

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

Example 10 with PropertyBasedInstanceConfig

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

Aggregations

PropertyBasedInstanceConfig (com.netflix.exhibitor.core.config.PropertyBasedInstanceConfig)11 LoadedInstanceConfig (com.netflix.exhibitor.core.config.LoadedInstanceConfig)10 Properties (java.util.Properties)7 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 BufferedInputStream (java.io.BufferedInputStream)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 FileInputStream (java.io.FileInputStream)1 Semaphore (java.util.concurrent.Semaphore)1 CuratorFramework (org.apache.curator.framework.CuratorFramework)1