diff options
| author | Georgios Andreadis <g.andreadis@student.tudelft.nl> | 2020-02-21 16:57:17 +0100 |
|---|---|---|
| committer | Georgios Andreadis <g.andreadis@student.tudelft.nl> | 2020-02-21 16:57:17 +0100 |
| commit | 8d05ee524981bacfe4af4fe0097c935309115481 (patch) | |
| tree | 9b9931ec263cd071e96617e339aa907af332f296 /opendc/opendc-core/src/main | |
| parent | 37a5902767bc787bcc470e42b5b078e340a67b18 (diff) | |
| parent | 49b673e26ebf9f6a1c96f083d3876b19027b2abc (diff) | |
Merge branch 'feat/2.x-tagging' into 'feat/2.x'
Add support for resource tagging
See merge request opendc/opendc-simulator!26
Diffstat (limited to 'opendc/opendc-core/src/main')
| -rw-r--r-- | opendc/opendc-core/src/main/kotlin/com/atlarge/opendc/core/resource/Resource.kt | 37 | ||||
| -rw-r--r-- | opendc/opendc-core/src/main/kotlin/com/atlarge/opendc/core/resource/TagContainer.kt | 36 |
2 files changed, 73 insertions, 0 deletions
diff --git a/opendc/opendc-core/src/main/kotlin/com/atlarge/opendc/core/resource/Resource.kt b/opendc/opendc-core/src/main/kotlin/com/atlarge/opendc/core/resource/Resource.kt new file mode 100644 index 00000000..25a494bc --- /dev/null +++ b/opendc/opendc-core/src/main/kotlin/com/atlarge/opendc/core/resource/Resource.kt @@ -0,0 +1,37 @@ +/* + * MIT License + * + * Copyright (c) 2020 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 com.atlarge.opendc.core.resource + +import com.atlarge.opendc.core.Identity + +/** + * Represents a generic cloud resource. + */ +public interface Resource : Identity { + /** + * The tags of this cloud resource. + */ + public val tags: TagContainer +} diff --git a/opendc/opendc-core/src/main/kotlin/com/atlarge/opendc/core/resource/TagContainer.kt b/opendc/opendc-core/src/main/kotlin/com/atlarge/opendc/core/resource/TagContainer.kt new file mode 100644 index 00000000..6ba1cf0b --- /dev/null +++ b/opendc/opendc-core/src/main/kotlin/com/atlarge/opendc/core/resource/TagContainer.kt @@ -0,0 +1,36 @@ +/* + * MIT License + * + * Copyright (c) 2020 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 com.atlarge.opendc.core.resource + +/** + * An immutable map containing the tags of some resource. + */ +typealias TagContainer = Map<String, Any> + +/** + * Obtain the value of the tag with the specified [key] of type [T]. If the tag does not exist or the tag is of + * different type, `null` is returned. + */ +inline fun <reified T : Any> TagContainer.typed(key: String): T? = this[key] as? T |
