クラウド上のサービス開発の新しい動向 --- javaee7とplay2.0 ---

101
クラウド上のサービス開発の新しい動向 --- JavaEE7Play2.0 --- @maruyama097 丸山不二夫

Upload: maruyama097

Post on 22-Apr-2015

3.512 views

Category:

Documents


5 download

DESCRIPTION

 

TRANSCRIPT

Page 1: クラウド上のサービス開発の新しい動向 --- JavaEE7とPlay2.0 ---

クラウド上のサービス開発の新しい動向

--- JavaEE7とPlay2.0 ---

@maruyama097

丸山不二夫

Page 2: クラウド上のサービス開発の新しい動向 --- JavaEE7とPlay2.0 ---

Agenda

21世紀の最初の10年に起きたこと

今後の展望とエンタープライズ・クラウドの課題

JavaEE 7

Play 2.0

資料 A) GlassfishのService Deploy

B) GlassfishのAmazon EC2へのdeploy

C) Play 2.0 Template Overview

D) Play 2.0 routesファイル サンプル

Page 3: クラウド上のサービス開発の新しい動向 --- JavaEE7とPlay2.0 ---

21世紀の最初の10年に起きたこと

21世紀の最初の10年が終わった。

この10年の、特に、この数年のITの世界の変化は目覚ましいものがある。

Page 4: クラウド上のサービス開発の新しい動向 --- JavaEE7とPlay2.0 ---

2001/9/11

Page 5: クラウド上のサービス開発の新しい動向 --- JavaEE7とPlay2.0 ---

2011/3/11

Page 6: クラウド上のサービス開発の新しい動向 --- JavaEE7とPlay2.0 ---

21世紀、最初の10年 携帯電話の爆発的普及

15.00 18.60

22.47

27.63

34.21

42.15

50.99

60.36

68.77

78.59

8 10.62

12.32 14.15

15.87 17.67

20.79 23.55

26.81 30.48

0

10

20

30

40

50

60

70

80

90

2001 2002 2003 2004 2005 2006 2007 2008 2009 2010

インターネット

携帯電話

21世紀の最初の10年で、 世界人口の80%が携帯 電話を持ち、30%がイン ターネットを利用するよう になった。

Page 7: クラウド上のサービス開発の新しい動向 --- JavaEE7とPlay2.0 ---

15.00 18.60

22.47

27.63

34.21

42.15

50.99

60.36

68.77

78.59

8 10.62

12.32 14.15

15.87 17.67

20.79 23.55

26.81 30.48

0

10

20

30

40

50

60

70

80

90

2001 2002 2003 2004 2005 2006 2007 2008 2009 2010

21世紀、最初の10年 インターネットの発展とクラウドの登場

インターネット

携帯電話

21世紀初頭、Googleの登場を画期に、 コンシューマ向けのインターネット・ クラウドが成立し、その技術は、 Amazon,MSにより、エンター プライズ向けのクラウド として発展した。

2004年 Google上場

2006年 Amazon EC2/S3

2008年 Microsoft Azure

Page 8: クラウド上のサービス開発の新しい動向 --- JavaEE7とPlay2.0 ---

2005年から2010年までの 世界のトランジスター数の変化

IDF2011 Keynote より 2011/9/13

Page 9: クラウド上のサービス開発の新しい動向 --- JavaEE7とPlay2.0 ---

2007年-2011年 クラウド・デバイスの登場

15.00 18.60

22.47

27.63

34.21

42.15

50.99

60.36

68.77

78.59

0

10

20

30

40

50

60

70

80

90

2001 2002 2003 2004 2005 2006 2007 2008 2009 2010

スマートフォン

携帯電話

21世紀の最初の10年の 後半で、スマートフォンが 登場し、アメリカでは携帯 電話全体の30%を占める ようになった。

2007年 iPhone, 2008年 Android

Page 10: クラウド上のサービス開発の新しい動向 --- JavaEE7とPlay2.0 ---

2007年-2011年 クラウド・デバイスの躍進

21世紀の最初の10年の 後半で、Android、iPhone iPad等のクラウド・デバイス の拡大は急速で、PCを上回 る勢いである。

Page 11: クラウド上のサービス開発の新しい動向 --- JavaEE7とPlay2.0 ---

2011年に起きたこと

昨年2011年に起きたことを振り返る。

2011年は、大きな転換点であったと思う。

Page 12: クラウド上のサービス開発の新しい動向 --- JavaEE7とPlay2.0 ---

新しいネットワーク・メディアのインパクト

2011年1月 チュニジア

2011年2月 エジプト

2011年3月 リビア

2011年4月 シリア

2010/02/10 エジプト 2010/04/22 シリア

中近東・北アフリカでの一連の 変化でも、新しいネットワーク・ メディアは、大きな役割を果た したと言われている。

Page 13: クラウド上のサービス開発の新しい動向 --- JavaEE7とPlay2.0 ---

Apple iCloud WWDC 2011 6/6-6/10

Page 14: クラウド上のサービス開発の新しい動向 --- JavaEE7とPlay2.0 ---

Facebookユーザー8億人を突破 2011年9月22日 f8

1日当たりの利用者数、5億人に達する

Page 15: クラウド上のサービス開発の新しい動向 --- JavaEE7とPlay2.0 ---

Amazon Kindle Fire 2011年11月14日

Page 16: クラウド上のサービス開発の新しい動向 --- JavaEE7とPlay2.0 ---

Google Checkoutの Googleウォレットへの統合 11月18日

Google ウォレットは、客の支払い情報を安全に保存する仮想の財布(ウォレット)で、実店舗でもオンラインでも、すばやく支払いを行うことができる。従来のGoogle Checkout は Google ウォレットに統合された。

2014年までに50% のスマートフォンが NFCを内蔵するよう になるだろう。 コマース担当副社長 Stephanie Tilenius

Page 17: クラウド上のサービス開発の新しい動向 --- JavaEE7とPlay2.0 ---

クラウドとクラウド・デバイス 一年前(2010年)の状況

クラウド クラウド・ デバイス

マーケット

Apple × ○ iTune/ AppStore

Google ○ ○ Android Market

Microsoft ○ ×

Amazon ○ ×

Facebook × ×

Page 18: クラウド上のサービス開発の新しい動向 --- JavaEE7とPlay2.0 ---

クラウド+クラウド・デバイスの 新しいプレーヤの形成 2011年

クラウド クラウド・ デバイス

マーケット

Apple ○ ○ iTune/ AppStore

Google ○ ○ Android Market

Microsoft ○ ○ Marketplace

Amazon ○ ○ Amazon

Facebook △ △ ?

Page 19: クラウド上のサービス開発の新しい動向 --- JavaEE7とPlay2.0 ---

iPhoneで、AT&Tのトラフィック 3年で50倍に

http://bit.ly/1I8Wbd

ブロードバンドの帯域も、個人によって またたく間に、消費される。

Page 20: クラウド上のサービス開発の新しい動向 --- JavaEE7とPlay2.0 ---

この間、日本では ネットワーク障害があいついだ

http://www.nttdocomo.co.jp/binary/pdf/info/notice/page/120127_00.pdf

Page 21: クラウド上のサービス開発の新しい動向 --- JavaEE7とPlay2.0 ---

この間、日本では ネットワーク障害があいついだ

Page 22: クラウド上のサービス開発の新しい動向 --- JavaEE7とPlay2.0 ---

今後の展望と エンタープライズ・クラウドの課題

これから起きるだろうことを考える。

新しいネットワーク・メディアの躍進と新しいネットワーク・マーケットの台頭の二つを軸に変化は進んでゆくだろう。こうした視点から、エンタープライズ・クラウドの課題を考える。

Page 23: クラウド上のサービス開発の新しい動向 --- JavaEE7とPlay2.0 ---

2010年から2015年までの 世界のトランジスター数の予想

IDF2011 Keynote より 2011/9/13

Page 24: クラウド上のサービス開発の新しい動向 --- JavaEE7とPlay2.0 ---

ネットワークへの個人の登場にともなって、 ネットワーク上の情報は、爆発的に増大を続ける。

Page 25: クラウド上のサービス開発の新しい動向 --- JavaEE7とPlay2.0 ---

新しいネットワーク・メディアと 新しいネットワーク・マーケット

巨大なクラウドと膨大な数のクラウド・デバイスによって、新しいスタイルのコミュニケーションと情報の共有、自由時間の享受を可能とするネットワーク・メディアが成立しつつある。こうして、旧メディアの没落が始まる。

いままた、無数の個人のネットワーク利用を背景として、クラウドとクラウド・デバイスの連携の拡大は、新しいネットワーク上のマーケット、新しい経済システムを準備しつつある。

Page 26: クラウド上のサービス開発の新しい動向 --- JavaEE7とPlay2.0 ---

数百万コアが集積した巨大なクラウド

無数のクラウド・デバイス

Page 27: クラウド上のサービス開発の新しい動向 --- JavaEE7とPlay2.0 ---

コマース市場の拡大 新しいネットワーク・マーケットの成立

日常の消費行動を含め、全ての経済行動が、ネットワーク上で行われるようになる。

これを担うシステムは、これまでのエンタープライズ・システムの規模を大きく超えるものになる。システムの規模拡大は必須である。

全ての処理がリアルタイムで行われる必要はないのだが、コンシューマ向けのクラウド・サービスとは異なって、そのトランザクション処理には、いくつかの厳しい要請が課せられることになる。

Page 28: クラウド上のサービス開発の新しい動向 --- JavaEE7とPlay2.0 ---

コマース市場に対応する エンタープライズ・クラウドの課題

巨大なスケールと厳密なトランザクションが、コマース市場をターゲットとしたクラウド・サービスの新しい課題になる。

コンシューマ向けのクラウドに厳密なトランザクションを持ち込むか、エンタープライズ・システムをスケールさせるか?

おそらく可能な対応は後者である。

Page 29: クラウド上のサービス開発の新しい動向 --- JavaEE7とPlay2.0 ---

コマース市場に対応する エンタープライズ・クラウドの課題

基本的には、コマース向けのクラウドへのニーズの高まりは、現在の基幹系システムのクラウド化・スケールアウト化の一層の推進によって応えられることになるだろう。

コマース市場の拡大に伴って、エンタープライズ・クラウドの本当の姿が明らかになる。

Page 30: クラウド上のサービス開発の新しい動向 --- JavaEE7とPlay2.0 ---

クラウド受容の現段階

エンタープライズにおけるクラウドの受容は、意識的には、Hypeを超え、大きく進んだ。

客観的には、かつてのRelational DBやLinuxやJavaの受容と同様に、それは、エンタープライズの周辺部から進行している。

現時点では、エンタープライズ・システムの中核においては、システムやリソースの統合、管理コストの削減という観点からのPrivateクラウドの構築が関心の焦点である。

次の段階を展望する必要がある。

Page 31: クラウド上のサービス開発の新しい動向 --- JavaEE7とPlay2.0 ---

無数のクラウド技術の並存

その一例 jcloudが対応するクラウド・サービス

Amazon Web Services

Elastic Block Store Models

Azure Storage Service

BlueLock vCloud

Cloud Sigma

Eucalyptus

File System

Go Grid

HP Cloud Services

IBM Developer Cloud

OpenStack

Rackspace

RimuHosting

Terremark eCloud

Terremark vCloud Express

Page 32: クラウド上のサービス開発の新しい動向 --- JavaEE7とPlay2.0 ---

もっともっと、沢山のクラウド・ ベンダーが存在する

Page 33: クラウド上のサービス開発の新しい動向 --- JavaEE7とPlay2.0 ---

クラウド技術のオープン化・標準化

クラウド技術が、産業界に広く受け入れられて行くうえで、他のIT技術と同じように、オープンな業界標準を持つことが必要だという声が、説得力を持つ段階に近づいている。

クラウド上のデータとアプリケーション・システムの双方が、標準的なPortabilityのインターフェースを持つようになるのが望ましい。

クラウド・プレーヤたちは、Interoperabilityの標準をサポートする必要がある。

Page 34: クラウド上のサービス開発の新しい動向 --- JavaEE7とPlay2.0 ---

企業の生産性向上とクラウド

企業にとってクラウド利用の主要な目的は、クラウド上で顧客にサービスを提供すること。

いかに速く、いかに簡単に、堅牢なエンタープライズのサービスを開発し、クラウド上に展開できるかは、エンタープライズのクラウド利用にとって中心的な課題。

企業の生産性向上の鍵を、開発プラットフォームのクラウド化が握っている。

ただし、問題もある。日本のユーザー企業は、自社でソフトを開発しているか?

Page 35: クラウド上のサービス開発の新しい動向 --- JavaEE7とPlay2.0 ---

もう一つの別の視点 個人の可能性の拡大とクラウド

この間のIT技術の変化を大きくドライブしてきたのは、クラウド・デバイスの普及でも、SNSの拡大でも、IT技術のコンシューマ化の流れである。

それは、とりもなおさず、無数の個人がIT技術の利用者になったということである。

開発の側でも、開発者個人のPCの所有と自由なネットワーク・アクセスは、客観的には、ソフトウェアの開発環境を大きく変えてきた。オープンソースの広がりは、こうした変化を背景としている。

少なくとも、個人としての開発者にとって、クラウド利用は、さらに大きな変化の突破口になりうる。

Page 36: クラウド上のサービス開発の新しい動向 --- JavaEE7とPlay2.0 ---

一人で、出来ること

Page 37: クラウド上のサービス開発の新しい動向 --- JavaEE7とPlay2.0 ---

一人で、出来ること

Page 38: クラウド上のサービス開発の新しい動向 --- JavaEE7とPlay2.0 ---

これが、僕のクラウドのイメージ

Page 39: クラウド上のサービス開発の新しい動向 --- JavaEE7とPlay2.0 ---

Java EE 7

Page 40: クラウド上のサービス開発の新しい動向 --- JavaEE7とPlay2.0 ---

JavaEEのクラウド化の意味

JavaEE7は、現在エンタープライズの基幹系で広く利用されているJavaEEのPaaSクラウド化を目指したもの。

アプリケーション開発者が、クラウドのインフラをあれこれを意識しなくても、よく知られたJavaEE技術で開発したアプリケーションを、そのままクラウドにdeployし、すぐにクラウドサービスを開始できるという、多くのJava技術者にとっては、魅力的な枠組み。

Page 41: クラウド上のサービス開発の新しい動向 --- JavaEE7とPlay2.0 ---

JavaEEのクラウド化の意味

JavaEEのクラウド化は、エンタープライズJavaの事実上の標準技術が、クラウド化されることを意味する。

JavaEE7の構想が 多数のベンダーの 賛成によって始まっ たことは、クラウド の標準化にとって も、大きな意味を 持っている。

Page 42: クラウド上のサービス開発の新しい動向 --- JavaEE7とPlay2.0 ---

JavaEE7の今後の展開

今年の終わりまでには、JavaEE7の仕様が固まるだろう。(長期戦である)

来年には、WebLogic(Oracle), WebSphere(IBM),Jboss(Redhat)等のアプリケーション・サーバーのJavaEE7対応版が、市場に投入されるだろう。

PaaSエンタープライズ・クラウドの本命の一つと、筆者は考えている。

Page 43: クラウド上のサービス開発の新しい動向 --- JavaEE7とPlay2.0 ---

Play 2.0

Play 2.0は、ある意味で、かつてのSpringと同様に、JavaEEのアンチ・テーゼである。開発の容易さにフォーカスしながら、取り入れている技術は新しく、強力である。

残念ながら、今回は、Playの中核の一つであるAkkaについては、説明を割愛した。

Page 44: クラウド上のサービス開発の新しい動向 --- JavaEE7とPlay2.0 ---

Devoxx2011でPlay2.0を発表する、SadekとGuillaume 2011/11/16

Sadek Drobi

Guillaume Bort

Page 45: クラウド上のサービス開発の新しい動向 --- JavaEE7とPlay2.0 ---

Play 2.0とTypesafe社

Playは、仏Zenexity社のGuillaume Bort

氏を中心に開発された、オープンソースのWebアプリケーションフレームワークである。

2011年11月16日、米Typesafe社は、Guillaume Bort氏を顧問に迎え入れ、PlayをTypesafe stack 2.0と統合することを発表。あわせてPlay2.0 betaをリリースした。

米Typesafe社は、Scalaの創始者Martin Oderskyが会長を務め、James Gosling、Doug Leaが顧問に名を連ねている。

Page 46: クラウド上のサービス開発の新しい動向 --- JavaEE7とPlay2.0 ---

Play 2.0の特徴

Java/Scalaベースの、Type Safeな、Webアプリ開発の為の軽量フレームワーク。

アジャイルな開発手法にフォーカス。

RESTfulアーキテクチャーを志向。

SQL/NonSQL 多様なDataStoreに対応。

Multi-Coreに対応した、Actorベースの非同期並列プログラミング(Akka)。

クラウドを意識したプラットホーム。

Page 47: クラウド上のサービス開発の新しい動向 --- JavaEE7とPlay2.0 ---

アジャイルな開発スタイル

Playでは、compile-package-deployの面倒なサイクルを繰り返す必要はなく、ソースを修正したら、ブラウザのReloadボタンを押すだけでいい。

Playは、Buildシステムを自前で持ち、Javaのソースコードを直接コンパイルし、JVMに、hot-reloadする。

コンパイルエラーは、ブラウザーに表示される

Page 48: クラウド上のサービス開発の新しい動向 --- JavaEE7とPlay2.0 ---
Page 49: クラウド上のサービス開発の新しい動向 --- JavaEE7とPlay2.0 ---
Page 50: クラウド上のサービス開発の新しい動向 --- JavaEE7とPlay2.0 ---

RESTful アーキテクチャー

Webアプリケーションは、HTTPのRequestを受けて、Responseを返すものである。

ServletやStrutsは、HTTPのJavaレベルでのある抽象的な見方を与えているのだが、Webアプリケーションのフレームワークは、HTTPとそのコンセプトへの、完全でより直接のアクセスを可能にすべきである。

Template Engineを使えば、Servletは、必要ではない。

Page 51: クラウド上のサービス開発の新しい動向 --- JavaEE7とPlay2.0 ---

“Share-Nothing” Stateless アーキテクチャー

JavaのWebフレームワークの一部は、状態を持っている。

こうしたアプローチは、ページの状態を自動的に記憶するには役に立つ。同時に、「バックボタン」の処理等で面倒な問題も抱え込む。

Playは、PHP,Ruby on Railsと同様に、状態を持たない“Share-Nothing”アーキテクチャーを採用する。

Page 52: クラウド上のサービス開発の新しい動向 --- JavaEE7とPlay2.0 ---

HTTP Routing conf/routes

# Home page GET / controllers.Application.index # Hello action GET /hello controllers.Application.sayHell

URI

HTTP Method

Action

conf/routesファイルは、HTTP RequestのMethod、 URIに、それによって引き起こされるActionを対応させる。 Actionは、HTTP Responseを返す。

Page 53: クラウド上のサービス開発の新しい動向 --- JavaEE7とPlay2.0 ---

Controller Actionの記述 app/controllers/Application.java

app/controllers/以下のJava/Scalaファイルは、routesファイルで、HTTP Requestに対応づけられたActionを定義する。

package controllers; import play.*; import play.mvc.*; import views.html.*; public class Application extends Controller { public static Result index() { return ok(index.render("Hello World!")); } }

Page 54: クラウド上のサービス開発の新しい動向 --- JavaEE7とPlay2.0 ---

Template HTTP Responseの雛形 app/views/index.scala.html

app/views/ 以下のscala.htmlファイルは、Scala functionにコンパイルされ、Action記述から呼び出される。

@(name: String, repeat: Int, color: String) @main("Here is the result:") { <ul style="color: @if(color != null) { @color } else { "inherited" }"> @for(i <- 1 to repeat) { <li>Hello @name!</li> } </ul> <p class="buttons"> <a href="@routes.Application.index">Back to the form</a> </p> }

Page 55: クラウド上のサービス開発の新しい動向 --- JavaEE7とPlay2.0 ---

GET / controllers.Application.index

public static Result index() { return ok( index.render(“Hello World!”) ); }

@(message: String) <h1>@message</h1>

conf/routes ファイル

app/controllers/Application.java ファイル

app/views/index.scala.html ファイル

Controller

Template

Page 56: クラウド上のサービス開発の新しい動向 --- JavaEE7とPlay2.0 ---

JPAのサポートとMVC

Playは、ORMとして、Java標準のJPAをサポートしている。

Play2.0では、Stateless JPAと呼ばれる、新しい実装である、Ebeanが提供されている。

これらの定義ファイルは、app/models ディレクトリーに置かれている。

こうして、appディレクトリー下には、app/models, app/views, app/controllers の3つのディレクトリーが置かれることになる。

Page 57: クラウド上のサービス開発の新しい動向 --- JavaEE7とPlay2.0 ---

Modelの定義 app/models/Computer.java

@Entity public class Computer extends Model { @Id public Long id; @Constraints.Required public String name; @Formats.DateTime(pattern="yyyy-MM-dd") public Date introduced; @Formats.DateTime(pattern="yyyy-MM-dd") public Date discontinued; @ManyToOne public Company company;

Page 58: クラウド上のサービス開発の新しい動向 --- JavaEE7とPlay2.0 ---

Router

Model

Controller

Views

Play 2.0のMVC

# Home page GET / controllers.Application.index # Hello action GET /hello controllers.Application. sayHello

@Entity public class Company extends Model { @Id public Long id; @Constraints. Required public String name;

@(message: String) <h1>@message</h1>

public class Application extends Controller { public static Result index() { ……

Page 59: クラウド上のサービス開発の新しい動向 --- JavaEE7とPlay2.0 ---

public static Result sayHello() { Form<Hello> form = form(Hello.class).bindFromRequest(); if(form.hasErrors()) { return badRequest(index.render(form)); } else { Hello data = form.get(); return ok( hello.render(data.name, data.repeat, data.color) ); } }

def sayHello = Action { implicit request => helloForm.bindFromRequest.fold( formWithErrors => BadRequest(html.index(formWithErrors)), {case (name, repeat, color) => Ok(html.hello(name, repeat.toInt, color))} ) }

app/controllers/Application.java

app/controllers/Application.scala

JavaとScala

Page 60: クラウド上のサービス開発の新しい動向 --- JavaEE7とPlay2.0 ---

「エンタープライズ・クラウドの現在」

資料

A) GlassfishのService Deploy B) GlassfishのAmazon EC2へのdeploy C) Play 2.0 Template Overview D) Play 2.0 routesファイル サンプル

Page 61: クラウド上のサービス開発の新しい動向 --- JavaEE7とPlay2.0 ---

GlassfishのService Deploy

Devoxx 2011での、JavaEE7のアーキテクトJerome Dochezのスライドから。

Page 62: クラウド上のサービス開発の新しい動向 --- JavaEE7とPlay2.0 ---

Application Introspection

Virtual Cluster Creation

1.Application Introspection

サービスのdeployまでの流れ

まず、アプリケーションの提供する サービスを分析します。 次に、その分析結果に基づいて、 Virtual Clusterの生成に取り掛かり ます。

Page 63: クラウド上のサービス開発の新しい動向 --- JavaEE7とPlay2.0 ---

Application Introspection

Virtual Cluster Creation

Virtual Machines

With JavaEE

2. Virtual Cluster Creation

サービスのdeployまでの流れ

Virtual Nodeを作成し、 すべてのノード上に、 JavaEE7をインストール します。

Page 64: クラウド上のサービス開発の新しい動向 --- JavaEE7とPlay2.0 ---

Application Introspection

Virtual Cluster Creation

Virtual Machines

With JavaEE

2. Virtual Cluster Creation

サービスのdeployまでの流れ

Virtual Nodeを作成し、 Load Balancerを置き ます。 必要に応じてDatabase やMQ等の外部リソー スを置きます。 これで、次の段階の Associationの準備が 出来ました。

Virtual Machines with Load Balancer

Virtual Machines

with Database Service

Association

Page 65: クラウド上のサービス開発の新しい動向 --- JavaEE7とPlay2.0 ---

Application Introspection

Virtual Cluster Creation

Virtual Machines

With JavaEE

3. Association

サービスのdeployまでの流れ

Load Balancer, JavaEEサーバー Databaseを関連 付けます。 これで、アプリケ ーションのdeploy の準備が出来ま した。

Virtual Machines with Load Balancer

Virtual Machines

with Database Service

Association

Deployment

Page 66: クラウド上のサービス開発の新しい動向 --- JavaEE7とPlay2.0 ---

Application Introspection

Virtual Cluster Creation

Virtual Machines

With JavaEE

4. Deployment

サービスのdeployまでの流れ

JavaEEサーバー に、アプリケーシ ョンをdeployします。 Virtual

Machines with Load Balancer

Association

Deployment

Virtual Machines

with Database Service

Page 67: クラウド上のサービス開発の新しい動向 --- JavaEE7とPlay2.0 ---

Application Introspection

Virtual Cluster Creation

Virtual Machines

With JavaEE

クラウド・サービス開始

Virtual Machines with Load Balancer

Association

Deployment

Virtual Machines

with Database Service

Page 69: クラウド上のサービス開発の新しい動向 --- JavaEE7とPlay2.0 ---

Domain Manager

IaaS Management Service

AWS Plugin

Amazon Web Services

GF Instance GF Instance

DAS

Orchestrator Elasiticity Manager

Create Domain/Deploy

1. DAS Creation

2. DAS Creation

3. Deployment

4. VM Creation

5. VM Creation

6. Add Node 7. Deployment

Page 70: クラウド上のサービス開発の新しい動向 --- JavaEE7とPlay2.0 ---

Domain Manager

Create Domain/Deploy

PaaSの管理者は、まず、Domainをdeployします。 具体的には、Domain Managerを立ち上げます。

Page 71: クラウド上のサービス開発の新しい動向 --- JavaEE7とPlay2.0 ---

Domain Manager

IaaS Management Service

AWS Plugin

Amazon Web Services

Create Domain/Deploy

1. DAS Creation

Domain Managerの最初の仕事は、 DAS(Domain Administration Service) を立ち上げることです。 Domain Managerは、IaaS Management Service(IMS)を立ち上げて、IMSはAWS Plug-inを通じて、Amazon Web Serviceに働き掛け、DASのインスタンスを生成しようとします。

Page 72: クラウド上のサービス開発の新しい動向 --- JavaEE7とPlay2.0 ---

Domain Manager

IaaS Management Service

AWS Plugin

Amazon Web Services DAS

Create Domain/Deploy

1. DAS Creation

2. DAS Creation

DASが出来ました。Domain Managerの次の仕事は、 生成されたDASのインスタンス上に、Orchestratorと Elasicity Managerという二つのサービスをdeployし、 それらを走らせることです。

Page 73: クラウド上のサービス開発の新しい動向 --- JavaEE7とPlay2.0 ---

Domain Manager

IaaS Management Service

AWS Plugin

Amazon Web Services DAS

Orchestrator Elasiticity Manager

Create Domain/Deploy

3. Deployment

OrchestrtorとElasiticity Managerがdeployされました。 こうして動き始めたDAS(Domain Administration Service)の次の仕事は、 Glassfishが走るインスタンスを生成することです。

Page 74: クラウド上のサービス開発の新しい動向 --- JavaEE7とPlay2.0 ---

Domain Manager

IaaS Management Service

AWS Plugin

Amazon Web Services DAS

Orchestrator Elasiticity Manager

4. VM Creation

DASは、IMS(IaaS Management Service)に、Virtual Machineの生成を命じます。

Page 75: クラウド上のサービス開発の新しい動向 --- JavaEE7とPlay2.0 ---

Domain Manager

IaaS Management Service

AWS Plugin

Amazon Web Services

GF Instance GF Instance

DAS

Orchestrator Elasiticity Manager

4. VM Creation

5. VM Creation

IMSは、先ほどと同じく、AWS Plug-inを通じて、 Amazon Web Serviceに働き掛け、クラウド上に ノードを割り当て、それぞれのノードに Virtual Machineを生成します。

Page 76: クラウド上のサービス開発の新しい動向 --- JavaEE7とPlay2.0 ---

Domain Manager

IaaS Management Service

AWS Plugin

Amazon Web Services

GF Instance GF Instance

DAS

Orchestrator Elasiticity Manager

6. Add Node

各ノードは、ノードが割り当てられると OrchestratorにAdd Nodeの報告をします・

Page 77: クラウド上のサービス開発の新しい動向 --- JavaEE7とPlay2.0 ---

Domain Manager

IaaS Management Service

AWS Plugin

Amazon Web Services

GF Instance GF Instance

DAS

Orchestrator Elasiticity Manager

7. Deployment

Orchestratorは、それを受けると、 各ノード上のVMに、GlassFishの インスタンスをdeployします。

Page 78: クラウド上のサービス開発の新しい動向 --- JavaEE7とPlay2.0 ---

Domain Manager

IaaS Management Service

AWS Plugin

Amazon Web Services

GF Instance GF Instance

DAS

Orchestrator Elasiticity Manager

Page 79: クラウド上のサービス開発の新しい動向 --- JavaEE7とPlay2.0 ---

Domain Manager

IaaS Management Service

AWS Plugin

Amazon Web Services

GF Instance GF Instance

DAS

Orchestrator Elasiticity Manager

Create Domain/Deploy

1. DAS Creation

2. DAS Creation

3. Deployment

4. VM Creation

5. VM Creation

6. Add Node 7. Deployment

Page 80: クラウド上のサービス開発の新しい動向 --- JavaEE7とPlay2.0 ---

Play 2.0 Template Overview

https://github.com/playframework/Play20/wiki/JavaTemplates

Play 1.xでは、Templateの記述にGroovyが用いられていたが、Play 2.0からは、Scalaに変わった。

Page 81: クラウド上のサービス開発の新しい動向 --- JavaEE7とPlay2.0 ---

TemplateファイルとScala function

Templateファイルは、次のような命名規則でScala functionにコンパイルされる。

views/Application/index.scala.html

generates

views.html.Application.index

Page 82: クラウド上のサービス開発の新しい動向 --- JavaEE7とPlay2.0 ---

Templateファイルから生成された ScalaコードのJavaからの呼び出し

次のTemplateファイルindex.scala.htmlから生成されたScala function indexを

次のように、Javaから呼び出すことが出来る。

@(customer: Customer, orders: Seq[Order]) <h1>Welcome @customer.name!</h1> <ul> @for(order <- orders) { <li>@order.title</li> } </ul>

Html html = views.html.Application.index.render(customer, orders);

Page 83: クラウド上のサービス開発の新しい動向 --- JavaEE7とPlay2.0 ---

Template Syntax Special character ‘@’

‘@’は、Scala文の始まりを示す。文の終わりは指定する必要はなく、コードからPlayが、自動的に推測する。青字部分が、Scalaコードとして解釈される。

‘@’のエスケープには、’@@’を使う。

Hello @customer.name! Hello @(customer.firstName + customer.lastName)! Hello @{val name = customer.firstName + customer.lastName; name}!

My email is bob@@example.com

Page 84: クラウド上のサービス開発の新しい動向 --- JavaEE7とPlay2.0 ---

Template Parameters

Templateは、結局は、Scalaのfunctionなので、引数が必要である。

Templateの引数は、必ず、ファイルの第一行で宣言されねばならない。

@(customer: models.Customer, orders: Seq[models.Order]) @(title: String = "Home") @(title:String)(body: => Html) @(title: String)(body: => Html)(implicit request: play.api.mvc.Request)

Page 85: クラウド上のサービス開発の新しい動向 --- JavaEE7とPlay2.0 ---

Looping / If-Blocks

Templateの中で、for-comprehensionを利用できる。この時、コンパイラーは、ブロックの前にyieldキーワードを挿入することに注意

<ul> @for(p <- products) { <li>@p.name ([email protected])</li> } </ul>

@if(items.isEmpty) { <h1>Nothing to display</h1> } else { <h1>@items.size items!</h1> }

Page 86: クラウド上のサービス開発の新しい動向 --- JavaEE7とPlay2.0 ---

Declaring reusable blocks

Template中に、再利用可能なTemplateブロックを定義できる。

@display(product: models.Product) = { @product.name ([email protected]) } <ul> @products.map { p => @display(product = p) } </ul>

@title(text: String) = @{ text.split(' ').map(_.capitalize).mkString(" ") } <h1>@title("hello world")</h1>

Page 87: クラウド上のサービス開発の新しい動向 --- JavaEE7とPlay2.0 ---

Misc.

@defining(user.firstName + " " + user.lastName) { fullName => <div>Hello @fullName</div>}

Declaring reusable values

Import statements

Comments

@(customer: models.Customer, orders: Seq[models.Order]) @import utils.

@********************* * This is a comment * *********************@

Page 88: クラウド上のサービス開発の新しい動向 --- JavaEE7とPlay2.0 ---

Layout

views/main.scala.htmlがあれば、それがメインのレイアウト・ファイルになる。 @(title: String)(content: Html) <!DOCTYPE html> <html> <head> <title>@title</title> </head> <body> <section class="content">@content</section> </body> </html>

@main(title = "Home") { <h1>Home page</h1> }

views/Application/index.scala.html

Page 89: クラウド上のサービス開発の新しい動向 --- JavaEE7とPlay2.0 ---

@(title: String)(sidebar: Html)(content: Html) <!DOCTYPE html> <html> <head> <title>@title</title> </head> <body> <section class="sidebar">@sidebar</section> <section class="content">@content</section> </body> </html>

@main("Home") { <h1>Sidebar</h1> } { <h1>Home page</h1> }

@sidebar = { <h1>Sidebar</h1> } @main("Home")(sidebar) { <h1>Home page</h1> }

Page 90: クラウド上のサービス開発の新しい動向 --- JavaEE7とPlay2.0 ---

Tags views/tags/notice.scala.html

@(level: String = "error")(body: (String) => Html) @if(level == "success") { <p class="success"> @body("green") </p> } @if(level == "warning") { <p class="warning"> @body("orange") </p> } @if(level == "error") { <p class="error"> @body("red") </p> }

@import tags._ @notice("error") { color => Oops, something is <span style="color:@color">wrong</span> }

Page 91: クラウド上のサービス開発の新しい動向 --- JavaEE7とPlay2.0 ---

Play 2.0 routesファイル サンプル

Playのrouteファイルは、Playのコンセプトをよく表している。

Play 2.0と一緒に配布されている、プログラム・サンプルから、routesファイルを抜き出してみた。参考までサンプルの実行のスクリーン・ショットを添付した。

Page 92: クラウド上のサービス開発の新しい動向 --- JavaEE7とPlay2.0 ---
Page 93: クラウド上のサービス開発の新しい動向 --- JavaEE7とPlay2.0 ---
Page 94: クラウド上のサービス開発の新しい動向 --- JavaEE7とPlay2.0 ---

# Routes # This file defines all application routes (Higher priority routes first) # ~~~~ # Home page GET / controllers.Application.index # Hello action GET /hello controllers.Application.sayHello # Map static resources from the /public folder to the /assets URL path GET /assets/*file controllers.Assets.at(path="/public", file)

conf/routes

Page 95: クラウド上のサービス開発の新しい動向 --- JavaEE7とPlay2.0 ---
Page 96: クラウド上のサービス開発の新しい動向 --- JavaEE7とPlay2.0 ---
Page 97: クラウド上のサービス開発の新しい動向 --- JavaEE7とPlay2.0 ---

# Routes # This file defines all application routes (Higher priority routes first) # ~~~~ # Default path will just redirect to the computer list GET / controllers.Application.index # Computers list (look at the default values for pagination parameters) GET /computers controllers.Application.list(p:Int ?= 0, s:Int ?= 2, f ?= "") # Add computer GET /computers/new controllers.Application.create POST /computers controllers.Application.save # Edit existing computer GET /computers/:id controllers.Application.edit(id:Long) POST /computers/:id controllers.Application.update(id:Long) # Delete a computer POST /computers/:id/delete controllers.Application.delete(id:Long) # Map static resources from the /public folder to the /assets URL path GET /assets/*file controllers.Assets.at(path="/public", file)

Page 98: クラウド上のサービス開発の新しい動向 --- JavaEE7とPlay2.0 ---
Page 99: クラウド上のサービス開発の新しい動向 --- JavaEE7とPlay2.0 ---
Page 100: クラウド上のサービス開発の新しい動向 --- JavaEE7とPlay2.0 ---

# Routes # This file defines all application routes (Higher priority routes first) # ~~~~ # The home page GET / controllers.Projects.index # Authentication GET /login controllers.Application.login POST /login controllers.Application.authenticate GET /logout controllers.Application.logout # Projects POST /projects controllers.Projects.add POST /projects/groups controllers.Projects.addGroup() DELETE /projects/groups controllers.Projects.deleteGroup(group: String) PUT /projects/groups controllers.Projects.renameGroup(group: String) DELETE /projects/:project controllers.Projects.delete(project: Long) PUT /projects/:project controllers.Projects.rename(project: Long)

Page 101: クラウド上のサービス開発の新しい動向 --- JavaEE7とPlay2.0 ---

POST /projects/:project/team controllers.Projects.addUser(project: Long) DELETE /projects/:project/team controllers.Projects.removeUser(project: Long) # Tasks GET /projects/:project/tasks controllers.Tasks.index(project: Long) POST /projects/:project/tasks controllers.Tasks.add(project: Long, folder: String) PUT /tasks/:task controllers.Tasks.update(task: Long) DELETE /tasks/:task controllers.Tasks.delete(task: Long) POST /tasks/folder controllers.Tasks.addFolder DELETE /projects/:project/tasks/folder controllers.Tasks.deleteFolder(project: Long, folder: String) PUT /project/:project/tasks/folder controllers.Tasks.renameFolder(project: Long, folder: String) # Javascript routing GET /assets/javascripts/routes controllers.Application.javascriptRoutes # Map static resources from the /public folder to the /public path GET /assets/*file controllers.Assets.at(path="/public", file)