Search in sources :

Example 1 with ServicePropertiesJsonSerializer

use of com.linkedin.d2.balancer.properties.ServicePropertiesJsonSerializer in project rest.li by linkedin.

the class LoadBalancerClientCli method getServiceClustersURIsInfo.

public Map<String, UriProperties> getServiceClustersURIsInfo(String zkserver, String d2path, String serviceName) throws IOException, IllegalStateException, URISyntaxException, PropertyStoreException {
    Map<String, UriProperties> map = new HashMap<>();
    // zk stores
    String scstoreString = zkserver + ZKFSUtil.servicePath(d2path);
    String uristoreString = zkserver + ZKFSUtil.uriPath(d2path);
    ZooKeeperPermanentStore<ServiceProperties> zkServiceRegistry = (ZooKeeperPermanentStore<ServiceProperties>) getStore(_zkclient, scstoreString, new ServicePropertiesJsonSerializer());
    ZooKeeperEphemeralStore<UriProperties> zkUriRegistry = (ZooKeeperEphemeralStore<UriProperties>) getEphemeralStore(_zkclient, uristoreString, new UriPropertiesJsonSerializer(), new UriPropertiesMerger());
    List<String> currentservices = zkServiceRegistry.ls();
    for (String service : currentservices) {
        if (service.equals(serviceName)) {
            String clusterName = zkServiceRegistry.get(serviceName).getClusterName();
            UriProperties uripros = zkUriRegistry.get(clusterName);
            map.put(clusterName, uripros);
        }
    }
    return map;
}
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) UriProperties(com.linkedin.d2.balancer.properties.UriProperties)

Example 2 with ServicePropertiesJsonSerializer

use of com.linkedin.d2.balancer.properties.ServicePropertiesJsonSerializer in project rest.li by linkedin.

the class LoadBalancerClientCli method printStore.

public static String printStore(ZKConnection zkclient, String zkserver, String d2path, String cluster, String service, String serviceGroup) throws URISyntaxException, IOException, PropertyStoreException {
    StringBuilder sb = new StringBuilder();
    ZooKeeperPermanentStore<ClusterProperties> zkClusterRegistry = null;
    ZooKeeperPermanentStore<ServiceProperties> zkServiceRegistry = null;
    ZooKeeperEphemeralStore<UriProperties> zkUriRegistry = null;
    String clstoreString = zkserver + ZKFSUtil.clusterPath(d2path);
    String uristoreString = zkserver + ZKFSUtil.uriPath(d2path);
    zkClusterRegistry = (ZooKeeperPermanentStore<ClusterProperties>) getStore(zkclient, clstoreString, new ClusterPropertiesJsonSerializer());
    zkUriRegistry = (ZooKeeperEphemeralStore<UriProperties>) getEphemeralStore(zkclient, uristoreString, new UriPropertiesJsonSerializer(), new UriPropertiesMerger());
    if (serviceGroup != null) {
        String scstoreString = zkserver + ZKFSUtil.servicePath(d2path, serviceGroup);
        zkServiceRegistry = (ZooKeeperPermanentStore<ServiceProperties>) getStore(zkclient, scstoreString, new ServicePropertiesJsonSerializer());
    } else {
        String scstoreString = zkserver + ZKFSUtil.servicePath(d2path);
        zkServiceRegistry = (ZooKeeperPermanentStore<ServiceProperties>) getStore(zkclient, scstoreString, new ServicePropertiesJsonSerializer());
    }
    sb.append(printStore(zkClusterRegistry, zkUriRegistry, cluster));
    if (zkServiceRegistry.get(service).getClusterName().equals(cluster)) {
        sb.append(printService(zkServiceRegistry, service));
    }
    return sb.toString();
}
Also used : UriPropertiesJsonSerializer(com.linkedin.d2.balancer.properties.UriPropertiesJsonSerializer) ServiceProperties(com.linkedin.d2.balancer.properties.ServiceProperties) ClusterPropertiesJsonSerializer(com.linkedin.d2.balancer.properties.ClusterPropertiesJsonSerializer) ServicePropertiesJsonSerializer(com.linkedin.d2.balancer.properties.ServicePropertiesJsonSerializer) UriProperties(com.linkedin.d2.balancer.properties.UriProperties) ClusterProperties(com.linkedin.d2.balancer.properties.ClusterProperties) UriPropertiesMerger(com.linkedin.d2.balancer.properties.UriPropertiesMerger)

Example 3 with ServicePropertiesJsonSerializer

use of com.linkedin.d2.balancer.properties.ServicePropertiesJsonSerializer in project rest.li by linkedin.

the class LoadBalancerClientCli method getServiceURIsProps.

public Set<UriProperties> getServiceURIsProps(String zkserver, String d2path, String serviceName) throws IOException, IllegalStateException, URISyntaxException, PropertyStoreException {
    Set<UriProperties> uriprops = new HashSet<>();
    // zk stores
    String scstoreString = zkserver + ZKFSUtil.servicePath(d2path);
    String uristoreString = zkserver + ZKFSUtil.uriPath(d2path);
    ZooKeeperPermanentStore<ServiceProperties> zkServiceRegistry = (ZooKeeperPermanentStore<ServiceProperties>) getStore(_zkclient, scstoreString, new ServicePropertiesJsonSerializer());
    ZooKeeperEphemeralStore<UriProperties> zkUriRegistry = (ZooKeeperEphemeralStore<UriProperties>) getEphemeralStore(_zkclient, uristoreString, new UriPropertiesJsonSerializer(), new UriPropertiesMerger());
    String clusterName = zkServiceRegistry.get(serviceName).getClusterName();
    UriProperties uripros = zkUriRegistry.get(clusterName);
    uriprops.add(uripros);
    return uriprops;
}
Also used : UriPropertiesJsonSerializer(com.linkedin.d2.balancer.properties.UriPropertiesJsonSerializer) ServiceProperties(com.linkedin.d2.balancer.properties.ServiceProperties) ServicePropertiesJsonSerializer(com.linkedin.d2.balancer.properties.ServicePropertiesJsonSerializer) UriProperties(com.linkedin.d2.balancer.properties.UriProperties) ZooKeeperPermanentStore(com.linkedin.d2.discovery.stores.zk.ZooKeeperPermanentStore) UriPropertiesMerger(com.linkedin.d2.balancer.properties.UriPropertiesMerger) ZooKeeperEphemeralStore(com.linkedin.d2.discovery.stores.zk.ZooKeeperEphemeralStore) HashSet(java.util.HashSet)

Example 4 with ServicePropertiesJsonSerializer

use of com.linkedin.d2.balancer.properties.ServicePropertiesJsonSerializer 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<>();
    Map<String, ZooKeeperPermanentStore<ServiceProperties>> zkServiceRegistryMap = new HashMap<>();
    Map<String, List<String>> servicesGroupMap = new HashMap<>();
    // 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 5 with ServicePropertiesJsonSerializer

use of com.linkedin.d2.balancer.properties.ServicePropertiesJsonSerializer in project rest.li by linkedin.

the class ZKFSTogglingLoadBalancerFactoryImpl method createLoadBalancer.

@Override
public TogglingLoadBalancer createLoadBalancer(ZKConnection zkConnection, ScheduledExecutorService executorService) {
    _log.info("Using d2ServicePath: " + _d2ServicePath);
    ZooKeeperPermanentStore<ClusterProperties> zkClusterRegistry = createPermanentStore(zkConnection, ZKFSUtil.clusterPath(_baseZKPath), new ClusterPropertiesJsonSerializer(), executorService, _zookeeperReadWindowMs);
    _d2ClientJmxManager.setZkClusterRegistry(zkClusterRegistry);
    ZooKeeperPermanentStore<ServiceProperties> zkServiceRegistry = createPermanentStore(zkConnection, ZKFSUtil.servicePath(_baseZKPath, _d2ServicePath), new ServicePropertiesJsonSerializer(_clientServicesConfig), executorService, _zookeeperReadWindowMs);
    _d2ClientJmxManager.setZkServiceRegistry(zkServiceRegistry);
    String backupStoreFilePath = null;
    if (_enableSaveUriDataOnDisk) {
        backupStoreFilePath = _fsd2DirPath + File.separator + "urisValues";
    }
    ZooKeeperEphemeralStore<UriProperties> zkUriRegistry = createEphemeralStore(zkConnection, ZKFSUtil.uriPath(_baseZKPath), new UriPropertiesJsonSerializer(), new UriPropertiesMerger(), _useNewEphemeralStoreWatcher, backupStoreFilePath, executorService, _zookeeperReadWindowMs);
    _d2ClientJmxManager.setZkUriRegistry(zkUriRegistry);
    FileStore<ClusterProperties> fsClusterStore = createFileStore(FileSystemDirectory.getClusterDirectory(_fsd2DirPath), new ClusterPropertiesJsonSerializer());
    _d2ClientJmxManager.setFsClusterStore(fsClusterStore);
    FileStore<ServiceProperties> fsServiceStore = createFileStore(FileSystemDirectory.getServiceDirectory(_fsd2DirPath, _d2ServicePath), new ServicePropertiesJsonSerializer());
    _d2ClientJmxManager.setFsServiceStore(fsServiceStore);
    FileStore<UriProperties> fsUriStore = createFileStore(_fsd2DirPath + File.separator + "uris", new UriPropertiesJsonSerializer());
    _d2ClientJmxManager.setFsUriStore(fsUriStore);
    PropertyEventBus<ClusterProperties> clusterBus = new PropertyEventBusImpl<>(executorService);
    PropertyEventBus<ServiceProperties> serviceBus = new PropertyEventBusImpl<>(executorService);
    PropertyEventBus<UriProperties> uriBus = new PropertyEventBusImpl<>(executorService);
    // This ensures the filesystem store receives the events from the event bus so that
    // it can keep a local backup.
    clusterBus.register(fsClusterStore);
    serviceBus.register(fsServiceStore);
    uriBus.register(fsUriStore);
    TogglingPublisher<ClusterProperties> clusterToggle = _factory.createClusterToggle(zkClusterRegistry, fsClusterStore, clusterBus);
    TogglingPublisher<ServiceProperties> serviceToggle = _factory.createServiceToggle(zkServiceRegistry, fsServiceStore, serviceBus);
    TogglingPublisher<UriProperties> uriToggle = _factory.createUriToggle(zkUriRegistry, fsUriStore, uriBus);
    SimpleLoadBalancerState state = new SimpleLoadBalancerState(executorService, uriBus, clusterBus, serviceBus, _clientFactories, _loadBalancerStrategyFactories, _sslContext, _sslParameters, _isSSLEnabled, _partitionAccessorRegistry, _sslSessionValidatorFactory, _deterministicSubsettingMetadataProvider);
    _d2ClientJmxManager.setSimpleLoadBalancerState(state);
    SimpleLoadBalancer balancer = new SimpleLoadBalancer(state, _lbTimeout, _lbTimeoutUnit, executorService);
    _d2ClientJmxManager.setSimpleLoadBalancer(balancer);
    TogglingLoadBalancer togLB = _factory.createBalancer(balancer, state, clusterToggle, serviceToggle, uriToggle);
    togLB.start(new Callback<None>() {

        @Override
        public void onError(Throwable e) {
            _log.warn("Failed to run start on the TogglingLoadBalancer, may not have registered " + "SimpleLoadBalancer and State with JMX.");
        }

        @Override
        public void onSuccess(None result) {
            _log.info("Registered SimpleLoadBalancer and State with JMX.");
        }
    });
    return togLB;
}
Also used : ServicePropertiesJsonSerializer(com.linkedin.d2.balancer.properties.ServicePropertiesJsonSerializer) UriPropertiesMerger(com.linkedin.d2.balancer.properties.UriPropertiesMerger) TogglingLoadBalancer(com.linkedin.d2.balancer.util.TogglingLoadBalancer) UriPropertiesJsonSerializer(com.linkedin.d2.balancer.properties.UriPropertiesJsonSerializer) ClusterPropertiesJsonSerializer(com.linkedin.d2.balancer.properties.ClusterPropertiesJsonSerializer) UriProperties(com.linkedin.d2.balancer.properties.UriProperties) SimpleLoadBalancerState(com.linkedin.d2.balancer.simple.SimpleLoadBalancerState) SimpleLoadBalancer(com.linkedin.d2.balancer.simple.SimpleLoadBalancer) ServiceProperties(com.linkedin.d2.balancer.properties.ServiceProperties) PropertyEventBusImpl(com.linkedin.d2.discovery.event.PropertyEventBusImpl) ClusterProperties(com.linkedin.d2.balancer.properties.ClusterProperties) None(com.linkedin.common.util.None)

Aggregations

ServicePropertiesJsonSerializer (com.linkedin.d2.balancer.properties.ServicePropertiesJsonSerializer)17 ServiceProperties (com.linkedin.d2.balancer.properties.ServiceProperties)14 ClusterPropertiesJsonSerializer (com.linkedin.d2.balancer.properties.ClusterPropertiesJsonSerializer)11 UriPropertiesJsonSerializer (com.linkedin.d2.balancer.properties.UriPropertiesJsonSerializer)11 UriProperties (com.linkedin.d2.balancer.properties.UriProperties)9 UriPropertiesMerger (com.linkedin.d2.balancer.properties.UriPropertiesMerger)9 ClusterProperties (com.linkedin.d2.balancer.properties.ClusterProperties)8 ZooKeeperPermanentStore (com.linkedin.d2.discovery.stores.zk.ZooKeeperPermanentStore)8 HashMap (java.util.HashMap)7 None (com.linkedin.common.util.None)6 ZooKeeperEphemeralStore (com.linkedin.d2.discovery.stores.zk.ZooKeeperEphemeralStore)6 Test (org.testng.annotations.Test)6 FutureCallback (com.linkedin.common.callback.FutureCallback)5 ZKConnection (com.linkedin.d2.discovery.stores.zk.ZKConnection)5 DegraderLoadBalancerStrategyFactoryV3 (com.linkedin.d2.balancer.strategies.degrader.DegraderLoadBalancerStrategyFactoryV3)4 SimpleLoadBalancer (com.linkedin.d2.balancer.simple.SimpleLoadBalancer)3 SimpleLoadBalancerState (com.linkedin.d2.balancer.simple.SimpleLoadBalancerState)3 PropertyEventBusImpl (com.linkedin.d2.discovery.event.PropertyEventBusImpl)3 HashSet (java.util.HashSet)3 List (java.util.List)3