apache / dubbo-admin
Showing 8 of 25 files from the diff.

@@ -17,24 +17,24 @@
Loading
17 17
18 18
package org.apache.dubbo.admin.registry.config.impl;
19 19
20 -
import com.alibaba.nacos.api.PropertyKeyConst;
21 -
import java.util.Map;
22 20
import org.apache.dubbo.admin.common.util.Constants;
23 21
import org.apache.dubbo.admin.registry.config.GovernanceConfiguration;
24 -
import org.apache.dubbo.common.URL;
25 -
import org.apache.dubbo.common.logger.Logger;
26 -
import org.apache.dubbo.common.logger.LoggerFactory;
27 -
import org.apache.dubbo.common.utils.StringConstantFieldValuePredicate;
28 22
29 23
import com.alibaba.nacos.api.NacosFactory;
24 +
import com.alibaba.nacos.api.PropertyKeyConst;
30 25
import com.alibaba.nacos.api.config.ConfigService;
31 26
import com.alibaba.nacos.api.exception.NacosException;
32 27
import org.apache.commons.lang3.StringUtils;
28 +
import org.apache.dubbo.common.URL;
29 +
import org.apache.dubbo.common.logger.Logger;
30 +
import org.apache.dubbo.common.logger.LoggerFactory;
31 +
import org.apache.dubbo.common.utils.StringConstantFieldValuePredicate;
33 32
33 +
import java.util.Map;
34 34
import java.util.Properties;
35 35
36 -
import static com.alibaba.nacos.api.PropertyKeyConst.SERVER_ADDR;
37 36
import static com.alibaba.nacos.api.PropertyKeyConst.NAMESPACE;
37 +
import static com.alibaba.nacos.api.PropertyKeyConst.SERVER_ADDR;
38 38
39 39
public class NacosConfiguration implements GovernanceConfiguration {
40 40
    private static final Logger logger = LoggerFactory.getLogger(NacosConfiguration.class);

@@ -0,0 +1,41 @@
Loading
1 +
/*
2 +
 * Licensed to the Apache Software Foundation (ASF) under one or more
3 +
 * contributor license agreements.  See the NOTICE file distributed with
4 +
 * this work for additional information regarding copyright ownership.
5 +
 * The ASF licenses this file to You under the Apache License, Version 2.0
6 +
 * (the "License"); you may not use this file except in compliance with
7 +
 * the License.  You may obtain a copy of the License at
8 +
 *
9 +
 *     http://www.apache.org/licenses/LICENSE-2.0
10 +
 *
11 +
 * Unless required by applicable law or agreed to in writing, software
12 +
 * distributed under the License is distributed on an "AS IS" BASIS,
13 +
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 +
 * See the License for the specific language governing permissions and
15 +
 * limitations under the License.
16 +
 */
17 +
18 +
package org.apache.dubbo.admin.provider;
19 +
20 +
import org.apache.dubbo.admin.service.MockRuleService;
21 +
22 +
import org.apache.dubbo.config.annotation.DubboService;
23 +
import org.apache.dubbo.mock.api.MockContext;
24 +
import org.apache.dubbo.mock.api.MockResult;
25 +
import org.apache.dubbo.mock.api.MockService;
26 +
import org.springframework.beans.factory.annotation.Autowired;
27 +
28 +
/**
29 +
 * The {@link MockServiceProvider} register as a dubbo service, provide the mock function for the consumer of {@link MockService}.
30 +
 */
31 +
@DubboService
32 +
public class MockServiceProvider implements MockService {
33 +
34 +
    @Autowired
35 +
    private MockRuleService mockRuleService;
36 +
37 +
    @Override
38 +
    public MockResult mock(MockContext mockContext) {
39 +
        return mockRuleService.getMockData(mockContext);
40 +
    }
41 +
}

@@ -0,0 +1,98 @@
Loading
1 +
/*
2 +
 * Licensed to the Apache Software Foundation (ASF) under one or more
3 +
 * contributor license agreements.  See the NOTICE file distributed with
4 +
 * this work for additional information regarding copyright ownership.
5 +
 * The ASF licenses this file to You under the Apache License, Version 2.0
6 +
 * (the "License"); you may not use this file except in compliance with
7 +
 * the License.  You may obtain a copy of the License at
8 +
 *
9 +
 *     http://www.apache.org/licenses/LICENSE-2.0
10 +
 *
11 +
 * Unless required by applicable law or agreed to in writing, software
12 +
 * distributed under the License is distributed on an "AS IS" BASIS,
13 +
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 +
 * See the License for the specific language governing permissions and
15 +
 * limitations under the License.
16 +
 */
17 +
18 +
package org.apache.dubbo.admin.model.domain;
19 +
20 +
import org.apache.dubbo.admin.model.dto.MockRuleDTO;
21 +
22 +
/**
23 +
 * The entity for database query and insert.
24 +
 */
25 +
public class MockRule {
26 +
27 +
    private Long id;
28 +
29 +
    private String serviceName;
30 +
31 +
    private String methodName;
32 +
33 +
    private String rule;
34 +
35 +
    private Boolean enable;
36 +
37 +
    public String getServiceName() {
38 +
        return serviceName;
39 +
    }
40 +
41 +
    public void setServiceName(String serviceName) {
42 +
        this.serviceName = serviceName;
43 +
    }
44 +
45 +
    public String getMethodName() {
46 +
        return methodName;
47 +
    }
48 +
49 +
    public void setMethodName(String methodName) {
50 +
        this.methodName = methodName;
51 +
    }
52 +
53 +
    public String getRule() {
54 +
        return rule;
55 +
    }
56 +
57 +
    public void setRule(String rule) {
58 +
        this.rule = rule;
59 +
    }
60 +
61 +
    public Long getId() {
62 +
        return id;
63 +
    }
64 +
65 +
    public void setId(Long id) {
66 +
        this.id = id;
67 +
    }
68 +
69 +
    public Boolean getEnable() {
70 +
        return enable;
71 +
    }
72 +
73 +
    public void setEnable(Boolean enable) {
74 +
        this.enable = enable;
75 +
    }
76 +
77 +
    @java.lang.Override
78 +
    public String toString() {
79 +
        return "MockRule{" +
80 +
                "id=" + id +
81 +
                ", serviceName='" + serviceName + '\'' +
82 +
                ", methodName='" + methodName + '\'' +
83 +
                ", rule='" + rule + '\'' +
84 +
                ", enable=" + enable +
85 +
                '}';
86 +
    }
87 +
88 +
89 +
    public static MockRule toMockRule(MockRuleDTO mockRule) {
90 +
        MockRule rule = new MockRule();
91 +
        rule.setServiceName(mockRule.getServiceName().trim());
92 +
        rule.setMethodName(mockRule.getMethodName().trim());
93 +
        rule.setId(mockRule.getId());
94 +
        rule.setRule(mockRule.getRule());
95 +
        rule.setEnable(mockRule.getEnable());
96 +
        return rule;
97 +
    }
98 +
}

@@ -0,0 +1,116 @@
Loading
1 +
/*
2 +
 * Licensed to the Apache Software Foundation (ASF) under one or more
3 +
 * contributor license agreements.  See the NOTICE file distributed with
4 +
 * this work for additional information regarding copyright ownership.
5 +
 * The ASF licenses this file to You under the Apache License, Version 2.0
6 +
 * (the "License"); you may not use this file except in compliance with
7 +
 * the License.  You may obtain a copy of the License at
8 +
 *
9 +
 *     http://www.apache.org/licenses/LICENSE-2.0
10 +
 *
11 +
 * Unless required by applicable law or agreed to in writing, software
12 +
 * distributed under the License is distributed on an "AS IS" BASIS,
13 +
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 +
 * See the License for the specific language governing permissions and
15 +
 * limitations under the License.
16 +
 */
17 +
18 +
package org.apache.dubbo.admin.service.impl;
19 +
20 +
import org.apache.dubbo.admin.mapper.MockRuleMapper;
21 +
import org.apache.dubbo.admin.model.domain.MockRule;
22 +
import org.apache.dubbo.admin.model.dto.MockRuleDTO;
23 +
import org.apache.dubbo.admin.service.MockRuleService;
24 +
25 +
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
26 +
import org.apache.dubbo.mock.api.MockContext;
27 +
import org.apache.dubbo.mock.api.MockResult;
28 +
import org.springframework.beans.factory.annotation.Autowired;
29 +
import org.springframework.dao.DuplicateKeyException;
30 +
import org.springframework.data.domain.Page;
31 +
import org.springframework.data.domain.PageImpl;
32 +
import org.springframework.data.domain.Pageable;
33 +
import org.springframework.stereotype.Component;
34 +
35 +
import java.util.List;
36 +
import java.util.Objects;
37 +
import java.util.Optional;
38 +
import java.util.stream.Collectors;
39 +
40 +
/**
41 +
 * The implement of {@link MockRuleService}.
42 +
 */
43 +
@Component
44 +
public class MockRuleServiceImpl implements MockRuleService {
45 +
46 +
    @Autowired
47 +
    private MockRuleMapper mockRuleMapper;
48 +
49 +
    @Override
50 +
    public void createOrUpdateMockRule(MockRuleDTO mockRule) {
51 +
        if (Objects.isNull(mockRule.getServiceName()) || Objects.isNull(mockRule.getMethodName())
52 +
                || Objects.isNull(mockRule.getRule())) {
53 +
            throw new IllegalStateException("Param serviceName, methodName, rule cannot be null");
54 +
        }
55 +
        MockRule rule = MockRule.toMockRule(mockRule);
56 +
        QueryWrapper<MockRule> queryWrapper = new QueryWrapper<>();
57 +
        queryWrapper.eq("service_name", mockRule.getServiceName());
58 +
        queryWrapper.eq("method_name", mockRule.getMethodName());
59 +
        MockRule existRule = mockRuleMapper.selectOne(queryWrapper);
60 +
61 +
        // check if we can save or update the rule, we need keep the serviceName + methodName is unique.
62 +
        if (Objects.nonNull(existRule)) {
63 +
            if (Objects.equals(rule.getServiceName(), existRule.getServiceName())
64 +
                    && Objects.equals(rule.getMethodName(), existRule.getMethodName())) {
65 +
                if (!Objects.equals(rule.getId(), existRule.getId())) {
66 +
                    throw new DuplicateKeyException("Service Name and Method Name must be unique");
67 +
                }
68 +
            }
69 +
        }
70 +
71 +
        if (Objects.nonNull(rule.getId())) {
72 +
            mockRuleMapper.updateById(rule);
73 +
            return;
74 +
        }
75 +
        mockRuleMapper.insert(rule);
76 +
    }
77 +
78 +
    @Override
79 +
    public void deleteMockRuleById(Long id) {
80 +
        MockRule mockRule = mockRuleMapper.selectById(id);
81 +
        if (Objects.isNull(mockRule)) {
82 +
            throw new IllegalStateException("Mock Rule cannot find");
83 +
        }
84 +
        mockRuleMapper.deleteById(id);
85 +
    }
86 +
87 +
    @Override
88 +
    public Page<MockRuleDTO> listMockRulesByPage(String filter, Pageable pageable) {
89 +
        QueryWrapper<MockRule> queryWrapper = new QueryWrapper<>();
90 +
        Optional.ofNullable(filter)
91 +
                .ifPresent(f -> queryWrapper.like("service_name", f));
92 +
        List<MockRule> mockRules = mockRuleMapper.selectList(queryWrapper);
93 +
        int total = mockRules.size();
94 +
        final List<MockRuleDTO> content = mockRules.stream()
95 +
                .skip(pageable.getOffset())
96 +
                .limit(pageable.getPageSize())
97 +
                .map(MockRuleDTO::toMockRuleDTO)
98 +
                .collect(Collectors.toList());
99 +
        return new PageImpl<>(content, pageable, total);
100 +
    }
101 +
102 +
    @Override
103 +
    public MockResult getMockData(MockContext mockContext) {
104 +
        QueryWrapper<MockRule> queryWrapper = new QueryWrapper<>();
105 +
        queryWrapper.eq("service_name", mockContext.getServiceName());
106 +
        queryWrapper.eq("method_name", mockContext.getMethodName());
107 +
        MockRule mockRule = mockRuleMapper.selectOne(queryWrapper);
108 +
        MockResult mockResult = new MockResult();
109 +
        if (Objects.isNull(mockRule)) {
110 +
            return mockResult;
111 +
        }
112 +
        mockResult.setEnable(mockRule.getEnable());
113 +
        mockResult.setContent(mockRule.getRule());
114 +
        return mockResult;
115 +
    }
116 +
}

@@ -0,0 +1,62 @@
Loading
1 +
/*
2 +
 * Licensed to the Apache Software Foundation (ASF) under one or more
3 +
 * contributor license agreements.  See the NOTICE file distributed with
4 +
 * this work for additional information regarding copyright ownership.
5 +
 * The ASF licenses this file to You under the Apache License, Version 2.0
6 +
 * (the "License"); you may not use this file except in compliance with
7 +
 * the License.  You may obtain a copy of the License at
8 +
 *
9 +
 *     http://www.apache.org/licenses/LICENSE-2.0
10 +
 *
11 +
 * Unless required by applicable law or agreed to in writing, software
12 +
 * distributed under the License is distributed on an "AS IS" BASIS,
13 +
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 +
 * See the License for the specific language governing permissions and
15 +
 * limitations under the License.
16 +
 */
17 +
18 +
package org.apache.dubbo.admin.controller;
19 +
20 +
import org.apache.dubbo.admin.annotation.Authority;
21 +
import org.apache.dubbo.admin.model.dto.MockRuleDTO;
22 +
import org.apache.dubbo.admin.service.MockRuleService;
23 +
24 +
import org.springframework.beans.factory.annotation.Autowired;
25 +
import org.springframework.data.domain.Page;
26 +
import org.springframework.data.domain.Pageable;
27 +
import org.springframework.web.bind.annotation.DeleteMapping;
28 +
import org.springframework.web.bind.annotation.GetMapping;
29 +
import org.springframework.web.bind.annotation.PostMapping;
30 +
import org.springframework.web.bind.annotation.RequestBody;
31 +
import org.springframework.web.bind.annotation.RequestMapping;
32 +
import org.springframework.web.bind.annotation.RequestParam;
33 +
import org.springframework.web.bind.annotation.RestController;
34 +
35 +
/**
36 +
 * Mock Rule Controller.
37 +
 */
38 +
@Authority(needLogin = true)
39 +
@RestController
40 +
@RequestMapping("/api/{env}/mock/rule")
41 +
public class MockRuleController {
42 +
43 +
    @Autowired
44 +
    private MockRuleService mockRuleService;
45 +
46 +
    @PostMapping
47 +
    public boolean createOrUpdateMockRule(@RequestBody MockRuleDTO mockRule) {
48 +
        mockRuleService.createOrUpdateMockRule(mockRule);
49 +
        return true;
50 +
    }
51 +
52 +
    @DeleteMapping
53 +
    public boolean deleteMockRule(@RequestBody MockRuleDTO mockRule) {
54 +
        mockRuleService.deleteMockRuleById(mockRule.getId());
55 +
        return true;
56 +
    }
57 +
58 +
    @GetMapping("/list")
59 +
    public Page<MockRuleDTO> listMockRules(@RequestParam(required = false) String filter, Pageable pageable) {
60 +
        return mockRuleService.listMockRulesByPage(filter, pageable);
61 +
    }
62 +
}

@@ -17,14 +17,17 @@
Loading
17 17
18 18
package org.apache.dubbo.admin;
19 19
20 +
import org.apache.dubbo.config.spring.context.annotation.EnableDubbo;
21 +
import org.mybatis.spring.annotation.MapperScan;
20 22
import org.springframework.boot.SpringApplication;
21 23
import org.springframework.boot.autoconfigure.SpringBootApplication;
22 -
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
23 24
import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration;
24 25
25 26
@SpringBootApplication(exclude={
26 -
		DataSourceAutoConfiguration.class, HibernateJpaAutoConfiguration.class
27 +
		HibernateJpaAutoConfiguration.class
27 28
})
29 +
@EnableDubbo(scanBasePackages = {"org.apache.dubbo.admin.provider"})
30 +
@MapperScan(basePackages = {"org.apache.dubbo.admin.mapper"})
28 31
public class DubboAdminApplication {
29 32
30 33
	public static void main(String[] args) {

@@ -0,0 +1,95 @@
Loading
1 +
/*
2 +
 * Licensed to the Apache Software Foundation (ASF) under one or more
3 +
 * contributor license agreements.  See the NOTICE file distributed with
4 +
 * this work for additional information regarding copyright ownership.
5 +
 * The ASF licenses this file to You under the Apache License, Version 2.0
6 +
 * (the "License"); you may not use this file except in compliance with
7 +
 * the License.  You may obtain a copy of the License at
8 +
 *
9 +
 *     http://www.apache.org/licenses/LICENSE-2.0
10 +
 *
11 +
 * Unless required by applicable law or agreed to in writing, software
12 +
 * distributed under the License is distributed on an "AS IS" BASIS,
13 +
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 +
 * See the License for the specific language governing permissions and
15 +
 * limitations under the License.
16 +
 */
17 +
18 +
package org.apache.dubbo.admin.model.dto;
19 +
20 +
import org.apache.dubbo.admin.model.domain.MockRule;
21 +
22 +
import org.springframework.beans.BeanUtils;
23 +
24 +
/**
25 +
 * the dto which provide to front end.
26 +
 */
27 +
public class MockRuleDTO {
28 +
29 +
    private Long id;
30 +
31 +
    private String serviceName;
32 +
33 +
    private String methodName;
34 +
35 +
    private String rule;
36 +
37 +
    private Boolean enable;
38 +
39 +
    public Long getId() {
40 +
        return id;
41 +
    }
42 +
43 +
    public void setId(Long id) {
44 +
        this.id = id;
45 +
    }
46 +
47 +
    public String getRule() {
48 +
        return rule;
49 +
    }
50 +
51 +
    public void setRule(String rule) {
52 +
        this.rule = rule;
53 +
    }
54 +
55 +
    public String getServiceName() {
56 +
        return serviceName;
57 +
    }
58 +
59 +
    public void setServiceName(String serviceName) {
60 +
        this.serviceName = serviceName;
61 +
    }
62 +
63 +
    public String getMethodName() {
64 +
        return methodName;
65 +
    }
66 +
67 +
    public void setMethodName(String methodName) {
68 +
        this.methodName = methodName;
69 +
    }
70 +
71 +
    public Boolean getEnable() {
72 +
        return enable;
73 +
    }
74 +
75 +
    public void setEnable(Boolean enable) {
76 +
        this.enable = enable;
77 +
    }
78 +
79 +
    @Override
80 +
    public String toString() {
81 +
        return "MockRuleDTO{" +
82 +
                "id=" + id +
83 +
                ", serviceName='" + serviceName + '\'' +
84 +
                ", methodName='" + methodName + '\'' +
85 +
                ", rule='" + rule + '\'' +
86 +
                ", enable=" + enable +
87 +
                '}';
88 +
    }
89 +
90 +
    public static MockRuleDTO toMockRuleDTO(MockRule mockRule) {
91 +
        MockRuleDTO mockRuleDTO = new MockRuleDTO();
92 +
        BeanUtils.copyProperties(mockRule, mockRuleDTO);
93 +
        return mockRuleDTO;
94 +
    }
95 +
}

@@ -17,8 +17,6 @@
Loading
17 17
18 18
package org.apache.dubbo.admin.config;
19 19
20 -
import org.apache.commons.lang3.StringUtils;
21 -
22 20
import org.apache.dubbo.admin.common.exception.ConfigurationException;
23 21
import org.apache.dubbo.admin.common.util.Constants;
24 22
import org.apache.dubbo.admin.registry.config.GovernanceConfiguration;
@@ -28,8 +26,9 @@
Loading
28 26
import org.apache.dubbo.admin.registry.metadata.MetaDataCollector;
29 27
import org.apache.dubbo.admin.registry.metadata.impl.NoOpMetadataCollector;
30 28
import org.apache.dubbo.admin.service.impl.InstanceRegistryCache;
29 +
30 +
import org.apache.commons.lang3.StringUtils;
31 31
import org.apache.dubbo.common.URL;
32 -
import org.apache.dubbo.common.config.Environment;
33 32
import org.apache.dubbo.common.extension.ExtensionLoader;
34 33
import org.apache.dubbo.common.logger.Logger;
35 34
import org.apache.dubbo.common.logger.LoggerFactory;
@@ -39,18 +38,12 @@
Loading
39 38
import org.apache.dubbo.registry.RegistryService;
40 39
import org.apache.dubbo.registry.client.ServiceDiscovery;
41 40
import org.apache.dubbo.registry.client.ServiceDiscoveryFactory;
42 -
import org.apache.dubbo.rpc.model.ApplicationModel;
43 -
44 41
import org.springframework.beans.factory.annotation.Value;
45 42
import org.springframework.context.annotation.Bean;
46 43
import org.springframework.context.annotation.Configuration;
47 44
import org.springframework.context.annotation.DependsOn;
48 45
49 46
import java.util.Arrays;
50 -
import java.util.Collections;
51 -
import java.util.Map;
52 -
import java.util.SortedMap;
53 -
import java.util.TreeMap;
54 47
55 48
import static org.apache.dubbo.common.constants.CommonConstants.CLUSTER_KEY;
56 49
import static org.apache.dubbo.registry.client.ServiceDiscoveryFactory.getExtension;
@@ -138,38 +131,9 @@
Loading
138 131
                //throw exception
139 132
            }
140 133
        }
141 -
        initDubboEnvironment();
142 134
        return dynamicConfiguration;
143 135
    }
144 136
145 -
    private void initDubboEnvironment() {
146 -
        Environment env = ApplicationModel.getEnvironment();
147 -
        SortedMap<String, String> sortedMap = new TreeMap<>();
148 -
        if (registryUrl == null) {
149 -
            if (StringUtils.isNotBlank(registryAddress)) {
150 -
                registryUrl = formUrl(registryAddress, registryGroup, registryNameSpace, username, password);
151 -
            }
152 -
        }
153 -
154 -
        if (metadataUrl == null) {
155 -
            if (StringUtils.isNotEmpty(metadataAddress)) {
156 -
                metadataUrl = formUrl(metadataAddress, metadataGroup, metadataGroupNameSpace, username, password);
157 -
                metadataUrl = metadataUrl.addParameter(CLUSTER_KEY, cluster);
158 -
            }
159 -
        }
160 -
        if (registryUrl != null) {
161 -
            sortedMap.put("dubbo.registry.address", registryUrl.toFullString());
162 -
        }
163 -
        if (configCenterUrl != null) {
164 -
            sortedMap.put("dubbo.config-center.address", configCenterUrl.toFullString());
165 -
        }
166 -
        if (metadataUrl != null) {
167 -
            sortedMap.put("dubbo.metadata-report.address", metadataUrl.toFullString());
168 -
        }
169 -
        Map<String, String> map = Collections.unmodifiableSortedMap(sortedMap);
170 -
        env.updateAppConfigMap(map);
171 -
    }
172 -
173 137
    /*
174 138
     * generate registry client
175 139
     */
Files Complexity Coverage
dubbo-admin-server/src/main/java/org/apache/dubbo/admin 18.88% 21.35%
Project Totals (152 files) 18.88% 21.35%

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