提交 7db1047b 编写于 作者: W william.liangf

增加dubbo-registry-admin

git-svn-id: http://code.alibabatech.com/svn/dubbo/trunk@367 1a56cb94-b969-4eaa-88fa-be21384802f2
上级 f5f081b8
<!--
- Copyright 1999-2011 Alibaba Group.
-
- Licensed 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.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.alibaba</groupId>
<artifactId>dubbo-parent</artifactId>
<version>2.0.9-SNAPSHOT</version>
</parent>
<artifactId>dubbo-registry-admin</artifactId>
<packaging>jar</packaging>
<name>Dubbo Registry Admin Module</name>
<description>The registry admin module of dubbo project</description>
<properties>
<skip_maven_deploy>true</skip_maven_deploy>
</properties>
<dependencies>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>dubbo-registry</artifactId>
<version>${project.parent.version}</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>dubbo-container</artifactId>
<version>${project.parent.version}</version>
</dependency>
</dependencies>
</project>
\ No newline at end of file
<assembly>
<id>dist</id>
<formats>
<format>tar.gz</format>
</formats>
<includeBaseDirectory>true</includeBaseDirectory>
<fileSets>
<fileSet>
<directory>src/main/assembly/bin</directory>
<outputDirectory>bin</outputDirectory>
<fileMode>0755</fileMode>
</fileSet>
</fileSets>
<dependencySets>
<dependencySet>
<outputDirectory>lib</outputDirectory>
</dependencySet>
</dependencySets>
</assembly>
\ No newline at end of file
#!/bin/bash
cd `dirname $0`
./stop.sh
./start.sh
#!/bin/bash
cd `dirname $0`
BIN_DIR=`pwd`
cd ..
DEPLOY_DIR=`pwd`
LIB_DIR=$DEPLOY_DIR/lib
LOGS_DIR=$DEPLOY_DIR/logs
STDOUT_FILE=$LOGS_DIR/stdout.log
SERVER_PORT=$1
if [ ! -d $LOGS_DIR ]; then
mkdir $LOGS_DIR
fi
if [ -z "$SERVER_PORT" ]; then
SERVER_PORT=8080
fi
SERVER_PORT_COUNT=`netstat -tln | grep $SERVER_PORT | wc -l`
if [ $SERVER_PORT_COUNT -gt 0 ]; then
echo "********************************************************************"
echo "** Error: Dubbo registry admin server port $SERVER_PORT already used!"
echo "********************************************************************"
exit 1
fi
JAVA_OPTS=" -Djava.awt.headless=true -Djava.net.preferIPv4Stack=true "
JAVA_MEM_OPTS=""
BITS=`file $JAVA_HOME/bin/java | grep 64-bit`
if [ -n "$BITS" ]; then
let memTotal=`cat /proc/meminfo |grep MemTotal|awk '{printf "%d", $2/1024 }'`
if [ $memTotal -gt 2500 ];then
JAVA_MEM_OPTS=" -server -Xmx2g -Xms2g -Xmn256m -XX:PermSize=128m -Xss256k -XX:+DisableExplicitGC -XX:+UseConcMarkSweepGC -XX:+CMSParallelRemarkEnabled -XX:+UseCMSCompactAtFullCollection -XX:LargePageSizeInBytes=128m -XX:+UseFastAccessorMethods -XX:+UseCMSInitiatingOccupancyOnly -XX:CMSInitiatingOccupancyFraction=70 "
else
JAVA_MEM_OPTS=" -server -Xmx1g -Xms1g -Xmn256m -XX:PermSize=128m -Xss256k -XX:+DisableExplicitGC -XX:+UseConcMarkSweepGC -XX:+CMSParallelRemarkEnabled -XX:+UseCMSCompactAtFullCollection -XX:LargePageSizeInBytes=128m -XX:+UseFastAccessorMethods -XX:+UseCMSInitiatingOccupancyOnly -XX:CMSInitiatingOccupancyFraction=70 "
fi
else
JAVA_MEM_OPTS=" -server -Xms1024m -Xmx1024m -XX:PermSize=128m -XX:SurvivorRatio=2 -XX:+UseParallelGC "
fi
EXIST_PIDS=`ps --no-heading -C java -f --width 1000 | grep "$DEPLOY_DIR" |awk '{print $2}'`
if [ ! -z "$EXIST_PIDS" ]; then
echo "Dubbo registry admin server already started!"
echo "PID: $EXIST_PIDS"
exit;
fi
LIB_JARS=`ls $LIB_DIR|grep .jar|awk '{print "'$LIB_DIR'/"$0}'|tr "\n" ":"`
echo -e "Starting dubbo registry admin server on $SERVER_PORT \c"
nohup $JAVA_HOME/bin/java $JAVA_OPTS $JAVA_MEM_OPTS -classpath $LIB_JARS com.alibaba.dubbo.container.Main spring jetty log4j >> $STDOUT_FILE 2>&1 &
COUNT=0
while [ $COUNT -lt 1 ]; do
echo -e ".\c"
sleep 1
COUNT=`curl -s "http://127.0.0.1:$SERVER_PORT/status" |grep -c "OK"`
if [ $COUNT -lt 1 ]; then
break
fi
done
echo "OK!"
START_PIDS=`ps --no-heading -C java -f --width 1000 | grep "$DEPLOY_DIR" |awk '{print $2}'`
echo "PID: $START_PIDS"
#!/bin/bash
cd `dirname $0`
BIN_DIR=`pwd`
cd ..
DEPLOY_DIR=`pwd`
KILL_PIDS=`ps --no-heading -C java -f --width 1000 | grep "$DEPLOY_DIR" |awk '{print $2}'`
if [ -z "$KILL_PIDS" ]; then
echo "Dubbo registry admin server does not started!"
exit 1;
fi
echo -e "Stopping dubbo registry admin server \c"
for PID in $KILL_PIDS ; do
echo -e "$PID \c"
kill $PID > /dev/null 2>&1
done
COUNT=0
while [ $COUNT -lt 1 ]; do
echo -e ".\c"
sleep 1
COUNT=1
for PID in $KILL_PIDS ; do
PID_PS=`ps --no-heading -p $PID`
if [ -n "$PID_PS" ]; then
COUNT=0
break
fi
done
done
echo "OK!"
echo "PID: $KILL_PIDS"
/*
* Copyright 1999-2011 Alibaba Group.
*
* Licensed 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.dubbo.registry.admin;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import com.alibaba.dubbo.common.Extension;
import com.alibaba.dubbo.common.ExtensionLoader;
import com.alibaba.dubbo.common.URL;
import com.alibaba.dubbo.common.logger.Logger;
import com.alibaba.dubbo.common.logger.LoggerFactory;
import com.alibaba.dubbo.common.utils.ConcurrentHashSet;
import com.alibaba.dubbo.container.Container;
import com.alibaba.dubbo.registry.Registry;
import com.alibaba.dubbo.registry.RegistryFactory;
/**
* RegistryContainer
*
* @author william.liangf
*/
@Extension("registry")
public class RegistryContainer implements Container {
private static final Logger logger = LoggerFactory.getLogger(RegistryContainer.class);
public static final String REGISTRY_URL = "registry.url";
private final RegistryFactory registryFactory = ExtensionLoader.getExtensionLoader(RegistryFactory.class).getAdaptiveExtension();
private final Set<String> services = new ConcurrentHashSet<String>();
private final Map<String, List<URL>> providers = new ConcurrentHashMap<String, List<URL>>();
private final Map<String, List<URL>> routes = new ConcurrentHashMap<String, List<URL>>();
private Registry registry;
private static RegistryContainer INSTANCE = null;
public RegistryContainer() {
INSTANCE = this;
}
public static RegistryContainer getInstance() {
return INSTANCE;
}
public Registry getRegistry() {
return registry;
}
public Set<String> getServices() {
return Collections.unmodifiableSet(services);
}
public Map<String, List<URL>> getProviders() {
return Collections.unmodifiableMap(providers);
}
public Map<String, List<URL>> getRoutes() {
return Collections.unmodifiableMap(routes);
}
public List<URL> getProviders(String service) {
List<URL> urls = providers.get(service);
return urls == null ? null : Collections.unmodifiableList(urls);
}
public List<URL> getRoutes(String service) {
List<URL> urls = routes.get(service);
return urls == null ? null : Collections.unmodifiableList(urls);
}
public void start() {
/*String url = System.getProperty(REGISTRY_URL);
if (url == null || url.length() == 0) {
throw new IllegalArgumentException("Please set java start argument: -D" + REGISTRY_URL + "=zookeeper://127.0.0.1:2181");
}
URL registryUrl = URL.valueOf(url);
registry = registryFactory.getRegistry(registryUrl);
URL subscribeUrl = new URL(Constants.SUBSCRIBE_PROTOCOL, NetUtils.getLocalHost(), 0)
.addParameters(Constants.INTERFACE_KEY, Constants.ANY_VALUE,
Constants.GROUP_KEY, Constants.ANY_VALUE,
Constants.VERSION_KEY, Constants.ANY_VALUE);
registry.subscribe(subscribeUrl, new NotifyListener() {
public void notify(List<URL> urls) {
if (urls == null || urls.size() == 0) {
return;
}
String service = urls.get(0).getServiceName();
services.add(service);
List<URL> proivderUrls = new ArrayList<URL>();
List<URL> routeUrls = new ArrayList<URL>();
for (URL url : urls) {
if (Constants.ROUTE_PROTOCOL.equals(url.getProtocol())) {
routeUrls.add(url);
} else {
proivderUrls.add(url);
}
}
providers.put(service, proivderUrls);
routes.put(service, proivderUrls);
}
});*/
for (int i = 0; i < 5; i ++) {
String service = "com.alibaba.foo.BarService" + i;
services.add(service);
List<URL> proivderUrls = new ArrayList<URL>();
for (int j = 0; j < 10; j ++) {
proivderUrls.add(URL.valueOf("dubbo://10.20.153." + j + ":20880/" + service));
}
providers.put(service, proivderUrls);
List<URL> routeUrls = new ArrayList<URL>();
for (int j = 0; j < 10; j ++) {
routeUrls.add(URL.valueOf("registry://127.0.0.1:20880?type=js&rule=aaa" + j));
}
routes.put(service, routeUrls);
}
}
public void stop() {
try {
registry.destroy();
} catch (Throwable e) {
logger.error(e.getMessage(), e);
}
}
}
/*
* Copyright 1999-2011 Alibaba Group.
*
* Licensed 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.dubbo.registry.admin.pages;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import com.alibaba.dubbo.common.Extension;
import com.alibaba.dubbo.common.URL;
import com.alibaba.dubbo.container.page.Page;
import com.alibaba.dubbo.container.page.PageHandler;
import com.alibaba.dubbo.registry.admin.RegistryContainer;
/**
* ProvidersPageHandler
*
* @author william.liangf
*/
@Extension("providers")
public class ProvidersPageHandler implements PageHandler {
public Page handle(URL url) {
String service = url.getParameter("service");
List<List<String>> rows = new ArrayList<List<String>>();
String nav;
if (service != null && service.length() > 0) {
List<URL> providers = RegistryContainer.getInstance().getProviders(service);
if (providers != null && providers.size() > 0) {
for (URL provider : providers) {
List<String> row = new ArrayList<String>();
row.add(provider.toFullString());
rows.add(row);
}
}
nav = " &gt; <a href=\"services.html\">Services</a> &gt; " + service;
} else {
Collection<List<URL>> values = RegistryContainer.getInstance().getProviders().values();
if (values != null && values.size() > 0) {
for (List<URL> providers : values) {
if (providers != null && providers.size() > 0) {
for (URL provider : providers) {
List<String> row = new ArrayList<String>();
row.add(provider.toFullString());
rows.add(row);
}
}
}
}
nav = "";
}
return new Page("<a href=\"/\">Home</a>" + nav + " &gt; Providers", "Providers (" + rows.size() + ")",
new String[] { "Provider URL:" }, rows);
}
}
/*
* Copyright 1999-2011 Alibaba Group.
*
* Licensed 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.dubbo.registry.admin.pages;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import com.alibaba.dubbo.common.Extension;
import com.alibaba.dubbo.common.URL;
import com.alibaba.dubbo.container.page.Page;
import com.alibaba.dubbo.container.page.PageHandler;
import com.alibaba.dubbo.registry.admin.RegistryContainer;
import com.alibaba.dubbo.rpc.RpcConstants;
/**
* RoutesPageHandler
*
* @author william.liangf
*/
@Extension("routes")
public class RoutesPageHandler implements PageHandler {
public Page handle(URL url) {
String service = url.getParameter("service");
List<List<String>> rows = new ArrayList<List<String>>();
String nav;
if (service != null && service.length() > 0) {
List<URL> routes = RegistryContainer.getInstance().getRoutes(service);
if (routes != null && routes.size() > 0) {
for (URL route : routes) {
List<String> row = new ArrayList<String>();
row.add(route.getParameter(RpcConstants.TYPE_KEY));
row.add(route.getParameterAndDecoded(RpcConstants.RULE_KEY).replace("<", "lt;").replace(">", "gt;"));
rows.add(row);
}
}
nav = " &gt; <a href=\"services.html\">Services</a> &gt; " + service;
} else {
Collection<List<URL>> values = RegistryContainer.getInstance().getRoutes().values();
if (values != null && values.size() > 0) {
for (List<URL> routes : values) {
if (routes != null && routes.size() > 0) {
for (URL route : routes) {
List<String> row = new ArrayList<String>();
row.add(route.getParameter(RpcConstants.TYPE_KEY));
row.add(route.getParameterAndDecoded(RpcConstants.RULE_KEY).replace("<", "lt;").replace(">", "gt;"));
rows.add(row);
}
}
}
}
nav = "";
}
return new Page("<a href=\"/\">Home</a>" + nav + " &gt; Routes", "Routes (" + rows.size() + ")",
new String[] { "Route Type:", "Route Rule:" }, rows);
}
}
/*
* Copyright 1999-2011 Alibaba Group.
*
* Licensed 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.dubbo.registry.admin.pages;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import com.alibaba.dubbo.common.Extension;
import com.alibaba.dubbo.common.URL;
import com.alibaba.dubbo.container.page.Menu;
import com.alibaba.dubbo.container.page.Page;
import com.alibaba.dubbo.container.page.PageHandler;
import com.alibaba.dubbo.registry.admin.RegistryContainer;
/**
* ServicesPageHandler
*
* @author william.liangf
*/
@Menu(name = "Services", desc = "Services", order = 1000)
@Extension("services")
public class ServicesPageHandler implements PageHandler {
public Page handle(URL url) {
Set<String> services = RegistryContainer.getInstance().getServices();
List<List<String>> rows = new ArrayList<List<String>>();
if (services != null && services.size() > 0) {
for (String service : services) {
List<String> row = new ArrayList<String>();
row.add(service);
row.add("<a href=\"providers.html?service=" + service + "\">Providers</a>");
row.add("<a href=\"routes.html?service=" + service + "\">Routes</a>");
rows.add(row);
}
}
return new Page("<a href=\"/\">Home</a> &gt; Services", "Services (" + rows.size() + ")",
new String[] { "Service Name:", "Providers", "Routes" }, rows);
}
}
com.alibaba.dubbo.registry.admin.RegistryContainer
\ No newline at end of file
com.alibaba.dubbo.registry.admin.pages.ServicesPageHandler
com.alibaba.dubbo.registry.admin.pages.ProvidersPageHandler
com.alibaba.dubbo.registry.admin.pages.RoutesPageHandler
\ No newline at end of file
/*
* Copyright 1999-2011 Alibaba Group.
*
* Licensed 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.dubbo.registry.admin;
/**
* Main
*
* @author william.liangf
*/
public class Admin {
public static void main(String[] args) {
System.setProperty(RegistryContainer.REGISTRY_URL, "zookeeper://10.20.153.10:2181");
com.alibaba.dubbo.container.Main.main(new String[] {"registry", "log4j", "jetty"});
}
}
......@@ -43,6 +43,7 @@
<module>dubbo-registry-simple</module>
<module>dubbo-registry-multicast</module>
<module>dubbo-registry-zookeeper</module>
<module>dubbo-registry-admin</module>
<module>dubbo-monitor</module>
<module>dubbo-monitor-simple</module>
<module>dubbo-config</module>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册