diff --git a/52.Dubbo-OPS-Mointor/dubbo-admin/pom.xml b/52.Dubbo-OPS-Mointor/dubbo-admin/pom.xml
new file mode 100644
index 0000000..8639254
--- /dev/null
+++ b/52.Dubbo-OPS-Mointor/dubbo-admin/pom.xml
@@ -0,0 +1,80 @@
+
+
+ 4.0.0
+
+ com.alibaba
+ dubbo-admin
+ 0.0.1-SNAPSHOT
+ jar
+
+ dubbo-admin
+ Demo project for Spring Boot
+
+
+ org.springframework.boot
+ spring-boot-starter-parent
+ 2.0.2.RELEASE
+
+
+
+
+ UTF-8
+ UTF-8
+ 1.8
+
+
+
+
+ org.springframework.boot
+ spring-boot-starter-web
+
+
+
+ org.springframework.boot
+ spring-boot-starter-test
+ test
+
+
+
+ com.alibaba.boot
+ velocity-spring-boot-starter
+ 0.1.0
+
+
+
+ org.apache.commons
+ commons-lang3
+ 3.7
+
+
+
+ com.alibaba
+ dubbo
+ 2.6.2
+
+
+
+ org.apache.curator
+ curator-framework
+ 2.12.0
+
+
+ com.alibaba
+ fastjson
+ 1.2.46
+
+
+
+
+
+
+
+ org.springframework.boot
+ spring-boot-maven-plugin
+
+
+
+
+
+
diff --git a/52.Dubbo-OPS-Mointor/dubbo-admin/src/main/java/com/alibaba/dubboadmin/DubboAdminApplication.java b/52.Dubbo-OPS-Mointor/dubbo-admin/src/main/java/com/alibaba/dubboadmin/DubboAdminApplication.java
new file mode 100644
index 0000000..58ba7c3
--- /dev/null
+++ b/52.Dubbo-OPS-Mointor/dubbo-admin/src/main/java/com/alibaba/dubboadmin/DubboAdminApplication.java
@@ -0,0 +1,33 @@
+/*
+ * 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 com.alibaba.dubboadmin;
+
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.context.ApplicationContext;
+
+@SpringBootApplication
+public class DubboAdminApplication {
+
+ public static void main(String[] args) {
+ ApplicationContext act = SpringApplication.run(DubboAdminApplication.class, args);
+ SpringUtil.setApplicationContext(act);
+
+
+ }
+}
diff --git a/52.Dubbo-OPS-Mointor/dubbo-admin/src/main/java/com/alibaba/dubboadmin/SpringUtil.java b/52.Dubbo-OPS-Mointor/dubbo-admin/src/main/java/com/alibaba/dubboadmin/SpringUtil.java
new file mode 100644
index 0000000..c390c09
--- /dev/null
+++ b/52.Dubbo-OPS-Mointor/dubbo-admin/src/main/java/com/alibaba/dubboadmin/SpringUtil.java
@@ -0,0 +1,60 @@
+/*
+ * 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 com.alibaba.dubboadmin;
+
+
+import com.alibaba.dubbo.common.logger.Logger;
+import com.alibaba.dubbo.common.logger.LoggerFactory;
+
+import org.springframework.context.ApplicationContext;
+
+public class SpringUtil {
+
+ public static final Logger logger = LoggerFactory.getLogger(SpringUtil.class);
+ private static ApplicationContext applicationContext = null;
+
+ public static void setApplicationContext(ApplicationContext applicationContext){
+ if(SpringUtil.applicationContext == null){
+ logger.info("set applicationcontext");
+ SpringUtil.applicationContext = applicationContext;
+ }
+
+ }
+
+ //获取applicationContext
+ public static ApplicationContext getApplicationContext() {
+ return applicationContext;
+ }
+
+ //通过name获取 Bean.
+ public static Object getBean(String name){
+ return getApplicationContext().getBean(name);
+
+ }
+
+ //通过class获取Bean.
+ public static T getBean(Class clazz){
+ return getApplicationContext().getBean(clazz);
+ }
+
+ //通过name,以及Clazz返回指定的Bean
+ public static T getBean(String name,Class clazz){
+ return getApplicationContext().getBean(name, clazz);
+ }
+
+}
diff --git a/52.Dubbo-OPS-Mointor/dubbo-admin/src/main/java/com/alibaba/dubboadmin/config/I18nConfig.java b/52.Dubbo-OPS-Mointor/dubbo-admin/src/main/java/com/alibaba/dubboadmin/config/I18nConfig.java
new file mode 100644
index 0000000..669949d
--- /dev/null
+++ b/52.Dubbo-OPS-Mointor/dubbo-admin/src/main/java/com/alibaba/dubboadmin/config/I18nConfig.java
@@ -0,0 +1,58 @@
+/*
+ * 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 com.alibaba.dubboadmin.config;
+
+import java.util.Locale;
+
+import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.ComponentScan;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.web.servlet.LocaleResolver;
+import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
+import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
+import org.springframework.web.servlet.i18n.LocaleChangeInterceptor;
+import org.springframework.web.servlet.i18n.SessionLocaleResolver;
+
+
+@Configuration
+@EnableAutoConfiguration
+@ComponentScan
+//@ImportResource({"classpath*:dubbo-admin.xml"})
+public class I18nConfig implements WebMvcConfigurer {
+
+ @Bean
+ public LocaleResolver localeResolver() {
+ SessionLocaleResolver sessionLocaleResolver = new SessionLocaleResolver();
+ sessionLocaleResolver.setDefaultLocale(Locale.CHINA);
+ return sessionLocaleResolver;
+
+ }
+
+ @Bean
+ public LocaleChangeInterceptor localeChangeInterceptor() {
+ LocaleChangeInterceptor lci = new LocaleChangeInterceptor();
+ lci.setParamName("lang");
+ return lci;
+ }
+
+ @Override
+ public void addInterceptors(InterceptorRegistry registry) {
+ registry.addInterceptor(localeChangeInterceptor());
+ }
+}
diff --git a/52.Dubbo-OPS-Mointor/dubbo-admin/src/main/java/com/alibaba/dubboadmin/config/XmlConfiguration.java b/52.Dubbo-OPS-Mointor/dubbo-admin/src/main/java/com/alibaba/dubboadmin/config/XmlConfiguration.java
new file mode 100644
index 0000000..9c94a83
--- /dev/null
+++ b/52.Dubbo-OPS-Mointor/dubbo-admin/src/main/java/com/alibaba/dubboadmin/config/XmlConfiguration.java
@@ -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 com.alibaba.dubboadmin.config;
+
+import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.ImportResource;
+
+
+@Configuration
+@ImportResource({"classpath*:dubbo-admin.xml"})
+public class XmlConfiguration {
+
+}
diff --git a/52.Dubbo-OPS-Mointor/dubbo-admin/src/main/java/com/alibaba/dubboadmin/filter/LoginFilter.java b/52.Dubbo-OPS-Mointor/dubbo-admin/src/main/java/com/alibaba/dubboadmin/filter/LoginFilter.java
new file mode 100644
index 0000000..fe6c3aa
--- /dev/null
+++ b/52.Dubbo-OPS-Mointor/dubbo-admin/src/main/java/com/alibaba/dubboadmin/filter/LoginFilter.java
@@ -0,0 +1,232 @@
+/*
+ * 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 com.alibaba.dubboadmin.filter;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.UUID;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import javax.servlet.Filter;
+import javax.servlet.FilterChain;
+import javax.servlet.FilterConfig;
+import javax.servlet.ServletException;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+import javax.servlet.http.Cookie;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import com.alibaba.dubbo.common.logger.Logger;
+import com.alibaba.dubbo.common.logger.LoggerFactory;
+import com.alibaba.dubbo.common.utils.StringUtils;
+import com.alibaba.dubboadmin.governance.service.UserService;
+import com.alibaba.dubboadmin.governance.util.WebConstants;
+import com.alibaba.dubboadmin.registry.common.domain.User;
+import com.alibaba.dubboadmin.registry.common.util.Coder;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+@Component
+public class LoginFilter implements Filter{
+
+ private static final Logger logger = LoggerFactory.getLogger(LoginFilter.class);
+ private static Pattern PARAMETER_PATTERN = Pattern.compile("(\\w+)=[\"]?([^,\"]+)[\"]?[,]?\\s*");
+ private static final String BASIC_CHALLENGE = "Basic";
+ private static final String DIGEST_CHALLENGE = "Digest";
+ private static final String CHALLENGE = BASIC_CHALLENGE;
+ private static final String REALM = User.REALM;
+
+ @Autowired
+ private UserService userService;
+ private String logout = "/logout";
+ private String logoutCookie = "logout";
+
+ static Map parseParameters(String query) {
+ Matcher matcher = PARAMETER_PATTERN.matcher(query);
+ Map map = new HashMap();
+ while (matcher.find()) {
+ String key = matcher.group(1);
+ String value = matcher.group(2);
+ map.put(key, value);
+ }
+ return map;
+ }
+
+ static byte[] readToBytes(InputStream in) throws IOException {
+ byte[] buf = new byte[in.available()];
+ in.read(buf);
+ return buf;
+ }
+
+ @Override
+ public void init(FilterConfig filterConfig) throws ServletException {
+
+ }
+
+ @Override
+ public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
+ throws IOException, ServletException {
+
+ HttpServletRequest req = (HttpServletRequest)request;
+ HttpServletResponse resp = (HttpServletResponse) response;
+ if (logger.isInfoEnabled()) {
+ logger.info("AuthorizationValve of uri: " + req.getRequestURI());
+ }
+ String uri = req.getRequestURI();
+ String contextPath = req.getContextPath();
+ if (contextPath != null && contextPath.length() > 0 && !"/".equals(contextPath)) {
+ uri = uri.substring(contextPath.length());
+ }
+ if (uri.equals(logout)) {
+ if (!isLogout(req)) {
+ setLogout(true, resp);
+ showLoginForm(resp);
+ } else {
+ setLogout(false, resp);
+ resp.sendRedirect(contextPath == null || contextPath.length() == 0 ? "/" : contextPath);
+ }
+ return;
+ }
+ User user = null;
+ String authType = null;
+ String authorization = req.getHeader("Authorization");
+ if (authorization != null && authorization.length() > 0) {
+ int i = authorization.indexOf(' ');
+ if (i >= 0) {
+ authType = authorization.substring(0, i);
+ String authPrincipal = authorization.substring(i + 1);
+ if (BASIC_CHALLENGE.equalsIgnoreCase(authType)) {
+ user = loginByBase(authPrincipal);
+ } else if (DIGEST_CHALLENGE.equalsIgnoreCase(authType)) {
+ user = loginByDigest(authPrincipal, req);
+ }
+ }
+ }
+ if (user == null || user.getUsername() == null || user.getUsername().length() == 0) {
+ showLoginForm(resp);
+ return;
+ //pipelineContext.breakPipeline(1);
+ }
+ if (user != null && StringUtils.isNotEmpty(user.getUsername())) {
+ req.getSession().setAttribute(WebConstants.CURRENT_USER_KEY, user);
+ chain.doFilter(request, response);
+ }
+
+ }
+
+ @Override
+ public void destroy() {
+
+ }
+
+ private void showLoginForm(HttpServletResponse response) throws IOException {
+ if (DIGEST_CHALLENGE.equals(CHALLENGE)) {
+ response.setHeader("WWW-Authenticate", CHALLENGE + " realm=\"" + REALM + "\", qop=\"auth\", nonce=\""
+ + UUID.randomUUID().toString().replace("-", "") + "\", opaque=\""
+ + Coder.encodeMd5(REALM) + "\"");
+ } else {
+ response.setHeader("WWW-Authenticate", CHALLENGE + " realm=\"" + REALM + "\"");
+ }
+ response.setHeader("Cache-Control", "must-revalidate,no-cache,no-store");
+ response.setHeader("Content-Type", "text/html; charset=iso-8859-1");
+ response.sendError(HttpServletResponse.SC_UNAUTHORIZED);
+ }
+
+ private User getUser(String username) {
+ return userService.findUser(username);
+ }
+
+ private User loginByBase(String authorization) {
+ authorization = Coder.decodeBase64(authorization);
+ int i = authorization.indexOf(':');
+ String username = authorization.substring(0, i);
+ if (username != null && username.length() > 0) {
+ String password = authorization.substring(i + 1);
+ if (password != null && password.length() > 0) {
+ String passwordDigest = Coder.encodeMd5(username + ":" + REALM + ":" + password);
+ User user = getUser(username);
+ if (user != null) {
+ String pwd = user.getPassword();
+ if (pwd != null && pwd.length() > 0) {
+ if (passwordDigest.equals(pwd)) {
+ return user;
+ }
+ }
+ }
+ }
+ }
+ return null;
+ }
+
+ private User loginByDigest(String value, HttpServletRequest request) throws IOException {
+ Map params = parseParameters(value);
+ String username = params.get("username");
+ if (username != null && username.length() > 0) {
+ String passwordDigest = params.get("response");
+ if (passwordDigest != null && passwordDigest.length() > 0) {
+ User user = getUser(username);
+ if (user != null) {
+ String pwd = user.getPassword();
+ // A valid user, validate password
+ if (pwd != null && pwd.length() > 0) {
+ String uri = params.get("uri");
+ String nonce = params.get("nonce");
+ String nc = params.get("nc");
+ String cnonce = params.get("cnonce");
+ String qop = params.get("qop");
+ String method = request.getMethod();
+ String a1 = pwd;
+
+ String a2 = "auth-int".equals(qop)
+ ? Coder.encodeMd5(method + ":" + uri + ":" + Coder.encodeMd5(readToBytes(request.getInputStream())))
+ : Coder.encodeMd5(method + ":" + uri);
+ String digest = "auth".equals(qop) || "auth-int".equals(qop)
+ ? Coder.encodeMd5(a1 + ":" + nonce + ":" + nc + ":" + cnonce + ":" + qop + ":" + a2)
+ : Coder.encodeMd5(a1 + ":" + nonce + ":" + a2);
+ if (digest.equals(passwordDigest)) {
+ return user;
+ }
+ }
+ }
+ }
+ }
+ return null;
+ }
+
+ private boolean isLogout(HttpServletRequest request) {
+ Cookie[] cookies = request.getCookies();
+ if (cookies != null && cookies.length > 0) {
+ for (Cookie cookie : cookies) {
+ if (cookie != null && logoutCookie.equals(cookie.getName())) {
+ return "true".equals(cookie.getValue());
+ }
+ }
+ }
+ return false;
+ }
+
+ private void setLogout(boolean logoutValue, HttpServletResponse response) {
+ response.addCookie(new Cookie(logoutCookie, String.valueOf(logoutValue)));
+ }
+}
+
diff --git a/52.Dubbo-OPS-Mointor/dubbo-admin/src/main/java/com/alibaba/dubboadmin/governance/biz/common/i18n/MessageResourceService.java b/52.Dubbo-OPS-Mointor/dubbo-admin/src/main/java/com/alibaba/dubboadmin/governance/biz/common/i18n/MessageResourceService.java
new file mode 100644
index 0000000..e70c5ce
--- /dev/null
+++ b/52.Dubbo-OPS-Mointor/dubbo-admin/src/main/java/com/alibaba/dubboadmin/governance/biz/common/i18n/MessageResourceService.java
@@ -0,0 +1,25 @@
+/*
+ * 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 com.alibaba.dubboadmin.governance.biz.common.i18n;
+
+public interface MessageResourceService {
+
+ public String get(String key, Object... args);
+
+ public String getMessage(String key, Object... args);
+
+}
diff --git a/52.Dubbo-OPS-Mointor/dubbo-admin/src/main/java/com/alibaba/dubboadmin/governance/biz/common/i18n/impl/MessageResourceServiceImpl.java b/52.Dubbo-OPS-Mointor/dubbo-admin/src/main/java/com/alibaba/dubboadmin/governance/biz/common/i18n/impl/MessageResourceServiceImpl.java
new file mode 100644
index 0000000..c0b47b8
--- /dev/null
+++ b/52.Dubbo-OPS-Mointor/dubbo-admin/src/main/java/com/alibaba/dubboadmin/governance/biz/common/i18n/impl/MessageResourceServiceImpl.java
@@ -0,0 +1,53 @@
+/*
+ * 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 com.alibaba.dubboadmin.governance.biz.common.i18n.impl;
+
+
+import com.alibaba.dubboadmin.governance.biz.common.i18n.MessageResourceService;
+import com.alibaba.dubboadmin.web.mvc.common.i18n.LocaleUtil;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.MessageSource;
+import org.springframework.context.NoSuchMessageException;
+import org.springframework.stereotype.Component;
+
+@Component
+public class MessageResourceServiceImpl implements MessageResourceService {
+
+ @Autowired
+ private MessageSource messageSource;
+
+ public void setMessageSource(MessageSource messageSource) {
+ this.messageSource = messageSource;
+ }
+
+ public String get(String key, Object... args) {
+ try {
+ if (messageSource != null) {
+ return messageSource.getMessage(key, args, key, LocaleUtil.getLocale());
+ }
+ return key;
+ } catch (NoSuchMessageException e) {
+ return key;
+ }
+ }
+
+ public String getMessage(String key, Object... args) {
+ return get(key, args);
+ }
+
+}
diff --git a/52.Dubbo-OPS-Mointor/dubbo-admin/src/main/java/com/alibaba/dubboadmin/governance/service/ConfigService.java b/52.Dubbo-OPS-Mointor/dubbo-admin/src/main/java/com/alibaba/dubboadmin/governance/service/ConfigService.java
new file mode 100644
index 0000000..a3a0ee8
--- /dev/null
+++ b/52.Dubbo-OPS-Mointor/dubbo-admin/src/main/java/com/alibaba/dubboadmin/governance/service/ConfigService.java
@@ -0,0 +1,34 @@
+/*
+ * 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 com.alibaba.dubboadmin.governance.service;
+
+import java.util.List;
+import java.util.Map;
+
+import com.alibaba.dubboadmin.registry.common.domain.Config;
+
+/**
+ * TODO Comment of ConfigDAO
+ *
+ */
+public interface ConfigService {
+
+ void update(List configs);
+
+ Map findAllConfigsMap();
+
+}
diff --git a/52.Dubbo-OPS-Mointor/dubbo-admin/src/main/java/com/alibaba/dubboadmin/governance/service/ConsumerService.java b/52.Dubbo-OPS-Mointor/dubbo-admin/src/main/java/com/alibaba/dubboadmin/governance/service/ConsumerService.java
new file mode 100644
index 0000000..e980eeb
--- /dev/null
+++ b/52.Dubbo-OPS-Mointor/dubbo-admin/src/main/java/com/alibaba/dubboadmin/governance/service/ConsumerService.java
@@ -0,0 +1,58 @@
+/*
+ * 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 com.alibaba.dubboadmin.governance.service;
+
+import java.util.List;
+
+import com.alibaba.dubboadmin.registry.common.domain.Consumer;
+
+/**
+ * Query service for consumer info
+ *
+ */
+public interface ConsumerService {
+
+ List findByService(String serviceName);
+
+ Consumer findConsumer(Long id);
+
+ List findAll();
+
+ /**
+ * query for all consumer addresses
+ */
+ List findAddresses();
+
+ List findAddressesByApplication(String application);
+
+ List findAddressesByService(String serviceName);
+
+ List findByAddress(String consumerAddress);
+
+ List findServicesByAddress(String consumerAddress);
+
+ List findApplications();
+
+ List findApplicationsByServiceName(String serviceName);
+
+ List findByApplication(String application);
+
+ List findServicesByApplication(String application);
+
+ List findServices();
+
+}
\ No newline at end of file
diff --git a/52.Dubbo-OPS-Mointor/dubbo-admin/src/main/java/com/alibaba/dubboadmin/governance/service/OverrideService.java b/52.Dubbo-OPS-Mointor/dubbo-admin/src/main/java/com/alibaba/dubboadmin/governance/service/OverrideService.java
new file mode 100644
index 0000000..afa2a67
--- /dev/null
+++ b/52.Dubbo-OPS-Mointor/dubbo-admin/src/main/java/com/alibaba/dubboadmin/governance/service/OverrideService.java
@@ -0,0 +1,49 @@
+/*
+ * 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 com.alibaba.dubboadmin.governance.service;
+
+import java.util.List;
+
+import com.alibaba.dubboadmin.registry.common.domain.Override;
+
+public interface OverrideService {
+
+ void saveOverride(Override override);
+
+ void updateOverride(Override override);
+
+ void deleteOverride(Long id);
+
+ void enableOverride(Long id);
+
+ void disableOverride(Long id);
+
+ List findByService(String service);
+
+ List findByAddress(String address);
+
+ List findByServiceAndAddress(String service, String address);
+
+ List findByApplication(String application);
+
+ List findByServiceAndApplication(String service, String application);
+
+ List findAll();
+
+ Override findById(Long id);
+
+}
diff --git a/52.Dubbo-OPS-Mointor/dubbo-admin/src/main/java/com/alibaba/dubboadmin/governance/service/OwnerService.java b/52.Dubbo-OPS-Mointor/dubbo-admin/src/main/java/com/alibaba/dubboadmin/governance/service/OwnerService.java
new file mode 100644
index 0000000..367125a
--- /dev/null
+++ b/52.Dubbo-OPS-Mointor/dubbo-admin/src/main/java/com/alibaba/dubboadmin/governance/service/OwnerService.java
@@ -0,0 +1,41 @@
+/*
+ * 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 com.alibaba.dubboadmin.governance.service;
+
+import java.util.List;
+
+import com.alibaba.dubboadmin.registry.common.domain.Owner;
+
+public interface OwnerService {
+
+ List findAllServiceNames();
+
+ List findServiceNamesByUsername(String username);
+
+ List findUsernamesByServiceName(String serviceName);
+
+ List findByService(String serviceName);
+
+ List findAll();
+
+ Owner findById(Long id);
+
+ void saveOwner(Owner owner);
+
+ void deleteOwner(Owner owner);
+
+}
diff --git a/52.Dubbo-OPS-Mointor/dubbo-admin/src/main/java/com/alibaba/dubboadmin/governance/service/ProviderService.java b/52.Dubbo-OPS-Mointor/dubbo-admin/src/main/java/com/alibaba/dubboadmin/governance/service/ProviderService.java
new file mode 100644
index 0000000..15ba776
--- /dev/null
+++ b/52.Dubbo-OPS-Mointor/dubbo-admin/src/main/java/com/alibaba/dubboadmin/governance/service/ProviderService.java
@@ -0,0 +1,73 @@
+/*
+ * 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 com.alibaba.dubboadmin.governance.service;
+
+import java.util.List;
+
+import com.alibaba.dubboadmin.registry.common.domain.Provider;
+
+/**
+ * ProviderService
+ *
+ */
+public interface ProviderService {
+
+ void create(Provider provider);
+
+ void enableProvider(Long id);
+
+ void disableProvider(Long id);
+
+ void doublingProvider(Long id);
+
+ void halvingProvider(Long id);
+
+ void deleteStaticProvider(Long id);
+
+ void updateProvider(Provider provider);
+
+ Provider findProvider(Long id);
+
+ List findServices();
+
+ List findAddresses();
+
+ List findAddressesByApplication(String application);
+
+ List findAddressesByService(String serviceName);
+
+ List findApplicationsByServiceName(String serviceName);
+
+ List findByService(String serviceName);
+
+ List findAll();
+
+ List findByAddress(String providerAddress);
+
+ List findServicesByAddress(String providerAddress);
+
+ List findApplications();
+
+ List findByApplication(String application);
+
+ List findServicesByApplication(String application);
+
+ List findMethodsByService(String serviceName);
+
+ Provider findByServiceAndAddress(String service, String address);
+
+}
\ No newline at end of file
diff --git a/52.Dubbo-OPS-Mointor/dubbo-admin/src/main/java/com/alibaba/dubboadmin/governance/service/RouteService.java b/52.Dubbo-OPS-Mointor/dubbo-admin/src/main/java/com/alibaba/dubboadmin/governance/service/RouteService.java
new file mode 100644
index 0000000..236d881
--- /dev/null
+++ b/52.Dubbo-OPS-Mointor/dubbo-admin/src/main/java/com/alibaba/dubboadmin/governance/service/RouteService.java
@@ -0,0 +1,57 @@
+/*
+ * 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 com.alibaba.dubboadmin.governance.service;
+
+import java.util.List;
+
+import com.alibaba.dubboadmin.registry.common.domain.Route;
+
+/**
+ * RouteService
+ *
+ */
+public interface RouteService {
+
+ void createRoute(Route route);
+
+ void updateRoute(Route route);
+
+ void deleteRoute(Long id);
+
+ void enableRoute(Long id);
+
+ void disableRoute(Long id);
+
+ Route findRoute(Long id);
+
+ List findAll();
+
+ List findByService(String serviceName);
+
+ List findByAddress(String address);
+
+ List findByServiceAndAddress(String service, String address);
+
+ List findForceRouteByService(String service);
+
+ List findForceRouteByAddress(String address);
+
+ List findForceRouteByServiceAndAddress(String service, String address);
+
+ List findAllForceRoute();
+
+}
diff --git a/52.Dubbo-OPS-Mointor/dubbo-admin/src/main/java/com/alibaba/dubboadmin/governance/service/UserService.java b/52.Dubbo-OPS-Mointor/dubbo-admin/src/main/java/com/alibaba/dubboadmin/governance/service/UserService.java
new file mode 100644
index 0000000..1869859
--- /dev/null
+++ b/52.Dubbo-OPS-Mointor/dubbo-admin/src/main/java/com/alibaba/dubboadmin/governance/service/UserService.java
@@ -0,0 +1,51 @@
+/*
+ * 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 com.alibaba.dubboadmin.governance.service;
+
+import java.util.List;
+
+import com.alibaba.dubboadmin.registry.common.domain.User;
+
+/**
+ * UserService
+ *
+ */
+public interface UserService {
+
+ List findAllUsers();
+
+ User findUser(String username);
+
+ User findById(Long id);
+
+ void createUser(User user);
+
+ void updateUser(User user);
+
+ void modifyUser(User user);
+
+ boolean updatePassword(User user, String oldPassword);
+
+ void resetPassword(User user);
+
+ void enableUser(User user);
+
+ void disableUser(User user);
+
+ void deleteUser(User user);
+
+}
diff --git a/52.Dubbo-OPS-Mointor/dubbo-admin/src/main/java/com/alibaba/dubboadmin/governance/service/impl/AbstractService.java b/52.Dubbo-OPS-Mointor/dubbo-admin/src/main/java/com/alibaba/dubboadmin/governance/service/impl/AbstractService.java
new file mode 100644
index 0000000..3c01d63
--- /dev/null
+++ b/52.Dubbo-OPS-Mointor/dubbo-admin/src/main/java/com/alibaba/dubboadmin/governance/service/impl/AbstractService.java
@@ -0,0 +1,46 @@
+/*
+ * 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 com.alibaba.dubboadmin.governance.service.impl;
+
+import java.util.Map;
+import java.util.concurrent.ConcurrentMap;
+
+import com.alibaba.dubbo.common.URL;
+import com.alibaba.dubbo.common.logger.Logger;
+import com.alibaba.dubbo.common.logger.LoggerFactory;
+import com.alibaba.dubbo.registry.RegistryService;
+import com.alibaba.dubboadmin.governance.sync.RegistryServerSync;
+
+import org.springframework.beans.factory.annotation.Autowired;
+
+/**
+ * IbatisDAO
+ *
+ */
+public class AbstractService {
+
+ protected static final Logger logger = LoggerFactory.getLogger(AbstractService.class);
+ @Autowired
+ protected RegistryService registryService;
+ @Autowired
+ private RegistryServerSync sync;
+
+ public ConcurrentMap>> getRegistryCache() {
+ return sync.getRegistryCache();
+ }
+
+}
diff --git a/52.Dubbo-OPS-Mointor/dubbo-admin/src/main/java/com/alibaba/dubboadmin/governance/service/impl/ConfigServiceImpl.java b/52.Dubbo-OPS-Mointor/dubbo-admin/src/main/java/com/alibaba/dubboadmin/governance/service/impl/ConfigServiceImpl.java
new file mode 100644
index 0000000..7921ac6
--- /dev/null
+++ b/52.Dubbo-OPS-Mointor/dubbo-admin/src/main/java/com/alibaba/dubboadmin/governance/service/impl/ConfigServiceImpl.java
@@ -0,0 +1,46 @@
+/*
+ * 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 com.alibaba.dubboadmin.governance.service.impl;
+
+import java.util.List;
+import java.util.Map;
+
+import com.alibaba.dubboadmin.governance.service.ConfigService;
+import com.alibaba.dubboadmin.registry.common.domain.Config;
+
+/**
+ * TODO Comment of IbatisConfigDAO
+ *
+ */
+public class ConfigServiceImpl extends AbstractService implements ConfigService {
+
+ /* (non-Javadoc)
+ * @see com.alibaba.dubbo.governance.service.ConfigService#update(java.util.List)
+ */
+ public void update(List configs) {
+ // TODO Auto-generated method stub
+
+ }
+
+ /* (non-Javadoc)
+ * @see com.alibaba.dubbo.governance.service.ConfigService#findAllConfigsMap()
+ */
+ public Map findAllConfigsMap() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+}
diff --git a/52.Dubbo-OPS-Mointor/dubbo-admin/src/main/java/com/alibaba/dubboadmin/governance/service/impl/ConsumerServiceImpl.java b/52.Dubbo-OPS-Mointor/dubbo-admin/src/main/java/com/alibaba/dubboadmin/governance/service/impl/ConsumerServiceImpl.java
new file mode 100644
index 0000000..bf7c3da
--- /dev/null
+++ b/52.Dubbo-OPS-Mointor/dubbo-admin/src/main/java/com/alibaba/dubboadmin/governance/service/impl/ConsumerServiceImpl.java
@@ -0,0 +1,223 @@
+/*
+ * 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 com.alibaba.dubboadmin.governance.service.impl;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ConcurrentMap;
+
+import com.alibaba.dubbo.common.Constants;
+import com.alibaba.dubbo.common.URL;
+import com.alibaba.dubboadmin.governance.service.ConsumerService;
+import com.alibaba.dubboadmin.governance.sync.util.Pair;
+import com.alibaba.dubboadmin.governance.sync.util.SyncUtils;
+import com.alibaba.dubboadmin.registry.common.domain.Consumer;
+
+import org.springframework.stereotype.Component;
+
+@Component
+public class ConsumerServiceImpl extends AbstractService implements ConsumerService {
+
+ public List findByService(String service) {
+ return SyncUtils.url2ConsumerList(findConsumerUrlByService(service));
+ }
+
+ public Consumer findConsumer(Long id) {
+ return SyncUtils.url2Consumer(findConsumerUrl(id));
+ }
+
+ private Pair findConsumerUrl(Long id) {
+ return SyncUtils.filterFromCategory(getRegistryCache(), Constants.CONSUMERS_CATEGORY, id);
+ }
+
+ public List findAll() {
+ return SyncUtils.url2ConsumerList(findAllConsumerUrl());
+ }
+
+ private Map findAllConsumerUrl() {
+ Map filter = new HashMap();
+ filter.put(Constants.CATEGORY_KEY, Constants.CONSUMERS_CATEGORY);
+ return SyncUtils.filterFromCategory(getRegistryCache(), filter);
+ }
+
+ public List findAddresses() {
+ List ret = new ArrayList();
+ ConcurrentMap> consumerUrls = getRegistryCache().get(Constants.CONSUMERS_CATEGORY);
+ if (null == consumerUrls) return ret;
+
+ for (Map.Entry> e1 : consumerUrls.entrySet()) {
+ Map value = e1.getValue();
+ for (Map.Entry e2 : value.entrySet()) {
+ URL u = e2.getValue();
+ String app = u.getAddress();
+ if (app != null) ret.add(app);
+ }
+ }
+
+ return ret;
+ }
+
+ public List findAddressesByApplication(String application) {
+ List ret = new ArrayList();
+ ConcurrentMap> consumerUrls = getRegistryCache().get(Constants.CONSUMERS_CATEGORY);
+
+ if(consumerUrls == null)
+ return ret;
+
+ for (Map.Entry> e1 : consumerUrls.entrySet()) {
+ Map value = e1.getValue();
+ for (Map.Entry e2 : value.entrySet()) {
+ URL u = e2.getValue();
+ if (application.equals(u.getParameter(Constants.APPLICATION_KEY))) {
+ String addr = u.getAddress();
+ if (addr != null) ret.add(addr);
+ }
+ }
+ }
+
+ return ret;
+ }
+
+ public List findAddressesByService(String service) {
+ List ret = new ArrayList();
+ ConcurrentMap> consumerUrls = getRegistryCache().get(Constants.CONSUMERS_CATEGORY);
+ if (null == consumerUrls) return ret;
+
+ for (Map.Entry e2 : consumerUrls.get(service).entrySet()) {
+ URL u = e2.getValue();
+ String app = u.getAddress();
+ if (app != null) ret.add(app);
+ }
+
+ return ret;
+ }
+
+ public List findByAddress(String consumerAddress) {
+ return SyncUtils.url2ConsumerList(findConsumerUrlByAddress(consumerAddress));
+ }
+
+ public List findServicesByAddress(String address) {
+ List ret = new ArrayList();
+ ConcurrentMap> consumerUrls = getRegistryCache().get(Constants.CONSUMERS_CATEGORY);
+ if (consumerUrls == null || address == null || address.length() == 0) return ret;
+
+ for (Map.Entry> e1 : consumerUrls.entrySet()) {
+ Map value = e1.getValue();
+ for (Map.Entry e2 : value.entrySet()) {
+ URL u = e2.getValue();
+ if (address.equals(u.getAddress())) {
+ ret.add(e1.getKey());
+ break;
+ }
+ }
+ }
+
+ return ret;
+ }
+
+ private Map findConsumerUrlByAddress(String address) {
+ Map filter = new HashMap();
+ filter.put(Constants.CATEGORY_KEY, Constants.CONSUMERS_CATEGORY);
+ filter.put(SyncUtils.ADDRESS_FILTER_KEY, address);
+
+ return SyncUtils.filterFromCategory(getRegistryCache(), filter);
+ }
+
+ public List findApplications() {
+ List ret = new ArrayList();
+ ConcurrentMap> consumerUrls = getRegistryCache().get(Constants.CONSUMERS_CATEGORY);
+ if (consumerUrls == null) return ret;
+
+ for (Map.Entry> e1 : consumerUrls.entrySet()) {
+ Map value = e1.getValue();
+ for (Map.Entry e2 : value.entrySet()) {
+ URL u = e2.getValue();
+ String app = u.getParameter(Constants.APPLICATION_KEY);
+ if (app != null) ret.add(app);
+ }
+ }
+
+ return ret;
+ }
+
+ public List findApplicationsByServiceName(String service) {
+ List ret = new ArrayList();
+ ConcurrentMap> consumerUrls = getRegistryCache().get(Constants.CONSUMERS_CATEGORY);
+ if (consumerUrls == null) return ret;
+
+ Map value = consumerUrls.get(service);
+ if (value == null) {
+ return ret;
+ }
+ for (Map.Entry e2 : value.entrySet()) {
+ URL u = e2.getValue();
+ String app = u.getParameter(Constants.APPLICATION_KEY);
+ if (app != null) ret.add(app);
+ }
+
+ return ret;
+ }
+
+ public List findByApplication(String application) {
+ return SyncUtils.url2ConsumerList(findConsumerUrlByApplication(application));
+ }
+
+ private Map findConsumerUrlByApplication(String application) {
+ Map filter = new HashMap();
+ filter.put(Constants.CATEGORY_KEY, Constants.CONSUMERS_CATEGORY);
+ filter.put(Constants.APPLICATION_KEY, application);
+
+ return SyncUtils.filterFromCategory(getRegistryCache(), filter);
+ }
+
+ public List findServicesByApplication(String application) {
+ List ret = new ArrayList();
+ ConcurrentMap> consumerUrls = getRegistryCache().get(Constants.CONSUMERS_CATEGORY);
+ if (consumerUrls == null || application == null || application.length() == 0) return ret;
+
+ for (Map.Entry> e1 : consumerUrls.entrySet()) {
+ Map value = e1.getValue();
+ for (Map.Entry e2 : value.entrySet()) {
+ URL u = e2.getValue();
+ if (application.equals(u.getParameter(Constants.APPLICATION_KEY))) {
+ ret.add(e1.getKey());
+ break;
+ }
+ }
+ }
+
+ return ret;
+ }
+
+ public List findServices() {
+ List ret = new ArrayList();
+ ConcurrentMap> consumerUrls = getRegistryCache().get(Constants.CONSUMERS_CATEGORY);
+ if (consumerUrls != null) ret.addAll(consumerUrls.keySet());
+ return ret;
+ }
+
+ public Map findConsumerUrlByService(String service) {
+ Map filter = new HashMap();
+ filter.put(Constants.CATEGORY_KEY, Constants.CONSUMERS_CATEGORY);
+ filter.put(SyncUtils.SERVICE_FILTER_KEY, service);
+
+ return SyncUtils.filterFromCategory(getRegistryCache(), filter);
+ }
+
+}
diff --git a/52.Dubbo-OPS-Mointor/dubbo-admin/src/main/java/com/alibaba/dubboadmin/governance/service/impl/OverrideServiceImpl.java b/52.Dubbo-OPS-Mointor/dubbo-admin/src/main/java/com/alibaba/dubboadmin/governance/service/impl/OverrideServiceImpl.java
new file mode 100644
index 0000000..151bbac
--- /dev/null
+++ b/52.Dubbo-OPS-Mointor/dubbo-admin/src/main/java/com/alibaba/dubboadmin/governance/service/impl/OverrideServiceImpl.java
@@ -0,0 +1,191 @@
+/*
+ * 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 com.alibaba.dubboadmin.governance.service.impl;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import com.alibaba.dubbo.common.Constants;
+import com.alibaba.dubbo.common.URL;
+import com.alibaba.dubboadmin.governance.service.OverrideService;
+import com.alibaba.dubboadmin.governance.sync.util.Pair;
+import com.alibaba.dubboadmin.governance.sync.util.SyncUtils;
+import com.alibaba.dubboadmin.registry.common.domain.Override;
+
+import org.springframework.stereotype.Component;
+
+/**
+ * IbatisOverrideDAO.java
+ *
+ */
+@Component
+public class OverrideServiceImpl extends AbstractService implements OverrideService {
+
+ public void saveOverride(Override override) {
+ URL url = getUrlFromOverride(override);
+ registryService.register(url);
+ }
+
+ public void updateOverride(Override override) {
+ Long id = override.getId();
+ if (id == null) {
+ throw new IllegalStateException("no override id");
+ }
+ URL oldOverride = findOverrideUrl(id);
+ if (oldOverride == null) {
+ throw new IllegalStateException("Route was changed!");
+ }
+ URL newOverride = getUrlFromOverride(override);
+
+ registryService.unregister(oldOverride);
+ registryService.register(newOverride);
+
+ }
+
+ public void deleteOverride(Long id) {
+ URL oldOverride = findOverrideUrl(id);
+ if (oldOverride == null) {
+ throw new IllegalStateException("Route was changed!");
+ }
+ registryService.unregister(oldOverride);
+ }
+
+ public void enableOverride(Long id) {
+ if (id == null) {
+ throw new IllegalStateException("no override id");
+ }
+
+ URL oldOverride = findOverrideUrl(id);
+ if (oldOverride == null) {
+ throw new IllegalStateException("Override was changed!");
+ }
+ if (oldOverride.getParameter("enabled", true)) {
+ return;
+ }
+
+ URL newOverride = oldOverride.addParameter("enabled", true);
+ registryService.unregister(oldOverride);
+ registryService.register(newOverride);
+
+ }
+
+ public void disableOverride(Long id) {
+ if (id == null) {
+ throw new IllegalStateException("no override id");
+ }
+
+ URL oldProvider = findOverrideUrl(id);
+ if (oldProvider == null) {
+ throw new IllegalStateException("Override was changed!");
+ }
+ if (!oldProvider.getParameter("enabled", true)) {
+ return;
+ }
+
+ URL newProvider = oldProvider.addParameter("enabled", false);
+ registryService.unregister(oldProvider);
+ registryService.register(newProvider);
+
+ }
+
+ private Map findOverrideUrl(String service, String address, String application) {
+ Map filter = new HashMap();
+ filter.put(Constants.CATEGORY_KEY, Constants.CONFIGURATORS_CATEGORY);
+ if (service != null && service.length() > 0) {
+ filter.put(SyncUtils.SERVICE_FILTER_KEY, service);
+ }
+ if (address != null && address.length() > 0) {
+ filter.put(SyncUtils.ADDRESS_FILTER_KEY, address);
+ }
+ if (application != null && application.length() > 0) {
+ filter.put(Constants.APPLICATION_KEY, application);
+ }
+ return SyncUtils.filterFromCategory(getRegistryCache(), filter);
+ }
+
+ public List findByAddress(String address) {
+ return SyncUtils.url2OverrideList(findOverrideUrl(null, address, null));
+ }
+
+ public List findByServiceAndAddress(String service, String address) {
+ return SyncUtils.url2OverrideList(findOverrideUrl(service, address, null));
+ }
+
+ public List findByApplication(String application) {
+ return SyncUtils.url2OverrideList(findOverrideUrl(null, null, application));
+ }
+
+ public List findByService(String service) {
+ return SyncUtils.url2OverrideList(findOverrideUrl(service, null, null));
+ }
+
+ public List findByServiceAndApplication(String service, String application) {
+ return SyncUtils.url2OverrideList(findOverrideUrl(service, null, application));
+ }
+
+ public List findAll() {
+ return SyncUtils.url2OverrideList(findOverrideUrl(null, null, null));
+ }
+
+ private Pair findOverrideUrlPair(Long id) {
+ return SyncUtils.filterFromCategory(getRegistryCache(), Constants.CONFIGURATORS_CATEGORY, id);
+ }
+
+ public Override findById(Long id) {
+ return SyncUtils.url2Override(findOverrideUrlPair(id));
+ }
+
+ private URL getUrlFromOverride(Override override) {
+ return override.toUrl();
+ /*Map params = ConvertUtil.serviceName2Map(override.getService());
+ if(!params.containsKey(Constants.INTERFACE_KEY)) {
+ throw new IllegalArgumentException("No interface info");
+ }
+ if(!params.containsKey(Constants.VERSION_KEY)) {
+ throw new IllegalArgumentException("No version info");
+ }
+
+ boolean enabled = override.isEnabled();
+ if(!enabled) {
+ params.put("enabled", "false");
+ }
+ String application = override.getApplication();
+ if(!StringUtils.isEmpty(application)) {
+ params.put("application", application);
+ }
+ String address = override.getAddress();
+ if(!StringUtils.isEmpty(address)) {
+ params.put("address", address);
+ }
+
+ String overrideAddress = override.getOverrideAddress();
+ if(StringUtils.isEmpty(overrideAddress)) {
+ overrideAddress = "0.0.0.0";
+ }
+ params.put(Constants.CATEGORY_KEY, Constants.CONFIGURATORS_CATEGORY);
+
+ URL url = new URL("override", overrideAddress, -1, params);
+ url = url.addParameterString(override.getParams());
+ return url;*/
+ }
+
+ URL findOverrideUrl(Long id) {
+ return getUrlFromOverride(findById(id));
+ }
+
+}
diff --git a/52.Dubbo-OPS-Mointor/dubbo-admin/src/main/java/com/alibaba/dubboadmin/governance/service/impl/OwnerServiceImpl.java b/52.Dubbo-OPS-Mointor/dubbo-admin/src/main/java/com/alibaba/dubboadmin/governance/service/impl/OwnerServiceImpl.java
new file mode 100644
index 0000000..4fa2613
--- /dev/null
+++ b/52.Dubbo-OPS-Mointor/dubbo-admin/src/main/java/com/alibaba/dubboadmin/governance/service/impl/OwnerServiceImpl.java
@@ -0,0 +1,160 @@
+/*
+ * 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 com.alibaba.dubboadmin.governance.service.impl;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import com.alibaba.dubbo.common.Constants;
+import com.alibaba.dubbo.common.utils.StringUtils;
+import com.alibaba.dubboadmin.governance.service.OverrideService;
+import com.alibaba.dubboadmin.governance.service.OwnerService;
+import com.alibaba.dubboadmin.governance.service.ProviderService;
+import com.alibaba.dubboadmin.registry.common.domain.Override;
+import com.alibaba.dubboadmin.registry.common.domain.Owner;
+import com.alibaba.dubboadmin.registry.common.domain.Provider;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+@Component
+public class OwnerServiceImpl extends AbstractService implements OwnerService {
+
+ @Autowired
+ ProviderService providerService;
+
+ @Autowired
+ OverrideService overrideService;
+
+ public List findAllServiceNames() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public List findServiceNamesByUsername(String username) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public List findUsernamesByServiceName(String serviceName) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public List findByService(String serviceName) {
+ List pList = providerService.findByService(serviceName);
+ List cList = overrideService.findByServiceAndAddress(serviceName, Constants.ANYHOST_VALUE);
+ return toOverrideLiset(pList, cList);
+ }
+
+ public List findAll() {
+ List pList = providerService.findAll();
+ List cList = overrideService.findAll();
+ return toOverrideLiset(pList, cList);
+ }
+
+ public Owner findById(Long id) {
+
+ return null;
+ }
+
+ private List toOverrideLiset(List pList, List cList) {
+ Map oList = new HashMap();
+ for (Provider p : pList) {
+ if (p.getUsername() != null) {
+ for (String username : Constants.COMMA_SPLIT_PATTERN.split(p.getUsername())) {
+ Owner o = new Owner();
+ o.setService(p.getService());
+ o.setUsername(username);
+ oList.put(o.getService() + "/" + o.getUsername(), o);
+ }
+ }
+ }
+ for (Override c : cList) {
+ Map 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(username);
+ oList.put(o.getService() + "/" + o.getUsername(), o);
+ }
+ }
+ }
+ return new ArrayList(oList.values());
+ }
+
+ public void saveOwner(Owner owner) {
+ List 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 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 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 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());
+ }
+ }
+ }
+ }
+ }
+
+}
diff --git a/52.Dubbo-OPS-Mointor/dubbo-admin/src/main/java/com/alibaba/dubboadmin/governance/service/impl/ProviderServiceImpl.java b/52.Dubbo-OPS-Mointor/dubbo-admin/src/main/java/com/alibaba/dubboadmin/governance/service/impl/ProviderServiceImpl.java
new file mode 100644
index 0000000..8ee59e1
--- /dev/null
+++ b/52.Dubbo-OPS-Mointor/dubbo-admin/src/main/java/com/alibaba/dubboadmin/governance/service/impl/ProviderServiceImpl.java
@@ -0,0 +1,461 @@
+/*
+ * 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 com.alibaba.dubboadmin.governance.service.impl;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.concurrent.ConcurrentMap;
+
+import com.alibaba.dubbo.common.Constants;
+import com.alibaba.dubbo.common.URL;
+import com.alibaba.dubbo.common.utils.StringUtils;
+import com.alibaba.dubboadmin.governance.service.OverrideService;
+import com.alibaba.dubboadmin.governance.service.ProviderService;
+import com.alibaba.dubboadmin.governance.sync.util.Pair;
+import com.alibaba.dubboadmin.governance.sync.util.SyncUtils;
+import com.alibaba.dubboadmin.registry.common.domain.Override;
+import com.alibaba.dubboadmin.registry.common.domain.Provider;
+import com.alibaba.dubboadmin.registry.common.route.ParseUtils;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+/**
+ * IbatisProviderService
+ *
+ */
+@Component
+public class ProviderServiceImpl extends AbstractService implements ProviderService {
+
+ @Autowired
+ OverrideService overrideService;
+
+ public void create(Provider provider) {
+ URL url = provider.toUrl();
+ registryService.register(url);
+ }
+
+ public void enableProvider(Long id) {
+ if (id == null) {
+ throw new IllegalStateException("no provider id");
+ }
+
+ Provider oldProvider = findProvider(id);
+
+ if (oldProvider == null) {
+ throw new IllegalStateException("Provider was changed!");
+ }
+ if (oldProvider.isDynamic()) {
+ // Make sure we only have one override configured disable property.
+ if (!oldProvider.isEnabled()) {
+ Override override = new Override();
+ override.setAddress(oldProvider.getAddress());
+ override.setService(oldProvider.getService());
+ override.setEnabled(true);
+ override.setParams(Constants.DISABLED_KEY + "=false");
+ overrideService.saveOverride(override);
+ return;
+ }
+ List oList = overrideService.findByServiceAndAddress(oldProvider.getService(), oldProvider.getAddress());
+
+ for (Override o : oList) {
+ Map params = StringUtils.parseQueryString(o.getParams());
+ if (params.containsKey(Constants.DISABLED_KEY)) {
+ if (params.get(Constants.DISABLED_KEY).equals("true")) {
+ overrideService.deleteOverride(o.getId());
+ }
+ }
+ }
+ } else {
+ oldProvider.setEnabled(true);
+ updateProvider(oldProvider);
+ }
+ }
+
+ public void disableProvider(Long id) {
+ if (id == null) {
+ throw new IllegalStateException("no provider id");
+ }
+
+ Provider oldProvider = findProvider(id);
+ if (oldProvider == null) {
+ throw new IllegalStateException("Provider was changed!");
+ }
+
+ if (oldProvider.isDynamic()) {
+ // Make sure we only have one override configured disable property.
+ if (oldProvider.isEnabled()) {
+ Override override = new Override();
+ override.setAddress(oldProvider.getAddress());
+ override.setService(oldProvider.getService());
+ override.setEnabled(true);
+ override.setParams(Constants.DISABLED_KEY + "=true");
+ overrideService.saveOverride(override);
+ return;
+ }
+ List oList = overrideService.findByServiceAndAddress(oldProvider.getService(), oldProvider.getAddress());
+
+ for (Override o : oList) {
+ Map params = StringUtils.parseQueryString(o.getParams());
+ if (params.containsKey(Constants.DISABLED_KEY)) {
+ if (params.get(Constants.DISABLED_KEY).equals("false")) {
+ overrideService.deleteOverride(o.getId());
+ }
+ }
+ }
+ } else {
+ oldProvider.setEnabled(false);
+ updateProvider(oldProvider);
+ }
+
+ }
+
+ public void doublingProvider(Long id) {
+ setWeight(id, 2F);
+ }
+
+ public void halvingProvider(Long id) {
+ setWeight(id, 0.5F);
+ }
+
+ public void setWeight(Long id, float factor) {
+ if (id == null) {
+ throw new IllegalStateException("no provider id");
+ }
+ Provider oldProvider = findProvider(id);
+ if (oldProvider == null) {
+ throw new IllegalStateException("Provider was changed!");
+ }
+ Map map = StringUtils.parseQueryString(oldProvider.getParameters());
+ String weight = map.get(Constants.WEIGHT_KEY);
+ if (oldProvider.isDynamic()) {
+ // Make sure we only have one override configured disable property.
+ List overrides = overrideService.findByServiceAndAddress(oldProvider.getService(), oldProvider.getAddress());
+ if (overrides == null || overrides.size() == 0) {
+ int value = getWeight(weight, factor);
+ if (value != Constants.DEFAULT_WEIGHT) {
+ Override override = new Override();
+ override.setAddress(oldProvider.getAddress());
+ override.setService(oldProvider.getService());
+ override.setEnabled(true);
+ override.setParams(Constants.WEIGHT_KEY + "=" + String.valueOf(value));
+ overrideService.saveOverride(override);
+ }
+ } else {
+ for (Override override : overrides) {
+ Map params = StringUtils.parseQueryString(override.getParams());
+ String overrideWeight = params.get(Constants.WEIGHT_KEY);
+ if (overrideWeight == null || overrideWeight.length() == 0) {
+ overrideWeight = weight;
+ }
+ int value = getWeight(overrideWeight, factor);
+ if (value == getWeight(weight, 1)) {
+ params.remove(Constants.WEIGHT_KEY);
+ } else {
+ params.put(Constants.WEIGHT_KEY, String.valueOf(value));
+ }
+ if (params.size() > 0) {
+ override.setParams(StringUtils.toQueryString(params));
+ overrideService.updateOverride(override);
+ } else {
+ overrideService.deleteOverride(override.getId());
+ }
+ }
+ }
+ } else {
+ int value = getWeight(weight, factor);
+ if (value == Constants.DEFAULT_WEIGHT) {
+ map.remove(Constants.WEIGHT_KEY);
+ } else {
+ map.put(Constants.WEIGHT_KEY, String.valueOf(value));
+ }
+ oldProvider.setParameters(StringUtils.toQueryString(map));
+ updateProvider(oldProvider);
+ }
+ }
+
+ private int getWeight(String value, float factor) {
+ int weight = 100;
+ if (value != null && value.length() > 0) {
+ weight = Integer.parseInt(value);
+ }
+ weight = (int) (weight * factor);
+ if (weight < 1) weight = 1;
+ if (weight == 2) weight = 3;
+ if (weight == 24) weight = 25;
+ return weight;
+ }
+
+ public void deleteStaticProvider(Long id) {
+ URL oldProvider = findProviderUrl(id);
+ if (oldProvider == null) {
+ throw new IllegalStateException("Provider was changed!");
+ }
+ registryService.unregister(oldProvider);
+ }
+
+ public void updateProvider(Provider provider) {
+ Long id = provider.getId();
+ if (id == null) {
+ throw new IllegalStateException("no provider id");
+ }
+
+ URL oldProvider = findProviderUrl(id);
+ if (oldProvider == null) {
+ throw new IllegalStateException("Provider was changed!");
+ }
+ URL newProvider = provider.toUrl();
+
+ registryService.unregister(oldProvider);
+ registryService.register(newProvider);
+ }
+
+ public Provider findProvider(Long id) {
+ return SyncUtils.url2Provider(findProviderUrlPair(id));
+ }
+
+ public Pair findProviderUrlPair(Long id) {
+ return SyncUtils.filterFromCategory(getRegistryCache(), Constants.PROVIDERS_CATEGORY, id);
+ }
+
+ public List findServices() {
+ List ret = new ArrayList();
+ ConcurrentMap> providerUrls = getRegistryCache().get(Constants.PROVIDERS_CATEGORY);
+ if (providerUrls != null) ret.addAll(providerUrls.keySet());
+ return ret;
+ }
+
+ public List findAddresses() {
+ List ret = new ArrayList();
+
+ ConcurrentMap> providerUrls = getRegistryCache().get(Constants.PROVIDERS_CATEGORY);
+ if (null == providerUrls) return ret;
+
+ for (Map.Entry> e1 : providerUrls.entrySet()) {
+ Map value = e1.getValue();
+ for (Map.Entry e2 : value.entrySet()) {
+ URL u = e2.getValue();
+ String app = u.getAddress();
+ if (app != null) ret.add(app);
+ }
+ }
+
+ return ret;
+ }
+
+ public List findAddressesByApplication(String application) {
+ List ret = new ArrayList();
+ ConcurrentMap> providerUrls = getRegistryCache().get(Constants.PROVIDERS_CATEGORY);
+ for (Map.Entry> e1 : providerUrls.entrySet()) {
+ Map value = e1.getValue();
+ for (Map.Entry e2 : value.entrySet()) {
+ URL u = e2.getValue();
+ if (application.equals(u.getParameter(Constants.APPLICATION_KEY))) {
+ String addr = u.getAddress();
+ if (addr != null) ret.add(addr);
+ }
+ }
+ }
+
+ return ret;
+ }
+
+ public List findAddressesByService(String service) {
+ List ret = new ArrayList();
+ ConcurrentMap> providerUrls = getRegistryCache().get(Constants.PROVIDERS_CATEGORY);
+ if (null == providerUrls) return ret;
+
+ for (Map.Entry e2 : providerUrls.get(service).entrySet()) {
+ URL u = e2.getValue();
+ String app = u.getAddress();
+ if (app != null) ret.add(app);
+ }
+
+ return ret;
+ }
+
+ public List findApplicationsByServiceName(String service) {
+ List ret = new ArrayList();
+ ConcurrentMap> providerUrls = getRegistryCache().get(Constants.PROVIDERS_CATEGORY);
+ if (null == providerUrls) return ret;
+
+ Map value = providerUrls.get(service);
+ if (value == null) {
+ return ret;
+ }
+ for (Map.Entry e2 : value.entrySet()) {
+ URL u = e2.getValue();
+ String app = u.getParameter(Constants.APPLICATION_KEY);
+ if (app != null) ret.add(app);
+ }
+
+ return ret;
+ }
+
+ public List findByService(String serviceName) {
+ return SyncUtils.url2ProviderList(findProviderUrlByService(serviceName));
+ }
+
+ private Map findProviderUrlByService(String service) {
+ Map filter = new HashMap();
+ filter.put(Constants.CATEGORY_KEY, Constants.PROVIDERS_CATEGORY);
+ filter.put(SyncUtils.SERVICE_FILTER_KEY, service);
+
+ return SyncUtils.filterFromCategory(getRegistryCache(), filter);
+ }
+
+ public List findAll() {
+ return SyncUtils.url2ProviderList(findAllProviderUrl());
+ }
+
+ private Map findAllProviderUrl() {
+ Map filter = new HashMap();
+ filter.put(Constants.CATEGORY_KEY, Constants.PROVIDERS_CATEGORY);
+ return SyncUtils.filterFromCategory(getRegistryCache(), filter);
+ }
+
+ public List findByAddress(String providerAddress) {
+ return SyncUtils.url2ProviderList(findProviderUrlByAddress(providerAddress));
+ }
+
+ public Map findProviderUrlByAddress(String address) {
+ Map filter = new HashMap();
+ filter.put(Constants.CATEGORY_KEY, Constants.PROVIDERS_CATEGORY);
+ filter.put(SyncUtils.ADDRESS_FILTER_KEY, address);
+
+ return SyncUtils.filterFromCategory(getRegistryCache(), filter);
+ }
+
+ public List findServicesByAddress(String address) {
+ List ret = new ArrayList();
+
+ ConcurrentMap> providerUrls = getRegistryCache().get(Constants.PROVIDERS_CATEGORY);
+ if (providerUrls == null || address == null || address.length() == 0) return ret;
+
+ for (Map.Entry> e1 : providerUrls.entrySet()) {
+ Map value = e1.getValue();
+ for (Map.Entry e2 : value.entrySet()) {
+ URL u = e2.getValue();
+ if (address.equals(u.getAddress())) {
+ ret.add(e1.getKey());
+ break;
+ }
+ }
+ }
+
+ return ret;
+ }
+
+ public List findApplications() {
+ List ret = new ArrayList();
+ ConcurrentMap> providerUrls = getRegistryCache().get(Constants.PROVIDERS_CATEGORY);
+ if (providerUrls == null) return ret;
+
+ for (Map.Entry> e1 : providerUrls.entrySet()) {
+ Map value = e1.getValue();
+ for (Map.Entry e2 : value.entrySet()) {
+ URL u = e2.getValue();
+ String app = u.getParameter(Constants.APPLICATION_KEY);
+ if (app != null) ret.add(app);
+ }
+ }
+
+ return ret;
+ }
+
+ public List findByApplication(String application) {
+ return SyncUtils.url2ProviderList(findProviderUrlByApplication(application));
+ }
+
+ private Map findProviderUrlByApplication(String application) {
+ Map filter = new HashMap();
+ filter.put(Constants.CATEGORY_KEY, Constants.PROVIDERS_CATEGORY);
+ filter.put(Constants.APPLICATION_KEY, application);
+ return SyncUtils.filterFromCategory(getRegistryCache(), filter);
+ }
+
+ public List findServicesByApplication(String application) {
+ List ret = new ArrayList();
+
+ ConcurrentMap> providerUrls = getRegistryCache().get(Constants.PROVIDERS_CATEGORY);
+ if (providerUrls == null || application == null || application.length() == 0) return ret;
+
+ for (Map.Entry> e1 : providerUrls.entrySet()) {
+ Map value = e1.getValue();
+ for (Map.Entry e2 : value.entrySet()) {
+ URL u = e2.getValue();
+ if (application.equals(u.getParameter(Constants.APPLICATION_KEY))) {
+ ret.add(e1.getKey());
+ break;
+ }
+ }
+ }
+
+ return ret;
+ }
+
+ public List findMethodsByService(String service) {
+ List ret = new ArrayList();
+
+ ConcurrentMap> providerUrls = getRegistryCache().get(Constants.PROVIDERS_CATEGORY);
+ if (providerUrls == null || service == null || service.length() == 0) return ret;
+
+ Map providers = providerUrls.get(service);
+ if (null == providers || providers.isEmpty()) return ret;
+
+ Entry p = providers.entrySet().iterator().next();
+ String value = p.getValue().getParameter("methods");
+ if (value == null || value.length() == 0) {
+ return ret;
+ }
+ String[] methods = value.split(ParseUtils.METHOD_SPLIT);
+ if (methods == null || methods.length == 0) {
+ return ret;
+ }
+
+ for (String m : methods) {
+ ret.add(m);
+ }
+ return ret;
+ }
+
+ private URL findProviderUrl(Long id) {
+ return findProvider(id).toUrl();
+ }
+
+ public Provider findByServiceAndAddress(String service, String address) {
+ return SyncUtils.url2Provider(findProviderUrl(service, address));
+ }
+
+ private Pair findProviderUrl(String service, String address) {
+ Map filter = new HashMap();
+ filter.put(Constants.CATEGORY_KEY, Constants.PROVIDERS_CATEGORY);
+ filter.put(SyncUtils.ADDRESS_FILTER_KEY, address);
+
+ Map ret = SyncUtils.filterFromCategory(getRegistryCache(), filter);
+ if (ret.isEmpty()) {
+ return null;
+ } else {
+ Long key = ret.entrySet().iterator().next().getKey();
+ return new Pair(key, ret.get(key));
+ }
+ }
+
+}
diff --git a/52.Dubbo-OPS-Mointor/dubbo-admin/src/main/java/com/alibaba/dubboadmin/governance/service/impl/RouteServiceImpl.java b/52.Dubbo-OPS-Mointor/dubbo-admin/src/main/java/com/alibaba/dubboadmin/governance/service/impl/RouteServiceImpl.java
new file mode 100644
index 0000000..f618e90
--- /dev/null
+++ b/52.Dubbo-OPS-Mointor/dubbo-admin/src/main/java/com/alibaba/dubboadmin/governance/service/impl/RouteServiceImpl.java
@@ -0,0 +1,169 @@
+/*
+ * 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 com.alibaba.dubboadmin.governance.service.impl;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import com.alibaba.dubbo.common.Constants;
+import com.alibaba.dubbo.common.URL;
+import com.alibaba.dubboadmin.governance.service.RouteService;
+import com.alibaba.dubboadmin.governance.sync.util.Pair;
+import com.alibaba.dubboadmin.governance.sync.util.SyncUtils;
+import com.alibaba.dubboadmin.registry.common.domain.Route;
+
+import org.springframework.stereotype.Component;
+
+/**
+ * IbatisRouteService
+ *
+ */
+@Component
+public class RouteServiceImpl extends AbstractService implements RouteService {
+
+ public void createRoute(Route route) {
+ registryService.register(route.toUrl());
+ }
+
+ public void updateRoute(Route route) {
+ Long id = route.getId();
+ if (id == null) {
+ throw new IllegalStateException("no route id");
+ }
+ URL oldRoute = findRouteUrl(id);
+ if (oldRoute == null) {
+ throw new IllegalStateException("Route was changed!");
+ }
+
+ registryService.unregister(oldRoute);
+ registryService.register(route.toUrl());
+ }
+
+ public void deleteRoute(Long id) {
+ URL oldRoute = findRouteUrl(id);
+ if (oldRoute == null) {
+ throw new IllegalStateException("Route was changed!");
+ }
+ registryService.unregister(oldRoute);
+ }
+
+ public void enableRoute(Long id) {
+ if (id == null) {
+ throw new IllegalStateException("no route id");
+ }
+
+ URL oldRoute = findRouteUrl(id);
+ if (oldRoute == null) {
+ throw new IllegalStateException("Route was changed!");
+ }
+ if (oldRoute.getParameter("enabled", true)) {
+ return;
+ }
+
+ registryService.unregister(oldRoute);
+ URL newRoute = oldRoute.addParameter("enabled", true);
+ registryService.register(newRoute);
+
+ }
+
+ public void disableRoute(Long id) {
+ if (id == null) {
+ throw new IllegalStateException("no route id");
+ }
+
+ URL oldRoute = findRouteUrl(id);
+ if (oldRoute == null) {
+ throw new IllegalStateException("Route was changed!");
+ }
+ if (!oldRoute.getParameter("enabled", true)) {
+ return;
+ }
+
+ URL newRoute = oldRoute.addParameter("enabled", false);
+ registryService.unregister(oldRoute);
+ registryService.register(newRoute);
+
+ }
+
+ public List findAll() {
+ return SyncUtils.url2RouteList(findAllUrl());
+ }
+
+ private Map findAllUrl() {
+ Map filter = new HashMap();
+ filter.put(Constants.CATEGORY_KEY, Constants.ROUTERS_CATEGORY);
+
+ return SyncUtils.filterFromCategory(getRegistryCache(), filter);
+ }
+
+ public Route findRoute(Long id) {
+ return SyncUtils.url2Route(findRouteUrlPair(id));
+ }
+
+ public Pair findRouteUrlPair(Long id) {
+ return SyncUtils.filterFromCategory(getRegistryCache(), Constants.ROUTERS_CATEGORY, id);
+ }
+
+ private URL findRouteUrl(Long id) {
+ return findRoute(id).toUrl();
+ }
+
+ private Map findRouteUrl(String service, String address, boolean force) {
+ Map filter = new HashMap();
+ filter.put(Constants.CATEGORY_KEY, Constants.ROUTERS_CATEGORY);
+ if (service != null && service.length() > 0) {
+ filter.put(SyncUtils.SERVICE_FILTER_KEY, service);
+ }
+ if (address != null && address.length() > 0) {
+ filter.put(SyncUtils.ADDRESS_FILTER_KEY, address);
+ }
+ if (force) {
+ filter.put("force", "true");
+ }
+ return SyncUtils.filterFromCategory(getRegistryCache(), filter);
+ }
+
+ public List findByService(String serviceName) {
+ return SyncUtils.url2RouteList(findRouteUrl(serviceName, null, false));
+ }
+
+ public List findByAddress(String address) {
+ return SyncUtils.url2RouteList(findRouteUrl(null, address, false));
+ }
+
+ public List findByServiceAndAddress(String service, String address) {
+ return SyncUtils.url2RouteList(findRouteUrl(service, address, false));
+ }
+
+ public List findForceRouteByService(String service) {
+ return SyncUtils.url2RouteList(findRouteUrl(service, null, true));
+ }
+
+ public List findForceRouteByAddress(String address) {
+ return SyncUtils.url2RouteList(findRouteUrl(null, address, true));
+ }
+
+ public List