diff options
| author | Fabian Mastenbroek <mail.fabianm@gmail.com> | 2021-04-25 21:53:42 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-04-25 21:53:42 +0200 |
| commit | 128f76f7fd7c8abb41a3bbbd9f1980cbc20ae7a5 (patch) | |
| tree | add513890005233a7784466797bfe6f5052e9eeb /opendc-serverless/opendc-serverless-api | |
| parent | 128a1db017545597a5c035b7960eb3fd36b5f987 (diff) | |
| parent | 57b54b59ed74ec37338ae26b3864d051255aba49 (diff) | |
build: Flatten project structure
This change updates the project structure to become flattened.
Previously, the simulator, frontend and API each lived into their own directory.
With this change, all modules of the project live in the top-level directory of
the repository.
Diffstat (limited to 'opendc-serverless/opendc-serverless-api')
3 files changed, 176 insertions, 0 deletions
diff --git a/opendc-serverless/opendc-serverless-api/build.gradle.kts b/opendc-serverless/opendc-serverless-api/build.gradle.kts new file mode 100644 index 00000000..ec33ccce --- /dev/null +++ b/opendc-serverless/opendc-serverless-api/build.gradle.kts @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2021 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. + */ + +description = "Serverless API for OpenDC" + +/* Build configuration */ +plugins { + `kotlin-library-conventions` +} + +dependencies { + api(platform(project(":opendc-platform"))) +} diff --git a/opendc-serverless/opendc-serverless-api/src/main/kotlin/org/opendc/serverless/api/ServerlessClient.kt b/opendc-serverless/opendc-serverless-api/src/main/kotlin/org/opendc/serverless/api/ServerlessClient.kt new file mode 100644 index 00000000..b66369ec --- /dev/null +++ b/opendc-serverless/opendc-serverless-api/src/main/kotlin/org/opendc/serverless/api/ServerlessClient.kt @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2021 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.serverless.api + +import java.util.* + +/** + * Client interface to the OpenDC Serverless service. + */ +public interface ServerlessClient : AutoCloseable { + /** + * Obtain the list of [ServerlessFunction]s accessible by the requesting user. + */ + public suspend fun queryFunctions(): List<ServerlessFunction> + + /** + * Obtain a [ServerlessFunction] by its unique identifier. + * + * @param id The identifier of the flavor. + */ + public suspend fun findFunction(id: UUID): ServerlessFunction? + + /** + * Obtain a [ServerlessFunction] by its name. + * + * @param name The name of the function. + */ + public suspend fun findFunction(name: String): ServerlessFunction? + + /** + * Create a new serverless function. + * + * @param name The name of the function. + * @param memorySize The memory allocated for the function in MB. + * @param labels The labels associated with the function. + * @param meta The metadata associated with the function. + */ + public suspend fun newFunction( + name: String, + memorySize: Long, + labels: Map<String, String> = emptyMap(), + meta: Map<String, Any> = emptyMap() + ): ServerlessFunction + + /** + * Invoke the function with the specified [name]. + */ + public suspend fun invoke(name: String) + + /** + * Release the resources associated with this client, preventing any further API calls. + */ + public override fun close() +} diff --git a/opendc-serverless/opendc-serverless-api/src/main/kotlin/org/opendc/serverless/api/ServerlessFunction.kt b/opendc-serverless/opendc-serverless-api/src/main/kotlin/org/opendc/serverless/api/ServerlessFunction.kt new file mode 100644 index 00000000..f1360966 --- /dev/null +++ b/opendc-serverless/opendc-serverless-api/src/main/kotlin/org/opendc/serverless/api/ServerlessFunction.kt @@ -0,0 +1,70 @@ +/* + * Copyright (c) 2021 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.serverless.api + +import java.util.UUID + +/** + * A serverless function instance. + */ +public interface ServerlessFunction { + /** + * The unique identifier of the function. + */ + public val uid: UUID + + /** + * The name of the function. + */ + public val name: String + + /** + * The amount of memory allocated for this function in MB. + */ + public val memorySize: Long + + /** + * The identifying labels attached to the resource. + */ + public val labels: Map<String, String> + + /** + * The non-identifying metadata attached to the resource. + */ + public val meta: Map<String, Any> + + /** + * Invoke the serverless function. + */ + public suspend operator fun invoke() + + /** + * Request the function to be deleted. + */ + public suspend fun delete() + + /** + * Refresh the local state of this object. + */ + public suspend fun refresh() +} |
