DITAS Creating Services for a VDC Use Case
The DITAS Project What is trying to solve? Current applications are eager to acquire and consume more and more amounts of data Data is coming from distributed heterogeneous devices (IoT and mobile applications) Need to deal with data in an effective, fast, agile, and secure manner. What it offers? Optimal combination of edge nodes and cloud services Abstraction from data management Tools to enable developers easily create and deploy data intensive applications
DITAS Toolset DITAS SDK DITAS SDK provides extensions of popular tools such as Node-RED to define applications. The key element of this tool is to allow developers to design applications by specifying Virtual Data Containers (VDC s) and constraints/preferences for Cloud & Edge resources to be exploited. Virtual Data Container VDC VDCs provide an abstraction layer for developers so they can focus only on data, what they want to use and why, forgetting about implementation details. With VDCs applications can easily access required data, in the desired format and with the proper quality level, rather than directly searching for and accessing them among various data infrastructure providers DITAS Execution Environment DITAS EE is based on our powerful execution engine capable of managing a distributed architecture and taking care of data movement and computation, maintaining coordination with other resources involved in the same application.
Example of Cloud deployed Application
VDC Use Case A VDC in order to support all of its functionality, it heavily uses communication between services that may be deployed in different environments. Today we will see how to design and deploy services and establish a protocol for their communication What we will see? What is Spring and Spring Boot (The tool based on which we will build our services) What is REST API (communication between services) Hands-on coding example
Spring Framework Overview What is Spring Framework? Spring is the most popular application development framework for enterprise Java. Open source JAVA platform since 2003 Spring supports all major application servers and JEE standards Spring handles the infrastructure so you can focus on your application Key Features of Spring Framework Dependency Injection (DI) and Inversion Of Control (IoC) Aspect Oriented Programming (AOP) Spring Modules
DI & IoC Dependency Injection (DI) An injection is the passing of a dependency (a service) to a dependent object (client). Passing the service to the client, rather than allowing client to build or find the service, is the fundamental requirement of the pattern Inversion of Control (IoC) In software engineering, Inversion of Control describes a design in witch custom- written portion of a computer program receive the flow of control from a generic, reusable library. By contrast with traditional programming, in which our custom code makes calls to a library, IoC enables a framework to take control of the flow of a program and make calls to our custom code. DI is merely one concrete example of IoC Spring IoC Container The container will create the objects, wire them together, configure them and manage their complete lifecycle from creation till destruction.
Spring Framework Runtime
Spring Framework Ecosystem
Spring Boot Why Spring Boot ? Stand-alone Spring applications No XML Configuration by developers Auto Configuration Uses project management tools such as MAVEN or GRADLE Starter Dependencies Embedded Tomcat or Jetty Fast development and production-ready environment Documentation https://docs.spring.io/spring-boot/docs/current/reference/html/index.html
RESTful APIs What is REST ? Stands for RE presentational S tate T ransfer It is an architectural style which is based on web-standards and the HTTP protocol. In a REST based architecture everything is a Resource. Resources are identified by global IDs ( URIs or URLs ) A Resource is accessed via common interface based on the HTTP standard methods ( GET, POST, PUT, DELETE etc.) You typically have a REST server (producer) which provides access to the resources and a REST client (consumer) which accesses and modifies REST resources. The most common representation for REST resources is JSON. REST is stateless by nature. Excellent for distributed systems .
HTTP Methods for REST HTTP Methods CRUD Operation Description GET SELECT Fetches a resource POST INSERT Adds to an existing resource PUT UPDATE Overrides existing resource DELETE DELETE Deletes a resource Example of REST request • GET http://ditas/blueprints/5cb99cf1763d081d2656624f/?section=INTERNAL_STRUCTURE
What are we building? A RESTful API using Spring and Spring Boot The server will expose resources through REST API for retrieving, adding, updating and deleting users from a mock application The REST server will be deployed (localhost) using the Spring Boot’s embedded Tomcat Finally we will test the API
The Rest API we’ll build GET GET /user/getAll Gets all users GET GET /user/get/{id} Gets the user of the specified id POST POST /user/add Adds new user PUT PUT /user/update/{id} Updates the user of the specified id DELET DELETE /user/delete/{id} Deletes the user of the specified id
Tools we will use Spring Tool Set 4 (STS 4) https://spring.io/tools Java 11 https://www.oracle.com/technetwork/java/javase/downloads/jd k11-downloads-5066655.html Gradle 3.x https://gradle.org/install/ (optional)
Creating a Spring Boot project
The project’s structure
The entity User
The User’s Controller
The User’s Service
Testing the API GET GET /user/get/1 GET GET /user/getAll (1) (3) RESPONSE RESPONSE { [{ "userId": 1, "userId": 1, "username": “ thodfl", "username": “ thodfl", "fullname": “Thodoris Florakis", "fullname": “Thodoris Florakis", "email": “thodoris@email.com " "email": “thodoris@email.com " } }, { PO POST ST /user/add (2) "userId": 2, BODY "username": “ vretml", { "fullname": “Vrettos Moulos", "userId": 3, "email": “vrettos@email.com " "username": “ alexps", }, "fullname": “Alex Psychas", { "email": “alex@email.com " "userId": 3, } "username": “ alexps", RESPONSE "fullname": “Alex Psychas", {} "email": “alex@email.com " }]
What’s next Add persistence (MySQL, MongoDB, etc.) Add ORM (JPA, Hibernate) Create Response Entities Secure the API (Authentication, API Key)
Questions ?
Thank you!
More recommend