dynamic groovy edges

Download Dynamic Groovy Edges

Post on 15-Jan-2015

555 views

Category:

Technology

3 download

Embed Size (px)

DESCRIPTION

Spring and Groovy to create dynamic integration edges and regression isolation.

TRANSCRIPT

  • 1. 1 Managing Change and Achieving Regression Isolation Dynamic Groovy Edges May 21st, 2012 Prepared for: Triangle Java Users Group (TriJUG)

2. 2 Who Am I? Well Java Architect with ICF Ironworks Adjunct Professor Started with HTML and Lotus Notes in 1992 In the interim there was C, C++, VB, Lotus Script, PERL, LabVIEW, etc. Not so much an Early Adopter as much as a Fast Follower of Java Technologies Learned Java 1.1 in 1997, J2EE in 1999 Alphabet Soup (MCSE, ICAAD, ICASA, SCJP, SCJD, PMP, CSM) LinkedIn: http://www.linkedin.com/in/iamjimmyray Blog: http://jimmyraywv.blogspot.com/ Avoiding Tech-sand 3. 3 Managing Change and Achieving Regression Isolation Dynamic Groovy Edges 4. 4 JEE Application Architecture Arranged into layers When there are N layers: There are N-1 layer junctions There are (N-1) X 2 layer edges In this diagram there are three layers, two layer junctions, and four layer edges. We control edges 5. 5 The Issue with Layers Often written by someone else You often have little control or influence over the implementation of the layer to which you must integrate You control your side (edge) of the interface junction Notorious change zones Changes occur at different paces 6. 6 Keeping Up the Pace Pace Layering Approach to Application Design http://www.doozer.com/developer-exchange/entry/accelerating-innovation- by-adopting-a-pace-layered-application-strategy Complex systems can be decomposed into multiple layers, where the layers change at different rates. The fast layers learn, absorb shocks and get attention; the slow layers remember, constrain and have power. One of the implications of this model is that information architects can do what they have always doneslow, deep, rich work; while tagging can spin madly on the surface. If it is worth keeping, it will seep down into the lower layers. Donna Maurer 7. 7 When Layers Change In Java web applications, regression analysis and testing are usually tied to the boundaries of the application or deployment artifacts: JARs, WARs, EARS etc. Upstream and downstream dependencies also come into play Not to be confused with functional testing of changed components If you redeploy the entire WAR or EAR, you could find yourself testing that entire application boundary. As well as its integration junctions (critical patches not withstanding) 8. 8 Detecting Changes How do we detect changes to web services as soon as possible? XMLUnit/JUnit Tests Easily written in Groovy Hudson scheduled Ant tasks DIFFERENCE CODE:19:CHILD_NODELIST_LENGTH_ID:Comparing 2 nodes with different numbers of children Control(prod) Node: Target(dev) Node: 9. 9 Demo Detecting Changes Groovy Console JUnit XMLUnit Apache 2.2 Tomcat 6.0.35 10. 10 CI Using Groovy XmlUnit Tests Wrap Groovy script with Ant Execute in Hudson build Use Gradle with the Groovy Plugin Run your Groovy test within Gradle build 11. 11 Managing Change How do we better manage the change between the layers? Understand that we cannot stop change Reduce regression testing needs by shrinking regression boundaries Prepare our teams for the changes with more dynamic reaction techniques Start with Groovy beans OrStart with Java beans and move to Groovy as needed Detect changes as early as possible, and before they impact downstream systems 12. 12 Groovy Edges Build your edges with Groovy (or other dynamic JVM language) objects Groovy can be written as a script and parsed at run- time and compiled into Java byte-code and then loaded by the Groovy class loader. Groovy scripts can contain Groovy and Java syntax in the script file (*.groovy). Groovy can use the same Java APIs that are used by traditional Java code. Groovy adds features that make it easier to work with XML (primary language of choice for most integrations) Markup Builder XML Slurper 13. 13 Groovy Markup Builder Allows developers to use builder patterns to construct XML def writer = new StringWriter(); def xml = new MarkupBuilder(writer); xml.'ser:writeEmployee'('xmlns:ser':"http://service.rjug.ironworks.com/"){ employee{ dateOfBirth(emsRequest.getEmployee().getDateOfBirth()) firstName(emsRequest.getEmployee().getFirstName()) lastName(emsRequest.getEmployee().getLastName()) middleName(emsRequest.getEmployee().getMiddleName()) employeeId(emsRequest.getEmployee().getEmployeeId()) hireDate(emsRequest.getEmployee().getHireDate()) address{ addressLine1(emsRequest.getEmployee().getAddress().getAddressLine1()) 14. 14 A Word About Hard-Coding (or not) When is hard-coding not really? Our internal beliefs have shifted slightly. How about when it is in Groovy? Especially when that Groovy is treated as content and not part of a rigid deployment architecture? Still have to work within the boundaries (constraints) of the JVM 15. 15 Groovy XML Slurper Groovy construct for efficient partial XML processing. EmployeeManagerServiceResponse emsResponse = new EmployeeManagerServiceResponse(); GPathResult response; try{ response = new XmlSlurper().parseText(rawResponse.getWriter().toString()); emsResponse.getEmployee().setFirstName(response.'return'.firstName.text()); emsResponse.getEmployee().setLastName(response.'return'.lastName.text()); 16. 16 Groovy XML Slurper Another Example slurper.jobList.job.each { it.docs.doc.each { doc = new DocDto(); docs.add(doc); doc.setDocumentId(new BigInteger(it.documentId.toString())); //doc.setDcmntNbr(new BigInteger(it.dcmntNbr.toString())); doc.setOriginalFilename(it.originalFilename.toString()); doc.setPhasecode(it.phasecode.toString()); doc.setRcvdDt(it.rcvdDt.toString()); doc.setStatuscode(it.statuscode.toString()); doc.setStepcode(it.stepcode.toString()); 562132403073245.pdf422009-01-10 00:00:00.0ABC 17. 17 A Word About Groovy Slurping XML Payloads No longer tied to JAXB This is uncomfortable for some traditional Java developers Can use Groovy closures on collections (even nested collections) Easy to enable/disable getter calls, especially if Groovy is stored outside of rigid deployment structure (CMS, Apache, etc.) This is scary to some Still requires Configuration Management rigor Its about risk tolerance It could be that this approach is better suited for non-production environments within certain organizations 18. 18 Groovy XML Slurper Trade-offs Use the Groovy XML Slurper when you do not have to parse the entire XML Slurper uses paths expressions as apposed to constructing a DOM Path expression might be executed multiple times Could be slower in larger, more complex XML There are also differences when editing XML The XML Parser allows for edits inline The XML Slurper would require another slurp after changes are applied. The XML Slurper is well suited for simple web service clients Allows direct access via getters to return object graph 19. 19 Groovy Edge Component Web Service Client For SOA interfaces implemented with web services, web service clients are primarily the target edge component for dynamic updating. Using Groovy to write these web services clients makes it easier to update clients. Features can be added or removed and quickly redeployed via content changes, and not necessarily Java deployments Spring will reload the Groovy web service client when it changes This provides a great solution for prototyping in an Agile environment. For MVC containers, the controller is the edge component that is up for Groovy-enizing, Groovy-ization, etc. 20. 20 Spring Beans 21. 21 Groovy Location Property groovy.url=http://localhost/groovy/EmployeeManagerServiceImpl.gro ovy Not only that, but Store your properties outside of the WAR/EAR, reachable via URL 22. 22 Loading Properties http://localhost/properties/service.properties 23. 23 Demo Web Services Provider Simple JAX-WS Bottom-up web service Environment: Apache2.2 Tomcat 6.0.35 Java 1.6 JRE JAX-WS RI 2.2 JAXB 2.2.3 SoapUI 4.0.0 Spring Data Layer MongoDB Data Repository MongoDB NoSQL Database (Upcoming TriJUG Event: 07/16/12 Deep Mistry Mongo DB) 24. 24 Demo Web Services Consumer Simple Spring WS Client Environment: Apache2.2 Tomcat 6.0.35 Java 1.6 JRE Spring Framework 3.0.x Spring WS Groovy Web Services Framework 25. 25 This Is Not Bleeding Edge Yet, it is still new to a lot of Spring users January 2009: http://www.ibm.com/developerworks/java/library/j- groovierspring2/index.html At the NVSS NFJS conference in Reston in April 2012, there were still sessions on Spring and Groovy integration with dynamic beans NFJS Due in Raleigh, NC August 24-26 http://www.nofluffjuststuff.com/home/main 26. 26 Spring Bean Configuration Issues Spring needs to be able to locate Groovy script content in order to load configurations. ERROR - ContextLoader.initWebApplicationContext(220) | Context initialization failed org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'employeeManagerService' defined in file [C:Toolsapache-tomcat-6.0.16w ebappsDynamicGroovyTutorialWEB-INFclassescontextservice_ws.xml]: Cannot resolve reference to bean 'employeeManagerServiceImpl' while setting bean property 'groovyImpl'; 27. 27 Spring Bean Config With Content Proxy Use a Content Proxy The Content Proxy is deployed into a separate WAR and addressable via a URL (perhaps a RESTful web service) that would retrieve the dynamic Spring Bean configuration scripts If the scripts are not found in script repository, the Content Proxy can load the scripts from a backup site or even from inside the application boundaries Default Location. The Content Proxy is a layer of indirection to better manage the link between your Spring application and the content management system that you may be using. Content Proxies are also very helpful when scripts (or other content) are loaded from a CMS through an API that would not link directly to the Spring Bean configurator. Provides a layer of indire

Recommended

View more >