a groovy kind of java (san francisco java user group)
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
A Groovy Kind of Java The Groovy Way to Manage Apps in the Cloud
@natishalom
THE GOOD OLD APPLICATION PACKAGE
GOOD AS LONG AS…
You assume the other components are managed (DB, LB, …)
Everything in your app is Java-based Servers are statically deployed
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
THE NEW APPLICATION STACK
Application
Pod
Web Server LB
DB
Distributed Dependencies
Tomcat, Node.js, Ruby, NoSQL
THE NEW APPLICATION STACK
Packaging is just not enough...
What about the operational aspect?
Deployment
Installation
Configuration
Startup
Dependency
Post Deployment
Monitoring
Update / Maintenanc
e
Fail-over
…AND ALL THAT NEEDS TO REMAIN CONSISTENT ACROSS THE STACK
We need a new way to describe and deploy these apps...
® Copyright 2012 GigaSpaces Ltd. All Rights Reserved11
A DSL TO THE RESCUE
® 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.
® Copyright 2012 GigaSpaces Ltd. All Rights Reserved13
THE RUBY WAY...
® Copyright 2012 GigaSpaces Ltd. All Rights Reserved14
HOW CAN I DO THE SAME THING IN JAVA?
® Copyright 2012 GigaSpaces Ltd. All Rights Reserved15
GROOVY – GREAT FOR JAVA BASED DSL
Removes Syntactical Noise
® Copyright 2012 GigaSpaces Ltd. All Rights Reserved16
GROOVY – GREAT FOR JAVA BASED DSL
Extendable
® Copyright 2012 GigaSpaces Ltd. All Rights Reserved17
GROOVY – GREAT FOR JAVA BASED DSL
Readable
® Copyright 2012 GigaSpaces Ltd. All Rights Reserved18
CREATING A GROOVY-BASED APPLICATION RECIPE DSL – THE CLOUDIFY WAY
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
® 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"]}
}
® 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"
...}
® 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 } }])
® 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) }
® 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
}
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)
® Copyright 2012 GigaSpaces Ltd. All Rights Reserved26
UNDER THE HOOD...
® Copyright 2012 GigaSpaces Ltd. All Rights Reserved27
LET’S START WITH A BASIC GROOVY FILE
® Copyright 2012 GigaSpaces Ltd. All Rights Reserved28
USE CONSTRUCTOR WITH NAMED PARAMETERS
® Copyright 2012 GigaSpaces Ltd. All Rights Reserved29
ADD IMPORT CUSTOMIZER TO GROOVY SHELL
® Copyright 2012 GigaSpaces Ltd. All Rights Reserved30
BETTER, BUT NEEDS A BIT MORE
® 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.
® Copyright 2012 GigaSpaces Ltd. All Rights Reserved32
OVERRIDE SCRIPT BASE CLASS
Tweak a few small things, like redirecting println() to Logger
® 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
® Copyright 2012 GigaSpaces Ltd. All Rights Reserved34
LOAD AN OPTIONAL PROPERTIES FILE AND BIND TO SHELL
Bind to Groovy Shell
® Copyright 2012 GigaSpaces Ltd. All Rights Reserved35
EASY TO READ, BUT STILL POWERFUL
® Copyright 2012 GigaSpaces Ltd. All Rights Reserved36
EXTENSIVE PLATFORM SUPPORT
37
ON ANY CLOUD
® Copyright 2011 Gigaspaces Ltd. All Rights Reserved
Your Own Data Center
Live Demo
® Copyright 2011 Gigaspaces Ltd. All Rights Reserved38
Get it todayhttp://www.cloudifysource.org
http://github.com/CloudifySource/cloudify