diff options
author | 2019-12-26 16:26:25 -0500 | |
---|---|---|
committer | 2019-12-30 18:18:38 +0000 | |
commit | 41712e142c8d2b2bff9bc9e094f45306a60d7cb9 (patch) | |
tree | 1a6578a40b45235c8486a179b84b2e5932d164cf /ms/blueprintsprocessor/modules/commons/rest-lib/src/main | |
parent | 730c940a84b9056fed993ccef08dc5ec4053db21 (diff) |
Relationship Type and Templates models
Enrichment Support for Relationship Types and Templates.
Relationship DSL support for ConnectTo connections ( RestClient, SshClient, MessageProducer, MessageConsume, Nats)
Moved datatype map from collection to complex type
Issue-ID: CCSDK-1054
Signed-off-by: Brinda Santh <bs2796@att.com>
Change-Id: I0f18db2cb52e1e93dfab04498b8298587cba2540
Diffstat (limited to 'ms/blueprintsprocessor/modules/commons/rest-lib/src/main')
2 files changed, 78 insertions, 31 deletions
diff --git a/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/BluePrintRestLibConfiguration.kt b/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/BluePrintRestLibConfiguration.kt index 9e1be36a7..23125430a 100644 --- a/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/BluePrintRestLibConfiguration.kt +++ b/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/BluePrintRestLibConfiguration.kt @@ -48,6 +48,7 @@ fun BluePrintDependencyService.restClientService(jsonNode: JsonNode): BlueprintW class RestLibConstants { companion object { const val SERVICE_BLUEPRINT_REST_LIB_PROPERTY = "blueprint-rest-lib-property-service" + const val PROPERTY_REST_CLIENT_PREFIX = "blueprintsprocessor.restclient." const val PROPERTY_TYPE = "type" const val TYPE_TOKEN_AUTH = "token-auth" const val TYPE_BASIC_AUTH = "basic-auth" diff --git a/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/RestClientPropertiesDSL.kt b/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/RestClientPropertiesDSL.kt index 429931377..4c25cb5bf 100644 --- a/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/RestClientPropertiesDSL.kt +++ b/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/RestClientPropertiesDSL.kt @@ -17,54 +17,100 @@ package org.onap.ccsdk.cds.blueprintsprocessor.rest import com.fasterxml.jackson.databind.JsonNode +import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintTypes import org.onap.ccsdk.cds.controllerblueprints.core.asJsonPrimitive import org.onap.ccsdk.cds.controllerblueprints.core.asJsonType +import org.onap.ccsdk.cds.controllerblueprints.core.data.RelationshipType import org.onap.ccsdk.cds.controllerblueprints.core.dsl.PropertiesAssignmentBuilder +import org.onap.ccsdk.cds.controllerblueprints.core.dsl.RelationshipTemplateBuilder +import org.onap.ccsdk.cds.controllerblueprints.core.dsl.TopologyTemplateBuilder +import org.onap.ccsdk.cds.controllerblueprints.core.dsl.relationshipType + +/** Relationships Type DSL for Rest */ +fun BluePrintTypes.relationshipTypeConnectsToRestClient(): RelationshipType { + return relationshipType( + id = BluePrintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO_REST_CLIENT, + version = BluePrintConstants.DEFAULT_VERSION_NUMBER, + derivedFrom = BluePrintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO, + description = "Relationship connects to through" + ) { + property( + BluePrintConstants.PROPERTY_CONNECTION_CONFIG, + BluePrintConstants.DATA_TYPE_MAP, + true, + "Connection Config details." + ) + validTargetTypes(arrayListOf(BluePrintConstants.MODEL_TYPE_CAPABILITY_TYPE_ENDPOINT)) + } +} -fun BluePrintTypes.dslBasicAuthRestClientProperties(block: BasicAuthRestClientPropertiesBuilder.() -> Unit): JsonNode { - val assignments = BasicAuthRestClientPropertiesBuilder().apply(block).build() - assignments[RestLibConstants.PROPERTY_TYPE] = RestLibConstants.TYPE_BASIC_AUTH.asJsonPrimitive() - return assignments.asJsonType() +/** Relationships Templates DSL for Rest */ +fun TopologyTemplateBuilder.relationshipTemplateRestClient( + name: String, + description: String, + block: RestClientRelationshipTemplateBuilder.() -> Unit +) { + if (relationshipTemplates == null) relationshipTemplates = hashMapOf() + val relationshipTemplate = RestClientRelationshipTemplateBuilder(name, description).apply(block).build() + relationshipTemplates!![relationshipTemplate.id!!] = relationshipTemplate } -fun BluePrintTypes.dslTokenAuthRestClientProperties(block: TokenAuthRestClientPropertiesBuilder.() -> Unit): JsonNode { - val assignments = TokenAuthRestClientPropertiesBuilder().apply(block).build() - assignments[RestLibConstants.PROPERTY_TYPE] = RestLibConstants.TYPE_TOKEN_AUTH.asJsonPrimitive() +open class RestClientRelationshipTemplateBuilder(name: String, description: String) : + RelationshipTemplateBuilder( + name, + BluePrintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO_REST_CLIENT, description + ) { + + fun basicAuth(block: BasicAuthRestClientPropertiesAssignmentBuilder.() -> Unit) { + property(BluePrintConstants.PROPERTY_CONNECTION_CONFIG, BluePrintTypes.basicAuthRestClientProperties(block)) + } + + fun tokenAuth(block: TokenAuthRestClientPropertiesAssignmentBuilder.() -> Unit) { + property(BluePrintConstants.PROPERTY_CONNECTION_CONFIG, BluePrintTypes.tokenAuthRestClientProperties(block)) + } + + fun sslAuth(block: SslAuthRestClientPropertiesAssignmentBuilder.() -> Unit) { + property(BluePrintConstants.PROPERTY_CONNECTION_CONFIG, BluePrintTypes.sslRestClientProperties(block)) + } +} + +fun BluePrintTypes.basicAuthRestClientProperties(block: BasicAuthRestClientPropertiesAssignmentBuilder.() -> Unit): JsonNode { + val assignments = BasicAuthRestClientPropertiesAssignmentBuilder().apply(block).build() + assignments[RestClientProperties::type.name] = RestLibConstants.TYPE_BASIC_AUTH.asJsonPrimitive() return assignments.asJsonType() } -fun BluePrintTypes.dslSSLRestClientProperties(block: SSLRestClientPropertiesBuilder.() -> Unit): JsonNode { - val assignments = SSLRestClientPropertiesBuilder().apply(block).build() - assignments[RestLibConstants.PROPERTY_TYPE] = RestLibConstants.TYPE_SSL_NO_AUTH.asJsonPrimitive() +fun BluePrintTypes.tokenAuthRestClientProperties(block: TokenAuthRestClientPropertiesAssignmentBuilder.() -> Unit): JsonNode { + val assignments = TokenAuthRestClientPropertiesAssignmentBuilder().apply(block).build() + assignments[RestClientProperties::type.name] = RestLibConstants.TYPE_TOKEN_AUTH.asJsonPrimitive() return assignments.asJsonType() } -open class RestClientPropertiesBuilder : PropertiesAssignmentBuilder() { - fun type(type: String) { - type(type.asJsonPrimitive()) - } +fun BluePrintTypes.sslRestClientProperties(block: SslAuthRestClientPropertiesAssignmentBuilder.() -> Unit): JsonNode { + val assignments = SslAuthRestClientPropertiesAssignmentBuilder().apply(block).build() + assignments[RestClientProperties::type.name] = RestLibConstants.TYPE_SSL_NO_AUTH.asJsonPrimitive() + return assignments.asJsonType() +} - fun type(type: JsonNode) { - property(RestLibConstants.PROPERTY_TYPE, type) - } +open class RestClientPropertiesAssignmentBuilder : PropertiesAssignmentBuilder() { open fun url(url: String) { url(url.asJsonPrimitive()) } open fun url(url: JsonNode) { - property("url", url) + property(RestClientProperties::url, url) } } -open class BasicAuthRestClientPropertiesBuilder : RestClientPropertiesBuilder() { +open class BasicAuthRestClientPropertiesAssignmentBuilder : RestClientPropertiesAssignmentBuilder() { open fun password(password: String) { password(password.asJsonPrimitive()) } open fun password(password: JsonNode) { - property("password", password) + property(BasicAuthRestClientProperties::password, password) } open fun username(username: String) { @@ -72,27 +118,27 @@ open class BasicAuthRestClientPropertiesBuilder : RestClientPropertiesBuilder() } open fun username(username: JsonNode) { - property("username", username) + property(BasicAuthRestClientProperties::username, username) } } -open class TokenAuthRestClientPropertiesBuilder : RestClientPropertiesBuilder() { +open class TokenAuthRestClientPropertiesAssignmentBuilder : RestClientPropertiesAssignmentBuilder() { open fun token(token: String) { token(token.asJsonPrimitive()) } open fun token(token: JsonNode) { - property("token", token) + property(TokenAuthRestClientProperties::token, token) } } -open class SSLRestClientPropertiesBuilder : RestClientPropertiesBuilder() { +open class SslAuthRestClientPropertiesAssignmentBuilder : RestClientPropertiesAssignmentBuilder() { open fun keyStoreInstance(keyStoreInstance: String) { keyStoreInstance(keyStoreInstance.asJsonPrimitive()) } open fun keyStoreInstance(keyStoreInstance: JsonNode) { - property("keyStoreInstance", keyStoreInstance) + property(SSLRestClientProperties::keyStoreInstance, keyStoreInstance) } open fun sslTrust(sslTrust: String) { @@ -100,7 +146,7 @@ open class SSLRestClientPropertiesBuilder : RestClientPropertiesBuilder() { } open fun sslTrust(sslTrust: JsonNode) { - property("sslTrust", sslTrust) + property(SSLRestClientProperties::sslTrust, sslTrust) } open fun sslTrustPassword(sslTrustPassword: String) { @@ -108,7 +154,7 @@ open class SSLRestClientPropertiesBuilder : RestClientPropertiesBuilder() { } open fun sslTrustPassword(sslTrustPassword: JsonNode) { - property("sslTrustPassword", sslTrustPassword) + property(SSLRestClientProperties::sslTrustPassword, sslTrustPassword) } open fun sslKey(sslKey: String) { @@ -116,7 +162,7 @@ open class SSLRestClientPropertiesBuilder : RestClientPropertiesBuilder() { } open fun sslKey(sslKey: JsonNode) { - property("sslKey", sslKey) + property(SSLRestClientProperties::sslKey, sslKey) } open fun sslKeyPassword(sslKeyPassword: String) { @@ -124,14 +170,14 @@ open class SSLRestClientPropertiesBuilder : RestClientPropertiesBuilder() { } open fun sslKeyPassword(sslKeyPassword: JsonNode) { - property("sslKeyPassword", sslKeyPassword) + property(SSLRestClientProperties::sslKeyPassword, sslKeyPassword) } } -open class SSLBasicAuthRestClientPropertiesBuilder : SSLRestClientPropertiesBuilder() { +open class SSLBasicAuthRestClientPropertiesBuilder : SslAuthRestClientPropertiesAssignmentBuilder() { // TODO() } -open class SSLTokenAuthRestClientPropertiesBuilder : SSLRestClientPropertiesBuilder() { +open class SSLTokenAuthRestClientPropertiesBuilder : SslAuthRestClientPropertiesAssignmentBuilder() { // TODO() } |