Olivier Le Goaër [email protected] Séminaire LIRMM Montpellier, 30/09/2016 Executable modeling Executable modeling & & dynamic adaptation dynamic adaptation
Olivier Le Goaë[email protected]
Séminaire LIRMMMontpellier, 30/09/2016
Executable modeling Executable modeling &&
dynamic adaptation dynamic adaptation
2/31
A short bioA short bio
Positions● Ph.D in 2009 – AeLoS team, LINA
● Associate Professor since 2010 – MOVIES team, LIUPPA
Research topics● Software Evolution/Adaptation
● Software Architecture
● Model-Driven Engineering
Hobbies● Mobile technologies
● Web technologies
3/31
Domain-specific languages (DSL)Domain-specific languages (DSL)
General Purpose Languages● Not targeted to a particular kind of problem, but to any kinds of
software problem
Domain-Specific Languages● Targeted to a particular kind of problem
– with dedicated notations (textual or graphical), support (editor, checkers, etc.)
● Promises: more « efficient » languages for resolving a set of specific problems in a domain
● Each concern described in its own language– For software developpers (modeling, programming, querying, building,
documenting, ...), for software architects (ADL), for statisticians (R), for biologists, for sociologists, ...
4/31
Shapes for a DSLShapes for a DSL
Internal● Hosted by a
GPL
External● Stand-alone
Implicit● API-like
C# & Linq SQL Querydsl SQLJava API
QCustomer customer;customer = new QCustomer("c");
SQLQuery<?> query = new SQLQuery<Void>(connection);
List<String> lastNames = query.select(customer.lastName) .from(customer) .where(customer.firstName.eq("Bob")) .fetch();
System.out.print(lastNames);
SELECT lastNameFROM customerWHERE firstName = 'Bob';
var queryBobCustomers = from cust in customer where cust.firstName == "Bob" select cust.lastName;
foreach (var n in queryBobCustomers){ Console.WriteLine(n);}
5/31
Shapes for a DSLShapes for a DSL
Internal● Hosted by a
GPL
External● Stand-alone
Implicit● API-like
C# & Linq SQL Querydsl SQLJava API
QCustomer customer;customer = new QCustomer("c");
SQLQuery<?> query = new SQLQuery<Void>(connection);
List<String> lastNames = query.select(customer.lastName) .from(customer) .where(customer.firstName.eq("Bob")) .fetch();
System.out.print(lastNames);
SELECT lastNameFROM customerWHERE firstName = 'Bob';
var queryBobCustomers = from cust in customer where cust.firstName == "Bob" select cust.lastName;
foreach (var n in queryBobCustomers){ Console.WriteLine(n);}
6/31
Models are taking a new roleModels are taking a new role
« marauders map » – Harry Potter
Model playing a static role (design-time)
Model playing a dynamic role (run-time)
● Tells us about the structure of the castle (every classroom, every hallway, and every corner)
● Tells us about moving persons (shows foot prints)
7/31
Crossing the demarcation lineCrossing the demarcation line
Model of a system(conforms to a metamodel)
S
Running system
INTERPRETATION
Running system=
model under execution
Design-time
Run-time
COM
PILAT
ION
</xml>
sub{ }MDA ®
MM
exec(M)exec(M)
8/31
Executable modeling (xModeling)Executable modeling (xModeling)
Compilation● Translational semantics
– Code generation in a target language
Direct execution (~VM/interpreter)● Operational semantics
– Using an « action » language
– Using a M2M transformation (rare in practice)
Breathing life into models● Simulation, V&V, rapid prototyping...
● Ultimately, skip the implementation stage !
9/31
Controversies and debatesControversies and debates
Executable models "can be run, tested, debugged, and measured for performance"
UML / fUML as prominent examples● Is a class diagram executable? Alone ?
● Is a paquage diagram executable?
● Is a sequence diagram executable?
Raises the question of an executable nature● Behavior of a software system captured by a model M
● Ability to define a current execution state within M
● Ability to compute the next state (aka « step ») within M
10/31
xModeling built with MDExModeling built with MDE
Meta-models are just a specific OO data structures to represent abstract syntax trees● Operational semantics = computation steps and runtime data
● A VM/interpreter is a program working with such AST and that implements a given operational semantics
Executable metamodeling● xMOF (eXecutable MOF)
● Kermeta
● Ecore + body of operation(s) written Java/EMF
● …
11/31
xModeling's componentsxModeling's components
Abstract Syntax
Metamodel +
Well-formedness rules
Concrete Syntax
Graphical or textual
Semantics
How it behaves at runtime ?
12/31
Modeling with StatechartsModeling with Statecharts
--The instance of the finite state machine is unique (root)context StateMachine inv singleStateMachine: StateMachine.allInstances()->size() = 1 and self.container.oclIsUndefined()
--All the states are included in composites except the finite state machine herselfcontext State inv containerForAllStates: not self.oclIsTypeOf(StateMachine) implies not self.container.oclIsUndefined()
14/31
xModeling with Statecharts xModeling with Statecharts
runToCompletion()
isActive:boolean
0..1
lastKnownActiveState
-- When an history state exists and references a state, the latter must belongs to the compositecontext CompositeState inv historyInComposite: if self.historyState.oclIsUndefined() then true else if self.historyState.referencedState.oclIsUndefined() then true else self.states->includes(self.historyState.lastKnownActiveState) endif endif
15/31
xModeling with Statecharts xModeling with Statecharts
runToCompletion()
isActive:boolean
0..1
lastKnownActiveState
-- When an history state exists and references a state, the latter must belongs to the compositecontext CompositeState inv R3: if self.historyState.oclIsUndefined() then true else if self.historyState.referencedState.oclIsUndefined() then true else self.states->includes(self.historyState.lastKnownActiveState) endif endif
//operationnal semantics of UML2aspect class StateMachine { operation runToCompletion(e : Event) is do // suivre la transition trouvée en activant l'état // cible et en modifiant en conséquence la hiérarchie d'états actifs end}
//operationnal semantics of UML2aspect class StateMachine { operation runToCompletion(e : Event) is do // suivre la transition trouvée en activant l'état // cible et en modifiant en conséquence la hiérarchie d'états actifs end}
17/31
[email protected]@run.time
Overloaded term● Deals originally with software
adaptation issues at runtime
Advantage● Provides a reasoning support
on a running system
Drawback● Holding a causal link: M has to
remain the strict reflect of S
MM
SS
adaptation ?
représentation modification
Adaptationloop
18/31
[email protected] + [email protected] + xModeling
Treats the specific case where the considered running system is a model under execution
Idea : collapsing the adaptation loop● Solves the causal link issue...
● ...but the merge may leads to a burdened model M''
M
S = exec(M')S = exec(M')
adaptation ?
représentation modification S = exec(M'')
adaptation ?
modification
collapse
19/31
Non-supervised adaptation (self-*)Non-supervised adaptation (self-*)
Detect a situation requiring adaptation● Known versus unknown context (e.g. a new signal)
– Green runtime event is sometimes ignored (designer's choice at design-time)
– White runtime event is actually unknown at design-time
Perform adaptation actions● CRUD operators on any runtime data
Metamodel specialization unlocks adaptation● Model (sub)typing : adding new metaclasses and new constraints
– Adding new operations accordingly : for (a) detect and (b) perform
● Choosing the right level of specialization is tactful– Domain adaptations are rare but apply on any model instance of the metamodel
– Business adaptations are frequent but only apply on some models
20/31
Subtyped Cruise Control ModelSubtyped Cruise Control Model
completeness
tagged value
+
Consistency
22/31
Adaptable xModelingAdaptable xModeling
RunToCompletion()*
-- Each state must be associated to a transition for each identified eventcontext State def: knownEvents : Set(String) = Set{...};context State inv Completeness:self.knownEvents -> forAll( e | self.existsTransitionFor(e))
-- A transition tagged with {p, v} leads to a state also tagged with with {p, v} context StateMachine inv Consistency:......
23/31
Adaptable xModelingAdaptable xModeling
RunToCompletion()*
-- Each state must be associated to a transition for each identified eventcontext State def: knownEvents : Set(String) = Set{...};context State inv Completeness:self.knownEvents -> forAll( e | self.existsTransitionFor(e))
-- A transition tagged with {p, v} leads to a state tagged with with {p, v} context StateMachine inv Consistency:......
//adaptation operational semanticsaspect class StateMachine { operation runToCompletion(e : Event) is do if not e.isKnown() then
//introduces the new state and transitions thereofend
//same as usual (nominal behavior) end}
//adaptation operational semanticsaspect class StateMachine { operation runToCompletion(e : Event) is do if not e.isKnown() then
//introduces the new state and transitions thereofend
//same as usual (nominal behavior) end}
aspect class Event { operation isKnown() : Boolean is do //checks if an event is unknown or not end}
aspect class Event { operation isKnown() : Boolean is do //checks if an event is unknown or not end}isKnown()*
24/31
From craft to engineering with MDEFrom craft to engineering with MDE
Modeling
xModeling
AdaptablexModeling
Metamodel (static)+ [exec. translational semantics]
Metamodel (static + dynamic)+ exec. operational semantics
Metamodel (static + dynamic + adaptative) + adapt. operational semantics
25/31
Adaptation extends executionAdaptation extends execution
Execution semantics● Deals with the nominal behavior (known context)
● Operation(s) only apply on the dynamic part (the static part is on read-only mode)
Adaptation semantics● Is-a-kind-of execution semantics
● Deals with extra-ordinary situation (unknown context)
● Operation(s) may apply on all parts (static, dynamic, adaptation)
The two kinds of semantics are mixed
26/31
Implementation ChoicesImplementation Choices
Classic programming● Adaptation is tangled into execution
OO programming● Adaptation overrides execution (and calls « super »)
Contract-based programming● Adaptation occurs when a precondition of execution is violated
Aspect-oriented programming● Adaptation is woven into execution
xModeling !● Adaptation is modeled with a DSL and calls back to execution
27/31
xModeling built without MDExModeling built without MDE
PauWare engine (www.pauware.com)● Execution engine (VM) for statechart models
● Implements the complete UML2 execution semantics specification
● API written in Java (hence ported effortlessly to Android)
JavaJavaPauWare APIPauWare API
Code/xml that describes the statechart model to be loaded
Engine that executes the model loaded (« run-to-completion »)
Free implementation of the actions(called by reflection from the engine)
Consumes an event for each execution step
28/31
Android + PauWareAndroid + PauWare
SERVICEBROADCAST
RECEIVER
Android OS
AN
DR
OID
C
ON
NE C
TOR
e1/foo
e1
public void foo() { //do something}
public void bar() { //do other thing}
A statechart model
runs-to-completion
starts invokes
PauWareExecution
Engine
Java
xmiscxml
29/31
Supervised adaptationSupervised adaptation
Ability to load a new model on-the-fly● A model is just a runtime data taken as input of the engine
● Actions' implementation have to stay unchanged
SERVICE
BROADCASTRECEIVER
Android OS
AN
DR
OID
C
ON
NEC
TOR
events
runs-to-completion
starts invokes
PauWareExecution
Engine
Model Server
Google Cloud
Messaging
Push Notification
Fresh data retrieval
Adapter
e1/foo
public void foo() { //do something}
public void bar() { //do other thing}
30/31
World Wide Modeling (wwm)World Wide Modeling (wwm)
MDE-specific URI● model://host[:port]/M3/M2/M1
– model://localhost/Ecore/UML2/train
– model://localhost/Ecore/OCL/
Commands● model://host/M3?list
● model://host/M3/M2?info
● model://host/M3/M2/M1#fragment
Getting started (requires )● $> npm install wwm● JavaScript API for client-side and server-side programming