Search in sources :

Example 1 with PropertyStore

use of com.linkedin.d2.discovery.stores.PropertyStore in project rest.li by linkedin.

the class LoadBalancerClientCli method getStore.

public static <T> PropertyStore<T> getStore(ZKConnection zkclient, String store, PropertySerializer<T> serializer) throws URISyntaxException, IOException, PropertyStoreException {
    URI storeUri = URI.create(store);
    if (storeUri.getScheme() != null) {
        if (storeUri.getScheme().equals("zk")) {
            ZooKeeperPermanentStore<T> zkStore = new ZooKeeperPermanentStore<>(zkclient, serializer, storeUri.getPath());
            startStore(zkStore);
            return zkStore;
        } else {
            throw new URISyntaxException(store, "Unable to parse store uri. Only zk and file stores are supported.");
        }
    } else {
        // assume it's a local file
        return new FileStore<>(storeUri.getPath(), ".json", serializer);
    }
}
Also used : FileStore(com.linkedin.d2.discovery.stores.file.FileStore) ZooKeeperPermanentStore(com.linkedin.d2.discovery.stores.zk.ZooKeeperPermanentStore) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI)

Example 2 with PropertyStore

use of com.linkedin.d2.discovery.stores.PropertyStore in project rest.li by linkedin.

the class LoadBalancerClientCli method getEphemeralStore.

public static <T> PropertyStore<T> getEphemeralStore(ZKConnection zkclient, String store, PropertySerializer<T> serializer, ZooKeeperPropertyMerger<T> merger) throws URISyntaxException, IOException, PropertyStoreException {
    URI storeUri = URI.create(store);
    if (storeUri.getScheme() != null) {
        if (storeUri.getScheme().equals("zk")) {
            ZooKeeperEphemeralStore<T> zkStore = new ZooKeeperEphemeralStore<>(zkclient, serializer, merger, storeUri.getPath());
            startStore(zkStore);
            return zkStore;
        } else {
            throw new URISyntaxException(store, "Unable to parse store uri. Only zk and file stores are supported.");
        }
    } else {
        // assume it's a local file
        return new FileStore<>(storeUri.getPath(), ".json", serializer);
    }
}
Also used : FileStore(com.linkedin.d2.discovery.stores.file.FileStore) URISyntaxException(java.net.URISyntaxException) ZooKeeperEphemeralStore(com.linkedin.d2.discovery.stores.zk.ZooKeeperEphemeralStore) URI(java.net.URI)

Example 3 with PropertyStore

use of com.linkedin.d2.discovery.stores.PropertyStore in project rest.li by linkedin.

the class R2D2Server method putService.

private void putService(ServiceProperties serviceProperties) throws Exception {
    System.err.println("put: " + serviceProperties);
    ZKConnection client = new ZKConnection(_zookeeperHost + ":" + _zookeeperPort, 30000);
    PropertyStore<ServiceProperties> store = new ZooKeeperPermanentStore<>(client, new ServicePropertiesJsonSerializer(), _basePath + "/services");
    store.put(serviceProperties.getServiceName(), serviceProperties);
    client.getZooKeeper().close();
}
Also used : ServiceProperties(com.linkedin.d2.balancer.properties.ServiceProperties) ZKConnection(com.linkedin.d2.discovery.stores.zk.ZKConnection) ServicePropertiesJsonSerializer(com.linkedin.d2.balancer.properties.ServicePropertiesJsonSerializer) ZooKeeperPermanentStore(com.linkedin.d2.discovery.stores.zk.ZooKeeperPermanentStore)

Example 4 with PropertyStore

use of com.linkedin.d2.discovery.stores.PropertyStore in project rest.li by linkedin.

the class R2D2Server method putCluster.

private void putCluster(ClusterProperties clusterProperties) throws Exception {
    System.err.println("put: " + clusterProperties);
    ZKConnection client = new ZKConnection(_zookeeperHost + ":" + _zookeeperPort, 30000);
    PropertyStore<ClusterProperties> store = new ZooKeeperPermanentStore<>(client, new ClusterPropertiesJsonSerializer(), _basePath + "/clusters");
    store.put(clusterProperties.getClusterName(), clusterProperties);
    client.getZooKeeper().close();
}
Also used : ZKConnection(com.linkedin.d2.discovery.stores.zk.ZKConnection) ClusterPropertiesJsonSerializer(com.linkedin.d2.balancer.properties.ClusterPropertiesJsonSerializer) ZooKeeperPermanentStore(com.linkedin.d2.discovery.stores.zk.ZooKeeperPermanentStore) ClusterProperties(com.linkedin.d2.balancer.properties.ClusterProperties)

Example 5 with PropertyStore

use of com.linkedin.d2.discovery.stores.PropertyStore in project rest.li by linkedin.

the class ZooKeeperPermanentStoreTest method getStore.

@Override
public PropertyStore<String> getStore() throws PropertyStoreException {
    try {
        ZKConnection client = new ZKConnection("localhost:" + PORT, 30000);
        client.start();
        ZooKeeperPermanentStore<String> store = new ZooKeeperPermanentStore<>(client, new PropertyStringSerializer(), "/test-path");
        FutureCallback<None> callback = new FutureCallback<>();
        store.start(callback);
        callback.get();
        return store;
    } catch (Exception e) {
        throw new PropertyStoreException(e);
    }
}
Also used : PropertyStoreException(com.linkedin.d2.discovery.stores.PropertyStoreException) None(com.linkedin.common.util.None) PropertyStringSerializer(com.linkedin.d2.discovery.stores.PropertyStringSerializer) FutureCallback(com.linkedin.common.callback.FutureCallback) IOException(java.io.IOException) PropertyStoreException(com.linkedin.d2.discovery.stores.PropertyStoreException)

Aggregations

PropertyEventShutdownCallback (com.linkedin.d2.discovery.event.PropertyEventThread.PropertyEventShutdownCallback)3 ZooKeeperPermanentStore (com.linkedin.d2.discovery.stores.zk.ZooKeeperPermanentStore)3 URISyntaxException (java.net.URISyntaxException)3 CountDownLatch (java.util.concurrent.CountDownLatch)3 FutureCallback (com.linkedin.common.callback.FutureCallback)2 None (com.linkedin.common.util.None)2 PropertyStoreException (com.linkedin.d2.discovery.stores.PropertyStoreException)2 FileStore (com.linkedin.d2.discovery.stores.file.FileStore)2 ZKConnection (com.linkedin.d2.discovery.stores.zk.ZKConnection)2 IOException (java.io.IOException)2 URI (java.net.URI)2 Test (org.testng.annotations.Test)2 ClusterProperties (com.linkedin.d2.balancer.properties.ClusterProperties)1 ClusterPropertiesJsonSerializer (com.linkedin.d2.balancer.properties.ClusterPropertiesJsonSerializer)1 ServiceProperties (com.linkedin.d2.balancer.properties.ServiceProperties)1 ServicePropertiesJsonSerializer (com.linkedin.d2.balancer.properties.ServicePropertiesJsonSerializer)1 PropertyStringSerializer (com.linkedin.d2.discovery.stores.PropertyStringSerializer)1 ZooKeeperEphemeralStore (com.linkedin.d2.discovery.stores.zk.ZooKeeperEphemeralStore)1 ExecutionException (java.util.concurrent.ExecutionException)1 TimeoutException (java.util.concurrent.TimeoutException)1