Search in sources :

Example 6 with PropertyStoreException

use of com.linkedin.d2.discovery.stores.PropertyStoreException 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<T>(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<T>(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 7 with PropertyStoreException

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

the class LoadBalancerClientCli method printStores.

public static String printStores(ZKConnection zkclient, String zkserver, String d2path) throws IOException, IllegalStateException, URISyntaxException, PropertyStoreException, Exception {
    int serviceCount = 0;
    String zkstr = "\nZKServer:" + zkserver;
    StringBuilder sb = new StringBuilder();
    Set<String> currentservices = new HashSet<String>();
    Map<String, ZooKeeperPermanentStore<ServiceProperties>> zkServiceRegistryMap = new HashMap<String, ZooKeeperPermanentStore<ServiceProperties>>();
    Map<String, List<String>> servicesGroupMap = new HashMap<String, List<String>>();
    // zk stores
    String clstoreString = zkserver + ZKFSUtil.clusterPath(d2path);
    String uristoreString = zkserver + ZKFSUtil.uriPath(d2path);
    ZooKeeperPermanentStore<ClusterProperties> zkClusterRegistry = (ZooKeeperPermanentStore<ClusterProperties>) getStore(zkclient, clstoreString, new ClusterPropertiesJsonSerializer());
    ZooKeeperEphemeralStore<UriProperties> zkUriRegistry = (ZooKeeperEphemeralStore<UriProperties>) getEphemeralStore(zkclient, uristoreString, new UriPropertiesJsonSerializer(), new UriPropertiesMerger());
    List<String> currentclusters = zkClusterRegistry.ls();
    List<String> currenturis = zkUriRegistry.ls();
    List<String> servicesGroups = getServicesGroups(zkclient, d2path);
    for (String serviceGroup : servicesGroups) {
        String scstoreString = zkserver + ZKFSUtil.servicePath(d2path, serviceGroup);
        ZooKeeperPermanentStore<ServiceProperties> zkServiceRegistry = (ZooKeeperPermanentStore<ServiceProperties>) getStore(zkclient, scstoreString, new ServicePropertiesJsonSerializer());
        zkServiceRegistryMap.put(serviceGroup, zkServiceRegistry);
        List<String> services = zkServiceRegistry.ls();
        currentservices.addAll(services);
        servicesGroupMap.put(serviceGroup, services);
        serviceCount += services.size();
    }
    sb.append(zkstr);
    sb.append(" Total Clusters:");
    sb.append(currentclusters.size());
    sb.append(zkstr);
    sb.append(" Total Services:");
    sb.append(serviceCount);
    sb.append(zkstr);
    sb.append(" Total URIs:");
    sb.append(currenturis.size());
    sb.append("\n============================================================");
    sb.append("\nSERVICE GROUPS");
    for (String serviceGroup : servicesGroupMap.keySet()) {
        sb.append("\nGROUP:" + serviceGroup + "           Services:" + servicesGroupMap.get(serviceGroup));
    }
    for (String cluster : currentclusters) {
        int count = 0;
        sb.append("\n============================================================");
        sb.append("\nCLUSTER '");
        sb.append(cluster);
        sb.append("':");
        for (String service : currentservices) {
            for (String serviceGroup : servicesGroupMap.keySet()) {
                ZooKeeperPermanentStore<ServiceProperties> zkStorePropsForSerivceGroup = zkServiceRegistryMap.get(serviceGroup);
                if (zkStorePropsForSerivceGroup != null) {
                    ServiceProperties serviceProps = zkStorePropsForSerivceGroup.get(service);
                    if (serviceProps != null) {
                        if (cluster.equals(serviceProps.getClusterName())) {
                            sb.append("\n-------------------");
                            sb.append("\nSERVICE '" + service + "':");
                            sb.append(printStore(zkClusterRegistry, zkUriRegistry, zkServiceRegistryMap.get(serviceGroup), cluster, service));
                            count++;
                            break;
                        }
                    }
                }
            }
        }
        if (count == 0) {
            sb.append(printStore(zkClusterRegistry, zkUriRegistry, cluster));
            sb.append("\nNo services were found in this cluster.");
        }
    }
    return sb.toString();
}
Also used : HashMap(java.util.HashMap) ServicePropertiesJsonSerializer(com.linkedin.d2.balancer.properties.ServicePropertiesJsonSerializer) ZooKeeperPermanentStore(com.linkedin.d2.discovery.stores.zk.ZooKeeperPermanentStore) UriPropertiesMerger(com.linkedin.d2.balancer.properties.UriPropertiesMerger) ZooKeeperEphemeralStore(com.linkedin.d2.discovery.stores.zk.ZooKeeperEphemeralStore) UriPropertiesJsonSerializer(com.linkedin.d2.balancer.properties.UriPropertiesJsonSerializer) ServiceProperties(com.linkedin.d2.balancer.properties.ServiceProperties) ClusterPropertiesJsonSerializer(com.linkedin.d2.balancer.properties.ClusterPropertiesJsonSerializer) UriProperties(com.linkedin.d2.balancer.properties.UriProperties) ClusterProperties(com.linkedin.d2.balancer.properties.ClusterProperties) List(java.util.List) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet)

Example 8 with PropertyStoreException

use of com.linkedin.d2.discovery.stores.PropertyStoreException 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<T>(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<T>(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 9 with PropertyStoreException

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

the class ZooKeeperAnnouncerJmx method markDown.

@Override
public void markDown() throws PropertyStoreException {
    FutureCallback<None> callback = new FutureCallback<None>();
    _announcer.markDown(callback);
    try {
        callback.get(10, TimeUnit.SECONDS);
    } catch (Exception e) {
        throw new PropertyStoreException(e);
    }
}
Also used : PropertyStoreException(com.linkedin.d2.discovery.stores.PropertyStoreException) None(com.linkedin.common.util.None) FutureCallback(com.linkedin.common.callback.FutureCallback) IOException(java.io.IOException) PropertyStoreException(com.linkedin.d2.discovery.stores.PropertyStoreException)

Example 10 with PropertyStoreException

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

the class ZooKeeperAnnouncerJmx method reset.

@Override
public void reset() throws PropertyStoreException {
    FutureCallback<None> callback = new FutureCallback<None>();
    _announcer.reset(callback);
    try {
        callback.get(10, TimeUnit.SECONDS);
    } catch (Exception e) {
        throw new PropertyStoreException(e);
    }
}
Also used : PropertyStoreException(com.linkedin.d2.discovery.stores.PropertyStoreException) None(com.linkedin.common.util.None) FutureCallback(com.linkedin.common.callback.FutureCallback) IOException(java.io.IOException) PropertyStoreException(com.linkedin.d2.discovery.stores.PropertyStoreException)

Aggregations

None (com.linkedin.common.util.None)19 FutureCallback (com.linkedin.common.callback.FutureCallback)18 HashMap (java.util.HashMap)18 UriProperties (com.linkedin.d2.balancer.properties.UriProperties)15 Test (org.testng.annotations.Test)14 PartitionData (com.linkedin.d2.balancer.properties.PartitionData)9 PropertyStoreException (com.linkedin.d2.discovery.stores.PropertyStoreException)9 ServiceProperties (com.linkedin.d2.balancer.properties.ServiceProperties)8 URI (java.net.URI)8 ClusterProperties (com.linkedin.d2.balancer.properties.ClusterProperties)7 ServicePropertiesJsonSerializer (com.linkedin.d2.balancer.properties.ServicePropertiesJsonSerializer)7 UriPropertiesJsonSerializer (com.linkedin.d2.balancer.properties.UriPropertiesJsonSerializer)7 UriPropertiesMerger (com.linkedin.d2.balancer.properties.UriPropertiesMerger)7 IOException (java.io.IOException)7 HashSet (java.util.HashSet)6 PropertyEventBusImpl (com.linkedin.d2.discovery.event.PropertyEventBusImpl)5 ZooKeeperEphemeralStore (com.linkedin.d2.discovery.stores.zk.ZooKeeperEphemeralStore)5 ExecutionException (java.util.concurrent.ExecutionException)5 ClusterPropertiesJsonSerializer (com.linkedin.d2.balancer.properties.ClusterPropertiesJsonSerializer)4 PropertyStringSerializer (com.linkedin.d2.discovery.stores.PropertyStringSerializer)4