- About
- Prerequisites
- Framework libraries
- API documentation
- Running the application
- Setting the CI/CD pipeline
- Deployment using CI/CD pipeline
- Test
This is Consent Management RESTful API written in Java and Spring Framework. It gets build using Apache-Maven. This project is intended to be a demonstration the working of the API from a Consent management system. In this project, automated unit testing has been done using junit and data mocking for the automated unit tests using Mockito. The data captured through Rest API are being kept in MySQL. This repository is also currently integrated with CI/CD pipeline using Jenkins server on EC2 instances from AWS.
- Java SDK(1.8)
- Spring framework
- Apache-Tomcat server(8.5)
- MySQL(5.6)
- Hibernate
It is an ORM (Object Relational Mapping) tool. It's been used in Consent Management for interactions with database and for data persistence using Java Persistence API. It helps in keeping the data layer from rest of the layers.
- Spring
It's an MVC framework designed around DispatchSerlet. All The RESTful Apis in Consent Management is being developed using Spring MVC framework. It helps in seperation of concerns.
- Junit
It is a unit testing framework for the Java programming language. It is important in the development of test-driven development. In Consent management all the development is supported by automated unit testing using junit.
- Mockito
It is a popular mock framework which can be used in conjunction with JUnit. Mockito allows you to create and configure mock objects. In Consent management all the objects needed for unit testing is being done through Mockito.
- Springfox
It is an automated JSON API documentation for API's built with Spring. It's been integrated with framework in Consent Management for the documentation of rest apis by providing swagger files for the same.
- Maven
Maven is a build automation tool used primarily for Java projects. All the Consent management tools are being built using Maven.
-
Run the server and browse to http://localhost:8080/ConsentManagement/swagger-ui.html
-
Swagger in json format can be found at http://localhost:8080/ConsentManagement/v2/api-docs
-
Clone the repository git clone https://github.com/amitvinodsharma/ConsentManagement.git
-
Create database with a name "consentmanagement" on MySQL instance. All the tables will get created on runtime by hibernate incase not present in the database.
-
Change the connection string in src/main/webapp/WEB-INF/spring-servlet.xml with your database instance.
-
Build the code using Maven
-
After successfull build and all unit test passed in junit.
-
Run the project on Tomcat server (http://localhost:8080/ConsentManagement).
For Consent management, linux EC2 instances have been used as Jenkins server and Tomcat server.
Get the latest version of jenkins from https://pkg.jenkins.io/redhat-stable/ and install
yum -y install wget sudo wget -O /etc/yum.repos.d/jenkins.repo https://pkg.jenkins.io/redhat-stable/jenkins.repo sudo rpm --import https://pkg.jenkins.io/redhat-stable/jenkins.io.key yum -y install jenkins
yum install java-1.8* #yum -y install java-1.8.0-openjdk
service jenkins start
chkconfig jenkins on
By default jenkins runs at port 8080, You can access jenkins at
http://YOUR-SERVER-PUBLIC-IP:8080
- The default Username is
admin - Grab the default password
- Password Location:
/var/lib/jenkins/secrets/initialAdminPassword SkipPlugin Installation; Done in later steps and mentioned below- Change admin password
Admin>Configure>Password
- Configure
javapathManage Jenkins>Global Tool Configuration>JDK
- Create another admin user id
1. Download maven packages https://maven.apache.org/download.cgi onto Jenkins server. In this case, I am using /opt/maven as my installation directory
- Link : https://maven.apache.org/download.cgi
# Creating maven directory under /opt mkdir /opt/maven cd /opt/maven # downloading maven version 3.6.0 wget http://mirrors.estointernet.in/apache/maven/maven-3/3.6.1/binaries/apache-maven-3.6.1-bin.tar.gz tar -xvzf apache-maven-3.6.1-bin.tar.gz
vi ~/.bash_profile
M2_HOME=/opt/maven/apache-maven-3.6.1
M2=$M2_HOME/bin
PAHT=<Existing_PATH>:$M2_HOME:$M23.1. Install maven plugin without restart
Manage Jenkins>Jenkins Plugins>available>Maven InvokerManage Jenkins>Jenkins Plugins>available>Maven Integration
3.2. Configure maven path
Manage Jenkins>Global Tool Configuration>Maven
- Machine with Java v1.8.x
2.1. Download tomcat packages from https://tomcat.apache.org/download-80.cgi onto /opt on EC2 instance
# Create tomcat directory
cd /opt
wget http://mirrors.fibergrid.in/apache/tomcat/tomcat-8/v8.5.35/bin/apache-tomcat-8.5.35.tar.gz
tar -xvzf /opt/apache-tomcat-8.5.35.tar.gz2.2. give executing permissions to startup.sh and shutdown.sh which are under bin.
chmod +x /opt/apache-tomcat-8.5.35/bin/startup.sh
shutdown.sh2.3. create link files for tomcat startup.sh and shutdown.sh
ln -s /opt/apache-tomcat-8.5.35/bin/startup.sh /usr/local/bin/tomcatup
ln -s /opt/apache-tomcat-8.5.35/bin/shutdown.sh /usr/local/bin/tomcatdown
tomcatup2.4 Update users information in the tomcat-users.xml file goto tomcat home directory and Add below users to conf/tomcat-user.xml file
<role rolename="manager-gui"/>
<role rolename="manager-script"/>
<role rolename="manager-jmx"/>
<role rolename="manager-status"/>
<user username="admin" password="admin" roles="manager-gui, manager-script, manager-jmx, manager-status"/>
<user username="deployer" password="deployer" roles="manager-script"/>
<user username="tomcat" password="s3cret" roles="manager-gui"/>2.5. Restart serivce and try to login to tomcat application from the browser. This time it should be Successful
1.1. Jenkins server running 1.2. Tomcat Server running
2.1 Install 'deploy to container' plugin. This plugin needs to deploy on tomcat server.
- Install 'deploy to container' plugin without restart
Manage Jenkins>Jenkins Plugins>available>deploy to container
2.2 Jenkins should need access to the tomcat server to deploy build artifacts. setup credentials to enable this process. use credentials option on Jenkins home page.
- setup credentials
credentials>jenkins>Global credentials>add credentials- Username :
deployer - Password :
deployer - id :
deployer - Description:
user to deploy on tomcat vm
- Username :
-
Enter an item name:
Deploy_on_Tomcat_Server- Select 'Maven project'
-
Source Code Management:
- Repository:
https://github.com/amitvinodsharma/ConsentManagement.git - Branches to build :
*/master
- Repository:
-
Poll SCM : -
* * * * -
Build:
- Root POM:
pom.xml - Goals and options:
clean install package
- Root POM:
-
Post-build Actions
- Deploy war/ear to container
- WAR/EAR files :
**/*.war - Containers :
Tomcat 8.x- Credentials:
deployer(user created on above) - Tomcat URL :
http://<PUBLIC_IP>:8080
- Credentials:
- WAR/EAR files :
- Deploy war/ear to container
Save and run the job now.
For testing all of the CRUD actions, I recommend using Postman.