use of com.tencent.polaris.api.plugin.registry.ResourceFilter in project polaris-java by polarismesh.
the class InstancesDetectTask method doInstanceDetectForService.
private void doInstanceDetectForService(ServiceKey serviceKey) throws PolarisException {
ServiceEventKey svcEventKey = new ServiceEventKey(serviceKey, EventType.INSTANCE);
ServiceInstances instances = extensions.getLocalRegistry().getInstances(new ResourceFilter(svcEventKey, true, true));
if (!instances.isInitialized() || instances.getInstances().size() == 0) {
return;
}
Map<Instance, DetectResult> aliveResults = new HashMap<>();
for (Instance instance : instances.getInstances()) {
if (destroy.get()) {
// 如果要停止定时任务,则剩下的实例探测也没必要进行下去了
break;
}
DetectResult result = detectInstance(instance);
if (result == null || result.getRetStatus() != RetStatus.RetSuccess) {
continue;
}
aliveResults.put(instance, result);
}
if (MapUtils.isNotEmpty(aliveResults)) {
ServiceUpdateRequest updateRequest = buildInstanceUpdateResult(serviceKey, aliveResults);
LOG.info("update cache for outlier detect, value is {}", updateRequest);
extensions.getLocalRegistry().updateInstances(updateRequest);
}
}
use of com.tencent.polaris.api.plugin.registry.ResourceFilter 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.plugin.registry.ResourceFilter 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.plugin.registry.ResourceFilter 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.plugin.registry.ResourceFilter in project polaris-java by polarismesh.
the class ChangeStateUtils method getInstance.
/**
* 获取实例ID
*
* @param instanceGauge 实例统计数据
* @param localRegistry 本地缓存插件
* @return ID
*/
public static InstanceByProto getInstance(InstanceGauge instanceGauge, LocalRegistry localRegistry) {
ServiceEventKey serviceEventKey = new ServiceEventKey(new ServiceKey(instanceGauge.getNamespace(), instanceGauge.getService()), EventType.INSTANCE);
ResourceFilter resourceFilter = new ResourceFilter(serviceEventKey, true, true);
ServiceInstances instances = localRegistry.getInstances(resourceFilter);
if (!instances.isInitialized()) {
return null;
}
ServiceInstancesByProto serviceInstancesByProto = (ServiceInstancesByProto) instances;
Instance instance = instanceGauge.getInstance();
if (instance instanceof InstanceByProto) {
return (InstanceByProto) instance;
}
InstanceByProto instanceByProto;
String instanceId = instanceGauge.getInstanceId();
if (StringUtils.isNotBlank(instanceId)) {
instanceByProto = serviceInstancesByProto.getInstance(instanceId);
} else {
Node node = new Node(instanceGauge.getHost(), instanceGauge.getPort());
instanceByProto = serviceInstancesByProto.getInstanceByNode(node);
}
if (null != instanceByProto) {
instanceGauge.setInstance(instanceByProto);
}
return instanceByProto;
}
Aggregations