Search in sources :

Example 1 with InstanceProperty

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);
}
Also used : Instance(com.tencent.polaris.api.pojo.Instance) HashMap(java.util.HashMap) ServiceUpdateRequest(com.tencent.polaris.api.plugin.registry.ServiceUpdateRequest) ArrayList(java.util.ArrayList) InstanceProperty(com.tencent.polaris.api.plugin.registry.InstanceProperty) DetectResult(com.tencent.polaris.api.pojo.DetectResult) HashMap(java.util.HashMap) Map(java.util.Map)

Example 2 with InstanceProperty

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;
            }
        }
    }
}
Also used : InstanceByProto(com.tencent.polaris.client.pojo.InstanceByProto) RegistryCacheValue(com.tencent.polaris.api.pojo.RegistryCacheValue) InstanceLocalValue(com.tencent.polaris.api.pojo.InstanceLocalValue) InstanceProperty(com.tencent.polaris.api.plugin.registry.InstanceProperty) ServiceEventKey(com.tencent.polaris.api.pojo.ServiceEventKey) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap)

Example 3 with InstanceProperty

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));
    }
}
Also used : Instance(com.tencent.polaris.api.pojo.Instance) HashMap(java.util.HashMap) InstanceProperty(com.tencent.polaris.api.plugin.registry.InstanceProperty) StatusDimension(com.tencent.polaris.api.pojo.StatusDimension) CircuitBreakerStatus(com.tencent.polaris.api.pojo.CircuitBreakerStatus) HashMap(java.util.HashMap) Map(java.util.Map) ResultKey(com.tencent.polaris.api.plugin.circuitbreaker.CircuitBreakResult.ResultKey)

Aggregations

InstanceProperty (com.tencent.polaris.api.plugin.registry.InstanceProperty)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3 Instance (com.tencent.polaris.api.pojo.Instance)2 ResultKey (com.tencent.polaris.api.plugin.circuitbreaker.CircuitBreakResult.ResultKey)1 ServiceUpdateRequest (com.tencent.polaris.api.plugin.registry.ServiceUpdateRequest)1 CircuitBreakerStatus (com.tencent.polaris.api.pojo.CircuitBreakerStatus)1 DetectResult (com.tencent.polaris.api.pojo.DetectResult)1 InstanceLocalValue (com.tencent.polaris.api.pojo.InstanceLocalValue)1 RegistryCacheValue (com.tencent.polaris.api.pojo.RegistryCacheValue)1 ServiceEventKey (com.tencent.polaris.api.pojo.ServiceEventKey)1 StatusDimension (com.tencent.polaris.api.pojo.StatusDimension)1 InstanceByProto (com.tencent.polaris.client.pojo.InstanceByProto)1 ArrayList (java.util.ArrayList)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1