diff options
author | Kristóf Marussy <kris7topher@gmail.com> | 2019-05-17 20:37:45 -0400 |
---|---|---|
committer | Kristóf Marussy <kris7topher@gmail.com> | 2019-05-17 20:37:45 -0400 |
commit | 256de89b45a055533650481593e026359d50c203 (patch) | |
tree | 246c6218ecafd8fcd1430eed9e31f8b5a845fb07 /Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit | |
parent | Formalize CPS case study for optimization (diff) | |
download | VIATRA-Generator-256de89b45a055533650481593e026359d50c203.tar.gz VIATRA-Generator-256de89b45a055533650481593e026359d50c203.tar.zst VIATRA-Generator-256de89b45a055533650481593e026359d50c203.zip |
Model generator for CPS case study
Added extra constraint for redundancy in CPS deployments
Diffstat (limited to 'Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit')
4 files changed, 602 insertions, 0 deletions
diff --git a/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/.gitignore b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/.gitignore index bd8f7d9f..b634f74b 100644 --- a/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/.gitignore +++ b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/.gitignore | |||
@@ -14,3 +14,4 @@ | |||
14 | /.AverageFreeHddMetric.java._trace | 14 | /.AverageFreeHddMetric.java._trace |
15 | /.CostMetric.java._trace | 15 | /.CostMetric.java._trace |
16 | /.CpsCost.java._trace | 16 | /.CpsCost.java._trace |
17 | /.RedundantInstancesOnSameHost.java._trace | ||
diff --git a/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/CpsQueries.java b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/CpsQueries.java index 4442718b..916f35f7 100644 --- a/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/CpsQueries.java +++ b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/CpsQueries.java | |||
@@ -15,6 +15,7 @@ import hu.bme.mit.inf.dslreasoner.domains.cps.queries.CpsHosts; | |||
15 | import hu.bme.mit.inf.dslreasoner.domains.cps.queries.InstanceDoesNotSatisfyRequirement; | 15 | import hu.bme.mit.inf.dslreasoner.domains.cps.queries.InstanceDoesNotSatisfyRequirement; |
16 | import hu.bme.mit.inf.dslreasoner.domains.cps.queries.NotEnoughAvailableHdd; | 16 | import hu.bme.mit.inf.dslreasoner.domains.cps.queries.NotEnoughAvailableHdd; |
17 | import hu.bme.mit.inf.dslreasoner.domains.cps.queries.NotEnoughAvailableMemory; | 17 | import hu.bme.mit.inf.dslreasoner.domains.cps.queries.NotEnoughAvailableMemory; |
18 | import hu.bme.mit.inf.dslreasoner.domains.cps.queries.RedundantInstancesOnSameHost; | ||
18 | import hu.bme.mit.inf.dslreasoner.domains.cps.queries.RequirementNotSatisfied; | 19 | import hu.bme.mit.inf.dslreasoner.domains.cps.queries.RequirementNotSatisfied; |
19 | import hu.bme.mit.inf.dslreasoner.domains.cps.queries.TotalHdd; | 20 | import hu.bme.mit.inf.dslreasoner.domains.cps.queries.TotalHdd; |
20 | import hu.bme.mit.inf.dslreasoner.domains.cps.queries.TotalMemory; | 21 | import hu.bme.mit.inf.dslreasoner.domains.cps.queries.TotalMemory; |
@@ -40,6 +41,7 @@ import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedPatternGroup; | |||
40 | * <li>notEnoughAvailableHdd</li> | 41 | * <li>notEnoughAvailableHdd</li> |
41 | * <li>instanceDoesNotSatisfyRequirement</li> | 42 | * <li>instanceDoesNotSatisfyRequirement</li> |
42 | * <li>requirementNotSatisfied</li> | 43 | * <li>requirementNotSatisfied</li> |
44 | * <li>redundantInstancesOnSameHost</li> | ||
43 | * <li>averageFreeMemoryMetric</li> | 45 | * <li>averageFreeMemoryMetric</li> |
44 | * <li>averageFreeHddMetric</li> | 46 | * <li>averageFreeHddMetric</li> |
45 | * <li>costMetric</li> | 47 | * <li>costMetric</li> |
@@ -79,6 +81,7 @@ public final class CpsQueries extends BaseGeneratedPatternGroup { | |||
79 | querySpecifications.add(NotEnoughAvailableHdd.instance()); | 81 | querySpecifications.add(NotEnoughAvailableHdd.instance()); |
80 | querySpecifications.add(InstanceDoesNotSatisfyRequirement.instance()); | 82 | querySpecifications.add(InstanceDoesNotSatisfyRequirement.instance()); |
81 | querySpecifications.add(RequirementNotSatisfied.instance()); | 83 | querySpecifications.add(RequirementNotSatisfied.instance()); |
84 | querySpecifications.add(RedundantInstancesOnSameHost.instance()); | ||
82 | querySpecifications.add(AverageFreeMemoryMetric.instance()); | 85 | querySpecifications.add(AverageFreeMemoryMetric.instance()); |
83 | querySpecifications.add(AverageFreeHddMetric.instance()); | 86 | querySpecifications.add(AverageFreeHddMetric.instance()); |
84 | querySpecifications.add(CostMetric.instance()); | 87 | querySpecifications.add(CostMetric.instance()); |
@@ -173,6 +176,14 @@ public final class CpsQueries extends BaseGeneratedPatternGroup { | |||
173 | return RequirementNotSatisfied.Matcher.on(engine); | 176 | return RequirementNotSatisfied.Matcher.on(engine); |
174 | } | 177 | } |
175 | 178 | ||
179 | public RedundantInstancesOnSameHost getRedundantInstancesOnSameHost() { | ||
180 | return RedundantInstancesOnSameHost.instance(); | ||
181 | } | ||
182 | |||
183 | public RedundantInstancesOnSameHost.Matcher getRedundantInstancesOnSameHost(final ViatraQueryEngine engine) { | ||
184 | return RedundantInstancesOnSameHost.Matcher.on(engine); | ||
185 | } | ||
186 | |||
176 | public AverageFreeMemoryMetric getAverageFreeMemoryMetric() { | 187 | public AverageFreeMemoryMetric getAverageFreeMemoryMetric() { |
177 | return AverageFreeMemoryMetric.instance(); | 188 | return AverageFreeMemoryMetric.instance(); |
178 | } | 189 | } |
diff --git a/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/RedundantInstancesOnSameHost.java b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/RedundantInstancesOnSameHost.java new file mode 100644 index 00000000..bbb55158 --- /dev/null +++ b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/RedundantInstancesOnSameHost.java | |||
@@ -0,0 +1,587 @@ | |||
1 | /** | ||
2 | * Generated from platform:/resource/hu.bme.mit.inf.dslreasoner.domains.cps/src/hu/bme/mit/inf/dslreasoner/domains/cps/queries/CpsQueries.vql | ||
3 | */ | ||
4 | package hu.bme.mit.inf.dslreasoner.domains.cps.queries; | ||
5 | |||
6 | import hu.bme.mit.inf.dslreasoner.domains.cps.Requirement; | ||
7 | import java.util.Arrays; | ||
8 | import java.util.Collection; | ||
9 | import java.util.LinkedHashSet; | ||
10 | import java.util.List; | ||
11 | import java.util.Objects; | ||
12 | import java.util.Optional; | ||
13 | import java.util.Set; | ||
14 | import java.util.function.Consumer; | ||
15 | import java.util.stream.Collectors; | ||
16 | import java.util.stream.Stream; | ||
17 | import org.apache.log4j.Logger; | ||
18 | import org.eclipse.emf.ecore.EClass; | ||
19 | import org.eclipse.viatra.query.runtime.api.IPatternMatch; | ||
20 | import org.eclipse.viatra.query.runtime.api.IQuerySpecification; | ||
21 | import org.eclipse.viatra.query.runtime.api.ViatraQueryEngine; | ||
22 | import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFPQuery; | ||
23 | import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFQuerySpecification; | ||
24 | import org.eclipse.viatra.query.runtime.api.impl.BaseMatcher; | ||
25 | import org.eclipse.viatra.query.runtime.api.impl.BasePatternMatch; | ||
26 | import org.eclipse.viatra.query.runtime.emf.types.EClassTransitiveInstancesKey; | ||
27 | import org.eclipse.viatra.query.runtime.emf.types.EStructuralFeatureInstancesKey; | ||
28 | import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint; | ||
29 | import org.eclipse.viatra.query.runtime.matchers.psystem.PBody; | ||
30 | import org.eclipse.viatra.query.runtime.matchers.psystem.PVariable; | ||
31 | import org.eclipse.viatra.query.runtime.matchers.psystem.annotations.PAnnotation; | ||
32 | import org.eclipse.viatra.query.runtime.matchers.psystem.annotations.ParameterReference; | ||
33 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.Equality; | ||
34 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExportedParameter; | ||
35 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.Inequality; | ||
36 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.TypeConstraint; | ||
37 | import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter; | ||
38 | import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameterDirection; | ||
39 | import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PVisibility; | ||
40 | import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple; | ||
41 | import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples; | ||
42 | import org.eclipse.viatra.query.runtime.util.ViatraQueryLoggingUtil; | ||
43 | |||
44 | /** | ||
45 | * A pattern-specific query specification that can instantiate Matcher in a type-safe way. | ||
46 | * | ||
47 | * <p>Original source: | ||
48 | * <code><pre> | ||
49 | * {@literal @}Constraint(severity = "error", key = {Req}, | ||
50 | * message = "Redundant instances must not be allocated to the same host.") | ||
51 | * pattern redundantInstancesOnSameHost(Req : Requirement) { | ||
52 | * Requirement.instances(Req, App1); | ||
53 | * Requirement.instances(Req, App2); | ||
54 | * App1 != App2; | ||
55 | * ApplicationInstance.allocatedTo(App1, Host); | ||
56 | * ApplicationInstance.allocatedTo(App2, Host); | ||
57 | * } | ||
58 | * </pre></code> | ||
59 | * | ||
60 | * @see Matcher | ||
61 | * @see Match | ||
62 | * | ||
63 | */ | ||
64 | @SuppressWarnings("all") | ||
65 | public final class RedundantInstancesOnSameHost extends BaseGeneratedEMFQuerySpecification<RedundantInstancesOnSameHost.Matcher> { | ||
66 | /** | ||
67 | * Pattern-specific match representation of the hu.bme.mit.inf.dslreasoner.domains.cps.queries.redundantInstancesOnSameHost pattern, | ||
68 | * to be used in conjunction with {@link Matcher}. | ||
69 | * | ||
70 | * <p>Class fields correspond to parameters of the pattern. Fields with value null are considered unassigned. | ||
71 | * Each instance is a (possibly partial) substitution of pattern parameters, | ||
72 | * usable to represent a match of the pattern in the result of a query, | ||
73 | * or to specify the bound (fixed) input parameters when issuing a query. | ||
74 | * | ||
75 | * @see Matcher | ||
76 | * | ||
77 | */ | ||
78 | public static abstract class Match extends BasePatternMatch { | ||
79 | private Requirement fReq; | ||
80 | |||
81 | private static List<String> parameterNames = makeImmutableList("Req"); | ||
82 | |||
83 | private Match(final Requirement pReq) { | ||
84 | this.fReq = pReq; | ||
85 | } | ||
86 | |||
87 | @Override | ||
88 | public Object get(final String parameterName) { | ||
89 | if ("Req".equals(parameterName)) return this.fReq; | ||
90 | return null; | ||
91 | } | ||
92 | |||
93 | public Requirement getReq() { | ||
94 | return this.fReq; | ||
95 | } | ||
96 | |||
97 | @Override | ||
98 | public boolean set(final String parameterName, final Object newValue) { | ||
99 | if (!isMutable()) throw new java.lang.UnsupportedOperationException(); | ||
100 | if ("Req".equals(parameterName) ) { | ||
101 | this.fReq = (Requirement) newValue; | ||
102 | return true; | ||
103 | } | ||
104 | return false; | ||
105 | } | ||
106 | |||
107 | public void setReq(final Requirement pReq) { | ||
108 | if (!isMutable()) throw new java.lang.UnsupportedOperationException(); | ||
109 | this.fReq = pReq; | ||
110 | } | ||
111 | |||
112 | @Override | ||
113 | public String patternName() { | ||
114 | return "hu.bme.mit.inf.dslreasoner.domains.cps.queries.redundantInstancesOnSameHost"; | ||
115 | } | ||
116 | |||
117 | @Override | ||
118 | public List<String> parameterNames() { | ||
119 | return RedundantInstancesOnSameHost.Match.parameterNames; | ||
120 | } | ||
121 | |||
122 | @Override | ||
123 | public Object[] toArray() { | ||
124 | return new Object[]{fReq}; | ||
125 | } | ||
126 | |||
127 | @Override | ||
128 | public RedundantInstancesOnSameHost.Match toImmutable() { | ||
129 | return isMutable() ? newMatch(fReq) : this; | ||
130 | } | ||
131 | |||
132 | @Override | ||
133 | public String prettyPrint() { | ||
134 | StringBuilder result = new StringBuilder(); | ||
135 | result.append("\"Req\"=" + prettyPrintValue(fReq)); | ||
136 | return result.toString(); | ||
137 | } | ||
138 | |||
139 | @Override | ||
140 | public int hashCode() { | ||
141 | return Objects.hash(fReq); | ||
142 | } | ||
143 | |||
144 | @Override | ||
145 | public boolean equals(final Object obj) { | ||
146 | if (this == obj) | ||
147 | return true; | ||
148 | if (obj == null) { | ||
149 | return false; | ||
150 | } | ||
151 | if ((obj instanceof RedundantInstancesOnSameHost.Match)) { | ||
152 | RedundantInstancesOnSameHost.Match other = (RedundantInstancesOnSameHost.Match) obj; | ||
153 | return Objects.equals(fReq, other.fReq); | ||
154 | } else { | ||
155 | // this should be infrequent | ||
156 | if (!(obj instanceof IPatternMatch)) { | ||
157 | return false; | ||
158 | } | ||
159 | IPatternMatch otherSig = (IPatternMatch) obj; | ||
160 | return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray()); | ||
161 | } | ||
162 | } | ||
163 | |||
164 | @Override | ||
165 | public RedundantInstancesOnSameHost specification() { | ||
166 | return RedundantInstancesOnSameHost.instance(); | ||
167 | } | ||
168 | |||
169 | /** | ||
170 | * Returns an empty, mutable match. | ||
171 | * Fields of the mutable match can be filled to create a partial match, usable as matcher input. | ||
172 | * | ||
173 | * @return the empty match. | ||
174 | * | ||
175 | */ | ||
176 | public static RedundantInstancesOnSameHost.Match newEmptyMatch() { | ||
177 | return new Mutable(null); | ||
178 | } | ||
179 | |||
180 | /** | ||
181 | * Returns a mutable (partial) match. | ||
182 | * Fields of the mutable match can be filled to create a partial match, usable as matcher input. | ||
183 | * | ||
184 | * @param pReq the fixed value of pattern parameter Req, or null if not bound. | ||
185 | * @return the new, mutable (partial) match object. | ||
186 | * | ||
187 | */ | ||
188 | public static RedundantInstancesOnSameHost.Match newMutableMatch(final Requirement pReq) { | ||
189 | return new Mutable(pReq); | ||
190 | } | ||
191 | |||
192 | /** | ||
193 | * Returns a new (partial) match. | ||
194 | * This can be used e.g. to call the matcher with a partial match. | ||
195 | * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. | ||
196 | * @param pReq the fixed value of pattern parameter Req, or null if not bound. | ||
197 | * @return the (partial) match object. | ||
198 | * | ||
199 | */ | ||
200 | public static RedundantInstancesOnSameHost.Match newMatch(final Requirement pReq) { | ||
201 | return new Immutable(pReq); | ||
202 | } | ||
203 | |||
204 | private static final class Mutable extends RedundantInstancesOnSameHost.Match { | ||
205 | Mutable(final Requirement pReq) { | ||
206 | super(pReq); | ||
207 | } | ||
208 | |||
209 | @Override | ||
210 | public boolean isMutable() { | ||
211 | return true; | ||
212 | } | ||
213 | } | ||
214 | |||
215 | private static final class Immutable extends RedundantInstancesOnSameHost.Match { | ||
216 | Immutable(final Requirement pReq) { | ||
217 | super(pReq); | ||
218 | } | ||
219 | |||
220 | @Override | ||
221 | public boolean isMutable() { | ||
222 | return false; | ||
223 | } | ||
224 | } | ||
225 | } | ||
226 | |||
227 | /** | ||
228 | * Generated pattern matcher API of the hu.bme.mit.inf.dslreasoner.domains.cps.queries.redundantInstancesOnSameHost pattern, | ||
229 | * providing pattern-specific query methods. | ||
230 | * | ||
231 | * <p>Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)}, | ||
232 | * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}. | ||
233 | * | ||
234 | * <p>Matches of the pattern will be represented as {@link Match}. | ||
235 | * | ||
236 | * <p>Original source: | ||
237 | * <code><pre> | ||
238 | * {@literal @}Constraint(severity = "error", key = {Req}, | ||
239 | * message = "Redundant instances must not be allocated to the same host.") | ||
240 | * pattern redundantInstancesOnSameHost(Req : Requirement) { | ||
241 | * Requirement.instances(Req, App1); | ||
242 | * Requirement.instances(Req, App2); | ||
243 | * App1 != App2; | ||
244 | * ApplicationInstance.allocatedTo(App1, Host); | ||
245 | * ApplicationInstance.allocatedTo(App2, Host); | ||
246 | * } | ||
247 | * </pre></code> | ||
248 | * | ||
249 | * @see Match | ||
250 | * @see RedundantInstancesOnSameHost | ||
251 | * | ||
252 | */ | ||
253 | public static class Matcher extends BaseMatcher<RedundantInstancesOnSameHost.Match> { | ||
254 | /** | ||
255 | * Initializes the pattern matcher within an existing VIATRA Query engine. | ||
256 | * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. | ||
257 | * | ||
258 | * @param engine the existing VIATRA Query engine in which this matcher will be created. | ||
259 | * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation | ||
260 | * | ||
261 | */ | ||
262 | public static RedundantInstancesOnSameHost.Matcher on(final ViatraQueryEngine engine) { | ||
263 | // check if matcher already exists | ||
264 | Matcher matcher = engine.getExistingMatcher(querySpecification()); | ||
265 | if (matcher == null) { | ||
266 | matcher = (Matcher)engine.getMatcher(querySpecification()); | ||
267 | } | ||
268 | return matcher; | ||
269 | } | ||
270 | |||
271 | /** | ||
272 | * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation | ||
273 | * @return an initialized matcher | ||
274 | * @noreference This method is for internal matcher initialization by the framework, do not call it manually. | ||
275 | * | ||
276 | */ | ||
277 | public static RedundantInstancesOnSameHost.Matcher create() { | ||
278 | return new Matcher(); | ||
279 | } | ||
280 | |||
281 | private static final int POSITION_REQ = 0; | ||
282 | |||
283 | private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(RedundantInstancesOnSameHost.Matcher.class); | ||
284 | |||
285 | /** | ||
286 | * Initializes the pattern matcher within an existing VIATRA Query engine. | ||
287 | * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. | ||
288 | * | ||
289 | * @param engine the existing VIATRA Query engine in which this matcher will be created. | ||
290 | * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation | ||
291 | * | ||
292 | */ | ||
293 | private Matcher() { | ||
294 | super(querySpecification()); | ||
295 | } | ||
296 | |||
297 | /** | ||
298 | * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters. | ||
299 | * @param pReq the fixed value of pattern parameter Req, or null if not bound. | ||
300 | * @return matches represented as a Match object. | ||
301 | * | ||
302 | */ | ||
303 | public Collection<RedundantInstancesOnSameHost.Match> getAllMatches(final Requirement pReq) { | ||
304 | return rawStreamAllMatches(new Object[]{pReq}).collect(Collectors.toSet()); | ||
305 | } | ||
306 | |||
307 | /** | ||
308 | * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters. | ||
309 | * </p> | ||
310 | * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed. | ||
311 | * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>. | ||
312 | * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. | ||
313 | * @param pReq the fixed value of pattern parameter Req, or null if not bound. | ||
314 | * @return a stream of matches represented as a Match object. | ||
315 | * | ||
316 | */ | ||
317 | public Stream<RedundantInstancesOnSameHost.Match> streamAllMatches(final Requirement pReq) { | ||
318 | return rawStreamAllMatches(new Object[]{pReq}); | ||
319 | } | ||
320 | |||
321 | /** | ||
322 | * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. | ||
323 | * Neither determinism nor randomness of selection is guaranteed. | ||
324 | * @param pReq the fixed value of pattern parameter Req, or null if not bound. | ||
325 | * @return a match represented as a Match object, or null if no match is found. | ||
326 | * | ||
327 | */ | ||
328 | public Optional<RedundantInstancesOnSameHost.Match> getOneArbitraryMatch(final Requirement pReq) { | ||
329 | return rawGetOneArbitraryMatch(new Object[]{pReq}); | ||
330 | } | ||
331 | |||
332 | /** | ||
333 | * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match, | ||
334 | * under any possible substitution of the unspecified parameters (if any). | ||
335 | * @param pReq the fixed value of pattern parameter Req, or null if not bound. | ||
336 | * @return true if the input is a valid (partial) match of the pattern. | ||
337 | * | ||
338 | */ | ||
339 | public boolean hasMatch(final Requirement pReq) { | ||
340 | return rawHasMatch(new Object[]{pReq}); | ||
341 | } | ||
342 | |||
343 | /** | ||
344 | * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters. | ||
345 | * @param pReq the fixed value of pattern parameter Req, or null if not bound. | ||
346 | * @return the number of pattern matches found. | ||
347 | * | ||
348 | */ | ||
349 | public int countMatches(final Requirement pReq) { | ||
350 | return rawCountMatches(new Object[]{pReq}); | ||
351 | } | ||
352 | |||
353 | /** | ||
354 | * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. | ||
355 | * Neither determinism nor randomness of selection is guaranteed. | ||
356 | * @param pReq the fixed value of pattern parameter Req, or null if not bound. | ||
357 | * @param processor the action that will process the selected match. | ||
358 | * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked | ||
359 | * | ||
360 | */ | ||
361 | public boolean forOneArbitraryMatch(final Requirement pReq, final Consumer<? super RedundantInstancesOnSameHost.Match> processor) { | ||
362 | return rawForOneArbitraryMatch(new Object[]{pReq}, processor); | ||
363 | } | ||
364 | |||
365 | /** | ||
366 | * Returns a new (partial) match. | ||
367 | * This can be used e.g. to call the matcher with a partial match. | ||
368 | * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. | ||
369 | * @param pReq the fixed value of pattern parameter Req, or null if not bound. | ||
370 | * @return the (partial) match object. | ||
371 | * | ||
372 | */ | ||
373 | public RedundantInstancesOnSameHost.Match newMatch(final Requirement pReq) { | ||
374 | return RedundantInstancesOnSameHost.Match.newMatch(pReq); | ||
375 | } | ||
376 | |||
377 | /** | ||
378 | * Retrieve the set of values that occur in matches for Req. | ||
379 | * @return the Set of all values or empty set if there are no matches | ||
380 | * | ||
381 | */ | ||
382 | protected Stream<Requirement> rawStreamAllValuesOfReq(final Object[] parameters) { | ||
383 | return rawStreamAllValues(POSITION_REQ, parameters).map(Requirement.class::cast); | ||
384 | } | ||
385 | |||
386 | /** | ||
387 | * Retrieve the set of values that occur in matches for Req. | ||
388 | * @return the Set of all values or empty set if there are no matches | ||
389 | * | ||
390 | */ | ||
391 | public Set<Requirement> getAllValuesOfReq() { | ||
392 | return rawStreamAllValuesOfReq(emptyArray()).collect(Collectors.toSet()); | ||
393 | } | ||
394 | |||
395 | /** | ||
396 | * Retrieve the set of values that occur in matches for Req. | ||
397 | * @return the Set of all values or empty set if there are no matches | ||
398 | * | ||
399 | */ | ||
400 | public Stream<Requirement> streamAllValuesOfReq() { | ||
401 | return rawStreamAllValuesOfReq(emptyArray()); | ||
402 | } | ||
403 | |||
404 | @Override | ||
405 | protected RedundantInstancesOnSameHost.Match tupleToMatch(final Tuple t) { | ||
406 | try { | ||
407 | return RedundantInstancesOnSameHost.Match.newMatch((Requirement) t.get(POSITION_REQ)); | ||
408 | } catch(ClassCastException e) { | ||
409 | LOGGER.error("Element(s) in tuple not properly typed!",e); | ||
410 | return null; | ||
411 | } | ||
412 | } | ||
413 | |||
414 | @Override | ||
415 | protected RedundantInstancesOnSameHost.Match arrayToMatch(final Object[] match) { | ||
416 | try { | ||
417 | return RedundantInstancesOnSameHost.Match.newMatch((Requirement) match[POSITION_REQ]); | ||
418 | } catch(ClassCastException e) { | ||
419 | LOGGER.error("Element(s) in array not properly typed!",e); | ||
420 | return null; | ||
421 | } | ||
422 | } | ||
423 | |||
424 | @Override | ||
425 | protected RedundantInstancesOnSameHost.Match arrayToMatchMutable(final Object[] match) { | ||
426 | try { | ||
427 | return RedundantInstancesOnSameHost.Match.newMutableMatch((Requirement) match[POSITION_REQ]); | ||
428 | } catch(ClassCastException e) { | ||
429 | LOGGER.error("Element(s) in array not properly typed!",e); | ||
430 | return null; | ||
431 | } | ||
432 | } | ||
433 | |||
434 | /** | ||
435 | * @return the singleton instance of the query specification of this pattern | ||
436 | * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded | ||
437 | * | ||
438 | */ | ||
439 | public static IQuerySpecification<RedundantInstancesOnSameHost.Matcher> querySpecification() { | ||
440 | return RedundantInstancesOnSameHost.instance(); | ||
441 | } | ||
442 | } | ||
443 | |||
444 | private RedundantInstancesOnSameHost() { | ||
445 | super(GeneratedPQuery.INSTANCE); | ||
446 | } | ||
447 | |||
448 | /** | ||
449 | * @return the singleton instance of the query specification | ||
450 | * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded | ||
451 | * | ||
452 | */ | ||
453 | public static RedundantInstancesOnSameHost instance() { | ||
454 | try{ | ||
455 | return LazyHolder.INSTANCE; | ||
456 | } catch (ExceptionInInitializerError err) { | ||
457 | throw processInitializerError(err); | ||
458 | } | ||
459 | } | ||
460 | |||
461 | @Override | ||
462 | protected RedundantInstancesOnSameHost.Matcher instantiate(final ViatraQueryEngine engine) { | ||
463 | return RedundantInstancesOnSameHost.Matcher.on(engine); | ||
464 | } | ||
465 | |||
466 | @Override | ||
467 | public RedundantInstancesOnSameHost.Matcher instantiate() { | ||
468 | return RedundantInstancesOnSameHost.Matcher.create(); | ||
469 | } | ||
470 | |||
471 | @Override | ||
472 | public RedundantInstancesOnSameHost.Match newEmptyMatch() { | ||
473 | return RedundantInstancesOnSameHost.Match.newEmptyMatch(); | ||
474 | } | ||
475 | |||
476 | @Override | ||
477 | public RedundantInstancesOnSameHost.Match newMatch(final Object... parameters) { | ||
478 | return RedundantInstancesOnSameHost.Match.newMatch((hu.bme.mit.inf.dslreasoner.domains.cps.Requirement) parameters[0]); | ||
479 | } | ||
480 | |||
481 | /** | ||
482 | * Inner class allowing the singleton instance of {@link JvmGenericType: hu.bme.mit.inf.dslreasoner.domains.cps.queries.RedundantInstancesOnSameHost (visibility: PUBLIC, simpleName: RedundantInstancesOnSameHost, identifier: hu.bme.mit.inf.dslreasoner.domains.cps.queries.RedundantInstancesOnSameHost, deprecated: <unset>) (abstract: false, static: false, final: true, packageName: hu.bme.mit.inf.dslreasoner.domains.cps.queries) (interface: false, strictFloatingPoint: false, anonymous: false)} to be created | ||
483 | * <b>not</b> at the class load time of the outer class, | ||
484 | * but rather at the first call to {@link JvmGenericType: hu.bme.mit.inf.dslreasoner.domains.cps.queries.RedundantInstancesOnSameHost (visibility: PUBLIC, simpleName: RedundantInstancesOnSameHost, identifier: hu.bme.mit.inf.dslreasoner.domains.cps.queries.RedundantInstancesOnSameHost, deprecated: <unset>) (abstract: false, static: false, final: true, packageName: hu.bme.mit.inf.dslreasoner.domains.cps.queries) (interface: false, strictFloatingPoint: false, anonymous: false)#instance()}. | ||
485 | * | ||
486 | * <p> This workaround is required e.g. to support recursion. | ||
487 | * | ||
488 | */ | ||
489 | private static class LazyHolder { | ||
490 | private static final RedundantInstancesOnSameHost INSTANCE = new RedundantInstancesOnSameHost(); | ||
491 | |||
492 | /** | ||
493 | * Statically initializes the query specification <b>after</b> the field {@link #INSTANCE} is assigned. | ||
494 | * This initialization order is required to support indirect recursion. | ||
495 | * | ||
496 | * <p> The static initializer is defined using a helper field to work around limitations of the code generator. | ||
497 | * | ||
498 | */ | ||
499 | private static final Object STATIC_INITIALIZER = ensureInitialized(); | ||
500 | |||
501 | public static Object ensureInitialized() { | ||
502 | INSTANCE.ensureInitializedInternal(); | ||
503 | return null; | ||
504 | } | ||
505 | } | ||
506 | |||
507 | private static class GeneratedPQuery extends BaseGeneratedEMFPQuery { | ||
508 | private static final RedundantInstancesOnSameHost.GeneratedPQuery INSTANCE = new GeneratedPQuery(); | ||
509 | |||
510 | private final PParameter parameter_Req = new PParameter("Req", "hu.bme.mit.inf.dslreasoner.domains.cps.Requirement", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.example.org/cps", "Requirement")), PParameterDirection.INOUT); | ||
511 | |||
512 | private final List<PParameter> parameters = Arrays.asList(parameter_Req); | ||
513 | |||
514 | private GeneratedPQuery() { | ||
515 | super(PVisibility.PUBLIC); | ||
516 | } | ||
517 | |||
518 | @Override | ||
519 | public String getFullyQualifiedName() { | ||
520 | return "hu.bme.mit.inf.dslreasoner.domains.cps.queries.redundantInstancesOnSameHost"; | ||
521 | } | ||
522 | |||
523 | @Override | ||
524 | public List<String> getParameterNames() { | ||
525 | return Arrays.asList("Req"); | ||
526 | } | ||
527 | |||
528 | @Override | ||
529 | public List<PParameter> getParameters() { | ||
530 | return parameters; | ||
531 | } | ||
532 | |||
533 | @Override | ||
534 | public Set<PBody> doGetContainedBodies() { | ||
535 | setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED)); | ||
536 | Set<PBody> bodies = new LinkedHashSet<>(); | ||
537 | { | ||
538 | PBody body = new PBody(this); | ||
539 | PVariable var_Req = body.getOrCreateVariableByName("Req"); | ||
540 | PVariable var_App1 = body.getOrCreateVariableByName("App1"); | ||
541 | PVariable var_App2 = body.getOrCreateVariableByName("App2"); | ||
542 | PVariable var_Host = body.getOrCreateVariableByName("Host"); | ||
543 | new TypeConstraint(body, Tuples.flatTupleOf(var_Req), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "Requirement"))); | ||
544 | body.setSymbolicParameters(Arrays.<ExportedParameter>asList( | ||
545 | new ExportedParameter(body, var_Req, parameter_Req) | ||
546 | )); | ||
547 | // Requirement.instances(Req, App1) | ||
548 | new TypeConstraint(body, Tuples.flatTupleOf(var_Req), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "Requirement"))); | ||
549 | PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}"); | ||
550 | new TypeConstraint(body, Tuples.flatTupleOf(var_Req, var__virtual_0_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.example.org/cps", "Requirement", "instances"))); | ||
551 | new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "ApplicationInstance"))); | ||
552 | new Equality(body, var__virtual_0_, var_App1); | ||
553 | // Requirement.instances(Req, App2) | ||
554 | new TypeConstraint(body, Tuples.flatTupleOf(var_Req), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "Requirement"))); | ||
555 | PVariable var__virtual_1_ = body.getOrCreateVariableByName(".virtual{1}"); | ||
556 | new TypeConstraint(body, Tuples.flatTupleOf(var_Req, var__virtual_1_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.example.org/cps", "Requirement", "instances"))); | ||
557 | new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_1_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "ApplicationInstance"))); | ||
558 | new Equality(body, var__virtual_1_, var_App2); | ||
559 | // App1 != App2 | ||
560 | new Inequality(body, var_App1, var_App2); | ||
561 | // ApplicationInstance.allocatedTo(App1, Host) | ||
562 | new TypeConstraint(body, Tuples.flatTupleOf(var_App1), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "ApplicationInstance"))); | ||
563 | PVariable var__virtual_2_ = body.getOrCreateVariableByName(".virtual{2}"); | ||
564 | new TypeConstraint(body, Tuples.flatTupleOf(var_App1, var__virtual_2_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.example.org/cps", "ApplicationInstance", "allocatedTo"))); | ||
565 | new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_2_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "HostInstance"))); | ||
566 | new Equality(body, var__virtual_2_, var_Host); | ||
567 | // ApplicationInstance.allocatedTo(App2, Host) | ||
568 | new TypeConstraint(body, Tuples.flatTupleOf(var_App2), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "ApplicationInstance"))); | ||
569 | PVariable var__virtual_3_ = body.getOrCreateVariableByName(".virtual{3}"); | ||
570 | new TypeConstraint(body, Tuples.flatTupleOf(var_App2, var__virtual_3_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.example.org/cps", "ApplicationInstance", "allocatedTo"))); | ||
571 | new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_3_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.example.org/cps", "HostInstance"))); | ||
572 | new Equality(body, var__virtual_3_, var_Host); | ||
573 | bodies.add(body); | ||
574 | } | ||
575 | { | ||
576 | PAnnotation annotation = new PAnnotation("Constraint"); | ||
577 | annotation.addAttribute("severity", "error"); | ||
578 | annotation.addAttribute("key", Arrays.asList(new Object[] { | ||
579 | new ParameterReference("Req") | ||
580 | })); | ||
581 | annotation.addAttribute("message", "Redundant instances must not be allocated to the same host."); | ||
582 | addAnnotation(annotation); | ||
583 | } | ||
584 | return bodies; | ||
585 | } | ||
586 | } | ||
587 | } | ||
diff --git a/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/internal/CpsQueriesAll.java b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/internal/CpsQueriesAll.java index 5f6d161d..58b113eb 100644 --- a/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/internal/CpsQueriesAll.java +++ b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src-gen/hu/bme/mit/inf/dslreasoner/domains/cps/queries/internal/CpsQueriesAll.java | |||
@@ -15,6 +15,7 @@ import hu.bme.mit.inf.dslreasoner.domains.cps.queries.CpsHosts; | |||
15 | import hu.bme.mit.inf.dslreasoner.domains.cps.queries.InstanceDoesNotSatisfyRequirement; | 15 | import hu.bme.mit.inf.dslreasoner.domains.cps.queries.InstanceDoesNotSatisfyRequirement; |
16 | import hu.bme.mit.inf.dslreasoner.domains.cps.queries.NotEnoughAvailableHdd; | 16 | import hu.bme.mit.inf.dslreasoner.domains.cps.queries.NotEnoughAvailableHdd; |
17 | import hu.bme.mit.inf.dslreasoner.domains.cps.queries.NotEnoughAvailableMemory; | 17 | import hu.bme.mit.inf.dslreasoner.domains.cps.queries.NotEnoughAvailableMemory; |
18 | import hu.bme.mit.inf.dslreasoner.domains.cps.queries.RedundantInstancesOnSameHost; | ||
18 | import hu.bme.mit.inf.dslreasoner.domains.cps.queries.RequirementNotSatisfied; | 19 | import hu.bme.mit.inf.dslreasoner.domains.cps.queries.RequirementNotSatisfied; |
19 | import hu.bme.mit.inf.dslreasoner.domains.cps.queries.TotalHdd; | 20 | import hu.bme.mit.inf.dslreasoner.domains.cps.queries.TotalHdd; |
20 | import hu.bme.mit.inf.dslreasoner.domains.cps.queries.TotalMemory; | 21 | import hu.bme.mit.inf.dslreasoner.domains.cps.queries.TotalMemory; |
@@ -48,6 +49,7 @@ import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedPatternGroup; | |||
48 | * <li>instanceDoesNotSatisfyRequirement</li> | 49 | * <li>instanceDoesNotSatisfyRequirement</li> |
49 | * <li>satisfyingInstance</li> | 50 | * <li>satisfyingInstance</li> |
50 | * <li>requirementNotSatisfied</li> | 51 | * <li>requirementNotSatisfied</li> |
52 | * <li>redundantInstancesOnSameHost</li> | ||
51 | * <li>averageFreeMemoryMetric</li> | 53 | * <li>averageFreeMemoryMetric</li> |
52 | * <li>freeMemoryPercentage</li> | 54 | * <li>freeMemoryPercentage</li> |
53 | * <li>averageFreeHddMetric</li> | 55 | * <li>averageFreeHddMetric</li> |
@@ -94,6 +96,7 @@ public final class CpsQueriesAll extends BaseGeneratedPatternGroup { | |||
94 | querySpecifications.add(InstanceDoesNotSatisfyRequirement.instance()); | 96 | querySpecifications.add(InstanceDoesNotSatisfyRequirement.instance()); |
95 | querySpecifications.add(SatisfyingInstance.instance()); | 97 | querySpecifications.add(SatisfyingInstance.instance()); |
96 | querySpecifications.add(RequirementNotSatisfied.instance()); | 98 | querySpecifications.add(RequirementNotSatisfied.instance()); |
99 | querySpecifications.add(RedundantInstancesOnSameHost.instance()); | ||
97 | querySpecifications.add(AverageFreeMemoryMetric.instance()); | 100 | querySpecifications.add(AverageFreeMemoryMetric.instance()); |
98 | querySpecifications.add(FreeMemoryPercentage.instance()); | 101 | querySpecifications.add(FreeMemoryPercentage.instance()); |
99 | querySpecifications.add(AverageFreeHddMetric.instance()); | 102 | querySpecifications.add(AverageFreeHddMetric.instance()); |