Search in sources :

Example 6 with URLImpl

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;
}
Also used : HashMap(java.util.HashMap) URL(com.networknt.registry.URL) URLImpl(com.networknt.registry.URLImpl)

Example 7 with URLImpl

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;
}
Also used : URLImpl(com.networknt.registry.URLImpl) Before(org.junit.Before)

Example 8 with URLImpl

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;
}
Also used : HashMap(java.util.HashMap) URL(com.networknt.registry.URL) URLImpl(com.networknt.registry.URLImpl)

Example 9 with URLImpl

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;
}
Also used : ArrayList(java.util.ArrayList) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Map(java.util.Map) URL(com.networknt.registry.URL) URLImpl(com.networknt.registry.URLImpl)

Example 10 with URLImpl

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"));
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) URL(com.networknt.registry.URL) URLImpl(com.networknt.registry.URLImpl) Test(org.junit.Test)

Aggregations

URLImpl (com.networknt.registry.URLImpl)10 URL (com.networknt.registry.URL)7 HashMap (java.util.HashMap)6 ArrayList (java.util.ArrayList)4 Test (org.junit.Test)3 Registry (com.networknt.registry.Registry)1 Undertow (io.undertow.Undertow)1 IOException (java.io.IOException)1 BindException (java.net.BindException)1 InetAddress (java.net.InetAddress)1 KeyStoreException (java.security.KeyStoreException)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 UnrecoverableKeyException (java.security.UnrecoverableKeyException)1 Map (java.util.Map)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 InstanceSpec (org.apache.curator.test.InstanceSpec)1 TestingServer (org.apache.curator.test.TestingServer)1 Before (org.junit.Before)1 OptionMap (org.xnio.OptionMap)1