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/hu/bme/mit/inf/dslreasoner/domains | |
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/hu/bme/mit/inf/dslreasoner/domains')
2 files changed, 106 insertions, 0 deletions
diff --git a/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src/hu/bme/mit/inf/dslreasoner/domains/cps/generator/CpsGenerator.xtend b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src/hu/bme/mit/inf/dslreasoner/domains/cps/generator/CpsGenerator.xtend new file mode 100644 index 00000000..0a510f0f --- /dev/null +++ b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src/hu/bme/mit/inf/dslreasoner/domains/cps/generator/CpsGenerator.xtend | |||
@@ -0,0 +1,96 @@ | |||
1 | package hu.bme.mit.inf.dslreasoner.domains.cps.generator | ||
2 | |||
3 | import hu.bme.mit.inf.dslreasoner.domains.cps.CpsFactory | ||
4 | import hu.bme.mit.inf.dslreasoner.domains.cps.CyberPhysicalSystem | ||
5 | import hu.bme.mit.inf.dslreasoner.domains.cps.HostType | ||
6 | import java.util.Collection | ||
7 | import java.util.Random | ||
8 | |||
9 | class CpsGenerator { | ||
10 | extension val CpsFactory = CpsFactory.eINSTANCE | ||
11 | |||
12 | static val MIN_MEMORY = 1 | ||
13 | static val MAX_MEMORY = 6 | ||
14 | static val MIN_HDD = 1 | ||
15 | static val MAX_HDD = 30 | ||
16 | static val HIGH_CPU_FRACTION = 4 | ||
17 | static val MIN_REPLICAS = 1 | ||
18 | static val MAX_REPLICAS = 4 | ||
19 | |||
20 | val Random random | ||
21 | val int applicationTypeCount | ||
22 | val int demandFactor | ||
23 | |||
24 | new(long randomSeed, int applicationTypeCount, int demandFactor) { | ||
25 | this.random = new Random(randomSeed) | ||
26 | this.applicationTypeCount = applicationTypeCount | ||
27 | this.demandFactor = demandFactor | ||
28 | } | ||
29 | |||
30 | def generateCpsProblem() { | ||
31 | createCyberPhysicalSystem => [ | ||
32 | val cps = it | ||
33 | createLowCpuHostTypes | ||
34 | val highCpuHostTypes = createHighCpuHostTypes | ||
35 | for (var int i = 0; i < applicationTypeCount; i++) { | ||
36 | if (i % HIGH_CPU_FRACTION == 0) { | ||
37 | createRandomApplicationType(highCpuHostTypes) | ||
38 | } else { | ||
39 | createRandomApplicationType(hostTypes) | ||
40 | } | ||
41 | } | ||
42 | for (var int i = 0; i < demandFactor; i++) { | ||
43 | requests += createRequest => [ | ||
44 | for (appType : cps.applicationTypes) { | ||
45 | requirements += createRequirement => [ | ||
46 | count = nextInt(CpsGenerator.MIN_REPLICAS, CpsGenerator.MAX_REPLICAS) | ||
47 | type = appType | ||
48 | ] | ||
49 | } | ||
50 | ] | ||
51 | } | ||
52 | ] | ||
53 | } | ||
54 | |||
55 | private def void createRandomApplicationType(CyberPhysicalSystem it, Collection<HostType> allowedHostTypes) { | ||
56 | val appType = createApplicationType | ||
57 | val memory = nextInt(MIN_MEMORY, MAX_MEMORY) | ||
58 | val hdd = nextInt(MIN_HDD, MAX_HDD) | ||
59 | for (hostType : allowedHostTypes) { | ||
60 | appType.requirements += createResourceRequirement => [ | ||
61 | requiredMemory = memory | ||
62 | requiredHdd = hdd | ||
63 | ] | ||
64 | } | ||
65 | applicationTypes += appType | ||
66 | } | ||
67 | |||
68 | private def createLowCpuHostTypes(CyberPhysicalSystem it) { | ||
69 | #[ | ||
70 | createHostType(2, 8, 75), // m5d.large | ||
71 | createHostType(4, 16, 150), // m5d.xlarge | ||
72 | createHostType(3, 16, 75), // r5d.large | ||
73 | createHostType(6, 32, 150) // r5d.xlarge | ||
74 | ] | ||
75 | } | ||
76 | |||
77 | private def createHighCpuHostTypes(CyberPhysicalSystem it) { | ||
78 | #[ | ||
79 | createHostType(2, 4, 50), // c5d.large | ||
80 | createHostType(4, 8, 100) // c5d.xlarge | ||
81 | ] | ||
82 | } | ||
83 | |||
84 | private def createHostType(CyberPhysicalSystem it, int cost, int memory, int hdd) { | ||
85 | val hostType = createHostType => [ | ||
86 | defaultMemory = memory | ||
87 | defaultHdd = hdd | ||
88 | ] | ||
89 | hostTypes += hostType | ||
90 | hostType | ||
91 | } | ||
92 | |||
93 | private def nextInt(int lower, int upper) { | ||
94 | lower + random.nextInt(upper - lower + 1) | ||
95 | } | ||
96 | } | ||
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 7f7cc5a4..40337443 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 | |||
@@ -96,6 +96,16 @@ pattern requirementNotSatisfied(Req : Requirement) { | |||
96 | check(Instances < RequiredCount); | 96 | check(Instances < RequiredCount); |
97 | } | 97 | } |
98 | 98 | ||
99 | @Constraint(severity = "error", key = {Req}, | ||
100 | message = "Redundant instances must not be allocated to the same host.") | ||
101 | pattern redundantInstancesOnSameHost(Req : Requirement) { | ||
102 | Requirement.instances(Req, App1); | ||
103 | Requirement.instances(Req, App2); | ||
104 | App1 != App2; | ||
105 | ApplicationInstance.allocatedTo(App1, Host); | ||
106 | ApplicationInstance.allocatedTo(App2, Host); | ||
107 | } | ||
108 | |||
99 | pattern averageFreeMemoryMetric(Average : java Double) { | 109 | pattern averageFreeMemoryMetric(Average : java Double) { |
100 | Average == avg find freeMemoryPercentage(_, #_); | 110 | Average == avg find freeMemoryPercentage(_, #_); |
101 | } | 111 | } |