diff --git a/Jenkinsfile b/Jenkinsfile
new file mode 100644
index 0000000..00aa6bf
--- /dev/null
+++ b/Jenkinsfile
@@ -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)
+ }
+ }
+}
+
diff --git a/pom.xml b/pom.xml
index eff5d1c..df1fc07 100644
--- a/pom.xml
+++ b/pom.xml
@@ -1,6 +1,4 @@
-
-
+
4.0.0
com.example
@@ -18,6 +16,19 @@
+
+
+
+
+ org.springframework.cloud
+ spring-cloud-starter
+ 1.1.5.RELEASE
+ pom
+ import
+
+
+
+
UTF-8
UTF-8
@@ -31,11 +42,28 @@
5.1.6
+
+ org.postgresql
+ postgresql
+ 9.4-1206-jdbc42
+
+
+
+ org.hsqldb
+ hsqldb
+ runtime
+
+
+
+ org.springframework.boot
+ spring-boot-starter-jdbc
+
+
org.springframework.boot
spring-boot-starter-web
-
+
org.springframework.boot
spring-boot-starter-test
@@ -43,10 +71,18 @@
- mysql
- mysql-connector-java
+ org.springframework.boot
+ spring-boot-starter-actuator
+
+
+ org.springframework.cloud
+ spring-cloud-config-client
+ 1.2.1.RELEASE
+
+
+
@@ -55,8 +91,32 @@
org.springframework.boot
spring-boot-maven-plugin
-
+
+
+ io.fabric8
+ fabric8-maven-plugin
+ 3.5.22
+
+
+
+ resource
+ build
+
+
+
+
+
+
+
+
+ veerspace
+
+
+
+
+
+
-
+
\ No newline at end of file
diff --git a/schema.sql b/schema.sql
deleted file mode 100644
index 7a8eb9f..0000000
--- a/schema.sql
+++ /dev/null
@@ -1 +0,0 @@
-CREATE TABLE `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;
diff --git a/src/main/java/com/example/SpringSampleAppApplication.java b/src/main/java/com/example/SpringSampleAppApplication.java
index 7cf9600..93641ca 100644
--- a/src/main/java/com/example/SpringSampleAppApplication.java
+++ b/src/main/java/com/example/SpringSampleAppApplication.java
@@ -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;
@@ -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 {
@@ -48,18 +54,40 @@ public String home(){
return "
"+hostname+"
";
}
- @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
@@ -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=""+rs.getInt("CUST_ID") + rs.getString("NAME")+rs.getInt("Age")+"
";
+ String res="Customers List
";
+ while (rs.next()) {
+ res=res+"CustomerId: "+rs.getInt("CUST_ID") + " Customer Name: "+ rs.getString("NAME")+" Age: "+rs.getInt("Age")+"";
+ }
+ rs.close();
return res;
} catch (SQLException e) {
throw new RuntimeException(e);
diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties
index 4e8c8f5..89fbd36 100644
--- a/src/main/resources/application.properties
+++ b/src/main/resources/application.properties
@@ -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://<>:<>/<>?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
diff --git a/src/main/resources/data-hsqldb.sql b/src/main/resources/data-hsqldb.sql
new file mode 100644
index 0000000..ea6e18a
--- /dev/null
+++ b/src/main/resources/data-hsqldb.sql
@@ -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);
+
diff --git a/src/main/resources/data-mysql.sql b/src/main/resources/data-mysql.sql
new file mode 100644
index 0000000..87c3dc5
--- /dev/null
+++ b/src/main/resources/data-mysql.sql
@@ -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);
+
diff --git a/src/main/resources/data-postgresql.sql b/src/main/resources/data-postgresql.sql
new file mode 100644
index 0000000..931d2dc
--- /dev/null
+++ b/src/main/resources/data-postgresql.sql
@@ -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);
+
diff --git a/src/main/resources/schema-hsqldb.sql b/src/main/resources/schema-hsqldb.sql
new file mode 100644
index 0000000..8409b3f
--- /dev/null
+++ b/src/main/resources/schema-hsqldb.sql
@@ -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) );
diff --git a/src/main/resources/schema-mysql.sql b/src/main/resources/schema-mysql.sql
new file mode 100644
index 0000000..a2db236
--- /dev/null
+++ b/src/main/resources/schema-mysql.sql
@@ -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;
+
+
diff --git a/src/main/resources/schema-postgresql.sql b/src/main/resources/schema-postgresql.sql
new file mode 100644
index 0000000..b75bb8e
--- /dev/null
+++ b/src/main/resources/schema-postgresql.sql
@@ -0,0 +1,4 @@
+CREATE TABLE IF NOT EXISTS customer (
+ CUST_ID serial primary key,
+ NAME varchar(100) NOT NULL,
+ AGE integer NOT NULL);