Automating Software Evolution through Model-Driven Engineering Troy University 8th Annual Computer Science Colloquium on Information Technology April 3, 2007 – Rosa Parks Auditorium SoftCom Jeff Gray UAB – CIS Department Department of Computer and Information Sciences University of Alabama at Birmingham Previous support by DARPA/IXO PCES. Current funding from NSF-CSR and NSF CAREER. Overview of Presentation Background Domain-Specific Modeling Overview of SoftCom Motivation Research Focus Video Demos Example Case Studies Model-Driven Software Evolution Software Composition and Modeling Laboratory http://www.cis.uab.edu/softcom/ Model Transformation Toolsuite • Model Transformation Engine • Transformation Testing Framework • Model Transformation Debugger • Model Version Control • Model-Driven Program Transformation Eclipse DSL Debugging Framework Robot.java and Mapping.java Robot DSL 1 2 3 4 5 6 begin left down up right end public class Robot { public static void main(String[] args) { …… //move left x=x-1; time=time+1; //move down y=y-1; time=time+1; …… 2 3 1 } } Lexer, Parser •Evolution of large legacy apps from models import java.util.ArrayList; public class Mapping { ArrayList mapping; public Mapping(){ mapping=new ArrayList(); mapping.add(new Map(1, "Robot.java",2,8)); mapping.add(new Map(2, "Robot.java",10,14)); …… } } Generated Lexer, and Parser by ANTLR Robot DSL Grammar In ANTLR Notation ESML Models DMS Transform ation Rules Variables View Debugger View 4 6 5 Mapping Component default base domain Cpp~VisualCpp6. pattern UM_GUARD_EXTERNAL_REGION_as_ identifier_or_template_id(): identifier_or_template_id = "UM__GUARD_EXTERNAL_REGION". pattern GetExternalPushLock_as_identi fier_or _te mplate_id(): identifier_or_template_id = "GetExternalPushLock". pattern ExternalLockStmt(): expression_statement = "\ DSL Editor Java Command Line Debugger void BM__PushPullComponentImpl::Update (const UUEventSet& events) { DMS BM__ComponentInstrumentation::EventConsumer(GetI d(), "Update", events); void BM__PushPullComponentImpl::Update (const UUEventSet& events) { BM__ComponentInstrumentation::EventConsumer(Ge tId(), "Update", events); unsigned int tempData1 = GetId().GetGroupId(); unsigned int tempData2 = GetId().GetItemId(); std::vector<BM__ClosedComponent*>::iterator devIter = Common/Project Library of Bold Stroke C++ Source Code Robot DSL Debugging Perspective in Eclipse UM__GUARD_EXTERNAL_REGIO N(GetExternalPushLock()); Transformed Bold Stroke C++ code Jing Zhang and Jane Lin www.cis.uab.edu/gray/Research/C-SAW/ • Framework for building debuggers and testing engines for different categories of domain-specific languages • AspectG is an aspect weaver for grammars Hui Wu www.cis.uab.edu/wuh/DDF Supported by: Eclipse Innovation Grant Software Composition and Modeling Laboratory http://www.cis.uab.edu/softcom/ Speech Enabled Software Development SpeechClipse • Assistive technology for disabled programmers • Integrates open source speech recognition with a popular open IDE • Videos and papers available at: Clone Detection and Visualization www.cis.uab.edu/info/Eclipse/SpeechClipse Language Independent Refactoring and Aspect Weaving • Visualization and analysis of clone detection results from CloneDR as an Eclipse plug-in Suman Roychoudhurry www.cis.uab.edu/softcom/GenAWeave Robert Tairas www.cis.uab.edu/tairasr/clones High School Outreach at UAB CIS Mentoring for Science Fair Competitions • Weekly mentoring at UAB throughout academic year; students treated like a PhD student with office space www.cis.uab.edu/gray/Pubs/jerrod-sutton.pdf Computer Graphics Camp • Week-long summer camp in computer graphics • Students use C++ and OpenGL to create projects focused on geometric modeling, algorithm visualization, and motion design www.cis.uab.edu/cscamp/ Summer Robotics Internship • Seven-week internship • Students taught Java through series of robotics projects www.cis.uab.edu/heritage High School Programming Contest • May 12, 2007 • 2006: 46 students from 12 schools (Huntsville to Mobile) • 6 problems in 3 hours • Prizes: Laptop, Xbox, software, books, gift certificates • Alice Film Festival! www.cis.uab.edu/progams/hspc High School Outreach at UAB CIS Field Trips to the CIS Department •3-hour tour of the CIS department: • Several topical lectures • Over 150 students in Fall 2006 • Free Pizza lunch! http://www.cis.uab.edu/field-trips Alabama K-12 Workshop • July 31, 2006; 16 statewide participants • Purpose: To discuss critical issues needed to raise awareness of computing in Alabama schools. http://www.cis.uab.edu/programs/hsws/ Lectures for Technology Clubs CIS faculty are available to give topical lectures to classes; if interested, faculty can help bootstrap a club Dual/Concurrent Enrollment • Opportunity to earn college credit in the summer by taking the CIS 201 course (Intro to Java) • 3-4 students each summer • Potential tuition waiver in some cases • Greatly speed up mentoring experience • Prepare students for programming contest next May • “Concurrent/Dual” enrollment http://www.cis.uab.edu/cs201 SpeechClipse video demo… http://www.cis.uab.edu/info/Eclipse/SpeechClipse/demo.html Domain-Specific Modeling Categories of End-Users Spreadsheet Admin Assistants Business Query Systems Businessman Auto Factory Worker Scientist Modeling Language DSL for Physics Question But what is a model? (Naïve introduction) Next Few slides adapted from Jean Bezivin…. A very popular model: geographical maps (thanks to Jean Bezivin for this idea) Models 1819 City Plan 2000 Census Map The System Aerial Map System repOf Model Road Map Every map has a legend legend = metamodel Metamodel c2 Model Another Notation (DSL) Executable Model Music notation Power Tab Editor Metamodel c2 Model Sheet music Two Views: Traditional notes Guitar tab Assisted Drawing Tools (e.g. MS/Visio) Metamodel c2 Model (thanks to Jean Bezivin for this slide) Schema definitions: Going “Meta” Domain-Specific Modeling Programming Language Definition Database Schema Definition Grammar for a specific language (e.g., Java) Table, constraint, and stored procedure definitions for a specific domain (e.g., payroll database) Schema definition Metamodel for a specific domain (e.g., Petri Net) Schema instance Domain model (e.g., Petri Net model of a teller machine) A program written in a Specific language Intension of a database at a specific instance in time (e.g., the June 2006 payroll instance) Model Interpreter Language compiler/interpreter Transactions and behavior of stored procedures in an executing application Schema execution Characteristics of Modeling Languages Each model conforms to its metamodel A model is a representation of a system satisfying substitutability For each question that can be asked of the system, the model produces the same answer Not true for me and road maps! (from Jean Bezivin) Observation “One size fits all” approach is appearing to be inadequate for many end-user needs Current trend is to provide “domain-specific” modeling languages that are customized to a specific domain Too complex and contains “kitchen sink” approach providing things most users do not need (UML) Notations and abstractions are exactly what the users expects; focused on problem space, not technology solution space But, how to create such modeling languages and environments? Expensive to create from scratch for each domain Background: Domain-Specific Modeling (cont’d) M e t a m o d e l Metamodeling Interface Environment Evolution Application Domain Application Evolution App 1 Metamodel Definition App 2 App 3 DEFINE Modeling Environment M o d e l I n t e r p r e t e r Model Builder Meta-Level Translation INTERPRET void CComponent::InvokeEx(CBuilder &buil der,CBuilderObject *focus, CBui lderObjectList &selected, long param) { CString DMSRoot = ""; DMSRoot = SelectFolder("Please Select DMS Root Folder:"); if (DMSRoot != "") { DMSRulePath = DMSRoot + RULESPATH + "Rules\\"; MSRuleApplierPath = DMSRoot + RULESPATH + "RuleApplier\\"; AfxMessageBox("DMSRulePath = " + DMSRulePath , MB_OK); CString OEPRoot = ""; OEPRoot = SelectFolder("Please Selec Model Interpretation Models Model Interpreters The Generic Modeling Environment (GME) adopts the DSM approach and provides a plug-in mechanism for extension. Example DSMLs (not UML) Model-Driven Software Evolution Model-Driven Program Transformation with C-SAW With Jane Lin and Jing Zhang Supported previously by DARPA PCES and a current NSF CSR and NSF CAREER grant. The “Twisted Plot” Metaphor The Problem of Keeping Track of Things in Your Head • The interactions among characters and Chapte r1 Chapte r2 … … Conclusion Logically Consistent? overlapping events makes a good novel (“thickness” of plot as a complexity metric) • The author must take care in preserving, throughout the entire novel, internal consistency within plot • e.g., a change in the conclusion of the plot may necessitate global changes in all chapters • Keeping track of all the twists can be difficult because the various concerns of the plot are distributed across multiple chapters • but…Software development is MANY orders of magnitude more difficult! Core Focus: Ability to evolve models The size of system models will continue to grow Models containing several hundreds or even thousands of modeling elements Others have reported similarly (Johann/Egyed – ASE 2004) A key benefit of modeling Ability to explore various design alternatives (i.e., “knobs”) E.g., understanding tradeoff between battery consumption and memory size of an embedded device E.g., scaling a model to 800 nodes to examine performance implications; reduce to 500 nodes with same analysis… Reducing complexities of the modeling activity Limit the amount of mouse clicking and typing required within a modeling tool to describe a change Improves productivity and reduces potential manual errors A general metric for determining the effectiveness of a modeling toolsuite comprises the degree of effort required to make a correct change to a set of models. Key Challenges: Crosscutting Concerns in Domain-Specific Models Challenge 1: Crosscutting Models Base models become constrained to capture a particular design Concerns that are related to some global property are dispersed across the model Multiple Levels of Hierarchy c A B d C-SAW is an aspect-oriented weaver at the modeling level d B e c d Changeability??? Changes to models must have a causal connection to underlying source Parsing large legacy systems and performing required adaptations is too difficult for each new system to be encountered Solution: Model-Driven Program Transformation e Context Sensitive Challenge 2: Fidelity Between Models and Code e c Crosscutting Constraints F B Solution: Model Weaving Replicated Structures A model interpreter generates DMS transformation rules from properties described in models Challenge 1: Solved with Aspect-Oriented Modeling Crosscutting Constraints in Real-Time/Embedded Models C-SAW: Model Transformation Engine MetaModel Defines Defines ECL Parser Modeling APIs Modeling APIs ECL Interpreter Aspect Weaving Source Model Target Model Defines CopyAtom strategy CopyAtom ECL Transformation Specifications Implemented as a GME plug-in to assist in the rapid adaptation and evolution of models by weaving crosscutting changes into models. Key Challenge 2: Evolution of legacy models and code ∆MM 1 Metamodel0 ∆MM 2 Metamodel1 Define ∆MM n Metamodeln Define Based on ∆M 1 Model0 Define ∆M 2 Model1 Interpret …… ∆M n Modeln Interpret ∆I 1 Legacy Source0 …… Interpret ∆I 2 Legacy Source1 …… ∆I n Legacy Sourcen ∆MM: The changes made to the meta-models ∆M: The changes reflected in the domain models ∆I: The changes reflected in the legacy source What about other artifacts of the modeling process during metamodel evolution? Interpreters, constraints, model transformations… Solution: Two-Level Aspect Weaving 1. Model weaving to explore design alternatives more rapidly 1 //show("Data fields exist. Add two concurrency atoms."); //add the first concurrency atom concurrencyAtom1 := addAtom("Concurrency", "InternalLock"); concurrencyAtom1.setAttribute("Enable", "1");// "1" is true, "0" is false concurrencyAtom1.setAttribute("LockType", "Thread Mutex"); concurrencyAtom1.setAttribute("LockStrategy", "Internal Locking"); //add the second concurrency atom concurrencyAtom2 := addAtom("Concurrency", "ExternalLock"); concurrencyAtom2.setAttribute("Enable", "1");// "1" is true, "0" is false concurrencyAtom2.setAttribute("LockType", "Thread Mutex"); concurrencyAtom2.setAttribute("LockStrategy", "External Locking"); Modeling Aspect GME Model • Design decisions crosscut model hierarchy • Difficult to change models to new configuration • Design decisions captured as higher level policy strategies and weaved into models 2. Model driven program transformation Weaved Model • Ensures causal connection between model changes and represented source code of legacy system • Assists in legacy evolution from new properties specified in models • Model interpreters generate transformation rules to modify source 2 DMS Xform Rules Base C++ Source Code void BM__PushPullComponentImpl::Update (const UUEventSet& events) { BM__ComponentInstrumentation::EventConsumer(GetId(), "Update", events); unsigned int tempData1 = GetId().GetGroupId(); unsigned int tempData2 = GetId().GetItemId(); std::vector<BM__ClosedComponent*>::iterator devIter = devices_.begin(); std::vector<BM__ClosedComponent*>::iterator endIter = devices_.end(); for (; devIter != endIter; ++devIter) { BM__ClosedComponent* component = *devIter; const UUIdentifier& id = component->GetId(); if (idInEventSet(id, events)) { const BM__ClosedFunctionalFacet& facet = component>ProvideClosedFunctionalFacet(); BM__ComponentInstrumentation::SendDirectCall(GetId(), "Update", component>GetId(), "GetData1"); tempData1 += facet.GetData1(); BM__ComponentInstrumentation::SendDirectCall(GetId(), "Update", component>GetId(), "GetData2"); tempData2 += facet.GetData2(); } } data1_ = tempData1; data2_ = tempData2; } 3 Transformed C++ Code void BM__PushPullComponentImpl::Update (const UUEventSet& events) { UM__GUARD_EXTERNAL_REGION(GetExternalPushLock()); BM__ComponentInstrumentation::EventConsumer(GetId(), "Update", events); unsigned int tempData1 = GetId().GetGroupId(); unsigned int tempData2 = GetId().GetItemId(); std::vector<BM__ClosedComponent*>::iterator devIter = devices_.begin(); std::vector<BM__ClosedComponent*>::iterator endIter = devices_.end(); for (; devIter != endIter; ++devIter) { BM__ClosedComponent* component = *devIter; const UUIdentifier& id = component->GetId(); if (idInEventSet(id, events)) { const BM__ClosedFunctionalFacet& facet = component->ProvideClosedFunctionalFacet(); BM__ComponentInstrumentation::SendDirectCall(GetId(), "Update", component->GetId(), "GetData1"); tempData1 += facet.GetData1(); BM__ComponentInstrumentation::SendDirectCall(GetId(), "Update", component->GetId(), "GetData2"); tempData2 += facet.GetData2(); } } UM__GUARD_INTERNAL_REGION; log.add(“data1_=”+data1_); data1_ = tempData1; data2_ = tempData2; log.add(“data2_=”+data2_); } 3. Experimentation: Boeing’s Bold Stroke Application • Apply original Bold Stroke C++ source code and generated transformation rules to DMS; result is a transformed version of Bold Stroke that is consistent with the model specification Case Study: Bold Stroke Product Line Background Context Mission-control software for Boeing military aircraft under development since 1995 (F-15/F-18) CORBA event-based systems Thousands of components implemented in over 4 million lines of C++ code Key Challenges Difficult to evolve the underlying source representation to address new requirements; impossible to determine, a priori, all of the future adaptation requests Difficult to migrate the source representation to newer component models Example: C-SAW Assertion Strategy strategy FindData1() { atoms()->select(a | a.kindOf()=="Data" and a.name()=="data1_")->AddConds(); void BM__ClosedEDComponent:: } Update(const UUEventSet& events) default base domain Cpp~VisualCpp6. { strategy AddConds() pattern assertStmt() : { statement = "assert(data1_>200);". declare p : model; declareassert(data1_>200); data, pre, post : atom; // <- Precondition pattern aspect(s:statement_seq): data := self; p := parent(); statement_seq = " \assertStmt\(\){ \s }". BM_CompInstrumentation:: patternEventConsumer(GetId(), joinpoint(id:identifier): "Update", events); pre:=p.addAtom("Condition","PrecondData1_"); unsigned int tempData1 = GetId().GetGroupId(); qualified_id = "\id :: Update". pre.setAttribute("Kind", "PreCondition"); unsigned int tempData2 = GetId().GetItemId(); pre.setAttribute("Expression", "data1_>200"); p.addConnection("AddCondition", data); rulepre, precondition(ret:decl_specifier_seq, //* REMOVED code for Real-time Event Channel id:identifier, } post:=p.addAtom("Condition", "PostcondData1_"); //* REMOVED actual variable names (proprietary) p:parameter_declaration_clause, post.setAttribute("Kind", "PostCondition"); post.setAttribute("Expression", "data1_<500"); data1_ =s:statement_seq): tempData1; p.addConnection("AddCondition", function_definition post, data); -> function_definition data2_ = tempData2; = "\ret \joinpoint \(\id\)(\p){\s}" // <- Postcondition ->assert(data1_<500); "\ret \joinpoint \(\id\)(\p){\aspect\(\s\)}" aspect Start() { if ~[modsList:statement_seq .s matches rootFolder().findFolder("ComponentTypes"). } "\:statement_seq \apect\(\modsList\)"]. models()->select(m|m.name().endWith("Impl"))->FindData1(); public ruleset applyrules = { precondition }. } Video Demonstration: C-SAW and Model-Driven Program Transformation Evolving a black-box data recorder… http://www.cis.uab.edu/gray/Research/C-SAW/video-demo.htm New Challenge: Replicating a Base Model to Address Scalability Issues Single UAV Model Three UAV Model Model Scalability Base models must be replicated to explore alternative designs Model elements need to be replicated, in addition to all required connections Example applications Event QoS Aspect Language System Integration Modeling Language Specify properties of high-performance physics experiments UAV QoS Language (not described here) Specify properties of event-based communication within a DRE (e.g., mission-computing avionics) Specify properties of video QoS in an Unmanned Aerial Vehicle A language to address performance issues among distributed systems using network patterns strategy expandSite(site, numGW : integer) { Scaling the Event QoS Aspect Language findModel("Site " + intToString(site)).addGateWay_r(1, numGW); } strategy addGateWay_r(curr, numGW : integer) { if (curr <= numGW) then addGateWay(curr); addGateWay_r(curr+1, numGW); endif; } strategy addGateWay(num : integer) { declare site_gw : atom; declare ec : model; site_gw := addAtom("CORBA_Gateway", "CORBA_Gateway" + intToString(num)); ec := findModel("Event_Channel"); addConnection("LocalGateway_EC", site_gw, ec); } Conclusion and Ongoing Work Benefits of Model-Driven Engineering Captures domain abstractions that are appropriate for an enduser; enables analysis at higher levels of abstraction Model transformations assist in evolution tasks that would be too tedious and error prone to do manually Ongoing Work Framework for testing the correctness of model transformations Model differentiation algorithms “Model Transformation by Example” Version control of models at proper abstraction level Evolution of other modeling artifacts in an automated manner Related Web Pages C-SAW http://www.cis.uab.edu/Research/C-SAW/ Contains papers, downloads, video demos K-12 Outreach Activities http://www.cis.uab.edu/gray/Outreach Contains papers, posters, and video demos SoftCom Research Lab SoftCom http://www.cis.uab.edu/softcom Department of Computer and Information Sciences University of Alabama at Birmingham Avionics Mission Computing Context Domain Forces Development Forces Embedded 100+ Distributed HRT + SRT Mission Critical Stringent performance requirements Developers Lengthy product lifecycles Component oriented Millions of SLOC 1,000s of component instances Wendy Roll, Boeing PCES-1 Focus: Simulating Joint OEP Scenario Modeling of Adaptive QoS Systems Generative technology •Adaptive Behaviors •Environmental stimulus •Middleware interfaces •Matlab and Stateflow simulations •QuO CDL Execution Synthesis Design Initial Implementations Complete for: • 1 UAV Case • 3 UAV Case (@ Demonstration) • 30 UAV Case (With Weaver)