Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
08694ee
Changes including chaos
asunder123 Oct 1, 2021
9c48976
Corrections
asunder123 Oct 1, 2021
2e1d778
Succesfully installed chaos
asunder123 Oct 1, 2021
8ff5820
Update readme.md
asunder123 Oct 1, 2021
fcf792d
Changes to add jaeger client
asunder123 Oct 4, 2021
98a6afe
Merge branch 'test' of https://github.com/asunder123/spring-boot-rest…
asunder123 Oct 4, 2021
b28ff11
Create Jenkinsfile
asunder123 Oct 5, 2021
d013297
Update Jenkinsfile
asunder123 Oct 5, 2021
0e8ecd6
Update Jenkinsfile
asunder123 Oct 5, 2021
0dd25f6
Update Jenkinsfile
asunder123 Oct 5, 2021
c0a622f
Update Jenkinsfile
asunder123 Oct 5, 2021
4e73287
Update Jenkinsfile
asunder123 Oct 5, 2021
bc57b3f
Update Jenkinsfile
asunder123 Oct 5, 2021
5235b5d
Update Jenkinsfile
asunder123 Oct 5, 2021
333cccd
Update Jenkinsfile
asunder123 Oct 5, 2021
f24279e
Update Jenkinsfile
asunder123 Oct 5, 2021
9b18a34
Update Jenkinsfile
asunder123 Oct 5, 2021
7d68b1f
Update Jenkinsfile
asunder123 Oct 5, 2021
d09559b
Update Jenkinsfile
asunder123 Oct 5, 2021
af12179
Update Jenkinsfile
asunder123 Oct 5, 2021
bfc2f7b
Update Jenkinsfile
asunder123 Oct 5, 2021
2fdea00
Update Jenkinsfile
asunder123 Oct 5, 2021
062a881
Update Jenkinsfile
asunder123 Oct 5, 2021
7526d31
Update Jenkinsfile
asunder123 Oct 5, 2021
8d18f9c
Update Jenkinsfile
asunder123 Oct 5, 2021
f7d5b42
Update Jenkinsfile
asunder123 Oct 5, 2021
b90e3b0
Update Jenkinsfile
asunder123 Oct 5, 2021
2ec08ea
Update Jenkinsfile
asunder123 Oct 5, 2021
62a712b
Update Jenkinsfile
asunder123 Oct 5, 2021
22228db
Update Jenkinsfile
asunder123 Oct 5, 2021
450eb2a
Update Jenkinsfile
asunder123 Oct 5, 2021
bfe4ff5
Update Jenkinsfile
asunder123 Oct 5, 2021
decdbf1
Update Jenkinsfile
asunder123 Oct 5, 2021
ce80c59
Update Jenkinsfile
asunder123 Oct 5, 2021
fb4802d
Update Jenkinsfile
asunder123 Oct 5, 2021
f1d0c7c
Create test
asunder123 Oct 5, 2021
55b9261
Delete test
asunder123 Oct 5, 2021
0259cdc
Create triggerjenkins
asunder123 Oct 5, 2021
1cb97aa
Create testcleanbuild
asunder123 Oct 5, 2021
dd885d2
Update Jenkinsfile
asunder123 Oct 5, 2021
53615bf
Update Jenkinsfile
asunder123 Oct 5, 2021
6bb0835
Changes
asunder123 Oct 5, 2021
0587051
Changes to application properties
asunder123 Oct 5, 2021
970f2d7
Changes to appl properties
asunder123 Oct 5, 2021
5987d53
Trigger jenkins script
asunder123 Oct 5, 2021
9f0e958
Bash script to test jar after changes
asunder123 Oct 6, 2021
ba6eedc
Delete testcleanbuild
asunder123 Oct 6, 2021
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
14 changes: 14 additions & 0 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@

pipeline {
agent { any { image 'maven:3.3.3' } }
stages {
stage('build') {
steps {
sh 'mvn --version'
sh 'mvn clean package'
sh 'mvn clean install'
}
}

}
}
75 changes: 72 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,79 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.1.RELEASE</version>
<version>2.3.12.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<!--maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<maven.compiler.release>11</maven.compiler.release-->
</properties>

<dependencies>
<!--dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>5.0.6.RELEASE</version>
</dependency-->
<dependency>
<groupId>io.opentracing.contrib</groupId>
<artifactId>opentracing-spring-jaeger-web-starter</artifactId>
<version>3.3.1</version>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>1.4.200</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
<version>2.5.4</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.20</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>de.codecentric</groupId>
<artifactId>chaos-monkey-spring-boot</artifactId>
<!--classifier>jar-with-dependencies</classifier-->
<version>2.5.3</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>

<!--dependency>
<groupId>de.codecentric</groupId>
<artifactId>chaos-monkey-spring-boot</artifactId>
<classifier>jar-wth-dependencies</classifier>
<version>2.5.3</version>
</dependency-->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
Expand All @@ -49,6 +106,18 @@
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<!--version>2.3.6.RELEASE</version-->
<!--configuration>
<fork>true</fork>
<mainClass>SpringBootRestcontrollerExampleApplication</mainClass>
</configuration-->
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
Expand Down
27 changes: 23 additions & 4 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Spring Boot @RestController Example
# Spring Boot @RestController Example with Chaos Monkey Enabled in Spring Application Properties

## Description

Expand All @@ -8,8 +8,27 @@ The main goal of the project is to show how to write a `@RestController` in Spri

## How does it work?

You can use the endpoints behind `http://localhost:8080/spanish-greetings`. If you append `/random` to a `GET` request you'll receive a random Spanish greeting (which are actually hard-coded). You can also `GET` them by `id` (only from 1 to 3). To create a new one, you need to perform a `POST` operation.
You can use the endpoints behind `http://localhost:8082/spanish-greetings`. If you append `/random` to a `GET` request you'll receive a random Spanish greeting (which are actually hard-coded). You can also `GET` them by `id` (only from 1 to 3). To create a new one, you need to perform a `POST` operation.

Actually, much better if you just start the application and navigate to `http://localhost:8082/swagger-ui.html`. There you'll find a nice API documentation thanks to Swagger. Moreover, *you can play with it*.

![Swagger Documentation](images/swagger.png)

Upon Succesful Initialization of Chaos Monkey you should see something like this :

![image](https://user-images.githubusercontent.com/50335583/135620733-ee4eb8bc-918d-461a-8cca-40f085976f90.png)


In addition to the end points and controller, chaos testing can be done as shown using postman for the endpoints exposed under actuator:

![image](https://user-images.githubusercontent.com/50335583/135618904-26996ad8-1824-4d03-a97c-4e878b8ef2a2.png)
![image](https://user-images.githubusercontent.com/50335583/135619103-a6322eba-2fb0-4df9-847c-68daf95f5a6b.png)
![image](https://user-images.githubusercontent.com/50335583/135619155-9b62c70a-b8fa-4028-b11a-d58f2ba09b75.png)
![image](https://user-images.githubusercontent.com/50335583/135619288-a3968210-c7aa-48d9-8105-36be2bbacc18.png)
![image](https://user-images.githubusercontent.com/50335583/135619450-1a7e2d03-0fa4-4c14-bcdb-7d95c6cbee98.png)
![image](https://user-images.githubusercontent.com/50335583/135620247-d62f0021-a1e1-4464-9e62-0d58e705d623.png)




Actually, much better if you just start the application and navigate to `http://localhost:8080/swagger-ui.html`. There you'll find a nice API documentation thanks to Swagger. Moreover, *you can play with it*.

![Swagger Documentation](images/swagger.png)
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
package es.macero.dev;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.*;
import org.springframework.context.annotation.Bean;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
//import es.macero.dev.restexample.SpanishGreeting;

@SpringBootApplication
@SpringBootApplication(scanBasePackages="es.macero")
@EnableSwagger2
@EnableAutoConfiguration
public class SpringBootRestcontrollerExampleApplication {

public static void main(String[] args) {

SpringApplication.run(SpringBootRestcontrollerExampleApplication.class, args);
}

Expand All @@ -24,6 +27,15 @@ public Docket api() {
.apis(RequestHandlerSelectors.any())
.paths(PathSelectors.regex("/spanish-greeting.*"))
.build();



}

/*@Bean
public SpanishGreetingSpanishGreeting() {

return new SpanishGreeting();
}*/

}
8 changes: 6 additions & 2 deletions src/main/java/es/macero/dev/restexample/SpanishGreeting.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
package es.macero.dev.restexample;
import org.springframework.stereotype.*;
import org.springframework.beans.factory.annotation.*;

class SpanishGreeting {

@Component
public class SpanishGreeting {

//@Value("${name}")
private String message;

// Required for JSON deserialization
Expand Down
33 changes: 33 additions & 0 deletions src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#spring.datasource.url=jdbc:mysql://localhost:3306/db
#spring.datasource.username=""
#spring.datasource.password=""
#spring.datasource.driver-class-name=com.mysql.jdbc.Driver
#spring.jpa.database-platform = org.hibernate.dialect.MySQL5Dialect
spring.main.allow-bean-definition-overriding=true
opentracing.jaeger.http.sender.url=http://localhost:16686/api/traces
spring.datasource.url=jdbc:h2:mem:testdb
spring.datasource.driverClassName=org.h2.Driver
spring.datasource.username=
spring.datasource.password=
spring.jpa.database-platform=org.hibernate.dialect.H2Dialect
spring.jpa.generate-ddl=true
sring.jpa.hibernate.ddl-auto = update
spring.profiles.active=chaos-monkey
management.server.add-application-context-header=true
server.port=8082
chaos.monkey.enabled=true
#chaos.monkey.assaults.latencyActive=true
#chaos.monkey.assaults.latencyRangeStart=1000
#chaos.monkey.assaults.latencyRangeEnd=4500
chaos.monkey.watcher.controller=true
chaos.monkey.watcher.restController=true
chaos.monkey.watcher.service=true
chaos.monkey.assaults.watchedCustomServices=*
#chaos.monkey.watcher.repository=false
chaos.monkey.assaults.level=1
spring.aop.proxy-target-class=true
spring.application.admin.enabled=true
management.endpoint.chaosmonkey.enabled=true
#management.endpoint.chaosmonkeyjmx.enabled=false
management.endpoints.web.exposure.include=*
#management.server.port=8888
Empty file.