public static String toCategoryPathIncludeVersion(GrpcURL url, ThrallRoleType roleType) { switch (roleType) { case CONSUMER: return toServicePath(url) + Constants.PATH_SEPARATOR + url.getVersion() + Constants.PATH_SEPARATOR + Constants.CONSUMERS_CATEGORY; case PROVIDER: return toServicePath(url) + Constants.PATH_SEPARATOR + url.getVersion() + Constants.PATH_SEPARATOR + Constants.PROVIDERS_CATEGORY; default: throw new java.lang.IllegalArgumentException("there is no role type"); } }
@Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + ((host == null) ? 0 : host.hashCode()); result = prime * result + ((password == null) ? 0 : password.hashCode()); result = prime * result + ((path == null) ? 0 : path.hashCode()); result = prime * result + port; result = prime * result + ((protocol == null) ? 0 : protocol.hashCode()); result = prime * result + ((username == null) ? 0 : username.hashCode()); result = prime * result + ((this.getGroup() == null) ? 0 : this.getGroup().hashCode()); result = prime * result + ((this.getVersion() == null) ? 0 : this.getVersion().hashCode()); return result; }
public String getServiceKey() { String inf = getServiceInterface(); if (inf == null) return null; StringBuilder buf = new StringBuilder(); String group = getGroup(); if (group != null && group.length() > 0) { buf.append(group).append("/"); } buf.append(inf); String version = getVersion(); if (version != null && version.length() > 0) { buf.append(":").append(version); } return buf.toString(); }
@Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; GrpcURL other = (GrpcURL) obj; if (host == null) { if (other.host != null) return false; } else if (!host.equals(other.host)) return false; if (password == null) { if (other.password != null) return false; } else if (!password.equals(other.password)) return false; if (path == null) { if (other.path != null) return false; } else if (!path.equals(other.path)) return false; if (port != other.port) return false; if (protocol == null) { if (other.protocol != null) return false; } else if (!protocol.equals(other.protocol)) return false; if (username == null) { if (other.username != null) return false; } else if (!username.equals(other.username)) return false; if (this.getGroup() == null) { if (other.getGroup() != null) return false; } else if (!this.getGroup().equals(other.getGroup())) return false; if (this.getVersion() == null) { if (other.getVersion() != null) return false; } else if (!this.getVersion().equals(other.getVersion())) return false; return true; }
public static boolean isMatch(GrpcURL subscribedUrl, GrpcURL providerUrl) { String subscribedInterface = subscribedUrl.getServiceInterface(); String providerInterface = providerUrl.getServiceInterface(); if (StringUtils.equals(subscribedInterface, providerInterface)) { return false; } if (!providerUrl.getParameter(Constants.ENABLED_KEY, true)) { return false; } String subscribedGroup = subscribedUrl.getGroup(); String subscribedVersion = subscribedUrl.getVersion(); String providerGroup = providerUrl.getGroup(); String providerVersion = providerUrl.getVersion(); return StringUtils.equals(subscribedGroup, providerGroup) && StringUtils.equals(subscribedVersion, providerVersion); }
private ConsulService buildConsulHealthService(GrpcURL url) { return ConsulService.newSalukiService()// .withAddress(url.getHost())// .withPort(Integer.valueOf(url.getPort()).toString())// .withName(GrpcURLUtils.toServiceName(url.getGroup()))// .withTag(GrpcURLUtils.healthServicePath(url, ThrallRoleType.PROVIDER))// .withId(url.getHost() + ":" + url.getPort() + "-" + url.getPath() + "-" + url.getVersion())// .withCheckInterval(Integer.valueOf(ConsulConstants.TTL).toString()).build(); }