-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
57 changed files
with
2,467 additions
and
11 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
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
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,46 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<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>fm-cloud-demo</artifactId> | ||
<groupId>com.fm</groupId> | ||
<version>1.0-SNAPSHOT</version> | ||
</parent> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<artifactId>fm-graybunny-server</artifactId> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-web</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-test</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.cloud</groupId> | ||
<artifactId>spring-cloud-starter-eureka</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.cloud</groupId> | ||
<artifactId>spring-cloud-starter-feign</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.cloud</groupId> | ||
<artifactId>spring-cloud-starter-zuul</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.fm</groupId> | ||
<artifactId>fm-cloud-starter-bamboo</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.fm</groupId> | ||
<artifactId>fm-cloud-starter-graybunny-server</artifactId> | ||
</dependency> | ||
|
||
</dependencies> | ||
|
||
</project> |
39 changes: 39 additions & 0 deletions
39
...demo/fm-graybunny-server/src/main/java/com/fm/gray/server/GrayBunnyServerApplication.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,39 @@ | ||
package com.fm.gray.server; | ||
|
||
import org.slf4j.LoggerFactory; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
import org.springframework.boot.builder.SpringApplicationBuilder; | ||
import org.springframework.boot.context.properties.EnableConfigurationProperties; | ||
import org.springframework.cloud.client.discovery.EnableDiscoveryClient; | ||
import org.springframework.cloud.netflix.feign.EnableFeignClients; | ||
import org.springframework.core.env.Environment; | ||
|
||
import java.net.InetAddress; | ||
import java.net.UnknownHostException; | ||
|
||
/** | ||
* Created by saleson on 2017/10/18. | ||
*/ | ||
@SpringBootApplication | ||
@EnableDiscoveryClient | ||
@EnableFeignClients | ||
public class GrayBunnyServerApplication { | ||
private static final org.slf4j.Logger log = LoggerFactory.getLogger(GrayBunnyServerApplication.class); | ||
|
||
|
||
public static void main(String[] args) throws UnknownHostException { | ||
Environment env = new SpringApplicationBuilder(GrayBunnyServerApplication.class).web(true).run(args).getEnvironment(); | ||
log.info( | ||
"\n----------------------------------------------------------\n\t" | ||
+ "Application '{}' is running! Access URLs:\n\t" + "Local: \t\thttp://127.0.0.1:{}\n\t" | ||
+ "External: \thttp://{}:{}\n----------------------------------------------------------", | ||
env.getProperty("spring.application.name"), env.getProperty("server.port"), | ||
InetAddress.getLocalHost().getHostAddress(), env.getProperty("server.port")); | ||
|
||
String configServerStatus = env.getProperty("configserver.status"); | ||
log.info( | ||
"\n----------------------------------------------------------\n\t" | ||
+ "Config Server: \t{}\n----------------------------------------------------------", | ||
configServerStatus == null ? "Not found or not setup for this application" : configServerStatus); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
fm-cloud/fm-cloud-demo/fm-graybunny-server/src/main/resources/config/application.yml
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,11 @@ | ||
spring: | ||
application: | ||
name: graybunny-server | ||
server: | ||
port: 10202 | ||
eureka: | ||
client: | ||
register-with-eureka: true | ||
fetch-registry: true | ||
serviceUrl: | ||
defaultZone: http://localhost:10002/eureka/ |
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
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
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
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
79 changes: 79 additions & 0 deletions
79
fm-cloud/fm-cloud-plugins/fm-cloud-gray-bunny-core/pom.xml
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,79 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<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>fm-plugins</artifactId> | ||
<groupId>com.fm</groupId> | ||
<version>1.0-SNAPSHOT</version> | ||
</parent> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<artifactId>fm-cloud-gray-bunny-core</artifactId> | ||
|
||
<dependencies> | ||
|
||
<dependency> | ||
<groupId>com.fm</groupId> | ||
<artifactId>fm-cloud-bamboo</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-web</artifactId> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-test</artifactId> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.cloud</groupId> | ||
<artifactId>spring-cloud-starter-eureka</artifactId> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.cloud</groupId> | ||
<artifactId>spring-cloud-starter-feign</artifactId> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.cloud</groupId> | ||
<artifactId>spring-cloud-starter-zuul</artifactId> | ||
<scope>provided</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.springframework.cloud</groupId> | ||
<artifactId>spring-cloud-netflix-core</artifactId> | ||
<scope>provided</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>io.springfox</groupId> | ||
<artifactId>springfox-swagger2</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.springfox</groupId> | ||
<artifactId>springfox-swagger-ui</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.springfox</groupId> | ||
<artifactId>springfox-spring-web</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.springfox</groupId> | ||
<artifactId>springfox-bean-validators</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>com.sun.jersey</groupId> | ||
<artifactId>jersey-servlet</artifactId> | ||
<version>1.19.1</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
|
||
</project> |
105 changes: 105 additions & 0 deletions
105
...plugins/fm-cloud-gray-bunny-core/src/main/java/com/fm/gray/DefaultGrayServiceManager.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,105 @@ | ||
package com.fm.gray; | ||
|
||
import com.fm.gray.core.*; | ||
|
||
import java.util.*; | ||
import java.util.concurrent.ConcurrentHashMap; | ||
import java.util.concurrent.locks.Lock; | ||
import java.util.concurrent.locks.ReentrantLock; | ||
|
||
public class DefaultGrayServiceManager implements GrayServiceManager { | ||
|
||
|
||
private Map<String, GrayService> grayServiceMap = new ConcurrentHashMap<>(); | ||
private Lock lock = new ReentrantLock(); | ||
|
||
|
||
@Override | ||
public void addGrayInstance(GrayInstance instance) { | ||
GrayService grayService = grayServiceMap.get(instance.getServiceId()); | ||
lock.lock(); | ||
try { | ||
if (grayService == null) { | ||
grayService = new GrayService(); | ||
grayService.setServiceId(instance.getServiceId()); | ||
grayServiceMap.put(instance.getServiceId(), grayService); | ||
} | ||
if (!grayService.contains(instance.getInstanceId())) { | ||
grayService.addGrayInstance(instance); | ||
} | ||
} finally { | ||
lock.unlock(); | ||
} | ||
} | ||
|
||
@Override | ||
public void deleteGrayInstance(String serviceId, String instanceId) { | ||
GrayService grayService = grayServiceMap.get(serviceId); | ||
if (grayService == null) { | ||
return; | ||
} | ||
lock.lock(); | ||
try { | ||
if (grayService.removeGrayInstance(instanceId) != null && grayService.getGrayInstances().isEmpty()) { | ||
grayServiceMap.remove(serviceId); | ||
} | ||
} finally { | ||
lock.unlock(); | ||
} | ||
|
||
} | ||
|
||
@Override | ||
public void addGrayPolicy(String serviceId, String instanceId, String policyGroupId, GrayPolicy policy) { | ||
GrayInstance grayInstance= getGrayInstane(serviceId, instanceId); | ||
if(grayInstance!=null){ | ||
grayInstance.addGrayPolicy(policyGroupId, policy); | ||
} | ||
} | ||
|
||
@Override | ||
public void deleteGrayPolicy(String serviceId, String instanceId, String policyGroupId, String policyId) { | ||
GrayInstance grayInstance= getGrayInstane(serviceId, instanceId); | ||
if(grayInstance!=null){ | ||
grayInstance.removeGrayPolicy(policyGroupId, policyId); | ||
} | ||
} | ||
|
||
@Override | ||
public void addGrayPolicyGroup(String serviceId, String instanceId, GrayPolicyGroup policyGroup) { | ||
GrayInstance grayInstance= getGrayInstane(serviceId, instanceId); | ||
if(grayInstance!=null){ | ||
grayInstance.addGrayPolicyGroup(policyGroup); | ||
} | ||
} | ||
|
||
@Override | ||
public void deleteGrayPolicyGroup(String serviceId, String instanceId, String policyGroupId) { | ||
GrayInstance grayInstance= getGrayInstane(serviceId, instanceId); | ||
if(grayInstance!=null){ | ||
grayInstance.removeGrayPolicyGroup(policyGroupId); | ||
} | ||
} | ||
|
||
|
||
@Override | ||
public Collection<GrayService> allGrayService() { | ||
return Collections.unmodifiableCollection(grayServiceMap.values()); | ||
} | ||
|
||
@Override | ||
public GrayService getGrayService(String serviceId){ | ||
return grayServiceMap.get(serviceId); | ||
} | ||
|
||
|
||
|
||
@Override | ||
public GrayInstance getGrayInstane(String serviceId, String instanceId){ | ||
GrayService grayService = getGrayService(serviceId); | ||
if(grayService!=null){ | ||
return grayService.getGrayInstance(instanceId); | ||
} | ||
return null; | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
...cloud-plugins/fm-cloud-gray-bunny-core/src/main/java/com/fm/gray/GrayBunnyAppContext.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,16 @@ | ||
package com.fm.gray; | ||
|
||
import com.fm.gray.core.GrayManager; | ||
|
||
public class GrayBunnyAppContext { | ||
private static GrayManager grayManager; | ||
|
||
|
||
public static GrayManager getGrayManager() { | ||
return grayManager; | ||
} | ||
|
||
static void setGrayManager(GrayManager grayManager) { | ||
GrayBunnyAppContext.grayManager = grayManager; | ||
} | ||
} |
Oops, something went wrong.