Skip to content

Commit 7285aa9

Browse files
committed
Adding UFO Control
1 parent b374010 commit 7285aa9

8 files changed

Lines changed: 402 additions & 0 deletions

File tree

ufocontrol/build.gradle

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
buildscript {
2+
ext {
3+
springBootVersion = '1.4.1.RELEASE'
4+
}
5+
repositories {
6+
mavenCentral()
7+
}
8+
dependencies {
9+
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
10+
}
11+
}
12+
13+
apply plugin: 'java'
14+
apply plugin: 'eclipse'
15+
apply plugin: 'idea'
16+
apply plugin: 'spring-boot'
17+
apply plugin: 'io.spring.dependency-management'
18+
19+
jar {
20+
baseName = 'ufocontrol'
21+
version = '0.0.1-SNAPSHOT'
22+
}
23+
sourceCompatibility = 1.8
24+
targetCompatibility = 1.8
25+
26+
repositories {
27+
mavenCentral()
28+
}
29+
30+
31+
dependencies {
32+
compile('org.springframework.cloud:spring-cloud-starter-hystrix')
33+
compile('org.springframework.boot:spring-boot-starter-web')
34+
testCompile('org.springframework.boot:spring-boot-starter-test')
35+
}
36+
37+
dependencyManagement {
38+
imports {
39+
mavenBom "org.springframework.cloud:spring-cloud-dependencies:Brixton.SR5"
40+
}
41+
}
42+
43+
44+
eclipse {
45+
classpath {
46+
containers.remove('org.eclipse.jdt.launching.JRE_CONTAINER')
47+
containers 'org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8'
48+
}
49+
}

ufocontrol/pom.xml

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
6+
<groupId>hello</groupId>
7+
<artifactId>ufocontrol</artifactId>
8+
<version>0.0.1-SNAPSHOT</version>
9+
<packaging>jar</packaging>
10+
11+
<parent>
12+
<groupId>org.springframework.boot</groupId>
13+
<artifactId>spring-boot-starter-parent</artifactId>
14+
<version>1.4.1.RELEASE</version>
15+
<relativePath/> <!-- lookup parent from repository -->
16+
</parent>
17+
18+
<properties>
19+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
20+
<java.version>1.8</java.version>
21+
</properties>
22+
23+
<dependencies>
24+
<dependency>
25+
<groupId>org.springframework.cloud</groupId>
26+
<artifactId>spring-cloud-starter-hystrix</artifactId>
27+
</dependency>
28+
<dependency>
29+
<groupId>org.springframework.boot</groupId>
30+
<artifactId>spring-boot-starter-web</artifactId>
31+
</dependency>
32+
33+
<dependency>
34+
<groupId>org.springframework.boot</groupId>
35+
<artifactId>spring-boot-starter-test</artifactId>
36+
<scope>test</scope>
37+
</dependency>
38+
</dependencies>
39+
40+
<dependencyManagement>
41+
<dependencies>
42+
<dependency>
43+
<groupId>org.springframework.cloud</groupId>
44+
<artifactId>spring-cloud-dependencies</artifactId>
45+
<version>Brixton.SR5</version>
46+
<type>pom</type>
47+
<scope>import</scope>
48+
</dependency>
49+
</dependencies>
50+
</dependencyManagement>
51+
52+
<build>
53+
<plugins>
54+
<plugin>
55+
<groupId>org.springframework.boot</groupId>
56+
<artifactId>spring-boot-maven-plugin</artifactId>
57+
</plugin>
58+
</plugins>
59+
</build>
60+
61+
62+
</project>

ufocontrol/resources/UFOAdmin.html

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<html>
2+
<head>
3+
<title>Mastering the Dynatrace UFO</title>
4+
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
5+
</head>
6+
<body>
7+
<div style="padding:16px;">
8+
UFO IP : <input type="textbox" id="IP" value="10.0.0.76"></input>
9+
</div>
10+
<div style="padding:16px;">
11+
Top Color : <input type="textbox" id="TopColor" value="00FF00"></input> Bottom Color : <input type="textbox" id="BottomColor" value="FF0000"></input>
12+
13+
</div>
14+
<div>
15+
<p class="status">last status call</p>
16+
</div>
17+
18+
<button id="Reset">Reset UFO</button>
19+
<button id="SetTop">Set TOP</button>
20+
<button id="SetBottom">Set Bottom</button>
21+
22+
<script>
23+
function getUFOURL() {
24+
return "http://" + $('#IP').val();
25+
}
26+
function callUFO(apiString) {
27+
var fullURL = getUFOURL() + apiString;
28+
$.ajax({
29+
url: fullURL
30+
}).done(function() {
31+
$('.status').append("success");
32+
}).fail(function() {
33+
$('.status').append("success");
34+
});
35+
}
36+
37+
$("#Reset").click(function () {
38+
callUFO("/api?top_init=0&bottom_init=0");
39+
});
40+
41+
$("#SetTop").click(function () {
42+
var color = $('#TopColor').val();
43+
callUFO("/api?top_init=1&top_bg=" + color);
44+
});
45+
46+
$("#SetBottom").click(function () {
47+
var color = $('#BottomColor').val();
48+
callUFO("/api?bottom_init=0&bottom_bg=" + color);
49+
});
50+
</script>
51+
52+
</body>
53+
</html>
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
package hello;
2+
3+
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
4+
5+
import org.springframework.beans.factory.annotation.Value;
6+
import org.springframework.stereotype.Service;
7+
import org.springframework.web.client.RestTemplate;
8+
9+
import java.net.URI;
10+
import java.util.ArrayList;
11+
import java.util.List;
12+
13+
@Service
14+
public class BookService {
15+
16+
@Value("${bookstore.url}")
17+
private String bookstoreUrl;
18+
public String getBookstoreUrl() {
19+
if(bookstoreUrl == null || bookstoreUrl.length() == 0) bookstoreUrl = "http://localhost:9090";
20+
return bookstoreUrl;
21+
}
22+
23+
private final RestTemplate restTemplate;
24+
25+
// some helper functions
26+
public static List<String>convertStringToList(String listAsString) {
27+
List<String> returnList = new ArrayList<String>();
28+
for(String value : listAsString.split(",")) {
29+
returnList.add(value.trim());
30+
}
31+
return returnList;
32+
}
33+
34+
public static String convertListToString(List<String> list) {
35+
StringBuffer sb = new StringBuffer();
36+
for(String str : list) {
37+
if(sb.length() >= 0) sb.append(",");
38+
sb.append(str);
39+
}
40+
return sb.toString();
41+
}
42+
43+
public BookService(RestTemplate rest) {
44+
this.restTemplate = rest;
45+
}
46+
47+
@HystrixCommand(fallbackMethod = "reliable")
48+
public String readingList() {
49+
URI uri = URI.create(getBookstoreUrl() + "/recommended");
50+
51+
return this.restTemplate.getForObject(uri, String.class);
52+
}
53+
54+
@HystrixCommand(fallbackMethod = "reliableAll")
55+
public String allBooks() {
56+
URI uri = URI.create(getBookstoreUrl() + "/all");
57+
58+
return this.restTemplate.getForObject(uri, String.class);
59+
}
60+
61+
@HystrixCommand(fallbackMethod = "reliableGenres")
62+
public List<String> genres() {
63+
URI uri = URI.create(getBookstoreUrl() + "/genres");
64+
return convertStringToList(this.restTemplate.getForObject(uri, String.class));
65+
}
66+
67+
@HystrixCommand(fallbackMethod = "reliableBooksByGenres")
68+
public List<String> booksByGenre(String genre) {
69+
URI uri = URI.create(getBookstoreUrl() + "/all/" + genre);
70+
71+
return convertStringToList(this.restTemplate.getForObject(uri, String.class));
72+
}
73+
74+
public String reliableAll() {
75+
return "all books";
76+
}
77+
78+
public String reliable() {
79+
return "Cloud Native Java (O'Reilly)";
80+
}
81+
82+
public List<String> reliableGenres() {
83+
return convertStringToList("Fiction, Computer");
84+
}
85+
86+
public List<String> reliableBooksByGenres(String genre) {
87+
return convertStringToList("Book 1 in " + genre);
88+
}
89+
}

0 commit comments

Comments
 (0)