提交 d985458c 编写于 作者: L liangfei0201

DUBBO-489 修改页面

上级 a989a203
......@@ -18,4 +18,8 @@ public interface OwnerService {
Owner findById(Long id);
void saveOwner(Owner owner);
void deleteOwner(Owner owner);
}
package com.alibaba.dubbo.governance.service.impl;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import com.alibaba.dubbo.governance.service.ConsumerService;
import com.alibaba.dubbo.common.Constants;
import com.alibaba.dubbo.common.utils.StringUtils;
import com.alibaba.dubbo.governance.service.OverrideService;
import com.alibaba.dubbo.governance.service.OwnerService;
import com.alibaba.dubbo.governance.service.ProviderService;
import com.alibaba.dubbo.registry.common.domain.Consumer;
import com.alibaba.dubbo.registry.common.domain.Override;
import com.alibaba.dubbo.registry.common.domain.Owner;
import com.alibaba.dubbo.registry.common.domain.Provider;
......@@ -18,7 +22,7 @@ public class OwnerServiceImpl extends AbstractService implements OwnerService {
ProviderService providerService;
@Autowired
ConsumerService consumerService;
OverrideService overrideService;
public List<String> findAllServiceNames() {
// TODO Auto-generated method stub
......@@ -37,17 +41,13 @@ public class OwnerServiceImpl extends AbstractService implements OwnerService {
public List<Owner> findByService(String serviceName) {
List<Provider> pList = providerService.findByService(serviceName);
List<Consumer> cList = consumerService.findByService(serviceName);
List<Override> cList = overrideService.findByServiceAndAddress(serviceName, Constants.ANYHOST_VALUE);
return toOverrideLiset(pList,cList);
}
public List<Owner> findAll() {
List<Provider> pList = providerService.findAll();
List<Consumer> cList = consumerService.findAll();
List<Override> cList = overrideService.findAll();
return toOverrideLiset(pList,cList);
}
......@@ -56,26 +56,85 @@ public class OwnerServiceImpl extends AbstractService implements OwnerService {
return null;
}
private List<Owner> toOverrideLiset(List<Provider> pList , List<Consumer> cList){
List<Owner> oList = new ArrayList<Owner>();
private List<Owner> toOverrideLiset(List<Provider> pList, List<Override> cList){
Map<String, Owner> oList = new HashMap<String, Owner>();
for(Provider p : pList){
if(p.getUsername() != null){
Owner o = new Owner();
o.setService(p.getService());
o.setUsername(p.getUsername());
oList.add(o);
oList.put(o.getService() + "/" + o.getUsername(), o);
}
}
for(Consumer c : cList){
if(c.getUsername() != null){
for(Override c : cList){
Map<String, String> params = StringUtils.parseQueryString(c.getParams());
String usernames = params.get("owner");
if(usernames != null && usernames.length() > 0){
for (String username : Constants.COMMA_SPLIT_PATTERN.split(usernames)) {
Owner o = new Owner();
o.setService(c.getService());
o.setUsername(c.getUsername());
oList.add(o);
o.setUsername(username);
oList.put(o.getService() + "/" + o.getUsername(), o);
}
}
}
return new ArrayList<Owner>(oList.values());
}
public void saveOwner(Owner owner) {
List<Override> overrides = overrideService.findByServiceAndAddress(owner.getService(), Constants.ANYHOST_VALUE);
if (overrides == null || overrides.size() == 0) {
Override override = new Override();
override.setAddress(Constants.ANYHOST_VALUE);
override.setService(owner.getService());
override.setEnabled(true);
override.setParams("owner=" + owner.getUsername());
overrideService.saveOverride(override);
} else {
for(Override override : overrides){
Map<String, String> params = StringUtils.parseQueryString(override.getParams());
String usernames = params.get("owner");
if (usernames == null || usernames.length() == 0) {
usernames = owner.getUsername();
} else {
usernames = usernames + "," + owner.getUsername();
}
params.put("owner", usernames);
override.setParams(StringUtils.toQueryString(params));
overrideService.updateOverride(override);
}
}
}
public void deleteOwner(Owner owner) {
List<Override> overrides = overrideService.findByServiceAndAddress(owner.getService(), Constants.ANYHOST_VALUE);
if (overrides == null || overrides.size() == 0) {
Override override = new Override();
override.setAddress(Constants.ANYHOST_VALUE);
override.setService(owner.getService());
override.setEnabled(true);
override.setParams("owner=" + owner.getUsername());
overrideService.saveOverride(override);
} else {
for(Override override : overrides){
Map<String, String> params = StringUtils.parseQueryString(override.getParams());
String usernames = params.get("owner");
if (usernames != null && usernames.length() > 0) {
if (usernames.equals(owner.getUsername())) {
params.remove("owner");
} else {
usernames = usernames.replace(owner.getUsername() + ",", "").replace("," + owner.getUsername(), "");
params.put("owner", usernames);
}
if (params.size() > 0) {
override.setParams(StringUtils.toQueryString(params));
overrideService.updateOverride(override);
} else {
overrideService.deleteOverride(override.getId());
}
}
}
}
return oList;
}
}
......@@ -82,7 +82,7 @@ public class Tool {
public static String getHostPrefix(String address) {
if (address != null && address.length() > 0) {
String hostname = getHostName(address);
if (! address.equals(hostname)) {
if (! address.startsWith(hostname)) {
return "(" + hostname + ")";
}
}
......
......@@ -7,14 +7,17 @@
*/
package com.alibaba.dubbo.governance.web.governance.module.screen;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import com.alibaba.dubbo.governance.service.OwnerService;
import com.alibaba.dubbo.governance.service.ProviderService;
import com.alibaba.dubbo.governance.web.common.module.screen.Restful;
import com.alibaba.dubbo.registry.common.domain.Owner;
import com.alibaba.dubbo.registry.common.util.Tool;
/**
* Providers. URI: /services/$service/owners
......@@ -26,6 +29,9 @@ public class Owners extends Restful {
@Autowired
private OwnerService ownerService;
@Autowired
private ProviderService providerService;
public void index(Map<String, Object> context) {
String service = (String) context.get("service");
List<Owner> owners;
......@@ -38,10 +44,46 @@ public class Owners extends Restful {
}
public void add(Map<String, Object> context) {
String service = (String) context.get("service");
if (service == null || service.length() == 0) {
List<String> serviceList = Tool.sortSimpleName(new ArrayList<String>(providerService.findServices()));
context.put("serviceList", serviceList);
}
}
public void create(Owner owner, Map<String, Object> context) {
owner.getUsername();
public boolean create(Owner owner, Map<String, Object> context) {
String service = owner.getService();
String username = owner.getUsername();
if (service == null || service.length() == 0
|| username == null || username.length() == 0){
context.put("message", getMessage("NoSuchOperationData"));
return false;
}
if (! super.currentUser.hasServicePrivilege(service)) {
context.put("message", getMessage("HaveNoServicePrivilege", service));
return false;
}
ownerService.saveOwner(owner);
return true;
}
public boolean delete(Long[] ids, Map<String, Object> context) {
String service = (String) context.get("service");
String username = (String) context.get("username");
Owner owner = new Owner();
owner.setService(service);
owner.setUsername(username);
if (service == null || service.length() == 0
|| username == null || username.length() == 0){
context.put("message", getMessage("NoSuchOperationData"));
return false;
}
if (! super.currentUser.hasServicePrivilege(service)) {
context.put("message", getMessage("HaveNoServicePrivilege", service));
return false;
}
ownerService.deleteOwner(owner);
return true;
}
}
......@@ -186,7 +186,7 @@ public class User extends Entity {
public boolean hasServicePrivilege(String service) {
if (service == null || service.length() == 0)
throw new IllegalArgumentException("service == null");
return false;
if (role == null || GUEST.equalsIgnoreCase(role)) {
return false;
}
......
......@@ -90,7 +90,7 @@
#set($tabs = ["services", "addresses", "overrides"])
#else
#if($_type != "services" && $_type != "applications" && $_type != "addresses")
#set($tabs = ["accesses", "weights", "loadbalances", "routes", "owners", "overrides"])
#set($tabs = ["routes", "overrides", "accesses", "weights", "loadbalances", "owners"])
#end
#end
#if($tabs.size() > 0)
......
......@@ -6,22 +6,21 @@
<table cellpadding="0" cellspacing="0" class="info">
<tr>
<th width="100">$i18n.get("service")&nbsp;&nbsp;<font color='red'>*</font></th>
<td width="300">
<td>
#if($service)
<input type="hidden" id="serviceName" name="service" value="$service" />$service
#else
<textarea id="serviceName" name="service" style="ime-mode:disabled" rows="8" cols="40"></textarea>
<textarea id="serviceName" name="service" style="ime-mode:disabled" rows="2" cols="40"></textarea>
#if ($serviceList && $serviceList.size() > 0)
<select id="selectService" name="selectService" onchange="fnSetService(this)">
<option value="">$i18n.get("Choose")</option>
#foreach ($s in $serviceList)
<option value="$s">$s</option>
<option value="$s">$tool.getSimpleName($s)</option>
#end
</select>
#end
#end
</td>
<td></td>
</tr>
<tr>
<th style="width: 100px;">$i18n.get("ConsumerAddress"):&nbsp;&nbsp;<font color='red'>*</font></th>
......@@ -29,10 +28,10 @@
#if($address)
<input type="hidden" id="address" name="address" value="$tool.getIP($address)" />$tool.getIP($address)
#else
<textarea id="consumerAddress" name="consumerAddress" rows="10" cols="40"></textarea>
<textarea id="consumerAddress" name="consumerAddress" rows="2" cols="40"></textarea>
#end
<font color="blue">$i18n.get("BatchAddressTip")</font>
</td>
<td><font color="blue">$i18n.get("BatchAddressTip")</font></td>
</tr>
<tr>
<th>$i18n.get("status"):</th>
......@@ -41,13 +40,12 @@
<option value="false" selected="selected">$i18n.get("Forbidden")</option>
<option value="true">$i18n.get("Allowed")</option>
</select>
<font color="blue">$i18n.get("AccessControlTip")</font>
</td>
<td><font color="blue">$i18n.get("AccessControlTip")</font></td>
</tr>
<tr>
<th><div class="btn"><a href="#" onclick="if(check()){document.getElementById('accessesForm').submit();}">$i18n.get("save")</a></div></th>
<td></td>
<td></td>
</tr>
</table>
</form>
......
......@@ -71,8 +71,9 @@
<font color="red">$i18n.get("NoProvider")</font>
#end
</td>
#if($currentUser.hasServicePrivilege($consumer.service))
#if($currentUser.role != "G")
<td>
#if($currentUser.hasServicePrivilege($consumer.service))
<a href="consumers/$consumer.id/edit"><img src="$rootContextPath.getURI("images/ico_edit.png")" width="12" height="12" /><span class="ico_font">$i18n.get("edit")</span></a>
<span class="ico_line">|</span>
#if($tool.isInBlackList($consumer))
......@@ -94,6 +95,7 @@
<span class="ico_line">|</span>
<a href="#" onclick="showConfirm('$i18n.get("confirm.fail.mock")', '$consumer.address -&gt; $tool.getSimpleName($consumer.service)', 'consumers/$consumer.id/tolerant'); return false;"><img src="$rootContextPath.getURI("images/ico_run.png")" width="12" height="12" /><span class="ico_font">$i18n.get("fail.mock")</span></a>
#end
#end
</td>
#end
</tr>
......
<div class="ico_btn">
<a href="#if($id)../#end../providers"><img src="$rootContextPath.getURI("images/ico_back.png")" width="12" height="12" /><span class="ico_font">$i18n.get("back")</span></a>
<a href="../owners"><img src="$rootContextPath.getURI("images/ico_back.png")" width="12" height="12" /><span class="ico_font">$i18n.get("back")</span></a>
</div>
<br/>
<form id="providerForm" action="#if($id)../#end../providers" method="POST">
<form id="df" action="../owners" method="POST">
<table cellpadding="0" cellspacing="0" class="info">
#if(! $service)
#if($provider.service)
<input type="hidden" id="service" name="service" value="$!provider.service" />
#else
<tr>
<th style="width: 100px;">$i18n.get("service"):</th>
<td style="width: 300px;"><input id="service" type="text" name="service" class="setting_input" style="width: 200px;" />
<select onchange="fnSetService(this)">
<th style="width: 150px;">$i18n.get("service")&nbsp;&nbsp;<font color='red'>*</font></th>
<td>
#if($service)
<input type="hidden" id="serviceName" name="service" value="$service" />$service
#else
<input id="serviceName" name="service" rows="5" cols="40" maxlength="200">
#if ($serviceList && $serviceList.size() > 0)
<select id="selectService" name="selectService" onchange="fnSetService(this)">
<option value="">$i18n.get("Choose")</option>
#foreach($s in $serviceList)
<option value="$s">$s</option>
#foreach ($s in $serviceList)
<option value="$s">$tool.getSimpleName($s)</option>
#end
</select>
</td>
</tr>
#end
#end
<tr>
<th style="width: 100px;">$i18n.get("url"):</th>
<td><input type="text" id="url" name="url" value="#if($provider.url)$!provider.url?$!provider.parameters#{else}dubbo://#if($address)$address#{else}0.0.0.0:20880#end/#if($service)$service#{else}com.xxx.XxxService#end?application=#if($application)$application#{else}xxx#end&version=1.0.0#end" class="setting_input" style="width: 700px;" maxlength="2000"/></td>
</tr>
<tr>
<th>$i18n.get("type"):</th>
<td><font color="blue">$i18n.get("static")</font></td>
</td>
</tr>
<tr>
<th>$i18n.get("status"): </th>
<td>
<select name="enabled">
<option value="true">$i18n.get("enable")</option>
<option value="false" selected="selected">$i18n.get("disable")</option>
</select>
</td>
<th style="width: 150px;">$i18n.get("Username")&nbsp;&nbsp;<font color='red'>*</font></th>
<td><input type="text" id="username" name="username" style="ime-mode:disabled" value="$operator" maxlength="100"/></td>
</tr>
<tr>
<th><div class="btn"><a href="#" onclick="if(check()){document.getElementById('providerForm').submit();}">$i18n.get("save")</a></div></th>
<th><div class="btn"><a href="#" onclick="if(check()){document.getElementById('df').submit();}">$i18n.get("save")</a></div></th>
<td></td>
</tr>
</table>
</form>
<script type="text/javascript">
//通过服务名后面的选择框,快速设置service_name的值
function fnSetService(obj){
if(obj.value != ''){
var old = document.getElementById('service').value;
if (old == '') {
old = "com.xxx.XxxService";
}
byId('url').value = byId('url').value.replace(old, obj.value);
document.getElementById('service').value = obj.value;
}
}
function check(){
#if(! $service)
var service = byId('service').value.trim();
if(service == '') {
showAlert("$i18n.get("PleaseInput")$i18n.get("service")", 'service');
return false;
}
#end
var url = byId('url').value.trim();
if(url == '' || url.indexOf('0.0.0.0') > 0 || url.indexOf('com.xxx.XxxService') > 0 || url.indexOf('application=xxx') > 0){
showAlert("$i18n.get("PleaseInput")$i18n.get("url")", 'url');
<script language="javascript">
function check(){
var username = byId('username').value.trim();
if(username == ''){
showAlert("$i18n.get("PleaseInput")$i18n.get("Username")", 'username');
return false;
}
return true;
}
function fnSetService(obj){
if(obj.value!=''){
byId('serviceName').value = obj.value;
}
}
</script>
\ No newline at end of file
<div class="ico_btn">
#if($currentUser.role != "G")
<a href="owners/add"><img src="$rootContextPath.getURI("images/ico_add.png")" width="12" height="12" /><span class="ico_font">$i18n.get("add")</span></a>
#end
</div>
<br/>
<table cellpadding="0" cellspacing="0" class="list list_dubbo" id="table_o">
<tr>
......@@ -5,6 +10,7 @@
#if(! $service)
<th>$i18n.get("service"): <input type="text" onkeyup="searchTable('table_o', 2, this.value);" onclick="searchTable('table_o', 2, this.value);" />&nbsp;<img src="$rootContextPath.getURI("images/ico_search.png")" width="12" height="12" /></th>
#end
#if($currentUser.role != "G")<th>$i18n.get("operation")</th>#end
</tr>
#foreach($owner in $owners)
<tr>
......@@ -12,6 +18,13 @@
#if(! $service)
<td><a href="services/$owner.service/owners">$owner.service</a></td>
#end
#if($currentUser.role != "G")
<td>
#if($currentUser.hasServicePrivilege($owner.service))
<a href="#" onclick="showConfirm('$i18n.get("confirm.delete")', '$owner.username', 'owners/0/delete?username=$owner.username#if(! $service)&service=$owner.service#end'); return false;"><img src="$rootContextPath.getURI("images/ico_delete.png")" width="12" height="12" /><span class="ico_font">$i18n.get("delete")</span></a>
#end
</td>
#end
</tr>
#end
</table>
......
......@@ -14,7 +14,7 @@
<select onchange="fnSetService(this)">
<option value="">$i18n.get("Choose")</option>
#foreach($s in $serviceList)
<option value="$s">$s</option>
<option value="$s">$tool.getSimpleName($s)</option>
#end
</select>
</td>
......
......@@ -64,8 +64,9 @@
<font color="green">$i18n.get("ok")</font>
#end
</td>
#if($currentUser.hasServicePrivilege($provider.service))
#if($currentUser.role != "G")
<td>
#if($currentUser.hasServicePrivilege($provider.service))
<a href="providers/$provider.id/edit"><img src="$rootContextPath.getURI("images/ico_edit.png")" width="12" height="12" /><span class="ico_font">$i18n.get("edit")</span></a>
<span class="ico_line">|</span>
<a href="providers/$provider.id/add"><img src="$rootContextPath.getURI("images/ico_add.png")" width="12" height="12" /><span class="ico_font">$i18n.get("copy")</span></a>
......@@ -83,6 +84,7 @@
<span class="ico_line">|</span>
<a href="#" onclick="showConfirm('$i18n.get("confirm.delete")', '$provider.url', 'providers/$provider.id/delete'); return false;"><img src="$rootContextPath.getURI("images/ico_delete.png")" width="12" height="12" /><span class="ico_font">$i18n.get("delete")</span></a>
#end
#end
</td>
#end
</tr>
......
......@@ -10,12 +10,12 @@
#if($service)
<input type="hidden" id="multiservice" name="service" value="$service" />$service
#else
<textarea id="service" name="multiservice" style="ime-mode:disabled" rows="10" cols="40"></textarea>
<textarea id="service" name="multiservice" style="ime-mode:disabled" rows="2" cols="40"></textarea>
#if ($serviceList && $serviceList.size() > 0)
<select id="selectService" name="selectService" onchange="fnSetService(this)">
<option value="">$i18n.get("Choose")</option>
#foreach ($s in $serviceList)
<option value="$s">$s</option>
<option value="$s">$tool.getSimpleName($s)</option>
#end
</select>
#end
......@@ -28,15 +28,16 @@
#if($address)
<input type="hidden" id="address" name="address" value="$tool.getIP($address)" />$tool.getIP($address)
#else
<textarea id="address" name="address" rows="10" cols="30"></textarea><font color="blue">$i18n.get("BatchAddressTip")</font>
<textarea id="address" name="address" rows="2" cols="40"></textarea>
#if ($addressList && $addressList.size() > 0)
<select id="selectAddeess" name="selectAddeess" onchange="fnSetService(this,'address')">
<select id="selectAddeess" name="selectAddeess" onchange="fnSetAddress(this)">
<option value="">$i18n.get("Choose")</option>
#foreach ($s in $addressList)
<option value="$s">$tool.getHostPrefix($s)$s</option>
#end
</select>
#end
<font color="blue">$i18n.get("BatchAddressTip")</font>
#end
</td>
</tr>
......@@ -64,6 +65,12 @@ function fnSetService(obj){
}
}
function fnSetAddress(obj){
if(obj.value!=''){
byId('address').value = (byId('address').value.length > 0 ? byId('address').value + "\n" : "" ) + obj.value;
}
}
function checkService(service) {
//if(service.indexOf(',') != -1) return false;
......
......@@ -54,12 +54,12 @@
<li id="unique_tab1" ><a href="$rootContextPath.getURI("/")">$i18n.get("home")</a></li>
<li id="unique_tab2" class="sub_nav"><a href="#" onclick="return false;" style="cursor:default;">$i18n.get("governance")</a>
<ul>
#if($tool.checkUrl($currentUser,"/governance/routes"))<li><a href="$rootContextPath.getURI("/governance/routes")">$i18n.get("routes")</a></li>#end
#if($tool.checkUrl($currentUser,"/governance/overrides"))<li><a href="$rootContextPath.getURI("/governance/overrides")">$i18n.get("overrides")</a></li>#end
#if($tool.checkUrl($currentUser,"/governance/accesses"))<li><a href="$rootContextPath.getURI("/governance/accesses")">$i18n.get("accesses")</a></li>#end
#if($tool.checkUrl($currentUser,"/governance/weights"))<li><a href="$rootContextPath.getURI("/governance/weights")">$i18n.get("weights")</a></li>#end
#if($tool.checkUrl($currentUser,"/governance/loadbalances"))<li><a href="$rootContextPath.getURI("/governance/loadbalances")">$i18n.get("loadbalances")</a></li>#end
#if($tool.checkUrl($currentUser,"/governance/routes"))<li><a href="$rootContextPath.getURI("/governance/routes")">$i18n.get("routes")</a></li>#end
#if($tool.checkUrl($currentUser,"/governance/owners"))<li><a href="$rootContextPath.getURI("/governance/owners")">$i18n.get("owners")</a></li>#end
#if($tool.checkUrl($currentUser,"/governance/overrides"))<li><a href="$rootContextPath.getURI("/governance/overrides")">$i18n.get("overrides")</a></li>#end
</ul>
</li>
<li id="unique_tab3" class="sub_nav"><a href="#" onclick="return false;" style="cursor:default;">$i18n.get("system.management")</a>
......
......@@ -124,11 +124,11 @@ $control.setTemplate("home:menu.vm")
<td style="padding-left: 10px;">
<a href="$rootContextPath.getURI("governance/providers/add")">$i18n.get("providers")</a>&nbsp;
<a href="$rootContextPath.getURI("governance/routes/add")">$i18n.get("routes")</a>&nbsp;
<a href="$rootContextPath.getURI("governance/overrides/add")">$i18n.get("overrides")</a>&nbsp;
<a href="$rootContextPath.getURI("governance/accesses/add")">$i18n.get("accesses")</a>&nbsp;
<a href="$rootContextPath.getURI("governance/weights/add")">$i18n.get("weights")</a>&nbsp;
<a href="$rootContextPath.getURI("governance/loadbalances/add")">$i18n.get("loadbalances")</a>&nbsp;
<a href="$rootContextPath.getURI("governance/owners/add")">$i18n.get("owners")</a>&nbsp;
<a href="$rootContextPath.getURI("governance/overrides/add")">$i18n.get("overrides")</a>&nbsp;
</td>
</tr>
<tr>
......@@ -164,7 +164,7 @@ $control.setTemplate("home:menu.vm")
|| keyword == '$i18n.get("please.input.address")') {
keyword = '*';
}
window.location.href = 'governance/' + searchType + '?keyword=' + keyword;
window.location.href = '$rootContextPath.getURI("governance")/' + searchType + '?keyword=' + keyword;
}
function setTab2(name, cursel, n) {
var obj = document.getElementById('searchContent');
......
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GB18030">
<title>Insert title here</title>
<script type="text/javascript">
window.location.href='index/'
</script>
</head>
<body>
</body>
</html>
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册