Skip to content

Commit

Permalink
灰度发布完成。
Browse files Browse the repository at this point in the history
  • Loading branch information
saleson committed Jan 9, 2018
1 parent b6afbb0 commit 0bae5f0
Show file tree
Hide file tree
Showing 57 changed files with 2,467 additions and 11 deletions.
4 changes: 4 additions & 0 deletions fm-cloud/fm-cloud-demo/fm-eureka-client2/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@
<groupId>com.fm</groupId>
<artifactId>fm-cloud-starter-bamboo</artifactId>
</dependency>
<dependency>
<groupId>com.fm</groupId>
<artifactId>fm-cloud-gray-bunny-core</artifactId>
</dependency>


</dependencies>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.fm.client;

import com.fm.gray.client.EnableGrayBunny;
import org.slf4j.LoggerFactory;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
Expand All @@ -19,17 +20,11 @@
@SpringBootApplication
@EnableDiscoveryClient
@EnableFeignClients
@EnableGrayBunny
public class EurekaClient2Application {
private static final org.slf4j.Logger log = LoggerFactory.getLogger(EurekaClient2Application.class);


@Bean
@LoadBalanced
public RestTemplate restTemplate() {
return new RestTemplate();

}

public static void main(String[] args) throws UnknownHostException {
Environment env = new SpringApplicationBuilder(EurekaClient2Application.class).web(true).run(args).getEnvironment();
log.info(
Expand Down
46 changes: 46 additions & 0 deletions fm-cloud/fm-cloud-demo/fm-graybunny-server/pom.xml
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>
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);
}
}
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/
1 change: 1 addition & 0 deletions fm-cloud/fm-cloud-demo/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
<module>fm-zuul</module>
<module>fm-zuul-server</module>
<module>fm-eureka-client2</module>
<module>fm-graybunny-server</module>
</modules>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,4 +132,9 @@ public MultiValueMap<String, String> getParams() {
public MultiValueMap<String, String> getHeaders() {
return headers;
}


public String getIp() {
return ip;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@
//@RibbonClients(defaultConfiguration = {BambooExtConfigration.class})
public class BambooConfiguration {


public static class UnUseBambooIRule{

}


@Autowired(required = false)
private IClientConfig config;

Expand All @@ -54,6 +60,7 @@ public EurekaServerExtractor eurekaServerExtractor(){


@Bean
@ConditionalOnMissingBean(value = {BambooConfiguration.UnUseBambooIRule.class})
public IRule ribbonRule() {
BambooZoneAvoidanceRule rule = new BambooZoneAvoidanceRule();
rule.initWithNiwsConfig(config);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@ public BambooZoneAvoidanceRule() {

@Override
public AbstractServerPredicate getPredicate() {
BambooRequestContext requestContext = BambooRequestContext.currentRequestCentxt();
if(requestContext==null || StringUtils.isEmpty(requestContext.getApiVersion())){
return super.getPredicate();
}
return bambooCompositePredicate;
}

Expand Down
79 changes: 79 additions & 0 deletions fm-cloud/fm-cloud-plugins/fm-cloud-gray-bunny-core/pom.xml
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>
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;
}
}
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;
}
}
Loading

0 comments on commit 0bae5f0

Please sign in to comment.