use of com.alibaba.dubbo.registry.common.domain.Override in project dubbo by alibaba.
the class OverrideUtils method overridesToWeights.
public static List<Weight> overridesToWeights(List<Override> overrides) {
List<Weight> weights = new ArrayList<Weight>();
if (overrides == null) {
return weights;
}
for (Override o : overrides) {
if (StringUtils.isEmpty(o.getParams())) {
continue;
} else {
Map<String, String> params = StringUtils.parseQueryString(o.getParams());
for (Map.Entry<String, String> entry : params.entrySet()) {
if (entry.getKey().equals("weight")) {
Weight weight = new Weight();
weight.setAddress(o.getAddress());
weight.setId(o.getId());
weight.setService(o.getService());
weight.setWeight(Integer.valueOf(entry.getValue()));
weights.add(weight);
}
}
}
}
return weights;
}
use of com.alibaba.dubbo.registry.common.domain.Override in project dubbo by alibaba.
the class Tool method getProviderWeight.
public static int getProviderWeight(Provider provider, List<Override> oList) {
for (Override o : oList) {
if (o.isMatch(provider)) {
Map<String, String> params = StringUtils.parseQueryString(o.getParams());
String weight = params.get(Constants.WEIGHT_KEY);
if (weight != null && weight.length() > 0) {
return Integer.parseInt(weight);
}
}
}
return provider.getWeight();
}
use of com.alibaba.dubbo.registry.common.domain.Override in project dubbo by alibaba.
the class Tool method getOverridesMock.
public String getOverridesMock(List<Override> overrides) {
if (overrides != null && overrides.size() > 0) {
for (Override override : overrides) {
Map<String, String> params = StringUtils.parseQueryString(override.getParams());
String mock = params.get("mock");
if (mock != null && mock.length() > 0) {
return mock;
}
}
}
return "";
}
use of com.alibaba.dubbo.registry.common.domain.Override in project dubbo by alibaba.
the class Applications method allmock.
private boolean allmock(Map<String, Object> context, String mock) throws Exception {
String service = (String) context.get("service");
if (service == null || service.length() == 0) {
context.put("message", getMessage("NoSuchOperationData"));
return false;
}
if (!super.currentUser.hasServicePrivilege(service)) {
context.put("message", getMessage("HaveNoServicePrivilege", service));
return false;
}
List<Override> overrides = overrideService.findByService(service);
Override allOverride = null;
if (overrides != null && overrides.size() > 0) {
for (Override override : overrides) {
if (override.isDefault()) {
allOverride = override;
break;
}
}
}
if (allOverride != null) {
Map<String, String> map = StringUtils.parseQueryString(allOverride.getParams());
if (mock == null || mock.length() == 0) {
map.remove("mock");
} else {
map.put("mock", URL.encode(mock));
}
if (map.size() > 0) {
allOverride.setParams(StringUtils.toQueryString(map));
allOverride.setEnabled(true);
allOverride.setOperator(operator);
allOverride.setOperatorAddress(operatorAddress);
overrideService.updateOverride(allOverride);
} else {
overrideService.deleteOverride(allOverride.getId());
}
} else if (mock != null && mock.length() > 0) {
Override override = new Override();
override.setService(service);
override.setParams("mock=" + URL.encode(mock));
override.setEnabled(true);
override.setOperator(operator);
override.setOperatorAddress(operatorAddress);
overrideService.saveOverride(override);
}
return true;
}
use of com.alibaba.dubbo.registry.common.domain.Override in project dubbo by alibaba.
the class Applications method mock.
private boolean mock(Map<String, Object> context, String mock) throws Exception {
String service = (String) context.get("service");
String applications = (String) context.get("application");
if (service == null || service.length() == 0 || applications == null || applications.length() == 0) {
context.put("message", getMessage("NoSuchOperationData"));
return false;
}
if (!super.currentUser.hasServicePrivilege(service)) {
context.put("message", getMessage("HaveNoServicePrivilege", service));
return false;
}
for (String application : SPACE_SPLIT_PATTERN.split(applications)) {
List<Override> overrides = overrideService.findByServiceAndApplication(service, application);
if (overrides != null && overrides.size() > 0) {
for (Override override : overrides) {
Map<String, String> map = StringUtils.parseQueryString(override.getParams());
if (mock == null || mock.length() == 0) {
map.remove("mock");
} else {
map.put("mock", URL.encode(mock));
}
if (map.size() > 0) {
override.setParams(StringUtils.toQueryString(map));
override.setEnabled(true);
override.setOperator(operator);
override.setOperatorAddress(operatorAddress);
overrideService.updateOverride(override);
} else {
overrideService.deleteOverride(override.getId());
}
}
} else if (mock != null && mock.length() > 0) {
Override override = new Override();
override.setService(service);
override.setApplication(application);
override.setParams("mock=" + URL.encode(mock));
override.setEnabled(true);
override.setOperator(operator);
override.setOperatorAddress(operatorAddress);
overrideService.saveOverride(override);
}
}
return true;
}
Aggregations