Spring Cloud in a Nutshell
-
Upload
tsuyoshi-miyake -
Category
Technology
-
view
706 -
download
5
Transcript of Spring Cloud in a Nutshell
![Page 1: Spring Cloud in a Nutshell](https://reader034.fdocuments.us/reader034/viewer/2022042817/55a78e1f1a28aba5318b459f/html5/thumbnails/1.jpg)
1 Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under aCreative Commons Attr ibut ion-NonCommercial l icense: http:/ /creat ivecommons.org/ licenses/by-nc/3.0/Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a
Creative Commons Attr ibut ion-NonCommercial l icense: http:/ /creat ivecommons.org/ licenses/by-nc/3.0/
Spring Cloud in a Nutshell
Tsuyoshi Miyake, Pivotal Software, Inc.@tsuyokb
![Page 2: Spring Cloud in a Nutshell](https://reader034.fdocuments.us/reader034/viewer/2022042817/55a78e1f1a28aba5318b459f/html5/thumbnails/2.jpg)
2 Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under aCreative Commons Attr ibut ion-NonCommercial l icense: http:/ /creat ivecommons.org/ licenses/by-nc/3.0/
Agenda
§ Spring Framework in a word!
§ What is Cloud Foundry?• History• Java/Spring on CF
§ What is Spring Cloud?• Goals• @ServiceScan• Extension
§ Demo
![Page 3: Spring Cloud in a Nutshell](https://reader034.fdocuments.us/reader034/viewer/2022042817/55a78e1f1a28aba5318b459f/html5/thumbnails/3.jpg)
3 Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under aCreative Commons Attr ibut ion-NonCommercial l icense: http:/ /creat ivecommons.org/ licenses/by-nc/3.0/
Spring Framework in a word!
![Page 4: Spring Cloud in a Nutshell](https://reader034.fdocuments.us/reader034/viewer/2022042817/55a78e1f1a28aba5318b459f/html5/thumbnails/4.jpg)
4 Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under aCreative Commons Attr ibut ion-NonCommercial l icense: http:/ /creat ivecommons.org/ licenses/by-nc/3.0/
“Don't call us, we'll call you- Hollywood principle
![Page 5: Spring Cloud in a Nutshell](https://reader034.fdocuments.us/reader034/viewer/2022042817/55a78e1f1a28aba5318b459f/html5/thumbnails/5.jpg)
5 Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under aCreative Commons Attr ibut ion-NonCommercial l icense: http:/ /creat ivecommons.org/ licenses/by-nc/3.0/
Container(App Server)
アプリケーション in アプリケーション・サーバー (コンテナ)
Application
Application Information(Context)
ServiceServiceService
![Page 6: Spring Cloud in a Nutshell](https://reader034.fdocuments.us/reader034/viewer/2022042817/55a78e1f1a28aba5318b459f/html5/thumbnails/6.jpg)
6 Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under aCreative Commons Attr ibut ion-NonCommercial l icense: http:/ /creat ivecommons.org/ licenses/by-nc/3.0/
Yes, we know a lot..
GRAILS
Full-stack, Web
XD
Stream, Taps, Jobs
BOOT
Bootable, Minimal, Ops-Ready
Big, Fast,
FlexibleData
Web, Integration,
Batch
WEB
Controllers, REST,WebSocket
INTEGRATION
Channels, Adapters,Filters, Transformers
BATCH
Jobs, Steps,Readers, Writers
BIG DATA
Ingestion, Export,Orchestration, Hadoop
DATA
NON-RELATIONALRELATIONAL
CORE
GROOVYFRAMEWORK SECURITY REACTOR
![Page 7: Spring Cloud in a Nutshell](https://reader034.fdocuments.us/reader034/viewer/2022042817/55a78e1f1a28aba5318b459f/html5/thumbnails/7.jpg)
7 Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under aCreative Commons Attr ibut ion-NonCommercial l icense: http:/ /creat ivecommons.org/ licenses/by-nc/3.0/
What is Cloud Foundry?
![Page 8: Spring Cloud in a Nutshell](https://reader034.fdocuments.us/reader034/viewer/2022042817/55a78e1f1a28aba5318b459f/html5/thumbnails/8.jpg)
8 Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under aCreative Commons Attr ibut ion-NonCommercial l icense: http:/ /creat ivecommons.org/ licenses/by-nc/3.0/
A bit history of Spring & Cloud Foundry
“Cloud Foundry will be the natural cloud deployment choice for Spring developers.Launching Cloud Foundry, The Industry’s First Open PaaS
Rod Johnson, Spring Engineering Blog, Apr 12 2011
![Page 9: Spring Cloud in a Nutshell](https://reader034.fdocuments.us/reader034/viewer/2022042817/55a78e1f1a28aba5318b459f/html5/thumbnails/9.jpg)
9 Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under aCreative Commons Attr ibut ion-NonCommercial l icense: http:/ /creat ivecommons.org/ licenses/by-nc/3.0/
3 meanings of Cloud Foundry for Spring/Java developers
As App Devs As Dev Ops As Dojo Devs
• UAA/Login Server with Spring Security
• Java Buildpack• Service Broker with
Spring Boot/MVC
• Spring + Grails native support
• Gradle, Maven plugin• Eclipse CF plugin• Spring Cloud
(Today’s Topic)
![Page 10: Spring Cloud in a Nutshell](https://reader034.fdocuments.us/reader034/viewer/2022042817/55a78e1f1a28aba5318b459f/html5/thumbnails/10.jpg)
10 Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under aCreative Commons Attr ibut ion-NonCommercial l icense: http:/ /creat ivecommons.org/ licenses/by-nc/3.0/
アプリケーションの Cloud Foundry Runtime へのデプロイ
① アプリケーションとメタデータの push
push app
Router② サービスの作成とバインド
③ アプリケーションのステージング
④ アプリケーションのデプロイ
⑤ アプリケーションのヘルスチェックPivotalCFElasticRuntime
Blobstore DB
Cloud Controller
Service Broker Node(s)
DEADEA
DEADEA
+ app MD
+ =
Servicecredentials
![Page 11: Spring Cloud in a Nutshell](https://reader034.fdocuments.us/reader034/viewer/2022042817/55a78e1f1a28aba5318b459f/html5/thumbnails/11.jpg)
11 Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under aCreative Commons Attr ibut ion-NonCommercial l icense: http:/ /creat ivecommons.org/ licenses/by-nc/3.0/
サービスの作成とバインディング
Router
CloudFoundryRuntime(ERS)
DBServicecredentials
reserve resourcescreate service (HTTP) create service (HTTP)
bind service (HTTP)bind service (HTTP) obtain connection data
CLI Cloud Controller
ServiceBroker
DataService
![Page 12: Spring Cloud in a Nutshell](https://reader034.fdocuments.us/reader034/viewer/2022042817/55a78e1f1a28aba5318b459f/html5/thumbnails/12.jpg)
12 Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under aCreative Commons Attr ibut ion-NonCommercial l icense: http:/ /creat ivecommons.org/ licenses/by-nc/3.0/
アプリケーションのステージングRo
uter
Blobstore DB
DEA Detect Compile UploadNoYesSystem
Buildpacks
+ =
Cloud Controller
PivotalCFElasticRuntime
![Page 13: Spring Cloud in a Nutshell](https://reader034.fdocuments.us/reader034/viewer/2022042817/55a78e1f1a28aba5318b459f/html5/thumbnails/13.jpg)
13 Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under aCreative Commons Attr ibut ion-NonCommercial l icense: http:/ /creat ivecommons.org/ licenses/by-nc/3.0/
What is Spring Cloud?
![Page 14: Spring Cloud in a Nutshell](https://reader034.fdocuments.us/reader034/viewer/2022042817/55a78e1f1a28aba5318b459f/html5/thumbnails/14.jpg)
14 Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under aCreative Commons Attr ibut ion-NonCommercial l icense: http:/ /creat ivecommons.org/ licenses/by-nc/3.0/
“Spring Cloud is DI Containerfor Cloud OS- Anonymous
![Page 15: Spring Cloud in a Nutshell](https://reader034.fdocuments.us/reader034/viewer/2022042817/55a78e1f1a28aba5318b459f/html5/thumbnails/15.jpg)
15 Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under aCreative Commons Attr ibut ion-NonCommercial l icense: http:/ /creat ivecommons.org/ licenses/by-nc/3.0/
Container(Cloud Foundry)
アプリケーション in Cloud Foundry (コンテナ)
Application
Application Information(Context)
ServiceServiceService
![Page 16: Spring Cloud in a Nutshell](https://reader034.fdocuments.us/reader034/viewer/2022042817/55a78e1f1a28aba5318b459f/html5/thumbnails/16.jpg)
16 Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under aCreative Commons Attr ibut ion-NonCommercial l icense: http:/ /creat ivecommons.org/ licenses/by-nc/3.0/
Spring Cloud Goals
§ クラウド内のアプリケーション環境、およびサービスの抽象化
§ 多様なクラウドへの対応
• Cloud Foundry• Heroku• Local
§ 拡張性
• 新クラウド環境への対応• 新サービスへの対応• 新フレームワークへの対応
![Page 17: Spring Cloud in a Nutshell](https://reader034.fdocuments.us/reader034/viewer/2022042817/55a78e1f1a28aba5318b459f/html5/thumbnails/17.jpg)
17 Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under aCreative Commons Attr ibut ion-NonCommercial l icense: http:/ /creat ivecommons.org/ licenses/by-nc/3.0/
Service Scan (@ServiceScan)
§ Java Config (@Configuration) と併用
§ アプリケーションにバインドされたサービスをスキャン
§ 各サービスについて Bean を作成
§ (Option) クラウド環境でのみ有効にするためには@Profile(“cloud”) を追加
@Configuration@ServiceScan// @Profile("cloud”)public class CloudConfig {}
![Page 18: Spring Cloud in a Nutshell](https://reader034.fdocuments.us/reader034/viewer/2022042817/55a78e1f1a28aba5318b459f/html5/thumbnails/18.jpg)
18 Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under aCreative Commons Attr ibut ion-NonCommercial l icense: http:/ /creat ivecommons.org/ licenses/by-nc/3.0/
Service Scan (@ServiceScan) カスタマイズ
§ パターン 1 : 同一タイプのサービス (e.g. DataSource) が 2 つ以上ある
§ パターン 2 : 各サービスの細かな設定が必要
§ パターン 3 : 独自サービスが必要
@Configurationpublic class CloudConfig extends AbstractCloudConfig {
@Beanpublic DataSource mysqlDataSource() {
return connectionFactory().dataSource("mysql-service");}@Beanpublic DataSource postgresDataSource() {
PoolConfig poolConfig = new PoolConfig(20, 200);ConnectionConfig connectionConfig = new
ConnectionConfig("characterEncoding=UTF-8");DataSourceConfig serviceConfig = new DataSourceConfig(poolConfig,
connectionConfig);return connectionFactory().dataSource("postgres-service”, serviceConfig);
}}
![Page 19: Spring Cloud in a Nutshell](https://reader034.fdocuments.us/reader034/viewer/2022042817/55a78e1f1a28aba5318b459f/html5/thumbnails/19.jpg)
19 Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under aCreative Commons Attr ibut ion-NonCommercial l icense: http:/ /creat ivecommons.org/ licenses/by-nc/3.0/
拡張性 (1) –新クラウド環境への対応 (Cloud Platform)
§ CloudConnector interface を実装• isInMatchingCloud(): 意図した Cloud 環境かどうかを判定• getApplicationInstanceInfo(): アプリケーションの情報(ID, ホスト名など)を返す• getServiceInfos(): アプリケーションが利用可能なサービスの接続情報を返す
§ Cloud Platform の登録• META-INF/services/org.springframework.cloud.CloudConnectorに実装クラス• java.util.ServiceLoaderにより load() される
public interface CloudConnector {boolean isInMatchingCloud();ApplicationInstanceInfo getApplicationInstanceInfo();List<ServiceInfo> getServiceInfos();
}
![Page 20: Spring Cloud in a Nutshell](https://reader034.fdocuments.us/reader034/viewer/2022042817/55a78e1f1a28aba5318b459f/html5/thumbnails/20.jpg)
20 Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under aCreative Commons Attr ibut ion-NonCommercial l icense: http:/ /creat ivecommons.org/ licenses/by-nc/3.0/
拡張性 (1) –新クラウド環境への対応 (Cloud Platform)
§ CloudFoundryでの実装例 (CloudFoundryConnector)public class CloudFoundryConnector extends AbstractCloudConnector<Map<String,Object>> {public boolean isInMatchingCloud() {return environment.getEnvValue("VCAP_APPLICATION") != null;
}public ApplicationInstanceInfo getApplicationInstanceInfo() {Map<String, Object> rawApplicationInstanceInfo =objectMapper.readValue(environment.getEnvValue("VCAP_APPLICATION"), Map.class);
…}protected List<Map<String,Object>> getServicesData() {String servicesString = environment.getEnvValue("VCAP_SERVICES");…
}}
![Page 21: Spring Cloud in a Nutshell](https://reader034.fdocuments.us/reader034/viewer/2022042817/55a78e1f1a28aba5318b459f/html5/thumbnails/21.jpg)
21 Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under aCreative Commons Attr ibut ion-NonCommercial l icense: http:/ /creat ivecommons.org/ licenses/by-nc/3.0/
拡張性 (2) –新サービスへの対応
§ ServiceInfoCreator interface を実装• accept(): 引数 Service Data を調べ、該当サービスでハンドル可能か判断• createServiceInfo(): サービス情報(URI など)を返す
§ サービスの登録
• META-INF/services/以下に実装クラスを列挙したファイルを置く• 名称は Cloud Platform 依存
org.springframework.cloud.cloudfoundry.CloudFoundryServiceInfoCreator• CloudFoundryの場合 MysqlServiceInfoCreator, MongoServiceInfoCreator など
public interface ServiceInfoCreator<SI extends ServiceInfo, SD> {public boolean accept(SD serviceData);public SI createServiceInfo(SD serviceData);
}
![Page 22: Spring Cloud in a Nutshell](https://reader034.fdocuments.us/reader034/viewer/2022042817/55a78e1f1a28aba5318b459f/html5/thumbnails/22.jpg)
22 Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under aCreative Commons Attr ibut ion-NonCommercial l icense: http:/ /creat ivecommons.org/ licenses/by-nc/3.0/
拡張性 (2) –新サービスへの対応
§ CloudFoundryでの実装例 (MongoServiceInfoCreator)
public class MongoServiceInfoCreator extendsCloudFoundryServiceInfoCreator<MongoServiceInfo> {public boolean accept(Map<String, Object> serviceData) {return tagsMatch(serviceData) || labelStartsWithTag(serviceData) ||
uriMatchesScheme(serviceData);}public MongoServiceInfo createServiceInfo(Map<String,Object>
serviceData) {@SuppressWarnings("unchecked")Map<String,Object> credentials = (Map<String, Object>)
serviceData.get("credentials");String id = (String) serviceData.get("name");String uri = getStringFromCredentials(credentials, "uri", "url");return new MongoServiceInfo(id, uri);
}}
![Page 23: Spring Cloud in a Nutshell](https://reader034.fdocuments.us/reader034/viewer/2022042817/55a78e1f1a28aba5318b459f/html5/thumbnails/23.jpg)
23 Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under aCreative Commons Attr ibut ion-NonCommercial l icense: http:/ /creat ivecommons.org/ licenses/by-nc/3.0/
拡張性 (3) –新フレームワークへの対応
§ spring-service-connector のみがSpring に依存
§ つまりここを “my-service-connector” にすることで独自のフレームワークに対
応可能
§ 具体的にはServiceConnectorCreator.create() を実装し、ServiceInfo(MysqlServiceInfo) からフレームワークの Object (DataSource) に変換
spring-service-connector
core
cloudfoundry-connector
heroku-connector
localconfig-connector
Spring Cloud
![Page 24: Spring Cloud in a Nutshell](https://reader034.fdocuments.us/reader034/viewer/2022042817/55a78e1f1a28aba5318b459f/html5/thumbnails/24.jpg)
24 Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under aCreative Commons Attr ibut ion-NonCommercial l icense: http:/ /creat ivecommons.org/ licenses/by-nc/3.0/
Demo
Unless otherwise indicated, these slides are© 2013-2014 Pivotal Software, Inc. and licensed under aCreative Commons Attr ibut ion-NonCommercial l icense:http:/ /creat ivecommons.org/ licenses/by-nc/3.0/
hello-spring-cloud
SPRING CLOUD
![Page 25: Spring Cloud in a Nutshell](https://reader034.fdocuments.us/reader034/viewer/2022042817/55a78e1f1a28aba5318b459f/html5/thumbnails/25.jpg)
25 Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under aCreative Commons Attr ibut ion-NonCommercial l icense: http:/ /creat ivecommons.org/ licenses/by-nc/3.0/
Learn More. Stay Connected.
§ Spring Cloud Project: http://projects.spring.io/spring-cloud/
§ Source Code: https://github.com/spring-projects/spring-cloud
§ Sample: https://github.com/cloudfoundry-samples/hello-spring-cloud
§ Recording: https://www.youtube.com/watch?v=F49_LJJPs_s
§ Blogs• https://spring.io/blog/2014/06/03/introducing-spring-cloud• https://spring.io/blog/2014/07/29/using-spring-cloud-programmatically• https://spring.io/blog/2014/08/05/extending-spring-cloud