summaryrefslogtreecommitdiffstats
path: root/ms/blueprintsprocessor/modules/commons/rest-lib/src
diff options
context:
space:
mode:
authorBrinda Santh <bs2796@att.com>2019-12-26 16:26:25 -0500
committerKAPIL SINGAL <ks220y@att.com>2019-12-30 18:18:38 +0000
commit41712e142c8d2b2bff9bc9e094f45306a60d7cb9 (patch)
tree1a6578a40b45235c8486a179b84b2e5932d164cf /ms/blueprintsprocessor/modules/commons/rest-lib/src
parent730c940a84b9056fed993ccef08dc5ec4053db21 (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')
-rw-r--r--ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/BluePrintRestLibConfiguration.kt1
-rw-r--r--ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/RestClientPropertiesDSL.kt108
-rw-r--r--ms/blueprintsprocessor/modules/commons/rest-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/service/RestClientPropertiesDSLTest.kt75
3 files changed, 124 insertions, 60 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()
}
diff --git a/ms/blueprintsprocessor/modules/commons/rest-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/service/RestClientPropertiesDSLTest.kt b/ms/blueprintsprocessor/modules/commons/rest-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/service/RestClientPropertiesDSLTest.kt
index f82fc6124..28784e4ae 100644
--- a/ms/blueprintsprocessor/modules/commons/rest-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/service/RestClientPropertiesDSLTest.kt
+++ b/ms/blueprintsprocessor/modules/commons/rest-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/service/RestClientPropertiesDSLTest.kt
@@ -17,43 +17,60 @@
package org.onap.ccsdk.cds.blueprintsprocessor.rest.service
import org.junit.Test
-import org.onap.ccsdk.cds.blueprintsprocessor.rest.dslBasicAuthRestClientProperties
-import org.onap.ccsdk.cds.blueprintsprocessor.rest.dslSSLRestClientProperties
-import org.onap.ccsdk.cds.blueprintsprocessor.rest.dslTokenAuthRestClientProperties
+import org.onap.ccsdk.cds.blueprintsprocessor.rest.relationshipTemplateRestClient
+import org.onap.ccsdk.cds.blueprintsprocessor.rest.relationshipTypeConnectsToRestClient
import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintTypes
+import org.onap.ccsdk.cds.controllerblueprints.core.dsl.relationshipTypeConnectsTo
+import org.onap.ccsdk.cds.controllerblueprints.core.dsl.serviceTemplate
+import kotlin.test.assertEquals
import kotlin.test.assertNotNull
class RestClientPropertiesDSLTest {
@Test
- fun testBasicAuthRestClientProperties() {
- val properties = BluePrintTypes.dslBasicAuthRestClientProperties {
- url("http://localhost:8080")
- username("xxxxx")
- password("******")
- }
- assertNotNull(properties, "failed to get dslBasicAuthRestClientProperties")
- }
+ fun testRestClientProperties() {
- @Test
- fun testBasicTokenAuthRestClientProperties() {
- val properties = BluePrintTypes.dslTokenAuthRestClientProperties {
- url("http://localhost:8080")
- token("sdfgfsadgsgf")
+ val serviceTemplate = serviceTemplate("rest-properties-test", "1.0.0", "xxx.@xx.com", "rest") {
+ topologyTemplate {
+ relationshipTemplateRestClient("sample-basic-auth", "") {
+ basicAuth {
+ url("http://localhost:8080")
+ username("xxxxx")
+ password("******")
+ }
+ }
+ relationshipTemplateRestClient("sample-token-auth", "") {
+ tokenAuth {
+ url("http://localhost:8080")
+ token("sdfgfsadgsgf")
+ }
+ }
+ relationshipTemplateRestClient("sample-ssl-auth", "") {
+ sslAuth {
+ url("http://localhost:8080")
+ keyStoreInstance("instance")
+ sslTrust("sample-trust")
+ sslTrustPassword("sample-trust-password")
+ sslKey("sample-sslkey")
+ sslKeyPassword("sample-key-password")
+ }
+ }
+ }
+ relationshipTypes(
+ arrayListOf(
+ BluePrintTypes.relationshipTypeConnectsToRestClient(),
+ BluePrintTypes.relationshipTypeConnectsTo()
+ )
+ )
}
- assertNotNull(properties, "failed to get dslTokenAuthRestClientProperties")
- }
- @Test
- fun testDslSSLRestClientProperties() {
- val properties = BluePrintTypes.dslSSLRestClientProperties {
- url("http://localhost:8080")
- keyStoreInstance("instance")
- sslTrust("sample-trust")
- sslTrustPassword("sample-trust-password")
- sslKey("sample-sslkey")
- sslKeyPassword("sample-key-password")
- }
- assertNotNull(properties, "failed to get dslSSLRestClientProperties")
+ // println(serviceTemplate.asJsonString(true))
+ assertNotNull(serviceTemplate, "failed to create service template")
+ val relationshipTemplates = serviceTemplate.topologyTemplate?.relationshipTemplates
+ assertNotNull(relationshipTemplates, "failed to get relationship templates")
+ assertEquals(3, relationshipTemplates.size, "relationshipTemplates doesn't match")
+ assertNotNull(relationshipTemplates["sample-basic-auth"], "failed to get sample-basic-auth")
+ assertNotNull(relationshipTemplates["sample-token-auth"], "failed to get sample-token-auth")
+ assertNotNull(relationshipTemplates["sample-ssl-auth"], "failed to get sample-ssl-auth")
}
}