use of com.tencent.polaris.api.plugin.registry.InstanceProperty in project polaris-java by polarismesh.
the class InstancesDetectTask method buildInstanceUpdateResult.
private ServiceUpdateRequest buildInstanceUpdateResult(ServiceKey serviceKey, Map<Instance, DetectResult> aliveResults) {
List<InstanceProperty> instances = new ArrayList<>();
for (Map.Entry<Instance, DetectResult> entry : aliveResults.entrySet()) {
Map<String, Object> properties = new HashMap<>();
properties.put(PROPERTY_DETECT_RESULT, entry.getValue());
InstanceProperty instanceProperty = new InstanceProperty(entry.getKey(), properties);
instances.add(instanceProperty);
}
return new ServiceUpdateRequest(serviceKey, instances);
}
use of com.tencent.polaris.api.plugin.registry.InstanceProperty in project polaris-java by polarismesh.
the class InMemoryRegistry method updateInstances.
@Override
public void updateInstances(ServiceUpdateRequest request) {
Collection<InstanceProperty> instanceProperties = request.getProperties();
if (CollectionUtils.isEmpty(instanceProperties)) {
return;
}
RegistryCacheValue cacheValue = getResource(new ServiceEventKey(request.getServiceKey(), EventType.INSTANCE), true, true);
if (null == cacheValue) {
// 服务不存在,忽略
return;
}
for (InstanceProperty instanceProperty : instanceProperties) {
InstanceByProto instance = (InstanceByProto) instanceProperty.getInstance();
InstanceLocalValue instanceLocalValue = instance.getInstanceLocalValue();
Map<String, Object> properties = instanceProperty.getProperties();
LOG.info("update instance properties for instance {}, properties {}", instance.getId(), properties);
for (Map.Entry<String, Object> entry : properties.entrySet()) {
switch(entry.getKey()) {
case InstanceProperty.PROPERTY_CIRCUIT_BREAKER_STATUS:
onCircuitBreakStatus(entry.getValue(), instanceLocalValue, instance);
break;
case InstanceProperty.PROPERTY_DETECT_RESULT:
instanceLocalValue.setDetectResult((DetectResult) entry.getValue());
break;
default:
break;
}
}
}
}
use of com.tencent.polaris.api.plugin.registry.InstanceProperty in project polaris-java by polarismesh.
the class InstancesCircuitBreakTask method buildInstanceProperty.
@SuppressWarnings("unchecked")
private void buildInstanceProperty(long now, Map<ResultKey, Instance> results, int maxRequestAfterHalfOpen, Map<String, InstanceProperty> instanceProperties, String cbName, CircuitBreakerStatus.Status status) {
if (MapUtils.isEmpty(results)) {
return;
}
for (Map.Entry<ResultKey, Instance> entry : results.entrySet()) {
ResultKey resultKey = entry.getKey();
Instance instance = entry.getValue();
String instId = resultKey.getInstId();
InstanceProperty instanceProperty = instanceProperties.get(instId);
if (null == instanceProperty) {
Map<String, Object> properties = new HashMap<>();
properties.put(PROPERTY_CIRCUIT_BREAKER_STATUS, new HashMap<StatusDimension, CircuitBreakerStatus>());
instanceProperty = new InstanceProperty(instance, properties);
instanceProperties.put(instId, instanceProperty);
}
Map<StatusDimension, CircuitBreakerStatus> statusMap = (Map<StatusDimension, CircuitBreakerStatus>) instanceProperty.getProperties().get(PROPERTY_CIRCUIT_BREAKER_STATUS);
statusMap.put(resultKey.getStatusDimension(), new CircuitBreakerStatus(cbName, status, now));
}
}
Aggregations