0
A Groovy Kind of JavaThe 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  Serv...
THINGS HAVE CHANGED• The world is heterogeneous• Cloud - The new data center• Tons of OSS projects• Speed of change ->  co...
THE NEW APPLICATION STACK    Distributed   Dependencies                                 Application                       ...
THE NEW APPLICATION STACK
Packaging is just not enough...
What about the operational aspect?Deployment                       Post Deployment        Installation                    ...
…AND ALL THATNEEDS TO REMAINCONSISTENT ACROSSTHE STACK
We need a new way to describe and      deploy these apps...
A DSL TO THE RESCUE11          ® Copyright 2012 GigaSpaces Ltd. All Rights Reserved
RECIPES – THE NEW APPLICATION DEPLOYMENT DSL                   Recipes define all the details needed to run an app:       ...
THE RUBY WAY...13         ® Copyright 2012 GigaSpaces Ltd. All Rights Reserved
HOW CAN I DO THE SAME THING IN JAVA?14             ® Copyright 2012 GigaSpaces Ltd. All Rights Reserved
GROOVY – GREAT FOR JAVA BASED DSLRemovesSyntacticalNoise15            ® Copyright 2012 GigaSpaces Ltd. All Rights Reserved
GROOVY – GREAT FOR JAVA BASED DSLExtendable16           ® Copyright 2012 GigaSpaces Ltd. All Rights Reserved
GROOVY – GREAT FOR JAVA BASED DSLReadable17         ® Copyright 2012 GigaSpaces Ltd. All Rights Reserved
CREATING A GROOVY-BASED APPLICATION     RECIPE DSL – THE CLOUDIFY WAY18            ® Copyright 2012 GigaSpaces Ltd. All Ri...
CLOUDIFY RECIPE DOMAIN MODEL Application:    Describes the application tiers and their dependencies               Applicat...
APPLICATION RECIPEapplication {      name="petclinic"      service {        name = "mongod"      }      service {        n...
SERVICE RECIPE: MACHINE TEMPLATESservice {  name "mysql"  icon "mysql.png"  type "DATABASE"            ...} lifecycle{   i...
SERVICE RECIPE: SCALING RULES  scalingRules ([    scalingRule {      serviceStatistics {          metric "Total Requests C...
SERVICE RECIPE: CUSTOM METRICSmonitors {  def ctxPath = ("default" ==context.applicationName)?"":"${context.applicationNam...
SERVICE RECIPE: MACHINE TEMPLATES        compute {          template "SMALL_LINUX"        }SMALL_LINUX : template{        ...
INTEGRATING WITH CHEF  service {      extend "../../../services/chef"      name "your service name"                       ...
UNDER THE HOOD...26            ® Copyright 2012 GigaSpaces Ltd. All Rights Reserved
LET’S START WITH A BASIC GROOVY FILE27         ® Copyright 2012 GigaSpaces Ltd. All Rights Reserved
USE CONSTRUCTOR WITH NAMED PARAMETERS28       ® Copyright 2012 GigaSpaces Ltd. All Rights Reserved
ADD IMPORT CUSTOMIZER TO GROOVY SHELL29        ® Copyright 2012 GigaSpaces Ltd. All Rights Reserved
BETTER, BUT NEEDS A BIT MORE30        ® Copyright 2012 GigaSpaces Ltd. All Rights Reserved
OVERRIDE SCRIPT BASE CLASS    A Groovy script is compiled into a Java class.    The Groovy commands runs in the run() me...
OVERRIDE SCRIPT BASE CLASS Tweak a few small things, like redirecting println() to Logger32            ® Copyright 2012 G...
AND TWEAK SOME MORE Override invokeMethod() and setProperty() Map method names to domain objects If not a domain object...
LOAD AN OPTIONAL PROPERTIES FILE AND BIND TO SHELL Bind to Groovy Shell34            ® Copyright 2012 GigaSpaces Ltd. All...
EASY TO READ, BUT STILL POWERFUL35         ® Copyright 2012 GigaSpaces Ltd. All Rights Reserved
EXTENSIVE PLATFORM SUPPORT36        ® Copyright 2012 GigaSpaces Ltd. All Rights Reserved
ON ANY CLOUD                                                 Your Own                                                Data ...
Live Demo38   ® Copyright 2011 Gigaspaces Ltd. All Rights Reserved
Get it today      http://www.cloudifysource.orghttp://github.com/CloudifySource/cloudify
Upcoming SlideShare
Loading in...5
×

A Groovy Kind of Java (San Francisco Java User Group)

1,572

Published on

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.

1 Comment
3 Likes
Statistics
Notes
No Downloads
Views
Total Views
1,572
On Slideshare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
32
Comments
1
Likes
3
Embeds 0
No embeds

No notes for slide
  • This is a simpler method to show how to set a service than the previous slide
  • Use wrapper class which is RunnableWe change the default base class from the default script class to our own extended script class – this enables us to add specific attributes and context to each element in the DSL.
  • See reference below
  • We needed to extend the invoke method to map between the service method and the service domain model using naming conventionThe dfferent between this method and monkey patching is that in this method can be called from a java code where monkey patching were adding modethods on the fly a feature that his not that intituive to use if your calling groovy from java.One of the differences is that in this mothod as appose to monkey patching the object meta data doesn’t change i.e. I will not be able to see a new method named service added to the class definition instead we have a defaul handler that will catch every undefined method and will invoke it through this handler.
  • Note that in this DSL theimpage and preStartMessage are defined as properties
  • Start local cloud Show recipe – install application – simple Show on ec2 Install Metrics LogsComparison charts
  • Transcript of "A Groovy Kind of Java (San Francisco Java User Group)"

    1. 1. A Groovy Kind of JavaThe Groovy Way to Manage Apps in the Cloud @natishalom
    2. 2. THE GOOD OLD APPLICATION PACKAGE
    3. 3. GOOD AS LONG AS…  You assume the other components are managed (DB, LB, …)  Everything in your app is Java-based  Servers are statically deployed
    4. 4. 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
    5. 5. THE NEW APPLICATION STACK Distributed Dependencies Application Pod DB Tomcat, Node.js, Ruby, NoSQL Web LB Server
    6. 6. THE NEW APPLICATION STACK
    7. 7. Packaging is just not enough...
    8. 8. What about the operational aspect?Deployment Post Deployment Installation Fail-overDependency Configuration Update / Maintenance Monitoring Startup
    9. 9. …AND ALL THATNEEDS TO REMAINCONSISTENT ACROSSTHE STACK
    10. 10. We need a new way to describe and deploy these apps...
    11. 11. A DSL TO THE RESCUE11 ® Copyright 2012 GigaSpaces Ltd. All Rights Reserved
    12. 12. 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.12 ® Copyright 2012 GigaSpaces Ltd. All Rights Reserved
    13. 13. THE RUBY WAY...13 ® Copyright 2012 GigaSpaces Ltd. All Rights Reserved
    14. 14. HOW CAN I DO THE SAME THING IN JAVA?14 ® Copyright 2012 GigaSpaces Ltd. All Rights Reserved
    15. 15. GROOVY – GREAT FOR JAVA BASED DSLRemovesSyntacticalNoise15 ® Copyright 2012 GigaSpaces Ltd. All Rights Reserved
    16. 16. GROOVY – GREAT FOR JAVA BASED DSLExtendable16 ® Copyright 2012 GigaSpaces Ltd. All Rights Reserved
    17. 17. GROOVY – GREAT FOR JAVA BASED DSLReadable17 ® Copyright 2012 GigaSpaces Ltd. All Rights Reserved
    18. 18. CREATING A GROOVY-BASED APPLICATION RECIPE DSL – THE CLOUDIFY WAY18 ® Copyright 2012 GigaSpaces Ltd. All Rights Reserved
    19. 19. CLOUDIFY RECIPE DOMAIN MODEL Application: Describes the application tiers and their dependencies Application Pod DB Service: Describe an individual tier e.g. Tomcat, Node.js, Ruby, NoSQL Web LB Server
    20. 20. APPLICATION RECIPEapplication { name="petclinic" service { name = "mongod" } service { name = "mongoConfig" } service { name = "apacheLB" } service { name = "mongos" dependsOn = ["mongoConfig", "mongod"] }} ® Copyright 2012 GigaSpaces Ltd. All Rights Reserved
    21. 21. SERVICE RECIPE: MACHINE TEMPLATESservice { name "mysql" icon "mysql.png" type "DATABASE" ...} 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" 21]) shutdown ([ "Linux.*":"mysql_uninstall.groovy" ]) ® Copyright 2012 GigaSpaces Ltd. All Rights Reserved
    22. 22. SERVICE RECIPE: SCALING RULES scalingRules ([ scalingRule { serviceStatistics { metric "Total Requests Count" statistics Statistics.maximumThroughput movingTimeRangeInSeconds 20 } highThreshold { value 1 instancesIncrease 1 } lowThreshold { value 0.2 instancesDecrease 1 } }22]) ® Copyright 2012 GigaSpaces Ltd. All Rights Reserved
    23. 23. SERVICE RECIPE: CUSTOM METRICSmonitors { 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)}23 ® Copyright 2012 GigaSpaces Ltd. All Rights Reserved
    24. 24. SERVICE RECIPE: MACHINE TEMPLATES compute { template "SMALL_LINUX" }SMALL_LINUX : template{ SMALL_LINUX : template imageId "1234" imageId "us-east-1/ami-76f0061f“ machineMemoryMB 3200 remoteDirectory "/home/ec2-user/gs-files“ hardwareId "103" machineMemoryMB 1600 remoteDirectory "/root/gs-files" hardwareId "m1.small" localDirectory "upload" locationId "us-east-1" keyFile "gigaPGHP.pem" localDirectory "upload" options ([ keyFile "myKeyFile.pem" "openstack.securityGroup" : "default", "openstack.keyPair" : "gigaPGHP" options ([ ]) "securityGroups" : ["default"]as privileged true String[],} "keyPair" : "myKeyFile" ]) overrides (["jclouds.ec2.ami-query":"", "jclouds.ec2.cc-ami-query":""]) privileged true } 24 ® Copyright 2012 GigaSpaces Ltd. All Rights Reserved
    25. 25. INTEGRATING WITH CHEF service { extend "../../../services/chef" name "your service name" Extending the Chef Recipe type "DATABASE" numInstances 1 compute { Custom Service Name template "SMALL_UBUNTU" } lifecycle { startDetectionTimeoutSecs 240 Add Custom Start Detector startDetection { ServiceUtils.isPortOccupied(System.getenv()["CLOUDIFY_AGENT_ENV_PRIVATE _IP"], 3306) } } } runParams = [ “param1": “value1”, “param2": [“key1”:”subvalue1”,…] Runtime parameters … "run_list": ["recipe[cookbook_name::recipe_name]"] ] Run list (Recipes or Roles)
    26. 26. UNDER THE HOOD...26 ® Copyright 2012 GigaSpaces Ltd. All Rights Reserved
    27. 27. LET’S START WITH A BASIC GROOVY FILE27 ® Copyright 2012 GigaSpaces Ltd. All Rights Reserved
    28. 28. USE CONSTRUCTOR WITH NAMED PARAMETERS28 ® Copyright 2012 GigaSpaces Ltd. All Rights Reserved
    29. 29. ADD IMPORT CUSTOMIZER TO GROOVY SHELL29 ® Copyright 2012 GigaSpaces Ltd. All Rights Reserved
    30. 30. BETTER, BUT NEEDS A BIT MORE30 ® Copyright 2012 GigaSpaces Ltd. All Rights Reserved
    31. 31. 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.31 ® Copyright 2012 GigaSpaces Ltd. All Rights Reserved
    32. 32. OVERRIDE SCRIPT BASE CLASS Tweak a few small things, like redirecting println() to Logger32 ® Copyright 2012 GigaSpaces Ltd. All Rights Reserved
    33. 33. 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 object33 ® Copyright 2012 GigaSpaces Ltd. All Rights Reserved
    34. 34. LOAD AN OPTIONAL PROPERTIES FILE AND BIND TO SHELL Bind to Groovy Shell34 ® Copyright 2012 GigaSpaces Ltd. All Rights Reserved
    35. 35. EASY TO READ, BUT STILL POWERFUL35 ® Copyright 2012 GigaSpaces Ltd. All Rights Reserved
    36. 36. EXTENSIVE PLATFORM SUPPORT36 ® Copyright 2012 GigaSpaces Ltd. All Rights Reserved
    37. 37. ON ANY CLOUD Your Own Data Center37 ® Copyright 2011 Gigaspaces Ltd. All Rights Reserved
    38. 38. Live Demo38 ® Copyright 2011 Gigaspaces Ltd. All Rights Reserved
    39. 39. Get it today http://www.cloudifysource.orghttp://github.com/CloudifySource/cloudify
    1. A particular slide catching your eye?

      Clipping is a handy way to collect important slides you want to go back to later.

    ×