use of com.linkedin.d2.balancer.properties.UriProperties in project rest.li by linkedin.
the class ZooKeeperServer method markUp.
@Override
public void markUp(final String clusterName, final URI uri, final Map<Integer, PartitionData> partitionDataMap, final Map<String, Object> uriSpecificProperties, final Callback<None> callback) {
final Callback<None> doPutCallback = new Callback<None>() {
@Override
public void onSuccess(None none) {
Map<URI, Map<Integer, PartitionData>> partitionDesc = new HashMap<URI, Map<Integer, PartitionData>>();
partitionDesc.put(uri, partitionDataMap);
Map<URI, Map<String, Object>> myUriSpecificProperties;
if (uriSpecificProperties != null && !uriSpecificProperties.isEmpty()) {
myUriSpecificProperties = new HashMap<URI, Map<String, Object>>();
myUriSpecificProperties.put(uri, uriSpecificProperties);
} else {
myUriSpecificProperties = Collections.emptyMap();
}
if (_log.isInfoEnabled()) {
StringBuilder sb = new StringBuilder();
sb.append(_store);
sb.append(" marked up for cluster: ");
sb.append(clusterName);
sb.append(", uri: ");
sb.append(uri);
sb.append(", announcing [partitionId: weight]s: {");
for (final int partitionId : partitionDataMap.keySet()) {
sb.append("[");
sb.append(partitionId);
sb.append(" : ");
sb.append(partitionDataMap.get(partitionId));
sb.append("]");
}
sb.append("}");
info(_log, sb);
}
_store.put(clusterName, new UriProperties(clusterName, partitionDesc, myUriSpecificProperties), callback);
}
@Override
public void onError(Throwable e) {
callback.onError(e);
}
};
Callback<UriProperties> getCallback = new Callback<UriProperties>() {
@Override
public void onSuccess(UriProperties uris) {
if (uris != null && uris.Uris().contains(uri)) {
warn(_log, "markUp called on a uri that already exists in cluster ", clusterName, ": ", uri);
// mark down before marking up with the new weight
markDown(clusterName, uri, doPutCallback);
} else {
doPutCallback.onSuccess(None.none());
}
}
@Override
public void onError(Throwable e) {
callback.onError(e);
}
};
_store.get(clusterName, getCallback);
}
use of com.linkedin.d2.balancer.properties.UriProperties 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<String, UriProperties>();
// 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;
}
use of com.linkedin.d2.balancer.properties.UriProperties 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();
}
use of com.linkedin.d2.balancer.properties.UriProperties 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<UriProperties>();
// 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;
}
use of com.linkedin.d2.balancer.properties.UriProperties 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();
}
Aggregations