Search in sources :

Example 1 with Routing

use of com.tencent.polaris.client.pb.RoutingProto.Routing in project polaris-java by polarismesh.

the class ServiceDynamicRuleTest method before.

@Before
public void before() {
    try {
        namingServer = NamingServer.startNamingServer(10081);
    } catch (IOException e) {
        Assert.fail(e.getMessage());
    }
    ServiceKey serviceKey = new ServiceKey(NAMESPACE_PRODUCTION, RULE_ROUTER_SERVICE);
    InstanceParameter parameter = new InstanceParameter();
    parameter.setWeight(100);
    parameter.setHealthy(true);
    parameter.setIsolated(false);
    Map<String, String> metadata = new HashMap<>();
    metadata.put("env", "base");
    parameter.setMetadata(metadata);
    namingServer.getNamingService().batchAddInstances(serviceKey, 10001, MATCH_META_COUNT, parameter);
    parameter.setMetadata(null);
    namingServer.getNamingService().batchAddInstances(serviceKey, 10010, 8, parameter);
    Map<String, MatchString> data = new HashMap<>();
    data.put("env", MatchString.newBuilder().setType(MatchStringType.EXACT).setValue(StringValue.newBuilder().setValue("base").build()).build());
    Map<String, MatchString> srcData = new HashMap<>();
    srcData.put("uid", MatchString.newBuilder().setType(MatchStringType.EXACT).setValue(StringValue.newBuilder().setValue("144115217417489762").build()).build());
    Routing routing = Routing.newBuilder().addInbounds(Route.newBuilder().addDestinations(Destination.newBuilder().putAllMetadata(data).setWeight(UInt32Value.newBuilder().setValue(100).build()).build()).addSources(Source.newBuilder().setNamespace(StringValue.newBuilder().setValue("*").build()).setService(StringValue.newBuilder().setValue("*").build()).putAllMetadata(srcData).build()).build()).build();
    namingServer.getNamingService().setRouting(serviceKey, routing);
}
Also used : MatchString(com.tencent.polaris.client.pb.ModelProto.MatchString) HashMap(java.util.HashMap) InstanceParameter(com.tencent.polaris.test.mock.discovery.NamingService.InstanceParameter) ServiceKey(com.tencent.polaris.api.pojo.ServiceKey) Routing(com.tencent.polaris.client.pb.RoutingProto.Routing) IOException(java.io.IOException) MatchString(com.tencent.polaris.client.pb.ModelProto.MatchString) Before(org.junit.Before)

Example 2 with Routing

use of com.tencent.polaris.client.pb.RoutingProto.Routing in project polaris-java by polarismesh.

the class RoutingCacheHandler method messageToCacheValue.

@Override
public RegistryCacheValue messageToCacheValue(RegistryCacheValue oldValue, Object newValue, boolean isCacheLoaded) {
    DiscoverResponse discoverResponse = (DiscoverResponse) newValue;
    Routing routing = discoverResponse.getRouting();
    String revision = "";
    if (null != routing) {
        revision = routing.getRevision().getValue();
    }
    return new ServiceRuleByProto(routing, revision, isCacheLoaded, getTargetEventType());
}
Also used : Routing(com.tencent.polaris.client.pb.RoutingProto.Routing) DiscoverResponse(com.tencent.polaris.client.pb.ResponseProto.DiscoverResponse) ServiceRuleByProto(com.tencent.polaris.client.pojo.ServiceRuleByProto)

Aggregations

Routing (com.tencent.polaris.client.pb.RoutingProto.Routing)2 ServiceKey (com.tencent.polaris.api.pojo.ServiceKey)1 MatchString (com.tencent.polaris.client.pb.ModelProto.MatchString)1 DiscoverResponse (com.tencent.polaris.client.pb.ResponseProto.DiscoverResponse)1 ServiceRuleByProto (com.tencent.polaris.client.pojo.ServiceRuleByProto)1 InstanceParameter (com.tencent.polaris.test.mock.discovery.NamingService.InstanceParameter)1 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 Before (org.junit.Before)1