Download as pdf or txt
Download as pdf or txt
You are on page 1of 61

MIDTERM REVIEW

© 2018 ICT Intelligence 1


Midterm
 Dalby Hall
 9:30 – 12:00
 Closed book/notes.
 No personal items including electronic devices
(cell phones, computers, calculators, PDAs).
 No additional papers are allowed. Sufficient blank
paper is included in the exam packet.
 Restroom and other personal breaks are not
permitted.
 Bring only pen, pencil (eraser)

© 2018 ICT Intelligence 2


Architecture styles

ESB

Layering Components Service Oriented


Architecture

3
LESSON 1

© 2018 ICT Intelligence 4


Lesson 1 Software Architecture topics
 Software qualities
 Architecture (design) principles
 Communicating architecture
 Context diagram
 Container diagram
 Component diagram , sequence diagram of
components
 Class diagram , sequence diagram of classes
 Identify risk
 Clustering
 Failover
© 2018 ICT Intelligence 5
Agile architecture
Use cases
Refine the
Functional •
architecture in
• User stories
Context diagram: Shows the big Identify
• Scenarios the Sprints
• Processes picture. risks
• Business rules
• Acceptance criteria
• …
Container diagram: Shows the
Qualities • Performance
high-level software
• Scalability
• Reusability architecture using containers Risk storming
• Security and technology choices.
• Availability
• Modifiability
• … Component diagram:
Decompose each container
Constraints • Budget
further into a number of
• Deadlines
• Enterprise arch. distinct components.
• Experience
• …

Detailed diagrams: Class


diagram, sequence diagram,
Principles • Keep it Simple
• Separation of concern deployment diagram.
• Loose coupling
• Information hiding Proof the architecture.
• Modularity
• Flexibility
Do the most risky things first.
• … Design and
visualize the
architecture
Architectural requirements
© 2018 ICT Intelligence 6
Architecture (design) principles
 Keep it simple
 Keep it flexible
 Loose coupling
 Separation of concern
 Information hiding
 Principle of modularity
 High cohesion, low coupling
 Open-closed principle

© 2018 ICT Intelligence 7


Most important qualities
 Performance
 Scalability
 Availability
 Reliability
 Maintainability
 Security
 Interoperability
 Usability

© 2018 ICT Intelligence 8


Clustering

Client 1 Server 1
Load

 Load balancing Client 1


balancer
Server 2

Server 1

 Failover client
Load
balancer
Server 2
What does failover solve?
Server 1 1 Call method 1 Server 1
1 Call method 1
Call method 1 Load Call method 1 Load
client client balancer
balancer
Server 2 Server 2

 Failover works for crashes


2 Server 1
between distributed calls.
Load
client
balancer  But what if the crash happens
Server 2 during the call?

3 Server 1
Call method 2
Load Call method 2
client
balancer
Server 2
Failover reduces the change on errors, but
cannot prevent all errors
10
LESSON 2

© 2018 ICT Intelligence 11


Lesson 2 Application Architecture topics
 Architecture styles
 Layering
 Client-server
 Pipe and filter
 Master-slave
 Microkernel
 Service class
 DOA/repository class
 Proxy/Gateway class
 Relational database versus nosql database
 Scaling databases
 Brewers cap theorem
 Strict consistency – eventual consistency
© 2018 ICT Intelligence 12
Architecture styles

Client

Client Server Presentation


Service

Client-server Business logic


Integration

Layering
Minimal functioning core

Plugin Plugin Plugin

Microkernel

Pipe-and-Filter

master

slave slave slave

Master-Slave

© 2018 ICT Intelligence 13


Application layers
Presentation Service Business logic Integration Data access
layer layer layer layer layer
AccountDAO

DI +save()
+load()
+update()
+delete()
+findByName()

AccountService Account AccountEntry

+deposit() +balance +amount


Client +withdraw() +accountNumber +date
+getAccount() * +description
+deposit()
+getAllAccounts() +accountnumber
+withdraw()
+transferFunds() +type
+getBalance()
+createAccount()

DI JMSSender

+sendJMSMessage()

© 2017 ICT Intelligence 14


Vertical Scaling
 Scale up
 Use a more powerful server
 Single point of failure
 Upgrading results in
downtime
 Limitations
 Cost
 Software does not use all
resources
 Hardware
 Vendor lock-in

© 2017 ICT Intelligence 15


Horizontal scaling
 Scale out
 Divide the data over
multiple servers
 Easy to add more
servers
 Without downtime

© 2017 ICT Intelligence 16


Brewer‘s CAP Theorem
 A distributed system can support only two of
the following characteristics
Consistency All of the nodes see the same
data at the same time.

The system is always


The system is highly
available, no
scalable. We can
downtime
distribute the data to
multiple servers

Availability Partition tolerance


© 2017 ICT Intelligence 17
Where to store state?

Browser Server DB

State in the client: State in the server:


State in the database:
Advantages: Advantages:
Advantages:
 High scalability  -
 High scalability
 Responsive Disadvantages:
 Long time persistence
Disadvantages:  Less responsive
Disadvantages:
 If the client/browser  Less scalable
 Low performance
crashes, you loose the state  No long time persistence
 No long time persistence
Integration techniques
technique advantage disadvantage When to use?
RMI Only Java to Java Never
High coupling
Messaging Buffer You need messaging middleware Between applications within the
Low coupling same organization
Asynchronous When you need asynchronous
requests
SOAP Standards for security, Complex When you need standards
transactions, etc.
Standard for interface
description
REST Simple No standards for security, transactions, etc Everywhere you need
No standard for interface description synchronous requests
Serialized objects over Simpler as RMI Only Java to Java For fast Java to Java integration
HTTP Webcontainer functionality High coupling between applications managed
by the same project
Database integration Simple High coupling Never
File based integration High coupling If you have to communicate large
files
LESSON 3

© 2018 ICT Intelligence 20


Lesson 3 Spring Boot topics
 Dependency injection
 REST
 Mongo

© 2018 ICT Intelligence 21


Dependency injection
<<interface>> <<interface>>
CustomerService EmailService

+addCustomer() +sendEmail()
SpringBootApplication

+main() dependency injection

CustomerServiceImpl EmailServiceImpl

+addCustomer() +sendEmail()

: SpringBootApplication : CustomerServiceImpl : EmailServiceImpl

1 : addCustomer()
2 : sendEmail()

© 2018 ICT Intelligence 22


Dependency Injection
public interface EmailService {
void sendEmail();
}

@Service
public class EmailServiceImpl implements EmailService{
public void sendEmail() {
System.out.println("Sending email");
}
}

public interface CustomerService {


void addCustomer();
}

@Service
public class CustomerServiceImpl implements CustomerService{
@Autowired
private EmailService emailService; Inject the EmailService in the
CustomerService
public void addCustomer() {
emailService.sendEmail();
}
}
© 2018 ICT Intelligence 23
REST
@RestController
public class ContactController {

@RequestMapping("/contact/{firstName}")
public ResponseEntity<?> getContact(@PathVariable String firstName) {
Contact contact = contacts.get(firstName);
if (contact == null) {
return new ResponseEntity<CustomErrorType>(new CustomErrorType("Contact with firstname= "
+ firstName + " is not available"),HttpStatus.NOT_FOUND);
}
return new ResponseEntity<Contact>(contact, HttpStatus.OK);
}

@RequestMapping(value="/contact", method=RequestMethod.POST)
public ResponseEntity<?> addContact(@RequestBody Contact contact) {
contacts.put(contact.getFirstName(), contact);
return new ResponseEntity<Contact>(contact, HttpStatus.OK);
}

© 2018 ICT Intelligence 24


Mapping annotations
@RequestMapping(value = "/add", method = RequestMethod.GET)
Same
@GetMapping("/add")

@RequestMapping(value = "/add", method = RequestMethod.POST)


Same
@PostMapping("/add")

@RequestMapping(value = "/del", method = RequestMethod.DELETE)


Same
@DeleteMapping("/del")

@RequestMapping(value = "/mod", method = RequestMethod.PUT)


Same
@PutMapping("/mod")

© 2018 ICT Intelligence 25


Mongo repository
public interface StudentRepository extends MongoRepository<Student, String> {

public interface StudentRepository extends MongoRepository<Student, String> {


Student findByName(String name);
} Define your own method based
on a standard convention

application.properties
spring.data.mongodb.host=localhost
spring.data.mongodb.port=27017
spring.data.mongodb.database=testdb

© 2018 ICT Intelligence 26


LESSON 4

© 2018 ICT Intelligence 27


Lesson 4 DDD topics
 Entity
 Value object
 Domain service
 Events
 Aggregate root
 RestTemplate

© 2018 ICT Intelligence 28


Example entity classes

Customer
Package
+CustomerId
+trackingNumber
+firstName
+weight
+lastName
+type
+email
+phone

Product
+productNumber
+name
+price

© 2018 ICT Intelligence 29


Example value object classes

Address
Money
-street
-city -amount
-zip -currency

+computeDistance(Address a) +add(Money m)
+equals(Address a) +subtract(Money m)
+equals(Money m)

Weight
Review Dimension
-value
-nrOfStars -unit -length
-description -width
+add(Weigth w) -heigth
+subtract(Weigth w)
+equals(Weigth w) +add(Dimension d)
+subtract(Dimentsion d)
+equals(Dimension d)

© 2018 ICT Intelligence 30


No identity
 Value objects tell something about another
object
<<value object>> <<value object>>
Weight Review
-value
-nrOfStars
-unit review
weigth -description
<<entity>> <<entity>> 1
1 +add(Weigth w)
Person Product
+subtract(Weigth w)
-customerNumber: long +equals(Weigth w) -productNumber: long
length -name: String location
<<value object>>
<<value object>>
Length
1 Location
1
-value -warehouseNumber: long
-unit +placeCode: String
+compare(Length l)

 Technically, value objects may have IDs using


some database persistence strategies.
 But they have no identity in the domain.
© 2018 ICT Intelligence 31
When to use value objects?
1. Representing a descriptive identity-less
concept <<entity>>
<<value object>>
-balance Money
BankAccount
1 +int amount
+id
+Currency currency

2. Enhancing explicitness
What is colorCode?

Shape
What is the allowed range?
+String colorCode

What is the structure of


the String?
© 2018 ICT Intelligence 32
Pushing behavior into value objects

<<entity>>
Customer
+customerNumber <<value object>>
-firstName Contact
-lastName -email
-email -phone
-phone 1 <<value object>>
+validate()
Address
-street
<<entity>> -street
-city Customer -city
-zip -zip
+customerNumber
-state -firstName 1 -state
-country -lastName -country
-userName +validate()
<<value object>> 1
-password +computeDistance(Address a)
Login
+validateEmail() +userName
+validatePhone() +password
+validateAddress() +validate()
+validateLogin() +check()
+checkUserNameAndPassword()
+computeDistance()

© 2018 ICT Intelligence 33


Domain service
 Sometimes behavior does not belong to an
entity or value object
 But it is still an important domain concept
 Use a domain service.

ShippingCostCalculator

+calculateCostToShip(Package package)

© 2018 ICT Intelligence 34


Domain event
 Classes that represent important events in the
problem domain that have already happened
 Immutable

DeliveryFailed
OrderReceived
+sender
+orderNumber
+receiver
+message

© 2018 ICT Intelligence 35


Aggregates
 Large models are split and grouped into
aggregates of entities and value objects that
are treated as a conceptual whole.

© 2018 ICT Intelligence 36


Referencing other aggregates
 Using an Id

<<value object>>
Address
+street
+city 1
+zip
<<aggregate root>> <<aggregate root>> <<value object>> <<value object>>
Customer Account AccountEntry amount Money
+customerId +date 1 +amount
+accountNumber *
+firstName +description +currency
+customerId
<<value object>> 1 +lastName
Contact
+email
+phone

© 2018 ICT Intelligence 37


Referencing other aggregates
 Add a new class

<<value object>>
Location
+building <<aggregate root>> <<value object>>
prerequisites CourseSchedule
+roomNumber 0..* Course
1
+scheduleId +courseNumber
<<aggregate root>> +creationDate *
Course +name
+status
+courseNumber +studentId
+name
* +departmentName
StudentReview
+status
+description

© 2018 ICT Intelligence 38


RestTemplate
@Autowired
private RestOperations restTemplate;

@Bean
RestTemplate restTemplate() {
RestTemplate restTemplate = new RestTemplate();
restTemplate.getMessageConverters().add(new MappingJackson2HttpMessageConverter());
restTemplate.getMessageConverters().add(new StringHttpMessageConverter());
return restTemplate;
}

© 2018 ICT Intelligence 39


LESSON 5

© 2018 ICT Intelligence 40


Lesson 5 DDD/components topics
 Ubiquitous language
 Rich domain model
 Bounded context
 Components
 Interface design
 DTO’s
 Adapter
 Proxy
 Spring Events

© 2018 ICT Intelligence 41


Principles of Domain Driven Design
 Use one common language to describe the
concepts of a domain
 Ubiquitous language
 Create a domain model that shows the important
concepts of the domain
 Rich domain model
 Let the software be a reflection of the real world
domain
 Create small contexts in which a domain model is
valid
 Bounded context

© 2018 ICT Intelligence 42


Bounded context example

© 2018 ICT Intelligence 43


Interface design
 Start with the client first
 Single responsibility principle
 Interface segregation principle
 Easy to use
 Easy to learn

© 2018 ICT Intelligence 44


Data Transfer Objects (DTO)

Products
Product
ProductService
+name
+getProduct(productNumber) +productNumber
+findProduct() +price
+addProduct() +description

ProductDTO
Both the ProductService and
+productNumber
the ShoppingService depend
+name only on the ProductDTO
+price

Shopping
Product
ShoppingService +productNumber
+name
+addProduct(Product) +price

© 2018 ICT Intelligence 45


How does it all fits together?
 Bounded context
 Component
 Service Entities, value objects,
 Module domain services, events

UI/web Service Domain Integration Data access


Controller Service Aggregate DAO/repo
sitory
DTO Aggregate

UI/web Service Domain Integration Data access


Controller Service Aggregate DAO/repo
sitory
DTO Aggregate

© 2018 ICT Intelligence 46


Spring Events
public class AddCustomerEvent { A simple event class
private String message;
Immutable
public AddCustomerEvent(String message) {
this.message = message;
}

public String getMessage() {


return message;
}
}

© 2018 ICT Intelligence 47


Event publisher and listener
@Service
public class CustomerServiceImpl implements CustomerService {
@Autowired
Inject a publisher
private ApplicationEventPublisher publisher;

public void addCustomer() {


publisher.publishEvent(new AddCustomerEvent("New customer is added"));
}
}

@Service
public class Listener { Listen to AddCustomer events

@EventListener
public void onEvent(AddCustomerEvent event) {
System.out.println("received event :" + event.getMessage());;
}
}

© 2018 ICT Intelligence 48


LESSON 6

© 2018 ICT Intelligence 49


Lesson 6 Integration patterns topics
 JMS
 Hub and spoke
 ESB
 Integration patterns

© 2018 ICT Intelligence 50


Sending an object
public class Person { public class Person {
private String firstName; private String firstName;
private String lastName; JSON private String lastName;
... ...
} }

JVM JVM
Messaging
middleware

Object A Object B

Person

© 2018 ICT Intelligence 51


Spring JMS sender
@Component
public class JmsSender {
@Autowired
JmsTemplate jmsTemplate;

public void sendJMSMessage(Person person) {


System.out.println("Sending a JMS message.");
jmsTemplate.convertAndSend("testQueue",person);
}
}
Name of the queue

application.properties
spring.activemq.broker-url=tcp://localhost:61616
spring.activemq.user=admin
spring.activemq.password=admin

© 2018 ICT Intelligence 52


Spring JMS receiver
@Component
public class PersonMessageListener { Name of the queue

@JmsListener(destination = "testQueue")
public void receiveMessage(final Person person) {
System.out.println("JMS receiver received message:" + person.getFirstName()+"
"+person.getLastName());
}
}

© 2018 ICT Intelligence 53


Hub and Spoke
 Integration broker

component component

Integration
component component
broker

component component

© 2017 ICT Intelligence 54


Service Oriented Architecture

DB

Process
orchestration

ESB

Service Service Service Service

DB DB DB DB

© 2018 ICT Intelligence 55


Enterprise Integration Patterns

© 2018 ICT Intelligence 56


LESSON 7

© 2018 ICT Intelligence 57


Lesson 7 Spring Integration topics
 ESB versus Integration Framework
 Integration patterns in spring integration
 Service activator
 Gateway
 Channels
 Point-to-point vs. Publish-subscribe
 Synchronous vs asynchronous
 Custom router
 Filter
 Transformer

© 2018 ICT Intelligence 58


ESB
 Runs outside the application
 Needs to be installed, started, stopped, monitored.

Application

ESB

© 2017 ICT Intelligence 59


Using Spring Integration
Spring application

Spring
beans

 Use SI inside and outside your application


© 2017 ICT Intelligence 60
What you should know
 Draw  Implement
 All integration  POJO classes for
patterns  Controller
 Gateway
 Custom router
 Splitter
 Aggregator
 Filter
 Transformer

© 2018 ICT Intelligence 61

You might also like