Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

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

2,002 views

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.

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

×