Overview of the technology constraints of putting classic and legacy applications on the cloud. This slide deck covers tools and prescriptive quantitative techniques and the why what and how of migrating applications to Cloud Foundry PaaS.
2013-2015 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Migrating the Monolith Rohit Kelapure @rkela
Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Monolith – Big Ball Of Mud
Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Monoliths in the Wild – Liferay Portal
Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Kiviat Metrics Graphs 5 https://github.com/pivotalservices/spring-music http://www.campwoodsw.com/sourcemonitor.html
Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ How The Hell Did We Get Here ? THROWAWAY CODE (QUICK HACK, KLEENEX CODE, DISPOSABLE CODE, SCRIPTING, KILLER DEMO, PERMANENT PROTOTYPE, BOOMTOWN) PIECEMEAL GROWTH (URBAN SPRAWL, ITERATIVE-INCREMENTAL DEVELOPMENT) KEEP IT WORKING (VITALITY, BABY STEPS, DAILY BUILD, FIRST, DO NO HARM) SHEARING LAYERS SWEEPING IT UNDER THE RUG (POTEMKIN VILLAGE, HOUSECLEANING, PRETTY FACE, QUARANTINE, HIDING IT UNDER THE BED, REHABILITATION) RECONSTRUCTION (TOTAL REWRITE, DEMOLITION, THROWAWAY THE FIRST ONE, START OVER) 6
Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Is there Any Hope ? Homeostasis and Retrospective feedback - “Homeostasis insulates the system from short-range fluctuations in its environment, while feedback mechanisms respond to long-term discrepancies between a system's actual and desired behavior, and adjust it accordingly.” • One of mud's most effective enemies is sunshine • Leverage Extreme Programming • Rely heavily on feedback to keep requirements in sync with code • Do not engage in extensive up-front planning • Pair programming and Test Driven Development 7
Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Map to Nirvana 1. Keep the system healthy 2. Conscientiously alternate periods 1. EXPANSION 2. CONSOLIDATION 3. Identify Seams 4. Find an inflection point 5. Cover the inflection point • Break external dependencies • Break internal dependencies 6. Write tests. 7. Make changes 8. Refactor the covered code. 8
Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Cloud Native Developer Experience
Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Yes! You can get these benefits by building Cloud Na5ve Apps on the Cloud
Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Wait! You have a por:olio of legacy applica5ons. Can they* be moved? How do we do this? * Okay, if you s5ll have apps running on an IBM System/360, they wouldn’t be the first I would move J
Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ The Prospect of Legacy Transformation Your portfolio is a complicated and poorly documented mix of many things App architecture is generally tightly coupled code and complex dependencies Your people spend their days working with legacy technology; they lack new skills
Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Approaches to App Migration 13
Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Migrating the Monolith OLD SCHOOL Measure Twice, Cut Once Detailed Application Assessment Magic Quadrant Application Suitability Static Analysis Rule Sets Questionnaires Analysis - Paralysis NEW SCHOOL Repeated smaller experiments Push app to production Test Driven Migration Replatforming Refactoring Extreme Refactoring 14
Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Traditional Ways of Transforming 16
Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Traditional Ways of Transforming Led by a Large SI on a Multi-Phase Program Always Starts with Analysis using Tools and/or Surveys Long projects with big budgets and large batches of work Results : powerpoint assessments NO running code PORTFOLIO ANALYSIS DESIGN MIGRATION TESTING ACCEPTANCE
Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Application Suitability Assessment 18
Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ App Suitability Magic Quadrants 19
Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ What We Believe • Test Driven Deployment • Work Incrementally • Failure is Okay, Experimentation Informs Strategy • Break Big Things Into Small Chunks Start With “One Thing” Keep Your Feedback Cycle as Short as Possible Automate Everything You Can (TDD, CI/ CD) Build New Skills Through Pairing and By Doing
Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Extreme Refactoring Process Scoping Inception Implementation Time Bound 10 weeks, 4 pairs ✪ ✪ Running applications ✪ ✪
Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Application Portfolio Scoping • Discovery – What is the problem we are solving – Understand App and Service composition – Broad App Technology Choices • Framing – How to Solve the Problem – Migration Flows for Java & .NET apps • Explain Baseline assumptions – App push to production – CI/CD Pipelines – Extreme Programming
Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Tools for Scoping • Contextual Enquiries • List All the APIs of an application java jdepend.textui.Jdepend spring-music-master/build | sed -n '/Summary/,$p' > <report.log> • Static Analysis Tools 1. SonarQube 2. Coverity 3. FindBugs 4. Checkstyle 5. PMD • Spring Migration Analyzer 24
Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Inception 1. Goals 2. Non Goals 3. Risks 4. Roles & Personas 5. Story Mapping 6. Estimation 7. Prioritization 8. Risks (revisited) 9. Next Steps 10. Retrospective
Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Cloud Foundry Sssh!! Let me Tell you a secret loves cloud native and non-cloud native apps is a polyglot platform (♥ Ruby, Groovy, Go, .NET, etc.)
Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Java App Replatforming Decision Tree
Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Java EE Web & Full Profile
Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Forklift Strategies q Push JavaEE Web profile apps to Java BP if they only use the servlet container + spring libraries q Push JavaEE Full profile apps to TomEE Buildpack q Create a self-contained fat jar, including the app server runtime into the app q Dockerize apps with Patterns and Recipes q Deploy app as a with BOSH release(VM/Job + Persistent disk) q Covert app to a managed service by creating a custom app-service broker 30
Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ CI/CD Pipeline Deploys to Production
Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 12 Factor App Which Factors To Sacrifice ? What Are The Problem Signs
Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 1. Codebase - MANDATORY One codebase tracked in revision control, many deploys. • Application is not in source control • Application is in source control, but it spans multiple repositories and/or version control systems. • There is no CI/CD pipeline 35 2. DEPENDENCIES - MANDATORY Explicitly declare and isolate dependencies • Application cannot be deployed as a single, cohesive unit • No Build Dependency Management System • App release artifacts works in one environment and not another • Relies on dependencies from a global context
Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 3. Configuration Store configuration in the environment. Proliferation of *.properties files (Java) Use of the Properties class (Java) Reading resources and files from disk for environment-specific settings All configuration is in the web.config and subsidiaries (.NET) Use of ConfigurationManager and related classes
Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 4. BACKING SERVICES Treat backing services as attached resources. Hard-coded (or non-environment-based) database connection strings Fixed URLs and/or ports for backing services Tight coupling with backing service type (e.g. relies on specific database driver rather than using adapters/JDBC/abstractions) Credentials for backing store embedded in configuration settings (may indicate tight environmental coupling) Backing services in Docker-to-Docker communication do not utilize Docker image linking. Relying on changes to the /etc/hosts file can be problematic in CF.
Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 5. Build, Release, Run Strictly separate build and run stages. Successful deployments to execution environment rely on the mutability of a deployment or the environment. Application fails the Configuration factor assessment. Cannot release, build, and run as separate, isolated activities.
Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 6. PROCESSES Execute the application as one or more stateless processes App is maintaining state (including session) in memory App shares data with other instances of itself (often found in home- grown HA solutions) App creates data on file system that will be used after the process terminates App is relying on Docker data volumes, which allow for data to persist outside the life cycle of the container App won’t function properly with multiple instances, or won’t function properly with multiple instances without the use of sticky sessions
Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 7. Port Binding Export services via port binding. App accepts input via non-HTTP communications protocols - JMX, Multicast, UDP, Custom TCP, RMI-IIOP Hard, fixed requirements to specific ports (e.g. app won’t start unless it is granted port 8081) App requires companion / worker / helper processes within process space or available on certain ports
Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 8. Concurrency Scale out via the process model. App cannot currently be scaled to multiple instances App cannot be scaled to multiple instances without “sticky session” routing App has huge memory requirements for scaling Reliance on, distributed App has failed the configuration and processes factors. App currently being deployed as an EAR/WAR.
Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 9. DISPOSABILITY Maximize robustness with fast startup and graceful shutdown Takes longer than 5 minutes for the application to start Terminating an application with SIGTERM can cause data loss or corruption Stopping IIS or terminating the app process/pool (.NET) can cause data loss or corruption Terminating an application takes a very long time/requires complicated coordination of resource de-allocation.
Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 10. Dev/Prod Parity Keep development, staging, and production as similar as possible. Docker containers that are pre-merged with configuration (e.g. they have a “QA Docker” and a “Prod Docker”) Prod and Dev differ to the point where app behavior varies across environments. Time gap between Dev/QA deployment and production is very long - often a symptom of large disparity between environments.
Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 11. LOGS Treat logs as event streams. Not using a unified logging solution (log4j, logback, slf4j, log4net, etc) and not using stdout for logs Custom code built into it for log aggregation and shipping rather than relying on external tools
Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Factors Not Supported • 12. Admin Processes - Run admin/management tasks as one-off processes. • Hardware Architecture & OS - Can only run applications built to for x86 or x64 systems. • Event Based Triggers - No system support of CRON or timer-based schedulers. • Background Processing, Queue Consumers and Multi Proc Apps – No native Support • Security – PAM & OS Based authentication mechanism will not work
Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Critical Features 1. Project Diego 2. CF v3 API 3. TCP Routing 4. Production Grade Persistence Services 5. Route Services 6. Context Path Routing
Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ PaaS Impediments & Remediations Anti-Cloud Pattern Remediation Multiple Inbound protocols like RMI, JMX, Custom-TCP TCP Routing, Tunneling, RMI over HTTP Persistence in local VMs like Caches, Transaction logs, CMS External managed data services, S3 Compatible blob store, mount external NFS locally, rsync, BOSH release a cf app Distributed Transactions - JTA & 2-pc commit Use standalone transaction managers like Atomikos & Bitronix . Introduce eventual consistency patterns Configuration Externalize, Plugin config via Config Server, Environment properties, System Properties, ServletInitializer that generates properties file Long Running Batch Processes CF v3 API - Different process types
Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Let Me Bring You Back From the Evil Empire 1. Get a lay of the land. Identify ALL the open source and proprietary APIs used by the app. • Make a list of all WebSphere/WebLogic/JBOSS Proprietary APIs used by your app, • Make a list of all the Java EE APIs used by your app, • Make a list of all Spring Framework APIs used the app, • Make a list of all 3rd party open source frameworks used by the app 2. Look at all the XML files bundled within the app. • Replace vendor specific deployment descriptors with TomEE descriptors or Spring Beans in Tomcat. 3. Server scoped shared libraries will need to be bundled in the app when pushed to CF.
Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Migrating from Enterprise App Servers to JBP 4. Disaggregate the EAR file into multiple war files and tie them together as one logical app. 5. Take advantage of Java EE6 and collapse EJBs and Servlets in a single war file. 6. Do not concern yourself with anything that deals with clustering, workload management, HA, smart routing or proxying. 7. Check if there is any native code and ensure that the native library is included with the app and built on the linuxfs32 file system. 8. Decide which messaging engine to use to exchange messages asynchronously. CF provides multiple JMS & AMQP messaging providers. 9. Auto-configure connections to back-end services or use spring-cloud- connectors to explicitly control the JDBC connection to the persistence tier in the cloud. 49
Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Finally Home… 10. Port JVM arguments, class path, and system properties to the buildpack and cf push manifests in Cloud Foundry. 11. Understand the external factors that affect migration like interaction with external CRM/ERP systems via XML or legacy web-service stacks. 12. If app relies on session persistence then configure session replication in CF by binding the app to a DB like Redis/Gemfire session replication on Cloud Foundry 13. http://wcmt.mybluemix.net/WMDT/#/ helps move Full WebSphere Application Server full profile applications to Liberty profile. Leverage tools like there and guides to from other app-server vendors. 14. Follow the Java App Migration Flow Chart to push the app to CF 50
Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Application Refactoring 51
Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Push 1. Push the app 2. See what fails 3. Write a test to capture the failing assert 4. Refactor app to get the tests to pass – Sacrifice some of the 12 factors – Create a story to track future refactoring 5. Modified app passes the test 6. Scrub & Repeat Pull 52 How To Refactor ? 1. Understand Bounded Contexts by whiteboarding of activity & component diagrams 2. Evaluate for 12 factor compliance. 3. Chose which components we want to tackle. 4. Rely heavily on integration tests, refactoring tools and interfaces 5. Leverage Proxy/Façade/Smart Routing pattern to create an alternate implementation 6. Run tests again pointing to the alternate endpoint 7. If tests pass get rid of the original implementation
Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Breaking the Monolith – Picking Seams • Stability and Point of Evolution • Inbound and Outbound Coupling • Tools - Xray, JDepend, Structure101 • Databases & Data Stores • Transaction Boundaries • Modes of Communication • Team Organization and Structure • Use Cases/User Journeys • Business Processes • Verbs & Operations • Nouns & Resources • Separated models for reading and writing 53
Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Monolith Decomposition Patterns 54
Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Anti-Corruption Layer 55 https://leanpub.com/Practicing-DDD
Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ STRANGLING THE MONOLITH 56
Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Inverse Conway Maneuver • Conway's Law asserts that organizations are constrained to produce application designs which are copies of their communication structures • Leads to unintended friction points. • Evolve your team and organizational structure to promote your desired architecture • Break down silos to foster collaboration • Your technology architecture will display isomorphism with your business architecture. 57
Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Adapter & Proxy Patterns 58 http://www.ibm.com/developerworks/rational/tutorials/ar-designpat1/
Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Dark Launching/Feature Flags Wrapping software features in a way that let you turn them on or off • Why ? • Private beta release • Commit your code in logical chunks • Release a new feature to all your users at a specific date • Not confident in how stable or how scalable a new feature is • How ? • Boolean – Feature will be on or off • Percentage – Certain % of Users, Cookie, Random, Group • List – User ID, Group ID, Organization ID, … • Identity – Always on! and cannot be turned off. • Nil - Always off! and cannot be turned on. • Cloud Foundry Constructs • cf scale, Configuration Server, Route Services 61
Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Migrating Data • Tools – SchemaSpy • Generate graphical representations of the relationships between tables. • Tools - Liquibase, Flyway, jooQ • Auto apply bundles of database refactorings • Require a transition period during which both the original and new schemas exist in production • Expose a Facade service to encapsulate DB changes • Move logic and constraints to the edge aka services • Implement retry and compensations • Database Transformation Patterns cataloged in “Refactoring Databases” seminal book by by Scott J Ambler and Pramod J. Sadalage 62
Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Database Repository Pattern 63
Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ JavaEE vs Spring Framework 64
Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Desirability Of Apps Moving to Cloud Foundry • Apps that are smaller than 100 MB • Apps that do NOT use Java EE 5 or below APIs • Apps that do NOT rely on a filesystem to persist across app restarts • App that bundle all their libraries within the app like Spring + external libs • Applications that do NOT leverage Distributed Transactions • Apps that start and shutdown under 3 minutes • Apps that do NOT use RMI, Multicast or other exotic TCP protocols. WebSocket is fine • Apps that do NOT require custom hardware • Apps that do NOT use app-server specific APIs or proprietary QoS • Apps that are strategic to the business with a low cost of change 65
Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 66 [email protected] http://cloud.rohitkelapure.com/ eBook: Practical Microservices: http://bit.ly/practicalmicroservices Learn More. Stay Connected. @springcentral Spring.io/video