) = block(context)
64 | }
65 | }
66 | }
67 |
--------------------------------------------------------------------------------
/opendc-core/src/main/kotlin/com/atlarge/opendc/simulator/Entity.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * MIT License
3 | *
4 | * Copyright (c) 2017 atlarge-research
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in all
14 | * copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | * SOFTWARE.
23 | */
24 |
25 | package com.atlarge.opendc.simulator
26 |
27 | /**
28 | * An entity in some model `M`.
29 | *
30 | * A [Entity] directly contains its immutable properties that remain unchanged during simulation.
31 | *
32 | *
In addition, other entities in simulation have direct, immutable access to the observable state of this entity.
33 | *
34 | * @param S The shape of the observable state of this entity, which is directly accessible by other components within
35 | * a simulation.
36 | * @author Fabian Mastenbroek (f.s.mastenbroek@student.tudelft.nl)
37 | */
38 | interface Entity {
39 | /**
40 | * The initial state of the entity.
41 | */
42 | val initialState: S
43 | }
44 |
--------------------------------------------------------------------------------
/opendc-core/src/main/kotlin/com/atlarge/opendc/simulator/Process.kt:
--------------------------------------------------------------------------------
1 | package com.atlarge.opendc.simulator
2 |
3 | /**
4 | * A process is dynamic entity within a simulation, that interacts with the model environment by the interchange of
5 | * messages.
6 | *
7 | * @param S The shape of the observable state of the process.
8 | * @param M The shape of the model in which the process exists.
9 | * @author Fabian Mastenbroek (f.s.mastenbroek@student.tudelft.nl)
10 | */
11 | interface Process : Entity {
12 | /**
13 | * This method is invoked to start the simulation a process.
14 | *
15 | * This method is assumed to be running during a simulation, but should hand back control to the simulator at
16 | * some point by suspending the process. This allows other processes to do work at the current point in time of the
17 | * simulation.
18 | * Suspending the process can be achieved by calling suspending method in the context:
19 | * - [Context.hold] - Hold for `n` units of time before resuming execution.
20 | * - [Context.receive] - Wait for a message to be received in the mailbox of the [Entity] before resuming
21 | * execution.
22 | *
23 | * If this method exits early, before the simulation has finished, the entity is assumed to be shutdown and its
24 | * simulation will not run any further.
25 | */
26 | suspend fun Context.run()
27 | }
28 |
--------------------------------------------------------------------------------
/opendc-core/src/main/kotlin/com/atlarge/opendc/simulator/Time.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * MIT License
3 | *
4 | * Copyright (c) 2017 atlarge-research
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in all
14 | * copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | * SOFTWARE.
23 | */
24 |
25 | package com.atlarge.opendc.simulator
26 |
27 | /**
28 | * An instantaneous point on the time-line, used to record event time-stamps in a simulation.
29 | */
30 | typealias Instant = Long
31 |
32 | /**
33 | * A time interval which represents the amount of elapsed time between two events.
34 | */
35 | typealias Duration = Long
36 |
--------------------------------------------------------------------------------
/opendc-core/src/main/kotlin/com/atlarge/opendc/simulator/instrumentation/Instrument.kt:
--------------------------------------------------------------------------------
1 | package com.atlarge.opendc.simulator.instrumentation
2 |
3 | import com.atlarge.opendc.simulator.Context
4 | import com.atlarge.opendc.simulator.Entity
5 | import kotlinx.coroutines.experimental.channels.ReceiveChannel
6 | import kotlinx.coroutines.experimental.channels.SendChannel
7 |
8 | /**
9 | * A kernel instrumentation device that allows the observation and measurement of properties of interest within some
10 | * model.
11 | *
12 | * An instrument is a [Process] that emits measurements from within some model in the form of a typed stream. An
13 | * instrument is attached to a simulation using the [Port.install] method, which returns a [ReceiveChannel] from
14 | * which the measurements can be extracted out of the simulation.
15 | *
16 | * @author Fabian Mastenbroek (f.s.mastenbroek@student.tudelft.nl)
17 | */
18 | typealias Instrument = suspend InstrumentScope.() -> Unit
19 |
20 | /**
21 | * This interface defines the scope in which an instrumentation device is built.
22 | *
23 | * An instrument is a [Process] without any observable state that is allowed to send messages to other [Entity]
24 | * instances in the simulation. In addition, the instrument can emit measurements using the methods provided by the
25 | * [SendChannel] interface.
26 | *
27 | * @author Fabian Mastenbroek (f.s.mastenbroek@student.tudelft.nl)
28 | */
29 | interface InstrumentScope: SendChannel, Context
30 |
--------------------------------------------------------------------------------
/opendc-core/src/main/kotlin/com/atlarge/opendc/simulator/instrumentation/Port.kt:
--------------------------------------------------------------------------------
1 | package com.atlarge.opendc.simulator.instrumentation
2 |
3 | import com.atlarge.opendc.simulator.kernel.Simulation
4 | import kotlinx.coroutines.experimental.channels.Channel
5 | import kotlinx.coroutines.experimental.channels.ReceiveChannel
6 |
7 | /**
8 | * A port allows users to install instrumentation devices to a [Simulation].
9 | *
10 | * @author Fabian Mastenbroek (f.s.mastenbroek@student.tudelft.nl)
11 | */
12 | interface Port {
13 | /**
14 | * Install the given instrumentation device to produce a stream of measurements of type T
.
15 | *
16 | * The [ReceiveChannel] returned by this channel is by default backed by an unlimited buffer
17 | * (using [Channel.UNLIMITED]), which may induce unnecessary overhead.
18 | *
19 | * @param instrument The instrumentation device to install.
20 | * @return A [ReceiveChannel] to which the of measurements produced by the instrument are published.
21 | */
22 | fun install(instrument: Instrument): ReceiveChannel = install(Channel.UNLIMITED, instrument)
23 |
24 | /**
25 | * Install the given instrumentation device to produce a stream of measurements of type code>T.
26 | *
27 | * @param capacity The capacity of the buffer of the channel.
28 | * @param instrument The instrumentation device to install.
29 | * @return A [ReceiveChannel] to which the of measurements produced by the instrument are published.
30 | */
31 | fun install(capacity: Int, instrument: Instrument): ReceiveChannel
32 |
33 | /**
34 | * Close this port and stop the instruments from producing more measurements.
35 | * This is an idempotent operation – repeated invocations of this function have no effect and return false.
36 | *
37 | * @param cause An optional cause that is thrown when trying to receive more elements from the installed
38 | * instruments.
39 | * @return `true` if the port was closed, `false` if it was already closed.
40 | */
41 | fun close(cause: Throwable? = null): Boolean
42 | }
43 |
--------------------------------------------------------------------------------
/opendc-core/src/main/kotlin/com/atlarge/opendc/simulator/kernel/Kernel.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * MIT License
3 | *
4 | * Copyright (c) 2017 atlarge-research
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in all
14 | * copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | * SOFTWARE.
23 | */
24 |
25 | package com.atlarge.opendc.simulator.kernel
26 |
27 | import com.atlarge.opendc.simulator.Bootstrap
28 |
29 | /**
30 | * A message-based discrete event simulator (DES). This interface is a factory for creating [Simulation]s using the
31 | * provided [Bootstrap] for the model.
32 | *
33 | * @author Fabian Mastenbroek (f.s.mastenbroek@student.tudelft.nl)
34 | */
35 | interface Kernel {
36 | /**
37 | * Create a simulation over the given model facilitated by this simulation kernel.
38 | *
39 | * @param bootstrap The apply procedure to apply the simulation with.
40 | * @return A [Simulation] instance representing the simulation.
41 | */
42 | fun create(bootstrap: Bootstrap): Simulation
43 | }
44 |
--------------------------------------------------------------------------------
/opendc-core/src/main/kotlin/com/atlarge/opendc/simulator/kernel/Simulation.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * MIT License
3 | *
4 | * Copyright (c) 2017 atlarge-research
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in all
14 | * copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | * SOFTWARE.
23 | */
24 |
25 | package com.atlarge.opendc.simulator.kernel
26 |
27 | import com.atlarge.opendc.simulator.Entity
28 | import com.atlarge.opendc.simulator.Instant
29 | import com.atlarge.opendc.simulator.instrumentation.Instrument
30 | import com.atlarge.opendc.simulator.instrumentation.Port
31 |
32 | /**
33 | * A message based discrete event simulation over some model `M`. This interface provides direct control over the
34 | * simulation, allowing the user to step over cycles of the simulation and inspecting the state of the simulation via
35 | * [Entity.state].
36 | *
37 | * @param M The shape of the model over which the simulation runs.
38 | * @author Fabian Mastenbroek (f.s.mastenbroek@student.tudelft.nl)
39 | */
40 | interface Simulation {
41 | /**
42 | * The model in which the simulation runs.
43 | */
44 | val model: M
45 |
46 | /**
47 | * The simulation time.
48 | */
49 | var time: Instant
50 |
51 | /**
52 | * The observable state of an [Entity] in simulation, which is provided by the simulation context.
53 | */
54 | val , S> E.state: S
55 |
56 | /**
57 | * Open a new [Port] to manage [Instrument]s.
58 | *
59 | * @return A new [Port] instance to install [Instrument]s to.
60 | */
61 | fun openPort(): Port
62 |
63 | /**
64 | * Step through one cycle in the simulation. This method will process all events in a single tick, update the
65 | * internal clock and then return the control to the user.
66 | *
67 | * This method will throw if a process running during the cycle throws an exception.
68 | */
69 | fun step()
70 |
71 | /**
72 | * Run a simulation over the specified model.
73 | * This method will step through multiple cycles in the simulation until no more message exist in the queue.
74 | *
75 | * This method will throw if a process running during a cycle throws an exception.
76 | */
77 | fun run()
78 |
79 | /**
80 | * Run a simulation over the specified model, stepping through cycles until the specified clock tick has
81 | * occurred. The control is then handed back to the user.
82 | *
83 | * This method will throw if a process running during a cycle throws an exception.
84 | *
85 | * @param until The point in simulation time at which the simulation should be paused and the control is handed
86 | * back to the user.
87 | */
88 | fun run(until: Instant)
89 | }
90 |
--------------------------------------------------------------------------------
/opendc-core/src/main/kotlin/com/atlarge/opendc/simulator/platform/Experiment.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * MIT License
3 | *
4 | * Copyright (c) 2017 atlarge-research
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in all
14 | * copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | * SOFTWARE.
23 | */
24 |
25 | package com.atlarge.opendc.simulator.platform
26 |
27 | import com.atlarge.opendc.simulator.Duration
28 | import com.atlarge.opendc.simulator.kernel.Kernel
29 |
30 | /**
31 | * A blueprint for a reproducible simulation in a pre-defined setting.
32 | *
33 | * @author Fabian Mastenbroek (f.s.mastenbroek@student.tudelft.nl)
34 | */
35 | interface Experiment {
36 | /**
37 | * Run the experiment on the specified kernel implementation.
38 | *
39 | * @param factory The factory to create the simulation kernel with.
40 | * @return The result of the experiment.
41 | */
42 | fun run(factory: Kernel): T
43 |
44 | /**
45 | * Run the experiment on the specified kernel implementation.
46 | *
47 | * @param factory The factory to create the simulation kernel with.
48 | * @param timeout The maximum duration of the experiment before returning to the caller.
49 | * @return The result of the experiment or `null`.
50 | */
51 | fun run(factory: Kernel, timeout: Duration): T?
52 | }
53 |
--------------------------------------------------------------------------------
/opendc-kernel-omega/build.gradle:
--------------------------------------------------------------------------------
1 | /*
2 | * MIT License
3 | *
4 | * Copyright (c) 2017 atlarge-research
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in all
14 | * copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | * SOFTWARE.
23 | */
24 |
25 | /* Build configuration */
26 | apply from: '../gradle/kotlin.gradle'
27 | apply plugin: 'java-library'
28 |
29 | /* Project configuration */
30 | repositories {
31 | jcenter()
32 | }
33 |
34 | dependencies {
35 | implementation "org.jetbrains.kotlin:kotlin-stdlib"
36 |
37 | api project(':opendc-core')
38 | implementation "io.github.microutils:kotlin-logging:1.4.6"
39 |
40 | testImplementation "org.junit.jupiter:junit-jupiter-api:$junit_jupiter_version"
41 | testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:$junit_jupiter_version"
42 | testImplementation "org.junit.platform:junit-platform-launcher:$junit_platform_version"
43 | testRuntimeOnly "org.slf4j:slf4j-simple:1.7.25"
44 | }
45 |
--------------------------------------------------------------------------------
/opendc-kernel-omega/src/main/kotlin/com/atlarge/opendc/omega/Messages.kt:
--------------------------------------------------------------------------------
1 | package com.atlarge.opendc.omega
2 |
3 | import com.atlarge.opendc.simulator.Context
4 | import com.atlarge.opendc.simulator.Process
5 |
6 | /**
7 | * An internal message used by the Omega simulation kernel to indicate to a suspended [Process], that it should wake up
8 | * and resume execution.
9 | *
10 | * This message is not guaranteed to work on other simulation kernels and [Context.interrupt] should be preferred to
11 | * wake up a process from another entity.
12 | *
13 | * @author Fabian Mastenbroek (f.s.mastenbroek@student.tudelft.nl)
14 | */
15 | object Resume
16 |
17 | /**
18 | * An internal message used by the Omega simulation kernel to indicate to a suspended [Process], that a timeout has been
19 | * reached and that it should wake up and resume execution.
20 | *
21 | * @author Fabian Mastenbroek (f.s.mastenbroek@student.tudelft.nl)
22 | */
23 | object Timeout
24 |
25 | /**
26 | * An internal message used by the Omega simulation kernel to launch a process.
27 | *
28 | * @author Fabian Mastenbroek (f.s.mastenbroek@student.tudelft.nl)
29 | */
30 | data class Launch(val process: Process<*, M>)
31 |
--------------------------------------------------------------------------------
/opendc-kernel-omega/src/main/kotlin/com/atlarge/opendc/omega/OmegaKernel.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * MIT License
3 | *
4 | * Copyright (c) 2017 atlarge-research
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in all
14 | * copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | * SOFTWARE.
23 | */
24 |
25 | package com.atlarge.opendc.omega
26 |
27 | import com.atlarge.opendc.simulator.Bootstrap
28 | import com.atlarge.opendc.simulator.kernel.Kernel
29 | import com.atlarge.opendc.simulator.kernel.Simulation
30 |
31 | /**
32 | * The Omega simulation kernel is the reference simulation kernel implementation for the OpenDC Simulator core.
33 | *
34 | * This simulator implementation is a single-threaded implementation, running simulation kernels synchronously and
35 | * provides a single priority queue for all events (messages, ticks, etc) that occur in the entities.
36 | *
37 | * @author Fabian Mastenbroek (f.s.mastenbroek@student.tudelft.nl)
38 | */
39 | object OmegaKernel : Kernel {
40 | /**
41 | * Create a simulation over the given model facilitated by this simulation kernel.
42 | *
43 | * @param bootstrap The apply procedure to apply the simulation with.
44 | * @return A [Simulation] instance to control the simulation.
45 | */
46 | override fun create(bootstrap: Bootstrap): Simulation = OmegaSimulation(bootstrap)
47 | }
48 |
--------------------------------------------------------------------------------
/opendc-kernel-omega/src/test/kotlin/com/atlarge/opendc/omega/ProcessTest.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * MIT License
3 | *
4 | * Copyright (c) 2018 atlarge-research
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in all
14 | * copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | * SOFTWARE.
23 | */
24 |
25 | package com.atlarge.opendc.omega
26 |
27 | import com.atlarge.opendc.simulator.Bootstrap
28 | import com.atlarge.opendc.simulator.Context
29 | import com.atlarge.opendc.simulator.Process
30 | import org.junit.jupiter.api.Test
31 | import kotlin.coroutines.experimental.suspendCoroutine
32 |
33 | /**
34 | * A test suite for processes in simulation.
35 | *
36 | * @author Fabian Mastenbroek (f.s.mastenbroek@student.tudelft.nl)
37 | */
38 | internal class ProcessTest {
39 | object FreezeProcess : Process {
40 | override val initialState = Unit
41 | override suspend fun Context.run() {
42 | receive()
43 | suspendCoroutine {}
44 | }
45 | }
46 |
47 | /**
48 | * Test whether the simulation will not resume an already resumed continuation
49 | * of a process.
50 | */
51 | @Test
52 | fun `simulation will not resume frozen process`() {
53 | val bootstrap: Bootstrap = Bootstrap.create { ctx ->
54 | ctx.start(FreezeProcess)
55 | ctx.schedule("Hello", destination = FreezeProcess, delay = 1)
56 | ctx.schedule("Hello", destination = FreezeProcess, delay = 1)
57 | }
58 | val simulation = OmegaKernel.create(bootstrap)
59 | simulation.run()
60 | }
61 | }
62 |
--------------------------------------------------------------------------------
/opendc-model-odc/core/build.gradle:
--------------------------------------------------------------------------------
1 | /*
2 | * MIT License
3 | *
4 | * Copyright (c) 2017 atlarge-research
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in all
14 | * copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | * SOFTWARE.
23 | */
24 |
25 | /* Build configuration */
26 | apply from: '../../gradle/kotlin.gradle'
27 | apply plugin: 'java-library'
28 |
29 | /* Project configuration */
30 | repositories {
31 | jcenter()
32 | }
33 |
34 | dependencies {
35 | implementation "org.jetbrains.kotlin:kotlin-stdlib"
36 |
37 | api project(':opendc-core')
38 | api project(':opendc-stdlib')
39 | implementation "io.github.microutils:kotlin-logging:1.4.6"
40 |
41 | testImplementation "org.junit.jupiter:junit-jupiter-api:$junit_jupiter_version"
42 | testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:$junit_jupiter_version"
43 | testImplementation "org.junit.platform:junit-platform-launcher:$junit_platform_version"
44 | testRuntimeOnly "org.slf4j:slf4j-simple:1.7.25"
45 | }
46 |
--------------------------------------------------------------------------------
/opendc-model-odc/core/src/main/kotlin/com/atlarge/opendc/model/odc/OdcModel.kt:
--------------------------------------------------------------------------------
1 | package com.atlarge.opendc.model.odc
2 |
3 | import com.atlarge.opendc.model.topology.MutableTopology
4 |
5 | /**
6 | * The OpenDC standard simulation model used for datacenter simulations.
7 | *
8 | * @author Fabian Mastenbroek (f.s.mastenbroek@student.tudelft.nl)
9 | */
10 | interface OdcModel : MutableTopology
11 |
--------------------------------------------------------------------------------
/opendc-model-odc/core/src/main/kotlin/com/atlarge/opendc/model/odc/platform/scheduler/Scheduler.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * MIT License
3 | *
4 | * Copyright (c) 2017 atlarge-research
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in all
14 | * copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | * SOFTWARE.
23 | */
24 |
25 | package com.atlarge.opendc.model.odc.platform.scheduler
26 |
27 | import com.atlarge.opendc.model.odc.OdcModel
28 | import com.atlarge.opendc.model.odc.platform.workload.Task
29 | import com.atlarge.opendc.model.odc.topology.machine.Machine
30 | import com.atlarge.opendc.simulator.Process
31 | import com.atlarge.opendc.simulator.util.EventBus
32 |
33 | /**
34 | * A cloud scheduler interface that schedules tasks across machines.
35 | *
36 | * @param S The shape of the state of the scheduler.
37 | * @author Fabian Mastenbroek (f.s.mastenbroek@student.tudelft.nl)
38 | */
39 | interface Scheduler : Process {
40 | /**
41 | * The name of this scheduler.
42 | */
43 | val name: String
44 |
45 | /**
46 | * The event bus of the scheduler.
47 | */
48 | val bus: EventBus
49 |
50 | /**
51 | * This message is sent to a scheduler to indicate a scheduling cycle.
52 | *
53 | * @property tasks The new tasks that should be added to the queue.
54 | */
55 | data class Schedule(val tasks: Set)
56 |
57 | /**
58 | * This message is sent to a scheduler to introduce new resources and release old resources.
59 | *
60 | * @property registered The new machines that have been registered to the datacenter.
61 | * @property unregistered The machines that have been unregistered.
62 | */
63 | data class Resources(val registered: Set, val unregistered: Set)
64 | }
65 |
66 |
--------------------------------------------------------------------------------
/opendc-model-odc/core/src/main/kotlin/com/atlarge/opendc/model/odc/platform/scheduler/stages/StageMeasurement.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * MIT License
3 | *
4 | * Copyright (c) 2018 atlarge-research
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in all
14 | * copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | * SOFTWARE.
23 | */
24 |
25 | package com.atlarge.opendc.model.odc.platform.scheduler.stages
26 |
27 | import com.atlarge.opendc.simulator.Instant
28 | import java.lang.management.ManagementFactory
29 |
30 | /**
31 | * The measurements related to a single stage in the scheduler.
32 | *
33 | * @property stage The identifier of the stage.
34 | * @property time The point in time at which the measurement occurred.
35 | * @property cpu The duration in cpu time (ns) of the stage.
36 | * @property wall The duration in wall time (ns) of the stage.
37 | * @property size The total size of the input of the stage.
38 | * @property iterations The amount of iterations in the stage.
39 | */
40 | data class StageMeasurement(val stage: Int,
41 | val time: Instant,
42 | val cpu: Long,
43 | val wall: Long,
44 | val size: Int,
45 | val iterations: Int)
46 |
47 | /**
48 | * A class that accumulates and manages the measurements of the stages.
49 | *
50 | * @property time The point in simulation time at which the measurements occur.
51 | * @property size The input size of the scheduler.
52 | */
53 | class StageMeasurementAccumulator(val time: Instant, val size: Int) {
54 | /**
55 | * A collection of measurements that have been collected during the runtime of the continuation.
56 | */
57 | val measurements: MutableList = mutableListOf()
58 |
59 | /**
60 | * The MXBean to measure cpu time.
61 | */
62 | val bean = ManagementFactory.getThreadMXBean()
63 |
64 | /**
65 | * Measure the initial cpu time
66 | */
67 | private var cpuStart = -1L
68 |
69 | /**
70 | * Measure the initial wall time.
71 | */
72 | private var wallStart = -1L
73 |
74 | /**
75 | * Start the accumulation of measurements.
76 | */
77 | fun start() {
78 | measurements.clear()
79 | cpuStart = bean.currentThreadUserTime
80 | wallStart = System.nanoTime()
81 | }
82 |
83 | /**
84 | * End the accumulation of measurements.
85 | */
86 | fun end() {
87 | val cpu = bean.currentThreadUserTime - cpuStart - measurements.map { it.cpu }.sum()
88 | val wall = System.nanoTime() - wallStart - measurements.map { it.wall }.sum()
89 | val measurement = StageMeasurement(measurements.size + 1, time, cpu, wall, size, 1)
90 | measurements.add(measurement)
91 | }
92 |
93 | /**
94 | * Measure the duration of a stage.
95 | *
96 | * @param stage The identifier of the stage.
97 | * @param input The size of the input.
98 | * @param block The block to measure.
99 | */
100 | inline fun runStage(stage: Int, input: Int, block: () -> R): R {
101 | val cpuStart = bean.currentThreadUserTime
102 | val wallStart = System.nanoTime()
103 |
104 | val res = block()
105 |
106 | val cpu = bean.currentThreadUserTime - cpuStart
107 | val wall = System.nanoTime() - wallStart
108 |
109 | val previous = if (stage - 1 < measurements.size) measurements[stage - 1] else null
110 | if (previous != null) {
111 | measurements[stage - 1] = StageMeasurement(stage, time, cpu + previous.cpu, wall + previous.wall, input + previous.size, previous.iterations + 1)
112 | } else {
113 | measurements.add(StageMeasurement(stage, time, cpu, wall, input, 1))
114 | }
115 |
116 | return res
117 | }
118 | }
119 |
--------------------------------------------------------------------------------
/opendc-model-odc/core/src/main/kotlin/com/atlarge/opendc/model/odc/platform/scheduler/stages/machine/Filtering.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * MIT License
3 | *
4 | * Copyright (c) 2018 atlarge-research
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in all
14 | * copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | * SOFTWARE.
23 | */
24 |
25 | package com.atlarge.opendc.model.odc.platform.scheduler.stages.machine
26 |
27 | import com.atlarge.opendc.model.odc.OdcModel
28 | import com.atlarge.opendc.model.odc.platform.scheduler.StageScheduler
29 | import com.atlarge.opendc.model.odc.platform.workload.Task
30 | import com.atlarge.opendc.model.odc.topology.machine.Machine
31 | import com.atlarge.opendc.simulator.context
32 |
33 | /**
34 | * This interface represents the **R4** stage of the Reference Architecture for Schedulers and acts as a filter yielding
35 | * a list of resources with sufficient resource-capacities, based on fixed or dynamic requirements, and on predicted or
36 | * monitored information about processing unit availability, memory occupancy, etc.
37 | */
38 | interface MachineDynamicFilteringPolicy {
39 | /**
40 | * Filter the list of machines based on dynamic information.
41 | *
42 | * @param machines The list of machines in the system.
43 | * @param task The task that is to be scheduled.
44 | * @return The machines on which the task can be scheduled.
45 | */
46 | suspend fun filter(machines: Set, task: Task): List
47 | }
48 |
49 | /**
50 | * A [MachineDynamicFilteringPolicy] based on the amount of cores available on the machine and the cores required for
51 | * the task.
52 | */
53 | class FunctionalMachineDynamicFilteringPolicy : MachineDynamicFilteringPolicy {
54 | override suspend fun filter(machines: Set, task: Task): List =
55 | context().run {
56 | machines
57 | .filter { state.machineCores[it] ?: 0 >= task.cores }
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/opendc-model-odc/core/src/main/kotlin/com/atlarge/opendc/model/odc/platform/scheduler/stages/task/Filtering.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * MIT License
3 | *
4 | * Copyright (c) 2018 atlarge-research
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in all
14 | * copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | * SOFTWARE.
23 | */
24 |
25 | package com.atlarge.opendc.model.odc.platform.scheduler.stages.task
26 |
27 | import com.atlarge.opendc.model.odc.platform.workload.Task
28 |
29 | /**
30 | * This interface represents the **T1** stage of the Reference Architecture for Schedulers and provides the scheduler
31 | * with a list of eligible tasks to be scheduled.
32 | */
33 | interface TaskEligibilityFilteringPolicy {
34 | /**
35 | * Filter the list of tasks provided as input, based on a filter-policy, e.g. a policy that allows
36 | * tasks to pass through only if their dependencies have already finished.
37 | *
38 | * @param queue The list of tasks that are ready to be scheduled.
39 | * @return The tasks that are allowed to be scheduled.
40 | */
41 | suspend fun filter(queue: Set): List
42 | }
43 |
44 | /**
45 | * The [FunctionalTaskEligibilityFilteringPolicy] filters tasks based on whether their dependencies have finished running.
46 | */
47 | class FunctionalTaskEligibilityFilteringPolicy : TaskEligibilityFilteringPolicy {
48 | override suspend fun filter(queue: Set): List = queue.filter { it.ready }
49 | }
50 |
--------------------------------------------------------------------------------
/opendc-model-odc/core/src/main/kotlin/com/atlarge/opendc/model/odc/platform/workload/Job.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * MIT License
3 | *
4 | * Copyright (c) 2017 atlarge-research
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in all
14 | * copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | * SOFTWARE.
23 | */
24 |
25 | package com.atlarge.opendc.model.odc.platform.workload
26 |
27 | /**
28 | * A bag of tasks which are submitted by a [User] to the cloud network.
29 | *
30 | * @author Fabian Mastenbroek (f.s.mastenbroek@student.tudelft.nl)
31 | */
32 | interface Job {
33 | /**
34 | * A unique identifier of the job.
35 | */
36 | val id: Int
37 |
38 | /**
39 | * The owner of this job.
40 | */
41 | val owner: User
42 |
43 | /**
44 | * The tasks this job consists of.
45 | */
46 | val tasks: Set
47 |
48 | /**
49 | * A flag to indicate the job has finished.
50 | */
51 | val finished: Boolean
52 | get() = tasks.all { it.finished }
53 | }
54 |
55 | /**
56 | * Create a topological sorting of the tasks in a job.
57 | *
58 | * @return The list of tasks within the job topologically sorted.
59 | */
60 | fun Job.toposort(): List {
61 | val res = mutableListOf()
62 | val visited = mutableSetOf()
63 | val adjacent = mutableMapOf>()
64 |
65 | for (task in tasks) {
66 | for (dependency in task.dependencies) {
67 | adjacent.getOrPut(dependency) { mutableListOf() }.add(task)
68 | }
69 | }
70 |
71 | fun visit(task: Task) {
72 | visited.add(task)
73 |
74 | adjacent[task] ?: emptyList()
75 | .asSequence()
76 | .filter { it !in visited }
77 | .forEach { visit(it) }
78 |
79 | res.add(task)
80 | }
81 |
82 | tasks
83 | .asSequence()
84 | .filter { it !in visited }
85 | .forEach { visit(it) }
86 | return res
87 | }
88 |
--------------------------------------------------------------------------------
/opendc-model-odc/core/src/main/kotlin/com/atlarge/opendc/model/odc/platform/workload/Task.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * MIT License
3 | *
4 | * Copyright (c) 2017 atlarge-research
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in all
14 | * copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | * SOFTWARE.
23 | */
24 |
25 | package com.atlarge.opendc.model.odc.platform.workload
26 |
27 | import com.atlarge.opendc.model.odc.topology.machine.Machine
28 | import com.atlarge.opendc.simulator.Instant
29 |
30 | /**
31 | * A task that runs as part of a [Job] on a [Machine].
32 | *
33 | * @author Fabian Mastenbroek (f.s.mastenbroek@student.tudelft.nl)
34 | */
35 | interface Task {
36 | /**
37 | * The unique identifier of the task.
38 | */
39 | val id: Int
40 |
41 | /**
42 | * The ID of the owner of the task
43 | */
44 | val owner_id: Int
45 |
46 | /**
47 | * The priority of the task.
48 | */
49 | val priority: Int
50 |
51 | /**
52 | * The amount of flops for this task.
53 | */
54 | val flops: Long
55 |
56 | /**
57 | * The dependencies of the task.
58 | */
59 | val dependencies: Set
60 |
61 | /**
62 | * Set of tasks that are dependent on this task.
63 | */
64 | val dependents: Set
65 |
66 | /**
67 | * The amount of cores required for running the task.
68 | */
69 | val cores: Int
70 |
71 | /**
72 | * The remaining flops for this task.
73 | */
74 | val remaining: Long
75 |
76 | /**
77 | * The input size, i.e. required input data.
78 | */
79 | val inputSize: Long
80 |
81 | /**
82 | * The output size.
83 | */
84 | val outputSize: Long
85 |
86 | /**
87 | * The state of the task.
88 | */
89 | val state: TaskState
90 |
91 | /**
92 | * A flag to indicate whether the task is ready to be started.
93 | */
94 | val ready: Boolean
95 | get() = dependencies.all { it.finished }
96 |
97 | /**
98 | * A flag to indicate whether the task has finished.
99 | */
100 | val finished: Boolean
101 | get() = state is TaskState.Finished
102 |
103 | /**
104 | * This method is invoked when a task has arrived at a datacenter.
105 | *
106 | * @param time The moment in time the task has arrived at the datacenter.
107 | */
108 | fun arrive(time: Instant)
109 |
110 | /**
111 | * Consume the given amount of flops of this task.
112 | *
113 | * @param time The current moment in time of the consumption.
114 | * @param flops The total amount of flops to consume.
115 | */
116 | fun consume(time: Instant, flops: Long)
117 | }
118 |
119 |
--------------------------------------------------------------------------------
/opendc-model-odc/core/src/main/kotlin/com/atlarge/opendc/model/odc/platform/workload/TaskState.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * MIT License
3 | *
4 | * Copyright (c) 2017 atlarge-research
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in all
14 | * copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | * SOFTWARE.
23 | */
24 |
25 | package com.atlarge.opendc.model.odc.platform.workload
26 |
27 | import com.atlarge.opendc.simulator.Duration
28 | import com.atlarge.opendc.simulator.Instant
29 |
30 |
31 | /**
32 | * This class hierarchy describes the states of a [Task].
33 | *
34 | * @author Fabian Mastenbroek (f.s.mastenbroek@student.tudelft.nl)
35 | */
36 | sealed class TaskState {
37 | /**
38 | * A state to indicate the task has not yet arrived at the [Datacenter].
39 | */
40 | object Underway : TaskState()
41 |
42 | /**
43 | * A state to indicate the task has arrived at the [Datacenter].
44 | *
45 | * @property at The moment in time the task has arrived.
46 | */
47 | data class Queued(val at: Instant) : TaskState()
48 |
49 | /**
50 | * A state to indicate the task has started running on a machine.
51 | *
52 | * @property previous The previous state of the task.
53 | * @property at The moment in time the task started.
54 | */
55 | data class Running(val previous: Queued, val at: Instant) : TaskState()
56 |
57 | /**
58 | * A state to indicate the task has finished.
59 | *
60 | * @property previous The previous state of the task.
61 | * @property at The moment in time the task finished.
62 | */
63 | data class Finished(val previous: Running, val at: Instant) : TaskState() {
64 | /**
65 | * The finish time of a task.
66 | */
67 | val finishTime: Instant
68 | get() = at
69 |
70 | /**
71 | * The start time of a task.
72 | */
73 | val startTime: Instant
74 | get() = previous.at
75 |
76 | /**
77 | * The enter time of a task.
78 | */
79 | val submitTime: Instant
80 | get() = previous.previous.at
81 |
82 | /**
83 | * The execution time of a task.
84 | */
85 | val executionTime: Duration
86 | get() = finishTime - startTime
87 |
88 | /**
89 | * The waiting time of a task.
90 | */
91 | val waitingTime: Duration
92 | get() = startTime - submitTime
93 | }
94 |
95 | /**
96 | * A state to indicate the task has failed.
97 | *
98 | * @property previous The previous state of the task.
99 | * @property at The moment in time the task failed.
100 | * @property reason The reason of the failure.
101 | */
102 | data class Failed(val previous: Running, val at: Instant, val reason: String) : TaskState()
103 | }
104 |
--------------------------------------------------------------------------------
/opendc-model-odc/core/src/main/kotlin/com/atlarge/opendc/model/odc/platform/workload/Trace.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * MIT License
3 | *
4 | * Copyright (c) 2017 atlarge-research
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in all
14 | * copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | * SOFTWARE.
23 | */
24 |
25 | package com.atlarge.opendc.model.odc.platform.workload
26 |
27 | /**
28 | * A timestamped sequence of jobs received in a cloud network.
29 | *
30 | * @author Fabian Mastenbroek (f.s.mastenbroek@student.tudelft.nl)
31 | */
32 | interface Trace {
33 | /**
34 | * The [Job]s in the trace.
35 | */
36 | val jobs: List
37 | }
38 |
--------------------------------------------------------------------------------
/opendc-model-odc/core/src/main/kotlin/com/atlarge/opendc/model/odc/platform/workload/User.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * MIT License
3 | *
4 | * Copyright (c) 2017 atlarge-research
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in all
14 | * copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | * SOFTWARE.
23 | */
24 |
25 | package com.atlarge.opendc.model.odc.platform.workload
26 |
27 | /**
28 | * A user of a cloud network that provides [Job]s for the simulation.
29 | *
30 | * Each user in a simulation has its own logical view of the cloud network which is used to route its jobs in the
31 | * physical network.
32 | *
33 | * @author Fabian Mastenbroek (f.s.mastenbroek@student.tudelft.nl)
34 | */
35 | interface User {
36 | /**
37 | * The unique identifier of the user.
38 | */
39 | val id: Int
40 |
41 | /**
42 | * The name of this user.
43 | */
44 | val name: String
45 | }
46 |
--------------------------------------------------------------------------------
/opendc-model-odc/core/src/main/kotlin/com/atlarge/opendc/model/odc/topology/container/Rack.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * MIT License
3 | *
4 | * Copyright (c) 2017 atlarge-research
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in all
14 | * copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | * SOFTWARE.
23 | */
24 |
25 | package com.atlarge.opendc.model.odc.topology.container
26 |
27 | import com.atlarge.opendc.simulator.Entity
28 |
29 | /**
30 | * A type of physical steel and electronic framework that is designed to house servers, networking devices, cables and
31 | * other datacenter computing equipment.
32 | *
33 | * @author Fabian Mastenbroek (f.s.mastenbroek@student.tudelft.nl)
34 | */
35 | interface Rack : Entity
36 |
--------------------------------------------------------------------------------
/opendc-model-odc/core/src/main/kotlin/com/atlarge/opendc/model/odc/topology/container/Room.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * MIT License
3 | *
4 | * Copyright (c) 2017 atlarge-research
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in all
14 | * copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | * SOFTWARE.
23 | */
24 |
25 | package com.atlarge.opendc.model.odc.topology.container
26 |
27 | import com.atlarge.opendc.simulator.Entity
28 |
29 | /**
30 | * A physical room in a datacenter with relationships to the entities within the room.
31 | *
32 | * @author Fabian Mastenbroek (f.s.mastenbroek@student.tudelft.nl)
33 | */
34 | interface Room : Entity
35 |
--------------------------------------------------------------------------------
/opendc-model-odc/core/src/main/kotlin/com/atlarge/opendc/model/odc/topology/machine/Cpu.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * MIT License
3 | *
4 | * Copyright (c) 2017 atlarge-research
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in all
14 | * copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | * SOFTWARE.
23 | */
24 |
25 | package com.atlarge.opendc.model.odc.topology.machine
26 |
27 | /**
28 | * A central processing unit.
29 | *
30 | * @author Fabian Mastenbroek (f.s.mastenbroek@student.tudelft.nl)
31 | */
32 | interface Cpu : ProcessingUnit
33 |
--------------------------------------------------------------------------------
/opendc-model-odc/core/src/main/kotlin/com/atlarge/opendc/model/odc/topology/machine/Gpu.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * MIT License
3 | *
4 | * Copyright (c) 2017 atlarge-research
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in all
14 | * copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | * SOFTWARE.
23 | */
24 |
25 | package com.atlarge.opendc.model.odc.topology.machine
26 |
27 | /**
28 | * A graphics processing unit.
29 | *
30 | * @author Fabian Mastenbroek (f.s.mastenbroek@student.tudelft.nl)
31 | */
32 | interface Gpu : ProcessingUnit
33 |
34 |
--------------------------------------------------------------------------------
/opendc-model-odc/core/src/main/kotlin/com/atlarge/opendc/model/odc/topology/machine/ProcessingUnit.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * MIT License
3 | *
4 | * Copyright (c) 2017 atlarge-research
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in all
14 | * copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | * SOFTWARE.
23 | */
24 |
25 | package com.atlarge.opendc.model.odc.topology.machine
26 |
27 | import com.atlarge.opendc.simulator.Entity
28 |
29 | /**
30 | * An interface representing a generic processing unit which is placed into a [Machine].
31 | *
32 | * @author Fabian Mastenbroek (f.s.mastenbroek@student.tudelft.nl)
33 | */
34 | interface ProcessingUnit : Entity {
35 | /**
36 | * The speed of this [ProcessingUnit] per core in MHz.
37 | */
38 | val clockRate: Int
39 |
40 | /**
41 | * The amount of cores within this [ProcessingUnit].
42 | */
43 | val cores: Int
44 |
45 | /**
46 | * The energy consumption of this [ProcessingUnit] in Watt.
47 | */
48 | val energyConsumption: Double
49 | }
50 |
--------------------------------------------------------------------------------
/opendc-model-odc/core/src/main/kotlin/com/atlarge/opendc/model/odc/topology/network/NetworkUnit.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * MIT License
3 | *
4 | * Copyright (c) 2017 atlarge-research
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in all
14 | * copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | * SOFTWARE.
23 | */
24 |
25 | package com.atlarge.opendc.model.odc.topology.network
26 |
27 | import com.atlarge.opendc.simulator.Entity
28 |
29 | /**
30 | * A generic interface for a network unit in a cloud network.
31 | *
32 | * @author Fabian Mastenbroek (f.s.mastenbroek@student.tudelft.nl)
33 | */
34 | interface NetworkUnit : Entity
35 |
--------------------------------------------------------------------------------
/opendc-model-odc/core/src/main/kotlin/com/atlarge/opendc/model/odc/topology/power/PowerUnit.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * MIT License
3 | *
4 | * Copyright (c) 2017 atlarge-research
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in all
14 | * copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | * SOFTWARE.
23 | */
24 |
25 | package com.atlarge.opendc.model.odc.topology.power
26 |
27 | import com.atlarge.opendc.simulator.Entity
28 |
29 | /**
30 | * An [Entity] which provides power for other entities a cloud network to run.
31 | *
32 | * @author Fabian Mastenbroek (f.s.mastenbroek@student.tudelft.nl)
33 | */
34 | interface PowerUnit : Entity
35 |
--------------------------------------------------------------------------------
/opendc-model-odc/core/src/main/kotlin/com/atlarge/opendc/model/odc/topology/storage/StorageUnit.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * MIT License
3 | *
4 | * Copyright (c) 2017 atlarge-research
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in all
14 | * copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | * SOFTWARE.
23 | */
24 |
25 | package com.atlarge.opendc.model.odc.topology.storage
26 |
27 | import com.atlarge.opendc.simulator.Entity
28 |
29 | /**
30 | * A generic interface for a storage unit in a cloud network.
31 | *
32 | * @author Fabian Mastenbroek (f.s.mastenbroek@student.tudelft.nl)
33 | */
34 | interface StorageUnit : Entity
35 |
--------------------------------------------------------------------------------
/opendc-model-odc/jpa/build.gradle:
--------------------------------------------------------------------------------
1 | /*
2 | * MIT License
3 | *
4 | * Copyright (c) 2017 atlarge-research
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in all
14 | * copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | * SOFTWARE.
23 | */
24 |
25 | /* Build configuration */
26 | apply from: '../../gradle/kotlin.gradle'
27 | apply plugin: 'java-library'
28 | apply plugin: 'kotlin-jpa'
29 |
30 | /* Project configuration */
31 | repositories {
32 | jcenter()
33 | }
34 |
35 | dependencies {
36 | implementation "org.jetbrains.kotlin:kotlin-stdlib"
37 |
38 | api project(':opendc-core')
39 | api project(':opendc-stdlib')
40 | api project(':opendc-model-odc:core')
41 | api "javax.persistence:javax.persistence-api:2.2"
42 | implementation "io.github.microutils:kotlin-logging:1.4.6"
43 |
44 | testImplementation "org.junit.jupiter:junit-jupiter-api:$junit_jupiter_version"
45 | testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:$junit_jupiter_version"
46 | testImplementation "org.junit.platform:junit-platform-launcher:$junit_platform_version"
47 | }
48 |
--------------------------------------------------------------------------------
/opendc-model-odc/jpa/src/main/kotlin/com/atlarge/opendc/model/odc/JpaBootstrap.kt:
--------------------------------------------------------------------------------
1 | package com.atlarge.opendc.model.odc
2 |
3 | import com.atlarge.opendc.model.odc.integration.jpa.schema.Experiment
4 | import com.atlarge.opendc.model.odc.integration.jpa.schema.Task
5 | import com.atlarge.opendc.model.odc.topology.JpaTopologyFactory
6 | import com.atlarge.opendc.model.topology.bootstrap
7 | import com.atlarge.opendc.simulator.Bootstrap
8 | import mu.KotlinLogging
9 |
10 | /**
11 | * A [Bootstrap] procedure for experiments retrieved from a JPA data store.
12 | *
13 | * @author Fabian Mastenbroek (f.s.mastenbroek@student.tudelft.nl)
14 | */
15 | class JpaBootstrap(val experiment: Experiment) : Bootstrap {
16 | /**
17 | * The logging instance.
18 | */
19 | private val logger = KotlinLogging.logger {}
20 |
21 | /**
22 | * Bootstrap a model `M` for a kernel in the given context.
23 | *
24 | * @param context The context to apply to model in.
25 | * @return The initialised model for the simulation.
26 | */
27 | override fun apply(context: Bootstrap.Context): JpaModel {
28 | val section = experiment.path.sections.first()
29 |
30 | // TODO We should not modify parts of the experiment in a apply as the apply should be reproducible.
31 | // Important: initialise the scheduler of the datacenter
32 | section.datacenter.scheduler = experiment.scheduler
33 |
34 | // Register the scheduler
35 | context.start(experiment.scheduler)
36 |
37 | val topology = JpaTopologyFactory(section)
38 | .create()
39 | .bootstrap()
40 | .apply(context)
41 | val trace = experiment.trace
42 | val tasks = trace.jobs.flatMap { it.tasks }
43 |
44 | // Schedule all messages in the trace
45 | tasks.forEach { task ->
46 | if (task is Task) {
47 | context.schedule(task, section.datacenter, delay = task.startTime)
48 | }
49 | }
50 |
51 | return JpaModel(experiment, topology)
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/opendc-model-odc/jpa/src/main/kotlin/com/atlarge/opendc/model/odc/JpaModel.kt:
--------------------------------------------------------------------------------
1 | package com.atlarge.opendc.model.odc
2 |
3 | import com.atlarge.opendc.model.odc.integration.jpa.schema.Experiment
4 | import com.atlarge.opendc.model.topology.MutableTopology
5 |
6 | /**
7 | * Implementation of the [OdcModel] using a JPA backend.
8 | *
9 | * @property experiment The experiment that is simulated.
10 | * @property topology The topology the simulation runs on.
11 | * @author Fabian Mastenbroek (f.s.mastenbroek@student.tudelft.nl)
12 | */
13 | data class JpaModel(val experiment: Experiment, val topology: MutableTopology) : OdcModel, MutableTopology by topology
14 |
15 |
--------------------------------------------------------------------------------
/opendc-model-odc/jpa/src/main/kotlin/com/atlarge/opendc/model/odc/integration/jpa/Jpa.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * MIT License
3 | *
4 | * Copyright (c) 2017 atlarge-research
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in all
14 | * copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | * SOFTWARE.
23 | */
24 |
25 | package com.atlarge.opendc.model.odc.integration.jpa
26 |
27 | import kotlinx.coroutines.experimental.Unconfined
28 | import kotlinx.coroutines.experimental.channels.ReceiveChannel
29 | import kotlinx.coroutines.experimental.channels.consume
30 | import kotlinx.coroutines.experimental.channels.produce
31 | import javax.persistence.EntityManager
32 | import javax.persistence.EntityManagerFactory
33 | import javax.persistence.RollbackException
34 | import kotlin.coroutines.experimental.CoroutineContext
35 | import kotlin.coroutines.experimental.coroutineContext
36 |
37 | /**
38 | * Run the given block in a transaction, committing on return of the block.
39 | *
40 | * @param block The block to execute in the transaction.
41 | */
42 | inline fun EntityManager.transaction(block: () -> Unit) {
43 | transaction.begin()
44 | block()
45 | transaction.commit()
46 | }
47 |
48 | /**
49 | * Write the given channel in batch to the database.
50 | *
51 | * @param factory The [EntityManagerFactory] to use to create an [EntityManager] which can persist the entities.
52 | * @param batchSize The size of each batch.
53 | */
54 | suspend fun ReceiveChannel.persist(factory: EntityManagerFactory, batchSize: Int = 1000) {
55 | val writer = factory.createEntityManager()
56 |
57 | this
58 | .buffer(coroutineContext, batchSize)
59 | .consume {
60 | val transaction = writer.transaction
61 | try {
62 |
63 | for (buffer in this) {
64 | transaction.begin()
65 | buffer.forEach { writer.persist(it) }
66 |
67 | writer.flush()
68 | writer.clear()
69 |
70 | transaction.commit()
71 | }
72 | } catch(e: RollbackException) {
73 | // Rollback transaction if still active
74 | if (transaction.isActive) {
75 | transaction.rollback()
76 | }
77 |
78 | throw e
79 | } finally {
80 | writer.close()
81 | }
82 | }
83 | }
84 |
85 | /**
86 | * Buffer a given amount of elements before emitting them as a list.
87 | *
88 | * @param size The size of the buffer.
89 | * @return A [ReceiveChannel] that emits lists of type [E] that have been buffered.
90 | */
91 | private fun ReceiveChannel.buffer(context: CoroutineContext = Unconfined, size: Int = 1000): ReceiveChannel> = produce(context) {
92 | consume {
93 | var buffer: MutableList = ArrayList(size)
94 |
95 | for (element in this) {
96 | if (buffer.size == size) {
97 | send(buffer)
98 | buffer = ArrayList(size)
99 | }
100 |
101 | buffer.add(element)
102 | }
103 |
104 | send(buffer)
105 | }
106 | }
107 |
--------------------------------------------------------------------------------
/opendc-model-odc/jpa/src/main/kotlin/com/atlarge/opendc/model/odc/integration/jpa/converter/DateTimeConverter.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * MIT License
3 | *
4 | * Copyright (c) 2018 atlarge-research
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in all
14 | * copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | * SOFTWARE.
23 | */
24 |
25 | package com.atlarge.opendc.model.odc.integration.jpa.converter
26 |
27 | import java.time.LocalDateTime
28 | import java.time.format.DateTimeFormatter
29 | import javax.persistence.AttributeConverter
30 |
31 | /**
32 | * The datetime_created and datetime_last_edited columns are in a subset of ISO-8601 (second fractions are ommitted):
33 | * YYYY-MM-DDTHH:MM:SS, where...
34 | * - YYYY is the four-digit year,
35 | * - MM is the two-digit month (1-12)
36 | * - DD is the two-digit day of the month (1-31)
37 | * - HH is the two-digit hours part (0-23)
38 | * - MM is the two-digit minutes part (0-59)
39 | * - SS is the two-digit seconds part (0-59)
40 | *
41 | */
42 | class DateTimeConverter : AttributeConverter {
43 | /**
44 | * The [DateTimeFormatter] to parse th [LocalDateTime] instance.
45 | */
46 | private val formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss")
47 |
48 | /**
49 | * Converts the data stored in the database column into the
50 | * value to be stored in the entity attribute.
51 | * Note that it is the responsibility of the converter writer to
52 | * specify the correct dbData type for the corresponding column
53 | * for use by the JDBC driver: i.e., persistence providers are
54 | * not expected to do such type conversion.
55 | *
56 | * @param dbData the data from the database column to be converted
57 | * @return the converted value to be stored in the entity attribute
58 | */
59 | override fun convertToEntityAttribute(dbData: String): LocalDateTime = LocalDateTime.parse(dbData, formatter)
60 |
61 | /**
62 | * Converts the value stored in the entity attribute into the
63 | * data representation to be stored in the database.
64 | *
65 | * @param attribute the entity attribute value to be converted
66 | * @return the converted data to be stored in the database column
67 | */
68 | override fun convertToDatabaseColumn(attribute: LocalDateTime): String = attribute.format(formatter)
69 | }
70 |
--------------------------------------------------------------------------------
/opendc-model-odc/jpa/src/main/kotlin/com/atlarge/opendc/model/odc/integration/jpa/converter/ParallelizableConverter.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * MIT License
3 | *
4 | * Copyright (c) 2017 atlarge-research
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in all
14 | * copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | * SOFTWARE.
23 | */
24 |
25 | package com.atlarge.opendc.model.odc.integration.jpa.converter
26 |
27 | import javax.persistence.AttributeConverter
28 |
29 | /**
30 | * An internal [AttributeConverter] that maps the values _PARALLEL_ and _SEQUENTIAL_ to a
31 | * boolean value indicating whether a task is parallelizable.
32 | *
33 | * @author Fabian Mastenbroek (f.s.mastenbroek@student.tudelft.nl)
34 | */
35 | class ParallelizableConverter : AttributeConverter {
36 | /**
37 | * Converts the data stored in the database column into the
38 | * value to be stored in the entity attribute.
39 | * Note that it is the responsibility of the converter writer to
40 | * specify the correct dbData type for the corresponding column
41 | * for use by the JDBC driver: i.e., persistence providers are
42 | * not expected to do such type conversion.
43 | *
44 | * @param dbData the data from the database column to be converted
45 | * @return the converted value to be stored in the entity attribute
46 | */
47 | override fun convertToEntityAttribute(dbData: String?): Boolean = when (dbData?.toUpperCase()) {
48 | "SEQUENTIAL" -> false
49 | "PARALLEL" -> true
50 | else -> false
51 | }
52 |
53 | /**
54 | * Converts the value stored in the entity attribute into the
55 | * data representation to be stored in the database.
56 | *
57 | * @param attribute the entity attribute value to be converted
58 | * @return the converted data to be stored in the database column
59 | */
60 | override fun convertToDatabaseColumn(attribute: Boolean?): String =
61 | if (attribute == true) "PARALLEL" else "SEQUENTIAL"
62 | }
63 |
--------------------------------------------------------------------------------
/opendc-model-odc/jpa/src/main/kotlin/com/atlarge/opendc/model/odc/integration/jpa/schema/Cpu.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * MIT License
3 | *
4 | * Copyright (c) 2017 atlarge-research
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in all
14 | * copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | * SOFTWARE.
23 | */
24 |
25 | package com.atlarge.opendc.model.odc.integration.jpa.schema
26 |
27 | import com.atlarge.opendc.model.odc.topology.machine.Cpu
28 | import javax.persistence.Entity
29 |
30 | /**
31 | * A cpu entity in the persistent schema.
32 | *
33 | * @property id The unique identifier of the cpu.
34 | * @property manufacturer The manufacturer of the cpu.
35 | * @property family The family of the cpu.
36 | * @property generation The generation of the cpu.
37 | * @property model The model of the cpu.
38 | * @property clockRate The clock rate of the cpu.
39 | * @property cores The amount of cores in the gpu.
40 | * @property energyConsumption The energy consumption of the cpu in Watt.
41 | * @author Fabian Mastenbroek (f.s.mastenbroek@student.tudelft.nl)
42 | */
43 | @Entity
44 | data class Cpu(
45 | val id: Int?,
46 | val manufacturer: String,
47 | val family: String,
48 | val generation: String,
49 | val model: String,
50 | override val clockRate: Int,
51 | override val cores: Int,
52 | override val energyConsumption: Double
53 | ) : Cpu {
54 | /**
55 | * The initial state of the entity.
56 | */
57 | override val initialState = Unit
58 | }
59 |
--------------------------------------------------------------------------------
/opendc-model-odc/jpa/src/main/kotlin/com/atlarge/opendc/model/odc/integration/jpa/schema/Datacenter.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * MIT License
3 | *
4 | * Copyright (c) 2017 atlarge-research
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in all
14 | * copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | * SOFTWARE.
23 | */
24 |
25 | package com.atlarge.opendc.model.odc.integration.jpa.schema
26 |
27 | import com.atlarge.opendc.model.odc.platform.scheduler.Scheduler
28 | import com.atlarge.opendc.model.odc.topology.container.Datacenter
29 | import com.atlarge.opendc.simulator.Duration
30 | import javax.persistence.Entity
31 |
32 | /**
33 | * A datacenter entity in the persistent schema.
34 | *
35 | * @property id The unique identifier of the datacenter.
36 | * @property rooms The rooms in the datacenter.
37 | * @author Fabian Mastenbroek (f.s.mastenbroek@student.tudelft.nl)
38 | */
39 | @Entity
40 | data class Datacenter(
41 | val id: Int?,
42 | val rooms: List
43 | ) : Datacenter {
44 | /**
45 | * Construct a datacenter. We need this useless constructor in order for Kotlin correctly initialise the
46 | * constant fields of the class.
47 | */
48 | private constructor() : this(-1, emptyList())
49 |
50 | /**
51 | * The task scheduler the datacenter uses.
52 | */
53 | override lateinit var scheduler: Scheduler<*>
54 | internal set
55 |
56 | /**
57 | * The interval at which task will be (re)scheduled.
58 | * We set this to a fixed constant since the database provides no way of configuring this.
59 | */
60 | override val interval: Duration = 10
61 |
62 | /**
63 | * The initial state of the datacenter.
64 | */
65 | override val initialState = Unit
66 | }
67 |
--------------------------------------------------------------------------------
/opendc-model-odc/jpa/src/main/kotlin/com/atlarge/opendc/model/odc/integration/jpa/schema/Experiment.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * MIT License
3 | *
4 | * Copyright (c) 2017 atlarge-research
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in all
14 | * copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | * SOFTWARE.
23 | */
24 |
25 | package com.atlarge.opendc.model.odc.integration.jpa.schema
26 |
27 | import com.atlarge.opendc.model.odc.platform.scheduler.Scheduler
28 | import com.atlarge.opendc.simulator.Instant
29 | import javax.persistence.Entity
30 |
31 | /**
32 | * An experiment definition for the OpenDC database schema.
33 | *
34 | * @property id The identifier of the experiment.
35 | * @property name The name of the experiment.
36 | * @property scheduler The scheduler used in the experiment.
37 | * @property simulation The [Simulation] object for this experiment.
38 | * @property trace The trace used for the simulation.
39 | * @property path The path of the experiment.
40 | * @author Fabian Mastenbroek (f.s.mastenbroek@student.tudelft.nl)
41 | */
42 | @Entity
43 | data class Experiment(
44 | val id: Int?,
45 | val name: String,
46 | val scheduler: Scheduler<*>,
47 | val simulation: Simulation,
48 | val trace: Trace,
49 | val path: Path
50 | ) {
51 | /**
52 | * The state of the experiment.
53 | */
54 | var state: ExperimentState = ExperimentState.QUEUED
55 |
56 | /**
57 | * The last tick that has been simulated.
58 | */
59 | var last: Instant = 0
60 | }
61 |
--------------------------------------------------------------------------------
/opendc-model-odc/jpa/src/main/kotlin/com/atlarge/opendc/model/odc/integration/jpa/schema/ExperimentState.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * MIT License
3 | *
4 | * Copyright (c) 2017 atlarge-research
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in all
14 | * copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | * SOFTWARE.
23 | */
24 |
25 | package com.atlarge.opendc.model.odc.integration.jpa.schema
26 |
27 | /**
28 | * Enumerations of the states an [Experiment] can assume.
29 | *
30 | * @author Fabian Mastenbroek (f.s.mastenbroek@student.tudelft.nl)
31 | */
32 | enum class ExperimentState {
33 | /**
34 | * This state indicates the experiment has been queued for simulation, but has not yet started.
35 | */
36 | QUEUED,
37 |
38 | /**
39 | * This state indicates the experiment has been claimed by a simulator for simulation, but
40 | * not yet started.
41 | */
42 | CLAIMED,
43 |
44 | /**
45 | * This state indicates the experiment is currently in simulation.
46 | */
47 | SIMULATING,
48 |
49 | /**
50 | * This state indicates the experiment has finished simulating.
51 | */
52 | FINISHED,
53 |
54 | /**
55 | * This states indicates the experiment was aborted due to a timeout.
56 | */
57 | ABORTED,
58 | }
59 |
--------------------------------------------------------------------------------
/opendc-model-odc/jpa/src/main/kotlin/com/atlarge/opendc/model/odc/integration/jpa/schema/Gpu.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * MIT License
3 | *
4 | * Copyright (c) 2017 atlarge-research
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in all
14 | * copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | * SOFTWARE.
23 | */
24 |
25 | package com.atlarge.opendc.model.odc.integration.jpa.schema
26 |
27 | import com.atlarge.opendc.model.odc.topology.machine.Gpu
28 | import javax.persistence.Entity
29 |
30 | /**
31 | * A gpu entity in the persistent schema.
32 | *
33 | * @property id The unique identifier of the gpu.
34 | * @property manufacturer The manufacturer of the gpu.
35 | * @property family The family of the gpu.
36 | * @property generation The generation of the gpu.
37 | * @property model The model of the gpu.
38 | * @property clockRate The clock rate of the gpu.
39 | * @property cores The amount of cores in the gpu.
40 | * @property energyConsumption The energy consumption of the gpu in Watt.
41 | * @author Fabian Mastenbroek (f.s.mastenbroek@student.tudelft.nl)
42 | */
43 | @Entity
44 | data class Gpu(
45 | val id: Int?,
46 | val manufacturer: String,
47 | val family: String,
48 | val generation: String,
49 | val model: String,
50 | override val clockRate: Int,
51 | override val cores: Int,
52 | override val energyConsumption: Double
53 | ) : Gpu {
54 | /**
55 | * The initial state of the entity.
56 | */
57 | override val initialState = Unit
58 | }
59 |
--------------------------------------------------------------------------------
/opendc-model-odc/jpa/src/main/kotlin/com/atlarge/opendc/model/odc/integration/jpa/schema/Job.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * MIT License
3 | *
4 | * Copyright (c) 2017 atlarge-research
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in all
14 | * copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | * SOFTWARE.
23 | */
24 |
25 | package com.atlarge.opendc.model.odc.integration.jpa.schema
26 |
27 | import com.atlarge.opendc.model.odc.platform.workload.Job
28 | import com.atlarge.opendc.model.odc.platform.workload.User
29 | import javax.persistence.Entity
30 |
31 | /**
32 | * A [Job] backed by the JPA API and an underlying database connection.
33 | *
34 | * @property id The unique identifier of the job.
35 | * @property tasks The collection of tasks the job consists of.
36 | * @author Fabian Mastenbroek (f.s.mastenbroek@student.tudelft.nl)
37 | */
38 | @Entity
39 | class Job(
40 | override val id: Int,
41 | override val tasks: MutableSet
42 | ) : Job {
43 | /**
44 | * The owner of the job, which is a singleton, since the database has no
45 | * concept of ownership yet.
46 | */
47 | override val owner: User = object : User {
48 | /**
49 | * The unique identifier of the user.
50 | */
51 | override val id: Int = 0
52 |
53 | /**
54 | * The name of this user.
55 | */
56 | override val name: String = "admin"
57 | }
58 |
59 | override fun toString(): String = "Job(id=$id, tasks=$tasks, owner=$owner)"
60 | }
61 |
--------------------------------------------------------------------------------
/opendc-model-odc/jpa/src/main/kotlin/com/atlarge/opendc/model/odc/integration/jpa/schema/JobMetrics.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * MIT License
3 | *
4 | * Copyright (c) 2018 atlarge-research
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in all
14 | * copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | * SOFTWARE.
23 | */
24 |
25 | package com.atlarge.opendc.model.odc.integration.jpa.schema
26 |
27 | import javax.persistence.Entity
28 |
29 | /**
30 | * The metrics of a task.
31 | *
32 | * @author Fabian Mastenbroek (f.s.mastenbroek@student.tudelft.nl)
33 | */
34 | @Entity
35 | data class JobMetrics(val id: Int?,
36 | val experiment: Experiment,
37 | val job: Job,
38 | val criticalPath: Long,
39 | val criticalPathLength: Int,
40 | val waiting: Long,
41 | val makespan: Long,
42 | val nsl: Long)
43 |
--------------------------------------------------------------------------------
/opendc-model-odc/jpa/src/main/kotlin/com/atlarge/opendc/model/odc/integration/jpa/schema/Machine.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * MIT License
3 | *
4 | * Copyright (c) 2017 atlarge-research
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in all
14 | * copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | * SOFTWARE.
23 | */
24 |
25 | package com.atlarge.opendc.model.odc.integration.jpa.schema
26 |
27 | import com.atlarge.opendc.model.odc.topology.machine.Machine
28 | import javax.persistence.Entity
29 |
30 | /**
31 | * A machine entity in the persistent schema.
32 | *
33 | * @property id The unique identifier of the machine.
34 | * @property position The position of the machine in the rack.
35 | * @property cpus The CPUs in the machine.
36 | * @property gpus The GPUs in the machine.
37 | * @property ethernetSpeed The ethernet speed in mbps (megabits per second, 1 Gb/s is 10,000 mbps).
38 | * @author Fabian Mastenbroek (f.s.mastenbroek@student.tudelft.nl)
39 | */
40 | @Entity
41 | class Machine(
42 | val id: Int?,
43 | val position: Int,
44 | val cpus: Set,
45 | val gpus: Set,
46 | ethernetSpeed: Double
47 | ) : Machine(ethernetSpeed) {
48 | override fun toString(): String = "Machine(id=$id, position=$position, cpus=$cpus, gpus=$gpus)"
49 | }
50 |
--------------------------------------------------------------------------------
/opendc-model-odc/jpa/src/main/kotlin/com/atlarge/opendc/model/odc/integration/jpa/schema/MachineState.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * MIT License
3 | *
4 | * Copyright (c) 2017 atlarge-research
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in all
14 | * copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | * SOFTWARE.
23 | */
24 |
25 | package com.atlarge.opendc.model.odc.integration.jpa.schema
26 |
27 | import com.atlarge.opendc.simulator.Instant
28 | import com.atlarge.opendc.simulator.instrumentation.lerp
29 | import javax.persistence.Entity
30 |
31 | /**
32 | * The state of a [Machine].
33 | *
34 | * @property id The unique identifier of the state.
35 | * @property machine The machine of the state.
36 | * @property experiment The experiment the machine is running in.
37 | * @property time The current moment in time.
38 | * @property temperature The temperature of the machine.
39 | * @property memoryUsage The memory usage of the machine.
40 | * @property load The load of the machine.
41 | * @author Fabian Mastenbroek (f.s.mastenbroek@student.tudelft.nl)
42 | */
43 | @Entity
44 | data class MachineState(
45 | val id: Int?,
46 | val machine: Machine,
47 | val experiment: Experiment,
48 | val time: Instant,
49 | val temperature: Double,
50 | val memoryUsage: Int,
51 | val load: Double
52 | ) {
53 | companion object {
54 | /**
55 | * A linear interpolator for [MachineState] instances.
56 | */
57 | val Interpolator: (Double, MachineState, MachineState) -> MachineState = { f, a, b ->
58 | a.copy(
59 | id = null,
60 | time = lerp(a.time, b.time, f),
61 | temperature = lerp(a.temperature, b.temperature, f),
62 | memoryUsage = lerp(a.memoryUsage, b.memoryUsage, f),
63 | load = lerp(a.load, b.load, f)
64 | )
65 | }
66 | }
67 | }
68 |
69 |
--------------------------------------------------------------------------------
/opendc-model-odc/jpa/src/main/kotlin/com/atlarge/opendc/model/odc/integration/jpa/schema/Path.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * MIT License
3 | *
4 | * Copyright (c) 2017 atlarge-research
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in all
14 | * copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | * SOFTWARE.
23 | */
24 |
25 | package com.atlarge.opendc.model.odc.integration.jpa.schema
26 |
27 | import javax.persistence.Entity
28 |
29 | /**
30 | * A [Path] holds all sections of the parent experiment.
31 | *
32 | * @property id The unique identifier of the path.
33 | * @property sections The sections of the path.
34 | * @author Fabian Mastenbroek (f.s.mastenbroek@student.tudelft.nl)
35 | */
36 | @Entity
37 | open class Path(
38 | val id: Int?,
39 | val sections: List
40 | )
41 |
--------------------------------------------------------------------------------
/opendc-model-odc/jpa/src/main/kotlin/com/atlarge/opendc/model/odc/integration/jpa/schema/Rack.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * MIT License
3 | *
4 | * Copyright (c) 2017 atlarge-research
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in all
14 | * copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | * SOFTWARE.
23 | */
24 |
25 | package com.atlarge.opendc.model.odc.integration.jpa.schema
26 |
27 | import com.atlarge.opendc.model.odc.topology.container.Rack
28 | import javax.persistence.Entity
29 |
30 | /**
31 | * A rack entity in a room in the persistent schema.
32 | *
33 | * @property id The unique identifier of the rack.
34 | * @property name The name of the rack.
35 | * @property capacity The capacity of the rack in terms of units.
36 | * @property powerCapacity The power capacity of the rack in Watt.
37 | * @property machines The machines in the rack.
38 | * @author Fabian Mastenbroek (f.s.mastenbroek@student.tudelft.nl)
39 | */
40 | @Entity
41 | class Rack(
42 | id: Int?,
43 | val name: String,
44 | val capacity: Int,
45 | val powerCapacity: Int,
46 | val machines: List
47 | ) : RoomObject(id), Rack {
48 | /**
49 | * The initial state of the entity.
50 | */
51 | override val initialState = Unit
52 | }
53 |
--------------------------------------------------------------------------------
/opendc-model-odc/jpa/src/main/kotlin/com/atlarge/opendc/model/odc/integration/jpa/schema/Room.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * MIT License
3 | *
4 | * Copyright (c) 2017 atlarge-research
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in all
14 | * copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | * SOFTWARE.
23 | */
24 |
25 | package com.atlarge.opendc.model.odc.integration.jpa.schema
26 |
27 | import com.atlarge.opendc.model.odc.topology.container.Room
28 | import javax.persistence.Entity
29 |
30 | /**
31 | * A room entity in the persistent schema.
32 | *
33 | * @property id The unique identifier of the room.
34 | * @property name The name of the room.
35 | * @property type The type of the room.
36 | * @property objects The objects in the room.
37 | * @author Fabian Mastenbroek (f.s.mastenbroek@student.tudelft.nl)
38 | */
39 | @Entity
40 | data class Room(
41 | val id: Int?,
42 | val name: String,
43 | val type: RoomType,
44 | val objects: List
45 | ) : Room {
46 | /**
47 | * The initial state of the entity.
48 | */
49 | override val initialState = Unit
50 | }
51 |
--------------------------------------------------------------------------------
/opendc-model-odc/jpa/src/main/kotlin/com/atlarge/opendc/model/odc/integration/jpa/schema/RoomObject.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * MIT License
3 | *
4 | * Copyright (c) 2017 atlarge-research
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in all
14 | * copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | * SOFTWARE.
23 | */
24 |
25 | package com.atlarge.opendc.model.odc.integration.jpa.schema
26 |
27 | import javax.persistence.Entity
28 |
29 | /**
30 | * An object in a room.
31 | *
32 | * @property id The unique identifier of the room.
33 | * @author Fabian Mastenbroek (f.s.mastenbroek@student.tudelft.nl)
34 | */
35 | @Entity
36 | abstract class RoomObject(val id: Int?)
37 |
--------------------------------------------------------------------------------
/opendc-model-odc/jpa/src/main/kotlin/com/atlarge/opendc/model/odc/integration/jpa/schema/RoomType.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * MIT License
3 | *
4 | * Copyright (c) 2017 atlarge-research
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in all
14 | * copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | * SOFTWARE.
23 | */
24 |
25 | package com.atlarge.opendc.model.odc.integration.jpa.schema
26 |
27 | /**
28 | * This enumeration defines the room types available in the OpenDC frontend.
29 | *
30 | * @author Fabian Mastenbroek (f.s.mastenbroek@student.tudelft.nl)
31 | */
32 | enum class RoomType {
33 | COOLING, HALLWAY, OFFICE, POWER, SERVER
34 | }
35 |
--------------------------------------------------------------------------------
/opendc-model-odc/jpa/src/main/kotlin/com/atlarge/opendc/model/odc/integration/jpa/schema/Section.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * MIT License
3 | *
4 | * Copyright (c) 2017 atlarge-research
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in all
14 | * copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | * SOFTWARE.
23 | */
24 |
25 | package com.atlarge.opendc.model.odc.integration.jpa.schema
26 |
27 | import com.atlarge.opendc.simulator.Instant
28 | import javax.persistence.Entity
29 |
30 | /**
31 | * A [Section] holds a datacenter and the tick on which the parent experiment should
32 | * switch to this section.
33 | *
34 | * @property id The unique identifier of the section.
35 | * @property datacenter The datacenter of this section.
36 | * @property startTime The position in time when the experiment should start using the
37 | * topology of this section.
38 | * @author Fabian Mastenbroek (f.s.mastenbroek@student.tudelft.nl)
39 | */
40 | @Entity
41 | data class Section(
42 | val id: Int?,
43 | val datacenter: Datacenter,
44 | val startTime: Instant
45 | )
46 |
--------------------------------------------------------------------------------
/opendc-model-odc/jpa/src/main/kotlin/com/atlarge/opendc/model/odc/integration/jpa/schema/Simulation.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * MIT License
3 | *
4 | * Copyright (c) 2018 atlarge-research
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in all
14 | * copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | * SOFTWARE.
23 | */
24 |
25 | package com.atlarge.opendc.model.odc.integration.jpa.schema
26 |
27 | import java.time.LocalDateTime
28 | import javax.persistence.Entity
29 |
30 | /**
31 | * A [Simulation] has several [Path]s, which define the topology of the datacenter at different times. A [Simulation]
32 | * also has several [Experiment]s, which can be run on a combination of [Path]s, [Scheduler]s and [Trace]s.
33 | * [Simulation]s also serve as the scope to which different [User]s can be authorized.
34 | *
35 | *
36 | * @property id The unique identifier of this simulation.
37 | * @property name the name of the simulation.
38 | * @property createdAt The date at which the simulation was created.
39 | * @property lastEditedAt The date at which the simulation was lasted edited.
40 | */
41 | @Entity
42 | data class Simulation(val id: Int?, val name: String, val createdAt: LocalDateTime, val lastEditedAt: LocalDateTime)
43 |
--------------------------------------------------------------------------------
/opendc-model-odc/jpa/src/main/kotlin/com/atlarge/opendc/model/odc/integration/jpa/schema/StageMeasurement.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * MIT License
3 | *
4 | * Copyright (c) 2018 atlarge-research
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in all
14 | * copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | * SOFTWARE.
23 | */
24 |
25 | package com.atlarge.opendc.model.odc.integration.jpa.schema
26 |
27 | import com.atlarge.opendc.simulator.Instant
28 | import javax.persistence.Entity
29 |
30 | /**
31 | * The measurement of a stage.
32 | *
33 | * @property id The identifier of the measurement.
34 | * @property experiment The experiment associated with the measurement.
35 | * @property stage The stage of the measurement.
36 | * @property cpu The duration in cpu time of the stage.
37 | * @property wall The duration in wall time of the stage.
38 | * @property size The input size of the stage.
39 | * @property iterations The amount of iterations.
40 | */
41 | @Entity
42 | data class StageMeasurement(val id: Int?,
43 | val experiment: Experiment,
44 | val stage: Int,
45 | val time: Instant,
46 | val cpu: Long,
47 | val wall: Long,
48 | val size: Int,
49 | val iterations: Int)
50 |
51 |
--------------------------------------------------------------------------------
/opendc-model-odc/jpa/src/main/kotlin/com/atlarge/opendc/model/odc/integration/jpa/schema/Task.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * MIT License
3 | *
4 | * Copyright (c) 2017 atlarge-research
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in all
14 | * copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | * SOFTWARE.
23 | */
24 |
25 | package com.atlarge.opendc.model.odc.integration.jpa.schema
26 |
27 | import com.atlarge.opendc.model.odc.platform.workload.Task
28 | import com.atlarge.opendc.model.odc.platform.workload.TaskState
29 | import com.atlarge.opendc.simulator.Instant
30 | import javax.persistence.Entity
31 | import javax.persistence.PostLoad
32 |
33 | /**
34 | * A [Task] backed by the JPA API and an underlying database connection.
35 | *
36 | * @property id The unique identifier of the job.
37 | * @property owner_id The unique identifier of the owner job.
38 | * @property priority The priority of the job.
39 | * @property flops The total amount of flops for the task.
40 | * @property cores The amount of cores required for running the task.
41 | * @property dependencies The dependencies of the task.
42 | * @property dependents Tasks that are dependent on this task.
43 | * @property inputSize The input size, i.e. required input data.
44 | * @property outputSize The output size.
45 | * @property startTime The start time in the simulation.
46 | * @author Fabian Mastenbroek (f.s.mastenbroek@student.tudelft.nl)
47 | */
48 | @Entity
49 | class Task(
50 | override val id: Int,
51 | override val owner_id: Int,
52 | override val priority: Int,
53 | override val flops: Long,
54 | override val cores: Int,
55 | override val dependencies: MutableSet,
56 | override val dependents: MutableSet,
57 | override val inputSize: Long,
58 | override val outputSize: Long,
59 | val startTime: Instant
60 | ) : Task {
61 | /**
62 | * The remaining flops for this task.
63 | */
64 | override var remaining: Long = 0
65 | private set
66 |
67 | /**
68 | * A flag to indicate whether the task has finished.
69 | */
70 | override var finished: Boolean = false
71 | private set
72 |
73 | /**
74 | * The state of the task.
75 | */
76 | override var state: TaskState = TaskState.Underway
77 | private set
78 |
79 | /**
80 | * This method initialises the task object after it has been created by the JPA implementation. We use this
81 | * initialisation method because JPA implementations only call the default constructor
82 | */
83 | @PostLoad
84 | internal fun init() {
85 | remaining = flops
86 | state = TaskState.Underway
87 | }
88 |
89 | /**
90 | * This method is invoked when a task has arrived at a datacenter.
91 | *
92 | * @param time The moment in time the task has arrived at the datacenter.
93 | */
94 | override fun arrive(time: Instant) {
95 | if (state != TaskState.Underway) {
96 | throw IllegalStateException("The task has already been submitted to a datacenter")
97 | }
98 | remaining = flops
99 | state = TaskState.Queued(time)
100 | }
101 |
102 | /**
103 | * Consume the given amount of flops of this task.
104 | *
105 | * @param time The current moment in time of the consumption.
106 | * @param flops The total amount of flops to consume.
107 | */
108 | override fun consume(time: Instant, flops: Long) {
109 | if (state is TaskState.Queued) {
110 | state = TaskState.Running(state as TaskState.Queued, time)
111 | } else if (finished) {
112 | return
113 | }
114 | remaining -= flops
115 | if (remaining <= 0) {
116 | remaining = 0
117 | finished = true
118 | state = TaskState.Finished(state as TaskState.Running, time)
119 | }
120 | }
121 |
122 | override fun toString(): String = "Task(id=$id, flops=$flops, cores=$cores, dependencies=$dependencies)"
123 | }
124 |
--------------------------------------------------------------------------------
/opendc-model-odc/jpa/src/main/kotlin/com/atlarge/opendc/model/odc/integration/jpa/schema/TaskMetrics.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * MIT License
3 | *
4 | * Copyright (c) 2018 atlarge-research
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in all
14 | * copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | * SOFTWARE.
23 | */
24 |
25 | package com.atlarge.opendc.model.odc.integration.jpa.schema
26 |
27 | import javax.persistence.Entity
28 |
29 | /**
30 | * The metrics of a task.
31 | *
32 | * @author Georgios Andreadis (g.andreadis@student.tudelft.nl)
33 | */
34 | @Entity
35 | data class TaskMetrics(val id: Int?,
36 | val experiment: Experiment,
37 | val task: Task,
38 | val job: Job,
39 | val waiting: Long,
40 | val execution: Long,
41 | val turnaround: Long)
42 |
--------------------------------------------------------------------------------
/opendc-model-odc/jpa/src/main/kotlin/com/atlarge/opendc/model/odc/integration/jpa/schema/TaskState.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * MIT License
3 | *
4 | * Copyright (c) 2017 atlarge-research
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in all
14 | * copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | * SOFTWARE.
23 | */
24 |
25 | package com.atlarge.opendc.model.odc.integration.jpa.schema
26 |
27 | import com.atlarge.opendc.simulator.Instant
28 | import com.atlarge.opendc.simulator.instrumentation.lerp
29 | import javax.persistence.Entity
30 |
31 | /**
32 | * The state of a [Task].
33 | *
34 | * @property id The unique identifier of the state.
35 | * @property task The task this is the state of.
36 | * @property experiment The experiment the machine is running in.
37 | * @property time The current moment in time.
38 | * @property remaining The remaining flops for the task.
39 | * @property cores The cores used for the task.
40 | * @author Fabian Mastenbroek (f.s.mastenbroek@student.tudelft.nl)
41 | */
42 | @Entity
43 | data class TaskState(
44 | val id: Int?,
45 | val task: Task,
46 | val experiment: Experiment,
47 | val time: Instant,
48 | val remaining: Int,
49 | val cores: Int
50 | ) {
51 | companion object {
52 | /**
53 | * A linear interpolator for [TaskState] instances.
54 | */
55 | val Interpolator: (Double, TaskState, TaskState) -> TaskState = { f, a, b ->
56 | a.copy(
57 | id = null,
58 | time = lerp(a.time, b.time, f),
59 | remaining = lerp(a.remaining, b.remaining, f)
60 | )
61 | }
62 | }
63 | }
64 |
65 |
66 |
--------------------------------------------------------------------------------
/opendc-model-odc/jpa/src/main/kotlin/com/atlarge/opendc/model/odc/integration/jpa/schema/Trace.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * MIT License
3 | *
4 | * Copyright (c) 2017 atlarge-research
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in all
14 | * copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | * SOFTWARE.
23 | */
24 |
25 | package com.atlarge.opendc.model.odc.integration.jpa.schema
26 |
27 | import com.atlarge.opendc.model.odc.platform.workload.Job
28 | import com.atlarge.opendc.model.odc.platform.workload.Trace
29 | import javax.persistence.Entity
30 |
31 | /**
32 | * A [Trace] backed by the JPA API and an underlying database connection.
33 | *
34 | * @property id The unique identifier of the trace.
35 | * @property name The name of the trace.
36 | * @property jobs The collection of jobs for this trace.
37 | * @author Fabian Mastenbroek (f.s.mastenbroek@student.tudelft.nl)
38 | */
39 | @Entity
40 | data class Trace(
41 | val id: Int?,
42 | val name: String,
43 | override val jobs: List
44 | ) : Trace
45 |
--------------------------------------------------------------------------------
/opendc-model-odc/jpa/src/main/kotlin/com/atlarge/opendc/model/odc/topology/JpaTopologyFactory.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * MIT License
3 | *
4 | * Copyright (c) 2017 atlarge-research
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in all
14 | * copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | * SOFTWARE.
23 | */
24 |
25 | package com.atlarge.opendc.model.odc.topology
26 |
27 | import com.atlarge.opendc.model.odc.integration.jpa.schema.Rack
28 | import com.atlarge.opendc.model.odc.integration.jpa.schema.Room
29 | import com.atlarge.opendc.model.odc.integration.jpa.schema.RoomObject
30 | import com.atlarge.opendc.model.odc.integration.jpa.schema.Section
31 | import com.atlarge.opendc.model.topology.*
32 |
33 | /**
34 | * A [TopologyFactory] that converts a [Section] of an experiment as defined by the API, into a proper [Topology].
35 | *
36 | * @property section The section to convert into a topology.
37 | * @property builder A builder for a topology to use.
38 | * @author Fabian Mastenbroek (f.s.mastenbroek@student.tudelft.nl)
39 | */
40 | class JpaTopologyFactory(val section: Section, val builder: TopologyBuilder = AdjacencyList.builder()) : TopologyFactory {
41 | /**
42 | * Create a [MutableTopology] instance.
43 | *
44 | * @return A mutable topology.
45 | */
46 | override fun create(): MutableTopology = builder.construct {
47 | val datacenter = section.datacenter
48 | add(datacenter)
49 | datacenter.rooms.forEach { room ->
50 | add(room)
51 | connect(datacenter, room, tag = "room")
52 |
53 | room.objects.forEach { roomObject(room, it) }
54 | }
55 | }
56 |
57 | /**
58 | * Handle the objects in a room.
59 | *
60 | * @param obj The obj to handle.
61 | */
62 | private fun MutableTopology.roomObject(parent: Room, obj: RoomObject) = when (obj) {
63 | is Rack -> rack(parent, obj)
64 | else -> Unit
65 | }
66 |
67 | /**
68 | * Handle a rack in a room.
69 | *
70 | * @param parent The parent of the rack.
71 | * @param rack The rack to handle.
72 | */
73 | private fun MutableTopology.rack(parent: Room, rack: Rack) {
74 | add(rack)
75 | connect(parent, rack, tag = "rack")
76 | rack.machines.forEach { machine ->
77 | add(machine)
78 | connect(rack, machine, tag = "machine")
79 |
80 | machine.cpus.forEach { cpu ->
81 | add(cpu)
82 | connect(machine, cpu, tag = "cpu")
83 | }
84 |
85 | machine.gpus.forEach { gpu ->
86 | add(gpu)
87 | connect(machine, gpu, tag = "gpu")
88 | }
89 | }
90 | }
91 | }
92 |
--------------------------------------------------------------------------------
/opendc-model-odc/sc18/Dockerfile:
--------------------------------------------------------------------------------
1 | # Docker mysql image for the OpenDC simulator project
2 | # This image requires the context to be set to the root directory of the project in order to correctly build.
3 | FROM gradle:4.9
4 | MAINTAINER Fabian Mastenbroek
5 |
6 | # Set the home directory to our gradle user's home.
7 | ENV HOME=/home/gradle
8 | ENV APP_HOME=$HOME/simulator
9 |
10 | # Copy OpenDC simulator
11 | COPY ./ $APP_HOME
12 |
13 | # Build as root
14 | USER root
15 |
16 | # Set the working directory to the simulator
17 | WORKDIR $APP_HOME
18 |
19 | # Build the application
20 | RUN gradle --no-daemon assemble installDist && mkdir data
21 |
22 | # Fix permissions
23 | RUN chown -R gradle:gradle $APP_HOME
24 |
25 | # Downgrade user
26 | USER gradle
27 |
28 | # Register data volume
29 | VOLUME ["$APP_HOME/data"]
30 |
31 | # Start the Gradle application on run
32 | ENTRYPOINT ["opendc-model-odc/sc18/build/install/sc18/bin/sc18"]
33 |
--------------------------------------------------------------------------------
/opendc-model-odc/sc18/build.gradle:
--------------------------------------------------------------------------------
1 | /*
2 | * MIT License
3 | *
4 | * Copyright (c) 2017 atlarge-research
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in all
14 | * copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | * SOFTWARE.
23 | */
24 |
25 | /* Build configuration */
26 | apply from: '../../gradle/kotlin.gradle'
27 | apply plugin: 'application'
28 |
29 | mainClassName = "com.atlarge.opendc.model.odc.platform.Sc18PlatformRunnerKt"
30 |
31 | /* Project configuration */
32 | repositories {
33 | jcenter()
34 | }
35 |
36 | dependencies {
37 | implementation "org.jetbrains.kotlin:kotlin-stdlib"
38 |
39 | compile project(':opendc-kernel-omega')
40 | compile project(':opendc-model-odc:jpa')
41 | implementation "io.github.microutils:kotlin-logging:1.4.6"
42 | implementation "com.github.ajalt:clikt:1.4.0"
43 | implementation "com.fasterxml.jackson.module:jackson-module-kotlin:2.9.6"
44 | implementation "com.opencsv:opencsv:4.2"
45 |
46 | runtimeOnly "org.apache.logging.log4j:log4j-slf4j-impl:2.11.1"
47 | runtimeOnly "org.hibernate:hibernate-core:5.2.5.Final"
48 | runtimeOnly "com.h2database:h2:1.4.197"
49 | }
50 |
--------------------------------------------------------------------------------
/opendc-model-odc/sc18/data/opendc.log:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/atlarge-research/opendc-simulator/f399e3d598d156926d0a74aa512f777ff0d9ad10/opendc-model-odc/sc18/data/opendc.log
--------------------------------------------------------------------------------
/opendc-model-odc/sc18/src/main/kotlin/com/atlarge/opendc/model/odc/platform/workload/format/sgwf/SgwfParser.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * MIT License
3 | *
4 | * Copyright (c) 2018 atlarge-research
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in all
14 | * copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | * SOFTWARE.
23 | */
24 |
25 | package com.atlarge.opendc.model.odc.platform.workload.format.sgwf
26 |
27 | import java.io.InputStream
28 |
29 | import com.atlarge.opendc.model.odc.integration.jpa.schema.Job as InternalJob
30 | import com.atlarge.opendc.model.odc.integration.jpa.schema.Task as InternalTask
31 | import com.atlarge.opendc.model.odc.integration.jpa.schema.Trace as InternalTrace
32 |
33 | /**
34 | * A parser for a simplified version of the Grid Workload Format. See the
35 | * Grid Workloads Archive (http://gwa.ewi.tudelft.nl/) for more information about the format.
36 | *
37 | * TODO: Describe simplified format
38 | */
39 | class SgwfParser {
40 | /**
41 | * Parse the given [InputStream] as Simplified Grid Workload Format file. After the method returns, the input stream
42 | * is closed.
43 | *
44 | * @param input The [InputStream] to parse as Simplified Grid Workload Format file.
45 | * @return The [Trace] that has been parsed.
46 | */
47 | fun parse(input: InputStream): InternalTrace {
48 | val jobs = mutableMapOf()
49 | val tasks = mutableMapOf()
50 | val taskDependencies = mutableMapOf>()
51 |
52 | input.bufferedReader().use { reader ->
53 | reader
54 | .lineSequence()
55 | .drop(1) // drop the header
56 | .filter { line ->
57 | !line.startsWith("#") && line.isNotBlank()
58 | }
59 | .forEach { line ->
60 | val values = line.split(",")
61 |
62 | if (values.size < 7) {
63 | throw IllegalArgumentException("The line is malformed: $line")
64 | }
65 |
66 | val jobId = values[0].trim().toInt()
67 | val taskId = values[1].trim().toInt()
68 | val priority: Int = 0
69 | val submitTime = values[2].trim().toLong()
70 | val runtime = values[3].trim().toLong()
71 | val cores = values[4].trim().toInt()
72 | val dependencies = values[6].split(" ")
73 | .filter { it.isNotEmpty() }
74 | .map { it.trim().toInt() }
75 | val inputSize: Long = 0
76 | val outputSize: Long = 0
77 |
78 | val flops: Long = 4000 * runtime * cores
79 |
80 | val task = InternalTask(taskId, jobId, priority, flops, cores, mutableSetOf(), mutableSetOf(),
81 | inputSize, outputSize, submitTime)
82 | val job = jobs.getOrPut(jobId) { InternalJob(jobId, mutableSetOf()) }
83 |
84 | job.tasks.add(task)
85 | tasks[taskId] = task
86 | taskDependencies[task] = dependencies
87 | }
88 | }
89 |
90 | taskDependencies.forEach { task, dependencies ->
91 | task.dependencies.addAll(dependencies.map { taskId ->
92 | tasks[taskId] ?: throw IllegalArgumentException("Dependency task with id $taskId not found")
93 | })
94 | dependencies.forEach {
95 | tasks[it]!!.dependents.add(task)
96 | }
97 | }
98 |
99 | return InternalTrace(0, "SGWF Trace", jobs.values.toList())
100 | }
101 | }
102 |
--------------------------------------------------------------------------------
/opendc-model-odc/sc18/src/main/kotlin/com/atlarge/opendc/model/odc/topology/format/sc18/Model.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * MIT License
3 | *
4 | * Copyright (c) 2018 atlarge-research
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in all
14 | * copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | * SOFTWARE.
23 | */
24 |
25 | package com.atlarge.opendc.model.odc.topology.format.sc18
26 |
27 | import com.fasterxml.jackson.annotation.JsonSubTypes
28 | import com.fasterxml.jackson.annotation.JsonTypeInfo
29 |
30 | /**
31 | * A datacenter setup.
32 | *
33 | * @property name The name of the setup.
34 | * @property rooms The rooms in the datacenter.
35 | */
36 | data class Setup(val name: String, val rooms: List)
37 |
38 | /**
39 | * A room in a datacenter.
40 | *
41 | * @property type The type of room in the datacenter.
42 | * @property objects The objects in the room.
43 | */
44 | data class Room(val type: String, val objects: List)
45 |
46 | /**
47 | * An object in a [Room].
48 | *
49 | * @property type The type of the room object.
50 | */
51 | @JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type")
52 | @JsonSubTypes(value = [JsonSubTypes.Type(name = "RACK", value = RoomObject.Rack::class)])
53 | sealed class RoomObject(val type: String) {
54 | /**
55 | * A rack in a server room.
56 | *
57 | * @property machines The machines in the rack.
58 | */
59 | data class Rack(val machines: List) : RoomObject("RACK")
60 | }
61 |
62 | /**
63 | * A machine in the setup that consists of the specified CPU's represented as
64 | * integer identifiers and ethernet speed.
65 | *
66 | * @property cpus The CPUs in the machine represented as integer identifiers.
67 | * @property ethernetSpeed The ethernet speed in mbps (megabits per second, 1 Gb/s is 10,000 mbps).
68 | */
69 | data class Machine(val cpus: List, val ethernetSpeed: Double)
70 |
--------------------------------------------------------------------------------
/opendc-model-odc/sc18/src/main/kotlin/com/atlarge/opendc/model/odc/topology/format/sc18/Sc18SetupParser.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * MIT License
3 | *
4 | * Copyright (c) 2018 atlarge-research
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in all
14 | * copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | * SOFTWARE.
23 | */
24 |
25 | package com.atlarge.opendc.model.odc.topology.format.sc18
26 |
27 | import com.atlarge.opendc.model.odc.integration.jpa.schema.Cpu
28 | import com.atlarge.opendc.model.odc.integration.jpa.schema.Datacenter
29 | import com.atlarge.opendc.model.odc.integration.jpa.schema.Path
30 | import com.atlarge.opendc.model.odc.integration.jpa.schema.Rack
31 | import com.atlarge.opendc.model.odc.integration.jpa.schema.RoomType
32 | import com.atlarge.opendc.model.odc.integration.jpa.schema.Section
33 | import com.fasterxml.jackson.databind.ObjectMapper
34 | import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
35 | import com.fasterxml.jackson.module.kotlin.readValue
36 | import java.io.InputStream
37 |
38 | import com.atlarge.opendc.model.odc.integration.jpa.schema.Machine as InternalMachine
39 | import com.atlarge.opendc.model.odc.integration.jpa.schema.Room as InternalRoom
40 |
41 | /**
42 | * A parser for the JSON experiment setup files used for the SC18 paper.
43 | *
44 | * @property objectMapper The Jackson [ObjectMapper] to map the setup file.
45 | */
46 | class Sc18SetupParser(private val objectMapper: ObjectMapper = jacksonObjectMapper()) {
47 | /**
48 | * Parse the given [InputStream] as setup file and convert it into a [Path].
49 | * After the method returns, the input stream is closed.
50 | *
51 | * @param input The [InputStream] to parse as setup file.
52 | * @return The [Path] that has been parsed.
53 | */
54 | fun parseSetup(input: InputStream): Setup = objectMapper.readValue(input)
55 |
56 | /**
57 | * Parse the given [InputStream] as setup file. After the method returns, the input stream
58 | * is closed.
59 | *
60 | * @param input The [InputStream] to parse as setup file.
61 | * @return The [Path] that has been parsed.
62 | */
63 | fun parse(input: InputStream): Path {
64 | val setup: Setup = parseSetup(input)
65 | val rooms = setup.rooms.map { room ->
66 | val objects = room.objects.map { roomObject ->
67 | when (roomObject) {
68 | is RoomObject.Rack -> {
69 | val machines = roomObject.machines.mapIndexed { position, machine ->
70 | val cpus = machine.cpus.map { id ->
71 | when (id) {
72 | 1 -> Cpu(null, "intel", "i7", "v6", "6700k", 4100, 4, 70.0)
73 | 2 -> Cpu(null, "intel", "i5", "v6", "6700k", 3500, 2, 50.0)
74 | else -> throw IllegalArgumentException("The cpu id $id is not recognized")
75 | }
76 | }
77 | InternalMachine(null, position, cpus.toSet(), emptySet(), machine.ethernetSpeed)
78 | }
79 | Rack(null, "", 0, 42, machines)
80 | }
81 | }
82 | }
83 | InternalRoom(null, room.type, RoomType.valueOf(room.type), objects)
84 | }
85 | val datacenter = Datacenter(null, rooms)
86 | val sections = listOf(Section(null, datacenter, 0))
87 | return Path(null, sections)
88 | }
89 | }
90 |
--------------------------------------------------------------------------------
/opendc-model-odc/sc18/src/main/resources/META-INF/persistence.xml:
--------------------------------------------------------------------------------
1 |
2 |
25 |
26 |
30 |
31 | org.hibernate.jpa.HibernatePersistenceProvider
32 | jpa/schema.xml
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
--------------------------------------------------------------------------------
/opendc-model-odc/sc18/src/main/resources/log4j2.xml:
--------------------------------------------------------------------------------
1 |
2 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
--------------------------------------------------------------------------------
/opendc-model-odc/setup/Dockerfile:
--------------------------------------------------------------------------------
1 | # Docker mysql image for the OpenDC simulator project
2 | # This image requires the context to be set to the root directory of the project in order to correctly build.
3 | FROM gradle:alpine
4 | MAINTAINER Fabian Mastenbroek
5 |
6 | # Set the home directory to our gradle user's home.
7 | ENV HOME=/home/gradle
8 | ENV APP_HOME=$HOME/simulator
9 |
10 | # Copy OpenDC simulator
11 | COPY ./ $APP_HOME
12 |
13 | # Build as root
14 | USER root
15 |
16 | # Set the working directory to the simulator
17 | WORKDIR $APP_HOME
18 |
19 | # Build the application
20 | RUN gradle --no-daemon assemble installDist
21 |
22 | # Fix permissions
23 | RUN chown -R gradle:gradle $APP_HOME
24 |
25 | # Downgrade user
26 | USER gradle
27 |
28 | # Start the Gradle application on run
29 | CMD opendc-model-odc/setup/build/install/setup/bin/setup
30 |
--------------------------------------------------------------------------------
/opendc-model-odc/setup/build.gradle:
--------------------------------------------------------------------------------
1 | /*
2 | * MIT License
3 | *
4 | * Copyright (c) 2017 atlarge-research
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in all
14 | * copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | * SOFTWARE.
23 | */
24 |
25 | /* Build configuration */
26 | apply from: '../../gradle/kotlin.gradle'
27 | apply plugin: 'application'
28 |
29 | mainClassName = "com.atlarge.opendc.model.odc.platform.JpaPlatformRunnerKt"
30 |
31 | /* Project configuration */
32 | repositories {
33 | jcenter()
34 | }
35 |
36 | dependencies {
37 | compile project(':opendc-model-odc:jpa')
38 | compile project(':opendc-kernel-omega')
39 | compile "io.github.microutils:kotlin-logging:1.4.6"
40 |
41 | runtimeOnly "org.slf4j:slf4j-simple:1.7.25"
42 | runtimeOnly "org.hibernate:hibernate-core:5.2.5.Final"
43 | runtimeOnly "mysql:mysql-connector-java:5.1.13"
44 | }
45 |
--------------------------------------------------------------------------------
/opendc-model-odc/setup/src/main/kotlin/com/atlarge/opendc/model/odc/platform/JpaPlatformRunner.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * MIT License
3 | *
4 | * Copyright (c) 2017 atlarge-research
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in all
14 | * copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | * SOFTWARE.
23 | */
24 |
25 | package com.atlarge.opendc.model.odc.platform
26 |
27 | import com.atlarge.opendc.omega.OmegaKernel
28 | import kotlinx.coroutines.experimental.asCoroutineDispatcher
29 | import kotlinx.coroutines.experimental.launch
30 | import mu.KotlinLogging
31 | import java.util.concurrent.ForkJoinPool
32 | import javax.persistence.Persistence
33 |
34 | val logger = KotlinLogging.logger {}
35 |
36 | /**
37 | * The main entry point of the program. This program polls experiments from a database and runs the
38 | * simulation and reports the results back to the database.
39 | *
40 | * @param args The command line arguments of the program.
41 | */
42 | fun main(args: Array) {
43 | val properties = HashMap()
44 | val env = System.getenv()
45 | properties["javax.persistence.jdbc.url"] = env["PERSISTENCE_URL"] ?: ""
46 | properties["javax.persistence.jdbc.user"] = env["PERSISTENCE_USER"] ?: ""
47 | properties["javax.persistence.jdbc.password"] = env["PERSISTENCE_PASSWORD"] ?: ""
48 |
49 | val factory = Persistence.createEntityManagerFactory("opendc-simulator", properties)
50 |
51 | val collectMachineStates = env["COLLECT_MACHINE_STATES"]?.equals("off", ignoreCase = true)?.not() ?: false
52 | val collectTaskStates = env["COLLECT_TASK_STATES"]?.equals("off", ignoreCase = true)?.not() ?: false
53 | val collectStageMeasurements = env["COLLECT_STAGE_MEASUREMENTS"]?.equals("off", ignoreCase = true)?.not() ?: true
54 | val collectTaskMetrics = env["COLLECT_TASK_METRICS"]?.equals("off", ignoreCase = true)?.not() ?: true
55 | val collectJobMetrics = env["COLLECT_JOB_METRICS"]?.equals("off", ignoreCase = true)?.not() ?: true
56 |
57 | val timeout = 500_000L
58 | val experiments = JpaExperimentManager(
59 | factory = factory,
60 | collectMachineStates = collectMachineStates,
61 | collectTaskStates = collectTaskStates,
62 | collectStageMeasurements = collectStageMeasurements,
63 | collectTaskMetrics = collectTaskMetrics,
64 | collectJobMetrics = collectJobMetrics
65 | )
66 | val kernel = OmegaKernel
67 |
68 | val dispatcher = ForkJoinPool().asCoroutineDispatcher()
69 |
70 | logger.info { "Waiting for enqueued experiments..." }
71 | while (true) {
72 | experiments.poll()?.let { experiment ->
73 | logger.info { "Found experiment. Submitting for simulation now..." }
74 | launch(dispatcher) {
75 | experiment.run(kernel, timeout)
76 | experiment.close()
77 | }
78 | }
79 |
80 | Thread.sleep(500)
81 | }
82 | }
83 |
--------------------------------------------------------------------------------
/opendc-model-odc/setup/src/main/resources/META-INF/persistence.xml:
--------------------------------------------------------------------------------
1 |
2 |
25 |
26 |
30 |
31 | org.hibernate.jpa.HibernatePersistenceProvider
32 | jpa/schema.xml
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
--------------------------------------------------------------------------------
/opendc-stdlib/build.gradle:
--------------------------------------------------------------------------------
1 | /*
2 | * MIT License
3 | *
4 | * Copyright (c) 2017 atlarge-research
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in all
14 | * copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | * SOFTWARE.
23 | */
24 |
25 | /* Build configuration */
26 | apply plugin: 'java-library'
27 | apply from: '../gradle/kotlin.gradle'
28 |
29 | /* Project configuration */
30 | repositories {
31 | jcenter()
32 | }
33 |
34 | dependencies {
35 | implementation "org.jetbrains.kotlin:kotlin-stdlib"
36 | api project(':opendc-core')
37 | implementation "io.github.microutils:kotlin-logging:1.4.6"
38 |
39 | testImplementation "org.junit.jupiter:junit-jupiter-api:$junit_jupiter_version"
40 | testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:$junit_jupiter_version"
41 | testImplementation "org.junit.platform:junit-platform-launcher:$junit_platform_version"
42 | testRuntimeOnly "org.slf4j:slf4j-simple:1.7.25"
43 | testImplementation project(':opendc-kernel-omega')
44 | }
45 |
--------------------------------------------------------------------------------
/opendc-stdlib/src/main/kotlin/com/atlarge/opendc/model/topology/Bootstrap.kt:
--------------------------------------------------------------------------------
1 | package com.atlarge.opendc.model.topology
2 |
3 | import com.atlarge.opendc.simulator.Bootstrap
4 | import com.atlarge.opendc.simulator.Entity
5 | import com.atlarge.opendc.simulator.Process
6 |
7 | /**
8 | * Create a [Bootstrap] procedure for the given [Topology].
9 | *
10 | * @return A apply procedure for the topology.
11 | */
12 | fun T.bootstrap(): Bootstrap = Bootstrap.create { ctx ->
13 | forEach {
14 | if (it is Process<*, *>) {
15 | @Suppress("UNCHECKED_CAST")
16 | ctx.start(it as Process<*, T>)
17 | }
18 | }
19 | listeners += object : TopologyListener {
20 | override fun Topology.onNodeAdded(node: Entity<*>) {
21 | if (node is Process<*, *>) {
22 | @Suppress("UNCHECKED_CAST")
23 | ctx.start(node as Process<*, T>)
24 | }
25 | }
26 |
27 | override fun Topology.onNodeRemoved(node: Entity<*>) {
28 | ctx.stop(node)
29 | }
30 | }
31 | this
32 | }
33 |
--------------------------------------------------------------------------------
/opendc-stdlib/src/main/kotlin/com/atlarge/opendc/model/topology/Component.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * MIT License
3 | *
4 | * Copyright (c) 2017 atlarge-research
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in all
14 | * copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | * SOFTWARE.
23 | */
24 |
25 | package com.atlarge.opendc.model.topology
26 |
27 | /**
28 | * A component within a [Topology], which is either a node or an [Edge] representing the relationship between
29 | * entities within a logical topology of a cloud network.
30 | **
31 | * @author Fabian Mastenbroek (f.s.mastenbroek@student.tudelft.nl)
32 | */
33 | interface Component
34 |
--------------------------------------------------------------------------------
/opendc-stdlib/src/main/kotlin/com/atlarge/opendc/model/topology/Edge.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * MIT License
3 | *
4 | * Copyright (c) 2017 atlarge-research
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in all
14 | * copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | * SOFTWARE.
23 | */
24 |
25 | package com.atlarge.opendc.model.topology
26 |
27 | import com.atlarge.opendc.simulator.Entity
28 |
29 | /**
30 | * An edge that represents a directed relationship between exactly two nodes in a logical topology of a cloud network.
31 | *
32 | * @param T The relationship type the edge represents within a logical topology.
33 | * @author Fabian Mastenbroek (f.s.mastenbroek@student.tudelft.nl)
34 | */
35 | interface Edge : Component {
36 | /**
37 | * The label of this edge.
38 | */
39 | val label: T
40 |
41 | /**
42 | * A tag to uniquely identify the relationship this edge represents.
43 | */
44 | val tag: String?
45 |
46 | /**
47 | * The source of the edge.
48 | *
49 | * This property is not guaranteed to have a runtime complexity of O(1)
, but must be at least
50 | * O(n)
, with respect to the size of the topology.
51 | */
52 | val from: Entity<*>
53 |
54 | /**
55 | * The destination of the edge.
56 | *
57 | * This property is not guaranteed to have a runtime complexity of O(1)
, but must be at least
58 | * O(n)
, with respect to the size of the topology.
59 | */
60 | val to: Entity<*>
61 | }
62 |
--------------------------------------------------------------------------------
/opendc-stdlib/src/main/kotlin/com/atlarge/opendc/model/topology/MutableTopology.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * MIT License
3 | *
4 | * Copyright (c) 2017 atlarge-research
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in all
14 | * copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | * SOFTWARE.
23 | */
24 |
25 | package com.atlarge.opendc.model.topology
26 |
27 | import com.atlarge.opendc.simulator.Entity
28 |
29 | /**
30 | * A subinterface of [Topology] which adds mutation methods. When mutation is not required, users
31 | * should prefer the [Topology] interface.
32 | *
33 | * @author Fabian Mastenbroek (f.s.mastenbroek@student.tudelft.nl)
34 | */
35 | interface MutableTopology : Topology, MutableSet> {
36 | /**
37 | * Create a directed, labeled edge between two nodes in the topology.
38 | *
39 | * @param from The source of the edge.
40 | * @param to The destination of the edge.
41 | * @param label The label of the edge.
42 | * @param tag The tag of the edge that uniquely identifies the relationship the edge represents.
43 | * @return The edge that has been created.
44 | */
45 | fun connect(from: Entity<*>, to: Entity<*>, label: T, tag: String? = null): Edge
46 |
47 | /**
48 | * Create a directed, unlabeled edge between two nodes in the topology.
49 | *
50 | * @param from The source of the edge.
51 | * @param to The destination of the edge.
52 | * @param tag The tag of the edge that uniquely identifies the relationship the edge represents.
53 | * @return The edge that has been created.
54 | */
55 | fun connect(from: Entity<*>, to: Entity<*>, tag: String? = null): Edge =
56 | connect(from, to, Unit, tag)
57 |
58 | /**
59 | * Create a directed, unlabeled edge between two nodes in the topology.
60 | *
61 | * @param dest The destination of the edge.
62 | * @return The edge that has been created.
63 | */
64 | infix fun Entity<*>.to(dest: Entity<*>): Edge = connect(this, dest)
65 | }
66 |
--------------------------------------------------------------------------------
/opendc-stdlib/src/main/kotlin/com/atlarge/opendc/model/topology/Topology.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * MIT License
3 | *
4 | * Copyright (c) 2017 atlarge-research
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in all
14 | * copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | * SOFTWARE.
23 | */
24 |
25 | package com.atlarge.opendc.model.topology
26 |
27 | import com.atlarge.opendc.simulator.Entity
28 |
29 | /**
30 | * A graph data structure which represents the logical topology of a cloud network consisting of one or more
31 | * datacenters.
32 | *
33 | * A topology is [Iterable] and allows implementation-dependent iteration of the nodes in the topology.
34 | *
35 | * @author Fabian Mastenbroek (f.s.mastenbroek@student.tudelft.nl)
36 | */
37 | interface Topology : TopologyContext, Cloneable, Set> {
38 | /**
39 | * The listeners of this topology.
40 | */
41 | val listeners: MutableSet
42 |
43 | /**
44 | * Create a copy of the topology.
45 | *
46 | * @return A new [Topology] with a copy of the graph.
47 | */
48 | public override fun clone(): Topology
49 | }
50 |
51 |
--------------------------------------------------------------------------------
/opendc-stdlib/src/main/kotlin/com/atlarge/opendc/model/topology/TopologyBuilder.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * MIT License
3 | *
4 | * Copyright (c) 2017 atlarge-research
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in all
14 | * copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | * SOFTWARE.
23 | */
24 |
25 | package com.atlarge.opendc.model.topology
26 |
27 | /**
28 | * A builder for [Topology] instances.
29 | *
30 | * @author Fabian Mastenbroek (f.s.mastenbroek@student.tudelft.nl)
31 | */
32 | interface TopologyBuilder : TopologyFactory {
33 | /**
34 | * Construct a [Topology] from the given block and return it.
35 | *
36 | * @param block The block to construct the topology.
37 | * @return The topology that has been built.
38 | */
39 | fun construct(block: MutableTopology.() -> Unit): MutableTopology = create().apply(block)
40 | }
41 |
--------------------------------------------------------------------------------
/opendc-stdlib/src/main/kotlin/com/atlarge/opendc/model/topology/TopologyContext.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * MIT License
3 | *
4 | * Copyright (c) 2017 atlarge-research
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in all
14 | * copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | * SOFTWARE.
23 | */
24 |
25 | package com.atlarge.opendc.model.topology
26 |
27 | import com.atlarge.opendc.simulator.Entity
28 |
29 | /**
30 | * A [TopologyContext] represents the context for entities in a specific topology, providing access to the identifier
31 | * and ingoing and outgoing edges of the [Entity] within a [Topology].
32 | *
33 | * @author Fabian Mastenbroek (f.s.mastenbroek@student.tudelft.nl)
34 | */
35 | interface TopologyContext {
36 | /**
37 | * A unique identifier of an [Entity] within the topology.
38 | */
39 | val Entity<*>.id: Int
40 |
41 | /**
42 | * The set of ingoing edges of an [Entity].
43 | */
44 | val Entity<*>.ingoingEdges: Set>
45 |
46 | /**
47 | * The set of outgoing edges of an [Entity].
48 | */
49 | val Entity<*>.outgoingEdges: Set>
50 | }
51 |
--------------------------------------------------------------------------------
/opendc-stdlib/src/main/kotlin/com/atlarge/opendc/model/topology/TopologyFactory.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * MIT License
3 | *
4 | * Copyright (c) 2017 atlarge-research
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in all
14 | * copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | * SOFTWARE.
23 | */
24 |
25 | package com.atlarge.opendc.model.topology
26 |
27 | /**
28 | * An interface for producing [Topology] instances. Implementors of this interface provide a way of generating a
29 | * topology based on the state of the factory.
30 | *
31 | * @author Fabian Mastenbroek (f.s.mastenbroek@student.tudelft.nl)
32 | */
33 | interface TopologyFactory {
34 | /**
35 | * Create a [MutableTopology] instance.
36 | *
37 | * @return A mutable topology.
38 | */
39 | fun create(): MutableTopology
40 | }
41 |
--------------------------------------------------------------------------------
/opendc-stdlib/src/main/kotlin/com/atlarge/opendc/model/topology/TopologyListener.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * MIT License
3 | *
4 | * Copyright (c) 2017 atlarge-research
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in all
14 | * copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | * SOFTWARE.
23 | */
24 |
25 | package com.atlarge.opendc.model.topology;
26 |
27 | import com.atlarge.opendc.simulator.Entity
28 |
29 | /**
30 | * A listener interface for [Topology] instances. The methods of this interface are invoked on
31 | * mutation of the topology the listener is listening to.
32 | *
33 | * @author Fabian Mastenbroek (f.s.mastenbroek@student.tudelft.nl)
34 | */
35 | interface TopologyListener {
36 | /**
37 | * This method is invoked when an [Entity] is added to the [Topology].
38 | *
39 | * @param node The entity that has been added to the [Topology].
40 | */
41 | fun Topology.onNodeAdded(node: Entity<*>) {}
42 |
43 | /**
44 | * This method is invoked when an [Entity] is removed from the [Topology].
45 | *
46 | * @param node The entity that has been removed from the [Topology].
47 | */
48 | fun Topology.onNodeRemoved(node: Entity<*>) {}
49 |
50 | /**
51 | * This method is invoked when an [Edge] is added to the [Topology].
52 | *
53 | * @param edge The edge that has been added to the [Topology].
54 | */
55 | fun Topology.onEdgeAdded(edge: Edge<*>) {}
56 |
57 | /**
58 | * This method is invoked when an [Edge] is removed from the [Topology].
59 | *
60 | * @param edge The entity that has been removed from the [Topology].
61 | */
62 | fun Topology.onEdgeRemoved(edge: Edge<*>) {}
63 | }
64 |
--------------------------------------------------------------------------------
/opendc-stdlib/src/main/kotlin/com/atlarge/opendc/model/topology/Traversable.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * MIT License
3 | *
4 | * Copyright (c) 2017 atlarge-research
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in all
14 | * copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | * SOFTWARE.
23 | */
24 |
25 | package com.atlarge.opendc.model.topology
26 |
27 | /**
28 | * Filter a [Set] of [Edge]s based on the tag of the edges and return the origin nodes casted to type `T`.
29 | *
30 | * @param tag The tag of the edges to get.
31 | * @return An [Iterable] of the specified type `T` with the given tag.
32 | */
33 | inline fun Set>.origins(tag: String) = filter { it.tag == tag }.map { it.from as T }
34 |
35 | /**
36 | * Filter a [Set] of [Edge]s based on the tag of the edges and return the destination nodes casted to type `T`.
37 | *
38 | * @param tag The tag of the edges to get.
39 | * @return An [Iterable] of the specified type `T` with the given tag.
40 | */
41 | inline fun Set>.destinations(tag: String) = filter { it.tag == tag }.map { it.to as T }
42 |
--------------------------------------------------------------------------------
/opendc-stdlib/src/main/kotlin/com/atlarge/opendc/simulator/Helpers.kt:
--------------------------------------------------------------------------------
1 | package com.atlarge.opendc.simulator
2 |
3 | import kotlin.coroutines.experimental.intrinsics.suspendCoroutineOrReturn
4 |
5 | /**
6 | * Try to find the [Context] instance associated with the [Process] in the call chain which has (indirectly) invoked the
7 | * caller of this method.
8 | *
9 | * Note however that this method does not guarantee type-safety as this method allows the user to cast to a context
10 | * with different generic type arguments.
11 | *
12 | * @return The context that has been found or `null` if this method is not called in a simulation context.
13 | */
14 | suspend fun contextOrNull(): Context? = suspendCoroutineOrReturn { it.context[Context] }
15 |
16 | /**
17 | * Find the [Context] instance associated with the [Process] in the call chain which has (indirectly) invoked the
18 | * caller of this method.
19 | *
20 | * Note however that this method does not guarantee type-safety as this method allows the user to cast to a context
21 | * with different generic type arguments.
22 | *
23 | * @throws IllegalStateException if the context cannot be found.
24 | * @return The context that has been found.
25 | */
26 | suspend fun context(): Context =
27 | contextOrNull() ?: throw IllegalStateException("The suspending call does not have an associated process context")
28 |
29 | /**
30 | * Try to find the untyped [Context] instance associated with the [Process] in the call chain which has (indirectly)
31 | * invoked the caller of this method.
32 | *
33 | * @return The untyped context that has been found or `null` if this method is not called in a simulation context.
34 | */
35 | suspend fun untypedContextOrNull(): Context<*, *>? = contextOrNull()
36 |
37 | /**
38 | * Find the [Context] instance associated with the [Process] in the call chain which has (indirectly) invoked the
39 | * caller of this method.
40 | *
41 | * @throws IllegalStateException if the context cannot be found.
42 | * @return The untyped context that has been found.
43 | */
44 | suspend fun untypedContext(): Context<*, *> = context()
45 |
--------------------------------------------------------------------------------
/opendc-stdlib/src/main/kotlin/com/atlarge/opendc/simulator/instrumentation/Helpers.kt:
--------------------------------------------------------------------------------
1 | package com.atlarge.opendc.simulator.instrumentation
2 |
3 | import kotlinx.coroutines.experimental.Unconfined
4 | import kotlinx.coroutines.experimental.channels.ReceiveChannel
5 | import kotlinx.coroutines.experimental.channels.consumeEach
6 | import kotlinx.coroutines.experimental.channels.produce
7 | import kotlinx.coroutines.experimental.channels.toChannel
8 | import kotlinx.coroutines.experimental.launch
9 | import kotlin.coroutines.experimental.CoroutineContext
10 | import kotlin.coroutines.experimental.coroutineContext
11 |
12 | /**
13 | * Transform each element in the channel into a [ReceiveChannel] of output elements that is then flattened into the
14 | * output stream by emitting elements from the channels as they become available.
15 | *
16 | * @param context The [CoroutineContext] to run the operation in.
17 | * @param transform The function to transform the elements into channels.
18 | * @return The flattened [ReceiveChannel] of merged elements.
19 | */
20 | fun ReceiveChannel.flatMapMerge(context: CoroutineContext = Unconfined,
21 | transform: suspend (E) -> ReceiveChannel): ReceiveChannel =
22 | produce(context) {
23 | val job = launch(Unconfined) {
24 | consumeEach {
25 | launch(coroutineContext) {
26 | transform(it).toChannel(this@produce)
27 | }
28 | }
29 | }
30 | job.join()
31 | }
32 |
33 | /**
34 | * Merge this channel with the other channel into an output stream by emitting elements from the channels as they
35 | * become available.
36 | *
37 | * @param context The [CoroutineContext] to run the operation in.
38 | * @param other The other channel to merge with.
39 | * @return The [ReceiveChannel] of merged elements.
40 | */
41 | fun ReceiveChannel.merge(context: CoroutineContext = Unconfined,
42 | other: ReceiveChannel): ReceiveChannel =
43 | produce(context) {
44 | val job = launch(Unconfined) {
45 | launch(coroutineContext) { toChannel(this@produce) }
46 | launch(coroutineContext) { other.toChannel(this@produce) }
47 | }
48 | job.join()
49 | }
50 |
--------------------------------------------------------------------------------
/opendc-stdlib/src/main/kotlin/com/atlarge/opendc/simulator/util/EventBus.kt:
--------------------------------------------------------------------------------
1 | package com.atlarge.opendc.simulator.util
2 |
3 | import com.atlarge.opendc.simulator.Context
4 | import com.atlarge.opendc.simulator.Entity
5 | import com.atlarge.opendc.simulator.Process
6 | import com.atlarge.opendc.simulator.instrumentation.Instrument
7 | import com.atlarge.opendc.simulator.untypedContext
8 |
9 | /**
10 | * A mechanism for publish-subscribe-style communication between entities without requiring the entities to
11 | * explicitly register with one another (and thus be aware of each other).
12 | *
13 | * Please not that the event bus does not preserve the sender of the published events. If you need a reference to the
14 | * original sender you have to provide it inside the message.
15 | *
16 | * @author Fabian Mastenbroek (f.s.mastenbroek@student.tudelft.nl)
17 | */
18 | class EventBus : Process {
19 | /**
20 | * The state of the event bus.
21 | */
22 | data class State(val subscribers: Set> = emptySet())
23 |
24 | /**
25 | * The initial state of the event bus.
26 | */
27 | override val initialState = EventBus.State()
28 |
29 | /**
30 | * Run the simulation process for this entity.
31 | */
32 | override suspend fun Context.run() {
33 | while (true) {
34 | val msg = receive()
35 | when (msg) {
36 | Subscribe ->
37 | if (sender != null) {
38 | state = state.copy(subscribers = state.subscribers.plus(sender!!))
39 | }
40 | Unsubscribe ->
41 | if (sender != null) {
42 | state = state.copy(subscribers = state.subscribers.minus(sender!!))
43 | }
44 | is Publish ->
45 | state.subscribers.forEach {
46 | it.send(msg.event)
47 | }
48 | }
49 | }
50 | }
51 |
52 | /**
53 | * Subscribe to this [EventBus] with the calling process.
54 | *
55 | * @throws IllegalStateException if the context cannot be found.
56 | */
57 | suspend fun subscribe() = untypedContext().run { this@EventBus.send(Subscribe) }
58 |
59 | /**
60 | * Unsubscribe to from [EventBus] with the calling process.
61 | *
62 | * @throws IllegalStateException if the context cannot be found.
63 | */
64 | suspend fun unsubscribe() = untypedContext().run { this@EventBus.send(Unsubscribe) }
65 |
66 | /**
67 | * Publish the given event to the [EventBus] with the calling process.
68 | *
69 | * @param event The event to publish.
70 | * @throws IllegalStateException if the context cannot be found.
71 | */
72 | suspend fun publish(event: Any) = untypedContext().run { this@EventBus.send(Publish(event)) }
73 |
74 | /**
75 | * This message is sent to the [EventBus] in order to subscribe to the bus
76 | * as sender of the message.
77 | */
78 | object Subscribe
79 |
80 | /**
81 | * This message is sent to the [EventBus] in order to unsubscribe from the
82 | * bus.
83 | */
84 | object Unsubscribe
85 |
86 | /**
87 | * This message is used to publish an event in the bus.
88 | *
89 | * @property event The event to publish.
90 | */
91 | data class Publish(val event: Any)
92 | }
93 |
94 | /**
95 | * Create an [Instrument] which listens to the event bus and publishes all events into a channel which can be processed
96 | * by the user.
97 | */
98 | fun EventBus.instrument(): Instrument = {
99 | subscribe()
100 | while (!isClosedForSend) {
101 | val event = receive()
102 |
103 | if (sender == this@instrument) {
104 | send(event)
105 | }
106 | }
107 | unsubscribe()
108 | }
109 |
--------------------------------------------------------------------------------
/opendc-stdlib/src/test/kotlin/com/atlarge/opendc/simulator/util/EventBusTest.kt:
--------------------------------------------------------------------------------
1 | package com.atlarge.opendc.simulator.util
2 |
3 | import com.atlarge.opendc.omega.OmegaKernel
4 | import com.atlarge.opendc.simulator.Bootstrap
5 | import com.atlarge.opendc.simulator.Context
6 | import com.atlarge.opendc.simulator.Process
7 | import com.atlarge.opendc.simulator.kernel.Simulation
8 | import kotlinx.coroutines.experimental.Unconfined
9 | import kotlinx.coroutines.experimental.channels.first
10 | import kotlinx.coroutines.experimental.launch
11 | import kotlinx.coroutines.experimental.runBlocking
12 | import kotlinx.coroutines.experimental.withTimeout
13 | import org.junit.jupiter.api.Assertions.assertEquals
14 | import org.junit.jupiter.api.Assertions.assertNull
15 | import org.junit.jupiter.api.Test
16 |
17 | /**
18 | * Test cases for the [EventBus] component.
19 | *
20 | * @author Fabian Mastenbroek (f.s.mastenbroek@student.tudelft.nl)
21 | */
22 | internal class EventBusTest {
23 | @Test
24 | fun `subscribe-publish`() {
25 | val bus = EventBus()
26 | val test = object : Process {
27 | override val initialState = Unit
28 |
29 | override suspend fun Context.run() {
30 | // Subscribe to event bus
31 | bus.subscribe()
32 |
33 | // Get first event
34 | assertEquals(receive(5)!!, 1)
35 | }
36 | }
37 |
38 | val simulation: Simulation = OmegaKernel.create(Bootstrap.create {
39 | it.start(bus)
40 | it.start(test)
41 | it.schedule(EventBus.Publish(1), bus, delay = 2)
42 | })
43 |
44 | simulation.run(10)
45 | }
46 |
47 | @Test
48 | fun `subscribe-unsubscribe-publish`() {
49 | val bus = EventBus()
50 | val test = object : Process {
51 | override val initialState = Unit
52 |
53 | override suspend fun Context.run() {
54 | // Subscribe to event bus
55 | bus.subscribe()
56 |
57 | // Unsubscribe from the bus
58 | bus.unsubscribe()
59 |
60 | // Get first event
61 | assertNull(receive(5))
62 | }
63 | }
64 |
65 | val simulation: Simulation = OmegaKernel.create(Bootstrap.create {
66 | it.start(bus)
67 | it.start(test)
68 | it.schedule(EventBus.Publish(1), bus, delay = 2)
69 | })
70 |
71 | simulation.run(10)
72 | }
73 |
74 | @Test
75 | fun subscribe_another_process() {
76 | val bus = EventBus()
77 | val testA = object : Process {
78 | override val initialState = Unit
79 |
80 | override suspend fun Context.run() {
81 | assertEquals(receive(5)!!, 2)
82 | }
83 | }
84 |
85 | val testB = object : Process {
86 | override val initialState = Unit
87 |
88 | override suspend fun Context.run() {
89 | bus.send(EventBus.Subscribe, sender = testA)
90 | }
91 | }
92 |
93 | val simulation: Simulation = OmegaKernel.create(Bootstrap.create {
94 | it.start(bus)
95 | it.start(testA)
96 | it.start(testB)
97 | it.schedule(EventBus.Publish(2), bus, delay = 2)
98 | })
99 |
100 | simulation.run(10)
101 | }
102 |
103 | @Test
104 | fun `event-bus-instrument`() {
105 | val bus = EventBus()
106 |
107 | val simulation: Simulation = OmegaKernel.create(Bootstrap.create {
108 | it.start(bus)
109 | it.schedule(EventBus.Publish(1), bus, delay = 2)
110 | })
111 |
112 | val events = simulation.openPort().install(bus.instrument())
113 |
114 | val job = launch(Unconfined) {
115 | assertEquals(1, events.first())
116 | }
117 |
118 | simulation.run(10)
119 |
120 | runBlocking {
121 | withTimeout(100) {
122 | job.join()
123 | }
124 | }
125 | }
126 |
127 | }
128 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | /*
2 | * MIT License
3 | *
4 | * Copyright (c) 2017 atlarge-research
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in all
14 | * copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | * SOFTWARE.
23 | */
24 | rootProject.name = "opendc-simulator"
25 |
26 | include 'opendc-core'
27 | include 'opendc-kernel-omega'
28 | include 'opendc-stdlib'
29 | include 'opendc-model-odc:core'
30 | include 'opendc-model-odc:jpa'
31 | include 'opendc-model-odc:sc18'
32 | include 'opendc-model-odc:setup'
33 |
--------------------------------------------------------------------------------