Skip to content

Commit

Permalink
Initiate TVShowDB services
Browse files Browse the repository at this point in the history
  • Loading branch information
VanRoy committed Dec 1, 2015
0 parents commit 8c78e3d
Show file tree
Hide file tree
Showing 80 changed files with 9,030 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ui/src/main/resources/static/css/* linguist-vendored
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.gradle
.idea
*.iml
*.ipr
*.iws
build
logs
38 changes: 38 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# TV Shows DB

Application de demonstration d'une architecture microservices avec Spring Cloud Netflix.

Les slides de la présentation sont sur [slideshare](http://fr.slideshare.net/3k1n0/se-lancer-dans-laventure-microservices-avec-spring-cloud-julien-roy).

Cette application met en oeuvre les elements suivants :

- Service Discovery ( Eureka )
- IPC ( Feign )
- Client Side Load Balancer ( Ribbon )
- Circuit Breaker ( Hystrix )
- API Gateway ( Zuul )

## Instructions

### Prérequis

Cette démo necessite un JDK 8 ainsi que Gradle 2.4.

### Lancement de l'application
```
# Compiler et lancer : supervisor, gateway, 1 show, 2 actors, 1 review
gradle build
./startup.sh -a 2
tail -f logs/show.out logs/actor-2.out
```

### Urls

| Service | Url |
| ----------- | -------- |
| Dashboard | http://localhost:8001 |
| Gateway | http://localhost:8002 |
| UI | http://localhost:8080 |
| Show | http://localhost:8011 |
| Actor | http://localhost:8021 |
| Review | http://localhost:8031 |
23 changes: 23 additions & 0 deletions actors/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
version = '0.0.1-SNAPSHOT'

apply plugin: 'spring-boot'
apply plugin: 'io.spring.dependency-management'

dependencies {

compile('org.springframework.boot:spring-boot-starter-actuator')
compile('org.springframework.boot:spring-boot-starter-data-jpa')
compile('org.springframework.boot:spring-boot-starter-data-rest')

compile('org.springframework.cloud:spring-cloud-starter-eureka')

runtime('com.h2database:h2')

testCompile('org.springframework.boot:spring-boot-starter-test')
}

dependencyManagement {
imports {
mavenBom "org.springframework.cloud:spring-cloud-starter-parent:${springCloudVersion}"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.github.vanroy.tvshowsdb;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;

@SpringBootApplication
@EnableDiscoveryClient
public class ActorsApplication {

public static void main(String[] args) {
SpringApplication.run(ActorsApplication.class, args);
}
}
54 changes: 54 additions & 0 deletions actors/src/main/java/com/github/vanroy/tvshowsdb/model/Actor.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package com.github.vanroy.tvshowsdb.model;

import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;

/**
* Actor model entity.
* @author Julien Roy
*/
@Entity
public class Actor {

@Id
private String id;
private String name;
@Column(length = 4096)
private String bio;
private Date birthdate;

public String getId() {
return id;
}

public void setId(String id) {
this.id = id;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public String getBio() {
return bio;
}

public void setBio(String bio) {
this.bio = bio;
}

public Date getBirthdate() {
return birthdate;
}

public void setBirthdate(Date birthdate) {
this.birthdate = birthdate;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.github.vanroy.tvshowsdb.repository;

import com.github.vanroy.tvshowsdb.model.Actor;
import org.springframework.data.repository.CrudRepository;
import org.springframework.data.rest.core.annotation.RepositoryRestResource;

/**
* Actor repository.
* @author Julien Roy
*/
@RepositoryRestResource
public interface ActorRepository extends CrudRepository<Actor, String> {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.github.vanroy.tvshowsdb.service;

import java.util.List;

import com.github.vanroy.tvshowsdb.model.Actor;
import com.github.vanroy.tvshowsdb.repository.ActorRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
* Actor Rest Service.
* @author Julien Roy
*/
//@RestController
public class ActorService {

@Autowired
private ActorRepository actorRepository;

@RequestMapping(method = RequestMethod.GET, value = "/actors")
Iterable<Actor> getActors() {
return actorRepository.findAll();
}

@RequestMapping(method = RequestMethod.GET, value = "/actors/{name}")
Actor get(@PathVariable("name") String name) {
return actorRepository.findOne(name);
}

}
31 changes: 31 additions & 0 deletions actors/src/main/resources/application.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
spring:
application:
name: actors

jpa:
hibernate.ddl-auto: create

info:
name: ${spring.application.name}
version: ${version}

server:
port: 8021

endpoints:
shutdown:
sensitive: false
enabled: true
health:
sensitive: false

eureka:
instance:
leaseRenewalIntervalInSeconds: 5
leaseExpirationDurationInSeconds: 5
metadataMap:
instanceId: ${spring.application.name}:${server.port}
client:
registryFetchIntervalSeconds: 5
serviceUrl:
defaultZone: http://localhost:8001/eureka/
7 changes: 7 additions & 0 deletions actors/src/main/resources/data.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
INSERT INTO actor ( id, name, birthdate, bio) VALUES ('andrew-lincoln', 'Andrew Lincoln', '1973-09-14', 'Andrew Lincoln is a British actor. Lincoln spent his early childhood in Hull, Yorkshire before his family relocated to Bath, Somerset when he was age 10. He was educated at Beechen Cliff School in Bath, and then the prestigious Royal Academy of Dramatic Art in London. His father is a civil engineer and his mother is a nurse');
INSERT INTO actor ( id, name, birthdate, bio) VALUES ('jon-bernthal', 'Jon Bernthal', '1977-09-20', 'Bernthal was born and raised in Washington, D.C. He is the son of Joan Lurie (née Marx) and Eric Lawrence "Rick" Bernthal, a lawyer with Latham & Watkins LLP. His paternal grandfather was musician and producer Murray Bernthal. He has two brothers, Nicholas and Thomas. His parents are both Jewish (his maternal grandfather was from Germany, while Jon''s other ancestors emigrated from Austria, Lithuania, Poland, and Russia). He graduated from the Sidwell Friends School in Washington.');
INSERT INTO actor ( id, name, birthdate, bio) VALUES ('sarah-wayne-callies', 'Sarah Wayne Callies', '1977-06-01', 'Callies was born in La Grange, Illinois, the daughter of Valerie Wayne and David E. Callies (born 1943), now divorced and respective English and law professors at the University of Hawaii, Manoa. At age one, Callies moved to Honolulu, Hawaii with her family. Throughout her youth, she expressed an interest in acting through participating in various school plays at the independent Punahou School. After graduating from high school, she entered Dartmouth College in Hanover, New Hampshire. In conjunction with her studies, Callies remained involved in theatre. She continued her education at Denver''s National Theater Conservatory, where she obtained her Master of Fine Arts degree in 2002.');

INSERT INTO actor ( id, name, birthdate, bio) VALUES ('bryan-cranston', 'Bryan Cranston', '1956-03-07', 'Cranston was born and raised in the Canoga Park neighborhood of Los Angeles, California, the son of Audrey Peggy Sell, a radio actress, and Joseph Louis "Joe" Cranston, an actor and former amateur boxer. He is the second of their three children. He is of Austrian, German, and Irish ancestry on his father''s side, while his maternal grandparents were immigrants from Germany. He has stated that his parents were "broken people" and that they were "incapacitated as far as parenting", causing the family to lose their house in a foreclosure.');

INSERT INTO actor ( id, name, birthdate, bio) VALUES ('sean-beann', 'Sean Beann', '1959-04-17', 'Bean was born in Handsworth, a suburb of Sheffield, which was then part of West Riding of Yorkshire (the County of South Yorkshire was created in 1974). He is the son of Rita (née Tuckwood) and Brian Bean. He has a younger sister named Lorraine. His father owned a fabrication shop which employed 50 people, including Bean''s mother, who worked as a secretary. Despite becoming relatively wealthy (his father owned a Rolls-Royce Silver Shadow), the family never moved away from the council estate as they preferred to remain close to friends and family. As a child, Bean smashed a glass door during an argument, which left a piece of glass embedded in his leg that briefly impeded his walking and left a large scar. This prevented him from pursuing his dream of playing football professionally.');
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.github.vanroy.tvshowsdb;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.SpringApplicationConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = ActorsApplication.class)
public class ActorsApplicationTests {

@Test
public void contextLoads() {
}

}
37 changes: 37 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
subprojects {

ext {
springBootVersion = '1.2.7.RELEASE'
springCloudVersion = 'Angel.SR3'
springCloudDashboardVersion = '1.0.0.RELEASE'
}

buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
classpath('io.spring.gradle:dependency-management-plugin:0.5.2.RELEASE')
}
}

apply plugin: 'java'
apply plugin: 'idea'

sourceCompatibility = 1.8
targetCompatibility = 1.8

repositories {
mavenLocal()
mavenCentral()
}

processResources {
from(sourceSets.main.resources.srcDirs) {
include '**/*.yml'
filter { String line -> line.replace "\${version}", version
}
}
}
}
19 changes: 19 additions & 0 deletions gateway/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
version = '0.0.1-SNAPSHOT'

apply plugin: 'spring-boot'
apply plugin: 'io.spring.dependency-management'

dependencies {
compile('org.springframework.boot:spring-boot-starter-web')

compile('org.springframework.cloud:spring-cloud-starter-eureka')
compile('org.springframework.cloud:spring-cloud-starter-zuul')

testCompile('org.springframework.boot:spring-boot-starter-test')
}

dependencyManagement {
imports {
mavenBom "org.springframework.cloud:spring-cloud-starter-parent:${springCloudVersion}"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.github.vanroy.tvshowsdb;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.netflix.zuul.EnableZuulProxy;

@SpringBootApplication
@EnableDiscoveryClient
@EnableZuulProxy
public class GatewayApplication {

public static void main(String[] args) {
SpringApplication.run(GatewayApplication.class, args);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.github.vanroy.tvshowsdb.filter;

import java.io.IOException;
import javax.servlet.*;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Component;

/**
* Add CORS headers to filters.
* @author Julien Roy
*/
@Component
public class SimpleCORSFilter implements Filter {

public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException {
HttpServletResponse response = (HttpServletResponse) res;
response.setHeader("Access-Control-Allow-Origin", "*");
response.setHeader("Access-Control-Allow-Methods", "POST, GET, PUT, OPTIONS, DELETE");
response.setHeader("Access-Control-Max-Age", "3600");
response.setHeader("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
chain.doFilter(req, res);
}

public void init(FilterConfig filterConfig) {}

public void destroy() {}

}
28 changes: 28 additions & 0 deletions gateway/src/main/resources/application.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
spring:
application:
name: gateway

info:
name: ${spring.application.name}
version: ${version}

server:
port: 8002

endpoints:
shutdown:
sensitive: false
enabled: true
health:
sensitive: false

eureka:
instance:
leaseRenewalIntervalInSeconds: 5
leaseExpirationDurationInSeconds: 5
metadataMap:
instanceId: ${spring.application.name}:${server.port}
client:
registryFetchIntervalSeconds: 5
serviceUrl:
defaultZone: http://localhost:8001/eureka/
Loading

0 comments on commit 8c78e3d

Please sign in to comment.