Commit 7fd83dc8 by Spencer Gibb

add @EnableTurbine to allow boot apps to embed the turbine server

parent 630aeb05
......@@ -7,7 +7,7 @@
<artifactId>spring-cloud-netflix</artifactId>
<version>1.0.0.BUILD-SNAPSHOT</version>
<packaging>pom</packaging>
<name>spring-cloud-netflix</name>
<name>Spring Cloud Netflix</name>
<description>Spring Cloud Netflix</description>
<parent>
......
......@@ -5,7 +5,7 @@
<artifactId>spring-cloud-netflix-core</artifactId>
<packaging>jar</packaging>
<name>spring-cloud-netflix-core</name>
<name>Spring Cloud Netflix Core</name>
<description>Spring Cloud Netflix Core</description>
<parent>
......
......@@ -2,7 +2,7 @@
<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">
<modelVersion>4.0.0</modelVersion>
<artifactId>spring-cloud-netflix-turbine</artifactId>
<packaging>war</packaging>
<packaging>jar</packaging>
<name>Spring Cloud Netflix Turbine</name>
<url>http://projects.spring.io/spring-cloud/</url>
<parent>
......@@ -14,30 +14,18 @@
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<!--skip deploy (this is just a test module) -->
<artifactId>maven-deploy-plugin</artifactId>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
</plugins>
</build>
<properties>
<spring-cloud-config.version>1.0.0.BUILD-SNAPSHOT</spring-cloud-config.version>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config</artifactId>
<version>${spring-cloud-config.version}</version>
<artifactId>spring-cloud-starters</artifactId>
<version>1.0.0.BUILD-SNAPSHOT</version>
<type>pom</type>
<scope>import</scope>
</dependency>
......@@ -45,24 +33,16 @@
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-netflix-core</artifactId>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<artifactId>spring-cloud-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-client</artifactId>
<artifactId>spring-cloud-starter-eureka</artifactId>
</dependency>
<dependency>
<groupId>com.netflix.eureka</groupId>
<artifactId>eureka-client</artifactId>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
</dependency>
<dependency>
<groupId>com.netflix.turbine</groupId>
......
/*
* Copyright 2013-2014 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 org.springframework.cloud.netflix.turbine;
import org.springframework.context.annotation.Import;
import java.lang.annotation.*;
/**
* @author Spencer Gibb
*
*/
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Import(TurbineConfiguration.class)
public @interface EnableTurbine {
}
package io.spring.cloud.netflix.turbine;
package org.springframework.cloud.netflix.turbine;
import com.netflix.appinfo.AmazonInfo;
import com.netflix.appinfo.DataCenterInfo;
......@@ -16,9 +16,9 @@ import org.slf4j.LoggerFactory;
import java.util.*;
/**
* Class that encapsulates an {@link InstanceDiscovery} implementation that uses Eureka (see https://github.com/Netflix/eureka)
* The plugin requires a list of applications configured. It then queries the set of instances for each application.
* Instance information retrieved from Eureka must be translated to something that Turbine can understand i.e the {@link Instance} class.
* Class that encapsulates an {@link com.netflix.turbine.discovery.InstanceDiscovery} implementation that uses Eureka (see https://github.com/Netflix/eureka)
* The plugin requires a list of applications configured. It then queries the set of instances for each application.
* Instance information retrieved from Eureka must be translated to something that Turbine can understand i.e the {@link com.netflix.turbine.discovery.Instance} class.
*
* All the logic to perform this translation can be overriden here, so that you can provide your own implementation if needed.
*/
......@@ -31,7 +31,7 @@ public class EurekaInstanceDiscovery implements InstanceDiscovery {
public EurekaInstanceDiscovery() {
// Eureka client should already be configured by spring-platform-netflix-core
// initialize eureka client. make sure eureka properties are properly configured in config.properties
// initialize eureka client.
//DiscoveryManager.getInstance().initComponent(new MyDataCenterInstanceConfig(), new DefaultEurekaClientConfig());
}
......@@ -42,7 +42,7 @@ public class EurekaInstanceDiscovery implements InstanceDiscovery {
@Override
public Collection<Instance> getInstanceList() throws Exception {
List<Instance> instances = new ArrayList<>();
List<Instance> instances = new ArrayList<Instance>();
List<String> appNames = parseApps();
if (appNames == null || appNames.size() == 0) {
......@@ -75,7 +75,7 @@ public class EurekaInstanceDiscovery implements InstanceDiscovery {
*/
private List<Instance> getInstancesForApp(String appName) throws Exception {
List<Instance> instances = new ArrayList<>();
List<Instance> instances = new ArrayList<Instance>();
logger.info("Fetching instances for app: {}", appName);
Application app = DiscoveryManager.getInstance().getDiscoveryClient().getApplication(appName);
......@@ -162,9 +162,10 @@ public class EurekaInstanceDiscovery implements InstanceDiscovery {
* @return
*/
protected String getClusterName(InstanceInfo iInfo) {
//TODO: make ASG configurable return iInfo.getASGName();
//TODO: make ASG configurable using app name for demo. //return iInfo.getASGName();
//AppGroupName is UPPERCASE from eureka
return iInfo.getAppGroupName();
//return iInfo.getAppGroupName();
return iInfo.getAppName();
}
/**
......
package io.spring.cloud.netflix.turbine;
package org.springframework.cloud.netflix.turbine;
import com.netflix.config.DynamicPropertyFactory;
import com.netflix.config.DynamicStringProperty;
......@@ -28,7 +28,7 @@ public class SpringAggregatorFactory implements ClusterMonitorFactory<AggDataFro
private static final DynamicStringProperty aggClusters = DynamicPropertyFactory.getInstance().getStringProperty("turbine.aggregator.clusterConfig", null);
/**
* @return {@link ClusterMonitor}<{@link AggDataFromCluster}>
* @return {@link com.netflix.turbine.monitor.cluster.ClusterMonitor}<{@link com.netflix.turbine.data.AggDataFromCluster}>
*/
@Override
public ClusterMonitor<AggDataFromCluster> getClusterMonitor(String name) {
......
package io.spring.cloud.netflix.turbine;
package org.springframework.cloud.netflix.turbine;
import com.netflix.config.DynamicBooleanProperty;
import com.netflix.config.DynamicPropertyFactory;
......@@ -13,6 +13,7 @@ import com.netflix.turbine.monitor.instance.InstanceUrlClosure;
/**
* Created by sgibb on 7/14/14.
* TODO: convert to ConfigurationProperties (how to do per-cluster configuration?)
*/
public class SpringClusterMonitor extends AggregateClusterMonitor {
......@@ -32,8 +33,8 @@ public class SpringClusterMonitor extends AggregateClusterMonitor {
*/
public static InstanceUrlClosure ClusterConfigBasedUrlClosure = new InstanceUrlClosure() {
private final DynamicStringProperty defaultUrlClosureConfig = DynamicPropertyFactory.getInstance().getStringProperty("turbine.instanceUrlSuffix", null);
private final DynamicBooleanProperty instanceInsertPort = DynamicPropertyFactory.getInstance().getBooleanProperty("turbine.instanceInsertPort", false);
private final DynamicStringProperty defaultUrlClosureConfig = DynamicPropertyFactory.getInstance().getStringProperty("turbine.instanceUrlSuffix", "hystrix.stream");
private final DynamicBooleanProperty instanceInsertPort = DynamicPropertyFactory.getInstance().getBooleanProperty("turbine.instanceInsertPort", true);
@Override
public String getUrlPath(Instance host) {
......
package io.spring.cloud.netflix.turbine;
package org.springframework.cloud.netflix.turbine;
import com.netflix.turbine.discovery.InstanceDiscovery;
import com.netflix.turbine.init.TurbineInit;
import com.netflix.turbine.plugins.PluginsFactory;
import com.netflix.turbine.streaming.servlet.TurbineStreamServlet;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.context.embedded.ServletRegistrationBean;
import org.springframework.boot.context.web.SpringBootServletInitializer;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.context.SmartLifecycle;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.Ordered;
/**
* Created by sgibb on 7/11/14.
*/
@Configuration
@ComponentScan
@EnableAutoConfiguration
public class Application extends SpringBootServletInitializer implements SmartLifecycle {
@EnableEurekaClient
public class TurbineConfiguration implements SmartLifecycle, Ordered {
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(Application.class).web(true);
}
public static void main(String[] args) {
new SpringApplicationBuilder(Application.class).web(true).run(args);
@Bean
public ServletRegistrationBean turbineStreamServlet() {
return new ServletRegistrationBean(new TurbineStreamServlet(), "/turbine.stream");
}
@Bean
public ServletRegistrationBean mockStreamServlet() {
return new ServletRegistrationBean(new TurbineStreamServlet(), "/turbine.stream");
public InstanceDiscovery instanceDiscovery() {
return new EurekaInstanceDiscovery();
}
private boolean running;
......@@ -48,7 +42,10 @@ public class Application extends SpringBootServletInitializer implements SmartLi
@Override
public void start() {
//TODO: figure out ordering, so this is already run by EurekaClientConfiguration
//DiscoveryManager.getInstance().initComponent(instanceConfig, clientConfig);
PluginsFactory.setClusterMonitorFactory(new SpringAggregatorFactory());
PluginsFactory.setInstanceDiscovery(instanceDiscovery());
TurbineInit.init();
}
......@@ -66,4 +63,9 @@ public class Application extends SpringBootServletInitializer implements SmartLi
public int getPhase() {
return 0;
}
@Override
public int getOrder() {
return -1;
}
}
#org.springframework.context.ApplicationListener=\
#org.springframework.cloud.netflix.eureka.EurekaStartingListener,\
#org.springframework.cloud.netflix.eureka.EurekaUpListener,\
#org.springframework.cloud.netflix.eureka.EurekaOutOfServiceListener
#org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
#org.springframework.cloud.netflix.archaius.ArchaiusAutoConfiguration,\
#org.springframework.cloud.netflix.feign.FeignAutoConfiguration
info:
component: Turbine
endpoints:
restart:
enabled: true
shutdown:
enabled: true
server:
port: 8989
context-path: /turbine
logging:
level: INFO
eureka:
client:
#Region where eureka is deployed -For AWS specify one of the AWS regions, for other datacenters specify a arbitrary string
#indicating the region.This is normally specified as a -D option (eg) -Deureka.region=us-east-1
region: default
#For eureka clients running in eureka server, it needs to connect to servers in other zones
preferSameZone: false
#Change this if you want to use a DNS based lookup for determining other eureka servers. For example
#of specifying the DNS entries, check the eureka-client-test.properties, eureka-client-prod.properties
#shouldUseDns: false
us-east-1:
availabilityZones: default
serviceUrl:
default: http://localhost:8080/eureka/v2/
defaultZone: http://localhost:8080/eureka/v2/
instance:
#Virtual host name by which the clients identifies this service
virtualHostName: ${spring.application.name}
spring:
application:
name: turbine
platform:
config:
uri: http://localhost:${config.port:8888}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment