diff options
author | Dan Timoney <dtimoney@att.com> | 2019-07-23 18:43:07 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2019-07-23 18:43:07 +0000 |
commit | 19035ee3f24c3f585ee27942000b1b81eefc82bc (patch) | |
tree | 3b955bf87db01b96ad401e8345822b514a4d7531 /ms/controllerblueprints/modules/blueprint-core/src/main | |
parent | 45880f115b90cfa38440b1a75ff12e55eadae07a (diff) | |
parent | 257dff5659f752d98dfe9421e9761aa5d84bd294 (diff) |
Merge "Improve service template access through cache."
Diffstat (limited to 'ms/controllerblueprints/modules/blueprint-core/src/main')
5 files changed, 112 insertions, 15 deletions
diff --git a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/interfaces/BluePrintDefinitions.kt b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/interfaces/BluePrintDefinitions.kt new file mode 100644 index 000000000..8267e5dcc --- /dev/null +++ b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/interfaces/BluePrintDefinitions.kt @@ -0,0 +1,61 @@ +/* + * Copyright © 2019 IBM. + * + * 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.cds.controllerblueprints.core.interfaces + +import org.onap.ccsdk.cds.controllerblueprints.core.data.ServiceTemplate + +interface BluePrintDefinitions { + + /** Define the service Template Model */ + fun serviceTemplate(): ServiceTemplate + + /** Load Custom Definitions that may used during runtime **/ + fun loadOtherDefinitions() + + /** Utility Method to add the definition */ + fun addOtherDefinition(key: String, definition: Any) + + /** Utility method to get the definition */ + fun <T : Any> otherDefinition(key: String): T + + fun otherDefinitions(): MutableMap<String, Any> +} + +abstract class AbstractBluePrintDefinitions : BluePrintDefinitions { + + private val otherDefinitionMap: MutableMap<String, Any> = hashMapOf() + + constructor() { + loadOtherDefinitions() + } + + override fun loadOtherDefinitions() { + } + + override fun <T : Any> otherDefinition(key: String): T { + return otherDefinitionMap[key] as T + } + + override fun addOtherDefinition(key: String, definition: Any) { + otherDefinitionMap[key] = definition + } + + override fun otherDefinitions(): MutableMap<String, Any> { + return otherDefinitionMap + } + +}
\ No newline at end of file diff --git a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/scripts/BluePrintCompilerCache.kt b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/scripts/BluePrintCompilerCache.kt index 73051392c..db139eb59 100644 --- a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/scripts/BluePrintCompilerCache.kt +++ b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/scripts/BluePrintCompilerCache.kt @@ -19,7 +19,6 @@ package org.onap.ccsdk.cds.controllerblueprints.core.scripts import com.google.common.cache.CacheBuilder import com.google.common.cache.CacheLoader import com.google.common.cache.LoadingCache -import com.google.common.util.concurrent.ListenableFuture import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintException import org.onap.ccsdk.cds.controllerblueprints.core.logger import org.onap.ccsdk.cds.controllerblueprints.core.normalizedFile @@ -52,10 +51,6 @@ object BluePrintClassLoader : CacheLoader<String, URLClassLoader>() { val log = logger(BluePrintClassLoader::class) - override fun reload(key: String, oldValue: URLClassLoader): ListenableFuture<URLClassLoader> { - return reload(key, oldValue) - } - override fun load(key: String): URLClassLoader { log.info("loading cache key($key)") val keyPath = normalizedFile(key) diff --git a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/service/BluePrintContext.kt b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/service/BluePrintContext.kt index 26181bb19..066516fcc 100644 --- a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/service/BluePrintContext.kt +++ b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/service/BluePrintContext.kt @@ -18,12 +18,12 @@ package org.onap.ccsdk.cds.controllerblueprints.core.service -import org.slf4j.LoggerFactory import com.fasterxml.jackson.databind.JsonNode import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintException import org.onap.ccsdk.cds.controllerblueprints.core.data.* import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils +import org.slf4j.LoggerFactory /** * @@ -32,7 +32,7 @@ import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils */ class BluePrintContext(val serviceTemplate: ServiceTemplate) { - private val log= LoggerFactory.getLogger(this::class.toString()) + private val log = LoggerFactory.getLogger(this::class.toString()) /** * Blueprint CBA extracted file location @@ -43,6 +43,13 @@ class BluePrintContext(val serviceTemplate: ServiceTemplate) { */ var entryDefinition = "" + /** Other definitions along with model, It may Resource Definition, Resource Assignments, Configurations etc..*/ + var otherDefinitions: MutableMap<String, Any> = hashMapOf() + + fun <T> otherDefinition(key: String) = otherDefinitions[key] as T + + fun checkOtherDefinition(key: String) = otherDefinitions.containsKey(key) + fun imports(): List<ImportDefinition>? = serviceTemplate.imports fun dslDefinitions() = serviceTemplate.dslDefinitions diff --git a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/utils/BluePrintFileUtils.kt b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/utils/BluePrintFileUtils.kt index ad91d45c3..17a7fd348 100755 --- a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/utils/BluePrintFileUtils.kt +++ b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/utils/BluePrintFileUtils.kt @@ -1,6 +1,7 @@ /* * Copyright © 2017-2018 AT&T Intellectual Property. * Modifications Copyright © 2019 Bell Canada. + * Modifications Copyright © 2019 IBM. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -215,6 +216,8 @@ class BluePrintFileUtils { "\nCSAR-Version: <VERSION>" + "\nCreated-By: <AUTHOR NAME>" + "\nEntry-Definitions: Definitions/<BLUEPRINT_NAME>.json" + + "\nTemplate-Name: <BLUEPRINT_NAME>"+ + "\nTemplate-Tags: <BLUEPRINT_VERSION>"+ "\nTemplate-Tags: <TAGS>" } diff --git a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/utils/BluePrintMetadataUtils.kt b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/utils/BluePrintMetadataUtils.kt index 6f090783a..3a1edccc0 100644 --- a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/utils/BluePrintMetadataUtils.kt +++ b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/utils/BluePrintMetadataUtils.kt @@ -20,11 +20,10 @@ package org.onap.ccsdk.cds.controllerblueprints.core.utils import com.fasterxml.jackson.databind.JsonNode import kotlinx.coroutines.runBlocking -import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants -import org.onap.ccsdk.cds.controllerblueprints.core.asJsonPrimitive +import org.onap.ccsdk.cds.controllerblueprints.core.* import org.onap.ccsdk.cds.controllerblueprints.core.data.ToscaMetaData -import org.onap.ccsdk.cds.controllerblueprints.core.normalizedFile -import org.onap.ccsdk.cds.controllerblueprints.core.readNBLines +import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BluePrintDefinitions +import org.onap.ccsdk.cds.controllerblueprints.core.scripts.BluePrintScriptsServiceImpl import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintContext import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintImportService import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintRuntimeService @@ -138,7 +137,12 @@ class BluePrintMetadataUtils { log.info("Reading blueprint path($blueprintBasePath) and entry definition file (${toscaMetaData.entityDefinitions})") - readBlueprintFile(toscaMetaData.entityDefinitions, blueprintBasePath) + // If the EntryDefinition is Kotlin file, compile and get Service Template + if (toscaMetaData.entityDefinitions.endsWith("kt")) { + readBlueprintKotlinFile(toscaMetaData, blueprintBasePath) + } else { + readBlueprintFile(toscaMetaData.entityDefinitions, blueprintBasePath) + } } private suspend fun getBaseEnhancementBluePrintContext(blueprintBasePath: String): BluePrintContext { @@ -158,15 +162,42 @@ class BluePrintMetadataUtils { } private suspend fun readBlueprintFile(entityDefinitions: String, basePath: String): BluePrintContext { - val rootFilePath: String = basePath.plus(File.separator).plus(entityDefinitions) + val normalizedBasePath = normalizedPathName(basePath) + val rootFilePath = normalizedPathName(normalizedBasePath, entityDefinitions) val rootServiceTemplate = ServiceTemplateUtils.getServiceTemplate(rootFilePath) // Recursively Import Template files - val schemaImportResolverUtils = BluePrintImportService(rootServiceTemplate, basePath) + val schemaImportResolverUtils = BluePrintImportService(rootServiceTemplate, normalizedBasePath) val completeServiceTemplate = schemaImportResolverUtils.getImportResolvedServiceTemplate() val blueprintContext = BluePrintContext(completeServiceTemplate) - blueprintContext.rootPath = basePath + blueprintContext.rootPath = normalizedBasePath blueprintContext.entryDefinition = entityDefinitions return blueprintContext } + + /** Reade the Service Template Definitions from the Kotlin file */ + private suspend fun readBlueprintKotlinFile(toscaMetaData: ToscaMetaData, basePath: String): BluePrintContext { + + checkNotNull(toscaMetaData.templateName) { "couldn't find 'Template-Name' key in TOSCA.meta" } + checkNotNull(toscaMetaData.templateVersion) { "couldn't find 'Template-Version' key in TOSCA.meta" } + + val definitionClassName = toscaMetaData.entityDefinitions.removeSuffix(".kt") + val normalizedBasePath = normalizedPathName(basePath) + + val bluePrintScriptsService = BluePrintScriptsServiceImpl() + val bluePrintDefinitions = bluePrintScriptsService + .scriptInstance<BluePrintDefinitions>(normalizedBasePath, toscaMetaData.templateName!!, + toscaMetaData.templateVersion!!, definitionClassName, true) + // Get the Service Template + val serviceTemplate = bluePrintDefinitions.serviceTemplate() + + // Clean the Default type import Definitions + BluePrintFileUtils.cleanImportTypes(serviceTemplate) + + val blueprintContext = BluePrintContext(serviceTemplate) + blueprintContext.rootPath = normalizedBasePath + blueprintContext.entryDefinition = toscaMetaData.entityDefinitions + blueprintContext.otherDefinitions = bluePrintDefinitions.otherDefinitions() + return blueprintContext + } } }
\ No newline at end of file |