Más contenido relacionado La actualidad más candente (20) Similar a Springon cloudfoundry (20) Springon cloudfoundry1. JSUG Spring勉強会資料料
Spring on Cloud Foundry SpringユーザのためのCloud
Foundry講座
2012年9月26日
ヴイエムウェア株式会社
Confidential
© 2009 VMware Inc. All rights reserved
2. アジェンダ
n はじめに
n Cloud Foundry概要
n Spring On Cloud Foundry【知っておくべき事】
• 環境変数
• Auto Reconfiguration
• Cloud Namespace
• Spring Profile
n まとめ
2 Confidential
4. VMwareのクラウドへのアプローチ
セキュアな VMware 対応の 独立した
プライベート クラウド パブリック クラウド パブリック クラウド
エンドユーザーコンピューティング
SaaS 他の SaaS
View Thin App Zimbra
End User Computing アプリケーション プロバイダー
SaaS
クラウドアプリケーションプラットフォーム NTTコミュニケー
ション
Spring vFabric Hyperic
CloudFoundry 他のクラウド
Cloud Applications インフラプロバイダ
PaaS
クラウドインフラストラクチャと管理ソリューション
vCloud
vCloud Datacenter
vSphere vCenter vShield
Public/Private/Hybrid Cloud Director
vCloud
Virtualized Infrastructure Express
IaaS
4 Confidential
5. The complexity IT and developers face today
〜~Before〜~ Webアプリケーション展開プロセス(workflow)
* An actual application provisioning/update flow in a large enterprise. Image is blurred for privacy reasons
5 Confidential
4
6. The complexity IT and developers face today
〜~After〜~ Webアプリケーション展開プロセス(workflow)
target <any cloud>
push <my app>
bind <my serivces>
instances <my app> + 100
* An actual application provisioning/update flow in a large enterprise. Image is blurred for privacy reasons
6 Confidential
4
7. 〜~Before〜~ Webアプリケーション展開プロセス
Webアプリケーションをクラウド上に展開するに約3ヶ⽉月程度度の期間が必要
tomcat
サーバ調達 ネットワーク OSインストール&
(1カ⽉月) /ストレージ DBインストール& JVM/Web/Appサーバ アプリケーション
パラメータ設定(4⽇日)
/サーバの構築(1ヶ⽉月) パラメータ設定/ インストール/ 運⽤用監視設定(7⽇日)
チューニング作業(7⽇日) アプリケーションデプロイ
パラメータ設定/
チューニング作業(10⽇日)
インフラ調達&構築(2ヶ⽉月) ミドルウェア構築&アプリケションの配布(1ヶ⽉月)
©2010 VMware, Inc. All right reserved.
-7-
8. 〜~After〜~ Webアプリケーション展開プロセス
Webアプリケーションをクラウド上に展開するに要する時間は、わずか5分以内
で完了了
アプリケション
コード
vmc target <any cloud>
push <m app>
bind <my services>
instances <my app> +
100
開発者
vmcコマンド Cloud Foundry
Cloud Foundry展開⽤用コマンド
アプリケションコード展開時間
約数分(5分以内)
©2010 VMware, Inc. All right reserved.
-8-
10. Cloud Foundry概要
10
Copyright © 2011 VMware, Inc. All rights reserved. This product is protected by U.S. and international copyright and intellectual property laws. VMware products are covered by one or more patents listed at http://www.vmware.com/go/patents .
11. Open PaaS Cloud Foundry
VMwareのイニシアティブよる業界初のオープンPaaSプロジェクト
Beta
開発者向けのPaaSサービス提供(www.cloudfoundry.com)
オープンソースコミュニティを設⽴立立、PaaS基盤をオープンソースと
して提供(www.cloudfoundry.org)
ロックインされたクラウド オープンなクラウド
q 独⾃自⾔言語 q 豊富な選択肢
q 独⾃自技術 q 標準的な技術
q ブラックボックス q オープンソース
プライベート
Other
11
Copyright © 2011 VMware, Inc. All rights reserved. This product is protected by U.S. and international copyright and intellectual property laws. VMware products are covered by one or more patents listed at http://www.vmware.com/go/patents .
12. PaaSクラウドのあるべき姿 Open PaaS Cloud Foundry
アプリケーションの⽤用途に応じてフレ
Your Application
Logic ームワーク、開発⾔言語を⾃自由に選択
開発者
Java Node.js Ruby VM Groovy/Grails
アプリケーションサービスの豊富 VM システムSLAに応じてプラットフ
な選択 ォーム(IaaS)を選択
Logic Logic Logic Logic
⼤大量量データトランザ コスト重視
クション
GemFIre/ パブリッククラウド
Redis データ関連サービスのバインディング RightScale
RDMS、三層型アプリ
ケーション
MySQL
メッセージ関連サービスのバインディング
ドキュメント指向DB プライベートクラウド
⼤大量量データ、スキー 仮想マシン(OVF)
マレス
Mongo DB セキュリティガ
バナンス重視
VMware vCloud
Director
システム間連携のメ
ッセージ
VMware
RabbitMQ vSphere
13. Cloud Foundry アーキテクチャ・スタック
Cloud Foundry
Clients (VMC,STS,Browser)
CF Kernel (VCAP)
Orchestrator(BOSH)
IaaS(vSphere,AWS,vCloud Director…)
Hardware Server/Network/Memory/Storage
13
Copyright © 2011 VMware, Inc. All rights reserved. This product is protected by U.S. and international copyright and intellectual property laws. VMware products are covered by one or more patents listed at http://www.vmware.com/go/patents .
14. Cloud Foundry Clients (vmcツール、eclipse⽤用プラグイン)
Eclipse⽤用
プラグインi
Cloud Foundry
vmcツールi
©2010 VMware, Inc. All right reserved.
- 14 -
15. vmcツール
n vmc target [URL]!
• 現在設定しているターゲットURLの表⽰示、新しいURLの設定
n vmc login [email]!
• ユーザのログイン処理理
n vmc push!
• Cloud Foundryへのアプリケーションの配布
n vmc instances [appname]!
• アプリケーションのインスタンス数の設定
n vmc start/stop/restart/delete[appname]!
• アプリケーションのstart/stop/restart/delete
©2010 VMware, Inc. All right reserved.
- 15 -
16. Cloud Foundry アーキテクチャ・スタック
Cloud Foundry
Clients (vmc,sts,Browser)
CF Kernel (VCAP)
Orchestrator(BOSH)
IaaS(vSphere,AWS,vCloud Director…)
Hardware Server/Network/Memory/Storage
16
Copyright © 2011 VMware, Inc. All rights reserved. This product is protected by U.S. and international copyright and intellectual property laws. VMware products are covered by one or more patents listed at http://www.vmware.com/go/patents .
17. Cloud Foundry vcap 内部アーキテクチャ
db
Cloud Controller
Nats Health Manager
Router
Dea
Service app app
17
Copyright © 2011 VMware, Inc. All rights reserved. This product is protected by U.S. and international copyright and intellectual property laws. VMware products are covered by one or more patents listed at http://www.vmware.com/go/patents .
18. Cloud Foundry アーキテクチャ・スタック
Cloud Foundry
Clients (vmc,sts,Browser)
CF Kernel (VCAP)
Orchestrator(BOSH)
IaaS(vSphere,AWS,vCloud Director…)
Hardware Server/Network/Memory/Storage
18
Copyright © 2011 VMware, Inc. All rights reserved. This product is protected by U.S. and international copyright and intellectual property laws. VMware products are covered by one or more patents listed at http://www.vmware.com/go/patents .
19. Cloud Foundry 本番稼働における課題
19
Copyright © 2011 VMware, Inc. All rights reserved. This product is protected by U.S. and international copyright and intellectual property laws. VMware products are covered by one or more patents listed at http://www.vmware.com/go/patents .
20. Deploy PaaS with BOSH
Sends droplet
heart beats and
exit messages
Router
Router
Registers and Registers and
unregisters unregisters
CLI Routes REST API Routes droplet
requests
requests
Droplet change
notifications
Droplet
Cloud Controller Orchestrates
Health Manager start/stop Cloud Controller (Start, Stop, Find) Droplet Execution
requests
Agent (DEA)
Periodically scans Persists droplets
for consistency and provisioned Guest applications
Advertise
services consume
Cloud Service
Controller
Provision and
Database
unprovision
Service "A"
Provision Service
and "A"
Provisioning Agent
unprovision
BOSH
IaaS
20
Copyright © 2011 VMware, Inc. All rights reserved. This product is protected by U.S. and international copyright and intellectual property laws. VMware products are covered by one or more patents listed at http://www.vmware.com/go/patents .
21. BOSHによるIaaSの選択
Cloud Foundry BOSH
Cloud Provider Interface(CPI)
https://github.com/piston/
openstack-bosh-cpi
21
Copyright © 2011 VMware, Inc. All rights reserved. This product is protected by U.S. and international copyright and intellectual property laws. VMware products are covered by one or more patents listed at http://www.vmware.com/go/patents .
22. Spring On Cloud Foundry【知っておくべき事項】
22
Copyright © 2011 VMware, Inc. All rights reserved. This product is protected by U.S. and international copyright and intellectual property laws. VMware products are covered by one or more patents listed at http://www.vmware.com/go/patents .
23. Spring On Cloud Foundry【知っておくべき事項】
アプリケーションのポータビリティ性の向上
CloudFoundryサービスとのバイディングに伴う設定の軽減
n 環境変数
Cloud foundryサービスの環境設定情報をアプリケーションでどのように取得できるか?
n Auto-‐‑‒Reconfiguration
DI機能を活かしたAuto-‐‑‒Reconfigurationの仕組み
n <cloud>ネームスペース
Auto-‐‑‒Reconfigurationを使わないバイディングの⽅方法
n Spring Profile
アプリケーションの動作環境によって、設定情報を切切り替える仕組み
23
Copyright © 2011 VMware, Inc. All rights reserved. This product is protected by U.S. and international copyright and intellectual property laws. VMware products are covered by one or more patents listed at http://www.vmware.com/go/patents .
24. 環境変数(サービス・バイディングに必要なパラメータ情報)
@RequestMapping("/env")!!
public void env(HttpServletResponse response) throws IOException { !!
response.setContentType("text/plain"); !!
PrintWriter out = response.getWriter(); !!
out.println("System Environment:");!!
for (Map.Entry<String, String> envvar : System.getenv().entrySet()) {
out.println(envvar.getKey() + ": " + envvar.getValue()); !!
}!
} !!
System().getenv().〜~ JSON形式の環境変数の取得
{
"postgresql-9.0": [{ !!
"name": "env-postgresql", !!
"label": "postgresql-9.0",!
……!
…… ! !!
"username": "u50ce600bba434bacbc99e034bb415644", !!
"password": "pf4dca5bd449d4732841f0c4ae3f299d0"!!
} !!
}] !!
} !!
!
24
Copyright © 2011 VMware, Inc. All rights reserved. This product is protected by U.S. and international copyright and intellectual property laws. VMware products are covered by one or more patents listed at http://www.vmware.com/go/patents .
25. 環境変数(サービス・バイディングに必要なパラメータ情報)
サービスとのバインディグなし
"
VCAP_SERVICES: {}
""
Postgresqlサービスとのバインディグ
{
"postgresql-9.0": [{ ""
"name": "env-postgresql", ""
"label": "postgresql-9.0", ""
"plan": "free", ""
"credentials": { ""
"name": "de24667f9344b4eeaad6b5a2326d52faa", ""
"host": "172.30.48.122", ""
"hostname": "172.30.48.122", ""
"port": 5432, ""
"user": "u50ce600bba434bacbc99e034bb415644", ""
"username": "u50ce600bba434bacbc99e034bb415644", ""
"password": "pf4dca5bd449d4732841f0c4ae3f299d0"""
} ""
}] ""
} " ""
25
Copyright © 2011 VMware, Inc. All rights reserved. This product is protected by U.S. and international copyright and intellectual property laws. VMware products are covered by one or more patents listed at http://www.vmware.com/go/patents .
26. DI機能を活かしたAuto-‐‑‒Reconfigurationの仕組み
Cloud Foundry ! Jar file Cloud Foundry !
MySQL
cloudfoundry-‐‑‒runtime MySQL
書換え
CLOUD MySQL Bean BeanFactoryPostProc web.xml
(__appCloudDataSource)
essor
Spring App
プロパティ書換え cloudfoundry-‐‑‒runtime
CloudFoundry環境
CLOUD MySQL Bean BeanFactoryPostProc
デプロイ
(__appCloudDataSource)
essor
ローカル開発環境
WAR file(Web App)
web.xml
MySQL Bean Spring Framework
(javax.sql.DataSource)
Spring App
Application Context.xml
参照/書換え
Spring Framework
Application Context.xml
Local MySQL
26
Copyright © 2011 VMware, Inc. All rights reserved. This product is protected by U.S. and international copyright and intellectual property laws. VMware products are covered by one or more patents listed at http://www.vmware.com/go/patents .
27. Auto-‐‑‒Reconfiguration機能(リプレス対象Bean)
Application Contextファイル
!
<bean class="org.apache.commons.dbcp.BasicDataSource" id="dataSource"> !!
<property name="driverClassName" value="com.mysql.jdbc.Driver"/>!!
<property name="url" value="jdbc:mysql://localhost:3306/inventory-db"/> !!
<property name="username" value="myuser"/> !!
<property name="password" value="mypass"/> !!
</bean> ! " ""
構築環境によって変更更するプロパティ値
Service Type 置換え対象となるBean type
Mysql,Postgres javax.sql.DataSource
Redis org.springframework.data.redis.connection.RedisConnecti
onFactory
MongoDB org.springframework.data.document.mongodb.MongoDbF
actory
RabbitMQ org.springframework.amqp.rabbit.connection.Connection
Factory
27
Copyright © 2011 VMware, Inc. All rights reserved. This product is protected by U.S. and international copyright and intellectual property laws. VMware products are covered by one or more patents listed at http://www.vmware.com/go/patents .
28. Auto-‐‑‒Reconfiguration機能(制限事項)
n 複数サービスのバインディングは利利⽤用不不可
複数のサービスタイプから⼀一つのサービスだけ使うとき有効になります。例例えば、
アプリケーションが⼀一つのリレーショナルデータベースサービス(MySQLもし
くはPostgres)だけをバイディングできます。
n 複数のマッチングタイプのBeanは利利⽤用不不可
複数のマッチングタイプのbeanから⼀一つのbeanだけ使うとき有効になります。
例例えば、Spring アプリケーション・コンテキストが複数のデータソースbeanを
使う事はできません。
28
Copyright © 2011 VMware, Inc. All rights reserved. This product is protected by U.S. and international copyright and intellectual property laws. VMware products are covered by one or more patents listed at http://www.vmware.com/go/patents .
29. Auto-‐‑‒Reconfiguration機能(Auto-‐‑‒Reconfigurationの無効化)
n Springアプリケーションでない”JavaWeb”のデプロイ
Springアプリケーションでない”JavaWeb”のアプリケーションをcf上にデプロイ
するとき。Auto-‐‑‒reconfiguration機能は有効でなくなり、アプリケーションの変
更更も⾏行行われません。
n <cloud> のエレメントが使われている場合
<cloud>ネームスペースエレメントをベースとしたBeanがアプリケーションに含
まれていた場合、Auto-‐‑‒reconfiguration機能は適⽤用外となります。
29
Copyright © 2011 VMware, Inc. All rights reserved. This product is protected by U.S. and international copyright and intellectual property laws. VMware products are covered by one or more patents listed at http://www.vmware.com/go/patents .
30. <cloud>ネームスペースエレメント
Auto-‐‑‒Reconfiguration機能の制限で使えないとき、<cloud>ネームスペース
エレメントを利利⽤用する。
ローカル環境
CloudFoundry環境
WAR file(Web App)
Spring App Spring App
cloudfoundry-‐‑‒runtime cloudfoundry-‐‑‒runtime
BeanFactoryPostProcessor BeanFactoryPostProcessor
デプロイ
MySQL Bean MongoDBFactoryBean MySQL Bean MongoDBFactoryBean
Spring Framework
Spring Framework
接続可能
MySQL Mongo DB
30
Copyright © 2011 VMware, Inc. All rights reserved. This product is protected by U.S. and international copyright and intellectual property laws. VMware products are covered by one or more patents listed at http://www.vmware.com/go/patents .
31. <cloud>ネームスペースエレメント 使うための事前準備
org.cloudfoundry:cloudfoundry-‐‑‒runtimeをdependencyとして含める必要。pom.xmlの
dependencyに追加。
<dependencies>"
<dependency>"
<groupId>org.cloudfoundry</groupId>"
<artifactId>cloudfoundry-runtime</artifactId>"
<version>0.8.1</version>"
</dependency>"
"
<!-- additional dependency declarations -->"
</dependencies>"
""
pom.xmlにSpring Framework Milestone Repositoryを持たせる必要。
<repositories>"
<repository>"
<id>org.springframework.maven.milestone</id>"
<name>Spring Framework Maven Milestone Repository</name>"
<url>http://maven.springframework.org/milestone</url>"
</repository>"
"
<!-- additional repository declarations -->"
</repositories>""
31
Copyright © 2011 VMware, Inc. All rights reserved. This product is protected by U.S. and international copyright and intellectual property laws. VMware products are covered by one or more patents listed at http://www.vmware.com/go/patents .
32. <cloud>ネームスペースエレメント <cloud:data-‐‑‒source>
n <cloud:data-‐‑‒source>
SpringアプリケーションでJDBC DataSourceの設定をするときに利利⽤用
• id – デフォルトのサービス名
• service-‐‑‒name – 複数のデータベースサービスをアプリケーションに接続させると
きに必要
<cloud:data-‐‑‒source id="dataSource" />
<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
<property name="dataSource" ref="dataSource" />
</bean>
"
n オプションが追加されたDataSourceの設定例例
<cloud:data-source id="mydatasource">"
<cloud:connection properties="charset=utf-8;" />"
<cloud:pool pool-size="5-10" max-wait-time="2000" />"
</cloud:data-source>"
32
Copyright © 2011 VMware, Inc. All rights reserved. This product is protected by U.S. and international copyright and intellectual property laws. VMware products are covered by one or more patents listed at http://www.vmware.com/go/patents .
33. Spring Profile
アプリケーションにポータビリティ性を持たせるために、動作環境によって、
設定情報を切切り替える仕組み
Spring App
Spring Framework
スイッチ
(Spring Profile)
<profile=”default”> <profile=”cloud”>
cloudfoundry-‐‑‒runtime
MySQL Bean BeanFactoryPostProcessor
MongoDB Bean
(javax.sql.DataSource)
MySQL Bean MongoDBFactoryBean
ローカル開発環境
Cloud Foundry環境
MySQL Mongo DB MySQL Mongo DB
33
Copyright © 2011 VMware, Inc. All rights reserved. This product is protected by U.S. and international copyright and intellectual property laws. VMware products are covered by one or more patents listed at http://www.vmware.com/go/patents .
34. Spring Profile
n <beans profile=“cloud”>
Springアプリケーションは、Cloud Foundryにデプロイされると”cloud”のプロファイルを
⾃自動に選択し、その環境情報が適⽤用される。
<bean id="mongoTemplate"
class="org.springframework.data.mongodb.core.MongoTemplate"> !!
<constructor-arg ref="mongoDbFactory" /> !!
</bean> !!
<beans profile="default">!!
<mongo:db-factory id="mongoDbFactory" dbname="pwdtest" host="127.0.0.1"
port="27017" username="test_user" password="efgh" /> !!
</beans>!!
<beans profile="cloud"> ""
<cloud:mongo-db-factory id="mongoDbFactory" /> ""
</beans> ""
"
34
Copyright © 2011 VMware, Inc. All rights reserved. This product is protected by U.S. and international copyright and intellectual property laws. VMware products are covered by one or more patents listed at http://www.vmware.com/go/patents .
35. まとめ
35
Copyright © 2011 VMware, Inc. All rights reserved. This product is protected by U.S. and international copyright and intellectual property laws. VMware products are covered by one or more patents listed at http://www.vmware.com/go/patents .
36. まとめ
n VMwareのイニシアティブよる業界初のオープンPaaSプロジ
ェクトとしてOpen PaaS Cloud foundryが誕⽣生
n Spring On Cloud Foundry【知っておくべき事】
• 環境変数
• Auto Reconfiguration
• Cloud Namespace
• Spring Profile
36
Copyright © 2011 VMware, Inc. All rights reserved. This product is protected by U.S. and international copyright and intellectual property laws. VMware products are covered by one or more patents listed at http://www.vmware.com/go/patents .