I have created a sample JAVA Rest Api application using Spring Boot v2.6.6. All the required code are uploaded in this git repository: master branch. Created Server Pojo with values id, name, language and framework. Also created Rest endpoints,
- @PostMapping("/addServer") Add new server
- @GetMapping("/servers") Viewing all servers
- @GetMapping("/servers/{id}") Find server by id
- @GetMapping("/server/{name}") Find server by name
- @DeleteMapping("/delete/{id}") Delete existing server by id For this project, I created spring boot application with web dependency. After creating pojo, a repository is needed to store all the values. For this MongoDB is chosen to store the values of the server. To work with MongoDb, First we need to add its maven dependency,
All the above endpoints are published into cloud using Heroku platform. Below are the url and the sereenshot of each endpoint. View All Servers: https://kaiburr-assessment.herokuapp.com/servers
Find server by id https://kaiburr-assessment.herokuapp.com/servers/625afd2ee1142879597471e2
Find server by name https://kaiburr-assessment.herokuapp.com/server/centos
Add new server https://kaiburr-assessment.herokuapp.com/addServer Body: { "name": "Ubuntu", "language": "Java", "framework": "Hibernate" }
Delete existing server https://kaiburr-assessment.herokuapp.com/delete/625c59da06d65c37b2470070
I have tried to add the swagger for the above application by adding the following maven dependency,
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-ui</artifactId>
<version>1.6.7</version>
</dependency>
I made this swagger exposed in different port instead of port running the application. To make this possible, I added actuator maven dependency and few configuration in application.properties file,
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
springdoc.use-management-port=true management.server.port=8090 management.endpoints.web.exposure.include=openapi, swaggerui Now, api-docs and swaggerui are exposed on the port 8090.
{ "openapi": "3.0.1", "info": { "title": "OpenAPI definition", "version": "v0" }, "servers": [ { "url": "http://localhost:8080", "description": "Generated server url" } ], "paths": { "/addServer": { "post": { "tags": [ "server-controller" ], "operationId": "saveServer", "requestBody": { "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ServerDto" } } }, "required": true }, "responses": { "200": { "description": "OK", "content": { "/": { "schema": { "type": "string" } } } } } } }, "/servers": { "get": { "tags": [ "server-controller" ], "operationId": "getAllServers", "responses": { "200": { "description": "OK", "content": { "/": { "schema": { "type": "array", "items": { "$ref": "#/components/schemas/ServerDto" } } } } } } } }, "/servers/{id}": { "get": { "tags": [ "server-controller" ], "operationId": "getServerById", "parameters": [ { "name": "id", "in": "path", "required": true, "schema": { "type": "string" } } ], "responses": { "200": { "description": "OK", "content": { "/": { "schema": { "$ref": "#/components/schemas/ServerDto" } } } } } } }, "/server/{name}": { "get": { "tags": [ "server-controller" ], "operationId": "getServerByName", "parameters": [ { "name": "name", "in": "path", "required": true, "schema": { "type": "string" } } ], "responses": { "200": { "description": "OK", "content": { "/": { "schema": { "type": "array", "items": { "$ref": "#/components/schemas/ServerDto" } } } } } } } }, "/hello": { "get": { "tags": [ "server-controller" ], "operationId": "name", "responses": { "200": { "description": "OK", "content": { "/": { "schema": { "type": "string" } } } } } } }, "/delete/{id}": { "delete": { "tags": [ "server-controller" ], "operationId": "DeleteServerById", "parameters": [ { "name": "id", "in": "path", "required": true, "schema": { "type": "string" } } ], "responses": { "200": { "description": "OK", "content": { "/": { "schema": { "type": "string" } } } } } } } }, "components": { "schemas": { "ServerDto": { "type": "object", "properties": { "id": { "type": "string" }, "name": { "type": "string" }, "language": { "type": "string" }, "framework": { "type": "string" } } } } } }
In this interactive swaggerui we can test all the endpoints as it provides all the functionalities to document and test APIs
For this task, I used the first application to create a docker image into https://hub.docker.com I added the Jib plugin into my project, Jib is an interesting plugin developed by Google. https://cloud.google.com/java/getting-started/jib This plugin will help to create docker image directly into the docker hub without any Dockerfile
<plugin>
<groupId>com.google.cloud.tools</groupId>
<artifactId>jib-maven-plugin</artifactId>
<version>2.8.0</version>
</plugin>
I was able to create docker image locally and then I pushed the image to the Docker hub
mvn compile jib:dockerBuild
I used the first application to create web UI. The framework I chose to create web UI was Vaadin. Vaadin is a application platform for java. We just need to add its maven dependency which will install all the node modules in the runtime. Two classes are created, MainView.java and ServerEditor. MainView file deals with all the UI parts that are needed for the application. ServerEditor file calls the controller for all the logics in the backend. Altogether, the frontend UI is developed using vaadin as a platform.
To add new Server “New Server” Button is clicked
New server details are filled in the respective boxes
New server is added to the list
Finding server by name
I used Jenkins to build and publish docker image into the registry. I downloaded all the necessary plugins in Jenkins to configure the docker build. The configurations were setup correctly in Jenkins and the code is cloned from this github repository. The application building part was successful while the docker image build was a failure. Due to some unknown exceptions, my docker build failed and was not able to create image. #UPDATE
I was able to build Docker image uploaded in the docker hub via Jenkins
The Machine Learning program is present in the branch “MachineLearning”. I imported brest_cancer dataset for the implementation. Did some preprocessing of data by separating target variable and viewing target classes ['malignant', 'benign'] and then finding the class counts. Used sklearn.model_selection package for splitting train and test data. The data is converted into binarized format then applied logistic regression since its 2 class problem