use of com.networknt.registry.URLImpl in project light-4j by networknt.
the class ConsulUtils method buildUrl.
/**
* build url from service
*
* @param service consul service
* @return URL object
*/
public static URL buildUrl(ConsulService service) {
URL url = null;
if (url == null) {
Map<String, String> params = new HashMap<String, String>();
// String group = service.getName();
// params.put(URLParamType.group.getName(), group);
// params.put(URLParamType.nodeType.getName(), Constants.NODE_TYPE_SERVICE);
url = new URLImpl(ConsulConstants.DEFAULT_PROTOCOL, service.getAddress(), service.getPort(), ConsulUtils.getPathFromServiceId(service.getId()), params);
}
return url;
}
use of com.networknt.registry.URLImpl in project light-4j by networknt.
the class ConsulUtilsTest method setUp.
@Before
public void setUp() throws Exception {
testGroup = "com.networknt.apia-1.0.0";
testServiceName = "com.networknt.apia-1.0.0";
testPath = "com.networknt.apia-1.0.0";
testHost = "127.0.0.1";
testPort = 8888;
testProtocol = "light";
url = new URLImpl(testProtocol, testHost, testPort, testPath);
testServiceId = testHost + ":" + testPath + ":" + testPort;
testServiceTag = ConsulConstants.CONSUL_TAG_LIGHT_PROTOCOL + ":" + testProtocol;
}
use of com.networknt.registry.URLImpl in project light-4j by networknt.
the class MockUtils method getMockUrl.
public static URL getMockUrl(String address, int port) {
Map<String, String> params = new HashMap<>();
// params.put(URLParamType.group.getName(), group);
// params.put(URLParamType.protocol.getName(), protocol);
URL url = new URLImpl(protocol, address, port, path, params);
return url;
}
use of com.networknt.registry.URLImpl in project light-4j by networknt.
the class CommandServiceManager method mergeResult.
private List<URL> mergeResult(URL url, Map<String, Integer> weights) {
List<URL> finalResult = new ArrayList<URL>();
if (weights.size() > 1) {
// construct a rule url with all groups and added as first
URL ruleUrl = new URLImpl("rule", url.getHost(), url.getPort(), url.getPath());
StringBuilder weightsBuilder = new StringBuilder(64);
for (Map.Entry<String, Integer> entry : weights.entrySet()) {
weightsBuilder.append(entry.getKey()).append(':').append(entry.getValue()).append(',');
}
ruleUrl.addParameter(URLParamType.weights.getName(), weightsBuilder.deleteCharAt(weightsBuilder.length() - 1).toString());
finalResult.add(ruleUrl);
}
for (String key : weights.keySet()) {
if (groupServiceCache.containsKey(key)) {
finalResult.addAll(groupServiceCache.get(key));
} else {
URL urlTemp = url.createCopy();
urlTemp.addParameter(URLParamType.group.getName(), key);
finalResult.addAll(discoverOneGroup(urlTemp));
registry.subscribeService(urlTemp, this);
}
}
return finalResult;
}
use of com.networknt.registry.URLImpl in project light-4j by networknt.
the class RoundRobinLoadBalanceTest method testSelect.
@Test
public void testSelect() throws Exception {
List<URL> urls = new ArrayList<>();
urls.add(new URLImpl("http", "127.0.0.1", 8081, "v1", new HashMap<String, String>()));
urls.add(new URLImpl("http", "127.0.0.1", 8082, "v1", new HashMap<String, String>()));
urls.add(new URLImpl("http", "127.0.0.1", 8083, "v1", new HashMap<String, String>()));
urls.add(new URLImpl("http", "127.0.0.1", 8084, "v1", new HashMap<String, String>()));
URL url = loadBalance.select(urls, null);
Assert.assertEquals(url, URLImpl.valueOf("http://127.0.0.1:8082/v1"));
url = loadBalance.select(urls, null);
Assert.assertEquals(url, URLImpl.valueOf("http://127.0.0.1:8083/v1"));
url = loadBalance.select(urls, null);
Assert.assertEquals(url, URLImpl.valueOf("http://127.0.0.1:8084/v1"));
url = loadBalance.select(urls, null);
Assert.assertEquals(url, URLImpl.valueOf("http://127.0.0.1:8081/v1"));
url = loadBalance.select(urls, null);
Assert.assertEquals(url, URLImpl.valueOf("http://127.0.0.1:8082/v1"));
}
Aggregations