Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
public class PrometheusCollector extends Collector {
private static Logger logger = LoggerFactory.getLogger(PrometheusCollector.class);
public static HTTPServer server;
private final static InetSocketAddress DEFAULT_PROMETHEUS_MONITOR_PORT = new InetSocketAddress(9095);
private final static InetSocketAddress DEFAULT_PROMETHEUS_MONITOR_PORT = new InetSocketAddress("0.0.0.0",9095);

private static final QName HTTPCONNECTOR_TYPE = new QName("http://xsd.tns.tibco.com/bw/models/sharedresource/httpconnector","HttpConnectorConfiguration");
private final static CountDownLatch proxyInitLatch = new CountDownLatch(1);
Expand Down
35 changes: 35 additions & 0 deletions turbine-server/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# turbine-server
___

## Turbine server for TIBCO BWCE
### Environment Variables -

PLATFORM = Openshit/Kubernetes (Default - Kubernetes)

NAMESPACE = k8s namespace to monitor (Default - Current Namespace)

### Label Selector

To include a particular application, add the following label to pods.

hystrix.enabled=true

### Build docker image

From the project path, execute -

mvn clean package docker:build

### Monitoring applications in projects/namespaces other than current

Permissions need to be provided to view services from other projects/namespaces.

##### Kubernetes (Tested on minikube)
Add clusterrolebinding

kubectl create clusterrolebinding [hystrix-namespace] --clusterrole cluster-admin --serviceaccount=[hystrix-namespace]:[user]

##### Openshift
oc project [project to monitor]

oc policy add-role-to-user view system:serviceaccount:[hystrix-namespace]:[user]
26 changes: 26 additions & 0 deletions turbine-server/com.tibco.bw.turbine.server/.classpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="target/classes" path="src/main/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
</classpath>
1 change: 1 addition & 0 deletions turbine-server/com.tibco.bw.turbine.server/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/target/
23 changes: 23 additions & 0 deletions turbine-server/com.tibco.bw.turbine.server/.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>com.tibco.bw.turbine.server</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
</natures>
</projectDescription>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
eclipse.preferences.version=1
encoding//src/main/java=UTF-8
encoding/<project>=UTF-8
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.source=1.8
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
activeProfiles=
eclipse.preferences.version=1
resolveWorkspaceProjects=true
version=1
104 changes: 104 additions & 0 deletions turbine-server/com.tibco.bw.turbine.server/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- /*Copyright © 2019. TIBCO Software Inc. All Rights Reserved.*/ -->

<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>

<groupId>com.tibco</groupId>
<artifactId>turbine-server</artifactId>
<version>2.0.0-SNAPSHOT</version>
<packaging>war</packaging>
<name>Netflix Turbine</name>

<properties>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.source>1.8</maven.compiler.source>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<docker.group.name>tibco</docker.group.name>
</properties>

<dependencies>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.netflix.turbine</groupId>
<artifactId>turbine-core</artifactId>
<version>1.0.0</version>
</dependency>
<dependency>
<groupId>io.fabric8</groupId>
<artifactId>openshift-client</artifactId>
<version>4.0.3</version>
</dependency>
<dependency>
<groupId>io.fabric8</groupId>
<artifactId>kubernetes-client</artifactId>
<version>4.0.3</version>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.6</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
<plugin>
<groupId>io.fabric8</groupId>
<artifactId>docker-maven-plugin</artifactId>
<version>0.26.1</version>
<configuration>
<dockerHost>http://localhost:2375</dockerHost>
<images>
<image>
<name>${docker.group.name}/${project.artifactId}:${project.version}</name>
<build>
<from>tomcat:8.0.30-jre8</from>
<tags>
<tag>latest</tag>
<tag>${project.version}</tag>
</tags>
<ports>
<port>8080</port>
</ports>
<runCmds>
<run>rm -rf /usr/local/tomcat/webapps/ROOT</run>
<run>rm -rf /usr/local/tomcat/webapps/docs</run>
<run>rm -rf /usr/local/tomcat/webapps/examples</run>
<run>rm -rf /usr/local/tomcat/webapps/host-manager</run>
<run>rm -rf /usr/local/tomcat/webapps/manager</run>
</runCmds>
<assembly>
<basedir>/usr/local</basedir>
<inline>
<files>
<file>
<source>${project.build.directory}/${project.artifactId}-${project.version}.war</source>
<outputDirectory>tomcat/webapps/</outputDirectory>
<destName>ROOT.war</destName>
</file>
</files>
</inline>
</assembly>
</build>
<run>
<ports>
<port>http.port:8080</port>
</ports>
</run>
</image>
</images>
</configuration>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*Copyright © 2019. TIBCO Software Inc. All Rights Reserved.*/
package com.tibco.bw.turbine.server;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.netflix.turbine.discovery.Instance;

public class DiscoveryFeedbackServlet extends HttpServlet {

private static final long serialVersionUID = 1L;
private static final OpenShiftDiscovery DISCOVERY = OpenShiftDiscovery.getOpenShiftDiscovery();

@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
resp.setContentType("text/html");
PrintWriter out = resp.getWriter();
out.println("<h1>Hystrix Endpoints: "+OpenShiftDiscovery.getNamespace() +"</h1>");
try {
for (Instance instance : DISCOVERY.getInstanceList()) {
out.println("<h3>" + instance.getHostname() + " : " + (instance.isUp()?"Running":"Unreachable") + "</h3>");
}
} catch (Throwable t) {
t.printStackTrace(out);
}
out.flush();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*Copyright © 2019. TIBCO Software Inc. All Rights Reserved.*/
package com.tibco.bw.turbine.server;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;

import com.netflix.turbine.discovery.Instance;
import com.netflix.turbine.discovery.InstanceDiscovery;

import io.fabric8.kubernetes.api.model.Pod;
import io.fabric8.kubernetes.api.model.PodList;
import io.fabric8.kubernetes.client.DefaultKubernetesClient;
import io.fabric8.kubernetes.client.KubernetesClient;
import io.fabric8.openshift.client.DefaultOpenShiftClient;

public class OpenShiftDiscovery implements InstanceDiscovery {

private static final Logger logger = Logger.getLogger(OpenShiftDiscovery.class.getName());
private static String platform= System.getenv("PLATFORM");
private static String namespace= System.getenv("NAMESPACE");
private static final String HYSTRIX_ENABLED = "hystrix.enabled";
private static final String TRUE = "true";
private static final String DEFAULT = "default";
private static final String OPENSHIFT = "Openshift";
private static final String KUBERNETES = "Kubernetes";
private static OpenShiftDiscovery openshiftDiscovery;
private boolean isOpenshift;
private KubernetesClient client;

public OpenShiftDiscovery() {

isOpenshift=(platform!=null && platform.equalsIgnoreCase(OPENSHIFT));
logger.log(Level.INFO,"Configuring for "+ (isOpenshift?OPENSHIFT:KUBERNETES));
try{
client=(isOpenshift)?new DefaultOpenShiftClient():new DefaultKubernetesClient();
}catch (Exception e){
logger.log(Level.SEVERE,"Cannot connect to master server.",e);
}
if(namespace==null)
namespace=client.getNamespace();
logger.log(Level.INFO,"Using Namespace " + namespace);
openshiftDiscovery=this;
}

public Collection<Instance> getInstanceList() throws Exception {
List<Instance> result = new ArrayList<Instance>();
try{
PodList podList=client.pods().inNamespace(namespace).withLabel(HYSTRIX_ENABLED, TRUE).list();
for(Pod pod : podList.getItems()){
String podip=pod.getStatus().getPodIP();
Instance instance = new Instance(podip, DEFAULT, true);
result.add(instance);
}
}catch(Exception e){
logger.log(Level.SEVERE,"Cannot fetch endpoints.",e);
}
return result;
}

public static String getNamespace(){
return namespace;
}

public static OpenShiftDiscovery getOpenShiftDiscovery(){
return openshiftDiscovery;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*Copyright © 2019. TIBCO Software Inc. All Rights Reserved.*/
package com.tibco.bw.turbine.server;

import java.util.logging.Logger;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

import com.netflix.turbine.plugins.PluginsFactory;
import com.netflix.turbine.init.TurbineInit;

public class TurbineInitializer implements ServletContextListener {

private static final Logger logger = Logger.getLogger(TurbineInitializer.class.getName());

@Override
public void contextInitialized(ServletContextEvent sce) {
logger.info("Starting Turbine server");
PluginsFactory.setInstanceDiscovery(new OpenShiftDiscovery());
TurbineInit.init();
}

@Override
public void contextDestroyed(ServletContextEvent sce) {
logger.info("Stopping Turbine server");
TurbineInit.stop();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#Copyright � 2019. TIBCO Software Inc. All Rights Reserved.#

#################################
# Turbine
#################################
# turbine clusters
turbine.aggregator.clusterConfig=default
# turbine url suffix to where the hystrix stream can be retrieved from each cluster instance
turbine.instanceUrlSuffix=:8090/hystrix.stream
#################################
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- /*Copyright © 2019. TIBCO Software Inc. All Rights Reserved.*/ -->
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5">

<listener>
<listener-class>com.tibco.bw.turbine.server.TurbineInitializer</listener-class>
</listener>

<servlet>
<description></description>
<display-name>TurbineStreamServlet</display-name>
<servlet-name>TurbineStreamServlet</servlet-name>
<servlet-class>com.netflix.turbine.streaming.servlet.TurbineStreamServlet</servlet-class>
</servlet>

<servlet>
<description>Discovery Feedback Servlet</description>
<display-name>DiscoveryFeedbackServlet</display-name>
<servlet-name>DiscoveryFeedbackServlet</servlet-name>
<servlet-class>com.tibco.bw.turbine.server.DiscoveryFeedbackServlet</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>TurbineStreamServlet</servlet-name>
<url-pattern>/turbine.stream</url-pattern>
</servlet-mapping>

<servlet-mapping>
<servlet-name>DiscoveryFeedbackServlet</servlet-name>
<url-pattern>/discovery</url-pattern>
</servlet-mapping>

</web-app>