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

  • 1,474 views
Uploaded 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 …

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.

  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
No Downloads

Views

Total Views
1,474
On Slideshare
0
From Embeds
0
Number of Embeds
2

Actions

Shares
Downloads
31
Comments
1
Likes
3

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    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

  • 1. A Groovy Kind of JavaThe Groovy Way to Manage Apps in the Cloud @natishalom
  • 2. THE GOOD OLD APPLICATION PACKAGE
  • 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. 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. THE NEW APPLICATION STACK Distributed Dependencies Application Pod DB Tomcat, Node.js, Ruby, NoSQL Web LB Server
  • 6. THE NEW APPLICATION STACK
  • 7. Packaging is just not enough...
  • 8. What about the operational aspect?Deployment Post Deployment Installation Fail-overDependency Configuration Update / Maintenance Monitoring Startup
  • 9. …AND ALL THATNEEDS TO REMAINCONSISTENT ACROSSTHE STACK
  • 10. We need a new way to describe and deploy these apps...
  • 11. A DSL TO THE RESCUE11 ® Copyright 2012 GigaSpaces Ltd. All Rights Reserved
  • 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. THE RUBY WAY...13 ® Copyright 2012 GigaSpaces Ltd. All Rights Reserved
  • 14. HOW CAN I DO THE SAME THING IN JAVA?14 ® Copyright 2012 GigaSpaces Ltd. All Rights Reserved
  • 15. GROOVY – GREAT FOR JAVA BASED DSLRemovesSyntacticalNoise15 ® Copyright 2012 GigaSpaces Ltd. All Rights Reserved
  • 16. GROOVY – GREAT FOR JAVA BASED DSLExtendable16 ® Copyright 2012 GigaSpaces Ltd. All Rights Reserved
  • 17. GROOVY – GREAT FOR JAVA BASED DSLReadable17 ® Copyright 2012 GigaSpaces Ltd. All Rights Reserved
  • 18. CREATING A GROOVY-BASED APPLICATION RECIPE DSL – THE CLOUDIFY WAY18 ® Copyright 2012 GigaSpaces Ltd. All Rights Reserved
  • 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. 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. 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. 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. 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. 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. 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. UNDER THE HOOD...26 ® Copyright 2012 GigaSpaces Ltd. All Rights Reserved
  • 27. LET’S START WITH A BASIC GROOVY FILE27 ® Copyright 2012 GigaSpaces Ltd. All Rights Reserved
  • 28. USE CONSTRUCTOR WITH NAMED PARAMETERS28 ® Copyright 2012 GigaSpaces Ltd. All Rights Reserved
  • 29. ADD IMPORT CUSTOMIZER TO GROOVY SHELL29 ® Copyright 2012 GigaSpaces Ltd. All Rights Reserved
  • 30. BETTER, BUT NEEDS A BIT MORE30 ® Copyright 2012 GigaSpaces Ltd. All Rights Reserved
  • 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. OVERRIDE SCRIPT BASE CLASS Tweak a few small things, like redirecting println() to Logger32 ® Copyright 2012 GigaSpaces Ltd. All Rights Reserved
  • 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. LOAD AN OPTIONAL PROPERTIES FILE AND BIND TO SHELL Bind to Groovy Shell34 ® Copyright 2012 GigaSpaces Ltd. All Rights Reserved
  • 35. EASY TO READ, BUT STILL POWERFUL35 ® Copyright 2012 GigaSpaces Ltd. All Rights Reserved
  • 36. EXTENSIVE PLATFORM SUPPORT36 ® Copyright 2012 GigaSpaces Ltd. All Rights Reserved
  • 37. ON ANY CLOUD Your Own Data Center37 ® Copyright 2011 Gigaspaces Ltd. All Rights Reserved
  • 38. Live Demo38 ® Copyright 2011 Gigaspaces Ltd. All Rights Reserved
  • 39. Get it today http://www.cloudifysource.orghttp://github.com/CloudifySource/cloudify