Skip to content

Commit

Permalink
Merge pull request apache#1026, fix some bugs reported in dubbo-admin
Browse files Browse the repository at this point in the history
* Fix dubbo-admin, cache refresh problem when service changed
* Fixed apache#972, promotion error of 'batch recover' on 'application' tab
* Fixed apache#466, use relative path when redirect
  • Loading branch information
chickenlj authored Dec 11, 2017
1 parent b9e9240 commit 1d570b0
Show file tree
Hide file tree
Showing 9 changed files with 65 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@
import org.springframework.beans.factory.annotation.Autowired;

import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.atomic.AtomicLong;
Expand All @@ -56,6 +58,12 @@ public class RegistryServerSync implements InitializingBean, DisposableBean, Not
Constants.CHECK_KEY, String.valueOf(false));

private static final AtomicLong ID = new AtomicLong();

/**
* Make sure ID never changed when the same url notified many times
*/
private final ConcurrentHashMap<String, Long> URL_IDS_MAPPER = new ConcurrentHashMap<String, Long>();

// ConcurrentMap<category, ConcurrentMap<servicename, Map<Long, URL>>>
private final ConcurrentMap<String, ConcurrentMap<String, Map<Long, URL>>> registryCache = new ConcurrentHashMap<String, ConcurrentMap<String, Map<Long, URL>>>();
@Autowired
Expand All @@ -81,6 +89,7 @@ public void notify(List<URL> urls) {
}
// Map<category, Map<servicename, Map<Long, URL>>>
final Map<String, Map<String, Map<Long, URL>>> categories = new HashMap<String, Map<String, Map<Long, URL>>>();
String interfaceName = null;
for (URL url : urls) {
String category = url.getParameter(Constants.CATEGORY_KEY, Constants.PROVIDERS_CATEGORY);
if (Constants.EMPTY_PROTOCOL.equalsIgnoreCase(url.getProtocol())) { // 注意:empty协议的group和version为*
Expand All @@ -103,6 +112,9 @@ public void notify(List<URL> urls) {
}
}
} else {
if (StringUtils.isEmpty(interfaceName)) {
interfaceName = url.getServiceInterface();
}
Map<String, Map<Long, URL>> services = categories.get(category);
if (services == null) {
services = new HashMap<String, Map<Long, URL>>();
Expand All @@ -114,15 +126,33 @@ public void notify(List<URL> urls) {
ids = new HashMap<Long, URL>();
services.put(service, ids);
}
ids.put(ID.incrementAndGet(), url);

//保证ID对于同一个URL的不可变
if (URL_IDS_MAPPER.containsKey(url.toFullString())) {
ids.put(URL_IDS_MAPPER.get(url.toFullString()), url);
} else {
long currentId = ID.incrementAndGet();
ids.put(currentId, url);
URL_IDS_MAPPER.putIfAbsent(url.toFullString(), currentId);
}
}
}
if (categories.size() == 0) {
return;
}
for (Map.Entry<String, Map<String, Map<Long, URL>>> categoryEntry : categories.entrySet()) {
String category = categoryEntry.getKey();
ConcurrentMap<String, Map<Long, URL>> services = registryCache.get(category);
if (services == null) {
services = new ConcurrentHashMap<String, Map<Long, URL>>();
registryCache.put(category, services);
} else {// 修复服务下线后不能清除Map缓存的问题:主要针对某唯一的“服务+分组+版本”服务下线,无法触发empty协议,用services.putAll(categoryEntry.getValue())无法清除缓存
Set<String> keys = new HashSet<String>(services.keySet());
for (String key : keys) {
if (Tool.getInterface(key).equals(interfaceName) && !categoryEntry.getValue().entrySet().contains(key)) {
services.remove(key);
}
}
}
services.putAll(categoryEntry.getValue());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#if($_method != "index")$i18n.get($_method)#end $i18n.get($_type)
</h2></div>
<div class="crumbs">
<a href="/">$i18n.get("home")</a> &gt; $i18n.get("governance")
<a href="$rootContextPath.getURI("/")">$i18n.get("home")</a> &gt; $i18n.get("governance")
#if($application && $application != '*')
&gt;
$i18n.get("applications")
Expand All @@ -31,15 +31,17 @@
#if($service && $service != '*')
&gt;
#if($application && $application != '*')
<a href="/governance/applications/$application/services">$i18n.get("services")</a>
<a href="$rootContextPath.getURI("/governance/applications")/$application/services">$i18n.get(
"services")</a>
#else
$i18n.get("services")
#end
&gt; $service
#elseif($address && $address != '*')
&gt;
#if($application && $application != '*')
<a href="/governance/applications/$application/addresses">$i18n.get("addresses")</a>
<a href="$rootContextPath.getURI("/governance/applications")/$application/addresses">$i18n.get(
"addresses")</a>
#else
$i18n.get("addresses")
#end
Expand Down Expand Up @@ -172,7 +174,7 @@
</tr>
</table>
</div>
<form id="favoritesForm" method="POST" action="/governance/favorites/create">
<form id="favoritesForm" method="POST" action="$rootContextPath.getURI("governance/favorites/create")">
<input name="search_name" id="search_name" type="hidden"/>
<input name="search_value" id="search_value" type="hidden"/>
</form>
Expand All @@ -192,7 +194,7 @@
|| keyword == '$i18n.get("please.input.address")') {
keyword = '*';
}
window.location.href = '/governance/' + searchType + '?keyword=' + keyword;
window.location.href = '$rootContextPath.getURI("governance/")' + searchType + '?keyword=' + keyword;
}
function initSearch() {
#if($application && ! $service && ! $address)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<a href="#" onclick="if(! hasCheckbox('ids')) { showAlert('$i18n.get(
"empty.list")'); } else if(! hasChecked('ids')) { showAlert('$i18n.get(
"please.select")'); } else { showConfirm('$i18n.get(
"confirm.batch.fail.mock")', 'applications/0/recover?application=' + getChecked('ids'));} return false;"><img
"confirm.batch.cancel.mock")', 'applications/0/recover?application=' + getChecked('ids'));} return false;"><img
src="$rootContextPath.getURI("images/ico_enable.png")" width="12" height="12"/><span
class="ico_font">$i18n.get("batch.cancel.mock")</span></a>
<span class="ico_line">|</span>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,9 @@
#if($currentUser.role != "G")
<th>$i18n.get("operation")</th>#end
</tr>
#set($providerApplication = "")

#foreach($provider in $providers)
#set($providerApplication = "")
<tr>
<td><input type="checkbox" name="ids" value="$provider.id"/></td>
<td>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
<tr height="42">
<td></td>
<td width="31"><img src="$rootContextPath.getURI("images/pop_close.png")"
onclick="window.location.href = '$redirect';" style="cursor: pointer;" width="20"
onclick="window.location.href = '$rootContextPath.getURI("$redirect")'';"
style="cursor: pointer;" width="20"
height="20"/></td>
</tr>
<tr height="120">
Expand All @@ -15,7 +16,8 @@
</tr>
<tr>
<td align="right">#if(!$success)
<div class="btn_info" style="float: right; clear: left;"><a href="$redirect">$i18n.get("confirm")</a>
<div class="btn_info" style="float: right; clear: left;"><a
href="$rootContextPath.getURI("$redirect")">$i18n.get("confirm")</a>
</div>#end</td>
<td></td>
</tr>
Expand All @@ -26,7 +28,7 @@
#if($success)
sleep(this, 500);
this.NextStep = function () {
window.location.href = '$redirect';
window.location.href = '$rootContextPath.getURI("$redirect")';
}
#end
function sleep(obj, iMinSecond) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
src="$rootContextPath.getURI("images/ico_search.png")" width="12" height="12"/>
</th>
<th width="135">$i18n.get("status"):
<select onchange="searchTable('table_o', 1, this.value);" onclick="searchTable('table_o', 1, this.value);">
<select onchange="searchTable('table_o', 2, this.value);" onclick="searchTable('table_o', 2, this.value);">
<option value="">$i18n.get("all")</option>
#if($application)
<option value="$i18n.get("provided")">$i18n.get("provided")</option>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
</h2>
</div>
<div class="crumbs">
<a href="/">$i18n.get("home")</a> &gt; $i18n.get("system.management")
<a href="$rootContextPath.getURI("/")">$i18n.get("home")</a> &gt; $i18n.get("system.management")
#if($service)
&gt; <a href="../../#if($_method == "show" || $_method == "add")../#elseif($_method ==
"edit")../../#{end}services">$i18n.get("services")</a>
Expand Down Expand Up @@ -60,7 +60,8 @@
#foreach ($tab in $tabs)
#if($tool.checkUrl($currentUser,"/sysinfo/$tab"))
<li id="$tab"#if($_type == $tab) class="active"#else style="color: white;"#end
onclick="window.location.href='/sysinfo/$tab';">$i18n.get($tab)</li>
onclick="window.location.href='$rootContextPath.getURI(
"/sysinfo/$tab")';">$i18n.get($tab)</li>
#end
#end
</ul>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
$i18n.get("NoProvider")
</td>
<td>
<a herf="#" onclick="window.open('/sysinfo/dump/noProviders')">$i18n.get("property.count")
<a herf="#" onclick="window.open('$rootContextPath.getURI("/sysinfo/dump/noProviders")')">$i18n.get(
"property.count")
($noProviderServices.size())</a>
</td>
</tr>
Expand All @@ -22,7 +23,8 @@
$i18n.get("services")
</td>
<td>
<a herf="#" onclick="window.open('/sysinfo/dump/services')">$i18n.get("property.count")
<a herf="#" onclick="window.open('$rootContextPath.getURI("/sysinfo/dump/services")')">$i18n.get(
"property.count")
($services.size())</a>
</td>
</tr>
Expand All @@ -31,7 +33,8 @@
$i18n.get("providers")
</td>
<td>
<a herf="#" onclick="window.open('/sysinfo/dump/providers')">$i18n.get("property.count")
<a herf="#" onclick="window.open('$rootContextPath.getURI("/sysinfo/dump/providers")')">$i18n.get(
"property.count")
($providers.size())</a>
</td>
</tr>
Expand All @@ -40,7 +43,8 @@
$i18n.get("consumers")
</td>
<td>
<a herf="#" onclick="window.open('/sysinfo/dump/consumers')">$i18n.get("property.count")
<a herf="#" onclick="window.open('$rootContextPath.getURI("/sysinfo/dump/consumers")')">$i18n.get(
"property.count")
($consumers.size())</a>
</td>
</tr>
Expand All @@ -50,7 +54,8 @@
</td>
<td>
#set ($client=$providers.size()+$consumers.size())
<a herf="#" onclick="window.open('/sysinfo/dump/versions')">$i18n.get("property.count")($client)</a>
<a herf="#" onclick="window.open('$rootContextPath.getURI("/sysinfo/dump/versions")')">$i18n.get(
"property.count")($client)</a>
</td>
</tr>
</table>
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
<tr height="42">
<td></td>
<td width="31"><img src="$rootContextPath.getURI("images/pop_close.png")"
onclick="window.location.href = '$redirect';" style="cursor: pointer;" width="20"
onclick="window.location.href = 'rootContextPath.getURI("$redirect")';" style="cursor:
pointer;" width="20"
height="20"/></td>
</tr>
<tr height="120">
Expand All @@ -14,7 +15,8 @@
</tr>
<tr>
<td align="right">#if(!$success)
<div class="btn_info" style="float: right; clear: left;"><a href="$redirect">$i18n.get("confirm")</a>
<div class="btn_info" style="float: right; clear: left;"><a
href="rootContextPath.getURI("$redirect")">$i18n.get("confirm")</a>
</div>#end</td>
<td></td>
</tr>
Expand All @@ -25,7 +27,7 @@
#if($success)
sleep(this, 500);
this.NextStep = function () {
window.location.href = '$redirect';
window.location.href = 'rootContextPath.getURI("$redirect")';
}
#end
function sleep(obj, iMinSecond) {
Expand Down

0 comments on commit 1d570b0

Please sign in to comment.