diff options
Diffstat (limited to 'Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src/hu/bme/mit/inf/dslreasoner/domains/cps/queries')
-rw-r--r-- | Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src/hu/bme/mit/inf/dslreasoner/domains/cps/queries/CpsQueries.vql | 82 |
1 files changed, 69 insertions, 13 deletions
diff --git a/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src/hu/bme/mit/inf/dslreasoner/domains/cps/queries/CpsQueries.vql b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src/hu/bme/mit/inf/dslreasoner/domains/cps/queries/CpsQueries.vql index 40337443..aa78dc38 100644 --- a/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src/hu/bme/mit/inf/dslreasoner/domains/cps/queries/CpsQueries.vql +++ b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src/hu/bme/mit/inf/dslreasoner/domains/cps/queries/CpsQueries.vql | |||
@@ -3,28 +3,23 @@ package hu.bme.mit.inf.dslreasoner.domains.cps.queries | |||
3 | import "http://www.eclipse.org/emf/2002/Ecore" | 3 | import "http://www.eclipse.org/emf/2002/Ecore" |
4 | import "http://www.example.org/cps" | 4 | import "http://www.example.org/cps" |
5 | 5 | ||
6 | @QueryBasedFeature(feature = "applications") | 6 | private pattern cpsApplications(Cps : CyberPhysicalSystem, AppInstance : ApplicationInstance) { |
7 | pattern cpsApplications(Cps : CyberPhysicalSystem, AppInstance : ApplicationInstance) { | ||
8 | CyberPhysicalSystem.applicationTypes.instances(Cps, AppInstance); | 7 | CyberPhysicalSystem.applicationTypes.instances(Cps, AppInstance); |
9 | } | 8 | } |
10 | 9 | ||
11 | @QueryBasedFeature(feature = "hosts") | 10 | private pattern cpsHosts(Cps : CyberPhysicalSystem, HostInstance : HostInstance) { |
12 | pattern cpsHosts(Cps : CyberPhysicalSystem, HostInstance : HostInstance) { | ||
13 | CyberPhysicalSystem.hostTypes.instances(Cps, HostInstance); | 11 | CyberPhysicalSystem.hostTypes.instances(Cps, HostInstance); |
14 | } | 12 | } |
15 | 13 | ||
16 | @QueryBasedFeature(feature = "totalMemory") | 14 | private pattern totalMemory(Host : HostInstance, Memory : EInt) { |
17 | pattern totalMemory(Host : HostInstance, Memory : EInt) { | ||
18 | HostInstance.type.defaultMemory(Host, Memory); | 15 | HostInstance.type.defaultMemory(Host, Memory); |
19 | } | 16 | } |
20 | 17 | ||
21 | @QueryBasedFeature(feature = "totalHdd") | 18 | private pattern totalHdd(Host : HostInstance, Hdd : EInt) { |
22 | pattern totalHdd(Host : HostInstance, Hdd : EInt) { | ||
23 | HostInstance.type.defaultHdd(Host, Hdd); | 19 | HostInstance.type.defaultHdd(Host, Hdd); |
24 | } | 20 | } |
25 | 21 | ||
26 | @QueryBasedFeature(feature = "availableMemory") | 22 | private pattern availableMemory(Host : HostInstance, Memory : java Integer) { |
27 | pattern availableMemory(Host : HostInstance, Memory : java Integer) { | ||
28 | find totalMemory(Host, TotalMemory); | 23 | find totalMemory(Host, TotalMemory); |
29 | RequiredMemory == sum find memoryRequirement(Host, _, #_); | 24 | RequiredMemory == sum find memoryRequirement(Host, _, #_); |
30 | Memory == eval(TotalMemory - RequiredMemory); | 25 | Memory == eval(TotalMemory - RequiredMemory); |
@@ -35,8 +30,7 @@ private pattern memoryRequirement(Host : HostInstance, App : ApplicationInstance | |||
35 | ResourceRequirement.requiredMemory(Req, Memory); | 30 | ResourceRequirement.requiredMemory(Req, Memory); |
36 | } | 31 | } |
37 | 32 | ||
38 | @QueryBasedFeature(feature = "availableHdd") | 33 | private pattern availableHdd(Host : HostInstance, Hdd : java Integer) { |
39 | pattern availableHdd(Host : HostInstance, Hdd : java Integer) { | ||
40 | find totalHdd(Host, TotalHdd); | 34 | find totalHdd(Host, TotalHdd); |
41 | RequiredHdd == sum find hddRequirement(Host, _, #_); | 35 | RequiredHdd == sum find hddRequirement(Host, _, #_); |
42 | Hdd == eval(TotalHdd - RequiredHdd); | 36 | Hdd == eval(TotalHdd - RequiredHdd); |
@@ -47,7 +41,7 @@ private pattern hddRequirement(Host : HostInstance, App : ApplicationInstance, H | |||
47 | ResourceRequirement.requiredHdd(Req, Hdd); | 41 | ResourceRequirement.requiredHdd(Req, Hdd); |
48 | } | 42 | } |
49 | 43 | ||
50 | private pattern resourceRequirement(Host : HostInstance, App : ApplicationInstance, Req : ResourceRequirement) { | 44 | pattern resourceRequirement(Host : HostInstance, App : ApplicationInstance, Req : ResourceRequirement) { |
51 | ApplicationInstance.allocatedTo(App, Host); | 45 | ApplicationInstance.allocatedTo(App, Host); |
52 | ApplicationInstance.type.requirements(App, Req); | 46 | ApplicationInstance.type.requirements(App, Req); |
53 | HostInstance.type(Host, HostType); | 47 | HostInstance.type(Host, HostType); |
@@ -106,6 +100,12 @@ pattern redundantInstancesOnSameHost(Req : Requirement) { | |||
106 | ApplicationInstance.allocatedTo(App2, Host); | 100 | ApplicationInstance.allocatedTo(App2, Host); |
107 | } | 101 | } |
108 | 102 | ||
103 | // | ||
104 | // Metrics | ||
105 | // | ||
106 | |||
107 | // Free memory | ||
108 | |||
109 | pattern averageFreeMemoryMetric(Average : java Double) { | 109 | pattern averageFreeMemoryMetric(Average : java Double) { |
110 | Average == avg find freeMemoryPercentage(_, #_); | 110 | Average == avg find freeMemoryPercentage(_, #_); |
111 | } | 111 | } |
@@ -116,6 +116,8 @@ private pattern freeMemoryPercentage(Host : HostInstance, Free : java Double) { | |||
116 | Free == eval((Available as double) / Total); | 116 | Free == eval((Available as double) / Total); |
117 | } | 117 | } |
118 | 118 | ||
119 | // Free HDD | ||
120 | |||
119 | pattern averageFreeHddMetric(Average : java Double) { | 121 | pattern averageFreeHddMetric(Average : java Double) { |
120 | Average == avg find freeHddPercentage(_, #_); | 122 | Average == avg find freeHddPercentage(_, #_); |
121 | } | 123 | } |
@@ -126,6 +128,8 @@ private pattern freeHddPercentage(Host : HostInstance, Free : java Double) { | |||
126 | Free == eval((Available as double) / Total); | 128 | Free == eval((Available as double) / Total); |
127 | } | 129 | } |
128 | 130 | ||
131 | // Total cost | ||
132 | |||
129 | pattern costMetric(Cost : java Integer) { | 133 | pattern costMetric(Cost : java Integer) { |
130 | Cost == sum find cpsCost(_, #_); | 134 | Cost == sum find cpsCost(_, #_); |
131 | } | 135 | } |
@@ -140,3 +144,55 @@ private pattern hostInstanceCost(Cps : CyberPhysicalSystem, Host : HostInstance, | |||
140 | find cpsHosts(Cps, Host); | 144 | find cpsHosts(Cps, Host); |
141 | HostInstance.type.cost(Host, Cost); | 145 | HostInstance.type.cost(Host, Cost); |
142 | } | 146 | } |
147 | |||
148 | // | ||
149 | // Transformation rule preconditions for rule-based DSE | ||
150 | // | ||
151 | |||
152 | pattern allocate(App : ApplicationInstance, Host : HostInstance) { | ||
153 | ApplicationInstance.type.requirements(App, Req); | ||
154 | ResourceRequirement.hostType.instances(Req, Host); | ||
155 | find unallocatedAppInstance(App); | ||
156 | find availableMemory(Host, AvailableMem); | ||
157 | find availableHdd(Host, AvailableHdd); | ||
158 | ResourceRequirement.requiredMemory(Req, RequiredMem); | ||
159 | ResourceRequirement.requiredHdd(Req, RequiredHdd); | ||
160 | check(AvailableMem >= RequiredMem); | ||
161 | check(AvailableHdd >= RequiredHdd); | ||
162 | neg ApplicationInstance.requirement.instances.allocatedTo(App, Host); | ||
163 | } | ||
164 | |||
165 | pattern unallocateAppInstance(App : ApplicationInstance) { | ||
166 | ApplicationInstance.allocatedTo(App, _); | ||
167 | } | ||
168 | |||
169 | pattern createHostInstance(HostType : HostType) { | ||
170 | find unallocatedAppInstance(App); | ||
171 | ApplicationInstance.type.requirements.hostType(App, HostType); | ||
172 | } | ||
173 | |||
174 | pattern removeHostInstance(HostInstance : HostInstance) { | ||
175 | neg HostInstance.applications(HostInstance, _); | ||
176 | } | ||
177 | |||
178 | private pattern unallocatedAppInstance(App : ApplicationInstance) { | ||
179 | neg ApplicationInstance.allocatedTo(App, _); | ||
180 | } | ||
181 | |||
182 | private pattern requiredAppInstances(Req : Requirement, Remaining : java Integer) { | ||
183 | Instances == count find satisfyingInstance(Req, _); | ||
184 | Requirement.count(Req, RequiredCount); | ||
185 | Remaining == eval(RequiredCount - Instances); | ||
186 | } | ||
187 | |||
188 | private pattern noHostToAllocateTo(App : ApplicationInstance) { | ||
189 | find unallocatedAppInstance(App); | ||
190 | neg find allocate(App, _); | ||
191 | } | ||
192 | |||
193 | pattern guidanceObjective(Value : java Integer) { | ||
194 | UnallocatedInstances == count find unallocatedAppInstance(_); | ||
195 | RequiredInstances == sum find requiredAppInstances(_, #_); | ||
196 | NoHostToAllocate == count find noHostToAllocateTo(_); | ||
197 | Value == eval(2 * UnallocatedInstances + 4 * RequiredInstances + NoHostToAllocate); | ||
198 | } | ||