Search in sources :

Example 1 with URIEndpointObject

use of org.apache.servicecomb.foundation.common.net.URIEndpointObject in project incubator-servicecomb-java-chassis by apache.

the class IpPortManager method getAvailableAddress.

private IpPort getAvailableAddress(int index) {
    if (index < defaultIpPort.size()) {
        return defaultIpPort.get(index);
    }
    List<CacheEndpoint> endpoints = getDiscoveredIpPort();
    if (endpoints == null || (index >= defaultIpPort.size() + endpoints.size())) {
        currentAvailableIndex.set(0);
        return defaultIpPort.get(0);
    }
    CacheEndpoint nextEndpoint = endpoints.get(index - defaultIpPort.size());
    return new URIEndpointObject(nextEndpoint.getEndpoint());
}
Also used : CacheEndpoint(org.apache.servicecomb.serviceregistry.cache.CacheEndpoint) URIEndpointObject(org.apache.servicecomb.foundation.common.net.URIEndpointObject)

Example 2 with URIEndpointObject

use of org.apache.servicecomb.foundation.common.net.URIEndpointObject in project incubator-servicecomb-java-chassis by apache.

the class TestVertxRestTransport method testSendException.

@Test
public void testSendException() {
    boolean validAssert;
    Invocation invocation = Mockito.mock(Invocation.class);
    AsyncResponse asyncResp = Mockito.mock(AsyncResponse.class);
    URIEndpointObject endpoint = Mockito.mock(URIEndpointObject.class);
    Endpoint end = Mockito.mock(Endpoint.class);
    Mockito.when(invocation.getEndpoint()).thenReturn(end);
    Mockito.when(invocation.getEndpoint().getAddress()).thenReturn(endpoint);
    try {
        validAssert = true;
        instance.send(invocation, asyncResp);
    } catch (Exception e) {
        validAssert = false;
    }
    Assert.assertFalse(validAssert);
}
Also used : Invocation(org.apache.servicecomb.core.Invocation) Endpoint(org.apache.servicecomb.core.Endpoint) URIEndpointObject(org.apache.servicecomb.foundation.common.net.URIEndpointObject) AsyncResponse(org.apache.servicecomb.swagger.invocation.AsyncResponse) IOException(java.io.IOException) Test(org.junit.Test)

Example 3 with URIEndpointObject

use of org.apache.servicecomb.foundation.common.net.URIEndpointObject in project incubator-servicecomb-java-chassis by apache.

the class TestTcpServer method testTcpServerNonSSL.

@SuppressWarnings({ "rawtypes", "unchecked" })
@Test
public void testTcpServerNonSSL(@Mocked Vertx vertx, @Mocked AsyncResultCallback<InetSocketAddress> callback, @Mocked NetServer netServer) {
    new Expectations() {

        {
            vertx.createNetServer();
            result = netServer;
            netServer.connectHandler((Handler) any);
            netServer.listen(anyInt, anyString, (Handler) any);
        }
    };
    URIEndpointObject endpointObject = new URIEndpointObject("highway://127.0.0.1:6663");
    TcpServer server = new TcpServerForTest(endpointObject);
    // assert done in Expectations
    server.init(vertx, "", callback);
}
Also used : Expectations(mockit.Expectations) URIEndpointObject(org.apache.servicecomb.foundation.common.net.URIEndpointObject) Test(org.junit.Test)

Example 4 with URIEndpointObject

use of org.apache.servicecomb.foundation.common.net.URIEndpointObject in project incubator-servicecomb-java-chassis by apache.

the class CseDiscoveryClient method getInstances.

@Override
public List<ServiceInstance> getInstances(final String serviceId) {
    DiscoveryContext context = new DiscoveryContext();
    context.setInputParameters(serviceId);
    DiscoveryTree discoveryTree = discoveryTrees.computeIfAbsent(serviceId, key -> {
        return new DiscoveryTree();
    });
    VersionedCache serversVersionedCache = discoveryTree.discovery(context, RegistryUtils.getAppId(), serviceId, DefinitionConst.VERSION_RULE_ALL);
    Map<String, MicroserviceInstance> servers = serversVersionedCache.data();
    List<ServiceInstance> instances = new ArrayList<>(servers.size());
    for (MicroserviceInstance s : servers.values()) {
        for (String endpoint : s.getEndpoints()) {
            URIEndpointObject uri = new URIEndpointObject(endpoint);
            instances.add(new DefaultServiceInstance(serviceId, uri.getHostOrIp(), uri.getPort(), uri.isSslEnabled()));
        }
    }
    return instances;
}
Also used : DefaultServiceInstance(org.springframework.cloud.client.DefaultServiceInstance) DiscoveryContext(org.apache.servicecomb.serviceregistry.discovery.DiscoveryContext) VersionedCache(org.apache.servicecomb.foundation.common.cache.VersionedCache) ArrayList(java.util.ArrayList) MicroserviceInstance(org.apache.servicecomb.serviceregistry.api.registry.MicroserviceInstance) DefaultServiceInstance(org.springframework.cloud.client.DefaultServiceInstance) ServiceInstance(org.springframework.cloud.client.ServiceInstance) URIEndpointObject(org.apache.servicecomb.foundation.common.net.URIEndpointObject) DiscoveryTree(org.apache.servicecomb.serviceregistry.discovery.DiscoveryTree)

Example 5 with URIEndpointObject

use of org.apache.servicecomb.foundation.common.net.URIEndpointObject in project incubator-servicecomb-java-chassis by apache.

the class ServiceCombServerList method getInitialListOfServers.

@Override
public List<Server> getInitialListOfServers() {
    DiscoveryContext context = new DiscoveryContext();
    context.setInputParameters(serviceId);
    VersionedCache serversVersionedCache = discoveryTree.discovery(context, RegistryUtils.getAppId(), serviceId, DefinitionConst.VERSION_RULE_ALL);
    Map<String, MicroserviceInstance> servers = serversVersionedCache.data();
    List<Server> instances = new ArrayList<>(servers.size());
    for (MicroserviceInstance s : servers.values()) {
        for (String endpoint : s.getEndpoints()) {
            URIEndpointObject uri = new URIEndpointObject(endpoint);
            instances.add(new Server(uri.getHostOrIp(), uri.getPort()));
        }
    }
    return instances;
}
Also used : DiscoveryContext(org.apache.servicecomb.serviceregistry.discovery.DiscoveryContext) VersionedCache(org.apache.servicecomb.foundation.common.cache.VersionedCache) Server(com.netflix.loadbalancer.Server) ArrayList(java.util.ArrayList) MicroserviceInstance(org.apache.servicecomb.serviceregistry.api.registry.MicroserviceInstance) URIEndpointObject(org.apache.servicecomb.foundation.common.net.URIEndpointObject)

Aggregations

URIEndpointObject (org.apache.servicecomb.foundation.common.net.URIEndpointObject)39 Endpoint (org.apache.servicecomb.core.Endpoint)16 Test (org.junit.Test)16 Expectations (mockit.Expectations)12 Invocation (org.apache.servicecomb.core.Invocation)7 HttpMethod (io.vertx.core.http.HttpMethod)4 RequestOptions (io.vertx.core.http.RequestOptions)4 OperationMeta (org.apache.servicecomb.core.definition.OperationMeta)4 HttpClientWithContext (org.apache.servicecomb.foundation.vertx.client.http.HttpClientWithContext)4 AsyncResponse (org.apache.servicecomb.swagger.invocation.AsyncResponse)4 ArrayList (java.util.ArrayList)3 RestOperationMeta (org.apache.servicecomb.common.rest.definition.RestOperationMeta)3 VersionedCache (org.apache.servicecomb.foundation.common.cache.VersionedCache)3 MicroserviceInstance (org.apache.servicecomb.registry.api.registry.MicroserviceInstance)3 Context (io.vertx.core.Context)2 Handler (io.vertx.core.Handler)2 HttpClient (io.vertx.core.http.HttpClient)2 HttpClientRequest (io.vertx.core.http.HttpClientRequest)2 RoutingContext (io.vertx.ext.web.RoutingContext)2 IOException (java.io.IOException)2