-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from alibaba/develop
更新代码
- Loading branch information
Showing
62 changed files
with
1,734 additions
and
220 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
Copyright 1999-2018 Alibaba Group Holding Ltd. | ||
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/xsd/maven-4.0.0.xsd"> | ||
<parent> | ||
<artifactId>nacos-all</artifactId> | ||
<groupId>com.alibaba.nacos</groupId> | ||
<version>1.1.0</version> | ||
</parent> | ||
|
||
<modelVersion>4.0.0</modelVersion> | ||
<artifactId>nacos-address</artifactId> | ||
<packaging>jar</packaging> | ||
|
||
<name>nacos-address ${project.version}</name> | ||
<url>http://maven.apache.org</url> | ||
|
||
<properties> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
<maven.compiler.source>1.8</maven.compiler.source> | ||
<maven.compiler.target>1.8</maven.compiler.target> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>junit</groupId> | ||
<artifactId>junit</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.commons</groupId> | ||
<artifactId>commons-lang3</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>${project.groupId}</groupId> | ||
<artifactId>nacos-naming</artifactId> | ||
<exclusions> | ||
<exclusion> | ||
<groupId>com.alibaba.nacos</groupId> | ||
<artifactId>nacos-cmdb</artifactId> | ||
</exclusion> | ||
</exclusions> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.mockito</groupId> | ||
<artifactId>mockito-all</artifactId> | ||
<version>1.10.19</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.hamcrest</groupId> | ||
<artifactId>hamcrest-all</artifactId> | ||
<version>1.3</version> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<resources> | ||
<resource> | ||
<directory>src/main/resources</directory> | ||
</resource> | ||
</resources> | ||
</build> | ||
|
||
<reporting> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.codehaus.mojo</groupId> | ||
<artifactId>findbugs-maven-plugin</artifactId> | ||
<version>3.0.4</version> | ||
</plugin> | ||
</plugins> | ||
</reporting> | ||
|
||
<profiles> | ||
<profile> | ||
<id>release-address</id> | ||
<build> | ||
<finalName>nacos-address</finalName> | ||
<plugins> | ||
<plugin> | ||
<artifactId>maven-jar-plugin</artifactId> | ||
<configuration> | ||
<archive> | ||
<manifest> | ||
<addDefaultImplementationEntries>true</addDefaultImplementationEntries> | ||
<addDefaultSpecificationEntries>true</addDefaultSpecificationEntries> | ||
</manifest> | ||
</archive> | ||
</configuration> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-maven-plugin</artifactId> | ||
<configuration> | ||
<mainClass>com.alibaba.nacos.address.AddressServer</mainClass> | ||
</configuration> | ||
<executions> | ||
<execution> | ||
<goals> | ||
<goal>repackage</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</profile> | ||
</profiles> | ||
</project> |
33 changes: 33 additions & 0 deletions
33
address/src/main/java/com/alibaba/nacos/address/AddressServer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
* Copyright 1999-2018 Alibaba Group Holding Ltd. | ||
* | ||
* 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.nacos.address; | ||
|
||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
|
||
/** | ||
* support address server. | ||
* | ||
* @author nacos | ||
* @since 1.1.0 | ||
*/ | ||
@SpringBootApplication(scanBasePackages = "com.alibaba.nacos") | ||
public class AddressServer { | ||
public static void main(String[] args) { | ||
|
||
SpringApplication.run(AddressServer.class, args); | ||
} | ||
} |
118 changes: 118 additions & 0 deletions
118
address/src/main/java/com/alibaba/nacos/address/component/AddressServerGeneratorManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
/* | ||
* Copyright (C) 2019 the original author or authors. | ||
* | ||
* 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.nacos.address.component; | ||
|
||
import com.alibaba.nacos.address.constant.AddressServerConstants; | ||
import com.alibaba.nacos.api.common.Constants; | ||
import com.alibaba.nacos.naming.core.Instance; | ||
import org.apache.commons.lang3.StringUtils; | ||
import org.springframework.stereotype.Component; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
/** | ||
* will generator some result by the input parameter. | ||
* | ||
* @author pbting | ||
* @date 2019-07-01 8:53 PM | ||
* @since 1.1.0 | ||
*/ | ||
@Component | ||
public class AddressServerGeneratorManager { | ||
|
||
public String generateProductName(String name) { | ||
|
||
if (StringUtils.isBlank(name) || AddressServerConstants.DEFAULT_PRODUCT.equals(name)) { | ||
|
||
return AddressServerConstants.ALIWARE_NACOS_DEFAULT_PRODUCT_NAME; | ||
} | ||
|
||
return String.format(AddressServerConstants.ALIWARE_NACOS_PRODUCT_DOM_TEMPLATE, name); | ||
} | ||
|
||
/** | ||
* Note: if the parameter inputted is empty then will return the empty list. | ||
* | ||
* @param serviceName | ||
* @param clusterName | ||
* @param ipArray | ||
* @return | ||
*/ | ||
public List<Instance> generateInstancesByIps(String serviceName, String rawProductName, String clusterName, String[] ipArray) { | ||
if (StringUtils.isEmpty(serviceName) | ||
|| StringUtils.isEmpty(clusterName) | ||
|| ipArray == null || ipArray.length == 0) { | ||
return Collections.emptyList(); | ||
} | ||
|
||
List<Instance> instanceList = new ArrayList<>(ipArray.length); | ||
for (String ip : ipArray) { | ||
String[] ipAndPort = generateIpAndPort(ip); | ||
Instance instance = new Instance(); | ||
instance.setIp(ipAndPort[0]); | ||
instance.setPort(Integer.valueOf(ipAndPort[1])); | ||
instance.setClusterName(clusterName); | ||
instance.setServiceName(serviceName); | ||
instance.setTenant(Constants.DEFAULT_NAMESPACE_ID); | ||
instance.setApp(rawProductName); | ||
instance.setEphemeral(false); | ||
instanceList.add(instance); | ||
} | ||
|
||
return instanceList; | ||
} | ||
|
||
public String[] generateIpAndPort(String ip) { | ||
|
||
int index = ip.indexOf(AddressServerConstants.IP_PORT_SEPARATOR); | ||
if (index != -1) { | ||
|
||
return new String[]{ip.substring(0, index), ip.substring(index + 1)}; | ||
} | ||
|
||
return new String[]{ip, String.valueOf(AddressServerConstants.DEFAULT_SERVER_PORT)}; | ||
} | ||
|
||
/** | ||
* @param instanceList a instance set will generate string response to client. | ||
* @return the result of response to client | ||
*/ | ||
public String generateResponseIps(List<Instance> instanceList) { | ||
|
||
StringBuilder ips = new StringBuilder(); | ||
instanceList.forEach(instance -> { | ||
ips.append(instance.getIp() + ":" + instance.getPort()); | ||
ips.append("\n"); | ||
}); | ||
|
||
return ips.toString(); | ||
} | ||
|
||
/** | ||
* @param rawServiceName the raw service name will not contains the {@Constans.DEFAULT_GROUP} | ||
* @return the nacos service name | ||
*/ | ||
public String generateNacosServiceName(String rawServiceName) { | ||
|
||
if (rawServiceName.indexOf(Constants.DEFAULT_GROUP) != -1) { | ||
return rawServiceName; | ||
} | ||
|
||
return Constants.DEFAULT_GROUP + AddressServerConstants.GROUP_SERVICE_NAME_SEP + rawServiceName; | ||
} | ||
} |
78 changes: 78 additions & 0 deletions
78
address/src/main/java/com/alibaba/nacos/address/component/AddressServerManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/* | ||
* Copyright (C) 2019 the original author or authors. | ||
* | ||
* 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.nacos.address.component; | ||
|
||
import com.alibaba.nacos.address.constant.AddressServerConstants; | ||
import org.apache.commons.lang3.StringUtils; | ||
import org.springframework.stereotype.Component; | ||
|
||
/** | ||
* This class holds the IP list of the CAI's address service. | ||
* | ||
* @author deshao | ||
* @date 2016/4/28 20:58 | ||
* @since 1.1.0 | ||
*/ | ||
@Component | ||
public class AddressServerManager { | ||
|
||
public String getRawProductName(String name) { | ||
|
||
if (StringUtils.isBlank(name) || AddressServerConstants.DEFAULT_PRODUCT.equals(name)) { | ||
|
||
return AddressServerConstants.DEFAULT_PRODUCT; | ||
} | ||
|
||
return name; | ||
} | ||
|
||
/** | ||
* <p> | ||
* if the name is empty then return the default {@UtilAndCommons#DEFAULT_CLUSTER_NAME}, | ||
* <p> | ||
* or return the source name by input | ||
* | ||
* @param name | ||
* @return | ||
*/ | ||
public String getDefaultClusterNameIfEmpty(String name) { | ||
|
||
if (StringUtils.isEmpty(name) || AddressServerConstants.DEFAULT_GET_CLUSTER.equals(name)) { | ||
return AddressServerConstants.DEFAULT_GET_CLUSTER; | ||
} | ||
|
||
return name; | ||
} | ||
|
||
public String getRawClusterName(String name) { | ||
|
||
return getDefaultClusterNameIfEmpty(name); | ||
} | ||
|
||
/** | ||
* @param ips multi ip will separator by the ',' | ||
* @return | ||
*/ | ||
public String[] splitIps(String ips) { | ||
|
||
if (StringUtils.isBlank(ips)) { | ||
|
||
return new String[0]; | ||
} | ||
|
||
return ips.split(AddressServerConstants.MULTI_IPS_SEPARATOR); | ||
} | ||
} |
Oops, something went wrong.