Search in sources :

Example 11 with Override

use of com.alibaba.dubbo.registry.common.domain.Override in project dubbo by alibaba.

the class OverrideUtils method overridesToWeights.

public static List<Weight> overridesToWeights(List<Override> overrides) {
    List<Weight> weights = new ArrayList<Weight>();
    if (overrides == null) {
        return weights;
    }
    for (Override o : overrides) {
        if (StringUtils.isEmpty(o.getParams())) {
            continue;
        } else {
            Map<String, String> params = StringUtils.parseQueryString(o.getParams());
            for (Map.Entry<String, String> entry : params.entrySet()) {
                if (entry.getKey().equals("weight")) {
                    Weight weight = new Weight();
                    weight.setAddress(o.getAddress());
                    weight.setId(o.getId());
                    weight.setService(o.getService());
                    weight.setWeight(Integer.valueOf(entry.getValue()));
                    weights.add(weight);
                }
            }
        }
    }
    return weights;
}
Also used : ArrayList(java.util.ArrayList) Override(com.alibaba.dubbo.registry.common.domain.Override) Map(java.util.Map) Weight(com.alibaba.dubbo.registry.common.domain.Weight)

Example 12 with Override

use of com.alibaba.dubbo.registry.common.domain.Override in project dubbo by alibaba.

the class Tool method getProviderWeight.

public static int getProviderWeight(Provider provider, List<Override> oList) {
    for (Override o : oList) {
        if (o.isMatch(provider)) {
            Map<String, String> params = StringUtils.parseQueryString(o.getParams());
            String weight = params.get(Constants.WEIGHT_KEY);
            if (weight != null && weight.length() > 0) {
                return Integer.parseInt(weight);
            }
        }
    }
    return provider.getWeight();
}
Also used : Override(com.alibaba.dubbo.registry.common.domain.Override)

Example 13 with Override

use of com.alibaba.dubbo.registry.common.domain.Override in project dubbo by alibaba.

the class Tool method getOverridesMock.

public String getOverridesMock(List<Override> overrides) {
    if (overrides != null && overrides.size() > 0) {
        for (Override override : overrides) {
            Map<String, String> params = StringUtils.parseQueryString(override.getParams());
            String mock = params.get("mock");
            if (mock != null && mock.length() > 0) {
                return mock;
            }
        }
    }
    return "";
}
Also used : Override(com.alibaba.dubbo.registry.common.domain.Override)

Example 14 with Override

use of com.alibaba.dubbo.registry.common.domain.Override in project dubbo by alibaba.

the class Applications method allmock.

private boolean allmock(Map<String, Object> context, String mock) throws Exception {
    String service = (String) context.get("service");
    if (service == null || service.length() == 0) {
        context.put("message", getMessage("NoSuchOperationData"));
        return false;
    }
    if (!super.currentUser.hasServicePrivilege(service)) {
        context.put("message", getMessage("HaveNoServicePrivilege", service));
        return false;
    }
    List<Override> overrides = overrideService.findByService(service);
    Override allOverride = null;
    if (overrides != null && overrides.size() > 0) {
        for (Override override : overrides) {
            if (override.isDefault()) {
                allOverride = override;
                break;
            }
        }
    }
    if (allOverride != null) {
        Map<String, String> map = StringUtils.parseQueryString(allOverride.getParams());
        if (mock == null || mock.length() == 0) {
            map.remove("mock");
        } else {
            map.put("mock", URL.encode(mock));
        }
        if (map.size() > 0) {
            allOverride.setParams(StringUtils.toQueryString(map));
            allOverride.setEnabled(true);
            allOverride.setOperator(operator);
            allOverride.setOperatorAddress(operatorAddress);
            overrideService.updateOverride(allOverride);
        } else {
            overrideService.deleteOverride(allOverride.getId());
        }
    } else if (mock != null && mock.length() > 0) {
        Override override = new Override();
        override.setService(service);
        override.setParams("mock=" + URL.encode(mock));
        override.setEnabled(true);
        override.setOperator(operator);
        override.setOperatorAddress(operatorAddress);
        overrideService.saveOverride(override);
    }
    return true;
}
Also used : Override(com.alibaba.dubbo.registry.common.domain.Override)

Example 15 with Override

use of com.alibaba.dubbo.registry.common.domain.Override in project dubbo by alibaba.

the class Applications method mock.

private boolean mock(Map<String, Object> context, String mock) throws Exception {
    String service = (String) context.get("service");
    String applications = (String) context.get("application");
    if (service == null || service.length() == 0 || applications == null || applications.length() == 0) {
        context.put("message", getMessage("NoSuchOperationData"));
        return false;
    }
    if (!super.currentUser.hasServicePrivilege(service)) {
        context.put("message", getMessage("HaveNoServicePrivilege", service));
        return false;
    }
    for (String application : SPACE_SPLIT_PATTERN.split(applications)) {
        List<Override> overrides = overrideService.findByServiceAndApplication(service, application);
        if (overrides != null && overrides.size() > 0) {
            for (Override override : overrides) {
                Map<String, String> map = StringUtils.parseQueryString(override.getParams());
                if (mock == null || mock.length() == 0) {
                    map.remove("mock");
                } else {
                    map.put("mock", URL.encode(mock));
                }
                if (map.size() > 0) {
                    override.setParams(StringUtils.toQueryString(map));
                    override.setEnabled(true);
                    override.setOperator(operator);
                    override.setOperatorAddress(operatorAddress);
                    overrideService.updateOverride(override);
                } else {
                    overrideService.deleteOverride(override.getId());
                }
            }
        } else if (mock != null && mock.length() > 0) {
            Override override = new Override();
            override.setService(service);
            override.setApplication(application);
            override.setParams("mock=" + URL.encode(mock));
            override.setEnabled(true);
            override.setOperator(operator);
            override.setOperatorAddress(operatorAddress);
            overrideService.saveOverride(override);
        }
    }
    return true;
}
Also used : Override(com.alibaba.dubbo.registry.common.domain.Override)

Aggregations

Override (com.alibaba.dubbo.registry.common.domain.Override)30 ArrayList (java.util.ArrayList)10 Provider (com.alibaba.dubbo.registry.common.domain.Provider)8 HashMap (java.util.HashMap)7 Map (java.util.Map)6 Consumer (com.alibaba.dubbo.registry.common.domain.Consumer)4 Route (com.alibaba.dubbo.registry.common.domain.Route)2 HashSet (java.util.HashSet)2 LinkedHashMap (java.util.LinkedHashMap)2 List (java.util.List)2 TreeSet (java.util.TreeSet)2 LoadBalance (com.alibaba.dubbo.registry.common.domain.LoadBalance)1 Owner (com.alibaba.dubbo.registry.common.domain.Owner)1 Weight (com.alibaba.dubbo.registry.common.domain.Weight)1