Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Copyright 2023 VMware, Inc.
* SPDX-License-Identifier: Apache-2.0
*/
@file:JvmName("Result")
package com.vmware.aria.operations
import com.vmware.aria.operations.definition.AdapterDefinition
import kotlinx.serialization.Serializable
import kotlinx.serialization.json.Json
import kotlinx.serialization.json.JsonArray
import kotlinx.serialization.json.JsonElement
import kotlinx.serialization.json.JsonObject
import kotlinx.serialization.json.JsonPrimitive
import kotlinx.serialization.json.encodeToJsonElement
enum class RelationshipUpdateModes {
/**
* If [CollectResult.updateRelationships] is [ALL], all relationships between objects are
* returned. This mode will remove any currently-existing relationships in VMware
* Aria Operations that are not present in the Result.
*/
ALL,
/**
* If [CollectResult.updateRelationships] is [NONE], no relationships will be returned, even if
* there are relationships between objects in the Result. All currently-existing
* relationships in VMware Aria Operations will be preserved.
*/
NONE,
/**
* If [CollectResult.updateRelationships] is [AUTO] (or not explicitly set), then the mode will
* behave like 'ALL' if any object in the Result has at least one relationship,
* otherwise the mode will behave like 'NONE' if no objects have any relationships in
* the Result. This default behavior makes it easy to skip collecting all relationships
* for a collection without overwriting previously-collected relationships, e.g., for
* performance reasons.
*/
AUTO,
/**
* If [CollectResult.updateRelationships] is [PER_OBJECT], then only objects with updated
* relationships will be returned. This is similar to 'AUTO' except that if an
* object's child relationships have not been updated/set (by calling 'add_child' or
* 'add_children'), existing child relationships in VMware Aria Operations will be
* preserved. This means that to remove all relationships from an [Object]
* (without setting any new relationships), the adapter must call [Object.addChildren] on
* the object with an empty collection of children. This mode is useful for updating a
* subset of objects' relationships in a collection, but requires more care to
* ensure relationships are removed when appropriate.
*/
PER_OBJECT,
}
/**
* Class for managing the results of an Adapter Instance 'connection' test
*/
@Serializable
class TestResult {
private var errorMessage: String? = null
/**
* @return true if the TestResult represents a successful test
*/
fun isSuccess() = errorMessage == null
/**
* Set the adapter instance connection test to failed, and display the given
* error message.
*
* If this method is called multiple times, only the most recent error message
* will be recorded. If [errorMessage] is set, the test is considered failed.
*
* @param errorMessage The error message to present to the user.
*/
fun withError(errorMessage: String) = apply {
this.errorMessage = errorMessage
}
/**
* @return Returns a JSON representation of this [TestResult] in the format required by
* Aria Operations, indicating either a successful test, or a failed test with
* error message.
*/
val json: JsonElement
get() = Json.encodeToJsonElement(this)
/**
* Opens the output pipe and sends result directly back to the server
*
* This method can only be called once per collection.
*
* @param outputPipe The path to the output pipe.
*/
@JvmOverloads
fun sendResults(outputPipe: String = Pipes.output) {
writeToPipe(json, outputPipe)
}
}
/**
* Class for managing the results of an adapter's getEndpointURLs call
*
* The result of is a set of urls that the adapter will connect to.
* Aria Operations will then attempt to connect to each of these urls securely,
* and prompt the user to accept or reject the certificate presented by each URL.
*/
@Serializable
class EndpointResult {
private val endpointUrls = mutableSetOf()
/**
* Adds an endpoint to the set of endpoints Aria Operations will test for
* certificate validation.
*
* If this method is called multiple times, each url will be called by Aria
* Operations.
*
* @param endpoint A string containing the url
*/
fun withEndpoint(endpoint: String) = apply {
this.endpointUrls.add(endpoint)
}
/**
* @return Returns a JSON representation of this [EndpointResult] in the format required by
* Aria Operations.
*/
val json: JsonElement
get() = Json.encodeToJsonElement(this)
/**
* Opens the output pipe and sends results directly back to the server
* This method can only be called once per collection.
* @param outputPipe The path to the output pipe.
*/
@JvmOverloads
fun sendResults(outputPipe: String = Pipes.output) {
writeToPipe(json, outputPipe)
}
}
/**
* Class for managing the results of an adapter's collection call.
*
* A [CollectResult] contains [Objects][Object], which can be added at initialization or later.
* Each [Object] has a [Key] containing one or more [Identifiers][Identifier] plus the object type
* and adapter type. [Keys][Key] must be unique across objects in a [CollectResult].
*
* @param objectList An optional [List] of objects to send to Aria Operations. [Objects][Object] can be
* added later using [CollectResult.addObject]. Defaults to an empty list.
* @param targetDefinition an optional description of the returned objects, used for validation
* purposes. Defaults to null.
*/
class CollectResult(
objectList: List