private void buildWeightsMap(Map<String, Integer> weights, RpcCommand.ClientCommand command) { for (String rule : command.getMergeGroups()) { String[] gw = rule.split(":"); int weight = 1; if (gw.length > 1) { try { weight = Integer.parseInt(gw[1]); } catch (NumberFormatException e) { throw new FrameworkException(new Status(WEIGHT_OUT_OF_RANGE, weight)); } if (weight < 0 || weight > 100) { throw new FrameworkException(new Status(WEIGHT_OUT_OF_RANGE, weight)); } } weights.put(gw[0], weight); } }
@Override protected void doUnregister(URL url) { try { serverLock.lock(); removeNode(url, ZkNodeType.AVAILABLE_SERVER); removeNode(url, ZkNodeType.UNAVAILABLE_SERVER); } catch (Throwable e) { throw new FrameworkException(new Status(UNREGISTER_ZOOKEEPER_ERROR, url, getUrl(), e.getMessage()), e); } finally { serverLock.unlock(); } }
public static String toNodeTypePath(URL url, ZkNodeType nodeType) { String type; if (nodeType == ZkNodeType.AVAILABLE_SERVER) { type = "server"; } else if (nodeType == ZkNodeType.UNAVAILABLE_SERVER) { type = "unavailableServer"; } else if (nodeType == ZkNodeType.CLIENT) { type = "client"; } else { throw new FrameworkException(new Status(GET_NODETYPEPATH_ERROR, url, nodeType.toString())); } return toServicePath(url) + Constants.PATH_SEPARATOR + type; }
public DirectRegistry(URL url) { super(url); for (Map.Entry<String, String> entry : url.getParameters().entrySet()) { List<URL> urls = new ArrayList<>(); try { if(entry.getValue().contains(",")) { String[] directUrlArray = entry.getValue().split(","); for (String directUrl : directUrlArray) { urls.add(URLImpl.valueOf(directUrl + "/" + entry.getKey())); } } else { urls.add(URLImpl.valueOf(entry.getValue() + "/" + entry.getKey())); } } catch (Exception e) { throw new FrameworkException(new Status(PARSE_DIRECT_URL_ERROR, url.toString())); } directUrls.put(entry.getKey(), urls); } }
@Override protected void unsubscribeService(URL url, ServiceListener serviceListener) { try { clientLock.lock(); Map<ServiceListener, IZkChildListener> childChangeListeners = serviceListeners.get(url); if (childChangeListeners != null) { IZkChildListener zkChildListener = childChangeListeners.get(serviceListener); if (zkChildListener != null) { client.unsubscribeChildChanges(ZkUtils.toNodeTypePath(url, ZkNodeType.CLIENT), zkChildListener); childChangeListeners.remove(serviceListener); } } } catch (Throwable e) { throw new FrameworkException(new Status(UNSUBSCRIBE_ZOOKEEPER_SERVICE_ERROR, url, getUrl(), e.getMessage()), e); } finally { clientLock.unlock(); } }
@Override public void register(URL url) { failedRegistered.remove(url); failedUnregistered.remove(url); try { super.register(url); } catch (Exception e) { if (isCheckingUrls(getUrl(), url)) { throw new FrameworkException(new Status(REGISTER_ERROR, registryClassName, url, getUrl()), e); } failedRegistered.add(url); } }
@Override public void unregister(URL url) { failedRegistered.remove(url); failedUnregistered.remove(url); try { super.unregister(url); } catch (Exception e) { if (isCheckingUrls(getUrl(), url)) { throw new FrameworkException(new Status(UNREGISTER_ERROR, registryClassName, url, getUrl()), e); } failedUnregistered.add(url); } }
@Override protected void doRegister(URL url) { try { serverLock.lock(); removeNode(url, ZkNodeType.AVAILABLE_SERVER); removeNode(url, ZkNodeType.UNAVAILABLE_SERVER); createNode(url, ZkNodeType.UNAVAILABLE_SERVER); } catch (Throwable e) { throw new FrameworkException(new Status(REGISTER_ZOOKEEPER_ERROR, url, getUrl(), e.getMessage()), e); } finally { serverLock.unlock(); } }
@Override protected List<URL> discoverService(URL url) { try { String parentPath = ZkUtils.toNodeTypePath(url, ZkNodeType.AVAILABLE_SERVER); List<String> currentChilds = new ArrayList<String>(); if (client.exists(parentPath)) { currentChilds = client.getChildren(parentPath); } return nodeChildsToUrls(parentPath, currentChilds); } catch (Throwable e) { throw new FrameworkException(new Status(DISCOVER_ZOOKEEPER_SERVICE_ERROR, url, getUrl(), e.getMessage()), e); } }
if(logger.isTraceEnabled()) logger.trace("Circuit breaker is tripped and not timeout yet!"); throw new ApiException(new Status(STATUS_CLIENT_CREDENTIALS_TOKEN_NOT_AVAILABLE));
if(logger.isInfoEnabled()) logger.info(String.format("[ZooKeeperRegistry] subscribe service: path=%s, info=%s", ZkUtils.toNodePath(url, ZkNodeType.AVAILABLE_SERVER), url.toFullStr())); } catch (Throwable e) { throw new FrameworkException(new Status(SUBSCRIBE_ZOOKEEPER_SERVICE_ERROR, url, getUrl(), e.getMessage()), e); } finally { clientLock.unlock();
@Override public void notifyService(URL serviceUrl, URL registryUrl, List<URL> urls) { if (registry == null) { throw new FrameworkException(new Status(REGISTRY_IS_NULL)); } URL urlCopy = serviceUrl.createCopy(); String groupName = urlCopy.getParameter(URLParamType.group.getName(), URLParamType.group.getValue()); groupServiceCache.put(groupName, urls); List<URL> finalResult = new ArrayList<URL>(); if(logger.isInfoEnabled()) logger.info("command cache is null. service:" + serviceUrl.toSimpleString()); // if no command cache, return group finalResult.addAll(discoverOneGroup(refUrl)); for (NotifyListener notifyListener : notifySet) { notifyListener.notify(registry.getUrl(), finalResult); } }
/** * This method is used to construct a standard error status in JSON format from an error code. * * @param exchange HttpServerExchange * @param code error code * @param args arguments for error description */ default void setExchangeStatus(HttpServerExchange exchange, String code, final Object... args) { Status status = new Status(code, args); if(status.getStatusCode() == 0) { // There is no entry in status.yml for this particular error code. status = new Status(ERROR_NOT_DEFINED, code); } exchange.setStatusCode(status.getStatusCode()); exchange.getResponseHeaders().put(Headers.CONTENT_TYPE, "application/json"); status.setDescription(status.getDescription().replaceAll("\\\\", "\\\\\\\\")); exchange.getResponseSender().send(status.toString()); StackTraceElement[] elements = Thread.currentThread().getStackTrace(); logger.error(status.toString() + " at " + elements[2].getClassName() + "." + elements[2].getMethodName() + "(" + elements[2].getFileName() + ":" + elements[2].getLineNumber() + ")"); }
@Override public void unsubscribe(URL url, NotifyListener listener) { removeForFailedSubAndUnsub(url, listener); try { super.unsubscribe(url, listener); } catch (Exception e) { if (isCheckingUrls(getUrl(), url)) { throw new FrameworkException(new Status(UNSUBSCRIBE_ERROR, registryClassName, url, getUrl()), e); } addToFailedMap(failedUnsubscribed, url, listener); } }
@Override public void subscribe(URL url, NotifyListener listener) { removeForFailedSubAndUnsub(url, listener); try { super.subscribe(url, listener); } catch (Exception e) { List<URL> cachedUrls = getCachedUrls(url); if (cachedUrls != null && cachedUrls.size() > 0) { listener.notify(getUrl(), cachedUrls); } else if (isCheckingUrls(getUrl(), url)) { logger.error(String.format("[%s] false to subscribe %s from %s", registryClassName, url, getUrl()), e); throw new FrameworkException(new Status(SUBSCRIBE_ERROR, registryClassName, url, getUrl()), e); } addToFailedMap(failedSubscribed, url, listener); } }
@Override public void register(URL url) { failedRegistered.remove(url); failedUnregistered.remove(url); try { super.register(url); } catch (Exception e) { if (isCheckingUrls(getUrl(), url)) { throw new FrameworkException(new Status(REGISTER_ERROR, registryClassName, url, getUrl()), e); } failedRegistered.add(url); } }
@Override public void unregister(URL url) { failedRegistered.remove(url); failedUnregistered.remove(url); try { super.unregister(url); } catch (Exception e) { if (isCheckingUrls(getUrl(), url)) { throw new FrameworkException(new Status(UNREGISTER_ERROR, registryClassName, url, getUrl()), e); } failedUnregistered.add(url); } }
private Status failFormatValidation( final String value, final SerializableParameter parameter, final String format) { return new Status("ERR11010", value, parameter.getName(), supportedParameterType(), format); } }
private Status failFormatValidation( final String value, final SerializableParameter parameter, final String format) { return new Status("ERR11010", value, parameter.getName(), supportedParameterType(), format); } }
@Override public void unsubscribe(URL url, NotifyListener listener) { removeForFailedSubAndUnsub(url, listener); try { super.unsubscribe(url, listener); } catch (Exception e) { if (isCheckingUrls(getUrl(), url)) { throw new FrameworkException(new Status(UNSUBSCRIBE_ERROR, registryClassName, url, getUrl()), e); } addToFailedMap(failedUnsubscribed, url, listener); } }