aboutsummaryrefslogtreecommitdiffstats
path: root/components/core/src/main
diff options
context:
space:
mode:
authorMuthuramalingam, Brinda Santh(bs2796) <bs2796@att.com>2018-11-12 15:08:40 -0500
committerMuthuramalingam, Brinda Santh(bs2796) <bs2796@att.com>2018-11-12 15:08:40 -0500
commitf4fb7a6f016fbe0bd06525b05eb26a365be7c6ba (patch)
treee1b8b7951d71232ceb2e9afee2350d7b291ba23d /components/core/src/main
parentcfd7f8b587045758a64ed36581e6e37083fb158c (diff)
Controller Blueprints Microservice
Add blueprint multiple import file capability. Change-Id: If57aecb08447252b0e84a7e55b081e682d6a0bbd Issue-ID: CCSDK-681 Signed-off-by: Muthuramalingam, Brinda Santh(bs2796) <bs2796@att.com>
Diffstat (limited to 'components/core/src/main')
-rw-r--r--components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintImportService.kt94
-rw-r--r--components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintValidatorService.kt10
-rw-r--r--components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/BluePrintMetadataUtils.kt9
-rw-r--r--components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/ServiceTemplateUtils.kt66
4 files changed, 170 insertions, 9 deletions
diff --git a/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintImportService.kt b/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintImportService.kt
new file mode 100644
index 000000000..fce06f3f5
--- /dev/null
+++ b/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintImportService.kt
@@ -0,0 +1,94 @@
+/*
+ * Copyright © 2017-2018 AT&T Intellectual Property.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * 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.
+ */
+
+package org.onap.ccsdk.apps.controllerblueprints.core.service
+
+import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException
+import org.onap.ccsdk.apps.controllerblueprints.core.data.ImportDefinition
+import org.onap.ccsdk.apps.controllerblueprints.core.data.ServiceTemplate
+import org.onap.ccsdk.apps.controllerblueprints.core.utils.ServiceTemplateUtils
+import org.slf4j.Logger
+import org.slf4j.LoggerFactory
+import java.io.File
+import java.net.URL
+import java.net.URLDecoder
+import java.nio.charset.Charset
+
+class BluePrintImportService(private val parentServiceTemplate: ServiceTemplate, private val blueprintBasePath: String) {
+
+ private val log: Logger = LoggerFactory.getLogger(this::class.toString())
+ val PARENT_SERVICE_TEMPLATE: String = "parent"
+
+ var importServiceTemplateMap: MutableMap<String, ServiceTemplate> = hashMapOf()
+
+
+ fun getImportResolvedServiceTemplate(): ServiceTemplate {
+ // Populate Imported Service Templates
+ traverseSchema(PARENT_SERVICE_TEMPLATE, parentServiceTemplate)
+
+ importServiceTemplateMap.forEach { key, serviceTemplate ->
+ ServiceTemplateUtils.merge(parentServiceTemplate, serviceTemplate)
+ log.debug("merged service template $key")
+ }
+ return parentServiceTemplate
+ }
+
+ private fun traverseSchema(key: String, serviceTemplate: ServiceTemplate) {
+ if (key != PARENT_SERVICE_TEMPLATE) {
+ importServiceTemplateMap[key] = serviceTemplate
+ }
+ val imports: List<ImportDefinition>? = serviceTemplate.imports
+
+ imports?.let {
+ serviceTemplate.imports?.forEach { importDefinition ->
+ val childServiceTemplate = resolveImportDefinition(importDefinition)
+ val keyName: String = importDefinition.file
+ traverseSchema(keyName, childServiceTemplate)
+ }
+ }
+ }
+
+ private fun resolveImportDefinition(importDefinition: ImportDefinition): ServiceTemplate {
+ var serviceTemplate: ServiceTemplate? = null
+ val file: String = importDefinition.file
+ val decodedSystemId: String = URLDecoder.decode(file, Charset.defaultCharset().toString())
+ log.trace("file ({}), decodedSystemId ({}) ", file, decodedSystemId)
+ try {
+ if (decodedSystemId.startsWith("http", true)
+ || decodedSystemId.startsWith("https", true)) {
+ val givenUrl: String = URL(decodedSystemId).toString()
+ val systemUrl: String = File(".").toURI().toURL().toString()
+ log.trace("givenUrl ({}), systemUrl ({}) ", givenUrl, systemUrl)
+ if (givenUrl.startsWith(systemUrl)) {
+
+ }
+ } else {
+ if (!decodedSystemId.startsWith("/")) {
+ importDefinition.file = StringBuilder().append(blueprintBasePath).append(File.separator).append(file).toString()
+ }
+ serviceTemplate = ServiceTemplateUtils.getServiceTemplate(importDefinition.file)
+ }
+ } catch (e: Exception) {
+ throw BluePrintException("failed to populate service template for ${importDefinition.file}", e)
+ }
+ if (serviceTemplate == null) {
+ throw BluePrintException("failed to populate service template for : ${importDefinition.file}")
+ }
+ return serviceTemplate
+ }
+
+
+} \ No newline at end of file
diff --git a/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintValidatorService.kt b/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintValidatorService.kt
index 7ad38332a..178373704 100644
--- a/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintValidatorService.kt
+++ b/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintValidatorService.kt
@@ -17,13 +17,13 @@
package org.onap.ccsdk.apps.controllerblueprints.core.service
+import com.att.eelf.configuration.EELFLogger
+import com.att.eelf.configuration.EELFManager
import com.fasterxml.jackson.databind.JsonNode
import com.google.common.base.Preconditions
import org.apache.commons.lang3.StringUtils
import org.onap.ccsdk.apps.controllerblueprints.core.*
import org.onap.ccsdk.apps.controllerblueprints.core.data.*
-import com.att.eelf.configuration.EELFLogger
-import com.att.eelf.configuration.EELFManager
import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils
import java.io.Serializable
@@ -530,7 +530,7 @@ open class BluePrintValidatorDefaultService : BluePrintValidatorService {
open fun checkValidArtifactType(artifactDefinitionName: String, artifactTypeName: String) {
val artifactType = serviceTemplate.artifactTypes?.get(artifactTypeName)
- ?: throw BluePrintException(format("Failed to ArtifactType for ArtifactDefinition : {}", artifactDefinitionName))
+ ?: throw BluePrintException("failed to artifactType($artifactTypeName) for ArtifactDefinition($artifactDefinitionName)")
checkValidArtifactTypeDerivedFrom(artifactTypeName, artifactType.derivedFrom)
}
@@ -538,14 +538,14 @@ open class BluePrintValidatorDefaultService : BluePrintValidatorService {
@Throws(BluePrintException::class)
open fun checkValidArtifactTypeDerivedFrom(artifactTypeName: String, derivedFrom: String) {
check(BluePrintTypes.validArtifactTypeDerivedFroms.contains(derivedFrom)) {
- throw BluePrintException(format("Failed to get ArtifactType ({})'s derivedFrom({}) definition ", artifactTypeName, derivedFrom))
+ throw BluePrintException("failed to get artifactType($artifactTypeName)'s derivedFrom($derivedFrom) definition")
}
}
@Throws(BluePrintException::class)
open fun checkValidDataTypeDerivedFrom(dataTypeName: String, derivedFrom: String) {
check(BluePrintTypes.validDataTypeDerivedFroms.contains(derivedFrom)) {
- throw BluePrintException(format("Failed to get DataType ({})'s derivedFrom({}) definition ", dataTypeName, derivedFrom))
+ throw BluePrintException(format("Failed to get DataType({})'s derivedFrom({}) definition ", dataTypeName, derivedFrom))
}
}
diff --git a/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/BluePrintMetadataUtils.kt b/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/BluePrintMetadataUtils.kt
index 43d55feac..320c306c3 100644
--- a/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/BluePrintMetadataUtils.kt
+++ b/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/BluePrintMetadataUtils.kt
@@ -25,6 +25,7 @@ import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants
import org.onap.ccsdk.apps.controllerblueprints.core.asJsonPrimitive
import org.onap.ccsdk.apps.controllerblueprints.core.data.ToscaMetaData
import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintContext
+import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintImportService
import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintRuntimeService
import org.onap.ccsdk.apps.controllerblueprints.core.service.DefaultBluePrintRuntimeService
import java.io.File
@@ -99,9 +100,9 @@ object BluePrintMetadataUtils {
fun readBlueprintFile(entityDefinitions: String, basePath: String): BluePrintContext {
val rootFilePath: String = basePath.plus(File.separator).plus(entityDefinitions)
val rootServiceTemplate = ServiceTemplateUtils.getServiceTemplate(rootFilePath)
- // TODO ("Fix for Multiple Service Template file definitions")
-// val schemaImportResolverUtils = BluePrintResolverService(rootServiceTemplate, basePath)
-// val completeServiceTemplate = schemaImportResolverUtils.getImportResolvedServiceTemplate()
- return BluePrintContext(rootServiceTemplate)
+ // Recursively Import Template files
+ val schemaImportResolverUtils = BluePrintImportService(rootServiceTemplate, basePath)
+ val completeServiceTemplate = schemaImportResolverUtils.getImportResolvedServiceTemplate()
+ return BluePrintContext(completeServiceTemplate)
}
} \ No newline at end of file
diff --git a/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/ServiceTemplateUtils.kt b/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/ServiceTemplateUtils.kt
index 0d739357c..0249e20b1 100644
--- a/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/ServiceTemplateUtils.kt
+++ b/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/ServiceTemplateUtils.kt
@@ -18,6 +18,7 @@ package org.onap.ccsdk.apps.controllerblueprints.core.utils
import org.apache.commons.io.FileUtils
import org.onap.ccsdk.apps.controllerblueprints.core.data.ServiceTemplate
+import org.onap.ccsdk.apps.controllerblueprints.core.data.TopologyTemplate
import java.io.File
import java.nio.charset.Charset
@@ -40,5 +41,70 @@ object ServiceTemplateUtils {
return JacksonUtils.readValue(content)
}
+ fun merge(parentServiceTemplate: ServiceTemplate, toMerge: ServiceTemplate, removeImports: Boolean? = true): ServiceTemplate {
+ if (removeImports!!) {
+ parentServiceTemplate.imports = null
+ toMerge.imports = null
+ }
+
+ toMerge.metadata?.let {
+ parentServiceTemplate.metadata = parentServiceTemplate.metadata ?: hashMapOf()
+ parentServiceTemplate.metadata?.putAll(toMerge.metadata as MutableMap)
+ }
+
+ toMerge.dslDefinitions?.let {
+ parentServiceTemplate.dslDefinitions = parentServiceTemplate.dslDefinitions ?: hashMapOf()
+ parentServiceTemplate.dslDefinitions?.putAll(toMerge.dslDefinitions as MutableMap)
+ }
+
+ toMerge.dataTypes?.let {
+ parentServiceTemplate.dataTypes = parentServiceTemplate.dataTypes ?: hashMapOf()
+ parentServiceTemplate.dataTypes?.putAll(toMerge.dataTypes as MutableMap)
+ }
+
+ toMerge.nodeTypes?.let {
+ parentServiceTemplate.nodeTypes = parentServiceTemplate.nodeTypes ?: hashMapOf()
+ parentServiceTemplate.nodeTypes?.putAll(toMerge.nodeTypes as MutableMap)
+ }
+
+ toMerge.artifactTypes?.let {
+ parentServiceTemplate.artifactTypes = parentServiceTemplate.artifactTypes ?: hashMapOf()
+ parentServiceTemplate.artifactTypes?.putAll(toMerge.artifactTypes as MutableMap)
+ }
+
+ toMerge.repositories?.let {
+ parentServiceTemplate.repositories = parentServiceTemplate.repositories ?: hashMapOf()
+ parentServiceTemplate.repositories?.putAll(toMerge.repositories as MutableMap)
+ }
+
+ parentServiceTemplate.topologyTemplate = parentServiceTemplate.topologyTemplate ?: TopologyTemplate()
+
+ toMerge.topologyTemplate?.inputs?.let {
+ parentServiceTemplate.topologyTemplate?.inputs = parentServiceTemplate.topologyTemplate?.inputs ?: hashMapOf()
+ parentServiceTemplate.topologyTemplate?.inputs?.putAll(parentServiceTemplate.topologyTemplate?.inputs as MutableMap)
+ }
+
+ toMerge.topologyTemplate?.nodeTemplates?.let {
+ parentServiceTemplate.topologyTemplate?.nodeTemplates = parentServiceTemplate.topologyTemplate?.nodeTemplates ?: hashMapOf()
+ parentServiceTemplate.topologyTemplate?.nodeTemplates?.putAll(parentServiceTemplate.topologyTemplate?.nodeTemplates as MutableMap)
+ }
+
+ toMerge.topologyTemplate?.relationshipTemplates?.let {
+ parentServiceTemplate.topologyTemplate?.relationshipTemplates = parentServiceTemplate.topologyTemplate?.relationshipTemplates ?: hashMapOf()
+ parentServiceTemplate.topologyTemplate?.relationshipTemplates?.putAll(parentServiceTemplate.topologyTemplate?.relationshipTemplates as MutableMap)
+ }
+
+ toMerge.topologyTemplate?.policies?.let {
+ parentServiceTemplate.topologyTemplate?.policies = parentServiceTemplate.topologyTemplate?.policies ?: hashMapOf()
+ parentServiceTemplate.topologyTemplate?.policies?.putAll(parentServiceTemplate.topologyTemplate?.policies as MutableMap)
+ }
+
+ toMerge.topologyTemplate?.workflows?.let {
+ parentServiceTemplate.topologyTemplate?.workflows = parentServiceTemplate.topologyTemplate?.workflows ?: hashMapOf()
+ parentServiceTemplate.topologyTemplate?.workflows?.putAll(parentServiceTemplate.topologyTemplate?.workflows as MutableMap)
+ }
+ return parentServiceTemplate
+ }
+
} \ No newline at end of file