From 256de89b45a055533650481593e026359d50c203 Mon Sep 17 00:00:00 2001 From: Kristóf Marussy Date: Fri, 17 May 2019 20:37:45 -0400 Subject: Model generator for CPS case study Added extra constraint for redundancy in CPS deployments --- .../domains/cps/generator/CpsGenerator.xtend | 96 ++++++++++++++++++++++ .../dslreasoner/domains/cps/queries/CpsQueries.vql | 10 +++ 2 files changed, 106 insertions(+) create mode 100644 Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src/hu/bme/mit/inf/dslreasoner/domains/cps/generator/CpsGenerator.xtend (limited to 'Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src/hu/bme/mit/inf/dslreasoner/domains/cps') 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 @@ +package hu.bme.mit.inf.dslreasoner.domains.cps.generator + +import hu.bme.mit.inf.dslreasoner.domains.cps.CpsFactory +import hu.bme.mit.inf.dslreasoner.domains.cps.CyberPhysicalSystem +import hu.bme.mit.inf.dslreasoner.domains.cps.HostType +import java.util.Collection +import java.util.Random + +class CpsGenerator { + extension val CpsFactory = CpsFactory.eINSTANCE + + static val MIN_MEMORY = 1 + static val MAX_MEMORY = 6 + static val MIN_HDD = 1 + static val MAX_HDD = 30 + static val HIGH_CPU_FRACTION = 4 + static val MIN_REPLICAS = 1 + static val MAX_REPLICAS = 4 + + val Random random + val int applicationTypeCount + val int demandFactor + + new(long randomSeed, int applicationTypeCount, int demandFactor) { + this.random = new Random(randomSeed) + this.applicationTypeCount = applicationTypeCount + this.demandFactor = demandFactor + } + + def generateCpsProblem() { + createCyberPhysicalSystem => [ + val cps = it + createLowCpuHostTypes + val highCpuHostTypes = createHighCpuHostTypes + for (var int i = 0; i < applicationTypeCount; i++) { + if (i % HIGH_CPU_FRACTION == 0) { + createRandomApplicationType(highCpuHostTypes) + } else { + createRandomApplicationType(hostTypes) + } + } + for (var int i = 0; i < demandFactor; i++) { + requests += createRequest => [ + for (appType : cps.applicationTypes) { + requirements += createRequirement => [ + count = nextInt(CpsGenerator.MIN_REPLICAS, CpsGenerator.MAX_REPLICAS) + type = appType + ] + } + ] + } + ] + } + + private def void createRandomApplicationType(CyberPhysicalSystem it, Collection allowedHostTypes) { + val appType = createApplicationType + val memory = nextInt(MIN_MEMORY, MAX_MEMORY) + val hdd = nextInt(MIN_HDD, MAX_HDD) + for (hostType : allowedHostTypes) { + appType.requirements += createResourceRequirement => [ + requiredMemory = memory + requiredHdd = hdd + ] + } + applicationTypes += appType + } + + private def createLowCpuHostTypes(CyberPhysicalSystem it) { + #[ + createHostType(2, 8, 75), // m5d.large + createHostType(4, 16, 150), // m5d.xlarge + createHostType(3, 16, 75), // r5d.large + createHostType(6, 32, 150) // r5d.xlarge + ] + } + + private def createHighCpuHostTypes(CyberPhysicalSystem it) { + #[ + createHostType(2, 4, 50), // c5d.large + createHostType(4, 8, 100) // c5d.xlarge + ] + } + + private def createHostType(CyberPhysicalSystem it, int cost, int memory, int hdd) { + val hostType = createHostType => [ + defaultMemory = memory + defaultHdd = hdd + ] + hostTypes += hostType + hostType + } + + private def nextInt(int lower, int upper) { + lower + random.nextInt(upper - lower + 1) + } +} 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) { check(Instances < RequiredCount); } +@Constraint(severity = "error", key = {Req}, + message = "Redundant instances must not be allocated to the same host.") +pattern redundantInstancesOnSameHost(Req : Requirement) { + Requirement.instances(Req, App1); + Requirement.instances(Req, App2); + App1 != App2; + ApplicationInstance.allocatedTo(App1, Host); + ApplicationInstance.allocatedTo(App2, Host); +} + pattern averageFreeMemoryMetric(Average : java Double) { Average == avg find freeMemoryPercentage(_, #_); } -- cgit v1.2.3-54-g00ecf