diff options
Diffstat (limited to 'ms')
18 files changed, 169 insertions, 84 deletions
diff --git a/ms/blueprintsprocessor/application/src/main/resources/application-dev.properties b/ms/blueprintsprocessor/application/src/main/resources/application-dev.properties index 380eb201..e64dee2a 100755 --- a/ms/blueprintsprocessor/application/src/main/resources/application-dev.properties +++ b/ms/blueprintsprocessor/application/src/main/resources/application-dev.properties @@ -44,5 +44,5 @@ blueprints.processor.functions.python.executor.modulePaths=./../../../components blueprintsprocessor.restconfEnabled=true
blueprintsprocessor.restclient.sdncodl.type=basic-auth
blueprintsprocessor.restclient.sdncodl.url=http://localhost:8282/
-blueprintsprocessor.restclient.sdncodl.userId=admin
-blueprintsprocessor.restclient.sdncodl.token=Kp8bJ4SXszM0WXlhak3eHlcse2gAw84vaoGGmJvUy2U
\ No newline at end of file +blueprintsprocessor.restclient.sdncodl.username=admin
+blueprintsprocessor.restclient.sdncodl.password=Kp8bJ4SXszM0WXlhak3eHlcse2gAw84vaoGGmJvUy2U
\ No newline at end of file diff --git a/ms/blueprintsprocessor/application/src/main/resources/application.properties b/ms/blueprintsprocessor/application/src/main/resources/application.properties index 8cafceba..3b97e672 100755 --- a/ms/blueprintsprocessor/application/src/main/resources/application.properties +++ b/ms/blueprintsprocessor/application/src/main/resources/application.properties @@ -47,4 +47,5 @@ security.user.name: ccsdkapps blueprintsprocessor.restconfEnabled=true blueprintsprocessor.restclient.sdncodl.type=basic-auth blueprintsprocessor.restclient.sdncodl.url=http://sdnc:8282/ -blueprintsprocessor.restclient.sdncodl.userId=admin +blueprintsprocessor.restclient.sdncodl.username=admin +blueprintsprocessor.restclient.sdncodl.password=Kp8bJ4SXszM0WXlhak3eHlcse2gAw84vaoGGmJvUy2U diff --git a/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/rest/service/BasicAuthRestClientService.kt b/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/rest/service/BasicAuthRestClientService.kt index 0502f67c..98a4fd58 100644 --- a/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/rest/service/BasicAuthRestClientService.kt +++ b/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/rest/service/BasicAuthRestClientService.kt @@ -1,5 +1,5 @@ /* - * Copyright © 2017-2019 AT&T, Bell Canada + * Copyright © 2017-2019 AT&T, Bell Canada, Nordix Foundation * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -12,6 +12,8 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 */ package org.onap.ccsdk.apps.blueprintsprocessor.rest.service @@ -26,21 +28,31 @@ import java.util.* class BasicAuthRestClientService(private val restClientProperties: BasicAuthRestClientProperties) : BlueprintWebClientService { - override fun headers(): Array<BasicHeader> { + override fun defaultHeaders(): Map<String, String> { val encodedCredentials = setBasicAuth(restClientProperties.username, restClientProperties.password) - val params = arrayListOf<BasicHeader>() - params.add(BasicHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE)) - params.add(BasicHeader(HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON_VALUE)) - params.add(BasicHeader(HttpHeaders.AUTHORIZATION, "Basic $encodedCredentials")) - return params.toTypedArray() + return mapOf( + HttpHeaders.CONTENT_TYPE to MediaType.APPLICATION_JSON_VALUE, + HttpHeaders.ACCEPT to MediaType.APPLICATION_JSON_VALUE, + HttpHeaders.AUTHORIZATION to "Basic $encodedCredentials") } override fun host(uri: String): String { return restClientProperties.url + uri } + override fun convertToBasicHeaders(headers: Map<String, String>): Array<BasicHeader> { + val customHeaders: MutableMap<String, String> = headers.toMutableMap() + if (!headers.containsKey(HttpHeaders.AUTHORIZATION)) { + val encodedCredentials = setBasicAuth(restClientProperties.username, restClientProperties.password) + customHeaders[HttpHeaders.AUTHORIZATION] = "Basic $encodedCredentials" + } + return super.convertToBasicHeaders(customHeaders) + } + private fun setBasicAuth(username: String, password: String): String { val credentialsString = "$username:$password" return Base64.getEncoder().encodeToString(credentialsString.toByteArray(Charset.defaultCharset())) } + + }
\ No newline at end of file diff --git a/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/rest/service/BlueprintWebClientService.kt b/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/rest/service/BlueprintWebClientService.kt index 9c2caad7..0629909e 100644 --- a/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/rest/service/BlueprintWebClientService.kt +++ b/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/rest/service/BlueprintWebClientService.kt @@ -1,5 +1,5 @@ /* - * Copyright © 2017-2019 AT&T, Bell Canada + * Copyright © 2017-2019 AT&T, Bell Canada, Nordix Foundation * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -12,15 +12,14 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 */ package org.onap.ccsdk.apps.blueprintsprocessor.rest.service import org.apache.commons.io.IOUtils -import org.apache.http.client.methods.HttpDelete -import org.apache.http.client.methods.HttpGet -import org.apache.http.client.methods.HttpPost -import org.apache.http.client.methods.HttpPut +import org.apache.http.client.methods.* import org.apache.http.entity.StringEntity import org.apache.http.impl.client.CloseableHttpClient import org.apache.http.impl.client.HttpClients @@ -32,7 +31,7 @@ import java.nio.charset.Charset interface BlueprintWebClientService { - fun headers(): Array<BasicHeader> + fun defaultHeaders(): Map<String, String> fun host(uri: String): String @@ -44,48 +43,73 @@ interface BlueprintWebClientService { } fun exchangeResource(methodType: String, path: String, request: String): String { + return this.exchangeResource(methodType, path, request, defaultHeaders()) + } + + fun exchangeResource(methodType: String, path: String, request: String, headers: Map<String, String>): String { + val convertedHeaders: Array<BasicHeader> = convertToBasicHeaders(headers) return when (HttpMethod.resolve(methodType)) { - HttpMethod.DELETE -> delete(path) - HttpMethod.GET -> get(path) - HttpMethod.POST -> post(path, request) - HttpMethod.PUT -> put(path, request) + HttpMethod.DELETE -> delete(path, convertedHeaders) + HttpMethod.GET -> get(path, convertedHeaders) + HttpMethod.POST -> post(path, request, convertedHeaders) + HttpMethod.PUT -> put(path, request, convertedHeaders) + HttpMethod.PATCH -> patch(path, request, convertedHeaders) else -> throw BluePrintProcessorException("Unsupported methodType($methodType)") } } - fun delete(path: String): String { + fun convertToBasicHeaders(headers: Map<String, String>): Array<BasicHeader> { + val convertedHeaders = Array<BasicHeader>(headers.size){ BasicHeader("","") } + var currentElement = 0 + for ((name, value) in headers) { + convertedHeaders[currentElement++] = BasicHeader(name, value) + } + return convertedHeaders + } + + fun delete(path: String, headers: Array<BasicHeader>): String { val httpDelete = HttpDelete(host(path)) - httpDelete.setHeaders(headers()) + httpDelete.setHeaders(headers) httpClient().execute(httpDelete).entity.content.use { return IOUtils.toString(it, Charset.defaultCharset()) } } - fun get(path: String): String { + fun get(path: String, headers: Array<BasicHeader>): String { val httpGet = HttpGet(host(path)) - httpGet.setHeaders(headers()) + httpGet.setHeaders(headers) httpClient().execute(httpGet).entity.content.use { return IOUtils.toString(it, Charset.defaultCharset()) } } - fun post(path: String, request: String): String { + fun post(path: String, request: String, headers: Array<BasicHeader>): String { val httpPost = HttpPost(host(path)) val entity = StringEntity(request) httpPost.entity = entity - httpPost.setHeaders(headers()) + httpPost.setHeaders(headers) httpClient().execute(httpPost).entity.content.use { return IOUtils.toString(it, Charset.defaultCharset()) } } - fun put(path: String, request: String): String { + fun put(path: String, request: String, headers: Array<BasicHeader>): String { val httpPut = HttpPut(host(path)) val entity = StringEntity(request) httpPut.entity = entity - httpPut.setHeaders(headers()) + httpPut.setHeaders(headers) httpClient().execute(httpPut).entity.content.use { return IOUtils.toString(it, Charset.defaultCharset()) } } + + fun patch(path: String, request: String, headers: Array<BasicHeader>): String { + val httpPatch = HttpPatch(host(path)) + val entity = StringEntity(request) + httpPatch.entity = entity + httpPatch.setHeaders(headers) + httpClient().execute(httpPatch).entity.content.use { + return IOUtils.toString(it, Charset.defaultCharset()) + } + } }
\ No newline at end of file diff --git a/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/rest/service/DME2ProxyRestClientService.kt b/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/rest/service/DME2ProxyRestClientService.kt index 2b2578a3..94e146d8 100644 --- a/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/rest/service/DME2ProxyRestClientService.kt +++ b/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/rest/service/DME2ProxyRestClientService.kt @@ -16,11 +16,10 @@ package org.onap.ccsdk.apps.blueprintsprocessor.rest.service -import org.apache.http.message.BasicHeader import org.onap.ccsdk.apps.blueprintsprocessor.rest.RestClientProperties class DME2ProxyRestClientService(restClientProperties: RestClientProperties) : BlueprintWebClientService { - override fun headers(): Array<BasicHeader> { + override fun defaultHeaders(): Map<String, String> { TODO("not implemented") //To change body of created functions use File | Settings | File Templates. } diff --git a/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/rest/service/SSLBasicAuthRestClientService.kt b/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/rest/service/SSLBasicAuthRestClientService.kt index dc2993d9..2bfacf41 100644 --- a/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/rest/service/SSLBasicAuthRestClientService.kt +++ b/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/rest/service/SSLBasicAuthRestClientService.kt @@ -19,7 +19,6 @@ package org.onap.ccsdk.apps.blueprintsprocessor.rest.service import org.apache.http.conn.ssl.SSLConnectionSocketFactory import org.apache.http.impl.client.CloseableHttpClient import org.apache.http.impl.client.HttpClients -import org.apache.http.message.BasicHeader import org.apache.http.ssl.SSLContextBuilder import org.onap.ccsdk.apps.blueprintsprocessor.rest.SSLBasicAuthRestClientProperties import org.onap.ccsdk.apps.blueprintsprocessor.rest.utils.WebClientUtils @@ -33,11 +32,10 @@ import java.security.cert.X509Certificate class SSLBasicAuthRestClientService(private val restClientProperties: SSLBasicAuthRestClientProperties) : BlueprintWebClientService { - override fun headers(): Array<BasicHeader> { - val params = arrayListOf<BasicHeader>() - params.add(BasicHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE)) - params.add(BasicHeader(HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON_VALUE)) - return params.toTypedArray() + override fun defaultHeaders(): Map<String, String> { + return mapOf( + HttpHeaders.CONTENT_TYPE to MediaType.APPLICATION_JSON_VALUE, + HttpHeaders.ACCEPT to MediaType.APPLICATION_JSON_VALUE) } override fun host(uri: String): String { diff --git a/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/rest/service/TokenAuthRestClientService.kt b/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/rest/service/TokenAuthRestClientService.kt index 6e90957d..d5dec3ae 100644 --- a/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/rest/service/TokenAuthRestClientService.kt +++ b/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/rest/service/TokenAuthRestClientService.kt @@ -1,5 +1,5 @@ /* - * Copyright © 2019 Bell Canada + * Copyright © 2019 Bell Canada, Nordix Foundation * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -12,6 +12,8 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 */ package org.onap.ccsdk.apps.blueprintsprocessor.rest.service @@ -24,12 +26,19 @@ import org.springframework.http.MediaType class TokenAuthRestClientService(private val restClientProperties: TokenAuthRestClientProperties) : BlueprintWebClientService { - override fun headers(): Array<BasicHeader> { - val params = arrayListOf<BasicHeader>() - params.add(BasicHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE)) - params.add(BasicHeader(HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON_VALUE)) - params.add(BasicHeader(HttpHeaders.AUTHORIZATION, restClientProperties.token)) - return params.toTypedArray() + override fun defaultHeaders(): Map<String, String> { + return mapOf( + HttpHeaders.CONTENT_TYPE to MediaType.APPLICATION_JSON_VALUE, + HttpHeaders.ACCEPT to MediaType.APPLICATION_JSON_VALUE, + HttpHeaders.AUTHORIZATION to restClientProperties.token!!) + } + + override fun convertToBasicHeaders(headers: Map<String, String>): Array<BasicHeader> { + val customHeaders: MutableMap<String, String> = headers.toMutableMap() + if (!headers.containsKey(HttpHeaders.AUTHORIZATION)) { + customHeaders[HttpHeaders.AUTHORIZATION] = restClientProperties.token!! + } + return super.convertToBasicHeaders(customHeaders) } override fun host(uri: String): String { diff --git a/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/rest/utils/WebClientUtils.kt b/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/rest/utils/WebClientUtils.kt index d6167a87..b9a014e3 100644 --- a/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/rest/utils/WebClientUtils.kt +++ b/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/rest/utils/WebClientUtils.kt @@ -30,6 +30,6 @@ class WebClientUtils { HttpRequestInterceptor { request, _ -> log.info("Rest request method(${request?.requestLine?.method}), url(${request?.requestLine?.uri})") } fun logResponse(): HttpResponseInterceptor = - HttpResponseInterceptor { response, _ -> log.info("Response status(${response.statusLine.statusCode})") } + HttpResponseInterceptor { response, _ -> log.info("Response status(${response.statusLine.statusCode} - ${response.statusLine.reasonPhrase})") } } }
\ No newline at end of file diff --git a/ms/blueprintsprocessor/modules/commons/rest-lib/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/rest/service/RestClientServiceTest.kt b/ms/blueprintsprocessor/modules/commons/rest-lib/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/rest/service/RestClientServiceTest.kt index 4fa82df2..0390550c 100644 --- a/ms/blueprintsprocessor/modules/commons/rest-lib/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/rest/service/RestClientServiceTest.kt +++ b/ms/blueprintsprocessor/modules/commons/rest-lib/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/rest/service/RestClientServiceTest.kt @@ -1,5 +1,6 @@ /* * Copyright © 2017-2018 AT&T Intellectual Property. + * Copyright (C) 2019 Nordix Foundation * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -12,6 +13,8 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 */ package org.onap.ccsdk.apps.blueprintsprocessor.rest.service @@ -29,9 +32,11 @@ import org.springframework.test.context.ContextConfiguration import org.springframework.test.context.TestPropertySource import org.springframework.test.context.junit4.SpringRunner import org.springframework.web.bind.annotation.GetMapping +import org.springframework.web.bind.annotation.PatchMapping import org.springframework.web.bind.annotation.RequestMapping import org.springframework.web.bind.annotation.RestController import kotlin.test.Test +import kotlin.test.assertEquals import kotlin.test.assertNotNull @RunWith(SpringRunner::class) @@ -58,6 +63,13 @@ class RestClientServiceTest { assertNotNull(response, "failed to get response") } + @Test + fun testPatch() { + val restClientService = bluePrintRestLibPropertyService.blueprintWebClientService("sample") + val response = restClientService.exchangeResource(HttpMethod.PATCH.name, "/sample/name", "") + assertEquals("Patch request successful", response, "failed to get patch response") + } + } @RestController @@ -65,5 +77,7 @@ class RestClientServiceTest { open class SampleController { @GetMapping("/name") fun getName(): String = "Sample Controller" + @PatchMapping("/name") + fun patchName(): String = "Patch request successful" } diff --git a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintContext.kt b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintContext.kt index e2211f7e..ca86c964 100644 --- a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintContext.kt +++ b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintContext.kt @@ -44,15 +44,15 @@ class BluePrintContext(val serviceTemplate: ServiceTemplate) { */ var entryDefinition = "" - val imports: List<ImportDefinition>? = serviceTemplate.imports + fun imports(): List<ImportDefinition>? = serviceTemplate.imports - val dslDefinitions = serviceTemplate.dslDefinitions + fun dslDefinitions() = serviceTemplate.dslDefinitions val metadata: MutableMap<String, String>? = serviceTemplate.metadata - val dataTypes: MutableMap<String, DataType>? = serviceTemplate.dataTypes + fun dataTypes(): MutableMap<String, DataType>? = serviceTemplate.dataTypes - val inputs: MutableMap<String, PropertyDefinition>? = serviceTemplate.topologyTemplate?.inputs + fun inputs(): MutableMap<String, PropertyDefinition>? = serviceTemplate.topologyTemplate?.inputs fun blueprintJson(pretty: Boolean = false): String = print("json", pretty) @@ -70,9 +70,9 @@ class BluePrintContext(val serviceTemplate: ServiceTemplate) { ?: throw BluePrintException("could't get template author from meta data") // Workflow - val workflows: MutableMap<String, Workflow>? = serviceTemplate.topologyTemplate?.workflows + fun workflows(): MutableMap<String, Workflow>? = serviceTemplate.topologyTemplate?.workflows - fun workflowByName(workFlowName: String): Workflow = workflows?.get(workFlowName) + fun workflowByName(workFlowName: String): Workflow = workflows()?.get(workFlowName) ?: throw BluePrintException("could't get workflow($workFlowName)") fun workflowInputs(workFlowName: String) = workflowByName(workFlowName).inputs @@ -99,27 +99,27 @@ class BluePrintContext(val serviceTemplate: ServiceTemplate) { } // DSL - fun dslPropertiesByName(name: String): JsonNode = dslDefinitions?.get(name) + fun dslPropertiesByName(name: String): JsonNode = dslDefinitions()?.get(name) ?: throw BluePrintException("could't get policy type for the dsl($name)") // Data Type - fun dataTypeByName(name: String): DataType? = dataTypes?.get(name) + fun dataTypeByName(name: String): DataType? = dataTypes()?.get(name) // Artifact Type - val artifactTypes: MutableMap<String, ArtifactType>? = serviceTemplate.artifactTypes + fun artifactTypes(): MutableMap<String, ArtifactType>? = serviceTemplate.artifactTypes // Policy Types - val policyTypes: MutableMap<String, PolicyType>? = serviceTemplate.policyTypes + fun policyTypes(): MutableMap<String, PolicyType>? = serviceTemplate.policyTypes - fun policyTypeByName(policyName: String) = policyTypes?.get(policyName) + fun policyTypeByName(policyName: String) = policyTypes()?.get(policyName) ?: throw BluePrintException("could't get policy type for the name($policyName)") fun policyTypesDerivedFrom(name: String): MutableMap<String, PolicyType>? { - return policyTypes?.filterValues { policyType -> policyType.derivedFrom == name }?.toMutableMap() + return policyTypes()?.filterValues { policyType -> policyType.derivedFrom == name }?.toMutableMap() } fun policyTypesTarget(target: String): MutableMap<String, PolicyType>? { - return policyTypes?.filterValues { it.targets.contains(target) }?.toMutableMap() + return policyTypes()?.filterValues { it.targets.contains(target) }?.toMutableMap() } fun policyTypesTargetNDerivedFrom(target: String, derivedFrom: String): MutableMap<String, PolicyType>? { @@ -129,14 +129,14 @@ class BluePrintContext(val serviceTemplate: ServiceTemplate) { } // Node Type Methods - val nodeTypes: MutableMap<String, NodeType>? = serviceTemplate.nodeTypes + fun nodeTypes(): MutableMap<String, NodeType>? = serviceTemplate.nodeTypes fun nodeTypeByName(name: String): NodeType = - nodeTypes?.get(name) + nodeTypes()?.get(name) ?: throw BluePrintException("could't get node type for the name($name)") fun nodeTypeDerivedFrom(name: String): MutableMap<String, NodeType>? { - return nodeTypes?.filterValues { nodeType -> nodeType.derivedFrom == name }?.toMutableMap() + return nodeTypes()?.filterValues { nodeType -> nodeType.derivedFrom == name }?.toMutableMap() } fun nodeTypeInterface(nodeTypeName: String, interfaceName: String): InterfaceDefinition { @@ -163,13 +163,13 @@ class BluePrintContext(val serviceTemplate: ServiceTemplate) { } // Node Template Methods - val nodeTemplates: MutableMap<String, NodeTemplate>? = serviceTemplate.topologyTemplate?.nodeTemplates + fun nodeTemplates(): MutableMap<String, NodeTemplate>? = serviceTemplate.topologyTemplate?.nodeTemplates fun nodeTemplateByName(name: String): NodeTemplate = - nodeTemplates?.get(name) ?: throw BluePrintException("could't get node template for the name($name)") + nodeTemplates()?.get(name) ?: throw BluePrintException("could't get node template for the name($name)") fun nodeTemplateForNodeType(name: String): MutableMap<String, NodeTemplate>? { - return nodeTemplates?.filterValues { nodeTemplate -> nodeTemplate.type == name }?.toMutableMap() + return nodeTemplates()?.filterValues { nodeTemplate -> nodeTemplate.type == name }?.toMutableMap() } fun nodeTemplateNodeType(nodeTemplateName: String): NodeType { diff --git a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintRuntimeService.kt b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintRuntimeService.kt index c5828073..c16d1ecc 100644 --- a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintRuntimeService.kt +++ b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintRuntimeService.kt @@ -488,7 +488,7 @@ open class DefaultBluePrintRuntimeService(private var id: String, private var bl override fun assignInputs(jsonNode: JsonNode) { log.info("assignInputs from input JSON ({})", jsonNode.toString()) - bluePrintContext.inputs?.forEach { propertyName, property -> + bluePrintContext.inputs()?.forEach { propertyName, property -> val valueNode: JsonNode = jsonNode.at(BluePrintConstants.PATH_DIVIDER + propertyName) ?: NullNode.getInstance() setInputValue(propertyName, property, valueNode) diff --git a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/BluePrintRuntimeUtils.kt b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/BluePrintRuntimeUtils.kt index c37d8eea..d20fc553 100644 --- a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/BluePrintRuntimeUtils.kt +++ b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/BluePrintRuntimeUtils.kt @@ -49,7 +49,7 @@ object BluePrintRuntimeUtils { fun assignInputs(bluePrintContext: BluePrintContext, jsonNode: JsonNode, context: MutableMap<String, JsonNode>) { log.info("assignInputs from input JSON ({})", jsonNode.toString()) - bluePrintContext.inputs?.forEach { propertyName, _ -> + bluePrintContext.inputs()?.forEach { propertyName, _ -> val valueNode: JsonNode = jsonNode.at("/".plus(propertyName)) ?: NullNode.getInstance() val path = BluePrintConstants.PATH_INPUTS.plus(BluePrintConstants.PATH_DIVIDER).plus(propertyName) diff --git a/ms/controllerblueprints/modules/blueprint-validation/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/validation/BluePrintNodeTemplateValidatorImpl.kt b/ms/controllerblueprints/modules/blueprint-validation/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/validation/BluePrintNodeTemplateValidatorImpl.kt index ded1f384..601ba4f5 100644 --- a/ms/controllerblueprints/modules/blueprint-validation/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/validation/BluePrintNodeTemplateValidatorImpl.kt +++ b/ms/controllerblueprints/modules/blueprint-validation/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/validation/BluePrintNodeTemplateValidatorImpl.kt @@ -247,6 +247,8 @@ open class BluePrintNodeTemplateValidatorImpl(private val bluePrintTypeValidator if (BluePrintTypes.validPrimitiveTypes().contains(propertyType)) { isValid = JacksonUtils.checkJsonNodeValueOfPrimitiveType(propertyType, propertyAssignment) + } else if (BluePrintTypes.validComplexTypes().contains(propertyType)) { + isValid = true } else if (BluePrintTypes.validCollectionTypes().contains(propertyType)) { val entrySchemaType = propertyDefinition.entrySchema?.type diff --git a/ms/controllerblueprints/modules/blueprint-validation/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/validation/BluePrintWorkflowValidatorImpl.kt b/ms/controllerblueprints/modules/blueprint-validation/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/validation/BluePrintWorkflowValidatorImpl.kt index 851a7c60..519358b1 100644 --- a/ms/controllerblueprints/modules/blueprint-validation/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/validation/BluePrintWorkflowValidatorImpl.kt +++ b/ms/controllerblueprints/modules/blueprint-validation/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/validation/BluePrintWorkflowValidatorImpl.kt @@ -58,9 +58,10 @@ open class BluePrintWorkflowValidatorImpl(private val bluePrintTypeValidatorServ val nodeTypeDerivedFrom = bluePrintRuntimeService.bluePrintContext().nodeTemplateNodeType(it).derivedFrom - check(nodeTypeDerivedFrom == BluePrintConstants.MODEL_TYPE_NODE_DG) { - "NodeType(${nodeTemplate.type}) derived from is '$nodeTypeDerivedFrom', Expected is " + - "'${BluePrintConstants.MODEL_TYPE_NODE_DG}'" + check(nodeTypeDerivedFrom == BluePrintConstants.MODEL_TYPE_NODE_DG + || nodeTypeDerivedFrom == BluePrintConstants.MODEL_TYPE_NODE_COMPONENT) { + "NodeType(${nodeTemplate.type}) derived from is '$nodeTypeDerivedFrom', Expected " + + "'${BluePrintConstants.MODEL_TYPE_NODE_DG}' or '${BluePrintConstants.MODEL_TYPE_NODE_COMPONENT}'" } } catch (e: Exception) { bluePrintRuntimeService.getBluePrintError() diff --git a/ms/controllerblueprints/modules/blueprint-validation/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/validation/BluePrintDesignTimeValidatorServiceTest.kt b/ms/controllerblueprints/modules/blueprint-validation/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/validation/BluePrintDesignTimeValidatorServiceTest.kt index 3fc918e6..d844d1ec 100644 --- a/ms/controllerblueprints/modules/blueprint-validation/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/validation/BluePrintDesignTimeValidatorServiceTest.kt +++ b/ms/controllerblueprints/modules/blueprint-validation/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/validation/BluePrintDesignTimeValidatorServiceTest.kt @@ -90,7 +90,9 @@ class BluePrintDesignTimeValidatorServiceTest { workflowValidator.validate(bluePrintRuntime, workflowName, workflow) assertEquals(1, bluePrintRuntime.getBluePrintError().errors.size) - assertEquals("Failed to validate Workflow(resource-assignment)'s step(test)'s definition : resource-assignment/steps/test : NodeType(TestNodeType) derived from is 'tosca.nodes.TEST', Expected is 'tosca.nodes.DG'", bluePrintRuntime.getBluePrintError().errors[0]) + assertEquals("Failed to validate Workflow(resource-assignment)'s step(test)'s definition : " + + "resource-assignment/steps/test : NodeType(TestNodeType) derived from is 'tosca.nodes.TEST', " + + "Expected 'tosca.nodes.DG' or 'tosca.nodes.Component'", bluePrintRuntime.getBluePrintError().errors[0]) } @Test diff --git a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintWorkflowEnhancerImpl.kt b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintWorkflowEnhancerImpl.kt index 9fbf0916..fc9ee504 100644 --- a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintWorkflowEnhancerImpl.kt +++ b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintWorkflowEnhancerImpl.kt @@ -82,8 +82,27 @@ open class BluePrintWorkflowEnhancerImpl(private val bluePrintRepoService: BlueP private fun enhanceStepTargets(name: String, workflow: Workflow) { - // Get the first Step Target NodeTemplate name( Since that is the DG Node Template) - val dgNodeTemplateName = bluePrintContext.workflowFirstStepNodeTemplate(name) + // Get the first Step Target NodeTemplate name( It may be Component or DG Node Template) + val firstNodeTemplateName = bluePrintContext.workflowFirstStepNodeTemplate(name) + + val derivedFrom = bluePrintContext.nodeTemplateNodeType(firstNodeTemplateName).derivedFrom + + when { + derivedFrom.startsWith(BluePrintConstants.MODEL_TYPE_NODE_COMPONENT, true) -> { + // DO Nothing + } + derivedFrom.startsWith(BluePrintConstants.MODEL_TYPE_NODE_DG, true) -> { + enhanceDGStepTargets(name, workflow, firstNodeTemplateName) + } + else -> { + throw BluePrintProcessorException("couldn't execute workflow($name) step mapped " + + "to node template($firstNodeTemplateName) derived from($derivedFrom)") + } + } + + } + + private fun enhanceDGStepTargets(name: String, workflow: Workflow, dgNodeTemplateName: String) { val dgNodeTemplate = bluePrintContext.nodeTemplateByName(dgNodeTemplateName) diff --git a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/ResourceDefinitionEnhancerService.kt b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/ResourceDefinitionEnhancerService.kt index 6171687f..816b3566 100644 --- a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/ResourceDefinitionEnhancerService.kt +++ b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/ResourceDefinitionEnhancerService.kt @@ -75,7 +75,7 @@ class ResourceDefinitionEnhancerServiceImpl(private val resourceDefinitionRepoSe // Get all the Mapping files from all node templates. private fun getAllResourceMappingFiles(blueprintContext: BluePrintContext): List<String>? { - return blueprintContext.nodeTemplates?.mapNotNull { nodeTemplateMap -> + return blueprintContext.nodeTemplates()?.mapNotNull { nodeTemplateMap -> // Return only Mapping Artifact File Names nodeTemplateMap.value.artifacts?.filter { artifactDefinitionMap -> diff --git a/ms/controllerblueprints/modules/service/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintEnhancerServiceImplTest.kt b/ms/controllerblueprints/modules/service/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintEnhancerServiceImplTest.kt index 919d202f..48183f4c 100644 --- a/ms/controllerblueprints/modules/service/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintEnhancerServiceImplTest.kt +++ b/ms/controllerblueprints/modules/service/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintEnhancerServiceImplTest.kt @@ -64,30 +64,34 @@ class BluePrintEnhancerServiceImplTest { fun testEnhancementAndValidation() { val basePath = "./../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration" - - val targetPath = Paths.get("target", "bp-enhance").toUri().path - - val bluePrintContext = bluePrintEnhancerService.enhance(basePath, targetPath) - Assert.assertNotNull("failed to get blueprintContext ", bluePrintContext) - - // Validate the Generated BluePrints - val valid = bluePrintValidatorService.validateBluePrints(targetPath) - Assert.assertTrue("blueprint validation failed ", valid) + testComponentInvokeEnhancementAndValidation(basePath, "base-enhance") } @Test @Throws(Exception::class) - fun testEnhancementAndValidation2() { + fun testComponentInvokeEnhancementAndValidation() { + val basePath = "./../../../../components/model-catalog/blueprint-model/test-blueprint/component_invoke" + testComponentInvokeEnhancementAndValidation(basePath, "component-enhance") + } + @Test + @Throws(Exception::class) + fun testGoldenEnhancementAndValidation() { val basePath = "./../../../../components/model-catalog/blueprint-model/test-blueprint/golden" + testComponentInvokeEnhancementAndValidation(basePath, "golden-enhance") + } - val targetPath = Paths.get("target", "bp-enhance").toUri().path + + private fun testComponentInvokeEnhancementAndValidation(basePath: String, targetDirName: String) { + + val targetPath = Paths.get("target", targetDirName).toUri().path val bluePrintContext = bluePrintEnhancerService.enhance(basePath, targetPath) Assert.assertNotNull("failed to get blueprintContext ", bluePrintContext) // Validate the Generated BluePrints val valid = bluePrintValidatorService.validateBluePrints(targetPath) - Assert.assertTrue("blueprint validation failed ", valid) + Assert.assertTrue("blueprint($basePath) validation failed ", valid) } + }
\ No newline at end of file |