diff options
| author | Fabian Mastenbroek <mail.fabianm@gmail.com> | 2022-12-04 22:03:18 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-12-04 22:03:18 +0000 |
| commit | b88f07ebb056293b1a29f24e4f42203c09bcbcf8 (patch) | |
| tree | 52e2de58503714cc6510db614b4a654af2fdda3c /opendc-compute/opendc-compute-api | |
| parent | 2ca72c0b62e08efd244eba1723bc4fc65d30eed2 (diff) | |
| parent | 4dfae28c5bd656806a7baf7855c95770f4ad0ed8 (diff) | |
merge: Clean up compute service (v1)
This pull request is one in a series of changes that attempt to clean up the
warts of the OpenDC Compute Service. These changes should make the
API more robust for future developments.
## Implementation Notes :hammer_and_pick:
* Do not suspend in compute API
* Expose state directly to clients
* Do not split interface and implementation
## External Dependencies :four_leaf_clover:
* N/A
## Breaking API Changes :warning:
* The methods of `ComputeClient` do not have the suspend modifier anymore.
* Changes to the classes of `ComputeClient` are now immediately visible on the server side.
It is not necessary to call `refresh` anymore.
* `ComputeService` must be constructed via its builder class now.
Diffstat (limited to 'opendc-compute/opendc-compute-api')
6 files changed, 19 insertions, 41 deletions
diff --git a/opendc-compute/opendc-compute-api/src/main/kotlin/org/opendc/compute/api/ComputeClient.kt b/opendc-compute/opendc-compute-api/src/main/kotlin/org/opendc/compute/api/ComputeClient.kt index 577fbc73..c26d0b8b 100644 --- a/opendc-compute/opendc-compute-api/src/main/kotlin/org/opendc/compute/api/ComputeClient.kt +++ b/opendc-compute/opendc-compute-api/src/main/kotlin/org/opendc/compute/api/ComputeClient.kt @@ -31,14 +31,14 @@ public interface ComputeClient : AutoCloseable { /** * Obtain the list of [Flavor]s accessible by the requesting user. */ - public suspend fun queryFlavors(): List<Flavor> + public fun queryFlavors(): List<Flavor> /** * Obtain a [Flavor] by its unique identifier. * * @param id The identifier of the flavor. */ - public suspend fun findFlavor(id: UUID): Flavor? + public fun findFlavor(id: UUID): Flavor? /** * Create a new [Flavor] instance at this compute service. @@ -49,7 +49,7 @@ public interface ComputeClient : AutoCloseable { * @param labels The identifying labels of the image. * @param meta The non-identifying meta-data of the image. */ - public suspend fun newFlavor( + public fun newFlavor( name: String, cpuCount: Int, memorySize: Long, @@ -60,14 +60,14 @@ public interface ComputeClient : AutoCloseable { /** * Obtain the list of [Image]s accessible by the requesting user. */ - public suspend fun queryImages(): List<Image> + public fun queryImages(): List<Image> /** * Obtain a [Image] by its unique identifier. * * @param id The identifier of the image. */ - public suspend fun findImage(id: UUID): Image? + public fun findImage(id: UUID): Image? /** * Create a new [Image] instance at this compute service. @@ -76,7 +76,7 @@ public interface ComputeClient : AutoCloseable { * @param labels The identifying labels of the image. * @param meta The non-identifying meta-data of the image. */ - public suspend fun newImage( + public fun newImage( name: String, labels: Map<String, String> = emptyMap(), meta: Map<String, Any> = emptyMap() @@ -85,14 +85,14 @@ public interface ComputeClient : AutoCloseable { /** * Obtain the list of [Server]s accessible by the requesting user. */ - public suspend fun queryServers(): List<Server> + public fun queryServers(): List<Server> /** * Obtain a [Server] by its unique identifier. * * @param id The identifier of the server. */ - public suspend fun findServer(id: UUID): Server? + public fun findServer(id: UUID): Server? /** * Create a new [Server] instance at this compute service. @@ -104,7 +104,7 @@ public interface ComputeClient : AutoCloseable { * @param meta The non-identifying meta-data of the server. * @param start A flag to indicate that the server should be started immediately. */ - public suspend fun newServer( + public fun newServer( name: String, image: Image, flavor: Flavor, diff --git a/opendc-compute/opendc-compute-api/src/main/kotlin/org/opendc/compute/api/Flavor.kt b/opendc-compute/opendc-compute-api/src/main/kotlin/org/opendc/compute/api/Flavor.kt index 5f511f91..d76e0fba 100644 --- a/opendc-compute/opendc-compute-api/src/main/kotlin/org/opendc/compute/api/Flavor.kt +++ b/opendc-compute/opendc-compute-api/src/main/kotlin/org/opendc/compute/api/Flavor.kt @@ -36,9 +36,4 @@ public interface Flavor : Resource { * The amount of RAM available to the server (in MB). */ public val memorySize: Long - - /** - * Delete the flavor instance. - */ - public suspend fun delete() } diff --git a/opendc-compute/opendc-compute-api/src/main/kotlin/org/opendc/compute/api/Image.kt b/opendc-compute/opendc-compute-api/src/main/kotlin/org/opendc/compute/api/Image.kt index 83e63b81..c4a04b96 100644 --- a/opendc-compute/opendc-compute-api/src/main/kotlin/org/opendc/compute/api/Image.kt +++ b/opendc-compute/opendc-compute-api/src/main/kotlin/org/opendc/compute/api/Image.kt @@ -25,9 +25,4 @@ package org.opendc.compute.api /** * An image containing a bootable operating system that can directly be executed by physical or virtual server. */ -public interface Image : Resource { - /** - * Delete the image instance. - */ - public suspend fun delete() -} +public interface Image : Resource diff --git a/opendc-compute/opendc-compute-api/src/main/kotlin/org/opendc/compute/api/Resource.kt b/opendc-compute/opendc-compute-api/src/main/kotlin/org/opendc/compute/api/Resource.kt index 08120848..58082130 100644 --- a/opendc-compute/opendc-compute-api/src/main/kotlin/org/opendc/compute/api/Resource.kt +++ b/opendc-compute/opendc-compute-api/src/main/kotlin/org/opendc/compute/api/Resource.kt @@ -49,7 +49,12 @@ public interface Resource { public val meta: Map<String, Any> /** - * Refresh the local state of the resource. + * Reload the attributes of the resource. */ - public suspend fun refresh() + public fun reload() + + /** + * Delete the resource. + */ + public fun delete() } diff --git a/opendc-compute/opendc-compute-api/src/main/kotlin/org/opendc/compute/api/Server.kt b/opendc-compute/opendc-compute-api/src/main/kotlin/org/opendc/compute/api/Server.kt index 64b73d0b..b4cc5129 100644 --- a/opendc-compute/opendc-compute-api/src/main/kotlin/org/opendc/compute/api/Server.kt +++ b/opendc-compute/opendc-compute-api/src/main/kotlin/org/opendc/compute/api/Server.kt @@ -50,27 +50,13 @@ public interface Server : Resource { /** * Request the server to be started. - * - * This method is guaranteed to return after the request was acknowledged, but might return before the server was - * started. */ - public suspend fun start() + public fun start() /** * Request the server to be stopped. - * - * This method is guaranteed to return after the request was acknowledged, but might return before the server was - * stopped. - */ - public suspend fun stop() - - /** - * Request the server to be deleted. - * - * This method is guaranteed to return after the request was acknowledged, but might return before the server was - * deleted. */ - public suspend fun delete() + public fun stop() /** * Register the specified [ServerWatcher] to watch the state of the server. diff --git a/opendc-compute/opendc-compute-api/src/main/kotlin/org/opendc/compute/api/ServerWatcher.kt b/opendc-compute/opendc-compute-api/src/main/kotlin/org/opendc/compute/api/ServerWatcher.kt index 48a17b30..cf995fc3 100644 --- a/opendc-compute/opendc-compute-api/src/main/kotlin/org/opendc/compute/api/ServerWatcher.kt +++ b/opendc-compute/opendc-compute-api/src/main/kotlin/org/opendc/compute/api/ServerWatcher.kt @@ -29,9 +29,6 @@ public interface ServerWatcher { /** * This method is invoked when the state of a [Server] changes. * - * Note that the state of [server] might not reflect the state as reported by the invocation, as a call to - * [Server.refresh] is required to update its state. - * * @param server The server whose state has changed. * @param newState The new state of the server. */ |
