Skip to content

Commit

Permalink
Hack Hystrix Dashbaord to have a select which loads eureka apps so yo…
Browse files Browse the repository at this point in the history
…u dont need to type it
  • Loading branch information
Diego Pacheco committed May 4, 2016
1 parent f5b2019 commit 0d9d1b6
Show file tree
Hide file tree
Showing 11 changed files with 106 additions and 168 deletions.
4 changes: 1 addition & 3 deletions hystrix-dashboard/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ dependencies {
compile 'org.apache.httpcomponents:httpclient:4.2.1'
compile 'log4j:log4j:1.2.17'
compile 'org.slf4j:slf4j-log4j12:1.7.0'
compile 'com.squareup.retrofit:retrofit:2.0.0-beta2'
compile 'com.squareup.retrofit2:converter-simplexml:2.0.2'
compile 'com.squareup.retrofit2:converter-jackson:2.0.2'
compile 'commons-io:commons-io:2.5'
testCompile 'junit:junit:4.12'
}

Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.netflix.hystrix.dashboard.stream;

import java.io.IOException;

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

import org.apache.commons.io.IOUtils;

/**
* Servlet that calls eureka REST api in order to get instances information. <BR>
* You need provide a url parameter. i.e: eureka?url=http://127.0.0.1:8080/eureka/v2/apps
*
* @author diegopacheco
*
*/
public class EurekaInfoServlet extends HttpServlet {

private static final long serialVersionUID = 1L;

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

String uri = request.getParameter("url");
if (uri==null || "".equals(uri)) response.getOutputStream().write("Error. You need supply a valid eureka URL ".getBytes());

try{
response.setContentType("application/xml");
response.setHeader("Content-Encoding", "gzip");
IOUtils.copy( UrlUtils.readXmlInputStream(uri) ,response.getOutputStream());
}catch(Exception e){
response.getOutputStream().write(("Error. You need supply a valid eureka URL. Ex: " + e + "").getBytes());
}

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.netflix.hystrix.dashboard.stream;

import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;

/**
* Utility class to work with InputStreams
*
* @author diegopacheco
*
*/
public class UrlUtils {

public static InputStream readXmlInputStream(String uri){

if (uri==null || "".equals(uri)) throw new IllegalArgumentException("Invalid uri. URI cannot be null or blank. ");

try{
URL url = new URL(uri);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("GET");
connection.setRequestProperty("Accept", "application/xml");

return connection.getInputStream();

}catch(Exception e){
throw new RuntimeException(e);
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.netflix.hystrix.dashboard.stream;

import org.junit.Test;

/**
* UrlUtilsTest unit tests
*
* @author diegopacheco
*
*/
public class UrlUtilsTest {

@Test(expected=IllegalArgumentException.class)
public void testReadXmlInputStreamWithNull() {
UrlUtils.readXmlInputStream(null);
}

@Test(expected=IllegalArgumentException.class)
public void testReadXmlInputStreamWithBlank() {
UrlUtils.readXmlInputStream("");
}

}

This file was deleted.

11 changes: 11 additions & 0 deletions hystrix-dashboard/src/main/webapp/WEB-INF/web.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,16 @@
<servlet-name>ProxyStreamServlet</servlet-name>
<url-pattern>/proxy.stream</url-pattern>
</servlet-mapping>

<servlet>
<description />
<display-name>EurekaInfoServlet</display-name>
<servlet-name>EurekaInfoServlet</servlet-name>
<servlet-class>com.netflix.hystrix.dashboard.stream.EurekaInfoServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>EurekaInfoServlet</servlet-name>
<url-pattern>/eureka</url-pattern>
</servlet-mapping>

</web-app>
6 changes: 2 additions & 4 deletions hystrix-dashboard/src/main/webapp/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,12 @@
}
});
});

console.log(2);

$(document).ready(function(){

$('#eurekaURL').on('input',function(e){

$.get($('#eurekaURL').val(), function( data ) {
url = window.location.pathname + "eureka?url=" + $('#eurekaURL').val()
$.get(url,function( data ) {

$(data.children).find("application").each(function(index,item){
appName = $(item).find("name")[0].innerHTML
Expand Down

0 comments on commit 0d9d1b6

Please sign in to comment.