a groovy kind of java (san francisco java user group)

39
A Groovy Kind of Java The Groovy Way to Manage Apps in the Cloud @natishalom

Upload: nati-shalom

Post on 15-Jan-2015

1.506 views

Category:

Documents


5 download

DESCRIPTION

Today's application stack is built out many popular OSS frameworks such as Cassandra, MongoDB, Scala, Play, Memcache, RabitMQ alongside the more traditional JEE stack which includes app servers such as Tomcat and JBoss. In this environment the same practices that we used to have in JEE centric world for managing and deploying our app are not relevant anymore. In this session we'll introduce a new open source framework based on Groovy for packaging your application, automating the scaling, failover, and more.

TRANSCRIPT

Page 1: A Groovy Kind of Java (San Francisco Java User Group)

A Groovy Kind of Java The Groovy Way to Manage Apps in the Cloud

@natishalom

Page 2: A Groovy Kind of Java (San Francisco Java User Group)

THE GOOD OLD APPLICATION PACKAGE

Page 3: A Groovy Kind of Java (San Francisco Java User Group)

GOOD AS LONG AS…

You assume the other components are managed (DB, LB, …)

Everything in your app is Java-based Servers are statically deployed

Page 4: A Groovy Kind of Java (San Francisco Java User Group)

THINGS HAVE CHANGED

• The world is heterogeneous• Cloud - The new data center• Tons of OSS projects• Speed of change ->

continuous delivery• Reduced Boundaries

between Dev and Ops

Page 5: A Groovy Kind of Java (San Francisco Java User Group)

THE NEW APPLICATION STACK

Application

Pod

Web Server LB

DB

Distributed Dependencies

Tomcat, Node.js, Ruby, NoSQL

Page 6: A Groovy Kind of Java (San Francisco Java User Group)

THE NEW APPLICATION STACK

Page 7: A Groovy Kind of Java (San Francisco Java User Group)

Packaging is just not enough...

Page 8: A Groovy Kind of Java (San Francisco Java User Group)

What about the operational aspect?

Deployment

Installation

Configuration

Startup

Dependency

Post Deployment

Monitoring

Update / Maintenanc

e

Fail-over

Page 9: A Groovy Kind of Java (San Francisco Java User Group)

…AND ALL THAT NEEDS TO REMAIN CONSISTENT ACROSS THE STACK

Page 10: A Groovy Kind of Java (San Francisco Java User Group)

We need a new way to describe and deploy these apps...

Page 11: A Groovy Kind of Java (San Francisco Java User Group)

® Copyright 2012 GigaSpaces Ltd. All Rights Reserved11

A DSL TO THE RESCUE

Page 12: A Groovy Kind of Java (San Francisco Java User Group)

® Copyright 2012 GigaSpaces Ltd. All Rights Reserved12

RECIPES – THE NEW APPLICATION DEPLOYMENT DSL

Recipes define all the details needed to run an app:

What middleware services to run Dependencies between services How to install services Where application and service binaries are When to spawn or terminate instances How to monitor each of the services.

Page 13: A Groovy Kind of Java (San Francisco Java User Group)

® Copyright 2012 GigaSpaces Ltd. All Rights Reserved13

THE RUBY WAY...

Page 14: A Groovy Kind of Java (San Francisco Java User Group)

® Copyright 2012 GigaSpaces Ltd. All Rights Reserved14

HOW CAN I DO THE SAME THING IN JAVA?

Page 15: A Groovy Kind of Java (San Francisco Java User Group)

® Copyright 2012 GigaSpaces Ltd. All Rights Reserved15

GROOVY – GREAT FOR JAVA BASED DSL

Removes Syntactical Noise

Page 16: A Groovy Kind of Java (San Francisco Java User Group)

® Copyright 2012 GigaSpaces Ltd. All Rights Reserved16

GROOVY – GREAT FOR JAVA BASED DSL

Extendable

Page 17: A Groovy Kind of Java (San Francisco Java User Group)

® Copyright 2012 GigaSpaces Ltd. All Rights Reserved17

GROOVY – GREAT FOR JAVA BASED DSL

Readable

Page 18: A Groovy Kind of Java (San Francisco Java User Group)

® Copyright 2012 GigaSpaces Ltd. All Rights Reserved18

CREATING A GROOVY-BASED APPLICATION RECIPE DSL – THE CLOUDIFY WAY

Page 19: A Groovy Kind of Java (San Francisco Java User Group)

CLOUDIFY RECIPE DOMAIN MODEL

Application

Pod

Web Server LB

DBService:

Describe an individual tiere.g. Tomcat, Node.js, Ruby, NoSQL

Application: Describes the

application tiers and their dependencies

Page 20: A Groovy Kind of Java (San Francisco Java User Group)

® Copyright 2012 GigaSpaces Ltd. All Rights Reserved

APPLICATION RECIPE

application {name="petclinic"service { name = "mongod" }service { name = "mongoConfig" }service { name = "apacheLB" }service { name = "mongos" dependsOn = ["mongoConfig",

"mongod"]}

}

Page 21: A Groovy Kind of Java (San Francisco Java User Group)

® Copyright 2012 GigaSpaces Ltd. All Rights Reserved

SERVICE RECIPE: MACHINE TEMPLATES

21

lifecycle{ install "mysql_install.groovy"  start "mysql_start.groovy"  startDetectionTimeoutSecs 900  startDetection "mysql_startDetection.groovy"  stopDetection {    !ServiceUtils.isPortOccupied(jdbcPort)  }  preStop ([         "Win.*":"killAllMysql.bat",                     "Linux.*":"mysql_stop.groovy"    ])  shutdown ([                             "Linux.*":"mysql_uninstall.groovy"  ])

service { name "mysql" icon "mysql.png" type "DATABASE"

...}

Page 22: A Groovy Kind of Java (San Francisco Java User Group)

® Copyright 2012 GigaSpaces Ltd. All Rights Reserved

SERVICE RECIPE: SCALING RULES

22

scalingRules ([ scalingRule { serviceStatistics { metric "Total Requests Count" statistics Statistics.maximumThroughput movingTimeRangeInSeconds 20 } highThreshold { value 1 instancesIncrease 1 } lowThreshold { value 0.2 instancesDecrease 1 } }])

Page 23: A Groovy Kind of Java (San Francisco Java User Group)

® Copyright 2012 GigaSpaces Ltd. All Rights Reserved23

SERVICE RECIPE: CUSTOM METRICS

monitors {

def ctxPath = ("default" == context.applicationName)?"":"${context.applicationName}“

def metricNamesToMBeansNames = ["Current Http Threads Busy": ["Catalina:type=ThreadPool,name=\"http-

bio- ${currHttpPort}\"", "currentThreadsBusy"], "Current Http Thread Count": ["Catalina:type=ThreadPool,name=\"http-

bio- ${currHttpPort}\"", "currentThreadCount"],

return getJmxMetrics("127.0.0.1",currJmxPort,metricNamesToMBeansNames) }

Page 24: A Groovy Kind of Java (San Francisco Java User Group)

® Copyright 2012 GigaSpaces Ltd. All Rights Reserved24

SERVICE RECIPE: MACHINE TEMPLATES

compute { template "SMALL_LINUX"}

SMALL_LINUX : template imageId "us-east-1/ami-76f0061f“ remoteDirectory "/home/ec2-user/gs-files“ machineMemoryMB 1600 hardwareId "m1.small" locationId "us-east-1" localDirectory "upload" keyFile "myKeyFile.pem"

options ([ "securityGroups" : ["default"]as

String[], "keyPair" : "myKeyFile"])

overrides (["jclouds.ec2.ami-query":"",

"jclouds.ec2.cc-ami-query":""])privileged true

}

SMALL_LINUX : template{ imageId "1234" machineMemoryMB 3200 hardwareId "103" remoteDirectory "/root/gs-files" localDirectory "upload" keyFile "gigaPGHP.pem" options ([ "openstack.securityGroup" : "default", "openstack.keyPair" : "gigaPGHP"

])privileged true

}

Page 25: A Groovy Kind of Java (San Francisco Java User Group)

INTEGRATING WITH CHEF service { extend "../../../services/chef" name "your service name" type "DATABASE" numInstances 1

compute { template "SMALL_UBUNTU" } lifecycle { startDetectionTimeoutSecs 240 startDetection { ServiceUtils.isPortOccupied(System.getenv()["CLOUDIFY_AGENT_ENV_PRIVATE_IP"], 3306) } }

}

Custom Service Name

Add Custom Start Detector

Extending the Chef Recipe

runParams = [“param1": “value1”,“param2": [“key1”:”subvalue1”,…]…"run_list": ["recipe[cookbook_name::recipe_name]"]]

Runtime parameters

Run list(Recipes or Roles)

Page 26: A Groovy Kind of Java (San Francisco Java User Group)

® Copyright 2012 GigaSpaces Ltd. All Rights Reserved26

UNDER THE HOOD...

Page 27: A Groovy Kind of Java (San Francisco Java User Group)

® Copyright 2012 GigaSpaces Ltd. All Rights Reserved27

LET’S START WITH A BASIC GROOVY FILE

Page 28: A Groovy Kind of Java (San Francisco Java User Group)

® Copyright 2012 GigaSpaces Ltd. All Rights Reserved28

USE CONSTRUCTOR WITH NAMED PARAMETERS

Page 29: A Groovy Kind of Java (San Francisco Java User Group)

® Copyright 2012 GigaSpaces Ltd. All Rights Reserved29

ADD IMPORT CUSTOMIZER TO GROOVY SHELL

Page 30: A Groovy Kind of Java (San Francisco Java User Group)

® Copyright 2012 GigaSpaces Ltd. All Rights Reserved30

BETTER, BUT NEEDS A BIT MORE

Page 31: A Groovy Kind of Java (San Francisco Java User Group)

® Copyright 2012 GigaSpaces Ltd. All Rights Reserved31

OVERRIDE SCRIPT BASE CLASS

A Groovy script is compiled into a Java class. The Groovy commands runs in the run() method. The created Groovy class extends the groovy.lang.Script class. Default implementations of:

get/setProperty invokeMethod println

Use GroovyShell to replace default base script class with our own implementation.

Page 32: A Groovy Kind of Java (San Francisco Java User Group)

® Copyright 2012 GigaSpaces Ltd. All Rights Reserved32

OVERRIDE SCRIPT BASE CLASS

Tweak a few small things, like redirecting println() to Logger

Page 33: A Groovy Kind of Java (San Francisco Java User Group)

® Copyright 2012 GigaSpaces Ltd. All Rights Reserved33

AND TWEAK SOME MORE

Override invokeMethod() and setProperty() Map method names to domain objects If not a domain object, map to field name of current object

Page 34: A Groovy Kind of Java (San Francisco Java User Group)

® Copyright 2012 GigaSpaces Ltd. All Rights Reserved34

LOAD AN OPTIONAL PROPERTIES FILE AND BIND TO SHELL

Bind to Groovy Shell

Page 35: A Groovy Kind of Java (San Francisco Java User Group)

® Copyright 2012 GigaSpaces Ltd. All Rights Reserved35

EASY TO READ, BUT STILL POWERFUL

Page 36: A Groovy Kind of Java (San Francisco Java User Group)

® Copyright 2012 GigaSpaces Ltd. All Rights Reserved36

EXTENSIVE PLATFORM SUPPORT

Page 37: A Groovy Kind of Java (San Francisco Java User Group)

37

ON ANY CLOUD

® Copyright 2011 Gigaspaces Ltd. All Rights Reserved

Your Own Data Center

Page 38: A Groovy Kind of Java (San Francisco Java User Group)

Live Demo

® Copyright 2011 Gigaspaces Ltd. All Rights Reserved38

Page 39: A Groovy Kind of Java (San Francisco Java User Group)

Get it todayhttp://www.cloudifysource.org

http://github.com/CloudifySource/cloudify