Formal Approaches to Software Architecture http://d3s.mff.cuni.cz Jaroslav Keznikl [email protected] CHARLES UNIVERSITY IN PRAGUE faculty of mathematics and physics Referred paper Modeling and Analyzing Architectural Change with Alloy Published at: SACβ10 Klaus Marius Hansen (University of Copenhagen) Mads Ingstrup (Aarhus University) Jaroslav Keznikl, D3S Seminar, 6.4.2011 Formal Approaches to Software Architecture 2 Why should we be interested? Formalization of research ideas Position paper about modeling in Alloy My personal interest in architecture models Jaroslav Keznikl, D3S Seminar, 6.4.2011 Formal Approaches to Software Architecture 3 Goals Formal architectural model Model of architectural changes Verification of architectural properties after sequence of changes Searching for operations that produce an architecture with certain properties Automated, usable at runtime Jaroslav Keznikl, D3S Seminar, 6.4.2011 Formal Approaches to Software Architecture 4 Recall: Alloy Modeling language Sets, elements, relations, predicates in firstorder logic on the sets and relations Alloy Analyzer tool finding an instance conforming to a given specification and a predicate (run command) finding a counterexample that satisfies a given specification and violate an assertion bounded scope Jaroslav Keznikl, D3S Seminar, 6.4.2011 Formal Approaches to Software Architecture 5 Recall: Alloy Syntax Basics sig A {} sig C extends A {} sig B { p: set A } sig D { q: A->B } // A is a set // C β π΄ // p β π΅ × π(π΄) // q β π· × π΄ × B // fact { q = D->A->B } fact { all a: A | some b: B | a in b.p } pred test[a: A] { some b: B | a in b.p } fact { all a: A | test[a] | β¦ } Jaroslav Keznikl, D3S Seminar, 6.4.2011 Formal Approaches to Software Architecture 6 Recall: Alloy Syntax Basics sig A {} // A is a set sig C extends A {} // C β π΄ sig B { p: set A } // p β π΅ × π(π΄) sig D { q: A->B }All elements of A are in//theq pβrelation π· × with π΄ ×some B element of B // fact { q = D->A->B } The same as b in p.a fact { all a: A | some b: B | a in b.p } pred test[a: A] { some b: B | a in b.p } fact { all a: A | test[a] | β¦ } Jaroslav Keznikl, D3S Seminar, 6.4.2011 Formal Approaches to Software Architecture 7 Static Architecture Model Architectural configuration Closely maps to an implementation in OSGi Jaroslav Keznikl, D3S Seminar, 6.4.2011 Formal Approaches to Software Architecture 9 Modeling architectural configurations Structural model = sets and relations sig Configuration { elements: set Element } abstract sig Element {} ππππππππ β ππππ£πππ × ππππ£πππ × πΌππ‘ππππππ sig Service extends Element { bindings: Service -> Interface, provides: set Interface, requires: set Interface, started: Bool } Jaroslav Keznikl, D3S Seminar, 6.4.2011 Formal Approaches to Software Architecture 10 Modeling architectural configurations II Consistency invariants = facts on sets and relations fact { all s : Service | some s.bindings implies s.started = True all s : Service | all sβ : Service, i : Interface { sβ->i in s.bindings implies ( i in sβ.provides and i in s.requires) } } Jaroslav Keznikl, D3S Seminar, 6.4.2011 Formal Approaches to Software Architecture 11 Modeling static architectural properties Architectural style = predicate on a configuration sig RingService extends Service { next: lone RingService }{ all s : Service | s in next iff some i: Interface | s->i in bindings } pred ring_style[c: Configuration] { let ring_services = RingService & c.elements & started.True { all rs : ring_services | ring_services in rs.^next } } Jaroslav Keznikl, D3S Seminar, 6.4.2011 Formal Approaches to Software Architecture 12 Dynamic Architecture Model Architectural change Architectural operations starting/stopping of a device/service (un)deployment of a component (un)binding of an interface Architectural trace Sequence of configurations where each step is caused by an architectural operation Architectural script Jaroslav Keznikl, D3S Seminar, 6.4.2011 Formal Approaches to Software Architecture 14 Modeling architectural change Change = transition from one configuration to another Configurations become totally ordered Mutable state is related to configurations Service example: Mutable state: bindings, started sig Service extends Element { [β¦] bindings: Service->Interface->Configuration started: Bool->Configuration } Jaroslav Keznikl, D3S Seminar, 6.4.2011 Formal Approaches to Software Architecture 15 Modeling architectural change Change = transition from one configuration to another Configurations become totally ordered Mutable state is related to configurations Service example: Mutable state: bindings, started sig Service extends Element { [β¦] bindings: Service->Interface->Configuration started: Bool->Configuration } ππππππππ β ππππ£πππ × ππππ£πππ × πΌππ‘ππππππ × πΆππππππ’πππ‘πππ Jaroslav Keznikl, D3S Seminar, 6.4.2011 Formal Approaches to Software Architecture 16 Modeling architectural operations Architectural operation = a predicate on configurations pred undeploy_component[ c,cβ: Configuration, d: Device, cmp: Component ]{ // Preconditions d.started.c = True cmp in d.components.c // Postconditions d.components.cβ = d.components.c β cmp // Invariant: all other local state remains unchanged deploy_undeploy_invariant[c, cβ, d, cmp] } Jaroslav Keznikl, D3S Seminar, 6.4.2011 Formal Approaches to Software Architecture 17 Modeling architectural operations II All configuration changes allowed only through one of the operations Configurations are totally ordered fact { all c: Configuration, cβ: c.next { some d: Device | start_device[c, cβ, d] or β¦ } } Jaroslav Keznikl, D3S Seminar, 6.4.2011 Formal Approaches to Software Architecture 18 Modeling architectural traces Architectural trace = sequence of operations run example { some dev: Device, cmp: Component { let c0 = first, c1 = c0.next, c2 = c1.next { init_configuration[c0] start_device[c0, c1, dev] deploy_component[c1, c2, dev, cmp] } }} Jaroslav Keznikl, D3S Seminar, 6.4.2011 Formal Approaches to Software Architecture 19 Analyzing Architectural Change Architectural change verification Input: a configuration Cinitial, an architectural script O1,β¦,On, a predicate Pgoal Output: does the architectural script preserve the Pgoal? (if not, find a counterexample) i.e., having C0 = Cinitial, C1 = C0.next, β¦, Cn =Cn-1.next, does O1[C0,C1] and ... and On[Cn-1,Cn] implies P[Cn] hold? Idea: Employ the Alloy Analyzer, able to find a counterexample that satisfies a given specification and violates an assertion (the check command) Jaroslav Keznikl, D3S Seminar, 6.4.2011 Formal Approaches to Software Architecture 21 Architectural change verification examples Style-related properties assert script_preserves_ring_style { all d: Device, cmp: Component, rs: RingService { let c0 = first, c1 = c0.next, c2 = c1.next, c3 = c2.next { ( init_configuration[c0] and start_device[c0, c1, d] and deploy_component[c1, c2, d, cmp] and start_service[c2, c3, d, cmp, rs] ) implies ring_style[c0] and ring_style[c3] }}} General properties True, False are regular set elements assert no_device_started_and_stopped { init_configuration[first] implies all d: Device, c: first.nexts | not True + False in d.started.c } Jaroslav Keznikl, D3S Seminar, 6.4.2011 Formal Approaches to Software Architecture 22 Architectural change planning Input: a configuration Cinitial, a predicate Pgoal Output: an architectural script O1,β¦,On, that leads from Cinitial into a configuration Cgoal, where Pgoal[Cgoal] is satisfied i.e., find C0 = Cinitial, C1, β¦, Cn-1,Cn =Cgoal, such that O1[C0;C1] and ... and On[Cn-1;Cn] and P[Cn] holds. Idea: Employ the Alloy Analyzer, able to find an instance conforming to a given specification and predicate (the run command) Jaroslav Keznikl, D3S Seminar, 6.4.2011 Formal Approaches to Software Architecture 23 Architectural change planning model The operations have to be associated with configurations abstract sig Operation {} one sig None, Start_Device, β¦ extends Operation {} sig Configuration { operation: Operation } pred start_device[c, cβ: Configuration, d: Device] { [β¦] cβ.operation = Start_Device } Jaroslav Keznikl, D3S Seminar, 6.4.2011 Formal Approaches to Software Architecture 24 Architectural change planning example Alloy Analyzer finds a sequence of configurations satisfying the planning predicate pred planning_example[d: Device, cmp: Component] { // Preconditions on first configuration d.started.first = False // Postconditions on last configuration d.components.last = cmp d.started.last = True } run planning_example Jaroslav Keznikl, D3S Seminar, 6.4.2011 Formal Approaches to Software Architecture 25 Conclusion Alloy-based planning vs. AI (IPP) planning IPP: still much faster Alloy: automated, analyzable output, suitable syntax OSGi-based implementation Alloy used at runtime for correctness checking of architectural changes Jaroslav Keznikl, D3S Seminar, 6.4.2011 Formal Approaches to Software Architecture 26 Conclusion Alloy-based planning vs. AI (IPP) planning IPP: still much faster Alloy: automated, analyzable output, suitable syntax OSGi-based implementation Alloy used at runtime for correctness checking of architectural changes Jaroslav Keznikl, D3S Seminar, 6.4.2011 Formal Approaches to Software Architecture 27 Thank You Resources: Flickr/André Mouraux/Amiens cathedral Dynamic Architecture/David Fisher Flickr/Rian Castillo/Hearst tower
© Copyright 2025 Paperzz