apache / dubbo-admin
Showing 10 of 21 files from the diff.

@@ -142,7 +142,7 @@
Loading
142 142
        }
143 143
144 144
        //for 2.6
145 -
        if (overrideDTO.getScope().equals(Constants.SERVICE)) {
145 +
        if (Constants.SERVICE.equals(overrideDTO.getScope())) {
146 146
            List<Override> overrides = convertDTOtoOldOverride(old);
147 147
            for (Override o : overrides) {
148 148
                registry.unregister(o.toUrl().addParameter(Constants.COMPATIBLE_CONFIG, true));
@@ -166,7 +166,7 @@
Loading
166 166
        dynamicConfiguration.setConfig(path, YamlParser.dumpObject(override));
167 167
168 168
        //2.6
169 -
        if (override.getScope().equals(Constants.SERVICE)) {
169 +
        if (Constants.SERVICE.equals(override.getScope())) {
170 170
            List<Override> overrides = convertDTOtoOldOverride(old);
171 171
            for (Override o : overrides) {
172 172
                o.setEnabled(false);
@@ -193,7 +193,7 @@
Loading
193 193
        dynamicConfiguration.setConfig(path, YamlParser.dumpObject(override));
194 194
195 195
        //for 2.6
196 -
        if (override.getScope().equals(Constants.SERVICE)) {
196 +
        if (Constants.SERVICE.equals(override.getScope())) {
197 197
            List<Override> overrides = convertDTOtoOldOverride(old);
198 198
            for (Override o : overrides) {
199 199
                o.setEnabled(true);
@@ -213,7 +213,14 @@
Loading
213 213
        String config = dynamicConfiguration.getConfig(path);
214 214
        if (config != null) {
215 215
            OverrideDTO overrideDTO = YamlParser.loadObject(config, OverrideDTO.class);
216 -
            return OverrideUtils.createFromOverride(overrideDTO);
216 +
            DynamicConfigDTO dynamicConfigDTO = OverrideUtils.createFromOverride(overrideDTO);
217 +
            if (dynamicConfigDTO != null) {
218 +
                dynamicConfigDTO.setId(id);
219 +
                if (Constants.SERVICE.equals(overrideDTO.getScope())) {
220 +
                    ConvertUtil.detachIdToService(id, dynamicConfigDTO);
221 +
                }
222 +
            }
223 +
            return dynamicConfigDTO;
217 224
        }
218 225
        return null;
219 226
    }
@@ -229,7 +236,7 @@
Loading
229 236
        dynamicConfiguration.setConfig(path, YamlParser.dumpObject(overrideDTO));
230 237
231 238
        //for 2.6
232 -
        if (scope.equals(Constants.SERVICE)) {
239 +
        if (Constants.SERVICE.equals(scope)) {
233 240
            registerWeight(weightDTO);
234 241
        }
235 242
@@ -248,7 +255,7 @@
Loading
248 255
            if (configs != null && configs.size() > 0) {
249 256
                for (OverrideConfig overrideConfig : configs) {
250 257
                    if (Constants.WEIGHT.equals(overrideConfig.getType())) {
251 -
                        if (overrideDTO.getScope().equals(Constants.SERVICE)) {
258 +
                        if (Constants.SERVICE.equals(overrideDTO.getScope())) {
252 259
                            oldWeight = OverrideUtils.configtoWeightDTO(overrideConfig, scope, id);
253 260
                        }
254 261
                        int index = configs.indexOf(overrideConfig);
@@ -285,7 +292,7 @@
Loading
285 292
            if (configs != null) {
286 293
                for (OverrideConfig overrideConfig : configs) {
287 294
                    if (Constants.WEIGHT.equals(overrideConfig.getType())) {
288 -
                        if (overrideDTO.getScope().equals(Constants.SERVICE)) {
295 +
                        if (Constants.SERVICE.equals(overrideDTO.getScope())) {
289 296
                            oldConfig = overrideConfig;
290 297
                        }
291 298
                        configs.remove(overrideConfig);
@@ -320,6 +327,10 @@
Loading
320 327
                for (OverrideConfig overrideConfig : configs) {
321 328
                    if (Constants.WEIGHT.equals(overrideConfig.getType())) {
322 329
                        WeightDTO weightDTO = OverrideUtils.configtoWeightDTO(overrideConfig, overrideDTO.getScope(), id);
330 +
                        weightDTO.setId(id);
331 +
                        if (Constants.SERVICE.equals(overrideDTO.getScope())) {
332 +
                            ConvertUtil.detachIdToService(id, weightDTO);
333 +
                        }
323 334
                        return weightDTO;
324 335
                    }
325 336
                }
@@ -340,7 +351,7 @@
Loading
340 351
341 352
        //for 2.6
342 353
343 -
        if (scope.equals(Constants.SERVICE)) {
354 +
        if (Constants.SERVICE.equals(scope)) {
344 355
            registerBalancing(balancingDTO);
345 356
        }
346 357
    }
@@ -358,7 +369,7 @@
Loading
358 369
            if (configs != null && configs.size() > 0) {
359 370
                for (OverrideConfig overrideConfig : configs) {
360 371
                    if (Constants.BALANCING.equals(overrideConfig.getType())) {
361 -
                        if (overrideDTO.getScope().equals(Constants.SERVICE)) {
372 +
                        if (Constants.SERVICE.equals(overrideDTO.getScope())) {
362 373
                            oldBalancing = OverrideUtils.configtoBalancingDTO(overrideConfig, Constants.SERVICE, overrideDTO.getKey());
363 374
                        }
364 375
                        int index = configs.indexOf(overrideConfig);
@@ -393,7 +404,7 @@
Loading
393 404
            if (configs != null) {
394 405
                for (OverrideConfig overrideConfig : configs) {
395 406
                    if (Constants.BALANCING.equals(overrideConfig.getType())) {
396 -
                        if (overrideDTO.getScope().equals(Constants.SERVICE)) {
407 +
                        if (Constants.SERVICE.equals(overrideDTO.getScope())) {
397 408
                            oldConfig = overrideConfig;
398 409
                        }
399 410
                        configs.remove(overrideConfig);
@@ -426,6 +437,10 @@
Loading
426 437
                for (OverrideConfig overrideConfig : configs) {
427 438
                    if (Constants.BALANCING.equals(overrideConfig.getType())) {
428 439
                        BalancingDTO balancingDTO = OverrideUtils.configtoBalancingDTO(overrideConfig, overrideDTO.getScope(), id);
440 +
                        balancingDTO.setId(id);
441 +
                        if (Constants.SERVICE.equals(overrideDTO.getScope())) {
442 +
                            ConvertUtil.detachIdToService(id, balancingDTO);
443 +
                        }
429 444
                        return balancingDTO;
430 445
                    }
431 446
                }

@@ -24,6 +24,9 @@
Loading
24 24
public abstract class BaseDTO {
25 25
    private String application;
26 26
    private String service;
27 +
    private String id;
28 +
    private String serviceVersion;
29 +
    private String serviceGroup;
27 30
28 31
    public String getApplication() {
29 32
        return application;
@@ -40,4 +43,28 @@
Loading
40 43
    public void setService(String service) {
41 44
        this.service = service;
42 45
    }
46 +
47 +
    public String getId() {
48 +
        return id;
49 +
    }
50 +
51 +
    public void setId(String id) {
52 +
        this.id = id;
53 +
    }
54 +
55 +
    public String getServiceVersion() {
56 +
        return serviceVersion;
57 +
    }
58 +
59 +
    public void setServiceVersion(String serviceVersion) {
60 +
        this.serviceVersion = serviceVersion;
61 +
    }
62 +
63 +
    public String getServiceGroup() {
64 +
        return serviceGroup;
65 +
    }
66 +
67 +
    public void setServiceGroup(String serviceGroup) {
68 +
        this.serviceGroup = serviceGroup;
69 +
    }
43 70
}

@@ -23,7 +23,7 @@
Loading
23 23
import org.apache.dubbo.admin.common.exception.ParamValidationException;
24 24
import org.apache.dubbo.admin.common.exception.ResourceNotFoundException;
25 25
import org.apache.dubbo.admin.common.exception.VersionValidationException;
26 -
import org.apache.dubbo.admin.common.util.Constants;
26 +
import org.apache.dubbo.admin.common.util.ConvertUtil;
27 27
import org.apache.dubbo.admin.model.dto.WeightDTO;
28 28
import org.apache.dubbo.admin.service.OverrideService;
29 29
import org.apache.dubbo.admin.service.ProviderService;
@@ -72,7 +72,6 @@
Loading
72 72
        if (id == null) {
73 73
            throw new ParamValidationException("Unknown ID!");
74 74
        }
75 -
        id = id.replace(Constants.ANY_VALUE, Constants.PATH_SEPARATOR);
76 75
        WeightDTO weight = overrideService.findWeight(id);
77 76
        if (weight == null) {
78 77
            throw new ResourceNotFoundException("Unknown ID!");
@@ -84,7 +83,9 @@
Loading
84 83
    @RequestMapping(method = RequestMethod.GET)
85 84
    public List<WeightDTO> searchWeight(@RequestParam(required = false) String service,
86 85
                                        @RequestParam(required = false) String application,
87 -
                                        @PathVariable String env) {
86 +
                                        @PathVariable String env,
87 +
                                        @RequestParam(required = false) String serviceVersion,
88 +
                                        @RequestParam(required = false) String serviceGroup) {
88 89
        if (StringUtils.isBlank(service) && StringUtils.isBlank(application)) {
89 90
            throw new ParamValidationException("Either service or application is required");
90 91
        }
@@ -92,7 +93,12 @@
Loading
92 93
        if (StringUtils.isNotBlank(application)) {
93 94
            weightDTO = overrideService.findWeight(application);
94 95
        } else {
95 -
            weightDTO = overrideService.findWeight(service);
96 +
            WeightDTO dto = new WeightDTO();
97 +
            dto.setService(service);
98 +
            dto.setServiceVersion(serviceVersion);
99 +
            dto.setServiceGroup(serviceGroup);
100 +
            String id = ConvertUtil.getIdFromDTO(dto);
101 +
            weightDTO = overrideService.findWeight(id);
96 102
        }
97 103
        List<WeightDTO> weightDTOS = new ArrayList<>();
98 104
        if (weightDTO != null) {
@@ -104,7 +110,6 @@
Loading
104 110
105 111
    @RequestMapping(value = "/{id}", method = RequestMethod.GET)
106 112
    public WeightDTO detailWeight(@PathVariable String id, @PathVariable String env) {
107 -
        id = id.replace(Constants.ANY_VALUE, Constants.PATH_SEPARATOR);
108 113
        WeightDTO weightDTO = overrideService.findWeight(id);
109 114
        if (weightDTO == null) {
110 115
            throw new ResourceNotFoundException("Unknown ID!");
@@ -114,7 +119,6 @@
Loading
114 119
115 120
    @RequestMapping(value = "/{id}", method = RequestMethod.DELETE)
116 121
    public boolean deleteWeight(@PathVariable String id, @PathVariable String env) {
117 -
        id = id.replace(Constants.ANY_VALUE, Constants.PATH_SEPARATOR);
118 122
        overrideService.deleteWeight(id);
119 123
        return true;
120 124
    }

@@ -23,7 +23,7 @@
Loading
23 23
import org.apache.dubbo.admin.common.exception.ParamValidationException;
24 24
import org.apache.dubbo.admin.common.exception.ResourceNotFoundException;
25 25
import org.apache.dubbo.admin.common.exception.VersionValidationException;
26 -
import org.apache.dubbo.admin.common.util.Constants;
26 +
import org.apache.dubbo.admin.common.util.ConvertUtil;
27 27
import org.apache.dubbo.admin.model.dto.BalancingDTO;
28 28
import org.apache.dubbo.admin.service.OverrideService;
29 29
import org.apache.dubbo.admin.service.ProviderService;
@@ -73,7 +73,6 @@
Loading
73 73
        if (id == null) {
74 74
            throw new ParamValidationException("Unknown ID!");
75 75
        }
76 -
        id = id.replace(Constants.ANY_VALUE, Constants.PATH_SEPARATOR);
77 76
        BalancingDTO balancing = overrideService.findBalance(id);
78 77
        if (balancing == null) {
79 78
            throw new ResourceNotFoundException("Unknown ID!");
@@ -86,7 +85,9 @@
Loading
86 85
    @RequestMapping(method = RequestMethod.GET)
87 86
    public List<BalancingDTO> searchLoadbalances(@RequestParam(required = false) String service,
88 87
                                                 @RequestParam(required = false) String application,
89 -
                                                 @PathVariable String env) {
88 +
                                                 @PathVariable String env,
89 +
                                                 @RequestParam(required = false) String serviceVersion,
90 +
                                                 @RequestParam(required = false) String serviceGroup) {
90 91
91 92
        if (StringUtils.isBlank(service) && StringUtils.isBlank(application)) {
92 93
            throw new ParamValidationException("Either service or application is required");
@@ -95,7 +96,12 @@
Loading
95 96
        if (StringUtils.isNotBlank(application)) {
96 97
            balancingDTO = overrideService.findBalance(application);
97 98
        } else {
98 -
            balancingDTO = overrideService.findBalance(service);
99 +
            BalancingDTO dto = new BalancingDTO();
100 +
            dto.setService(service);
101 +
            dto.setServiceVersion(serviceVersion);
102 +
            dto.setServiceGroup(serviceGroup);
103 +
            String id = ConvertUtil.getIdFromDTO(dto);
104 +
            balancingDTO = overrideService.findBalance(id);
99 105
        }
100 106
        List<BalancingDTO> balancingDTOS = new ArrayList<>();
101 107
        if (balancingDTO != null) {
@@ -106,7 +112,6 @@
Loading
106 112
107 113
    @RequestMapping(value = "/{id}", method = RequestMethod.GET)
108 114
    public BalancingDTO detailLoadBalance(@PathVariable String id, @PathVariable String env) throws ParamValidationException {
109 -
        id = id.replace(Constants.ANY_VALUE, Constants.PATH_SEPARATOR);
110 115
        BalancingDTO balancingDTO = overrideService.findBalance(id);
111 116
        if (balancingDTO == null) {
112 117
            throw new ResourceNotFoundException("Unknown ID!");
@@ -119,7 +124,6 @@
Loading
119 124
        if (id == null) {
120 125
            throw new IllegalArgumentException("Argument of id is null!");
121 126
        }
122 -
        id = id.replace(Constants.ANY_VALUE, Constants.PATH_SEPARATOR);
123 127
        overrideService.deleteBalance(id);
124 128
        return true;
125 129
    }

@@ -24,14 +24,12 @@
Loading
24 24
import org.apache.dubbo.admin.model.domain.Route;
25 25
import org.apache.dubbo.admin.model.dto.AccessDTO;
26 26
import org.apache.dubbo.admin.model.dto.ConditionRouteDTO;
27 -
import org.apache.dubbo.admin.model.dto.ConditionRouteResultDTO;
28 27
import org.apache.dubbo.admin.model.dto.TagRouteDTO;
29 28
import org.apache.dubbo.admin.model.store.RoutingRule;
30 29
import org.apache.dubbo.admin.model.store.TagRoute;
31 30
import org.apache.dubbo.admin.service.RouteService;
32 31
import org.apache.dubbo.common.URL;
33 32
import org.apache.dubbo.common.utils.StringUtils;
34 -
import org.springframework.beans.BeanUtils;
35 33
import org.springframework.stereotype.Component;
36 34
37 35
import java.util.LinkedList;
@@ -43,8 +41,8 @@
Loading
43 41
    private String prefix = Constants.CONFIG_KEY;
44 42
45 43
    @Override
46 -
    public void createConditionRoute(ConditionRouteDTO conditionRoute, String serviceVersion, String serviceGroup) {
47 -
        String id = ConvertUtil.getIdFromDTO(conditionRoute, serviceVersion, serviceGroup);
44 +
    public void createConditionRoute(ConditionRouteDTO conditionRoute) {
45 +
        String id = ConvertUtil.getIdFromDTO(conditionRoute);
48 46
        String path = getPath(id, Constants.CONDITION_ROUTE);
49 47
        String existConfig = dynamicConfiguration.getConfig(path);
50 48
        RoutingRule existRule = null;
@@ -65,8 +63,8 @@
Loading
65 63
    }
66 64
67 65
    @Override
68 -
    public void updateConditionRoute(ConditionRouteDTO newConditionRoute, String serviceVersion, String serviceGroup) {
69 -
        String id = ConvertUtil.getIdFromDTO(newConditionRoute, serviceVersion, serviceGroup);
66 +
    public void updateConditionRoute(ConditionRouteDTO newConditionRoute) {
67 +
        String id = ConvertUtil.getIdFromDTO(newConditionRoute);
70 68
        String path = getPath(id, Constants.CONDITION_ROUTE);
71 69
        String existConfig = dynamicConfiguration.getConfig(path);
72 70
        if (existConfig == null) {
@@ -89,8 +87,7 @@
Loading
89 87
    }
90 88
91 89
    @Override
92 -
    public void deleteConditionRoute(ConditionRouteDTO conditionRoute) {
93 -
        String id = ConvertUtil.getIdFromDTO(conditionRoute);
90 +
    public void deleteConditionRoute(String id) {
94 91
        String path = getPath(id, Constants.CONDITION_ROUTE);
95 92
96 93
        String config = dynamicConfiguration.getConfig(path);
@@ -107,7 +104,7 @@
Loading
107 104
        }
108 105
109 106
        //for 2.6
110 -
        if (route.getScope().equals(Constants.SERVICE)) {
107 +
        if (Constants.SERVICE.equals(route.getScope())) {
111 108
            RoutingRule originRule = YamlParser.loadObject(config, RoutingRule.class);
112 109
            ConditionRouteDTO conditionRouteDTO = RouteUtils.createConditionRouteFromRule(originRule);
113 110
            for (Route old : convertRouteToOldRoute(conditionRouteDTO)) {
@@ -131,7 +128,7 @@
Loading
131 128
                dynamicConfiguration.setConfig(path, YamlParser.dumpObject(ruleDTO));
132 129
            }
133 130
            //2.6
134 -
            if (ruleDTO.getScope().equals(Constants.SERVICE) && blackWhiteList.size() > 0) {
131 +
            if (Constants.SERVICE.equals(ruleDTO.getScope()) && blackWhiteList.size() > 0) {
135 132
                Route route = RouteUtils.convertBlackWhiteListtoRoute(blackWhiteList, Constants.SERVICE, id);
136 133
                registry.unregister(route.toUrl());
137 134
            }
@@ -180,7 +177,12 @@
Loading
180 177
        if (config != null) {
181 178
            RoutingRule ruleDTO = YamlParser.loadObject(config, RoutingRule.class);
182 179
            List<String> blackWhiteList = RouteUtils.filterBlackWhiteListFromConditions(ruleDTO.getConditions());
183 -
            return RouteUtils.convertToAccessDTO(blackWhiteList, ruleDTO.getScope(), ruleDTO.getKey());
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);
184 +
            }
185 +
            return accessDTO;
184 186
        }
185 187
        return null;
186 188
    }
@@ -211,22 +213,21 @@
Loading
211 213
    }
212 214
213 215
    @Override
214 -
    public void enableConditionRoute(ConditionRouteDTO conditionRoute) {
215 -
        String id = ConvertUtil.getIdFromDTO(conditionRoute);
216 +
    public void enableConditionRoute(String id) {
216 217
        String path = getPath(id, Constants.CONDITION_ROUTE);
217 218
218 219
        String config = dynamicConfiguration.getConfig(path);
219 220
        if (config != null) {
220 221
            RoutingRule ruleDTO = YamlParser.loadObject(config, RoutingRule.class);
221 222
222 -
            if (ruleDTO.getScope().equals(Constants.SERVICE)) {
223 +
            if (Constants.SERVICE.equals(ruleDTO.getScope())) {
223 224
                //for2.6
224 -
            	for (Route oldRoute : convertRouteToOldRoute(RouteUtils.createConditionRouteFromRule(ruleDTO))) {
225 -
	                URL oldURL = oldRoute.toUrl();
226 -
	                registry.unregister(oldURL);
227 -
	                oldURL = oldURL.addParameter("enabled", true);
228 -
	                registry.register(oldURL);
229 -
            	}
225 +
                for (Route oldRoute : convertRouteToOldRoute(RouteUtils.createConditionRouteFromRule(ruleDTO))) {
226 +
                    URL oldURL = oldRoute.toUrl();
227 +
                    registry.unregister(oldURL);
228 +
                    oldURL = oldURL.addParameter("enabled", true);
229 +
                    registry.register(oldURL);
230 +
                }
230 231
            }
231 232
232 233
            //2.7
@@ -237,15 +238,14 @@
Loading
237 238
    }
238 239
239 240
    @Override
240 -
    public void disableConditionRoute(ConditionRouteDTO conditionRoute) {
241 -
        String id = ConvertUtil.getIdFromDTO(conditionRoute);
241 +
    public void disableConditionRoute(String id) {
242 242
        String path = getPath(id, Constants.CONDITION_ROUTE);
243 243
244 244
        String config = dynamicConfiguration.getConfig(path);
245 245
        if (config != null) {
246 246
            RoutingRule routeRule = YamlParser.loadObject(config, RoutingRule.class);
247 247
248 -
            if (routeRule.getScope().equals(Constants.SERVICE)) {
248 +
            if (Constants.SERVICE.equals(routeRule.getScope())) {
249 249
                //for 2.6
250 250
            	for (Route oldRoute : convertRouteToOldRoute(RouteUtils.createConditionRouteFromRule(routeRule))) {
251 251
	                URL oldURL = oldRoute.toUrl();
@@ -263,12 +263,12 @@
Loading
263 263
    }
264 264
265 265
    @Override
266 -
    public ConditionRouteResultDTO findConditionRoute(ConditionRouteDTO crDTO) {
266 +
    public ConditionRouteDTO findConditionRoute(ConditionRouteDTO crDTO) {
267 267
        return findConditionRoute(ConvertUtil.getIdFromDTO(crDTO));
268 268
    }
269 269
270 270
    @Override
271 -
    public ConditionRouteResultDTO findConditionRoute(String id) {
271 +
    public ConditionRouteDTO findConditionRoute(String id) {
272 272
        String path = getPath(id, Constants.CONDITION_ROUTE);
273 273
        String config = dynamicConfiguration.getConfig(path);
274 274
        if (config != null) {
@@ -278,17 +278,15 @@
Loading
278 278
            if (org.apache.commons.lang3.StringUtils.isNotBlank(service)) {
279 279
                conditionRouteDTO.setService(service.replace("*", "/"));
280 280
            }
281 -
            ConditionRouteResultDTO result = new ConditionRouteResultDTO();
282 -
            BeanUtils.copyProperties(conditionRouteDTO, result);
283 -
            result.setScope(routingRule.getScope());
284 281
            String[] detachResult = ConvertUtil.detachId(id);
285 282
            if (detachResult.length > 1) {
286 -
                result.setServiceVersion(detachResult[1]);
283 +
                conditionRouteDTO.setServiceVersion(detachResult[1]);
287 284
            }
288 285
            if (detachResult.length > 2) {
289 -
                result.setServiceGroup(detachResult[2]);
286 +
                conditionRouteDTO.setServiceGroup(detachResult[2]);
290 287
            }
291 -
            return result;
288 +
            conditionRouteDTO.setId(id);
289 +
            return conditionRouteDTO;
292 290
        }
293 291
        return null;
294 292
    }

@@ -50,22 +50,12 @@
Loading
50 50
    }
51 51
52 52
    public static String getIdFromDTO(BaseDTO baseDTO) {
53 -
        String id;
54 -
        if (StringUtils.isNotEmpty(baseDTO.getApplication())) {
55 -
            id = baseDTO.getApplication();
56 -
        } else {
57 -
            id = baseDTO.getService();
58 -
        }
59 -
        return id;
60 -
    }
61 -
62 -
    public static String getIdFromDTO(BaseDTO baseDTO, String serviceVersion, String serviceGroup) {
63 53
        if (StringUtils.isNotEmpty(baseDTO.getApplication())) {
64 54
            return baseDTO.getApplication();
65 55
        }
66 56
        // id format: "${class}:${version}:${group}"
67 -
        return new StringBuilder(baseDTO.getService()).append(COLON).append(null2EmptyString(serviceVersion))
68 -
                .append(COLON).append(null2EmptyString(serviceGroup)).toString();
57 +
        return new StringBuilder(baseDTO.getService()).append(COLON).append(null2EmptyString(baseDTO.getServiceVersion()))
58 +
                .append(COLON).append(null2EmptyString(baseDTO.getServiceGroup())).toString();
69 59
    }
70 60
71 61
    /**
@@ -81,6 +71,17 @@
Loading
81 71
        }
82 72
    }
83 73
74 +
    public static void detachIdToService(String id, BaseDTO baseDTO) {
75 +
        String[] detachResult = detachId(id);
76 +
        baseDTO.setService(detachResult[0]);
77 +
        if (detachResult.length > 1) {
78 +
            baseDTO.setServiceVersion(detachResult[1]);
79 +
        }
80 +
        if (detachResult.length > 2) {
81 +
            baseDTO.setServiceGroup(detachResult[2]);
82 +
        }
83 +
    }
84 +
84 85
    public static String getServiceIdFromDTO(BaseDTO baseDTO, String serviceVersion, String serviceGroup,
85 86
                                             boolean groupAsFolder) {
86 87
        StringBuilder buf = new StringBuilder();

@@ -23,7 +23,7 @@
Loading
23 23
import org.apache.dubbo.admin.common.exception.ParamValidationException;
24 24
import org.apache.dubbo.admin.common.exception.ResourceNotFoundException;
25 25
import org.apache.dubbo.admin.common.exception.VersionValidationException;
26 -
import org.apache.dubbo.admin.common.util.Constants;
26 +
import org.apache.dubbo.admin.common.util.ConvertUtil;
27 27
import org.apache.dubbo.admin.model.dto.DynamicConfigDTO;
28 28
import org.apache.dubbo.admin.service.OverrideService;
29 29
import org.apache.dubbo.admin.service.ProviderService;
@@ -70,7 +70,6 @@
Loading
70 70
71 71
    @RequestMapping(value = "/{id}", method = RequestMethod.PUT)
72 72
    public boolean updateOverride(@PathVariable String id, @RequestBody DynamicConfigDTO overrideDTO, @PathVariable String env) {
73 -
        id = id.replace(Constants.ANY_VALUE, Constants.PATH_SEPARATOR);
74 73
        DynamicConfigDTO old = overrideService.findOverride(id);
75 74
        if (old == null) {
76 75
            throw new ResourceNotFoundException("Unknown ID!");
@@ -82,11 +81,18 @@
Loading
82 81
    @RequestMapping(method = RequestMethod.GET)
83 82
    public List<DynamicConfigDTO> searchOverride(@RequestParam(required = false) String service,
84 83
                                                 @RequestParam(required = false) String application,
85 -
                                                 @PathVariable String env) {
86 -
        DynamicConfigDTO override = null;
84 +
                                                 @PathVariable String env,
85 +
                                                 @RequestParam(required = false) String serviceVersion,
86 +
                                                 @RequestParam(required = false) String serviceGroup) {
87 +
        DynamicConfigDTO override;
87 88
        List<DynamicConfigDTO> result = new ArrayList<>();
88 89
        if (StringUtils.isNotBlank(service)) {
89 -
            override = overrideService.findOverride(service);
90 +
            DynamicConfigDTO configDTO = new DynamicConfigDTO();
91 +
            configDTO.setService(service);
92 +
            configDTO.setServiceVersion(serviceVersion);
93 +
            configDTO.setServiceGroup(serviceGroup);
94 +
            String id = ConvertUtil.getIdFromDTO(configDTO);
95 +
            override = overrideService.findOverride(id);
90 96
        } else if(StringUtils.isNotBlank(application)){
91 97
            override = overrideService.findOverride(application);
92 98
        } else {
@@ -100,34 +106,27 @@
Loading
100 106
101 107
    @RequestMapping(value = "/{id}", method = RequestMethod.GET)
102 108
    public DynamicConfigDTO detailOverride(@PathVariable String id, @PathVariable String env) {
103 -
        id = id.replace(Constants.ANY_VALUE, Constants.PATH_SEPARATOR);
104 109
        DynamicConfigDTO override = overrideService.findOverride(id);
105 110
        if (override == null) {
106 111
            throw new ResourceNotFoundException("Unknown ID!");
107 112
        }
108 -
109 113
        return override;
110 114
    }
111 115
112 116
    @RequestMapping(value = "/{id}", method = RequestMethod.DELETE)
113 117
    public boolean deleteOverride(@PathVariable String id, @PathVariable String env) {
114 -
        id = id.replace(Constants.ANY_VALUE, Constants.PATH_SEPARATOR);
115 118
        overrideService.deleteOverride(id);
116 119
        return true;
117 120
    }
118 121
119 122
    @RequestMapping(value = "/enable/{id}", method = RequestMethod.PUT)
120 123
    public boolean enableRoute(@PathVariable String id, @PathVariable String env) {
121 -
122 -
        id = id.replace(Constants.ANY_VALUE, Constants.PATH_SEPARATOR);
123 124
        overrideService.enableOverride(id);
124 125
        return true;
125 126
    }
126 127
127 128
    @RequestMapping(value = "/disable/{id}", method = RequestMethod.PUT)
128 129
    public boolean disableRoute(@PathVariable String id, @PathVariable String env) {
129 -
        id = id.replace(Constants.ANY_VALUE, Constants.PATH_SEPARATOR);
130 -
131 130
        overrideService.disableOverride(id);
132 131
        return true;
133 132
    }

@@ -20,7 +20,7 @@
Loading
20 20
import org.apache.dubbo.admin.common.exception.ParamValidationException;
21 21
import org.apache.dubbo.admin.common.exception.ResourceNotFoundException;
22 22
import org.apache.dubbo.admin.common.exception.VersionValidationException;
23 -
import org.apache.dubbo.admin.common.util.Constants;
23 +
import org.apache.dubbo.admin.common.util.ConvertUtil;
24 24
import org.apache.dubbo.admin.model.dto.AccessDTO;
25 25
import org.apache.dubbo.admin.model.dto.ConditionRouteDTO;
26 26
import org.apache.dubbo.admin.service.ConsumerService;
@@ -61,7 +61,9 @@
Loading
61 61
    @RequestMapping(method = RequestMethod.GET)
62 62
    public List<AccessDTO> searchAccess(@RequestParam(required = false) String service,
63 63
                                        @RequestParam(required = false) String application,
64 -
                                        @PathVariable String env) {
64 +
                                        @PathVariable String env,
65 +
                                        @RequestParam(required = false) String serviceVersion,
66 +
                                        @RequestParam(required = false) String serviceGroup) {
65 67
        if (StringUtils.isBlank(service) && StringUtils.isBlank(application)) {
66 68
            throw new ParamValidationException("Either service or application is required");
67 69
        }
@@ -70,7 +72,12 @@
Loading
70 72
        if (StringUtils.isNotBlank(application)) {
71 73
            accessDTO = routeService.findAccess(application);
72 74
        } else {
73 -
            accessDTO = routeService.findAccess(service);
75 +
            AccessDTO dto = new AccessDTO();
76 +
            dto.setService(service);
77 +
            dto.setServiceVersion(serviceVersion);
78 +
            dto.setServiceGroup(serviceGroup);
79 +
            String id = ConvertUtil.getIdFromDTO(dto);
80 +
            accessDTO = routeService.findAccess(id);
74 81
        }
75 82
        if (accessDTO != null) {
76 83
            accessDTO.setEnabled(true);
@@ -81,20 +88,22 @@
Loading
81 88
82 89
    @RequestMapping(value = "/{id}", method = RequestMethod.GET)
83 90
    public AccessDTO detailAccess(@PathVariable String id, @PathVariable String env) {
84 -
        id = id.replace(Constants.ANY_VALUE, Constants.PATH_SEPARATOR);
85 91
        AccessDTO accessDTO = routeService.findAccess(id);
92 +
        if (accessDTO == null) {
93 +
            throw new ResourceNotFoundException("Unknown ID!");
94 +
        }
86 95
        return accessDTO;
87 96
    }
88 97
89 98
    @RequestMapping(value = "/{id}", method = RequestMethod.DELETE)
90 -
    public void deleteAccess(@PathVariable String id, @PathVariable String env) {
91 -
        id = id.replace(Constants.ANY_VALUE, Constants.PATH_SEPARATOR);
99 +
    public boolean deleteAccess(@PathVariable String id, @PathVariable String env) {
92 100
        routeService.deleteAccess(id);
101 +
        return true;
93 102
    }
94 103
95 104
    @RequestMapping(method = RequestMethod.POST)
96 105
    @ResponseStatus(HttpStatus.CREATED)
97 -
    public void createAccess(@RequestBody AccessDTO accessDTO, @PathVariable String env) {
106 +
    public boolean createAccess(@RequestBody AccessDTO accessDTO, @PathVariable String env) {
98 107
        if (StringUtils.isBlank(accessDTO.getService()) && StringUtils.isBlank(accessDTO.getApplication())) {
99 108
            throw new ParamValidationException("Either Service or application is required.");
100 109
        }
@@ -106,16 +115,16 @@
Loading
106 115
            throw new ParamValidationException("One of Blacklist/Whitelist is required.");
107 116
        }
108 117
        routeService.createAccess(accessDTO);
118 +
        return true;
109 119
    }
110 120
111 121
    @RequestMapping(value = "/{id}", method = RequestMethod.PUT)
112 -
    public void updateAccess(@PathVariable String id, @RequestBody AccessDTO accessDTO, @PathVariable String env) {
113 -
114 -
        id = id.replace(Constants.ANY_VALUE, Constants.PATH_SEPARATOR);
122 +
    public boolean updateAccess(@PathVariable String id, @RequestBody AccessDTO accessDTO, @PathVariable String env) {
115 123
        ConditionRouteDTO route = routeService.findConditionRoute(id);
116 124
        if (Objects.isNull(route)) {
117 125
            throw new ResourceNotFoundException("Unknown ID!");
118 126
        }
119 127
        routeService.updateAccess(accessDTO);
128 +
        return true;
120 129
    }
121 130
}

@@ -23,10 +23,7 @@
Loading
23 23
import org.apache.dubbo.admin.common.exception.ParamValidationException;
24 24
import org.apache.dubbo.admin.common.exception.ResourceNotFoundException;
25 25
import org.apache.dubbo.admin.common.exception.VersionValidationException;
26 -
import org.apache.dubbo.admin.common.util.Constants;
27 -
import org.apache.dubbo.admin.common.util.ConvertUtil;
28 26
import org.apache.dubbo.admin.model.dto.ConditionRouteDTO;
29 -
import org.apache.dubbo.admin.model.dto.ConditionRouteResultDTO;
30 27
import org.apache.dubbo.admin.service.ConsumerService;
31 28
import org.apache.dubbo.admin.service.RouteService;
32 29
import org.springframework.beans.factory.annotation.Autowired;
@@ -57,9 +54,7 @@
Loading
57 54
58 55
    @RequestMapping(method = RequestMethod.POST)
59 56
    @ResponseStatus(HttpStatus.CREATED)
60 -
    public boolean createRule(@RequestBody ConditionRouteDTO routeDTO, @PathVariable String env,
61 -
                              @RequestParam(required = false) String serviceVersion,
62 -
                              @RequestParam(required = false) String serviceGroup) {
57 +
    public boolean createRule(@RequestBody ConditionRouteDTO routeDTO, @PathVariable String env) {
63 58
        String serviceName = routeDTO.getService();
64 59
        String app = routeDTO.getApplication();
65 60
        if (StringUtils.isEmpty(serviceName) && StringUtils.isEmpty(app)) {
@@ -68,44 +63,36 @@
Loading
68 63
        if (StringUtils.isNotEmpty(app) && consumerService.findVersionInApplication(app).equals("2.6")) {
69 64
            throw new VersionValidationException("dubbo 2.6 does not support application scope routing rule");
70 65
        }
71 -
        routeService.createConditionRoute(routeDTO, serviceVersion, serviceGroup);
66 +
        routeService.createConditionRoute(routeDTO);
72 67
        return true;
73 68
    }
74 69
75 70
    @RequestMapping(value = "/{id}", method = RequestMethod.PUT)
76 -
    public boolean updateRule(@PathVariable String id, @RequestBody ConditionRouteDTO newConditionRoute, @PathVariable String env,
77 -
                              @RequestParam(required = false) String serviceVersion,
78 -
                              @RequestParam(required = false) String serviceGroup) {
79 -
        id = id.replace(Constants.ANY_VALUE, Constants.PATH_SEPARATOR);
80 -
        ConditionRouteDTO crDTO = new ConditionRouteDTO();
81 -
        String serviceName = newConditionRoute.getService();
82 -
        if (StringUtils.isNotEmpty(serviceName)) {
83 -
            id = ConvertUtil.getIdFromDTO(newConditionRoute, serviceVersion, serviceGroup);
84 -
        }
85 -
        crDTO.setService(id);
86 -
        ConditionRouteDTO oldConditionRoute = routeService.findConditionRoute(crDTO);
71 +
    public boolean updateRule(@PathVariable String id, @RequestBody ConditionRouteDTO newConditionRoute, @PathVariable String env) {
72 +
        ConditionRouteDTO oldConditionRoute = routeService.findConditionRoute(id);
87 73
        if (oldConditionRoute == null) {
88 74
            throw new ResourceNotFoundException("can not find route rule for: " + id);
89 75
        }
90 -
        routeService.updateConditionRoute(newConditionRoute, serviceVersion, serviceGroup);
76 +
        routeService.updateConditionRoute(newConditionRoute);
91 77
        return true;
92 78
    }
93 79
94 80
    @RequestMapping(method = RequestMethod.GET)
95 -
    public List<ConditionRouteResultDTO> searchRoutes(@RequestParam(required = false) String application,
81 +
    public List<ConditionRouteDTO> searchRoutes(@RequestParam(required = false) String application,
96 82
                                                      @RequestParam(required = false) String service, @PathVariable String env,
97 83
                                                      @RequestParam(required = false) String serviceVersion,
98 84
                                                      @RequestParam(required = false) String serviceGroup) {
99 -
        ConditionRouteResultDTO conditionRoute;
100 -
        List<ConditionRouteResultDTO> result = new ArrayList<>();
85 +
        ConditionRouteDTO conditionRoute;
86 +
        List<ConditionRouteDTO> result = new ArrayList<>();
101 87
        ConditionRouteDTO crDTO = new ConditionRouteDTO();
102 88
        if (StringUtils.isNotBlank(application)) {
103 -
            crDTO.setService(application);
89 +
            crDTO.setApplication(application);
104 90
            conditionRoute = routeService.findConditionRoute(crDTO);
105 91
        } else if (StringUtils.isNotBlank(service)) {
106 92
            crDTO.setService(service);
107 -
            String id = ConvertUtil.getIdFromDTO(crDTO, serviceVersion, serviceGroup);
108 -
            conditionRoute = routeService.findConditionRoute(id);
93 +
            crDTO.setServiceVersion(serviceVersion);
94 +
            crDTO.setServiceGroup(serviceGroup);
95 +
            conditionRoute = routeService.findConditionRoute(crDTO);
109 96
        } else {
110 97
            throw new ParamValidationException("Either Service or application is required.");
111 98
        }
@@ -116,18 +103,8 @@
Loading
116 103
    }
117 104
118 105
    @RequestMapping(value = "/{id}", method = RequestMethod.GET)
119 -
    public ConditionRouteResultDTO detailRoute(@PathVariable String id, @PathVariable String env,
120 -
                                               @RequestParam(required = false) String serviceVersion,
121 -
                                               @RequestParam(required = false) String serviceGroup,
122 -
                                               @RequestParam String scope) {
123 -
        id = id.replace(Constants.ANY_VALUE, Constants.PATH_SEPARATOR);
124 -
        ConditionRouteDTO crDTO = new ConditionRouteDTO();
125 -
        crDTO.setService(id);
126 -
        if (Constants.SERVICE.equals(scope)) {
127 -
            id = ConvertUtil.getIdFromDTO(crDTO, serviceVersion, serviceGroup);
128 -
            crDTO.setService(id);
129 -
        }
130 -
        ConditionRouteResultDTO conditionRoute = routeService.findConditionRoute(crDTO);
106 +
    public ConditionRouteDTO detailRoute(@PathVariable String id, @PathVariable String env) {
107 +
        ConditionRouteDTO conditionRoute = routeService.findConditionRoute(id);
131 108
        if (conditionRoute == null || conditionRoute.getConditions() == null) {
132 109
            throw new ResourceNotFoundException("Unknown ID!");
133 110
        }
@@ -135,50 +112,20 @@
Loading
135 112
    }
136 113
137 114
    @RequestMapping(value = "/{id}", method = RequestMethod.DELETE)
138 -
    public boolean deleteRoute(@PathVariable String id, @PathVariable String env,
139 -
                               @RequestParam(required = false) String serviceVersion,
140 -
                               @RequestParam(required = false) String serviceGroup,
141 -
                               @RequestParam String scope) {
142 -
        id = id.replace(Constants.ANY_VALUE, Constants.PATH_SEPARATOR);
143 -
        ConditionRouteDTO crDTO = new ConditionRouteDTO();
144 -
        crDTO.setService(id);
145 -
        if (Constants.SERVICE.equals(scope)) {
146 -
            id = ConvertUtil.getIdFromDTO(crDTO, serviceVersion, serviceGroup);
147 -
            crDTO.setService(id);
148 -
        }
149 -
        routeService.deleteConditionRoute(crDTO);
115 +
    public boolean deleteRoute(@PathVariable String id, @PathVariable String env) {
116 +
        routeService.deleteConditionRoute(id);
150 117
        return true;
151 118
    }
152 119
153 120
    @RequestMapping(value = "/enable/{id}", method = RequestMethod.PUT)
154 -
    public boolean enableRoute(@PathVariable String id, @PathVariable String env,
155 -
                               @RequestParam(required = false) String serviceVersion,
156 -
                               @RequestParam(required = false) String serviceGroup,
157 -
                               @RequestParam String scope) {
158 -
        id = id.replace(Constants.ANY_VALUE, Constants.PATH_SEPARATOR);
159 -
        ConditionRouteDTO crDTO = new ConditionRouteDTO();
160 -
        crDTO.setService(id);
161 -
        if (Constants.SERVICE.equals(scope)) {
162 -
            id = ConvertUtil.getIdFromDTO(crDTO, serviceVersion, serviceGroup);
163 -
            crDTO.setService(id);
164 -
        }
165 -
        routeService.enableConditionRoute(crDTO);
121 +
    public boolean enableRoute(@PathVariable String id) {
122 +
        routeService.enableConditionRoute(id);
166 123
        return true;
167 124
    }
168 125
169 126
    @RequestMapping(value = "/disable/{id}", method = RequestMethod.PUT)
170 -
    public boolean disableRoute(@PathVariable String id, @PathVariable String env,
171 -
                                @RequestParam(required = false) String serviceVersion,
172 -
                                @RequestParam(required = false) String serviceGroup,
173 -
                                @RequestParam String scope) {
174 -
        id = id.replace(Constants.ANY_VALUE, Constants.PATH_SEPARATOR);
175 -
        ConditionRouteDTO crDTO = new ConditionRouteDTO();
176 -
        crDTO.setService(id);
177 -
        if (Constants.SERVICE.equals(scope)) {
178 -
            id = ConvertUtil.getIdFromDTO(crDTO, serviceVersion, serviceGroup);
179 -
            crDTO.setService(id);
180 -
        }
181 -
        routeService.disableConditionRoute(crDTO);
127 +
    public boolean disableRoute(@PathVariable String id, @PathVariable String env) {
128 +
        routeService.disableConditionRoute(id);
182 129
        return true;
183 130
    }
184 131

@@ -353,7 +353,7 @@
Loading
353 353
354 354
    public static ConditionRouteDTO createConditionRouteFromRule(RoutingRule routingRule) {
355 355
        ConditionRouteDTO conditionRouteDTO = new ConditionRouteDTO();
356 -
        if (routingRule.getScope().equals(Constants.SERVICE)) {
356 +
        if (Constants.SERVICE.equals(routingRule.getScope())) {
357 357
            conditionRouteDTO.setService(routingRule.getKey());
358 358
        } else {
359 359
            conditionRouteDTO.setApplication(routingRule.getKey());
Files Complexity Coverage
dubbo-admin-server/src/main/java/org/apache/dubbo/admin 20.02% 21.32%
Project Totals (97 files) 20.02% 21.32%

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