}
},
"resource-assignment": {
- "type": "component-resource-assignment",
+ "type": "component-resource-resolution",
"interfaces": {
- "ResourceAssignmentComponent": {
+ "ResourceResolutionComponent": {
"operations": {
"process": {
"inputs": {
}
},
"resource-assignment-py": {
- "type": "component-resource-assignment",
+ "type": "component-resource-resolution",
"interfaces": {
- "ResourceAssignmentComponent": {
+ "ResourceResolutionComponent": {
"operations": {
"process": {
"implementation": {
"activate-jython": {
"type": "component-jython-executor",
"interfaces": {
- "JythonExecutorComponent": {
+ "ComponentJythonExecutor": {
"operations": {
"process": {
"implementation": {
},
"derived_from": "tosca.nodes.component.Jython"
},
- "component-resource-assignment": {
+ "component-resource-resolution": {
"description": "This is Resource Assignment Component API",
"version": "1.0.0",
"attributes": {
}
},
"interfaces": {
- "ResourceAssignmentComponent": {
+ "ResourceResolutionComponent": {
"operations": {
"process": {
"inputs": {
}
},
"interfaces": {
- "JythonExecutorComponent": {
+ "ComponentJythonExecutor": {
"operations": {
"process": {
"inputs": {
}
},
"interfaces": {
- "JythonExecutorComponent": {
+ "ComponentJythonExecutor": {
"operations": {
"process": {
"inputs": {
-{\r
- "description": "This is Resource Assignment Component API",\r
- "version": "1.0.0",\r
- "attributes": {\r
- "assignment-params": {\r
- "required": true,\r
- "type": "string"\r
- }\r
- },\r
- "capabilities": {\r
- "component-node": {\r
- "type": "tosca.capabilities.Node"\r
- }\r
- },\r
- "interfaces": {\r
- "ResourceAssignmentComponent": {\r
- "operations": {\r
- "process": {\r
- "inputs": {\r
- "template-name": {\r
- "description": "Service Template Name.",\r
- "required": true,\r
- "type": "string"\r
- },\r
- "template-version": {\r
- "description": "Service Template Version.",\r
- "required": true,\r
- "type": "string"\r
- },\r
- "resource-type": {\r
- "description": "Request type.",\r
- "required": true,\r
- "type": "string"\r
- },\r
- "template-names": {\r
- "description": "Name of the artifact Node Templates, to get the template Content.",\r
- "required": true,\r
- "type": "list",\r
- "entry_schema": {\r
- "type": "string"\r
- }\r
- },\r
- "artifact-prefix-names": {\r
- "required": false,\r
- "description": "Template , Resource Assignment Artifact Prefix names",\r
- "type": "list",\r
- "entry_schema": {\r
- "type": "string"\r
- }\r
- },\r
- "request-id": {\r
- "description": "Request Id, Unique Id for the request.",\r
- "required": true,\r
- "type": "string"\r
- },\r
- "resource-id": {\r
- "description": "Resource Id.",\r
- "required": true,\r
- "type": "string"\r
- },\r
- "action-name": {\r
- "description": "Action Name of the process",\r
- "required": true,\r
- "type": "string"\r
- }\r
- },\r
- "outputs": {\r
- "resource-assignment-params": {\r
- "required": true,\r
- "type": "string"\r
- },\r
- "status": {\r
- "required": true,\r
- "type": "string"\r
- }\r
- }\r
- }\r
- }\r
- }\r
- },\r
- "derived_from": "tosca.nodes.Component"\r
+{
+ "description": "This is Resource Assignment Component API",
+ "version": "1.0.0",
+ "attributes": {
+ "assignment-params": {
+ "required": true,
+ "type": "string"
+ }
+ },
+ "capabilities": {
+ "component-node": {
+ "type": "tosca.capabilities.Node"
+ }
+ },
+ "interfaces": {
+ "ResourceResolutionComponent": {
+ "operations": {
+ "process": {
+ "inputs": {
+ "template-name": {
+ "description": "Service Template Name.",
+ "required": true,
+ "type": "string"
+ },
+ "template-version": {
+ "description": "Service Template Version.",
+ "required": true,
+ "type": "string"
+ },
+ "resource-type": {
+ "description": "Request type.",
+ "required": true,
+ "type": "string"
+ },
+ "template-names": {
+ "description": "Name of the artifact Node Templates, to get the template Content.",
+ "required": true,
+ "type": "list",
+ "entry_schema": {
+ "type": "string"
+ }
+ },
+ "artifact-prefix-names": {
+ "required": false,
+ "description": "Template , Resource Assignment Artifact Prefix names",
+ "type": "list",
+ "entry_schema": {
+ "type": "string"
+ }
+ },
+ "request-id": {
+ "description": "Request Id, Unique Id for the request.",
+ "required": false,
+ "type": "string"
+ },
+ "resource-id": {
+ "description": "Resource Id.",
+ "required": false,
+ "type": "string"
+ },
+ "action-name": {
+ "description": "Action Name of the process",
+ "required": false,
+ "type": "string"
+ }
+ },
+ "outputs": {
+ "resource-assignment-params": {
+ "required": true,
+ "type": "string"
+ },
+ "status": {
+ "required": true,
+ "type": "string"
+ }
+ }
+ }
+ }
+ }
+ },
+ "derived_from": "tosca.nodes.Component"
}
\ No newline at end of file
<groupId>org.onap.ccsdk.apps.blueprintsprocessor</groupId>
<artifactId>resource-api</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.onap.ccsdk.apps.blueprintsprocessor.functions</groupId>
+ <artifactId>python-executor</artifactId>
+ </dependency>
<dependency>
<groupId>org.onap.ccsdk.apps.blueprintsprocessor</groupId>
<artifactId>selfservice-api</artifactId>
blueprintsprocessor.db.primary.username=sdnctl
blueprintsprocessor.db.primary.password=sdnctl
blueprintsprocessor.db.primary.driverClassName=org.mariadb.jdbc.Driver
-blueprintsprocessor.db.primary.hibernateHbm2ddlAuto=none
-blueprintsprocessor.db.primary.hibernateDDLAuto=none
+blueprintsprocessor.db.primary.hibernateHbm2ddlAuto=update
+blueprintsprocessor.db.primary.hibernateDDLAuto=update
blueprintsprocessor.db.primary.hibernateNamingStrategy=org.hibernate.cfg.ImprovedNamingStrategy
blueprintsprocessor.db.primary.hibernateDialect=org.hibernate.dialect.MySQL5InnoDBDialect
-
# Python executor
blueprints.processor.functions.python.executor.executionPath=/opt/app/onap/scripts/jython
blueprints.processor.functions.python.executor.modulePaths=/opt/app/onap/scripts/jython
\ No newline at end of file
blueprintsprocessor.db.primary.hibernateDDLAuto=update
blueprintsprocessor.db.primary.hibernateNamingStrategy=org.hibernate.cfg.ImprovedNamingStrategy
blueprintsprocessor.db.primary.hibernateDialect=org.hibernate.dialect.H2Dialect
-
# Python executor
blueprints.processor.functions.python.executor.executionPath=/opt/app/onap/scripts/jython
-blueprints.processor.functions.python.executor.modulePaths=/opt/app/onap/scripts/jython
\ No newline at end of file
+blueprints.processor.functions.python.executor.modulePaths=/opt/app/onap/scripts/jython
pythonPath.add(blueprintBasePath)
pythonPath.addAll(pythonExecutorProperty.modulePaths)
- var blueprintPythonConfigurations = BluePrintPython(pythonExecutorProperty.executionPath, pythonPath, arrayListOf())
+ val blueprintPythonConfigurations = BluePrintPython(pythonExecutorProperty.executionPath, pythonPath, arrayListOf())
val blueprintPythonHost = BlueprintPythonHost(blueprintPythonConfigurations)
- var pyObject = blueprintPythonHost.getPythonComponent(content, pythonClassName, dependencyInstanceNames)
+ val pyObject = blueprintPythonHost.getPythonComponent(content, pythonClassName, dependencyInstanceNames)
log.info("Component Object {}", pyObject)
import org.onap.ccsdk.apps.controllerblueprints.core.checkNotEmptyOrThrow
import org.onap.ccsdk.apps.controllerblueprints.core.data.OperationAssignment
import org.slf4j.LoggerFactory
+import org.springframework.beans.factory.annotation.Autowired
import org.springframework.beans.factory.config.ConfigurableBeanFactory
import org.springframework.context.ApplicationContext
import org.springframework.context.annotation.Scope
private var componentFunction: AbstractComponentFunction? = null
- fun populateJythonComponentInstance(executionServiceInput: ExecutionServiceInput) {
+ override fun prepareRequest(executionRequest: ExecutionServiceInput): ExecutionServiceInput {
+ val request = super.prepareRequest(executionRequest)
+ // Populate Component Instance
+ populateJythonComponentInstance()
+ return request
+ }
+
+ override fun process(executionRequest: ExecutionServiceInput) {
+ log.info("Processing : $operationInputs")
+ // Invoke Jython Component Script
+ componentFunction!!.process(executionServiceInput)
+
+ }
+
+ override fun recover(runtimeException: RuntimeException, executionRequest: ExecutionServiceInput) {
+ componentFunction!!.recover(runtimeException, executionRequest)
+ }
+
+ private fun populateJythonComponentInstance() {
val bluePrintContext = bluePrintRuntimeService.bluePrintContext()
val operationAssignment: OperationAssignment = bluePrintContext
val instanceDependenciesNode: ArrayNode = operationInputs[PythonExecutorConstants.INPUT_INSTANCE_DEPENDENCIES] as? ArrayNode
?: throw BluePrintProcessorException("Failed to get property(${PythonExecutorConstants.INPUT_INSTANCE_DEPENDENCIES})")
- val jythonContextInstance: MutableMap<String, Any> = hashMapOf()
- jythonContextInstance["log"] = LoggerFactory.getLogger(pythonClassName)
- jythonContextInstance["bluePrintRuntimeService"] = bluePrintRuntimeService
- instanceDependenciesNode?.forEach { instanceName ->
- val instance = instanceName.textValue()
- val value = applicationContext.getBean(instance)
- ?: throw BluePrintProcessorException("couldn't get the dependency instance($instance)")
- jythonContextInstance[instance] = value
+ val jythonInstance: MutableMap<String, Any> = hashMapOf()
+ jythonInstance["log"] = LoggerFactory.getLogger(pythonClassName)
+ jythonInstance["bluePrintRuntimeService"] = bluePrintRuntimeService
+
+ instanceDependenciesNode.forEach { instanceName ->
+ jythonInstance[instanceName.textValue()] = applicationContext.getBean(instanceName.textValue())
}
+ // Setup componentFunction
componentFunction = blueprintPythonService.jythonInstance(bluePrintContext, pythonClassName,
- content!!, jythonContextInstance)
- }
-
-
- override fun process(executionServiceInput: ExecutionServiceInput) {
-
- log.info("Processing : $operationInputs")
- checkNotNull(bluePrintRuntimeService) { "failed to get bluePrintRuntimeService" }
-
- // Populate Component Instance
- populateJythonComponentInstance(executionServiceInput)
-
- // Invoke Jython Component Script
- componentFunction!!.process(executionServiceInput)
-
+ content!!, jythonInstance)
+ componentFunction?.bluePrintRuntimeService = bluePrintRuntimeService
+ componentFunction?.executionServiceInput = executionServiceInput
+ componentFunction?.stepName = stepName
+ componentFunction?.interfaceName = interfaceName
+ componentFunction?.operationName = operationName
+ componentFunction?.processId = processId
+ componentFunction?.workflowName = workflowName
}
-
- override fun recover(runtimeException: RuntimeException, executionRequest: ExecutionServiceInput) {
- componentFunction!!.recover(runtimeException, executionRequest)
- }
-
}
\ No newline at end of file
fun getPythonComponent(content: String?, interfaceName: String, properties: MutableMap<String, Any>?): PyObject {
bluePrintPython.content = content!!
bluePrintPython.pythonClassName = interfaceName
- bluePrintPython.moduleName = "Blueprint Python Scripting [Class Name = $interfaceName]"
+ bluePrintPython.moduleName = "Blueprint Python Script [Class Name = $interfaceName]"
return blueprintPythonInterpreterProxy.getPythonInstance(properties)
}
this.exec("import sys")
- bluePrintPython.content?.let {
+ bluePrintPython.content.let {
this.exec(bluePrintPython.content)
}
@Test
fun testPythonComponentInjection() {
-
val executionServiceInput = JacksonUtils.readValueFromClassPathFile("payload/requests/sample-activate-request.json",
ExecutionServiceInput::class.java)!!
val stepMetaData: MutableMap<String, JsonNode> = hashMapOf()
stepMetaData.putJsonElement(BluePrintConstants.PROPERTY_CURRENT_NODE_TEMPLATE, "activate-jython")
- stepMetaData.putJsonElement(BluePrintConstants.PROPERTY_CURRENT_INTERFACE, "JythonExecutorComponent")
+ stepMetaData.putJsonElement(BluePrintConstants.PROPERTY_CURRENT_INTERFACE, "ComponentJythonExecutor")
stepMetaData.putJsonElement(BluePrintConstants.PROPERTY_CURRENT_OPERATION, "process")
bluePrintRuntimeService.put("activate-jython-step-inputs", stepMetaData.asJsonNode())
\r
package org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution\r
\r
+import com.fasterxml.jackson.databind.node.JsonNodeFactory
import org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.processor.ResourceAssignmentProcessor\r
import org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.utils.ResourceAssignmentUtils\r
import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants\r
import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintProcessorException\r
import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintRuntimeService\r
+import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintTemplateService
import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils\r
import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignment\r
import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceDefinition\r
val resourceDictionaries: MutableMap<String, ResourceDefinition> = JacksonUtils.getMapFromFile(dictionaryFile, ResourceDefinition::class.java)\r
?: throw BluePrintProcessorException("couldn't get Dictionary Definitions")\r
\r
+ // Resolve resources
executeProcessors(bluePrintRuntimeService, resourceDictionaries, resourceAssignments, templateArtifactName)\r
\r
// Check Template is there\r
- val templateContent = bluePrintRuntimeService.resolveNodeTemplateArtifact(nodeTemplateName, mappingArtifactName)\r
+ val templateContent = bluePrintRuntimeService.resolveNodeTemplateArtifact(nodeTemplateName, templateArtifactName)
\r
- // TODO ("Generate Param JSON from Resource Assignment")\r
- val resolvedParamJsonContent = "{}"\r
+ val resolvedParamJsonContent = ResourceAssignmentUtils.generateResourceDataForAssignments(resourceAssignments.toList())
\r
if (templateContent.isNotEmpty()) {\r
- // TODO ( "Mash Data and Content")\r
- resolvedContent = "Mashed Content"\r
-\r
+ resolvedContent = BluePrintTemplateService.generateContent(templateContent, resolvedParamJsonContent)
} else {\r
resolvedContent = resolvedParamJsonContent\r
}\r
return resolvedContent\r
}\r
\r
-\r
private fun executeProcessors(blueprintRuntimeService: BluePrintRuntimeService<*>,\r
resourceDictionaries: MutableMap<String, ResourceDefinition>,\r
resourceAssignments: MutableList<ResourceAssignment>,\r
BluePrintConstants.DATA_TYPE_INTEGER -> (root as ObjectNode).put(rName, value as Int)
BluePrintConstants.DATA_TYPE_FLOAT -> (root as ObjectNode).put(rName, value as Float)
else -> {
- if (JacksonUtils.getJsonNode(value) != null) {
- (root as ObjectNode).set(rName, JacksonUtils.getJsonNode(value))
- } else {
- (root as ObjectNode).set(rName, null)
- }
+ (root as ObjectNode).set(rName, JacksonUtils.getJsonNode(value))
}
}
}
val stepMetaData: MutableMap<String, JsonNode> = hashMapOf()
stepMetaData.putJsonElement(BluePrintConstants.PROPERTY_CURRENT_NODE_TEMPLATE, "resource-assignment")
- stepMetaData.putJsonElement(BluePrintConstants.PROPERTY_CURRENT_INTERFACE, "ResourceAssignmentComponent")
+ stepMetaData.putJsonElement(BluePrintConstants.PROPERTY_CURRENT_INTERFACE, "ResourceResolutionComponent")
stepMetaData.putJsonElement(BluePrintConstants.PROPERTY_CURRENT_OPERATION, "process")
bluePrintRuntimeService.put("resource-assignment-step-inputs", stepMetaData.asJsonNode())
val artifactName = metadata[BluePrintConstants.METADATA_TEMPLATE_NAME]
val artifactVersion = metadata[BluePrintConstants.METADATA_TEMPLATE_VERSION]
- log.isDebugEnabled.apply {
- blueprintModelRepository.findByArtifactNameAndArtifactVersion(artifactName!!, artifactVersion!!)?.let {
- log.debug("Overwriting blueprint model :$artifactName::$artifactVersion")
- }
+ blueprintModelRepository.findByArtifactNameAndArtifactVersion(artifactName!!, artifactVersion!!)?.let {
+ log.info("Overwriting blueprint model :$artifactName::$artifactVersion")
+ blueprintModelRepository.deleteByArtifactNameAndArtifactVersion(artifactName, artifactVersion)
}
val blueprintModel = BlueprintProcessorModel()
@Configuration
open class MockComponentConfiguration {
- @Bean(name = ["component-resource-assignment", "component-netconf-executor", "component-jython-executor"])
+ @Bean(name = ["component-resource-resolution", "component-netconf-executor", "component-jython-executor"])
open fun createComponentFunction(): AbstractComponentFunction {
return MockComponentFunction()
}
fun <T> getMapFromJson(content: String, valueType: Class<T>): MutableMap<String, T>? {
val objectMapper = jacksonObjectMapper()
- val typeRef = object : TypeReference<MutableMap<String, T>>() {}
- return objectMapper.readValue(content, typeRef)
+ val mapType = objectMapper.typeFactory.constructMapType(Map::class.java, String::class.java, valueType)
+ return objectMapper.readValue(content, mapType)
}
fun <T> getMapFromFile(fileName: String, valueType: Class<T>): MutableMap<String, T>? {
@Test
fun testChainedProperty() {
val bluePrintContext = BluePrintMetadataUtils.getBluePrintContext(blueprintBasePath)
- val nodeType = bluePrintContext.nodeTypeChained("component-resource-assignment")
+ val nodeType = bluePrintContext.nodeTypeChained("component-resource-resolution")
assertNotNull(nodeType, "Failed to get chained node type")
log.trace("Properties {}", JacksonUtils.getJson(nodeType, true))
}
val inContext: MutableMap<String, JsonNode> = bluePrintRuntimeService
.resolveNodeTemplateInterfaceOperationInputs("resource-assignment",
- "ResourceAssignmentComponent", "process")
+ "ResourceResolutionComponent", "process")
assertNotNull(inContext, "Failed to populate interface input property values")
assertEquals(inContext["action-name"], JacksonUtils.jsonNodeFromObject("sample-action"), "Failed to populate parameter action-name")
bluePrintRuntimeService.setNodeTemplateAttributeValue("resource-assignment", "assignment-params", NullNode.getInstance())
bluePrintRuntimeService.resolveNodeTemplateInterfaceOperationOutputs("resource-assignment",
- "ResourceAssignmentComponent", "process")
+ "ResourceResolutionComponent", "process")
val outputStatus = bluePrintRuntimeService.getNodeTemplateOperationOutputValue("resource-assignment",
- "ResourceAssignmentComponent", "process", "status")
+ "ResourceResolutionComponent", "process", "status")
assertEquals("success".asJsonPrimitive(), outputStatus, "Failed to get operation property status")
val outputParams = bluePrintRuntimeService.getNodeTemplateOperationOutputValue("resource-assignment",
- "ResourceAssignmentComponent", "process", "resource-assignment-params")
+ "ResourceResolutionComponent", "process", "resource-assignment-params")
assertEquals(NullNode.getInstance(), outputParams, "Failed to get operation property resource-assignment-params")
}
const val PROPERTY_OUTPUT_KEY_MAPPING = "output-key-mapping"
const val PROPERTY_KEY_DEPENDENCIES = "key-dependencies"
- const val PATH_RESOURCE_DEFINITION_TYPE = "resource_definition_types"
+ const val PATH_RESOURCE_DEFINITION_TYPE = "resources_definition_types"
}
\ No newline at end of file
val artifactName = metadata[BluePrintConstants.METADATA_TEMPLATE_NAME]
val artifactVersion = metadata[BluePrintConstants.METADATA_TEMPLATE_VERSION]
- log.isDebugEnabled.apply {
- blueprintModelRepository.findByArtifactNameAndArtifactVersion(artifactName!!, artifactVersion!!)?.let {
- log.debug("Overwriting blueprint model :$artifactName::$artifactVersion")
- }
+
+ blueprintModelRepository.findByArtifactNameAndArtifactVersion(artifactName!!, artifactVersion!!)?.let {
+ log.info("Overwriting blueprint model :$artifactName::$artifactVersion")
+ blueprintModelRepository.deleteByArtifactNameAndArtifactVersion(artifactName, artifactVersion)
}
val blueprintModel = BlueprintModel()