package org.onap.ccsdk.apps.controllerblueprints.core.interfaces
-import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintError
import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException
import org.onap.ccsdk.apps.controllerblueprints.core.data.*
import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintContext
+import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintRuntimeService
interface BluePrintEnhancer<T> {
- fun enhance(bluePrintContext: BluePrintContext, error: BluePrintError, name: String, type: T)
+ fun enhance(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, type: T)
}
interface BluePrintServiceTemplateEnhancer : BluePrintEnhancer<ServiceTemplate>
@Throws(BluePrintException::class)
fun enhance(basePath: String): BluePrintContext
-
- @Throws(BluePrintException::class)
- fun enhance(serviceTemplate: ServiceTemplate): ServiceTemplate
}
interface BluePrintTypeEnhancerService {
fun getAttributeDefinitionEnhancers(): List<BluePrintAttributeDefinitionEnhancer>
- fun enhanceServiceTemplate(bluePrintContext: BluePrintContext, error: BluePrintError, name: String, serviceTemplate: ServiceTemplate) {
+ fun enhanceServiceTemplate(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, serviceTemplate: ServiceTemplate) {
val enhancers = getServiceTemplateEnhancers()
- doEnhancement(bluePrintContext, error, name, serviceTemplate, enhancers)
+ doEnhancement(bluePrintRuntimeService, name, serviceTemplate, enhancers)
}
- fun enhanceTopologyTemplate(bluePrintContext: BluePrintContext, error: BluePrintError, name: String, topologyTemplate: TopologyTemplate) {
+ fun enhanceTopologyTemplate(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, topologyTemplate: TopologyTemplate) {
val enhancers = getTopologyTemplateEnhancers()
- doEnhancement(bluePrintContext, error, name, topologyTemplate, enhancers)
+ doEnhancement(bluePrintRuntimeService, name, topologyTemplate, enhancers)
}
- fun enhanceWorkflow(bluePrintContext: BluePrintContext, error: BluePrintError, name: String, workflow: Workflow) {
+ fun enhanceWorkflow(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, workflow: Workflow) {
val enhancers = getWorkflowEnhancers()
- doEnhancement(bluePrintContext, error, name, workflow, enhancers)
+ doEnhancement(bluePrintRuntimeService, name, workflow, enhancers)
}
- fun enhanceNodeTemplate(bluePrintContext: BluePrintContext, error: BluePrintError, name: String, nodeTemplate: NodeTemplate) {
+ fun enhanceNodeTemplate(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, nodeTemplate: NodeTemplate) {
val enhancers = getNodeTemplateEnhancers()
- doEnhancement(bluePrintContext, error, name, nodeTemplate, enhancers)
+ doEnhancement(bluePrintRuntimeService, name, nodeTemplate, enhancers)
}
- fun enhanceNodeType(bluePrintContext: BluePrintContext, error: BluePrintError, name: String, nodeType: NodeType) {
+ fun enhanceNodeType(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, nodeType: NodeType) {
val enhancers = getNodeTypeEnhancers()
- doEnhancement(bluePrintContext, error, name, nodeType, enhancers)
+ doEnhancement(bluePrintRuntimeService, name, nodeType, enhancers)
}
- fun enhancePolicyType(bluePrintContext: BluePrintContext, error: BluePrintError, name: String, policyType: PolicyType) {
+ fun enhancePolicyType(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, policyType: PolicyType) {
val enhancers = getPolicyTypeEnhancers()
- doEnhancement(bluePrintContext, error, name, policyType, enhancers)
+ doEnhancement(bluePrintRuntimeService, name, policyType, enhancers)
}
- fun enhancePropertyDefinitions(bluePrintContext: BluePrintContext, error: BluePrintError, properties: MutableMap<String, PropertyDefinition>) {
+ fun enhancePropertyDefinitions(bluePrintRuntimeService: BluePrintRuntimeService<*>, properties: MutableMap<String, PropertyDefinition>) {
properties.forEach { propertyName, propertyDefinition ->
- enhancePropertyDefinition(bluePrintContext, error, propertyName, propertyDefinition)
+ enhancePropertyDefinition(bluePrintRuntimeService, propertyName, propertyDefinition)
}
}
- fun enhancePropertyDefinition(bluePrintContext: BluePrintContext, error: BluePrintError, name: String, propertyDefinition: PropertyDefinition) {
+ fun enhancePropertyDefinition(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, propertyDefinition: PropertyDefinition) {
val enhancers = getPropertyDefinitionEnhancers()
- doEnhancement(bluePrintContext, error, name, propertyDefinition, enhancers)
+ doEnhancement(bluePrintRuntimeService, name, propertyDefinition, enhancers)
}
- fun enhanceAttributeDefinitions(bluePrintContext: BluePrintContext, error: BluePrintError, attributes: MutableMap<String, AttributeDefinition>) {
+ fun enhanceAttributeDefinitions(bluePrintRuntimeService: BluePrintRuntimeService<*>, attributes: MutableMap<String, AttributeDefinition>) {
attributes.forEach { attributeName, attributeDefinition ->
- enhanceAttributeDefinition(bluePrintContext, error, attributeName, attributeDefinition)
+ enhanceAttributeDefinition(bluePrintRuntimeService, attributeName, attributeDefinition)
}
}
- fun enhanceAttributeDefinition(bluePrintContext: BluePrintContext, error: BluePrintError, name: String, attributeDefinition: AttributeDefinition) {
+ fun enhanceAttributeDefinition(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, attributeDefinition: AttributeDefinition) {
val enhancers = getAttributeDefinitionEnhancers()
- doEnhancement(bluePrintContext, error, name, attributeDefinition, enhancers)
+ doEnhancement(bluePrintRuntimeService, name, attributeDefinition, enhancers)
}
@Suppress("UNCHECKED_CAST")
- private fun <T> doEnhancement(bluePrintContext: BluePrintContext, error: BluePrintError, name: String, definition: Any, enhancers: List<BluePrintEnhancer<T>>) {
+ private fun <T> doEnhancement(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, definition: Any, enhancers: List<BluePrintEnhancer<T>>) {
if (enhancers.isNotEmpty()) {
enhancers.forEach {
- it.enhance(bluePrintContext, error, name, definition as T)
+ it.enhance(bluePrintRuntimeService, name, definition as T)
}
}
}
import com.fasterxml.jackson.databind.node.ObjectNode\r
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper\r
import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants\r
+import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintError\r
import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintProcessorException\r
import org.onap.ccsdk.apps.controllerblueprints.core.data.ArtifactDefinition\r
import org.onap.ccsdk.apps.controllerblueprints.core.data.NodeTemplate\r
\r
fun getAsDouble(key: String): Double?\r
\r
+ fun getBluePrintError(): BluePrintError\r
+\r
+ fun setBluePrintError(bluePrintError: BluePrintError)\r
+\r
/*\r
Get the Node Type Definition for the Node Template, Then iterate Node Type Properties and resolve the expressing\r
*/\r
\r
private var store: MutableMap<String, JsonNode> = hashMapOf()\r
\r
+ private var bluePrintError = BluePrintError()\r
+\r
override fun id(): String {\r
return id\r
}\r
return get(key).asDouble()\r
}\r
\r
+ override fun getBluePrintError(): BluePrintError {\r
+ return this.bluePrintError\r
+ }\r
+\r
+ override fun setBluePrintError(bluePrintError: BluePrintError) {\r
+ this.bluePrintError = bluePrintError\r
+ }\r
+\r
/*\r
- Get the Node Type Definition for the Node Template, Then iterate Node Type Properties and resolve the expressing\r
- */\r
+ Get the Node Type Definition for the Node Template, Then iterate Node Type Properties and resolve the expressing\r
+ */\r
override fun resolveNodeTemplateProperties(nodeTemplateName: String): MutableMap<String, JsonNode> {\r
log.info("resolveNodeTemplatePropertyValues for node template ({})", nodeTemplateName)\r
val propertyAssignmentValue: MutableMap<String, JsonNode> = hashMapOf()\r
setInputValue(propertyName, property, valueNode)\r
}\r
}\r
-\r
+ // Load Dynamic data Types\r
val workflowDynamicInputs: JsonNode? = jsonNode.get(dynamicInputPropertiesName)\r
\r
workflowDynamicInputs?.let {\r
- bluePrintContext.dataTypeByName(dynamicInputPropertiesName)?.properties?.forEach { propertyName, property ->\r
+ bluePrintContext.dataTypeByName("dt-$dynamicInputPropertiesName")?.properties?.forEach { propertyName, property ->\r
val valueNode: JsonNode = workflowDynamicInputs.at(BluePrintConstants.PATH_DIVIDER + propertyName)\r
?: NullNode.getInstance()\r
setInputValue(propertyName, property, valueNode)\r
throw BluePrintException("couldn't get definition file under path(${definitionDir.absolutePath})")
}
- blueprintContext.dataTypes.let {
- val dataTypesContent = JacksonUtils.getWrappedJson(BluePrintConstants.PATH_DATA_TYPES, blueprintContext.dataTypes!!, true)
- writeFile(definitionDir.absolutePath, BluePrintConstants.PATH_DATA_TYPES, dataTypesContent)
+ blueprintContext.serviceTemplate.dataTypes?.let {
+ val dataTypesContent = JacksonUtils.getWrappedJson(BluePrintConstants.PATH_DATA_TYPES, it, true)
+ writeTypeFile(definitionDir.absolutePath, BluePrintConstants.PATH_DATA_TYPES, dataTypesContent)
+ }
+ blueprintContext.serviceTemplate.artifactTypes?.let {
+ val artifactTypesContent = JacksonUtils.getWrappedJson(BluePrintConstants.PATH_ARTIFACT_TYPES, it, true)
+ writeTypeFile(definitionDir.absolutePath, BluePrintConstants.PATH_ARTIFACT_TYPES, artifactTypesContent)
}
- blueprintContext.artifactTypes.let {
- val artifactTypesContent = JacksonUtils.getWrappedJson(BluePrintConstants.PATH_ARTIFACT_TYPES, blueprintContext.artifactTypes!!, true)
- writeFile(definitionDir.absolutePath, BluePrintConstants.PATH_ARTIFACT_TYPES, artifactTypesContent)
+ blueprintContext.serviceTemplate.nodeTypes?.let {
+ val nodeTypesContent = JacksonUtils.getWrappedJson(BluePrintConstants.PATH_NODE_TYPES, it, true)
+ writeTypeFile(definitionDir.absolutePath, BluePrintConstants.PATH_NODE_TYPES, nodeTypesContent)
}
- blueprintContext.nodeTypes.let {
- val nodeTypesContent = JacksonUtils.getWrappedJson(BluePrintConstants.PATH_NODE_TYPES, blueprintContext.nodeTypes!!, true)
- writeFile(definitionDir.absolutePath, BluePrintConstants.PATH_NODE_TYPES, nodeTypesContent)
+ blueprintContext.serviceTemplate.policyTypes?.let {
+ val nodeTypesContent = JacksonUtils.getWrappedJson(BluePrintConstants.PATH_POLICY_TYPES, it, true)
+ writeTypeFile(definitionDir.absolutePath, BluePrintConstants.PATH_POLICY_TYPES, nodeTypesContent)
}
+ }
+ fun writeDefinitionFile(definitionFile: String, content: String) = runBlocking {
+ val definitionFile = File(definitionFile)
+
+ Files.write(definitionFile.toPath(), content.toByteArray(), StandardOpenOption.CREATE)
+ check(definitionFile.exists()) {
+ throw BluePrintException("couldn't write definition file under path(${definitionFile.absolutePath})")
+ }
}
- private fun writeFile(definitionPath: String, type: String, content: String) = runBlocking {
+ private fun writeTypeFile(definitionPath: String, type: String, content: String) = runBlocking {
val typeFile = File(definitionPath.plus(File.separator).plus("$type.json"))
Files.write(typeFile.toPath(), content.toByteArray(), StandardOpenOption.CREATE_NEW)