use of com.tencent.polaris.api.pojo.ServiceRule in project polaris-java by polarismesh.
the class BaseFlow method loadLocalResources.
private static boolean loadLocalResources(ServiceEventKey svcEventKey, ResourcesResponse resourcesResponse, LocalRegistry localRegistry) {
ResourceFilter filter = new ResourceFilter(svcEventKey, false, true);
if (svcEventKey.getEventType() == EventType.INSTANCE) {
ServiceInstances instances = localRegistry.getInstances(filter);
if (instances.isInitialized()) {
resourcesResponse.addServiceInstances(svcEventKey, instances);
return false;
} else {
return true;
}
}
if (svcEventKey.getEventType() == EventType.SERVICE) {
Services services = localRegistry.getServices(filter);
if (services.isInitialized()) {
resourcesResponse.addServices(svcEventKey, services);
return false;
} else {
return true;
}
}
ServiceRule serviceRule = localRegistry.getServiceRule(filter);
if (serviceRule.isInitialized()) {
resourcesResponse.addServiceRule(svcEventKey, serviceRule);
return false;
} else {
return true;
}
}
use of com.tencent.polaris.api.pojo.ServiceRule in project polaris-java by polarismesh.
the class GetResourcesInvoker method processSvcEventKey.
private int processSvcEventKey(LocalRegistry localRegistry, int callbacks, ServiceEventKey svcEventKey) {
ResourceFilter filter = new ResourceFilter(svcEventKey, internalRequest, useCache);
switch(svcEventKey.getEventType()) {
case INSTANCE:
ServiceInstances instances = localRegistry.getInstances(filter);
if (instances.isInitialized()) {
resourcesResponse.addServiceInstances(svcEventKey, instances);
} else {
localRegistry.loadInstances(svcEventKey, this);
callbacks++;
}
break;
case SERVICE:
Services services = localRegistry.getServices(filter);
if (services.isInitialized()) {
resourcesResponse.addServices(svcEventKey, services);
} else {
localRegistry.loadServices(svcEventKey, this);
callbacks++;
}
break;
default:
ServiceRule serviceRule = localRegistry.getServiceRule(filter);
if (serviceRule.isInitialized()) {
resourcesResponse.addServiceRule(svcEventKey, serviceRule);
} else {
localRegistry.loadServiceRule(svcEventKey, this);
callbacks++;
}
break;
}
return callbacks;
}
use of com.tencent.polaris.api.pojo.ServiceRule in project polaris-java by polarismesh.
the class GetResourcesInvoker method complete.
@Override
public void complete(ServiceEventKey svcEventKey) {
LocalRegistry localRegistry = extensions.getLocalRegistry();
ResourceFilter filter = new ResourceFilter(svcEventKey, internalRequest, useCache);
if (svcEventKey.getEventType() == ServiceEventKey.EventType.INSTANCE) {
ServiceInstances instances = localRegistry.getInstances(filter);
resourcesResponse.addServiceInstances(svcEventKey, instances);
} else if (svcEventKey.getEventType() == EventType.SERVICE) {
Services services = localRegistry.getServices(filter);
resourcesResponse.addServices(svcEventKey, services);
} else {
ServiceRule serviceRule = localRegistry.getServiceRule(filter);
resourcesResponse.addServiceRule(svcEventKey, serviceRule);
}
synchronized (notifier) {
int curTotal = responseIncrement.addAndGet(1);
if (totalCallback == curTotal) {
notifier.notifyAll();
}
}
}
use of com.tencent.polaris.api.pojo.ServiceRule in project polaris-java by polarismesh.
the class QuotaFlow method parseRules.
private static Map<String, Rule> parseRules(RegistryCacheValue oldValue) {
if (null == oldValue || !oldValue.isInitialized()) {
return null;
}
ServiceRule serviceRule = (ServiceRule) oldValue;
if (null == serviceRule.getRule()) {
return null;
}
Map<String, Rule> ruleMap = new HashMap<>();
RateLimit rateLimit = (RateLimit) serviceRule.getRule();
for (Rule rule : rateLimit.getRulesList()) {
ruleMap.put(rule.getRevision().getValue(), rule);
}
return ruleMap;
}
use of com.tencent.polaris.api.pojo.ServiceRule in project polaris-java by polarismesh.
the class QuotaFlow method lookupRule.
private Rule lookupRule(ServiceRule serviceRule, Map<String, String> labels) {
if (null == serviceRule.getRule()) {
return null;
}
RateLimit rateLimitProto = (RateLimit) serviceRule.getRule();
List<Rule> rulesList = rateLimitProto.getRulesList();
if (CollectionUtils.isEmpty(rulesList)) {
return null;
}
for (Rule rule : rulesList) {
if (null != rule.getDisable() && rule.getDisable().getValue()) {
continue;
}
if (rule.getAmountsCount() == 0) {
// 没有amount的规则就忽略
continue;
}
if (rule.getLabelsCount() == 0) {
return rule;
}
boolean allMatchLabels = true;
Map<String, MatchString> labelsMap = rule.getLabelsMap();
for (Map.Entry<String, MatchString> entry : labelsMap.entrySet()) {
if (!matchLabels(entry.getKey(), entry.getValue(), labels)) {
allMatchLabels = false;
break;
}
}
if (allMatchLabels) {
return rule;
}
}
return null;
}
Aggregations