use of com.tencent.polaris.client.pojo.ServiceInstancesByProto in project polaris-java by polarismesh.
the class Utils method checkUpdateInstances.
public static List<ServiceChangeEvent.OneInstanceUpdate> checkUpdateInstances(ServiceInstancesByProto oldVal, ServiceInstancesByProto newVal) {
Map<String, Instance> oldIns = oldVal.getInstances().stream().collect(Collectors.toMap(Instance::getId, instance -> instance));
Map<String, Instance> newIns = newVal.getInstances().stream().collect(Collectors.toMap(Instance::getId, instance -> instance));
List<ServiceChangeEvent.OneInstanceUpdate> ret = new LinkedList<>();
oldIns.forEach((id, instance) -> {
Instance ins = newIns.get(id);
if (ins == null) {
return;
}
if (!Objects.equals(ins.getRevision(), instance.getRevision())) {
ret.add(new ServiceChangeEvent.OneInstanceUpdate(instance, ins));
}
});
return ret;
}
use of com.tencent.polaris.client.pojo.ServiceInstancesByProto 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;
}
use of com.tencent.polaris.client.pojo.ServiceInstancesByProto in project polaris-java by polarismesh.
the class ServiceInstancesCacheHandler method messageToCacheValue.
@Override
public RegistryCacheValue messageToCacheValue(RegistryCacheValue oldValue, Object newValue, boolean isCacheLoaded) {
DiscoverResponse discoverResponse = (DiscoverResponse) newValue;
ServiceInstancesByProto oldServiceInstances = null;
if (null != oldValue) {
oldServiceInstances = (ServiceInstancesByProto) oldValue;
}
return new ServiceInstancesByProto(discoverResponse, oldServiceInstances, isCacheLoaded);
}
use of com.tencent.polaris.client.pojo.ServiceInstancesByProto in project polaris-java by polarismesh.
the class InstancesCircuitBreakTask method getInstance.
private Instance getInstance() {
ServiceEventKey serviceEventKey = new ServiceEventKey(serviceKey, EventType.INSTANCE);
ResourceFilter resourceFilter = new ResourceFilter(serviceEventKey, true, true);
ServiceInstancesByProto instances = (ServiceInstancesByProto) extensions.getLocalRegistry().getInstances(resourceFilter);
if (!instances.isInitialized()) {
return null;
}
return instances.getInstance(instId);
}
use of com.tencent.polaris.client.pojo.ServiceInstancesByProto in project spring-cloud-tencent by Tencent.
the class PolarisServiceStatusChangeListener method onResourceUpdated.
@Override
public void onResourceUpdated(ServiceEventKey svcEventKey, RegistryCacheValue oldValue, RegistryCacheValue newValue) {
if (newValue.getEventType() == ServiceEventKey.EventType.SERVICE) {
if (oldValue instanceof ServicesByProto && newValue instanceof ServicesByProto) {
LOG.debug("receive service={} change event", svcEventKey);
Set<String> oldServiceInfoSet = ((ServicesByProto) oldValue).getServices().stream().map(i -> i.getNamespace() + "::" + i.getService()).collect(Collectors.toSet());
Set<String> newServiceInfoSet = ((ServicesByProto) newValue).getServices().stream().map(i -> i.getNamespace() + "::" + i.getService()).collect(Collectors.toSet());
Sets.SetView<String> addServiceInfoSetView = Sets.difference(newServiceInfoSet, oldServiceInfoSet);
Sets.SetView<String> deleteServiceInfoSetView = Sets.difference(oldServiceInfoSet, newServiceInfoSet);
if (addServiceInfoSetView.isEmpty() && deleteServiceInfoSetView.isEmpty()) {
return;
}
LOG.info("Service status is update. Add service of {}. Delete service of {}", addServiceInfoSetView, deleteServiceInfoSetView);
// Trigger reload of gateway route cache.
this.publisher.publishEvent(new HeartbeatEvent(this, INDEX.getAndIncrement()));
}
} else if (newValue.getEventType() == ServiceEventKey.EventType.INSTANCE) {
if (oldValue instanceof ServiceInstancesByProto && newValue instanceof ServiceInstancesByProto) {
LOG.debug("receive service instances={} change event", svcEventKey);
ServiceInstancesByProto oldIns = (ServiceInstancesByProto) oldValue;
ServiceInstancesByProto newIns = (ServiceInstancesByProto) newValue;
if ((CollectionUtils.isEmpty(oldIns.getInstances()) && !CollectionUtils.isEmpty(newIns.getInstances())) || (!CollectionUtils.isEmpty(oldIns.getInstances()) && CollectionUtils.isEmpty(newIns.getInstances()))) {
LOG.info("Service status of {} is update.", newIns.getService());
// Trigger reload of gateway route cache.
this.publisher.publishEvent(new HeartbeatEvent(this, INDEX.getAndIncrement()));
}
}
}
}
Aggregations