Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
69 commits
Select commit Hold shift + click to select a range
abd996a
added environment variables
VeerMuchandi Nov 10, 2016
b848602
Update application.properties
VeerMuchandi Nov 10, 2016
392f840
number format
VeerMuchandi Nov 10, 2016
ed0422e
Update application.properties
VeerMuchandi Nov 10, 2016
0ff2e32
Update SpringSampleAppApplication.java
VeerMuchandi Nov 10, 2016
dcb4317
Update application.properties
VeerMuchandi Nov 10, 2016
d0d4dea
Update SpringSampleAppApplication.java
VeerMuchandi Nov 10, 2016
0250b77
Update SpringSampleAppApplication.java
VeerMuchandi Nov 10, 2016
2f4113f
Update SpringSampleAppApplication.java
VeerMuchandi Nov 10, 2016
4840eb1
Update SpringSampleAppApplication.java
VeerMuchandi Nov 10, 2016
b08087c
looping through customers
VeerMuchandi Nov 11, 2016
501815c
Update SpringSampleAppApplication.java
VeerMuchandi Nov 11, 2016
801721a
Update SpringSampleAppApplication.java
VeerMuchandi Nov 11, 2016
44cd001
Update SpringSampleAppApplication.java
VeerMuchandi Nov 11, 2016
7333bf5
Update SpringSampleAppApplication.java
VeerMuchandi Nov 11, 2016
bd2cdd5
Update pom.xml
VeerMuchandi Nov 11, 2016
ae3bc15
Update pom.xml
VeerMuchandi Nov 11, 2016
cbdfe42
moved schema.sql
VeerMuchandi Nov 11, 2016
ad078f6
chagned app properties
VeerMuchandi Nov 11, 2016
0b89eb6
added data.sql
VeerMuchandi Nov 11, 2016
2c5889e
added data.sql
VeerMuchandi Nov 11, 2016
1e2402f
Update application.properties
VeerMuchandi Nov 15, 2016
cd2d261
Update data.sql
VeerMuchandi Nov 15, 2016
a787304
Update SpringSampleAppApplication.java
VeerMuchandi Nov 15, 2016
4c18277
Update data.sql
VeerMuchandi Nov 15, 2016
d932109
Update SpringSampleAppApplication.java
VeerMuchandi Nov 15, 2016
22b5837
commented application props
VeerMuchandi Nov 16, 2016
6c387ae
removed jdbc plugin to test
VeerMuchandi Nov 16, 2016
d24925a
split non-database and database
VeerMuchandi Nov 16, 2016
db55a0c
added 2tier app
VeerMuchandi Nov 16, 2016
1812423
disable testing
VeerMuchandi Nov 16, 2016
853f378
added application properties
VeerMuchandi Nov 16, 2016
719b8b5
added refresh scope
VeerMuchandi Nov 16, 2016
38210af
added refresh scope
VeerMuchandi Nov 16, 2016
6a8e8dc
added maven dependency
VeerMuchandi Nov 16, 2016
4443cd9
added maven dependency
VeerMuchandi Nov 16, 2016
21912ea
added maven dependency
VeerMuchandi Nov 16, 2016
068c4d6
added maven dependency
VeerMuchandi Nov 16, 2016
9b38407
added maven dependency
VeerMuchandi Nov 16, 2016
681721f
added maven dependency
VeerMuchandi Nov 16, 2016
a163981
enable autoconfiguration
VeerMuchandi Nov 16, 2016
0441b43
added @component
VeerMuchandi Nov 16, 2016
1ab5d56
added actuator dependency
VeerMuchandi Nov 16, 2016
4b4f310
moved app properties
VeerMuchandi Nov 16, 2016
fbb46ac
hsqldb added
VeerMuchandi Nov 16, 2016
854b78f
edited the create scripts
VeerMuchandi Nov 16, 2016
75cf8fa
edited the create scripts
VeerMuchandi Nov 16, 2016
80b6a99
edited the create scripts
VeerMuchandi Nov 16, 2016
62c2869
edited the create scripts
VeerMuchandi Nov 16, 2016
a83db6e
separated scripts by database type
VeerMuchandi Nov 16, 2016
0dbac1f
drop table
VeerMuchandi Nov 17, 2016
6b5ddd6
shutdown
VeerMuchandi Nov 17, 2016
434bd5a
fixed data.sql
VeerMuchandi Nov 17, 2016
a5f4f4f
fixed schema-mysql.sql
VeerMuchandi Nov 17, 2016
87c57f4
added postgresql scripts
VeerMuchandi Nov 17, 2016
8f2bd8d
added postgresql dependency to pom.xm
VeerMuchandi Nov 17, 2016
af5c945
removed logging un and pwd
VeerMuchandi Nov 17, 2016
c5af406
removed 2 versions
VeerMuchandi Nov 17, 2016
b11dc6d
added lastnames matching databases for ease
VeerMuchandi Nov 17, 2016
fdb081c
Adding pipeline
Aug 28, 2017
e38d110
Delete Jenkinsfile
VeerMuchandi Aug 28, 2017
2c56d8c
Adding pipeline
Aug 28, 2017
5be3672
changed the location of application.properties
VeerMuchandi Aug 28, 2017
87a98fd
edited the location where hsqldb gets created /opt/app-root/src is no…
VeerMuchandi Aug 28, 2017
0e92bdc
split out live and ready
VeerMuchandi Feb 16, 2018
2bf6ad6
Merge branch 'master' of https://github.com/VeerMuchandi/spring-sampl…
VeerMuchandi Feb 16, 2018
03f6143
split out live and ready
VeerMuchandi Feb 16, 2018
c6954d7
fixed error with kill
VeerMuchandi Feb 16, 2018
608a340
changed method names
VeerMuchandi Feb 16, 2018
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
86 changes: 86 additions & 0 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
#!/usr/bin/groovy
@Library('github.com/fabric8io/fabric8-pipeline-library@master')

def localItestPattern = ""
try {
localItestPattern = ITEST_PATTERN
} catch (Throwable e) {
localItestPattern = "*IT"
}

def localFailIfNoTests = ""
try {
localFailIfNoTests = ITEST_FAIL_IF_NO_TEST
} catch (Throwable e) {
localFailIfNoTests = "false"
}

def versionPrefix = ""
try {
versionPrefix = VERSION_PREFIX
} catch (Throwable e) {
versionPrefix = "1.0"
}

def canaryVersion = "${versionPrefix}.${env.BUILD_NUMBER}"

def fabric8Console = "${env.FABRIC8_CONSOLE ?: ''}"
def utils = new io.fabric8.Utils()
def label = "buildpod.${env.JOB_NAME}.${env.BUILD_NUMBER}".replace('-', '_').replace('/', '_')
def envStage = utils.environmentNamespace('stage')
def envProd = utils.environmentNamespace('run')
def stashName = ""
def deploy = false
mavenNode {
checkout scm
if (utils.isCI()){

mavenCI{}

} else if (utils.isCD()){
deploy = true
echo 'NOTE: running pipelines for the first time will take longer as build and base docker images are pulled onto the node'
container(name: 'maven') {

stage('Build Release'){
mavenCanaryRelease {
version = canaryVersion
}
}

stage('Integration Testing'){
mavenIntegrationTest {
environment = 'Test'
failIfNoTests = localFailIfNoTests
itestPattern = localItestPattern
}
}

stage('Rollout to Stage'){
kubernetesApply(environment: envStage)
//stash deployments
stashName = label
stash includes: '**/*.yml', name: stashName
}
}
}
}

if (deploy){
node {
stage('Approve'){
approve {
room = null
version = canaryVersion
console = fabric8Console
environment = 'Stage'
}
}

stage('Rollout to Run'){
unstash stashName
kubernetesApply(environment: envProd)
}
}
}

76 changes: 68 additions & 8 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<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">
<?xml version="1.0" encoding="UTF-8" standalone="no"?><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.example</groupId>
Expand All @@ -18,6 +16,19 @@
<relativePath/> <!-- lookup parent from repository -->
</parent>

<!-- https://mvnrepository.com/artifact/org.springframework.cloud/spring-cloud-starter -->
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter</artifactId>
<version>1.1.5.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
Expand All @@ -31,22 +42,47 @@
<version>5.1.6</version>
</dependency>

<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>9.4-1206-jdbc42</version>
</dependency>

<dependency>
<groupId>org.hsqldb</groupId>
<artifactId>hsqldb</artifactId>
<scope>runtime</scope>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>


<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-client</artifactId>
<version>1.2.1.RELEASE</version>
</dependency>


</dependencies>

<build>
Expand All @@ -55,8 +91,32 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>

<plugin>
<groupId>io.fabric8</groupId>
<artifactId>fabric8-maven-plugin</artifactId>
<version>3.5.22</version>
<executions>
<execution>
<goals>
<goal>resource</goal>
<goal>build</goal>
</goals>
</execution>
</executions>

<configuration>
<resources>
<labels>
<all>
<space>veerspace</space>
</all>
</labels>
</resources>
</configuration>
</plugin>
</plugins>
</build>


</project>
</project>
1 change: 0 additions & 1 deletion schema.sql

This file was deleted.

50 changes: 43 additions & 7 deletions src/main/java/com/example/SpringSampleAppApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.stereotype.Component;

import java.io.Console;
import java.net.InetAddress;
Expand All @@ -28,11 +30,15 @@ public static void main(String[] args) {
}
}


@RestController
@RequestMapping("/")
@RefreshScope
@Component
class HomeRestController {

boolean healthy=true;
boolean alive=true;
String hostname="";
public HomeRestController(){
try {
Expand All @@ -48,18 +54,40 @@ public String home(){
return "<h1>"+hostname+"</h1>";
}

@RequestMapping("/healthz")
public ResponseEntity healthz(){
@RequestMapping("/ready")
public ResponseEntity ready(){
if (healthy)
return new ResponseEntity(HttpStatus.ACCEPTED);
else
return new ResponseEntity(HttpStatus.NOT_ACCEPTABLE);
}

@RequestMapping("/cancer")
public String cancer(){

@RequestMapping("/live")
public ResponseEntity live(){
if (alive)
return new ResponseEntity(HttpStatus.ACCEPTED);
else
return new ResponseEntity(HttpStatus.NOT_ACCEPTABLE);
}

@RequestMapping("/infect")
public String infect(){
healthy=false;
return "Killed "+hostname;
return hostname+" is getting Sick ";
}

@RequestMapping("/cure")
public String cure(){
healthy=true;
return hostname+" is getting Better ";
}


@RequestMapping("/kill")
public String suffer(){
alive=false;
return hostname+" is Dying ";
}

@Autowired
Expand All @@ -72,11 +100,19 @@ public String dbtest(){
Connection conn = null;

try {
//String connURL="jdbc:mysql://"+env.getProperty("MYSQL_SERVICE_HOST")+":"+env.getProperty("MYSQL_SERVICE_PORT")+"/"+env.getProperty("MYSQL_DATABASE")+"?useSSL=false";
//System.out.println("URL: "+connURL);
//conn = DriverManager.getConnection(connURL,env.getProperty("MYSQL_USER"),env.getProperty("MYSQL_PASSWORD"));
conn = DriverManager.getConnection(env.getProperty("spring.datasource.url"),env.getProperty("spring.datasource.username"),env.getProperty("spring.datasource.password"));
System.out.println("connection url: "+env.getProperty("spring.datasource.url"));
//System.out.println("Username: "+env.getProperty("spring.datasource.username")+"\nPassword: "+env.getProperty("spring.datasource.password"));
PreparedStatement ps = conn.prepareStatement(sql);
ResultSet rs = ps.executeQuery();
rs.next();
String res="<h1>"+rs.getInt("CUST_ID") + rs.getString("NAME")+rs.getInt("Age")+"</h1>";
String res="<h1>Customers List</h1></br>";
while (rs.next()) {
res=res+"CustomerId: "+rs.getInt("CUST_ID") + " Customer Name: "+ rs.getString("NAME")+" Age: "+rs.getInt("Age")+"</br>";
}
rs.close();
return res;
} catch (SQLException e) {
throw new RuntimeException(e);
Expand Down
10 changes: 7 additions & 3 deletions src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
spring.datasource.url= jdbc:mysql://localhost:3306/dev?useSSL=false
spring.datasource.username=root
spring.datasource.password=
# replace your own values based on the database service you created
# url = jdbc:mysql://<<service-host>>:<<service-port>>/<<dbname>>?useSSL=false
#spring.datasource.url= jdbc:mysql://mysql:3306/sampledb?useSSL=false
spring.datasource.platform=hsqldb
spring.datasource.url= jdbc:hsqldb:file:database/mydb;shutdown=true
spring.datasource.username=user
spring.datasource.password=password
5 changes: 5 additions & 0 deletions src/main/resources/data-hsqldb.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
delete from customer;
insert into customer (name, age) values ('Joe Hsql', 88);
insert into customer (name, age) values ('Jack Hsql', 54);
insert into customer (name, age) values ('Ann Hsql', 32);

5 changes: 5 additions & 0 deletions src/main/resources/data-mysql.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
delete from customer;
insert into customer values (null, "Joe Mysql", 88);
insert into customer values (null, "Jack Mysql", 54);
insert into customer values (null, "Ann Mysql", 32);

5 changes: 5 additions & 0 deletions src/main/resources/data-postgresql.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
delete from customer;
insert into customer (name,age) values ('Joe Psql', 88);
insert into customer (name,age) values ('Jack Psql', 54);
insert into customer (name,age) values ('Ann Psql', 32);

5 changes: 5 additions & 0 deletions src/main/resources/schema-hsqldb.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
DROP TABLE customer IF EXISTS;
CREATE TABLE customer ( CUST_ID int GENERATED BY DEFAULT AS IDENTITY
(START WITH 1, INCREMENT BY 1) NOT NULL,
NAME varchar(100) NOT NULL,
AGE int NOT NULL, PRIMARY KEY (CUST_ID) );
3 changes: 3 additions & 0 deletions src/main/resources/schema-mysql.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
CREATE TABLE IF NOT EXISTS `customer` ( `CUST_ID` int(10) unsigned NOT NULL AUTO_INCREMENT, `NAME` varchar(100) NOT NULL, `AGE` int(10) unsigned NOT NULL, PRIMARY KEY (`CUST_ID`) ) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8;


4 changes: 4 additions & 0 deletions src/main/resources/schema-postgresql.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
CREATE TABLE IF NOT EXISTS customer (
CUST_ID serial primary key,
NAME varchar(100) NOT NULL,
AGE integer NOT NULL);