Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] Dubbo Admin provides service mock ability. #838

Merged
merged 24 commits into from
Nov 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
0c3e600
commit the API
brotherlu-xcq Aug 24, 2021
8269157
develop the front page.
brotherlu-xcq Aug 25, 2021
ae554c5
add edit logic
brotherlu-xcq Aug 25, 2021
4a128bd
develop the front page and test.
brotherlu-xcq Aug 26, 2021
06a617b
ui change
brotherlu-xcq Aug 31, 2021
e8c87f5
change the config key and group
brotherlu-xcq Sep 1, 2021
e844fdd
change rule enable to config center.
brotherlu-xcq Sep 3, 2021
1b67bf6
update GlobalMockRule update logic.
brotherlu-xcq Sep 3, 2021
c5febb3
remove the GlobalMockRule
brotherlu-xcq Sep 8, 2021
37c1175
[feature admin mock] move the diver dependency out of the project.
brotherlu-xcq Sep 13, 2021
199ac2c
[feature admin mock] remove the contributor name and date in javadoc.
brotherlu-xcq Sep 13, 2021
45bc9ad
[feature admin mock] optimize the delete mock rule step.
brotherlu-xcq Sep 27, 2021
5268eb3
[feature admin mock] fix the dialog cannot be closed when delete succ…
brotherlu-xcq Sep 27, 2021
69bd103
[feature admin mock] add the support for h2 database.
brotherlu-xcq Oct 8, 2021
e3da8a7
[feature admin mock] rollback to zookeeper registry.
brotherlu-xcq Oct 13, 2021
3af2a15
[feature admin mock] fix properties.
brotherlu-xcq Oct 19, 2021
93518de
[feature admin mock] change mock-admin-api maven version.
brotherlu-xcq Oct 22, 2021
570d471
Merge branch 'develop' of https://github.com/brotherlu-xcq/dubbo-admi…
brotherlu-xcq Oct 24, 2021
fa2013f
[feature admin mock] fix the feedback and add the parameters in docke…
brotherlu-xcq Oct 25, 2021
4c93e1e
Merge branch 'feature-#mock' of https://github.com/brotherlu-xcq/dubb…
brotherlu-xcq Oct 25, 2021
1c629c9
[feature admin mock] fix the ci problem.
brotherlu-xcq Nov 2, 2021
3daa11c
[feature admin mock] fix the ci problem.
brotherlu-xcq Nov 2, 2021
e4b4c57
[feature admin mock] removed unused import.
brotherlu-xcq Nov 2, 2021
fb9ab7a
[feature admin mock] add license.
brotherlu-xcq Nov 2, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docker/latest/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ RUN apt-get update && apt-get install -y tini
COPY --from=0 /source/dubbo-admin-snapshot/dubbo-admin-distribution/target/dubbo-admin-0.3.0-SNAPSHOT.jar /app.jar
COPY --from=0 /source/dubbo-admin-snapshot/docker/entrypoint.sh /usr/local/bin/entrypoint.sh

ENV JAVA_OPTS ""
ENV JAVA_OPTS "-Dloader.path=/opt-libs"

ENTRYPOINT ["tini", "--", "/usr/local/bin/entrypoint.sh"]
EXPOSE 8080
15 changes: 14 additions & 1 deletion docker/stack.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,20 @@ services:
- zookeeper
ports:
- 8080:8080
# the db driver path
volumes:
- "/mnt/opt-libs:/opt-libs"
environment:
- admin.registry.address=zookeeper://zookeeper:2181
- admin.config-center=zookeeper://zookeeper:2181
- admin.metadata-report.address=zookeeper://zookeeper:2181
- admin.metadata-report.address=zookeeper://zookeeper:2181
- dubbo.application.name=dubbo-admin
- dubbo.registry.address=zookeeper://zookeeper:2181
- mybatis-plus.global-config.db-config.id-type=none
- spring.datasource.driver-class-name=com.mysql.jdbc.Driver
- spring.datasource.url=jdbc:mysql://xxx:3306/dubbo-admin?characterEncoding=utf8&connectTimeout=1000&socketTimeout=10000&autoReconnect=true
- spring.datasource.username=root
- spring.datasource.password=mysql
# use internal h2 as database
# - spring.datasource.url=jdbc:h2:mem:~/dubbo-admin;
# - spring.datasource.username=sa
18 changes: 18 additions & 0 deletions dubbo-admin-distribution/src/bin/config/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,21 @@ admin.check.sessionTimeoutMilli=3600000
server.compression.enabled=true
server.compression.mime-types=text/css,text/javascript,application/javascript
server.compression.min-response-size=10240

#dubbo config
dubbo.application.name=dubbo-admin
dubbo.registry.address=${admin.registry.address}

# mysql
#spring.datasource.driver-class-name=com.mysql.jdbc.Driver
#spring.datasource.url=jdbc:mysql://localhost:3306/dubbo-admin?characterEncoding=utf8&connectTimeout=1000&socketTimeout=10000&autoReconnect=true
#spring.datasource.username=root
#spring.datasource.password=mysql

# h2
spring.datasource.url=jdbc:h2:mem:~/dubbo-admin;
spring.datasource.username=sa
spring.datasource.password=

# id generate type
mybatis-plus.global-config.db-config.id-type=none
2 changes: 1 addition & 1 deletion dubbo-admin-distribution/src/bin/startup.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@ set SERVER=dubbo-admin

set "JAVA_OPT=%JAVA_OPT% -Xms512m -Xmx512m -Xmn256m"

set "JAVA_OPT=%JAVA_OPT% -jar %BASE_DIR%\lib\%SERVER%.jar"
set "JAVA_OPT=%JAVA_OPT% -Dloader.path=%BASE_DIR%\opt-libs -jar %BASE_DIR%\lib\%SERVER%.jar"

call "%JAVA%" %JAVA_OPT% dubbo.admin %*
4 changes: 2 additions & 2 deletions dubbo-admin-distribution/src/bin/startup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,6 @@ if [ ! -f "${BASE_DIR}/logs/start.out" ]; then
fi

JAVA_OPT="${JAVA_OPT} -Xms512m -Xmx512m -Xmn256m"
JAVA_OPT="${JAVA_OPT} -jar ${BASE_DIR}/lib/${SERVER}.jar"
nohup $JAVA ${JAVA_OPT} dubbo.admin >> ${BASE_DIR}/logs/catlog.out 2>&1 &
JAVA_OPT="${JAVA_OPT} -Dloader.path=${BASE_DIR}/opt-libs -jar ${BASE_DIR}/lib/${SERVER}.jar"
nohup "$JAVA" ${JAVA_OPT} dubbo.admin >> ${BASE_DIR}/logs/catlog.out 2>&1 &
echo "${SERVER} is starting,you can check the ${BASE_DIR}/logs/catlog.out"
27 changes: 27 additions & 0 deletions dubbo-admin-server/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,30 @@
<version>${jjwt-version}</version>
</dependency>


<dependency>
<groupId>org.apache.dubbo.extensions</groupId>
<artifactId>dubbo-mock-api</artifactId>
</dependency>

<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
</dependency>

<!-- the mysql db driver need user put it in /opt-libs path -->
<!-- <dependency>-->
<!-- <groupId>mysql</groupId>-->
<!-- <artifactId>mysql-connector-java</artifactId>-->
<!-- <version>5.1.49</version>-->
<!-- <scope>provided</scope>-->
<!-- </dependency>-->

<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>
</dependencies>

<build>
Expand All @@ -212,6 +236,9 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>2.0.2.RELEASE</version>
<configuration>
<layout>ZIP</layout>
</configuration>
<executions>
<execution>
<phase>package</phase>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,17 @@

package org.apache.dubbo.admin;

import org.apache.dubbo.config.spring.context.annotation.EnableDubbo;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration;

@SpringBootApplication(exclude={
DataSourceAutoConfiguration.class, HibernateJpaAutoConfiguration.class
HibernateJpaAutoConfiguration.class
})
@EnableDubbo(scanBasePackages = {"org.apache.dubbo.admin.provider"})
@MapperScan(basePackages = {"org.apache.dubbo.admin.mapper"})
public class DubboAdminApplication {

public static void main(String[] args) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@

package org.apache.dubbo.admin.config;

import org.apache.commons.lang3.StringUtils;

import org.apache.dubbo.admin.common.exception.ConfigurationException;
import org.apache.dubbo.admin.common.util.Constants;
import org.apache.dubbo.admin.registry.config.GovernanceConfiguration;
Expand All @@ -28,8 +26,9 @@
import org.apache.dubbo.admin.registry.metadata.MetaDataCollector;
import org.apache.dubbo.admin.registry.metadata.impl.NoOpMetadataCollector;
import org.apache.dubbo.admin.service.impl.InstanceRegistryCache;

import org.apache.commons.lang3.StringUtils;
import org.apache.dubbo.common.URL;
import org.apache.dubbo.common.config.Environment;
import org.apache.dubbo.common.extension.ExtensionLoader;
import org.apache.dubbo.common.logger.Logger;
import org.apache.dubbo.common.logger.LoggerFactory;
Expand All @@ -39,18 +38,12 @@
import org.apache.dubbo.registry.RegistryService;
import org.apache.dubbo.registry.client.ServiceDiscovery;
import org.apache.dubbo.registry.client.ServiceDiscoveryFactory;
import org.apache.dubbo.rpc.model.ApplicationModel;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.DependsOn;

import java.util.Arrays;
import java.util.Collections;
import java.util.Map;
import java.util.SortedMap;
import java.util.TreeMap;

import static org.apache.dubbo.common.constants.CommonConstants.CLUSTER_KEY;
import static org.apache.dubbo.registry.client.ServiceDiscoveryFactory.getExtension;
Expand Down Expand Up @@ -138,38 +131,9 @@ GovernanceConfiguration getDynamicConfiguration() {
//throw exception
}
}
initDubboEnvironment();
return dynamicConfiguration;
}

private void initDubboEnvironment() {
Environment env = ApplicationModel.getEnvironment();
SortedMap<String, String> sortedMap = new TreeMap<>();
if (registryUrl == null) {
if (StringUtils.isNotBlank(registryAddress)) {
registryUrl = formUrl(registryAddress, registryGroup, registryNameSpace, username, password);
}
}

if (metadataUrl == null) {
if (StringUtils.isNotEmpty(metadataAddress)) {
metadataUrl = formUrl(metadataAddress, metadataGroup, metadataGroupNameSpace, username, password);
metadataUrl = metadataUrl.addParameter(CLUSTER_KEY, cluster);
}
}
if (registryUrl != null) {
sortedMap.put("dubbo.registry.address", registryUrl.toFullString());
}
if (configCenterUrl != null) {
sortedMap.put("dubbo.config-center.address", configCenterUrl.toFullString());
}
if (metadataUrl != null) {
sortedMap.put("dubbo.metadata-report.address", metadataUrl.toFullString());
}
Map<String, String> map = Collections.unmodifiableSortedMap(sortedMap);
env.updateAppConfigMap(map);
}

/*
* generate registry client
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.dubbo.admin.controller;

import org.apache.dubbo.admin.annotation.Authority;
import org.apache.dubbo.admin.model.dto.MockRuleDTO;
import org.apache.dubbo.admin.service.MockRuleService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
* Mock Rule Controller.
*/
@Authority(needLogin = true)
@RestController
@RequestMapping("/api/{env}/mock/rule")
public class MockRuleController {

@Autowired
private MockRuleService mockRuleService;

@PostMapping
public boolean createOrUpdateMockRule(@RequestBody MockRuleDTO mockRule) {
mockRuleService.createOrUpdateMockRule(mockRule);
return true;
}

@DeleteMapping
public boolean deleteMockRule(@RequestBody MockRuleDTO mockRule) {
mockRuleService.deleteMockRuleById(mockRule.getId());
return true;
}

@GetMapping("/list")
public Page<MockRuleDTO> listMockRules(@RequestParam(required = false) String filter, Pageable pageable) {
return mockRuleService.listMockRulesByPage(filter, pageable);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.dubbo.admin.mapper;

import org.apache.dubbo.admin.model.domain.MockRule;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;

/**
* The database operator of mock rule.
*/
public interface MockRuleMapper extends BaseMapper<MockRule> {
}
Loading