apache / dubbo-admin

@@ -29,6 +29,7 @@
Loading
29 29
import org.apache.dubbo.admin.model.store.TagRoute;
30 30
import org.apache.dubbo.admin.service.RouteService;
31 31
import org.apache.dubbo.common.URL;
32 +
import org.apache.dubbo.common.utils.CollectionUtils;
32 33
import org.apache.dubbo.common.utils.StringUtils;
33 34
import org.springframework.stereotype.Component;
34 35
@@ -95,20 +96,19 @@
Loading
95 96
            //throw exception
96 97
        }
97 98
        RoutingRule route = YamlParser.loadObject(config, RoutingRule.class);
98 -
        List<String> blackWhiteList = RouteUtils.filterBlackWhiteListFromConditions(route.getConditions());
99 -
        if (blackWhiteList.size() != 0) {
100 -
           route.setConditions(blackWhiteList);
101 -
            dynamicConfiguration.setConfig(path, YamlParser.dumpObject(route));
102 -
        } else {
103 -
            dynamicConfiguration.deleteConfig(path);
104 -
        }
99 +
        dynamicConfiguration.deleteConfig(path);
105 100
106 101
        //for 2.6
107 102
        if (Constants.SERVICE.equals(route.getScope())) {
108 103
            RoutingRule originRule = YamlParser.loadObject(config, RoutingRule.class);
109 104
            ConditionRouteDTO conditionRouteDTO = RouteUtils.createConditionRouteFromRule(originRule);
110 105
            for (Route old : convertRouteToOldRoute(conditionRouteDTO)) {
111 -
            	registry.unregister(old.toUrl().addParameter(Constants.COMPATIBLE_CONFIG, true));
106 +
                URL oldUrl = old.toUrl();
107 +
                if(oldUrl.getParameter("rule").contains("host") && oldUrl.getParameter("rule").contains("false")) {
108 +
                    registry.unregister(oldUrl);
109 +
                } else {
110 +
                    registry.unregister(oldUrl.addParameter(Constants.COMPATIBLE_CONFIG, true));
111 +
                }
112 112
            }
113 113
        }
114 114
    }
@@ -120,7 +120,7 @@
Loading
120 120
        if (config != null) {
121 121
            RoutingRule ruleDTO = YamlParser.loadObject(config, RoutingRule.class);
122 122
            List<String> blackWhiteList = RouteUtils.filterBlackWhiteListFromConditions(ruleDTO.getConditions());
123 -
            List<String> conditions = RouteUtils.filterConditionRuleFromConditions(ruleDTO.getConditions());
123 +
            List<String> conditions = RouteUtils.removeBlackWhiteListRuleFromConditions(ruleDTO.getConditions());
124 124
            if (conditions.size() == 0) {
125 125
                dynamicConfiguration.deleteConfig(path);
126 126
            } else {
@@ -146,11 +146,12 @@
Loading
146 146
            ruleDTO = new RoutingRule();
147 147
            ruleDTO.setEnabled(true);
148 148
            if (StringUtils.isNoneEmpty(accessDTO.getApplication())) {
149 +
                ruleDTO.setKey(accessDTO.getApplication());
149 150
                ruleDTO.setScope(Constants.APPLICATION);
150 151
            } else {
152 +
                ruleDTO.setKey(accessDTO.getService().replace("/", "*"));
151 153
                ruleDTO.setScope(Constants.SERVICE);
152 154
            }
153 -
            ruleDTO.setKey(id);
154 155
            ruleDTO.setConditions(blackWhiteList);
155 156
        } else {
156 157
            ruleDTO = YamlParser.loadObject(config, RoutingRule.class);
@@ -177,12 +178,14 @@
Loading
177 178
        if (config != null) {
178 179
            RoutingRule ruleDTO = YamlParser.loadObject(config, RoutingRule.class);
179 180
            List<String> blackWhiteList = RouteUtils.filterBlackWhiteListFromConditions(ruleDTO.getConditions());
180 -
            AccessDTO accessDTO = RouteUtils.convertToAccessDTO(blackWhiteList, ruleDTO.getScope(), ruleDTO.getKey());
181 -
            accessDTO.setId(id);
182 -
            if (Constants.SERVICE.equals(ruleDTO.getScope())) {
183 -
                ConvertUtil.detachIdToService(id, accessDTO);
181 +
            if(CollectionUtils.isNotEmpty(blackWhiteList)) {
182 +
                AccessDTO accessDTO = RouteUtils.convertToAccessDTO(blackWhiteList, ruleDTO.getScope(), ruleDTO.getKey());
183 +
                accessDTO.setId(id);
184 +
                if (Constants.SERVICE.equals(ruleDTO.getScope())) {
185 +
                    ConvertUtil.detachIdToService(id, accessDTO);
186 +
                }
187 +
                return accessDTO;
184 188
            }
185 -
            return accessDTO;
186 189
        }
187 190
        return null;
188 191
    }
@@ -197,7 +200,7 @@
Loading
197 200
        if (config != null) {
198 201
            RoutingRule ruleDTO = YamlParser.loadObject(config, RoutingRule.class);
199 202
            oldList = RouteUtils.filterBlackWhiteListFromConditions(ruleDTO.getConditions());
200 -
            List<String> conditions = RouteUtils.filterConditionRuleFromConditions(ruleDTO.getConditions());
203 +
            List<String> conditions = RouteUtils.filterConditionsExcludeBlackWhiteList(ruleDTO.getConditions());
201 204
            conditions.addAll(blackWhiteList);
202 205
            ruleDTO.setConditions(conditions);
203 206
            dynamicConfiguration.setConfig(path, YamlParser.dumpObject(ruleDTO));
@@ -274,6 +277,9 @@
Loading
274 277
        if (config != null) {
275 278
            RoutingRule routingRule = YamlParser.loadObject(config, RoutingRule.class);
276 279
            ConditionRouteDTO conditionRouteDTO = RouteUtils.createConditionRouteFromRule(routingRule);
280 +
            if(null == conditionRouteDTO || CollectionUtils.isEmpty(conditionRouteDTO.getConditions())) {
281 +
                return null;
282 +
            }
277 283
            String service = conditionRouteDTO.getService();
278 284
            if (org.apache.commons.lang3.StringUtils.isNotBlank(service)) {
279 285
                conditionRouteDTO.setService(service.replace("*", "/"));

@@ -214,8 +214,8 @@
Loading
214 214
        String interfaze = Tool.getInterface(service);
215 215
        return URL.valueOf(Constants.ROUTE_PROTOCOL + "://" + Constants.ANYHOST_VALUE + "/" + interfaze
216 216
                + "?" + Constants.CATEGORY_KEY + "=" + Constants.ROUTERS_CATEGORY
217 -
                + "&router=condition&runtime=" + isRuntime() + "&enabled=" + isEnabled() + "&priority=" + getPriority() + "&force=" + isForce() + "&dynamic=" + isDynamic()
218 -
                + "&name=" + getName() + "&" + Constants.RULE_KEY + "=" + URL.encode(getMatchRule() + " => " + getFilterRule())
217 +
                + "&router=condition&runtime=" + isRuntime() + "&enabled=" + isEnabled() + "&priority=" + getPriority() + "&force=" + (getMatchRule().contains("host") ? "true" : isForce()) + "&dynamic=" + isDynamic()
218 +
                + "&name=" + getName() + "&" + Constants.RULE_KEY + "=" + URL.encode(getMatchRule() + " => " + (getMatchRule().contains("host") ? "false" : getFilterRule()))
219 219
                + (group == null ? "" : "&" + Constants.GROUP_KEY + "=" + group)
220 220
                + (version == null ? "" : "&" + Constants.VERSION_KEY + "=" + version));
221 221
    }

@@ -287,7 +287,41 @@
Loading
287 287
        return result;
288 288
    }
289 289
290 +
    /**
291 +
     * the function of "black white" is part of the function of condition route
292 +
     * @param conditions
293 +
     * @return
294 +
     */
295 +
    public static List<String> filterConditionsExcludeBlackWhiteList(List<String> conditions) {
296 +
        List<String> result = new ArrayList<>();
297 +
        if (conditions == null || conditions.isEmpty()) {
298 +
            return result;
299 +
        }
300 +
        for (String condition : conditions) {
301 +
            if (!isBlackList(condition) && !isWhiteList(condition)) {
302 +
                result.add(condition);
303 +
            }
304 +
        }
305 +
        return result;
306 +
    }
307 +
308 +
    /**
309 +
     * the function of "black white" is part of the function of condition route
310 +
     * @param conditions
311 +
     * @return
312 +
     */
290 313
    public static List<String> filterConditionRuleFromConditions(List<String> conditions) {
314 +
        List<String> result = new ArrayList<>();
315 +
        if (conditions == null || conditions.isEmpty()) {
316 +
            return result;
317 +
        }
318 +
        for (String condition : conditions) {
319 +
            result.add(condition);
320 +
        }
321 +
        return result;
322 +
    }
323 +
324 +
    public static List<String> removeBlackWhiteListRuleFromConditions(List<String> conditions) {
291 325
        List<String> result = new ArrayList<>();
292 326
        if (conditions == null || conditions.isEmpty()) {
293 327
            return result;
Files Complexity Coverage
dubbo-admin-server/src/main/java/org/apache/dubbo/admin 19.60% 20.96%
Project Totals (97 files) 19.60% 20.96%

No yaml found.

Create your codecov.yml to customize your Codecov experience

Sunburst
The inner-most circle is the entire project, moving away from the center are folders then, finally, a single file. The size and color of each slice is representing the number of statements and the coverage, respectively.
Icicle
The top section represents the entire project. Proceeding with folders and finally individual files. The size and color of each slice is representing the number of statements and the coverage, respectively.
Grid
Each block represents a single file in the project. The size and color of each block is represented by the number of statements and the coverage, respectively.
Loading