From 3363df4c72a064e590ca98f8e01832cfa4e15a3f Mon Sep 17 00:00:00 2001 From: Dante Niewenhuis Date: Tue, 27 Aug 2024 13:48:46 +0200 Subject: Renamed input files and internally server is changed to task (#246) * Updated SimTrace to use a single ArrayDeque instead of three separate lists for deadline, cpuUsage, and coreCount * Renamed input files to tasks.parquet and fragments.parquet. Renamed server to task. OpenDC nows exports tasks.parquet instead of server.parquet --- .../org/opendc/compute/service/ComputeService.java | 178 +++++++------- .../org/opendc/compute/service/ServiceServer.java | 255 --------------------- .../org/opendc/compute/service/ServiceTask.java | 255 +++++++++++++++++++++ .../org/opendc/compute/service/driver/Host.java | 52 ++--- .../compute/service/driver/HostListener.java | 8 +- .../service/driver/telemetry/HostSystemStats.java | 2 +- .../compute/service/telemetry/SchedulerStats.java | 12 +- 7 files changed, 379 insertions(+), 383 deletions(-) delete mode 100644 opendc-compute/opendc-compute-service/src/main/java/org/opendc/compute/service/ServiceServer.java create mode 100644 opendc-compute/opendc-compute-service/src/main/java/org/opendc/compute/service/ServiceTask.java (limited to 'opendc-compute/opendc-compute-service/src/main/java/org/opendc') diff --git a/opendc-compute/opendc-compute-service/src/main/java/org/opendc/compute/service/ComputeService.java b/opendc-compute/opendc-compute-service/src/main/java/org/opendc/compute/service/ComputeService.java index a7e9f509..a64f6a4e 100644 --- a/opendc-compute/opendc-compute-service/src/main/java/org/opendc/compute/service/ComputeService.java +++ b/opendc-compute/opendc-compute-service/src/main/java/org/opendc/compute/service/ComputeService.java @@ -44,8 +44,8 @@ import org.opendc.common.util.Pacer; import org.opendc.compute.api.ComputeClient; import org.opendc.compute.api.Flavor; import org.opendc.compute.api.Image; -import org.opendc.compute.api.Server; -import org.opendc.compute.api.ServerState; +import org.opendc.compute.api.Task; +import org.opendc.compute.api.TaskState; import org.opendc.compute.service.driver.Host; import org.opendc.compute.service.driver.HostListener; import org.opendc.compute.service.driver.HostModel; @@ -68,7 +68,7 @@ public final class ComputeService implements AutoCloseable { private final InstantSource clock; /** - * The {@link ComputeScheduler} responsible for placing the servers onto hosts. + * The {@link ComputeScheduler} responsible for placing the tasks onto hosts. */ private final ComputeScheduler scheduler; @@ -98,14 +98,14 @@ public final class ComputeService implements AutoCloseable { private final Set availableHosts = new HashSet<>(); /** - * The servers that should be launched by the service. + * The tasks that should be launched by the service. */ - private final Deque queue = new ArrayDeque<>(); + private final Deque taskQueue = new ArrayDeque<>(); /** - * The active servers in the system. + * The active tasks in the system. */ - private final Map activeServers = new HashMap<>(); + private final Map activeTasks = new HashMap<>(); /** * The registered flavors for this compute service. @@ -122,14 +122,14 @@ public final class ComputeService implements AutoCloseable { private final List images = new ArrayList<>(); /** - * The registered servers for this compute service. + * The registered tasks for this compute service. */ - private final Map serverById = new HashMap<>(); + private final Map taskById = new HashMap<>(); - private final List servers = new ArrayList<>(); + private final List tasks = new ArrayList<>(); /** - * A [HostListener] used to track the active servers. + * A [HostListener] used to track the active tasks. */ private final HostListener hostListener = new HostListener() { @Override @@ -151,28 +151,26 @@ public final class ComputeService implements AutoCloseable { } @Override - public void onStateChanged(@NotNull Host host, @NotNull Server server, @NotNull ServerState newState) { - final ServiceServer serviceServer = (ServiceServer) server; + public void onStateChanged(@NotNull Host host, @NotNull Task task, @NotNull TaskState newState) { + final ServiceTask serviceTask = (ServiceTask) task; - if (serviceServer.getHost() != host) { - // This can happen when a server is rescheduled and started on another machine, while being deleted from + if (serviceTask.getHost() != host) { + // This can happen when a task is rescheduled and started on another machine, while being deleted from // the old machine. return; } - serviceServer.setState(newState); + serviceTask.setState(newState); - if (newState == ServerState.TERMINATED - || newState == ServerState.DELETED - || newState == ServerState.ERROR) { - LOGGER.info("Server {} {} {} finished", server.getUid(), server.getName(), server.getFlavor()); + if (newState == TaskState.TERMINATED || newState == TaskState.DELETED || newState == TaskState.ERROR) { + LOGGER.info("task {} {} {} finished", task.getUid(), task.getName(), task.getFlavor()); - if (activeServers.remove(server) != null) { - serversActive--; + if (activeTasks.remove(task) != null) { + tasksActive--; } HostView hv = hostToView.get(host); - final ServiceFlavor flavor = serviceServer.getFlavor(); + final ServiceFlavor flavor = serviceTask.getFlavor(); if (hv != null) { hv.provisionedCores -= flavor.getCoreCount(); hv.instanceCount--; @@ -192,8 +190,8 @@ public final class ComputeService implements AutoCloseable { private long attemptsSuccess = 0L; private long attemptsFailure = 0L; private long attemptsError = 0L; - private int serversPending = 0; - private int serversActive = 0; + private int tasksPending = 0; + private int tasksActive = 0; /** * Construct a {@link ComputeService} instance. @@ -222,10 +220,10 @@ public final class ComputeService implements AutoCloseable { } /** - * Return the {@link Server}s hosted by this service. + * Return the {@link Task}s hosted by this service. */ - public List getServers() { - return Collections.unmodifiableList(servers); + public List getTasks() { + return Collections.unmodifiableList(tasks); } /** @@ -265,15 +263,14 @@ public final class ComputeService implements AutoCloseable { } /** - * Lookup the {@link Host} that currently hosts the specified {@link Server}. + * Lookup the {@link Host} that currently hosts the specified {@link Task}. */ - public Host lookupHost(Server server) { - if (server instanceof ServiceServer) { - return ((ServiceServer) server).getHost(); + public Host lookupHost(Task task) { + if (task instanceof ServiceTask) { + return ((ServiceTask) task).getHost(); } - ServiceServer internal = - Objects.requireNonNull(serverById.get(server.getUid()), "Invalid server passed to lookupHost"); + ServiceTask internal = Objects.requireNonNull(taskById.get(task.getUid()), "Invalid task passed to lookupHost"); return internal.getHost(); } @@ -294,9 +291,9 @@ public final class ComputeService implements AutoCloseable { attemptsSuccess, attemptsFailure, attemptsError, - servers.size(), - serversPending, - serversActive); + tasks.size(), + tasksPending, + tasksActive); } @Override @@ -310,17 +307,17 @@ public final class ComputeService implements AutoCloseable { } /** - * Enqueue the specified [server] to be scheduled onto a host. + * Enqueue the specified [task] to be scheduled onto a host. */ - SchedulingRequest schedule(ServiceServer server) { - LOGGER.debug("Enqueueing server {} to be assigned to host", server.getUid()); + SchedulingRequest schedule(ServiceTask task) { + LOGGER.debug("Enqueueing task {} to be assigned to host", task.getUid()); long now = clock.millis(); - SchedulingRequest request = new SchedulingRequest(server, now); + SchedulingRequest request = new SchedulingRequest(task, now); - server.launchedAt = Instant.ofEpochMilli(now); - queue.add(request); - serversPending++; + task.launchedAt = Instant.ofEpochMilli(now); + taskQueue.add(request); + tasksPending++; requestSchedulingCycle(); return request; } @@ -335,9 +332,9 @@ public final class ComputeService implements AutoCloseable { images.remove(image); } - void delete(ServiceServer server) { - serverById.remove(server.getUid()); - servers.remove(server); + void delete(ServiceTask task) { + taskById.remove(task.getUid()); + tasks.remove(task); } /** @@ -345,7 +342,7 @@ public final class ComputeService implements AutoCloseable { */ private void requestSchedulingCycle() { // Bail out in case the queue is empty. - if (queue.isEmpty()) { + if (taskQueue.isEmpty()) { return; } @@ -358,35 +355,34 @@ public final class ComputeService implements AutoCloseable { private void doSchedule() { // reorder tasks - while (!queue.isEmpty()) { - SchedulingRequest request = queue.peek(); + while (!taskQueue.isEmpty()) { + SchedulingRequest request = taskQueue.peek(); if (request.isCancelled) { - queue.poll(); - serversPending--; + taskQueue.poll(); + tasksPending--; continue; } - final ServiceServer server = request.server; + final ServiceTask task = request.task; // Check if all dependencies are met // otherwise continue - final ServiceFlavor flavor = server.getFlavor(); - final HostView hv = scheduler.select(request.server); + final ServiceFlavor flavor = task.getFlavor(); + final HostView hv = scheduler.select(request.task); - if (hv == null || !hv.getHost().canFit(server)) { - LOGGER.trace( - "Server {} selected for scheduling but no capacity available for it at the moment", server); + if (hv == null || !hv.getHost().canFit(task)) { + LOGGER.trace("Task {} selected for scheduling but no capacity available for it at the moment", task); if (flavor.getMemorySize() > maxMemory || flavor.getCoreCount() > maxCores) { // Remove the incoming image - queue.poll(); - serversPending--; + taskQueue.poll(); + tasksPending--; attemptsFailure++; - LOGGER.warn("Failed to spawn {}: does not fit", server); + LOGGER.warn("Failed to spawn {}: does not fit", task); - server.setState(ServerState.TERMINATED); + task.setState(TaskState.TERMINATED); continue; } else { break; @@ -396,25 +392,25 @@ public final class ComputeService implements AutoCloseable { Host host = hv.getHost(); // Remove request from queue - queue.poll(); - serversPending--; + taskQueue.poll(); + tasksPending--; - LOGGER.info("Assigned server {} to host {}", server, host); + LOGGER.info("Assigned task {} to host {}", task, host); try { - server.host = host; + task.host = host; - host.spawn(server); - host.start(server); + host.spawn(task); + host.start(task); - serversActive++; + tasksActive++; attemptsSuccess++; hv.instanceCount++; hv.provisionedCores += flavor.getCoreCount(); hv.availableMemory -= flavor.getMemorySize(); - activeServers.put(server, host); + activeTasks.put(task, host); } catch (Exception cause) { LOGGER.error("Failed to deploy VM", cause); attemptsError++; @@ -537,7 +533,7 @@ public final class ComputeService implements AutoCloseable { @NotNull @Override - public Server newServer( + public Task newTask( @NotNull String name, @NotNull Image image, @NotNull Flavor flavor, @@ -554,31 +550,31 @@ public final class ComputeService implements AutoCloseable { final ServiceImage internalImage = Objects.requireNonNull(service.imageById.get(image.getUid()), "Unknown image"); - ServiceServer server = new ServiceServer(service, uid, name, internalFlavor, internalImage, labels, meta); + ServiceTask task = new ServiceTask(service, uid, name, internalFlavor, internalImage, labels, meta); - service.serverById.put(uid, server); - service.servers.add(server); + service.taskById.put(uid, task); + service.tasks.add(task); if (start) { - server.start(); + task.start(); } - return server; + return task; } @Nullable @Override - public Server findServer(@NotNull UUID id) { + public Task findTask(@NotNull UUID id) { checkOpen(); - return service.serverById.get(id); + return service.taskById.get(id); } @NotNull @Override - public List queryServers() { + public List queryTasks() { checkOpen(); - return new ArrayList<>(service.servers); + return new ArrayList<>(service.tasks); } @Override @@ -593,30 +589,30 @@ public final class ComputeService implements AutoCloseable { @Nullable @Override - public void rescheduleServer(@NotNull Server server, @NotNull SimWorkload workload) { - ServiceServer internalServer = (ServiceServer) findServer(server.getUid()); - Host from = service.lookupHost(internalServer); + public void rescheduleTask(@NotNull Task task, @NotNull SimWorkload workload) { + ServiceTask internalTask = (ServiceTask) findTask(task.getUid()); + Host from = service.lookupHost(internalTask); - from.delete(internalServer); + from.delete(internalTask); - internalServer.host = null; + internalTask.host = null; - internalServer.setWorkload(workload); - internalServer.start(); + internalTask.setWorkload(workload); + internalTask.start(); } } /** - * A request to schedule a {@link ServiceServer} onto one of the {@link Host}s. + * A request to schedule a {@link ServiceTask} onto one of the {@link Host}s. */ static class SchedulingRequest { - final ServiceServer server; + final ServiceTask task; final long submitTime; boolean isCancelled; - SchedulingRequest(ServiceServer server, long submitTime) { - this.server = server; + SchedulingRequest(ServiceTask task, long submitTime) { + this.task = task; this.submitTime = submitTime; } } diff --git a/opendc-compute/opendc-compute-service/src/main/java/org/opendc/compute/service/ServiceServer.java b/opendc-compute/opendc-compute-service/src/main/java/org/opendc/compute/service/ServiceServer.java deleted file mode 100644 index e363faf2..00000000 --- a/opendc-compute/opendc-compute-service/src/main/java/org/opendc/compute/service/ServiceServer.java +++ /dev/null @@ -1,255 +0,0 @@ -/* - * Copyright (c) 2022 AtLarge Research - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package org.opendc.compute.service; - -import java.time.Instant; -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Objects; -import java.util.UUID; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; -import org.opendc.compute.api.Server; -import org.opendc.compute.api.ServerState; -import org.opendc.compute.api.ServerWatcher; -import org.opendc.compute.service.driver.Host; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Implementation of {@link Server} provided by {@link ComputeService}. - */ -public final class ServiceServer implements Server { - private static final Logger LOGGER = LoggerFactory.getLogger(ServiceServer.class); - - private final ComputeService service; - private final UUID uid; - - private final String name; - private final ServiceFlavor flavor; - private final ServiceImage image; - private final Map labels; - private Map meta; - - private final List watchers = new ArrayList<>(); - private ServerState state = ServerState.TERMINATED; - Instant launchedAt = null; - Host host = null; - private ComputeService.SchedulingRequest request = null; - - ServiceServer( - ComputeService service, - UUID uid, - String name, - ServiceFlavor flavor, - ServiceImage image, - Map labels, - Map meta) { - this.service = service; - this.uid = uid; - this.name = name; - this.flavor = flavor; - this.image = image; - this.labels = labels; - this.meta = meta; - } - - @NotNull - @Override - public UUID getUid() { - return uid; - } - - @NotNull - @Override - public String getName() { - return name; - } - - @NotNull - @Override - public ServiceFlavor getFlavor() { - return flavor; - } - - @NotNull - @Override - public ServiceImage getImage() { - return image; - } - - @NotNull - @Override - public Map getLabels() { - return Collections.unmodifiableMap(labels); - } - - @NotNull - @Override - public Map getMeta() { - return Collections.unmodifiableMap(meta); - } - - public void setWorkload(Object _workload) { - Map new_meta = new HashMap(); - new_meta.put("workload", _workload); - - meta = new_meta; - } - - @NotNull - @Override - public ServerState getState() { - return state; - } - - @Nullable - @Override - public Instant getLaunchedAt() { - return launchedAt; - } - - /** - * Return the {@link Host} on which the server is running or null if it is not running on a host. - */ - public Host getHost() { - return host; - } - - @Override - public void start() { - switch (state) { - case PROVISIONING: - LOGGER.debug("User tried to start server but request is already pending: doing nothing"); - case RUNNING: - LOGGER.debug("User tried to start server but server is already running"); - break; - case DELETED: - LOGGER.warn("User tried to start deleted server"); - throw new IllegalStateException("Server is deleted"); - default: - LOGGER.info("User requested to start server {}", uid); - setState(ServerState.PROVISIONING); - assert request == null : "Scheduling request already active"; - request = service.schedule(this); - break; - } - } - - @Override - public void stop() { - switch (state) { - case PROVISIONING: - cancelProvisioningRequest(); - setState(ServerState.TERMINATED); - break; - case RUNNING: - case ERROR: - final Host host = this.host; - if (host == null) { - throw new IllegalStateException("Server not running"); - } - host.stop(this); - break; - } - } - - @Override - public void watch(@NotNull ServerWatcher watcher) { - watchers.add(watcher); - } - - @Override - public void unwatch(@NotNull ServerWatcher watcher) { - watchers.remove(watcher); - } - - @Override - public void reload() { - // No-op: this object is the source-of-truth - } - - @Override - public void delete() { - switch (state) { - case PROVISIONING: - case TERMINATED: - cancelProvisioningRequest(); - service.delete(this); - setState(ServerState.DELETED); - break; - case RUNNING: - case ERROR: - final Host host = this.host; - if (host == null) { - throw new IllegalStateException("Server not running"); - } - host.delete(this); - service.delete(this); - setState(ServerState.DELETED); - break; - } - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - ServiceServer server = (ServiceServer) o; - return service.equals(server.service) && uid.equals(server.uid); - } - - @Override - public int hashCode() { - return Objects.hash(service, uid); - } - - @Override - public String toString() { - return "Server[uid=" + uid + ",name=" + name + ",state=" + state + "]"; - } - - void setState(ServerState state) { - if (this.state != state) { - for (ServerWatcher watcher : watchers) { - watcher.onStateChanged(this, state); - } - } - - this.state = state; - } - - /** - * Cancel the provisioning request if active. - */ - private void cancelProvisioningRequest() { - final ComputeService.SchedulingRequest request = this.request; - if (request != null) { - this.request = null; - request.isCancelled = true; - } - } -} diff --git a/opendc-compute/opendc-compute-service/src/main/java/org/opendc/compute/service/ServiceTask.java b/opendc-compute/opendc-compute-service/src/main/java/org/opendc/compute/service/ServiceTask.java new file mode 100644 index 00000000..e981921a --- /dev/null +++ b/opendc-compute/opendc-compute-service/src/main/java/org/opendc/compute/service/ServiceTask.java @@ -0,0 +1,255 @@ +/* + * Copyright (c) 2022 AtLarge Research + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package org.opendc.compute.service; + +import java.time.Instant; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.UUID; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; +import org.opendc.compute.api.Task; +import org.opendc.compute.api.TaskState; +import org.opendc.compute.api.TaskWatcher; +import org.opendc.compute.service.driver.Host; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Implementation of {@link Task} provided by {@link ComputeService}. + */ +public final class ServiceTask implements Task { + private static final Logger LOGGER = LoggerFactory.getLogger(ServiceTask.class); + + private final ComputeService service; + private final UUID uid; + + private final String name; + private final ServiceFlavor flavor; + private final ServiceImage image; + private final Map labels; + private Map meta; + + private final List watchers = new ArrayList<>(); + private TaskState state = TaskState.TERMINATED; + Instant launchedAt = null; + Host host = null; + private ComputeService.SchedulingRequest request = null; + + ServiceTask( + ComputeService service, + UUID uid, + String name, + ServiceFlavor flavor, + ServiceImage image, + Map labels, + Map meta) { + this.service = service; + this.uid = uid; + this.name = name; + this.flavor = flavor; + this.image = image; + this.labels = labels; + this.meta = meta; + } + + @NotNull + @Override + public UUID getUid() { + return uid; + } + + @NotNull + @Override + public String getName() { + return name; + } + + @NotNull + @Override + public ServiceFlavor getFlavor() { + return flavor; + } + + @NotNull + @Override + public ServiceImage getImage() { + return image; + } + + @NotNull + @Override + public Map getLabels() { + return Collections.unmodifiableMap(labels); + } + + @NotNull + @Override + public Map getMeta() { + return Collections.unmodifiableMap(meta); + } + + public void setWorkload(Object _workload) { + Map new_meta = new HashMap(); + new_meta.put("workload", _workload); + + meta = new_meta; + } + + @NotNull + @Override + public TaskState getState() { + return state; + } + + @Nullable + @Override + public Instant getLaunchedAt() { + return launchedAt; + } + + /** + * Return the {@link Host} on which the task is running or null if it is not running on a host. + */ + public Host getHost() { + return host; + } + + @Override + public void start() { + switch (state) { + case PROVISIONING: + LOGGER.debug("User tried to start task but request is already pending: doing nothing"); + case RUNNING: + LOGGER.debug("User tried to start task but task is already running"); + break; + case DELETED: + LOGGER.warn("User tried to start deleted task"); + throw new IllegalStateException("Task is deleted"); + default: + LOGGER.info("User requested to start task {}", uid); + setState(TaskState.PROVISIONING); + assert request == null : "Scheduling request already active"; + request = service.schedule(this); + break; + } + } + + @Override + public void stop() { + switch (state) { + case PROVISIONING: + cancelProvisioningRequest(); + setState(TaskState.TERMINATED); + break; + case RUNNING: + case ERROR: + final Host host = this.host; + if (host == null) { + throw new IllegalStateException("Task not running"); + } + host.stop(this); + break; + } + } + + @Override + public void watch(@NotNull TaskWatcher watcher) { + watchers.add(watcher); + } + + @Override + public void unwatch(@NotNull TaskWatcher watcher) { + watchers.remove(watcher); + } + + @Override + public void reload() { + // No-op: this object is the source-of-truth + } + + @Override + public void delete() { + switch (state) { + case PROVISIONING: + case TERMINATED: + cancelProvisioningRequest(); + service.delete(this); + setState(TaskState.DELETED); + break; + case RUNNING: + case ERROR: + final Host host = this.host; + if (host == null) { + throw new IllegalStateException("Task not running"); + } + host.delete(this); + service.delete(this); + setState(TaskState.DELETED); + break; + } + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + ServiceTask task = (ServiceTask) o; + return service.equals(task.service) && uid.equals(task.uid); + } + + @Override + public int hashCode() { + return Objects.hash(service, uid); + } + + @Override + public String toString() { + return "Task[uid=" + uid + ",name=" + name + ",state=" + state + "]"; + } + + void setState(TaskState state) { + if (this.state != state) { + for (TaskWatcher watcher : watchers) { + watcher.onStateChanged(this, state); + } + } + + this.state = state; + } + + /** + * Cancel the provisioning request if active. + */ + private void cancelProvisioningRequest() { + final ComputeService.SchedulingRequest request = this.request; + if (request != null) { + this.request = null; + request.isCancelled = true; + } + } +} diff --git a/opendc-compute/opendc-compute-service/src/main/java/org/opendc/compute/service/driver/Host.java b/opendc-compute/opendc-compute-service/src/main/java/org/opendc/compute/service/driver/Host.java index 760d7f1a..546f774b 100644 --- a/opendc-compute/opendc-compute-service/src/main/java/org/opendc/compute/service/driver/Host.java +++ b/opendc-compute/opendc-compute-service/src/main/java/org/opendc/compute/service/driver/Host.java @@ -25,14 +25,14 @@ package org.opendc.compute.service.driver; import java.util.Map; import java.util.Set; import java.util.UUID; -import org.opendc.compute.api.Server; +import org.opendc.compute.api.Task; import org.opendc.compute.service.driver.telemetry.GuestCpuStats; import org.opendc.compute.service.driver.telemetry.GuestSystemStats; import org.opendc.compute.service.driver.telemetry.HostCpuStats; import org.opendc.compute.service.driver.telemetry.HostSystemStats; /** - * Base interface for representing compute resources that host virtualized {@link Server} instances. + * Base interface for representing compute resources that host virtualized {@link Task} instances. */ public interface Host { /** @@ -61,43 +61,43 @@ public interface Host { Map getMeta(); /** - * Return the {@link Server} instances known to the host. + * Return the {@link Task} instances known to the host. */ - Set getInstances(); + Set getInstances(); /** - * Determine whether the specified server can still fit on this host. + * Determine whether the specified task can still fit on this host. */ - boolean canFit(Server server); + boolean canFit(Task task); /** - * Register the specified server on the host. + * Register the specified task on the host. */ - void spawn(Server server); + void spawn(Task task); /** - * Determine whether the specified server exists on the host. + * Determine whether the specified task exists on the host. */ - boolean contains(Server server); + boolean contains(Task task); /** - * Start the server if it is currently not running on this host. + * Start the task if it is currently not running on this host. * - * @throws IllegalArgumentException if the server is not present on the host. + * @throws IllegalArgumentException if the task is not present on the host. */ - void start(Server server); + void start(Task task); /** - * Stop the server if it is currently running on this host. + * Stop the task if it is currently running on this host. * - * @throws IllegalArgumentException if the server is not present on the host. + * @throws IllegalArgumentException if the task is not present on the host. */ - void stop(Server server); + void stop(Task task); /** - * Delete the specified server on this host and cleanup all resources associated with it. + * Delete the specified task on this host and cleanup all resources associated with it. */ - void delete(Server server); + void delete(Task task); /** * Add a [HostListener] to this host. @@ -115,12 +115,12 @@ public interface Host { HostSystemStats getSystemStats(); /** - * Query the system statistics of a {@link Server} that is located on this host. + * Query the system statistics of a {@link Task} that is located on this host. * - * @param server The {@link Server} to obtain the system statistics of. - * @throws IllegalArgumentException if the server is not present on the host. + * @param task The {@link Task} to obtain the system statistics of. + * @throws IllegalArgumentException if the task is not present on the host. */ - GuestSystemStats getSystemStats(Server server); + GuestSystemStats getSystemStats(Task task); /** * Query the CPU statistics of the host. @@ -128,10 +128,10 @@ public interface Host { HostCpuStats getCpuStats(); /** - * Query the CPU statistics of a {@link Server} that is located on this host. + * Query the CPU statistics of a {@link Task} that is located on this host. * - * @param server The {@link Server} to obtain the CPU statistics of. - * @throws IllegalArgumentException if the server is not present on the host. + * @param task The {@link Task} to obtain the CPU statistics of. + * @throws IllegalArgumentException if the task is not present on the host. */ - GuestCpuStats getCpuStats(Server server); + GuestCpuStats getCpuStats(Task task); } diff --git a/opendc-compute/opendc-compute-service/src/main/java/org/opendc/compute/service/driver/HostListener.java b/opendc-compute/opendc-compute-service/src/main/java/org/opendc/compute/service/driver/HostListener.java index feefca40..079c6cff 100644 --- a/opendc-compute/opendc-compute-service/src/main/java/org/opendc/compute/service/driver/HostListener.java +++ b/opendc-compute/opendc-compute-service/src/main/java/org/opendc/compute/service/driver/HostListener.java @@ -22,17 +22,17 @@ package org.opendc.compute.service.driver; -import org.opendc.compute.api.Server; -import org.opendc.compute.api.ServerState; +import org.opendc.compute.api.Task; +import org.opendc.compute.api.TaskState; /** * Listener interface for events originating from a {@link Host}. */ public interface HostListener { /** - * This method is invoked when the state of server on host changes. + * This method is invoked when the state of task on host changes. */ - default void onStateChanged(Host host, Server server, ServerState newState) {} + default void onStateChanged(Host host, Task task, TaskState newState) {} /** * This method is invoked when the state of a {@link Host} has changed. diff --git a/opendc-compute/opendc-compute-service/src/main/java/org/opendc/compute/service/driver/telemetry/HostSystemStats.java b/opendc-compute/opendc-compute-service/src/main/java/org/opendc/compute/service/driver/telemetry/HostSystemStats.java index d9dba274..c0713f3c 100644 --- a/opendc-compute/opendc-compute-service/src/main/java/org/opendc/compute/service/driver/telemetry/HostSystemStats.java +++ b/opendc-compute/opendc-compute-service/src/main/java/org/opendc/compute/service/driver/telemetry/HostSystemStats.java @@ -30,7 +30,7 @@ import java.time.Instant; * * @param uptime The cumulative uptime of the host since last boot (in ms). * @param downtime The cumulative downtime of the host since last boot (in ms). - * @param bootTime The time at which the server started. + * @param bootTime The time at which the task started. * @param powerDraw Instantaneous power draw of the system (in W). * @param energyUsage The cumulative energy usage of the system (in J). * @param guestsTerminated The number of guests that are in a terminated state. diff --git a/opendc-compute/opendc-compute-service/src/main/java/org/opendc/compute/service/telemetry/SchedulerStats.java b/opendc-compute/opendc-compute-service/src/main/java/org/opendc/compute/service/telemetry/SchedulerStats.java index 2157169b..fc044d8c 100644 --- a/opendc-compute/opendc-compute-service/src/main/java/org/opendc/compute/service/telemetry/SchedulerStats.java +++ b/opendc-compute/opendc-compute-service/src/main/java/org/opendc/compute/service/telemetry/SchedulerStats.java @@ -30,9 +30,9 @@ package org.opendc.compute.service.telemetry; * @param attemptsSuccess Scheduling attempts that resulted into an allocation onto a host. * @param attemptsFailure The number of failed scheduling attempt due to insufficient capacity at the moment. * @param attemptsError The number of scheduling attempts that failed due to system error. - * @param serversTotal The number of servers registered with the service. - * @param serversPending The number of servers that are pending to be scheduled. - * @param serversActive The number of servers that are currently managed by the service and running. + * @param tasksTotal The number of tasks registered with the service. + * @param tasksPending The number of tasks that are pending to be scheduled. + * @param tasksActive The number of tasks that are currently managed by the service and running. */ public record SchedulerStats( int hostsAvailable, @@ -40,6 +40,6 @@ public record SchedulerStats( long attemptsSuccess, long attemptsFailure, long attemptsError, - int serversTotal, - int serversPending, - int serversActive) {} + int tasksTotal, + int tasksPending, + int tasksActive) {} -- cgit v1.2.3