Skip to content
Permalink
Browse files
Fix application scope condition route (#764)
* fix docker file java_opts

* fix application scope condition route

* fix ci
  • Loading branch information
haoyann committed May 27, 2021
1 parent 1884242 commit 2b04f1adfdfacab3ac20114bdb4b239672772ab8
Showing 6 changed files with 41 additions and 19 deletions.
@@ -23,7 +23,7 @@
import org.apache.dubbo.admin.common.util.Constants;
import org.apache.dubbo.admin.model.dto.AccessDTO;
import org.apache.dubbo.admin.model.dto.ConditionRouteDTO;
import org.apache.dubbo.admin.service.ProviderService;
import org.apache.dubbo.admin.service.ConsumerService;
import org.apache.dubbo.admin.service.RouteService;
import org.apache.dubbo.common.logger.Logger;
import org.apache.dubbo.common.logger.LoggerFactory;
@@ -50,12 +50,12 @@ public class AccessesController {
private static final Logger logger = LoggerFactory.getLogger(AccessesController.class);

private final RouteService routeService;
private final ProviderService providerService;
private final ConsumerService consumerService;

@Autowired
public AccessesController(RouteService routeService, ProviderService providerService) {
public AccessesController(RouteService routeService, ConsumerService consumerService) {
this.routeService = routeService;
this.providerService = providerService;
this.consumerService = consumerService;
}

@RequestMapping(method = RequestMethod.GET)
@@ -99,7 +99,7 @@ public void createAccess(@RequestBody AccessDTO accessDTO, @PathVariable String
throw new ParamValidationException("Either Service or application is required.");
}
String application = accessDTO.getApplication();
if (StringUtils.isNotEmpty(application) && "2.6".equals(providerService.findVersionInApplication(application))) {
if (StringUtils.isNotEmpty(application) && "2.6".equals(consumerService.findVersionInApplication(application))) {
throw new VersionValidationException("dubbo 2.6 does not support application scope blackwhite list config");
}
if (accessDTO.getBlacklist() == null && accessDTO.getWhitelist() == null) {
@@ -27,7 +27,7 @@
import org.apache.dubbo.admin.common.util.ConvertUtil;
import org.apache.dubbo.admin.model.dto.ConditionRouteDTO;
import org.apache.dubbo.admin.model.dto.ConditionRouteResultDTO;
import org.apache.dubbo.admin.service.ProviderService;
import org.apache.dubbo.admin.service.ConsumerService;
import org.apache.dubbo.admin.service.RouteService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
@@ -47,12 +47,12 @@
public class ConditionRoutesController {

private final RouteService routeService;
private final ProviderService providerService;
private final ConsumerService consumerService;

@Autowired
public ConditionRoutesController(RouteService routeService, ProviderService providerService) {
public ConditionRoutesController(RouteService routeService, ConsumerService consumerService) {
this.routeService = routeService;
this.providerService = providerService;
this.consumerService = consumerService;
}

@RequestMapping(method = RequestMethod.POST)
@@ -65,7 +65,7 @@ public boolean createRule(@RequestBody ConditionRouteDTO routeDTO, @PathVariable
if (StringUtils.isEmpty(serviceName) && StringUtils.isEmpty(app)) {
throw new ParamValidationException("serviceName and app is Empty!");
}
if (StringUtils.isNotEmpty(app) && providerService.findVersionInApplication(app).equals("2.6")) {
if (StringUtils.isNotEmpty(app) && consumerService.findVersionInApplication(app).equals("2.6")) {
throw new VersionValidationException("dubbo 2.6 does not support application scope routing rule");
}
routeService.createConditionRoute(routeDTO, serviceVersion, serviceGroup);
@@ -38,4 +38,11 @@ public interface ConsumerService {
* query for all consumer addresses
*/
List<Consumer> findByAddress(String consumerAddress);

/**
* query consumer application version.
* @param application application name.
* @return version.
*/
String findVersionInApplication(String application);
}
@@ -16,11 +16,13 @@
*/
package org.apache.dubbo.admin.service.impl;

import org.apache.dubbo.admin.common.exception.ParamValidationException;
import org.apache.dubbo.admin.common.util.Constants;
import org.apache.dubbo.admin.common.util.SyncUtils;
import org.apache.dubbo.admin.model.domain.Consumer;
import org.apache.dubbo.admin.service.ConsumerService;
import org.apache.dubbo.common.URL;
import org.apache.dubbo.common.utils.StringUtils;
import org.apache.dubbo.metadata.report.identifier.MetadataIdentifier;
import org.springframework.stereotype.Component;

@@ -78,4 +80,18 @@ public Map<String, URL> findConsumerUrlByService(String service) {
return SyncUtils.filterFromCategory(getRegistryCache(), filter);
}

@Override
public String findVersionInApplication(String application) {
Map<String, String> filter = new HashMap<>();
filter.put(Constants.CATEGORY_KEY, Constants.CONSUMERS_CATEGORY);
filter.put(Constants.APPLICATION_KEY, application);
Map<String, URL> stringURLMap = SyncUtils.filterFromCategory(getRegistryCache(), filter);
if (stringURLMap == null || stringURLMap.isEmpty()) {
throw new ParamValidationException("there is no consumer for application: " + application);
}
String defaultVersion = "2.6";
URL url = stringURLMap.values().iterator().next();
String version = url.getParameter(Constants.SPECIFICATION_VERSION_KEY);
return StringUtils.isBlank(version) ? defaultVersion : version;
}
}
@@ -21,9 +21,8 @@
import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.dubbo.admin.AbstractSpringIntegrationTest;
import org.apache.dubbo.admin.model.dto.AccessDTO;
import org.apache.dubbo.admin.model.dto.ConditionRouteDTO;
import org.apache.dubbo.admin.model.dto.ConditionRouteResultDTO;
import org.apache.dubbo.admin.service.ProviderService;
import org.apache.dubbo.admin.service.ConsumerService;
import org.apache.dubbo.admin.service.RouteService;
import org.junit.After;
import org.junit.Test;
@@ -50,7 +49,7 @@ public class AccessesControllerTest extends AbstractSpringIntegrationTest {
@MockBean
private RouteService routeService;
@MockBean
private ProviderService providerService;
private ConsumerService consumerService;
@Autowired
private ObjectMapper objectMapper;

@@ -111,10 +110,10 @@ public void createAccess() {
restTemplate.postForLocation(url("/api/{env}/rules/access"), accessDTO, env);
// when application is present & dubbo's version is 2.6
accessDTO.setApplication(application);
when(providerService.findVersionInApplication(application)).thenReturn("2.6");
when(consumerService.findVersionInApplication(application)).thenReturn("2.6");
restTemplate.postForLocation(url("/api/{env}/rules/access"), accessDTO, env);
// dubbo's version is 2.7
when(providerService.findVersionInApplication(application)).thenReturn("2.7");
when(consumerService.findVersionInApplication(application)).thenReturn("2.7");
restTemplate.postForLocation(url("/api/{env}/rules/access"), accessDTO, env);
// black white list is not null
accessDTO.setBlacklist(new HashSet<>());
@@ -21,7 +21,7 @@
import org.apache.dubbo.admin.common.util.YamlParser;
import org.apache.dubbo.admin.model.dto.ConditionRouteDTO;
import org.apache.dubbo.admin.model.store.RoutingRule;
import org.apache.dubbo.admin.service.ProviderService;
import org.apache.dubbo.admin.service.ConsumerService;
import org.junit.After;
import org.junit.Test;
import org.springframework.boot.test.mock.mockito.MockBean;
@@ -52,7 +52,7 @@ public class ConditionRoutesControllerTest extends AbstractSpringIntegrationTest
private final String env = "whatever";

@MockBean
private ProviderService providerService;
private ConsumerService consumerService;

@After
public void tearDown() throws Exception {
@@ -73,7 +73,7 @@ public void shouldThrowWhenParamInvalid() {
assertThat(responseEntity.getBody(), containsString("serviceName and app is Empty!"));

dto.setApplication("application" + uuid);
when(providerService.findVersionInApplication(dto.getApplication())).thenReturn("2.6");
when(consumerService.findVersionInApplication(dto.getApplication())).thenReturn("2.6");
responseEntity = restTemplate.postForEntity(
url("/api/{env}/rules/route/condition"), dto, String.class, env
);
@@ -100,7 +100,7 @@ public void shouldCreateRule() {
assertThat(responseEntity.getStatusCode(), is(HttpStatus.CREATED));

dto.setApplication(application);
when(providerService.findVersionInApplication(dto.getApplication())).thenReturn("2.7");
when(consumerService.findVersionInApplication(dto.getApplication())).thenReturn("2.7");

responseEntity = restTemplate.postForEntity(
url("/api/{env}/rules/route/condition"), dto, String.class, env

0 comments on commit 2b04f1a

Please sign in to comment.