Cloud Manual
Cloud Manual
Approved by AICTE
Accredited by NBA&NAAC
LABORATORY MANUAL
BRANCH :
BATCH :
CLOUD COMPUTING [MVJ22CS61]
MISSION:
1. Concepts of computing discipline: To educate students at undergraduate, postgraduate and
doctoral levels in the fundamental and advanced concepts of computing discipline.
2. Quality Research: To provide strong theoretical and practical background across the Computer Science
and Engineering discipline with the emphasis on computing technologies, quality research,
consultancy and training.
3. Continuous Teaching Learning: To promote a teaching learning process that brings
advancements in Computer Science and Engineering discipline leading to new technologies
and products.
4. Social Responsibility and Ethical Values: To inculcate professionalbehavior, innovative
research Capabilities, leadership abilities and strong ethical values in the young minds so as
to work with the commitment for the betterment of the society.
PEO03: Social Responsibility: Graduates will be professionals with ethics, who will provide industry
growth and social transformation as responsible citizens.
2. Problem analysis: Identify, formulate, research literature, and analyse complex engineering problems
reaching substantiated conclusions using first principles of mathematics, natural sciences, and
engineering sciences.
3. Design/development of solutions: Design solutions for complex engineering problems and design
system components or processes that meet the specified needs with appropriate consideration for the
public health and safety, and the cultural, societal, and environmental considerations.
4. Conduct investigations of complex problems: Use research-based knowledge and research methods
including design of experiments, analysis and interpretation of data, and synthesis of the information
to provide valid conclusions.
5. Modern tool usage: Create, select, and apply appropriate techniques, resources, and modern
engineering and IT tools including prediction and modeling to complex engineering activities with an
understanding of the limitations.
6. The engineer and society: Apply reasoning informed by the contextual knowledge to assess societal,
health, safety, legal and cultural issues and the consequent responsibilities relevant to the professional
engineering practice.
7. Environment and sustainability: Understand the impact of the professional engineering solutions in
societal and environmental contexts, and demonstrate the knowledge of, and need for sustainable
development.
8. Ethics: Apply ethical principles and commit to professional ethics and responsibilities and norms of
the engineering practice.
9. Individual and team work: Function effectively as an individual, and as a member or leader in
diverse teams, and in multidisciplinary settings.
10. Communication: Communicate effectively on complex engineering activities with the engineering
community and with society at large, such as, being able to comprehend and write effective reports
and design documentation, make effective presentations, and give and receive clear instructions.
11. Project management and finance: Demonstrate knowledge and understanding of the engineering and
management principles and apply these to one’s own work, as a member and leader in a team, to
manage projects and in multidisciplinary environments.
12. Life-long learning: Recognize the need for, and have the preparation and ability to engage in
independent and life-long learning in the broadest context of technological change.
PSO1: Programming: Ability to understand, analyse and develop computer programs in the areas
related to algorithms, system software, multimedia, web design, DBMS, and networking for efficient
design of computer-based systems of varying complexity.
PSO2: Practical Solution: Ability to practically provide solutions for real world problems with a
broad range of programming language and open-source platforms in various computing domains.
COURSE OBJECTIVES :
1. Understand the core principles and concepts of cloud-native application development
3. Design scalable and resilient cloud-native applications using Spring Boot, RESTful APIs, Hibernate,
Docker, Kubernetes and microservices.
4. Build and deploy a cloud-native application using Spring Boot, Hibernate, REST API, Docker, Kubernetes,
and microservices.
5. Understand the fundamentals of microservices architecture, the relevance of Spring and the cloud, and
apply the best practices and patterns for developing, routing, securing, logging, and deploying microserv
PREREQUISITES:
1. Java.
2. Database.
3. API’s Creation.
4. Docker
5. Kubernetes
COURSEOUTCOMES(CO’s):
CONo CO’s
C60.1 Understand the essential principles and concepts of cloud-native application development,
including microservices, containerization, orchestration, and cloud-based security and scalability
C606.2 Develop a migration strategy for legacy applications to cloud-native architect
C606.3 Implement service discovery, configuration management, and monitoring using Spring Cloud and
Kubernetes
C606.4 Design, Develop, and deploy a scalable, resilient, and secure cloud-native application using Spring
Boot, Hibernate, REST API, Docker, Kubernetes, and microservices, leveraging containerization,
orchestration, and CI/CD pipelines to ensure efficient and reliable operation in
C606.5 Apply best practices and patterns to develop, route, secure, log, and deploy microservices,
enabling them to build scalable, resilient, and cloud-ready application
Software Requriment :
1. Eclipse IDE
2. Spring initilizer
3. Postman
4. Docker Desktop
Operating System :
1. Windows/ Linux.
CONTENTS
Exp 1: Demonstrate Dependency Injection using annotation based using Spring boot 2 hrs
Exp 2: Demonstrate Dependency Injection using constructor based using Spring boot 2 hrs
Exp 3: Create a Spring Boot Application using Maven Plugin - Write a sample REST 2 hrs
Controller API using Spring Annotations
- Using Postman invoke the REST Controller to demonstrate end to end working.
Exp 4: Write a sample REST App to demonstrate the below Concepts with a use-case of 2 hrs
your choice.
- GET, PUT, POST, DELETE.
Exp 5: Write a sample REST App to Validate the REST API POST & PUT request. - 2 hrs
Design a custom response with appropriate validation errors to the caller
Exp 6: Write a Java application using Hibernate to insert data into Student 2 hrs
DATABASE and retrieve info based on particular queries (For example update,
delete, search etc...)
Exp 7: Demonstrate Spring Data JPA integration in a Spring Boot application using 2 hrs
Hibernate
Exp 8: Demonstrate using Spring Boot: Complete the docker setup on your Sandbox. 2 hrs
Download a docker image from Docker Hub and deploy the same on your
docker server
Build a sample custom image for any of the App of your choice and run the
app image as a container.
Exp 9: Using a docker compose file, deploy multiple apps/containers(eg: 2 hrs
MySql,SpringBoot) onto the docker server ( Project based)
Exp10: Demonstrate with Spring Boot: Setup a Kubernetes development Env on your 2 hrs
Sandbox (use Docker Desktop or Minicube) (Project based)
Open Eclipse
Open start.spring.io in web Browser choose options which is selected and click GENERATE CTRL
OUTPUT:
Pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<projectxmlns="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 https://maven.apache.org/xsd/maven-
4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.4.2</version>
<relativePath/><!-- lookup parent from repository -->
</parent>
<groupId>com.example.pgm1</groupId>
<artifactId>demopgm1 </artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>demopgm1 </name>
<description>Demo project for Spring Boot</description>
<url/>
<licenses>
DEPARTEMENT OF CSE, MVJCE Page 16
CLOUD COMPUTING [MVJ22CS61]
<license/>
</licenses>
<developers>
<developer/>
</developers>
<scm>
<connection/>
<developerConnection/>
<tag/>
<url/>
</scm>
<properties>
<java.version>17</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
Demopgm1Application.java:
package com.example.pgm1.demopgm1;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class Demopgm1Application {
GreetingService.java -interface
package com.example.pgm1.demopgm1;
publicinterfaceGreetingService {
String greet();
}
GreetingServiceImpl.java
package com.example.pgm1.demopgm1;
importorg.springframework.stereotype.Service;
@Service
publicclass GreetingServiceImpl implements GreetingService {
@Override
public String greet() {
return"Hello, World!";
}
}
GreetingController.java
package com.example.pgm1.demopgm1.controller;
import org.springframework.beans.factory.annotation.Autowired;
importorg.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import com.example.pgm1.demopgm1.GreetingService;
@RestController
publicclass GreetingController {
@Autowired
public GreetingController(GreetingService greetingService) {
this.greetingService = greetingService;
}
@GetMapping("/greet")
public String greet() {
returngreetingService.greet();
}
}
DEPARTEMENT OF CSE, MVJCE Page 18
CLOUD COMPUTING [MVJ22CS61]
Pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<projectxmlns="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 https://maven.apache.org/xsd/maven-
4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.4.2</version>
<relativePath/><!-- lookup parent from repository -->
</parent>
<groupId>com.exampleconstructor1</groupId>
<artifactId>democonstructor1</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>democonstructor1</name>
<description>Demo project for Spring Boot constructor</description>
<url/>
<licenses>
<license/>
</licenses>
<developers>
<developer/>
</developers>
<scm>
<connection/>
<developerConnection/>
<tag/>
<url/>
</scm>
<properties>
<java.version>17</java.version>
</properties>
<dependencies>
<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>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
CarController
package com.exampleconstructor1.democonstructor1;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class CarController {
@Autowired
public CarController(CarService carService) {
this.carService = carService;
}
@GetMapping("/start")
public String startCar() {
carService.startCar();
return "Car started!";
}
}
CarService
package com.exampleconstructor1.democonstructor1;
publicinterface CarService {
void startCar();
}
CarServiceImpl
package com.exampleconstructor1.democonstructor1;
import org.springframework.stereotype.Service;
@Service
publicclass CarServiceImpl implements CarService {
@Override
publicvoid startCar() {
// TODO Auto-generated method stub
package com.exampleconstructor1.democonstructor1;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class Democonstructor1Application {
3. Create a Spring Boot Application using Maven Plugin - Write a sample REST Controller API using Spring
Annotations - Using Postman invoke the REST Controller to demonstrate end to end working.
DemoRestApplication.java
package com.examplerest.demo.rest;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class DemoRestApplication {
HelloControlle.java
package com.examplerest.demo.rest.controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
DEPARTEMENT OF CSE, MVJCE Page 23
CLOUD COMPUTING [MVJ22CS61]
@RequestMapping("/api")
public class HelloController {
@GetMapping("/hello")
public String sayHello() {
return "Hello, World!";
}
}
4.Write a sample REST App to demonstrate below Concepts with a use-case of your choice. - GET, PUT,
POST, DELETE .
Pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<projectxmlns="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 https://maven.apache.org/xsd/maven-
4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
DEPARTEMENT OF CSE, MVJCE Page 25
CLOUD COMPUTING [MVJ22CS61]
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.4.2</version>
<relativePath/><!-- lookup parent from repository -->
</parent>
<groupId>com.examplegppd</groupId>
<artifactId>bookstore</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>bookstore</name>
<description>Demo project for Spring Boot rest</description>
<url/>
<licenses>
<license/>
</licenses>
<developers>
<developer/>
</developers>
<scm>
<connection/>
<developerConnection/>
<tag/>
<url/>
</scm>
<properties>
<java.version>17</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
BookstoreApplication
package com.examplegppd.bookstore;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class BookstoreApplication {
Book
package com.examplegppd.bookstore.model;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
@Entity
publicclass Book {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private String title;
private String author;
public Long getId() {
returnid;
}
}
// Getters and Setters
DEPARTEMENT OF CSE, MVJCE Page 27
CLOUD COMPUTING [MVJ22CS61]
BookRepository.java
package com.examplegppd.bookstore.repository;
import org.springframework.data.jpa.repository.JpaRepository;
import com.examplegppd.bookstore.model.Book;
BookController
package com.examplegppd.bookstore.Restcontroller;
import java.util.List;
import java.util.Optional;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.examplegppd.bookstore.model.Book;
import com.examplegppd.bookstore.repository.BookRepository;
@RestController
@RequestMapping("/api/books")
public class BookController {
@Autowired
private BookRepository bookRepository;
@GetMapping
public List<Book> getAllBooks() {
return bookRepository.findAll();
}
@GetMapping("/{id}")
public ResponseEntity<Book> getBookById(@PathVariable Long id) {
Optional<Book> book = bookRepository.findById(id);
return book.map(ResponseEntity::ok).orElseGet(() -> ResponseEntity.notFound().build());
}
@PostMapping
public Book createBook(@RequestBody Book book) {
return bookRepository.save(book);
}
DEPARTEMENT OF CSE, MVJCE Page 28
CLOUD COMPUTING [MVJ22CS61]
@PutMapping("/{id}")
public ResponseEntity<Book> updateBook(@PathVariable Long id, @RequestBody Book bookDetails) {
Optional<Book> book = bookRepository.findById(id);
if (book.isPresent()) {
Book updatedBook = book.get();
updatedBook.setTitle(bookDetails.getTitle());
updatedBook.setAuthor(bookDetails.getAuthor());
bookRepository.save(updatedBook);
return ResponseEntity.ok(updatedBook);
} else {
return ResponseEntity.notFound().build();
}
}
@DeleteMapping("/{id}")
public ResponseEntity<Void> deleteBook(@PathVariable Long id) {
Optional<Book> book = bookRepository.findById(id);
if (book.isPresent()) {
bookRepository.delete(book.get());
return ResponseEntity.noContent().build();
} else {
return ResponseEntity.notFound().build();
}
}
}
BROWSER:
POSTMAN APP:POST
GET:
6. Write a sample REST App to Validate the REST API POST & PUT request. -Design a custom
response with appropriate validation errors to the caller
<licenses>
<license/>
</licenses>
<developers>
<developer/>
</developers>
<scm>
<connection/>
<developerConnection/>
<tag/>
<url/>
</scm>
<properties>
<java.version>17</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.mysql</groupId>
<artifactId>mysql-connector-j</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
DEPARTEMENT OF CSE, MVJCE Page 33
CLOUD COMPUTING [MVJ22CS61]
package com.example.pgm5.demopgm5.restapi;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class Demopgm5RestapiApplication {
package com.example.pgm5.demopgm5.restapi.controller;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.BindingResult;
import org.springframework.validation.FieldError;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.example.pgm5.demopgm5.restapi.jparepository.EmployeeRepository;
import com.example.pgm5.demopgm5.restapi.model.Employee;
import jakarta.validation.Valid;
@RestController
@RequestMapping("/api/employees")
public class EmployeeController {
@Autowired
private EmployeeRepository employeeRepository;
@PostMapping
public ResponseEntity<?> createEmployee(@Valid @RequestBody Employee employee, BindingResult
result) {
if (result.hasErrors()) {
Map<String, String> errors = new HashMap<>();
for (FieldError error : result.getFieldErrors()) {
DEPARTEMENT OF CSE, MVJCE Page 34
CLOUD COMPUTING [MVJ22CS61]
errors.put(error.getField(), error.getDefaultMessage());
}
return new ResponseEntity<>(errors, HttpStatus.BAD_REQUEST);
}
Employee savedEmployee = employeeRepository.save(employee);
return new ResponseEntity<>(savedEmployee, HttpStatus.CREATED);
}
@PutMapping("/{id}")
public ResponseEntity<?> updateEmployee(@PathVariable Long id, @Valid @RequestBody Employee
employee, BindingResult result) {
if (result.hasErrors()) {
Map<String, String> errors = new HashMap<>();
for (FieldError error : result.getFieldErrors()) {
errors.put(error.getField(), error.getDefaultMessage());
}
return new ResponseEntity<>(errors, HttpStatus.BAD_REQUEST);
}
return employeeRepository.findById(id).map(existingEmployee -> {
existingEmployee.setName(employee.getName());
existingEmployee.setAge(employee.getAge());
existingEmployee.setEmail(employee.getEmail());
Employee updatedEmployee = employeeRepository.save(existingEmployee);
return new ResponseEntity<>(updatedEmployee, HttpStatus.OK);
}).orElseGet(() -> new ResponseEntity<>(HttpStatus.NOT_FOUND));
}
@GetMapping
public List<Employee> getAllEmployees() {
return employeeRepository.findAll();
}
}
package com.example.pgm5.demopgm5.restapi.jparepository;
import org.springframework.data.jpa.repository.JpaRepository;
import com.example.pgm5.demopgm5.restapi.model.Employee;
package com.example.pgm5.demopgm5.restapi.model;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
DEPARTEMENT OF CSE, MVJCE Page 35
CLOUD COMPUTING [MVJ22CS61]
import jakarta.persistence.Table;
import jakarta.validation.constraints.Email;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Size;
@Entity
@Table(name = "employees")
publicclass Employee {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
7. Write a Java application using Hibernate to insert data into Student DATABASE and retrieve info based on particular
queries (For example update, delete, search etc...)
Pom.xml
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>com.mysql</groupId>
<artifactId>mysql-connector-j</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.3.1</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
package com.example.pgm6.demopgm5.studentdb;
import org.hibernate.Session;
import org.hibernate.Transaction;
import com.example.pgm6.demopgm5.studentdb.model.Student;
import com.example.pgm6.demopgm5.studentdb.util.HibernateUtil;
publicclass App {
publicstaticvoid main(String[] args) {
App app = new App();
Student student = new Student();
student.setId(1L);
student.setName("John ");
student.setAge(20);
app.saveStudent(student);
app.updateStudent(student.getId(), "Jane ", 21); // Pass correct arguments
app.getStudent(1L);
app.deleteStudent(1L);
}a
@SuppressWarnings("deprecation")
publicvoid saveStudent(Student student) {
System.out.println("Attempting to save student...");
Session session = HibernateUtil.getSessionFactory().openSession();
Transaction transaction = null;
try {
transaction = session.beginTransaction();
session.save(student);
transaction.commit();
System.out.println("Student saved successfully!");
} catch (Exception e) {
if (transaction != null&&transaction.isActive()) {
transaction.rollback();
}
e.printStackTrace();
} finally {
if (session != null&&session.isOpen()) {
session.close();
}
}
}
@SuppressWarnings("deprecation")
publicvoid updateStudent(Long id, String name, intage) {
session.close();
}
}
}
}
package com.example.pgm6.demopgm5.studentdb;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class Demopgm5StudentdbApplication {
package com.example.pgm6.demopgm5.studentdb.model;
import jakarta.persistence.Entity;
import jakarta.persistence.Id;
import jakarta.persistence.Table;
@Entity
@Table(name = "students")
publicclass Student {
@Id
private Long id;
private String name;
privateintage;
// Getters and Setters
public Long getId() { returnid; }
publicvoid setId(Long id) { this.id = id; }
package com.example.pgm6.demopgm5.studentdb.util;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
publicclass HibernateUtil {
static {
try {
sessionFactory = new Configuration().configure().buildSessionFactory();
} catch (Throwable ex) {
DEPARTEMENT OF CSE, MVJCE Page 43
CLOUD COMPUTING [MVJ22CS61]
thrownew ExceptionInInitializerError(ex);
}
}
publicstaticvoid shutdown() {
getSessionFactory().close();
}
}
Hibernate.cfg.xml
<?xmlversion="1.0"encoding="UTF-8"?>
<!DOCTYPEhibernate-configurationPUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<propertyname="hibernate.connection.driver_class">com.mysql.cj.jdbc.Driver</property>
<propertyname="hibernate.connection.password">1987</property>
<propertyname="hibernate.connection.url">jdbc:mysql://localhost:3306/mydb</property>
<propertyname="hibernate.connection.username">suji</property>
<propertyname="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
</session-factory>
</hibernate-configuration>
Application properties:
# Database connection settings
spring.datasource.url=jdbc:mysql://localhost:3306/studentdb
spring.datasource.username=suji
spring.datasource.password=yourpassword
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
# Hibernate settings
spring.jpa.hibernate.ddl-auto=update
spring.jpa.show-sql=true
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQLDialect
7.Demonstrate Spring Data JPA integration in a Spring Boot application using Hibernate
Pom.xml
<name>demohibernate7</name>
<description>Demo project for Spring Boot</description>
<url/>
<licenses>
<license/>
</licenses>
<developers>
<developer/>
</developers>
<scm>
<connection/>
<developerConnection/>
<tag/>
<url/>
</scm>
<properties>
<java.version>17</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency><groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.29</version></dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
Demohibernate7Application
package com.example.hibernatepgm7.demohibernate7;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
DEPARTEMENT OF CSE, MVJCE Page 46
CLOUD COMPUTING [MVJ22CS61]
@SpringBootApplication
public class Demohibernate7Application {
StudentController
package com.example.hibernatepgm7.demohibernate7;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
importorg.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.example.hibernatepgm7.demohibernate7.entity.Student;
@RestController
@RequestMapping("/students")
publicclass StudentController {
@Autowired
private StudentService studentService;
@PostMapping
public Student createStudent(@RequestBody Student student) {
returnstudentService.saveStudent(student);
}
@GetMapping("/{id}")
public Student getStudent(@PathVariable Long id) {
returnstudentService.getStudent(id);
}
@GetMapping
public List<Student> getAllStudents() {
returnstudentService.getAllStudents();
}
@DeleteMapping("/{id}")
publicvoid deleteStudent(@PathVariable Long id) {
studentService.deleteStudent(id);
}
DEPARTEMENT OF CSE, MVJCE Page 47
CLOUD COMPUTING [MVJ22CS61]
StudentRepository
package com.example.hibernatepgm7.demohibernate7;
import org.springframework.data.jpa.repository.JpaRepository;
import com.example.hibernatepgm7.demohibernate7.entity.Student;
StudentService
package com.example.hibernatepgm7.demohibernate7;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.example.hibernatepgm7.demohibernate7.entity.Student;
@Service
publicclass StudentService {
@Autowired
private StudentRepository studentRepository;
publicList<Student> getAllStudents() {
returnstudentRepository.findAll();
}
application.properties:
spring.datasource.url=jdbc:mysql://localhost:3306/studentdb
spring.datasource.username=suji
spring.datasource.password=Suji1987@#
spring.jpa.hibernate.ddl-auto=update
DEPARTEMENT OF CSE, MVJCE Page 48
CLOUD COMPUTING [MVJ22CS61]
spring.jpa.show-sql=true
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQLDialect
server.port=8080
logging.level.org.springframework=DEBUG
Using Browser:
8. Demonstrate using Spring Boot: Complete the docker setup on your Sandbox.
Download a docker image from Docker Hub and deploy the same on your docker
server
Build a sample custom image for any of the App of your choice and run the app
image as a container
Here's a step-by-step guide to demonstrating the use of Docker with Spring Boot:
If you haven't already, install Docker on your sandbox environment. You can download the Docker installer
from the official Docker website.
Open a terminal and run the following command to pull the official MySQL Docker image from Docker Hub:
This will download the latest MySQL Docker image from Docker Hub.
Run the following command to start a new container from the MySQL image:
This will start a new container named "mysql-server" and map port 3306 on the host machine to port 3306 in
the container.
Create a new Spring Boot application using your preferred method, such as using Spring Initializr or manually
creating the project structure.
Create a new file named "Dockerfile" in the root directory of your Spring Boot project. Add the following
contents to the file:
FROM openjdk:8-jdk-alpine
ARG JAR_FILE=target/*.jar
COPY ${JAR_FILE} app.jar
ENTRYPOINT ["java","-jar","/app.jar"]
This Dockerfile uses the official OpenJDK 8 image as a base, copies the Spring Boot application JAR file into
the container, and sets the entrypoint to run the JAR file using Java.
This will create a new Docker image with the name "my-spring-boot-app".
Run the following command to start a new container from the "my-spring-boot-app" image:
This will start a new container named "my-spring-boot-app" and map port 8080 on the host machine to port
8080 in the container.
Open a web browser and navigate to http://localhost:8080 to verify that the Spring Boot application is running
correctly.
That's it! You have now demonstrated the use of Docker with Spring Boot by building a custom Docker image
and running it as a container
1 Using a docker compose file, deploy multiple apps/containers (eg: MySql, Spring Boot)
onto the docker server ( Project based)
2 Demonstrate with Spring Boot: Setup a Kubernetes development Env on your Sandbox
(use Docker Desktop or Mini cube) ( Project based)
2. Can you explain the differences between IaaS, PaaS, and SaaS?
Answer: IaaS provides virtualized computing resources, PaaS provides a platform for developing and
deploying applications, and SaaS provides software applications over the internet.
2. Can you explain the differences between Public Cloud, Private Cloud, Hybrid Cloud, and Community
Cloud?
Answer: Public Cloud is a multi-tenant environment, Private Cloud is a single-tenant environment, Hybrid
Cloud is a combination of Public and Private Cloud, and Community Cloud is a shared environment for
specific industries or organizations.
Cloud Security
2. How can organizations ensure the security of their data in the Cloud?
Answer: Organizations can ensure the security of their data in the Cloud by using encryption, access controls,
and monitoring and auditing mechanisms.
Cloud Providers
2. Can you compare and contrast the services offered by AWS, Azure, and GCP?
Answer: AWS, Azure, and GCP offer a range of services, including computing, storage, and database services.
Each provider has its own strengths and weaknesses, and the choice of provider will depend on the specific
needs of the organization.
Case Studies
1. Can you describe a real-world example of a company that has successfully implemented Cloud Computing?
Answer: For example, Netflix has successfully implemented Cloud Computing using AWS, which has
enabled the company to scale its services and improve its customer experience.
2. What are some of the benefits and challenges that organizations may face when implementing Cloud
Computing?
Answer: Benefits may include increased scalability, flexibility, and cost savings, while challenges may
include security concerns, vendor lock-in, and the need for new skills and training.
Cloud Deployment
1. How would you deploy a Spring Boot application to a cloud platform such as AWS or Azure?
Answer: You can deploy a Spring Boot application to a cloud platform using a range of tools and services,
including AWS Elastic Beanstalk, Azure App Service, and Cloud Foundry.
2. What are some of the benefits and challenges of deploying a Spring Boot application to a cloud platform?
Answer: Benefits may include scalability, flexibility, and cost savings, while challenges may include security
concerns, vendor lock-in, and the need for new skills and training.
1. What is a cloud-native application and how does Spring Boot support this concept?
Answer: A cloud-native application is an application that is designed to take advantage of cloud computing
models, and Spring Boot provides a range of features and tools that support this concept, including support for
microservices, containers, and serverless computing.
Spring Cloud
2. How would you use Spring Cloud to build a cloud-native application using Spring Boot?
Answer: You would use Spring Cloud to build a cloud-native application using Spring Boot by following a
range of steps, including the use of Spring Cloud Config for configuration management, Spring Cloud Netflix
for service discovery and circuit breakers, and Spring Cloud Stream for event-driven architectures.
Case Studies
1. Can you describe a real-world example of a company that has successfully used Spring Boot to build a
cloud-native application?
Answer: For example, Netflix has successfully used Spring Boot to build a range of cloud-native applications,
including its content delivery network and its recommendation engine.
2. What are some of the benefits and challenges that organizations may face when using Spring Boot to build
cloud-native applications?
Answer: Benefits may include increased scalability, flexibility, and cost savings, while challenges may
include security concerns, vendor lock-in, and the need for new skills and training.
Kubernetes
4. How does Kubernetes provide high availability and scalability for applications?
Answer: Kubernetes provides high availability and scalability through the use of replica sets, deployments,
and horizontal pod autoscaling.
Docker
Introduction to Microservices
1. What are Microservices and how do they differ from Monolithic architecture?
Answer: Microservices are a software development technique that structures an application as a collection of
small, independent services that communicate with each other using APIs. Unlike Monolithic architecture,
Microservices allow for greater scalability, flexibility, and resilience.
Microservices Architecture
Microservices Communication
1. Can you describe a real-world example of a company that has successfully implemented Microservices?
Answer: For example, Netflix has successfully implemented Microservices, using a range of technologies,
including Java, Python, and Node.js, to build a scalable and resilient architecture.
2. What are some of the challenges and lessons learned from implementing Microservices in a real-world
scenario?
Answer: Challenges may include managing complexity, ensuring communication and collaboration between
teams, and handling errors and failures. Lessons learned may include the importance of automation,
monitoring, and logging, as well as the need for a culture of continuous learning and improvement.
SAFETY INSTRUCTIONS
Do’s :
Dont’s :