use of com.tencent.polaris.client.pb.CircuitBreakerProto.CircuitBreaker in project polaris-java by polarismesh.
the class NamingService method buildServiceResponse.
private ResponseProto.DiscoverResponse buildServiceResponse(int code, String info, DiscoverRequest req) {
ResponseProto.DiscoverResponse.Builder builder = ResponseProto.DiscoverResponse.newBuilder();
builder.setCode(UInt32Value.newBuilder().setValue(code).build());
CircuitBreakerProto.CircuitBreaker circuitBreaker;
RateLimitProto.RateLimit rateLimit;
RoutingProto.Routing routing;
List<ServiceProto.Instance> instances;
ServiceProto.Service service = req.getService();
ServiceKey serviceKey = new ServiceKey(service.getNamespace().getValue(), service.getName().getValue());
switch(req.getType()) {
case UNKNOWN:
break;
case INSTANCE:
instances = services.get(serviceKey);
if (CollectionUtils.isNotEmpty(instances)) {
builder.addAllInstances(instances);
}
builder.setType(DiscoverResponseType.INSTANCE);
break;
case CLUSTER:
break;
case ROUTING:
routing = serviceRoutings.get(serviceKey);
if (null != routing) {
builder.setRouting(routing);
}
builder.setType(DiscoverResponseType.ROUTING);
break;
case CIRCUIT_BREAKER:
circuitBreaker = serviceCircuitBreakers.get(serviceKey);
if (null != circuitBreaker) {
builder.setCircuitBreaker(circuitBreaker);
}
builder.setType(DiscoverResponseType.CIRCUIT_BREAKER);
break;
case RATE_LIMIT:
rateLimit = serviceRateLimits.get(serviceKey);
if (null != rateLimit) {
builder.setRateLimit(rateLimit);
}
builder.setType(DiscoverResponseType.RATE_LIMIT);
break;
case SERVICES:
Set<ServiceKey> keys = services.keySet();
Map<String, ServiceProto.Service> tmp = new HashMap<>();
String namespace = req.getService().getNamespace().getValue();
System.out.println("get service param : " + namespace);
keys.removeIf(serviceKey1 -> {
if (StringUtils.isBlank(namespace)) {
return false;
}
return !Objects.equals(namespace, serviceKey1.getNamespace());
});
keys.forEach(key -> {
tmp.put(key.getNamespace() + "##" + key.getService(), ServiceProto.Service.newBuilder().setNamespace(StringValue.newBuilder().setValue(key.getNamespace()).build()).setName(StringValue.newBuilder().setValue(key.getService()).build()).build());
});
final int[] index = { 0 };
tmp.forEach((s, svc) -> {
builder.addServices(index[0], svc);
index[0]++;
});
builder.setType(DiscoverResponseType.SERVICES);
break;
case UNRECOGNIZED:
break;
default:
break;
}
if (StringUtils.isNotBlank(info)) {
builder.setInfo(StringValue.newBuilder().setValue(info).build());
}
builder.setService(service);
return builder.build();
}
use of com.tencent.polaris.client.pb.CircuitBreakerProto.CircuitBreaker in project polaris-java by polarismesh.
the class CircuitBreakCacheHandler method messageToCacheValue.
@Override
public RegistryCacheValue messageToCacheValue(RegistryCacheValue oldValue, Object newValue, boolean isCacheLoaded) {
DiscoverResponse discoverResponse = (DiscoverResponse) newValue;
CircuitBreaker circuitBreaker = discoverResponse.getCircuitBreaker();
String revision = "";
if (null != circuitBreaker) {
revision = circuitBreaker.getRevision().getValue();
}
return new ServiceRuleByProto(circuitBreaker, revision, isCacheLoaded, getTargetEventType());
}
Aggregations