Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added power sources to OpenDC #258

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
import org.opendc.compute.simulator.host.SimHost;
import org.opendc.compute.simulator.scheduler.ComputeScheduler;
import org.opendc.compute.simulator.telemetry.SchedulerStats;
import org.opendc.simulator.compute.power.SimPowerSource;
import org.opendc.simulator.compute.workload.Workload;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -97,6 +98,11 @@ public final class ComputeService implements AutoCloseable {
*/
private final Set<HostView> availableHosts = new HashSet<>();

/**
* The available powerSources
*/
private final Set<SimPowerSource> powerSources = new HashSet<>();

/**
* The tasks that should be launched by the service.
*/
Expand Down Expand Up @@ -283,6 +289,15 @@ public void addHost(SimHost host) {
host.addListener(hostListener);
}

public void addPowerSource(SimPowerSource simPowerSource) {
// Check if host is already known
if (powerSources.contains(simPowerSource)) {
return;
}

powerSources.add(simPowerSource);
}

/**
* Remove a {@link SimHost} from the scheduling pool of the compute service.
*/
Expand Down Expand Up @@ -313,6 +328,10 @@ public InstantSource getClock() {
return this.clock;
}

public Set<SimPowerSource> getPowerSources() {
return Collections.unmodifiableSet(this.powerSources);
}

/**
* Collect the statistics about the scheduler component of this service.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import org.opendc.compute.simulator.telemetry.GuestCpuStats
import org.opendc.compute.simulator.telemetry.GuestSystemStats
import org.opendc.compute.simulator.telemetry.HostCpuStats
import org.opendc.compute.simulator.telemetry.HostSystemStats
import org.opendc.simulator.Multiplexer
import org.opendc.simulator.compute.cpu.CpuPowerModel
import org.opendc.simulator.compute.machine.SimMachine
import org.opendc.simulator.compute.models.MachineModel
Expand Down Expand Up @@ -61,6 +62,7 @@ public class SimHost(
private val graph: FlowGraph,
private val machineModel: MachineModel,
private val powerModel: CpuPowerModel,
private val powerMux: Multiplexer
) : AutoCloseable {
/**
* The event listeners registered with this host.
Expand Down Expand Up @@ -130,6 +132,7 @@ public class SimHost(
this.graph,
this.machineModel,
this.powerModel,
this.powerMux
) { cause ->
hostState = if (cause != null) HostState.ERROR else HostState.DOWN
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ package org.opendc.compute.simulator.provisioner
import org.opendc.compute.carbon.CarbonTrace
import org.opendc.compute.simulator.scheduler.ComputeScheduler
import org.opendc.compute.simulator.telemetry.ComputeMonitor
import org.opendc.compute.topology.specs.ClusterSpec
import org.opendc.compute.topology.specs.HostSpec
import java.time.Duration

Expand Down Expand Up @@ -74,7 +75,7 @@ public fun registerComputeMonitor(
*/
public fun setupHosts(
serviceDomain: String,
specs: List<HostSpec>,
specs: List<ClusterSpec>,
): ProvisioningStep {
return HostsProvisioningStep(serviceDomain, specs)
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ package org.opendc.compute.simulator.provisioner

import org.opendc.compute.simulator.host.SimHost
import org.opendc.compute.simulator.service.ComputeService
import org.opendc.compute.topology.specs.ClusterSpec
import org.opendc.compute.topology.specs.HostSpec
import org.opendc.simulator.Multiplexer
import org.opendc.simulator.compute.power.SimPowerSource
import org.opendc.simulator.engine.FlowEngine

/**
Expand All @@ -36,37 +39,57 @@ import org.opendc.simulator.engine.FlowEngine
*/
public class HostsProvisioningStep internal constructor(
private val serviceDomain: String,
private val specs: List<HostSpec>,
private val clusterSpecs: List<ClusterSpec>,
) : ProvisioningStep {
override fun apply(ctx: ProvisioningContext): AutoCloseable {
val service =
requireNotNull(
ctx.registry.resolve(serviceDomain, ComputeService::class.java),
) { "Compute service $serviceDomain does not exist" }
val hosts = mutableSetOf<SimHost>()
val simHosts = mutableSetOf<SimHost>()
val simPowerSources = mutableListOf<SimPowerSource>()

val flowEngine = FlowEngine.create(ctx.dispatcher)
val flowGraph = flowEngine.newGraph()
val engine = FlowEngine.create(ctx.dispatcher)
val graph = engine.newGraph()

for (spec in specs) {
val host =
SimHost(
spec.uid,
spec.name,
spec.meta,
ctx.dispatcher.timeSource,
flowGraph,
spec.model,
spec.cpuPowerModel,
)
for (cluster in clusterSpecs){

require(hosts.add(host)) { "Host with uid ${spec.uid} already exists" }
service.addHost(host)
// Create the Power Source to which hosts are connected
// TODO: Add connection to totalPower
val simPowerSource = SimPowerSource(graph)
service.addPowerSource(simPowerSource)
simPowerSources.add(simPowerSource)

val powerMux = Multiplexer(graph)
graph.addEdge(powerMux, simPowerSource)

// Create hosts, they are connected to the powerMux when SimMachine is created
for (hostSpec in cluster.hostSpecs) {
val simHost =
SimHost(
hostSpec.uid,
hostSpec.name,
hostSpec.meta,
ctx.dispatcher.timeSource,
graph,
hostSpec.model,
hostSpec.cpuPowerModel,
powerMux
)

require(simHosts.add(simHost)) { "Host with uid ${hostSpec.uid} already exists" }
service.addHost(simHost)
}
}

return AutoCloseable {
for (host in hosts) {
host.close()
for (simHost in simHosts) {
simHost.close()
}

for (simPowerSource in simPowerSources){
// TODO: add close function
// simPowerSource.close()
}
}
}
Expand Down
Loading
Loading