From 88c3ca25f1f06fae414be5c0fd2e3d1d09aab15a Mon Sep 17 00:00:00 2001 From: "Muthuramalingam, Brinda Santh(bs2796)" Date: Tue, 4 Dec 2018 20:53:22 -0500 Subject: Add Netconf Executor Function module Change-Id: If264e63d4fc4305bc26dc6b249a462afefcbfe1e Issue-ID: CCSDK-790 Signed-off-by: Muthuramalingam, Brinda Santh(bs2796) --- .../functions/netconf-executor/pom.xml | 40 +++++++++ .../netconf/executor/ComponentNetconfExecutor.kt | 38 +++++++++ .../netconf/executor/JsonParserService.kt | 24 ++++++ .../executor/NetconfExecutorConfiguration.kt | 26 ++++++ .../netconf/executor/NetconfRpcService.kt | 27 +++++++ .../executor/ComponentNetconfExecutorTest.kt | 79 ++++++++++++++++++ .../src/test/resources/logback-test.xml | 35 ++++++++ ms/blueprintsprocessor/functions/pom.xml | 1 + .../python/executor/ComponentJythonExecutor.kt | 44 +++++++--- .../python/executor/JythonExecutionService.kt | 7 +- .../python/executor/PythonExecutorConfiguration.kt | 6 ++ .../python/executor/ComponentJythonExecutorTest.kt | 2 - .../executor/mock/MockInstanceConfiguration.kt | 32 ++++++++ .../resolution/ResourceResolutionComponent.kt | 35 ++++++++ .../resolution/ResourceResolutionConstants.kt | 24 ++++++ .../resolution/ResourceResolutionService.kt | 89 ++++++++++++++++++++ .../DataBaseResourceAssignmentProcessor.kt | 37 +++++++++ .../DefaultResourceAssignmentProcessor.kt | 37 +++++++++ .../InputResourceAssignmentProcessor.kt | 37 +++++++++ .../SimpleRestResourceAssignmentProcessor.kt | 37 +++++++++ .../resolution/ResourceResolutionComponent.kt | 32 -------- .../resolution/ResourceResolutionConstants.kt | 25 ------ .../resolution/ResourceResolutionService.kt | 89 -------------------- .../DataBaseResourceAssignmentProcessor.kt | 37 --------- .../DefaultResourceAssignmentProcessor.kt | 37 --------- .../processor/InputResourceAssignmentProcessor.kt | 37 --------- .../SimpleRestResourceAssignmentProcessor.kt | 37 --------- .../resolution/ResourceResolutionServiceTest.kt | 94 ++++++++++++++++++++++ .../resolution/ResourceResolutionServiceTest.kt | 94 ---------------------- .../resource/api/ResourceResolutionController.java | 2 +- .../services/workflow/BlueprintServiceLogicTest.kt | 29 +++++++ .../workflow/mock/MockComponentFunction.kt | 33 ++++++++ ms/blueprintsprocessor/parent/pom.xml | 10 +++ 33 files changed, 807 insertions(+), 406 deletions(-) create mode 100644 ms/blueprintsprocessor/functions/netconf-executor/pom.xml create mode 100644 ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/ComponentNetconfExecutor.kt create mode 100644 ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/JsonParserService.kt create mode 100644 ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/NetconfExecutorConfiguration.kt create mode 100644 ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/NetconfRpcService.kt create mode 100644 ms/blueprintsprocessor/functions/netconf-executor/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/ComponentNetconfExecutorTest.kt create mode 100644 ms/blueprintsprocessor/functions/netconf-executor/src/test/resources/logback-test.xml create mode 100644 ms/blueprintsprocessor/functions/python-executor/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/python/executor/mock/MockInstanceConfiguration.kt create mode 100644 ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/ResourceResolutionComponent.kt create mode 100644 ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/ResourceResolutionConstants.kt create mode 100644 ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/ResourceResolutionService.kt create mode 100644 ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolutionprocessor/DataBaseResourceAssignmentProcessor.kt create mode 100644 ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolutionprocessor/DefaultResourceAssignmentProcessor.kt create mode 100644 ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolutionprocessor/InputResourceAssignmentProcessor.kt create mode 100644 ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolutionprocessor/SimpleRestResourceAssignmentProcessor.kt delete mode 100644 ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/resolution/ResourceResolutionComponent.kt delete mode 100644 ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/resolution/ResourceResolutionConstants.kt delete mode 100644 ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/resolution/ResourceResolutionService.kt delete mode 100644 ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/resolution/processor/DataBaseResourceAssignmentProcessor.kt delete mode 100644 ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/resolution/processor/DefaultResourceAssignmentProcessor.kt delete mode 100644 ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/resolution/processor/InputResourceAssignmentProcessor.kt delete mode 100644 ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/resolution/processor/SimpleRestResourceAssignmentProcessor.kt create mode 100644 ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/ResourceResolutionServiceTest.kt delete mode 100644 ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/resolution/ResourceResolutionServiceTest.kt (limited to 'ms/blueprintsprocessor') diff --git a/ms/blueprintsprocessor/functions/netconf-executor/pom.xml b/ms/blueprintsprocessor/functions/netconf-executor/pom.xml new file mode 100644 index 000000000..94103b598 --- /dev/null +++ b/ms/blueprintsprocessor/functions/netconf-executor/pom.xml @@ -0,0 +1,40 @@ + + + + + + org.onap.ccsdk.apps.blueprintsprocessor + functions + 0.4.0-SNAPSHOT + + 4.0.0 + org.onap.ccsdk.apps.blueprintsprocessor.functions + netconf-executor + Blueprints Processor Function - Netconf Executor + Blueprints Processor Function - Netconf Executor + + + + org.onap.ccsdk.apps.blueprintsprocessor.functions + python-executor + + + + + \ No newline at end of file diff --git a/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/ComponentNetconfExecutor.kt b/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/ComponentNetconfExecutor.kt new file mode 100644 index 000000000..e0fd73501 --- /dev/null +++ b/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/ComponentNetconfExecutor.kt @@ -0,0 +1,38 @@ +/* + * 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.blueprintsprocessor.functions.netconf.executor + +import org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.ExecutionServiceInput +import org.onap.ccsdk.apps.blueprintsprocessor.functions.python.executor.ComponentJythonExecutor +import org.onap.ccsdk.apps.blueprintsprocessor.functions.python.executor.PythonExecutorProperty +import org.slf4j.LoggerFactory +import org.springframework.beans.factory.config.ConfigurableBeanFactory +import org.springframework.context.annotation.Scope +import org.springframework.stereotype.Component + +@Component("component-netconf-executor") +@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) +open class ComponentNetconfExecutor(private val netconfExecutorConfiguration: NetconfExecutorConfiguration, + private val pythonExecutorProperty: PythonExecutorProperty) + : ComponentJythonExecutor(pythonExecutorProperty) { + + private val log = LoggerFactory.getLogger(ComponentJythonExecutor::class.java) + + override fun process(executionServiceInput: ExecutionServiceInput) { + super.process(executionServiceInput) + } +} \ No newline at end of file diff --git a/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/JsonParserService.kt b/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/JsonParserService.kt new file mode 100644 index 000000000..111736633 --- /dev/null +++ b/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/JsonParserService.kt @@ -0,0 +1,24 @@ +/* + * 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.blueprintsprocessor.functions.netconf.executor + +import org.springframework.stereotype.Service + +@Service("json-parser-service") +class JsonParserService { + +} \ No newline at end of file diff --git a/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/NetconfExecutorConfiguration.kt b/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/NetconfExecutorConfiguration.kt new file mode 100644 index 000000000..267a49a76 --- /dev/null +++ b/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/NetconfExecutorConfiguration.kt @@ -0,0 +1,26 @@ +/* + * 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.blueprintsprocessor.functions.netconf.executor + +import org.springframework.boot.context.properties.EnableConfigurationProperties +import org.springframework.context.annotation.ComponentScan +import org.springframework.context.annotation.Configuration + +@Configuration +@ComponentScan +@EnableConfigurationProperties +open class NetconfExecutorConfiguration \ No newline at end of file diff --git a/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/NetconfRpcService.kt b/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/NetconfRpcService.kt new file mode 100644 index 000000000..f4818106f --- /dev/null +++ b/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/NetconfRpcService.kt @@ -0,0 +1,27 @@ +/* + * 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.blueprintsprocessor.functions.netconf.executor + +import org.springframework.beans.factory.config.ConfigurableBeanFactory +import org.springframework.context.annotation.Scope +import org.springframework.stereotype.Service + +@Service("netconf-rpc-service") +@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) +class NetconfRpcService { + +} \ No newline at end of file diff --git a/ms/blueprintsprocessor/functions/netconf-executor/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/ComponentNetconfExecutorTest.kt b/ms/blueprintsprocessor/functions/netconf-executor/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/ComponentNetconfExecutorTest.kt new file mode 100644 index 000000000..90a5ea0b7 --- /dev/null +++ b/ms/blueprintsprocessor/functions/netconf-executor/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/ComponentNetconfExecutorTest.kt @@ -0,0 +1,79 @@ +/* + * 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.blueprintsprocessor.functions.netconf.executor + +import com.fasterxml.jackson.databind.JsonNode +import org.junit.Test +import org.junit.runner.RunWith +import org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.ActionIdentifiers +import org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.CommonHeader +import org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.ExecutionServiceInput +import org.onap.ccsdk.apps.blueprintsprocessor.functions.python.executor.PythonExecutorProperty +import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants +import org.onap.ccsdk.apps.controllerblueprints.core.putJsonElement +import org.onap.ccsdk.apps.controllerblueprints.core.utils.BluePrintMetadataUtils +import org.springframework.beans.factory.annotation.Autowired +import org.springframework.test.context.ContextConfiguration +import org.springframework.test.context.TestPropertySource +import org.springframework.test.context.junit4.SpringRunner + +@RunWith(SpringRunner::class) +@ContextConfiguration(classes = [NetconfExecutorConfiguration::class, PythonExecutorProperty::class]) +@TestPropertySource(properties = +["blueprints.processor.functions.python.executor.modulePaths=./../../../../components/scripts/python/ccsdk_blueprints", + "blueprints.processor.functions.python.executor.executionPath=./../../../../components/scripts/python/ccsdk_blueprints"]) +class ComponentNetconfExecutorTest { + + @Autowired + lateinit var componentNetconfExecutor: ComponentNetconfExecutor + + @Test + fun testComponentNetconfExecutor() { + + val executionServiceInput = ExecutionServiceInput() + val commonHeader = CommonHeader() + commonHeader.requestId = "1234" + executionServiceInput.commonHeader = commonHeader + + val actionIdentifiers = ActionIdentifiers() + actionIdentifiers.blueprintName = "baseconfiguration" + actionIdentifiers.blueprintVersion = "1.0.0" + actionIdentifiers.actionName = "activate" + executionServiceInput.actionIdentifiers = actionIdentifiers + + + val bluePrintRuntimeService = BluePrintMetadataUtils.getBluePrintRuntime(commonHeader.requestId, + "./../../../../components/model-catalog/blueprint-model/starter-blueprint/baseconfiguration") + + componentNetconfExecutor.bluePrintRuntimeService = bluePrintRuntimeService + + + val metaData: MutableMap = hashMapOf() + metaData.putJsonElement(BluePrintConstants.PROPERTY_CURRENT_STEP, "activate-jython") + + val stepMetaData: MutableMap = hashMapOf() + stepMetaData.putJsonElement(BluePrintConstants.PROPERTY_CURRENT_NODE_TEMPLATE, "activate-jython") + stepMetaData.putJsonElement(BluePrintConstants.PROPERTY_CURRENT_INTERFACE, "JythonExecutorComponent") + stepMetaData.putJsonElement(BluePrintConstants.PROPERTY_CURRENT_OPERATION, "process") + metaData.putJsonElement("activate-jython-step-inputs", stepMetaData) + executionServiceInput.metadata = metaData + + componentNetconfExecutor.apply(executionServiceInput) + + } +} + diff --git a/ms/blueprintsprocessor/functions/netconf-executor/src/test/resources/logback-test.xml b/ms/blueprintsprocessor/functions/netconf-executor/src/test/resources/logback-test.xml new file mode 100644 index 000000000..f9ec9fe57 --- /dev/null +++ b/ms/blueprintsprocessor/functions/netconf-executor/src/test/resources/logback-test.xml @@ -0,0 +1,35 @@ + + + + + + + %d{HH:mm:ss.SSS} %-5level %logger{100} - %msg%n + + + + + + + + + + + + + diff --git a/ms/blueprintsprocessor/functions/pom.xml b/ms/blueprintsprocessor/functions/pom.xml index efd550ddb..e4f8c8444 100644 --- a/ms/blueprintsprocessor/functions/pom.xml +++ b/ms/blueprintsprocessor/functions/pom.xml @@ -32,6 +32,7 @@ resource-resolution python-executor + netconf-executor diff --git a/ms/blueprintsprocessor/functions/python-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/python/executor/ComponentJythonExecutor.kt b/ms/blueprintsprocessor/functions/python-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/python/executor/ComponentJythonExecutor.kt index 2965cb5d1..166af0f71 100644 --- a/ms/blueprintsprocessor/functions/python-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/python/executor/ComponentJythonExecutor.kt +++ b/ms/blueprintsprocessor/functions/python-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/python/executor/ComponentJythonExecutor.kt @@ -16,37 +16,39 @@ package org.onap.ccsdk.apps.blueprintsprocessor.functions.python.executor +import com.fasterxml.jackson.databind.node.ArrayNode import org.apache.commons.io.FilenameUtils import org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.ExecutionServiceInput import org.onap.ccsdk.apps.blueprintsprocessor.functions.python.executor.utils.PythonExecutorUtils import org.onap.ccsdk.apps.blueprintsprocessor.services.execution.AbstractComponentFunction -import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintProcessorException import org.onap.ccsdk.apps.controllerblueprints.core.checkNotEmptyNThrow 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 import org.springframework.stereotype.Component @Component("component-jython-executor") -class ComponentJythonExecutor(private val pythonExecutorProperty: PythonExecutorProperty) : AbstractComponentFunction() { +@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) +open class ComponentJythonExecutor(private val pythonExecutorProperty: PythonExecutorProperty) : AbstractComponentFunction() { private val log = LoggerFactory.getLogger(ComponentJythonExecutor::class.java) private var componentFunction: AbstractComponentFunction? = null + @Autowired + lateinit var applicationContext: ApplicationContext - override fun process(executionServiceInput: ExecutionServiceInput) { - - log.info("Processing : ${executionServiceInput.metadata}") - checkNotNull(bluePrintRuntimeService) { "failed to get bluePrintRuntimeService" } - + fun populateJythonComponentInstance(executionServiceInput: ExecutionServiceInput) { val bluePrintContext = bluePrintRuntimeService!!.bluePrintContext() val operationAssignment: OperationAssignment = bluePrintContext .nodeTemplateInterfaceOperation(nodeTemplateName, interfaceName, operationName) - val blueprintBasePath: String = bluePrintRuntimeService!!.get(BluePrintConstants.PROPERTY_BLUEPRINT_BASE_PATH)?.asText() - ?: throw BluePrintProcessorException("python execute path is missing for node template ($nodeTemplateName)") + val blueprintBasePath: String = bluePrintContext.rootPath val artifactName: String = operationAssignment.implementation?.primary ?: throw BluePrintProcessorException("missing primary field to get artifact name for node template ($nodeTemplateName)") @@ -66,12 +68,30 @@ class ComponentJythonExecutor(private val pythonExecutorProperty: PythonExecutor pythonPath.add(blueprintBasePath) pythonPath.addAll(pythonExecutorProperty.modulePaths) - val properties: MutableMap = hashMapOf() - properties["log"] = log + val jythonInstances: MutableMap = hashMapOf() + jythonInstances["log"] = LoggerFactory.getLogger(nodeTemplateName) + + val instanceDependenciesNode: ArrayNode = operationInputs[PythonExecutorConstants.INPUT_INSTANCE_DEPENDENCIES] as? ArrayNode + ?: throw BluePrintProcessorException("Failed to get property(${PythonExecutorConstants.INPUT_INSTANCE_DEPENDENCIES})") + + instanceDependenciesNode.forEach { instanceName -> + jythonInstances[instanceName.textValue()] = applicationContext.getBean(instanceName.textValue()) + } componentFunction = PythonExecutorUtils.getPythonComponent(pythonExecutorProperty.executionPath, - pythonPath, content, pythonClassName, properties) + pythonPath, content, pythonClassName, jythonInstances) + } + + + 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) } diff --git a/ms/blueprintsprocessor/functions/python-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/python/executor/JythonExecutionService.kt b/ms/blueprintsprocessor/functions/python-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/python/executor/JythonExecutionService.kt index dc372af4c..6618d13c3 100644 --- a/ms/blueprintsprocessor/functions/python-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/python/executor/JythonExecutionService.kt +++ b/ms/blueprintsprocessor/functions/python-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/python/executor/JythonExecutionService.kt @@ -33,10 +33,11 @@ class JythonExecutionService(private val pythonExecutorProperty: PythonExecutorP lateinit var applicationContext: ApplicationContext - fun processJythonNodeTemplate(pythonClassName: String, content: String, pythonPath: MutableList, - jythonContextInstance: MutableMap, - dependencyInstanceNames: List): AbstractComponentFunction { + fun getJythonComponentFunction(pythonClassName: String, content: String, pythonPath: MutableList, + jythonContextInstance: MutableMap, + dependencyInstanceNames: List): AbstractComponentFunction { + pythonPath.addAll(pythonExecutorProperty.modulePaths) dependencyInstanceNames.forEach { instanceName -> jythonContextInstance[instanceName] = applicationContext.getBean(instanceName) diff --git a/ms/blueprintsprocessor/functions/python-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/python/executor/PythonExecutorConfiguration.kt b/ms/blueprintsprocessor/functions/python-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/python/executor/PythonExecutorConfiguration.kt index dd80fb0ae..be7374c5a 100644 --- a/ms/blueprintsprocessor/functions/python-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/python/executor/PythonExecutorConfiguration.kt +++ b/ms/blueprintsprocessor/functions/python-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/python/executor/PythonExecutorConfiguration.kt @@ -33,4 +33,10 @@ open class PythonExecutorProperty { @Value("#{'\${blueprints.processor.functions.python.executor.modulePaths}'.split(',')}") lateinit var modulePaths: List +} + +class PythonExecutorConstants { + companion object { + const val INPUT_INSTANCE_DEPENDENCIES = "instance-dependencies" + } } \ No newline at end of file diff --git a/ms/blueprintsprocessor/functions/python-executor/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/python/executor/ComponentJythonExecutorTest.kt b/ms/blueprintsprocessor/functions/python-executor/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/python/executor/ComponentJythonExecutorTest.kt index 23da74a88..708797484 100644 --- a/ms/blueprintsprocessor/functions/python-executor/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/python/executor/ComponentJythonExecutorTest.kt +++ b/ms/blueprintsprocessor/functions/python-executor/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/python/executor/ComponentJythonExecutorTest.kt @@ -35,13 +35,11 @@ import org.springframework.test.context.junit4.SpringRunner @TestPropertySource(properties = ["blueprints.processor.functions.python.executor.modulePaths=./../../../../components/scripts/python/ccsdk_blueprints", "blueprints.processor.functions.python.executor.executionPath=./../../../../components/scripts/python/ccsdk_blueprints"]) - class ComponentJythonExecutorTest { @Autowired lateinit var componentJythonExecutor: ComponentJythonExecutor - @Test fun testPythonComponentInjection() { diff --git a/ms/blueprintsprocessor/functions/python-executor/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/python/executor/mock/MockInstanceConfiguration.kt b/ms/blueprintsprocessor/functions/python-executor/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/python/executor/mock/MockInstanceConfiguration.kt new file mode 100644 index 000000000..41250e0ca --- /dev/null +++ b/ms/blueprintsprocessor/functions/python-executor/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/python/executor/mock/MockInstanceConfiguration.kt @@ -0,0 +1,32 @@ +/* + * 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.blueprintsprocessor.functions.python.executor.mock + +import org.springframework.context.annotation.Bean +import org.springframework.context.annotation.Configuration + +@Configuration +open class MockInstanceConfiguration { + @Bean(name = ["json-parser-service", "netconf-rpc-service"]) + open fun createComponentFunction(): MockJythonService { + return MockJythonService() + } +} + +class MockJythonService { + +} \ No newline at end of file diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/ResourceResolutionComponent.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/ResourceResolutionComponent.kt new file mode 100644 index 000000000..32696c579 --- /dev/null +++ b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/ResourceResolutionComponent.kt @@ -0,0 +1,35 @@ +/* + * 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.blueprintsprocessor.functions.resource.resolution + +import org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.ExecutionServiceInput +import org.onap.ccsdk.apps.blueprintsprocessor.services.execution.AbstractComponentFunction +import org.springframework.beans.factory.config.ConfigurableBeanFactory +import org.springframework.context.annotation.Scope +import org.springframework.stereotype.Component + +@Component("component-resource-resolution") +@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) +open class ResourceResolutionComponent : AbstractComponentFunction() { + override fun process(executionRequest: ExecutionServiceInput) { + TODO("not implemented") //To change body of created functions use File | Settings | File Templates. + } + + override fun recover(runtimeException: RuntimeException, executionRequest: ExecutionServiceInput) { + TODO("not implemented") //To change body of created functions use File | Settings | File Templates. + } +} \ No newline at end of file diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/ResourceResolutionConstants.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/ResourceResolutionConstants.kt new file mode 100644 index 000000000..aea3313ca --- /dev/null +++ b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/ResourceResolutionConstants.kt @@ -0,0 +1,24 @@ +/* + * 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.blueprintsprocessor.functions.resource.resolution + +class ResourceResolutionConstants { + companion object { + const val PREFIX_RESOURCE_ASSIGNMENT_PROCESSOR = "resource-assignment-processor-" + } + +} \ No newline at end of file diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/ResourceResolutionService.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/ResourceResolutionService.kt new file mode 100644 index 000000000..2b76b78a1 --- /dev/null +++ b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/ResourceResolutionService.kt @@ -0,0 +1,89 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2018 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.apps.blueprintsprocessor.functions.resource.resolution + +import org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.ResourceResolutionInput +import org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.ResourceResolutionOutput +import org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.Status +import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintProcessorException +import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignment +import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignmentProcessor +import org.onap.ccsdk.apps.controllerblueprints.resource.dict.utils.BulkResourceSequencingUtils +import org.springframework.beans.factory.annotation.Autowired +import org.springframework.context.ApplicationContext +import org.springframework.stereotype.Service + +/** + * ResourceResolutionService + * @author Brinda Santh + * 8/14/2018 + */ + +@Service +class ResourceResolutionService { + + + @Autowired + private lateinit var applicationContext: ApplicationContext + + fun resolveResource(resourceResolutionInput: ResourceResolutionInput): ResourceResolutionOutput { + val resourceResolutionOutput = ResourceResolutionOutput() + resourceResolutionOutput.actionIdentifiers = resourceResolutionInput.actionIdentifiers + resourceResolutionOutput.commonHeader = resourceResolutionInput.commonHeader + resourceResolutionOutput.resourceAssignments = resourceResolutionInput.resourceAssignments + + process(resourceResolutionOutput.resourceAssignments) + + val status = Status() + status.code = 200 + status.message = "Success" + resourceResolutionOutput.status = status + + return resourceResolutionOutput + } + + fun registeredResourceSources(): List { + return applicationContext.getBeanNamesForType(ResourceAssignmentProcessor::class.java) + .filter { it.startsWith(ResourceResolutionConstants.PREFIX_RESOURCE_ASSIGNMENT_PROCESSOR) } + .map { it.substringAfter(ResourceResolutionConstants.PREFIX_RESOURCE_ASSIGNMENT_PROCESSOR) } + } + + fun process(resourceAssignments: MutableList) { + + val bulkSequenced = BulkResourceSequencingUtils.process(resourceAssignments) + + bulkSequenced.map { batchResourceAssignments -> + batchResourceAssignments.filter { it.name != "*" && it.name != "start" } + .map { resourceAssignment -> + val dictionarySource = resourceAssignment.dictionarySource + val processorInstanceName = ResourceResolutionConstants.PREFIX_RESOURCE_ASSIGNMENT_PROCESSOR.plus(dictionarySource) + + val resourceAssignmentProcessor = applicationContext.getBean(processorInstanceName) as? ResourceAssignmentProcessor + ?: throw BluePrintProcessorException("failed to get resource processor for instance name($processorInstanceName) " + + "for resource assignment(${resourceAssignment.name})") + try { + // Invoke Apply Method + resourceAssignmentProcessor.apply(resourceAssignment) + } catch (e: RuntimeException) { + resourceAssignmentProcessor.recover(e, resourceAssignment) + throw BluePrintProcessorException(e) + } + } + } + } +} diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolutionprocessor/DataBaseResourceAssignmentProcessor.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolutionprocessor/DataBaseResourceAssignmentProcessor.kt new file mode 100644 index 000000000..80b2d0b79 --- /dev/null +++ b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolutionprocessor/DataBaseResourceAssignmentProcessor.kt @@ -0,0 +1,37 @@ +/* + * Copyright © 2018 IBM. + * Modifications 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.blueprintsprocessor.functions.resource.resolutionprocessor + +import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignment +import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignmentProcessor +import org.springframework.stereotype.Service + +/** + * DataBaseResourceAssignmentProcessor + * + * @author Brinda Santh + */ +@Service("resource-assignment-processor-db") +open class DataBaseResourceAssignmentProcessor : ResourceAssignmentProcessor(){ + + override fun process(executionRequest: ResourceAssignment) { + } + + override fun recover(runtimeException: RuntimeException, executionRequest: ResourceAssignment) { + } +} \ No newline at end of file diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolutionprocessor/DefaultResourceAssignmentProcessor.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolutionprocessor/DefaultResourceAssignmentProcessor.kt new file mode 100644 index 000000000..055292549 --- /dev/null +++ b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolutionprocessor/DefaultResourceAssignmentProcessor.kt @@ -0,0 +1,37 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2018 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.apps.blueprintsprocessor.functions.resource.resolutionprocessor + +import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignment +import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignmentProcessor +import org.springframework.stereotype.Service + +/** + * DefaultResourceAssignmentProcessor + * + * @author Brinda Santh + */ +@Service("resource-assignment-processor-default") +open class DefaultResourceAssignmentProcessor : ResourceAssignmentProcessor() { + + override fun process(executionRequest: ResourceAssignment) { + } + + override fun recover(runtimeException: RuntimeException, executionRequest: ResourceAssignment) { + } +} \ No newline at end of file diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolutionprocessor/InputResourceAssignmentProcessor.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolutionprocessor/InputResourceAssignmentProcessor.kt new file mode 100644 index 000000000..73fd3a1f8 --- /dev/null +++ b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolutionprocessor/InputResourceAssignmentProcessor.kt @@ -0,0 +1,37 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2018 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.apps.blueprintsprocessor.functions.resource.resolutionprocessor + +import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignment +import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignmentProcessor +import org.springframework.stereotype.Service + +/** + * InputResourceAssignmentProcessor + * + * @author Brinda Santh + */ +@Service("resource-assignment-processor-input") +open class InputResourceAssignmentProcessor : ResourceAssignmentProcessor() { + + override fun process(executionRequest: ResourceAssignment) { + } + + override fun recover(runtimeException: RuntimeException, executionRequest: ResourceAssignment) { + } +} \ No newline at end of file diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolutionprocessor/SimpleRestResourceAssignmentProcessor.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolutionprocessor/SimpleRestResourceAssignmentProcessor.kt new file mode 100644 index 000000000..64c8a1d3b --- /dev/null +++ b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolutionprocessor/SimpleRestResourceAssignmentProcessor.kt @@ -0,0 +1,37 @@ +/* + * Copyright © 2018 IBM. + * Modifications 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.blueprintsprocessor.functions.resource.resolutionprocessor + +import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignment +import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignmentProcessor +import org.springframework.stereotype.Service + +/** + * SimpleRestResourceAssignmentProcessor + * + * @author Brinda Santh + */ +@Service("resource-assignment-processor-mdsal") +open class SimpleRestResourceAssignmentProcessor : ResourceAssignmentProcessor() { + + override fun process(executionRequest: ResourceAssignment) { + } + + override fun recover(runtimeException: RuntimeException, executionRequest: ResourceAssignment) { + } +} \ No newline at end of file diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/resolution/ResourceResolutionComponent.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/resolution/ResourceResolutionComponent.kt deleted file mode 100644 index a485fa628..000000000 --- a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/resolution/ResourceResolutionComponent.kt +++ /dev/null @@ -1,32 +0,0 @@ -/* - * 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.blueprintsprocessor.services.resolution - -import org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.ExecutionServiceInput -import org.onap.ccsdk.apps.blueprintsprocessor.services.execution.AbstractComponentFunction -import org.springframework.stereotype.Component - -@Component("component-resource-resolution") -open class ResourceResolutionComponent : AbstractComponentFunction() { - override fun process(executionRequest: ExecutionServiceInput) { - TODO("not implemented") //To change body of created functions use File | Settings | File Templates. - } - - override fun recover(runtimeException: RuntimeException, executionRequest: ExecutionServiceInput) { - TODO("not implemented") //To change body of created functions use File | Settings | File Templates. - } -} \ No newline at end of file diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/resolution/ResourceResolutionConstants.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/resolution/ResourceResolutionConstants.kt deleted file mode 100644 index e234d0568..000000000 --- a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/resolution/ResourceResolutionConstants.kt +++ /dev/null @@ -1,25 +0,0 @@ -/* - * 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.blueprintsprocessor.services.resolution - -class ResourceResolutionConstants { - companion object { - const val PREFIX_RESOURCE_ASSIGNMENT_PROCESSOR = "resource-assignment-processor-" - - } - -} \ No newline at end of file diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/resolution/ResourceResolutionService.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/resolution/ResourceResolutionService.kt deleted file mode 100644 index 9e735cf0c..000000000 --- a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/resolution/ResourceResolutionService.kt +++ /dev/null @@ -1,89 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2018 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.apps.blueprintsprocessor.services.resolution - -import org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.ResourceResolutionInput -import org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.ResourceResolutionOutput -import org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.Status -import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintProcessorException -import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignment -import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignmentProcessor -import org.onap.ccsdk.apps.controllerblueprints.resource.dict.utils.BulkResourceSequencingUtils -import org.springframework.beans.factory.annotation.Autowired -import org.springframework.context.ApplicationContext -import org.springframework.stereotype.Service - -/** - * ResourceResolutionService - * @author Brinda Santh - * 8/14/2018 - */ - -@Service -class ResourceResolutionService { - - - @Autowired - private lateinit var applicationContext: ApplicationContext - - fun resolveResource(resourceResolutionInput: ResourceResolutionInput): ResourceResolutionOutput { - val resourceResolutionOutput = ResourceResolutionOutput() - resourceResolutionOutput.actionIdentifiers = resourceResolutionInput.actionIdentifiers - resourceResolutionOutput.commonHeader = resourceResolutionInput.commonHeader - resourceResolutionOutput.resourceAssignments = resourceResolutionInput.resourceAssignments - - process(resourceResolutionOutput.resourceAssignments) - - val status = Status() - status.code = 200 - status.message = "Success" - resourceResolutionOutput.status = status - - return resourceResolutionOutput - } - - fun registeredResourceSources(): List { - return applicationContext.getBeanNamesForType(ResourceAssignmentProcessor::class.java) - .filter { it.startsWith(ResourceResolutionConstants.PREFIX_RESOURCE_ASSIGNMENT_PROCESSOR) } - .map { it.substringAfter(ResourceResolutionConstants.PREFIX_RESOURCE_ASSIGNMENT_PROCESSOR) } - } - - fun process(resourceAssignments: MutableList) { - - val bulkSequenced = BulkResourceSequencingUtils.process(resourceAssignments) - - bulkSequenced.map { batchResourceAssignments -> - batchResourceAssignments.filter { it.name != "*" && it.name != "start" } - .map { resourceAssignment -> - val dictionarySource = resourceAssignment.dictionarySource - val processorInstanceName = ResourceResolutionConstants.PREFIX_RESOURCE_ASSIGNMENT_PROCESSOR.plus(dictionarySource) - - val resourceAssignmentProcessor = applicationContext.getBean(processorInstanceName) as? ResourceAssignmentProcessor - ?: throw BluePrintProcessorException("failed to get resource processor for instance name($processorInstanceName) " + - "for resource assignment(${resourceAssignment.name})") - try { - // Invoke Apply Method - resourceAssignmentProcessor.apply(resourceAssignment) - } catch (e: RuntimeException) { - resourceAssignmentProcessor.recover(e, resourceAssignment) - throw BluePrintProcessorException(e) - } - } - } - } -} diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/resolution/processor/DataBaseResourceAssignmentProcessor.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/resolution/processor/DataBaseResourceAssignmentProcessor.kt deleted file mode 100644 index 66e43f1be..000000000 --- a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/resolution/processor/DataBaseResourceAssignmentProcessor.kt +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright © 2018 IBM. - * Modifications 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.blueprintsprocessor.services.resolution.processor - -import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignment -import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignmentProcessor -import org.springframework.stereotype.Service - -/** - * DataBaseResourceAssignmentProcessor - * - * @author Brinda Santh - */ -@Service("resource-assignment-processor-db") -open class DataBaseResourceAssignmentProcessor : ResourceAssignmentProcessor(){ - - override fun process(executionRequest: ResourceAssignment) { - } - - override fun recover(runtimeException: RuntimeException, executionRequest: ResourceAssignment) { - } -} \ No newline at end of file diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/resolution/processor/DefaultResourceAssignmentProcessor.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/resolution/processor/DefaultResourceAssignmentProcessor.kt deleted file mode 100644 index e701e718d..000000000 --- a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/resolution/processor/DefaultResourceAssignmentProcessor.kt +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2018 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.apps.blueprintsprocessor.services.resolution.processor - -import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignment -import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignmentProcessor -import org.springframework.stereotype.Service - -/** - * DefaultResourceAssignmentProcessor - * - * @author Brinda Santh - */ -@Service("resource-assignment-processor-default") -open class DefaultResourceAssignmentProcessor : ResourceAssignmentProcessor() { - - override fun process(executionRequest: ResourceAssignment) { - } - - override fun recover(runtimeException: RuntimeException, executionRequest: ResourceAssignment) { - } -} \ No newline at end of file diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/resolution/processor/InputResourceAssignmentProcessor.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/resolution/processor/InputResourceAssignmentProcessor.kt deleted file mode 100644 index 9e177d46e..000000000 --- a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/resolution/processor/InputResourceAssignmentProcessor.kt +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2018 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.apps.blueprintsprocessor.services.resolution.processor - -import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignment -import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignmentProcessor -import org.springframework.stereotype.Service - -/** - * InputResourceAssignmentProcessor - * - * @author Brinda Santh - */ -@Service("resource-assignment-processor-input") -open class InputResourceAssignmentProcessor : ResourceAssignmentProcessor() { - - override fun process(executionRequest: ResourceAssignment) { - } - - override fun recover(runtimeException: RuntimeException, executionRequest: ResourceAssignment) { - } -} \ No newline at end of file diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/resolution/processor/SimpleRestResourceAssignmentProcessor.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/resolution/processor/SimpleRestResourceAssignmentProcessor.kt deleted file mode 100644 index e1b9a8ef2..000000000 --- a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/resolution/processor/SimpleRestResourceAssignmentProcessor.kt +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright © 2018 IBM. - * Modifications 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.blueprintsprocessor.services.resolution.processor - -import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignment -import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignmentProcessor -import org.springframework.stereotype.Service - -/** - * SimpleRestResourceAssignmentProcessor - * - * @author Brinda Santh - */ -@Service("resource-assignment-processor-mdsal") -open class SimpleRestResourceAssignmentProcessor : ResourceAssignmentProcessor() { - - override fun process(executionRequest: ResourceAssignment) { - } - - override fun recover(runtimeException: RuntimeException, executionRequest: ResourceAssignment) { - } -} \ No newline at end of file diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/ResourceResolutionServiceTest.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/ResourceResolutionServiceTest.kt new file mode 100644 index 000000000..238d1b0ac --- /dev/null +++ b/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/ResourceResolutionServiceTest.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.blueprintsprocessor.functions.resource.resolution + +import com.fasterxml.jackson.databind.node.ObjectNode +import org.apache.commons.collections.CollectionUtils +import org.apache.commons.io.FileUtils +import org.junit.Assert +import org.junit.Test +import org.junit.runner.RunWith +import org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.ResourceResolutionInput +import org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolutionprocessor.DataBaseResourceAssignmentProcessor +import org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolutionprocessor.DefaultResourceAssignmentProcessor +import org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolutionprocessor.InputResourceAssignmentProcessor +import org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolutionprocessor.SimpleRestResourceAssignmentProcessor +import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils +import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignment +import org.slf4j.LoggerFactory +import org.springframework.beans.factory.annotation.Autowired +import org.springframework.test.context.ContextConfiguration +import org.springframework.test.context.junit4.SpringRunner +import java.io.File +import java.nio.charset.Charset +import kotlin.test.assertNotNull +import kotlin.test.assertTrue + +/** + * ResourceResolutionServiceTest + * + * @author Brinda Santh DATE : 8/15/2018 + */ +@RunWith(SpringRunner::class) +@ContextConfiguration(classes = [ResourceResolutionService::class, + InputResourceAssignmentProcessor::class, DefaultResourceAssignmentProcessor::class, + DataBaseResourceAssignmentProcessor::class, SimpleRestResourceAssignmentProcessor::class]) +class ResourceResolutionServiceTest { + + private val log = LoggerFactory.getLogger(ResourceResolutionServiceTest::class.java) + + @Autowired + lateinit var resourceResolutionService: ResourceResolutionService + + + @Test + fun testRegisteredSource() { + val sources = resourceResolutionService.registeredResourceSources() + assertNotNull(sources, "failed to get registered sources") + assertTrue(sources.containsAll(arrayListOf("input", "default", "db", "mdsal")), "failed to get registered sources") + } + + @Test + @Throws(Exception::class) + fun testResolveResource() { + + Assert.assertNotNull("failed to create ResourceResolutionService", resourceResolutionService) + + val resourceResolutionInputContent = FileUtils.readFileToString( + File("src/test/resources/payload/requests/sample-resourceresolution-request.json"), Charset.defaultCharset()) + + val resourceResolutionInput = JacksonUtils.readValue(resourceResolutionInputContent, ResourceResolutionInput::class.java) + Assert.assertNotNull("failed to populate resourceResolutionInput request ", resourceResolutionInput) + + val resourceAssignmentContent = FileUtils.readFileToString( + File("src/test/resources/mapping/db/resource-assignments-simple.json"), Charset.defaultCharset()) + val batchResourceAssignment = JacksonUtils.getListFromJson(resourceAssignmentContent, ResourceAssignment::class.java) + + Assert.assertTrue("failed to create ResourceAssignment from file", CollectionUtils.isNotEmpty(batchResourceAssignment)) + resourceResolutionInput!!.resourceAssignments = batchResourceAssignment as MutableList + + val inputContent = JacksonUtils.jsonNodeFromFile("src/test/resources/payload/inputs/input.json") as ObjectNode + Assert.assertNotNull("failed to populate input payload ", inputContent) + resourceResolutionInput.payload = inputContent + log.info("ResourceResolutionInput : {}", JacksonUtils.getJson(resourceResolutionInput, true)) + + val resourceResolutionOutput = resourceResolutionService.resolveResource(resourceResolutionInput) + Assert.assertNotNull("failed to populate output", resourceResolutionOutput) + + } + +} diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/resolution/ResourceResolutionServiceTest.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/resolution/ResourceResolutionServiceTest.kt deleted file mode 100644 index 62adde73b..000000000 --- a/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/resolution/ResourceResolutionServiceTest.kt +++ /dev/null @@ -1,94 +0,0 @@ -/* - * 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.blueprintsprocessor.services.resolution - -import com.fasterxml.jackson.databind.node.ObjectNode -import org.apache.commons.collections.CollectionUtils -import org.apache.commons.io.FileUtils -import org.junit.Assert -import org.junit.Test -import org.junit.runner.RunWith -import org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.ResourceResolutionInput -import org.onap.ccsdk.apps.blueprintsprocessor.services.resolution.processor.DataBaseResourceAssignmentProcessor -import org.onap.ccsdk.apps.blueprintsprocessor.services.resolution.processor.DefaultResourceAssignmentProcessor -import org.onap.ccsdk.apps.blueprintsprocessor.services.resolution.processor.InputResourceAssignmentProcessor -import org.onap.ccsdk.apps.blueprintsprocessor.services.resolution.processor.SimpleRestResourceAssignmentProcessor -import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils -import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignment -import org.slf4j.LoggerFactory -import org.springframework.beans.factory.annotation.Autowired -import org.springframework.test.context.ContextConfiguration -import org.springframework.test.context.junit4.SpringRunner -import java.io.File -import java.nio.charset.Charset -import kotlin.test.assertNotNull -import kotlin.test.assertTrue - -/** - * ResourceResolutionServiceTest - * - * @author Brinda Santh DATE : 8/15/2018 - */ -@RunWith(SpringRunner::class) -@ContextConfiguration(classes = [ResourceResolutionService::class, - InputResourceAssignmentProcessor::class, DefaultResourceAssignmentProcessor::class, - DataBaseResourceAssignmentProcessor::class, SimpleRestResourceAssignmentProcessor::class]) -class ResourceResolutionServiceTest { - - private val log = LoggerFactory.getLogger(ResourceResolutionServiceTest::class.java) - - @Autowired - lateinit var resourceResolutionService: ResourceResolutionService - - - @Test - fun testRegisteredSource() { - val sources = resourceResolutionService.registeredResourceSources() - assertNotNull(sources, "failed to get registered sources") - assertTrue(sources.containsAll(arrayListOf("input", "default", "db", "mdsal")), "failed to get registered sources") - } - - @Test - @Throws(Exception::class) - fun testResolveResource() { - - Assert.assertNotNull("failed to create ResourceResolutionService", resourceResolutionService) - - val resourceResolutionInputContent = FileUtils.readFileToString( - File("src/test/resources/payload/requests/sample-resourceresolution-request.json"), Charset.defaultCharset()) - - val resourceResolutionInput = JacksonUtils.readValue(resourceResolutionInputContent, ResourceResolutionInput::class.java) - Assert.assertNotNull("failed to populate resourceResolutionInput request ", resourceResolutionInput) - - val resourceAssignmentContent = FileUtils.readFileToString( - File("src/test/resources/mapping/db/resource-assignments-simple.json"), Charset.defaultCharset()) - val batchResourceAssignment = JacksonUtils.getListFromJson(resourceAssignmentContent, ResourceAssignment::class.java) - - Assert.assertTrue("failed to create ResourceAssignment from file", CollectionUtils.isNotEmpty(batchResourceAssignment)) - resourceResolutionInput!!.resourceAssignments = batchResourceAssignment as MutableList - - val inputContent = JacksonUtils.jsonNodeFromFile("src/test/resources/payload/inputs/input.json") as ObjectNode - Assert.assertNotNull("failed to populate input payload ", inputContent) - resourceResolutionInput.payload = inputContent - log.info("ResourceResolutionInput : {}", JacksonUtils.getJson(resourceResolutionInput, true)) - - val resourceResolutionOutput = resourceResolutionService.resolveResource(resourceResolutionInput) - Assert.assertNotNull("failed to populate output", resourceResolutionOutput) - - } - -} diff --git a/ms/blueprintsprocessor/modules/inbounds/resource-api/src/main/java/org/onap/ccsdk/apps/blueprintsprocessor/resource/api/ResourceResolutionController.java b/ms/blueprintsprocessor/modules/inbounds/resource-api/src/main/java/org/onap/ccsdk/apps/blueprintsprocessor/resource/api/ResourceResolutionController.java index 8aeb41531..0f3b4a821 100644 --- a/ms/blueprintsprocessor/modules/inbounds/resource-api/src/main/java/org/onap/ccsdk/apps/blueprintsprocessor/resource/api/ResourceResolutionController.java +++ b/ms/blueprintsprocessor/modules/inbounds/resource-api/src/main/java/org/onap/ccsdk/apps/blueprintsprocessor/resource/api/ResourceResolutionController.java @@ -19,7 +19,7 @@ package org.onap.ccsdk.apps.blueprintsprocessor.resource.api; import io.swagger.annotations.ApiOperation; import org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.ResourceResolutionInput; import org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.ResourceResolutionOutput; -import org.onap.ccsdk.apps.blueprintsprocessor.services.resolution.ResourceResolutionService; +import org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.ResourceResolutionService; import org.springframework.http.MediaType; import org.springframework.web.bind.annotation.*; import reactor.core.publisher.Mono; diff --git a/ms/blueprintsprocessor/modules/services/workflow-service/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/workflow/BlueprintServiceLogicTest.kt b/ms/blueprintsprocessor/modules/services/workflow-service/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/workflow/BlueprintServiceLogicTest.kt index 2c1c40c9c..7312d2def 100644 --- a/ms/blueprintsprocessor/modules/services/workflow-service/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/workflow/BlueprintServiceLogicTest.kt +++ b/ms/blueprintsprocessor/modules/services/workflow-service/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/workflow/BlueprintServiceLogicTest.kt @@ -20,12 +20,16 @@ import org.junit.Test import org.junit.runner.RunWith import org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.ExecutionServiceInput import org.onap.ccsdk.apps.blueprintsprocessor.services.workflow.executor.ComponentExecuteNodeExecutor +import org.onap.ccsdk.apps.blueprintsprocessor.services.workflow.mock.PrototypeComponentFunction +import org.onap.ccsdk.apps.blueprintsprocessor.services.workflow.mock.SingletonComponentFunction import org.onap.ccsdk.apps.controllerblueprints.core.utils.BluePrintMetadataUtils import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils import org.slf4j.LoggerFactory import org.springframework.beans.factory.annotation.Autowired +import org.springframework.context.ApplicationContext import org.springframework.test.context.ContextConfiguration import org.springframework.test.context.junit4.SpringRunner +import kotlin.test.assertEquals @RunWith(SpringRunner::class) @ContextConfiguration(classes = [WorkflowServiceConfiguration::class, ComponentExecuteNodeExecutor::class]) @@ -33,6 +37,9 @@ class BlueprintServiceLogicTest { private val log = LoggerFactory.getLogger(BlueprintServiceLogicTest::class.java) + @Autowired + lateinit var applicationContext: ApplicationContext + @Autowired lateinit var blueprintDGExecutionService: BlueprintDGExecutionService @@ -61,4 +68,26 @@ class BlueprintServiceLogicTest { } + @Test + fun testSingleton() { + val singleton1 = applicationContext.getBean(SingletonComponentFunction::class.java) + singleton1.stepName = "step1" + val singleton2 = applicationContext.getBean(SingletonComponentFunction::class.java) + assertEquals(singleton1.stepName, singleton2.stepName, " failed to get singleton data") + } + + @Test + fun testProtoTypeFunction() { + val stepName1 = "step1" + val stepName2 = "step2" + val proto1 = applicationContext.getBean(PrototypeComponentFunction::class.java) + proto1.stepName = stepName1 + + val proto2 = applicationContext.getBean(PrototypeComponentFunction::class.java) + proto2.stepName = stepName2 + + assertEquals(stepName1, proto1.stepName, " Failed to match the step1 name") + assertEquals(stepName2, proto2.stepName, " Failed to match the step2 name") + } + } \ No newline at end of file diff --git a/ms/blueprintsprocessor/modules/services/workflow-service/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/workflow/mock/MockComponentFunction.kt b/ms/blueprintsprocessor/modules/services/workflow-service/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/workflow/mock/MockComponentFunction.kt index 9f7a9c974..1d738eef9 100644 --- a/ms/blueprintsprocessor/modules/services/workflow-service/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/workflow/mock/MockComponentFunction.kt +++ b/ms/blueprintsprocessor/modules/services/workflow-service/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/workflow/mock/MockComponentFunction.kt @@ -20,8 +20,11 @@ import org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.ExecutionServiceInp import org.onap.ccsdk.apps.blueprintsprocessor.services.execution.AbstractComponentFunction import org.onap.ccsdk.apps.controllerblueprints.core.asJsonPrimitive import org.slf4j.LoggerFactory +import org.springframework.beans.factory.config.ConfigurableBeanFactory import org.springframework.context.annotation.Bean import org.springframework.context.annotation.Configuration +import org.springframework.context.annotation.Scope +import org.springframework.stereotype.Component @Configuration open class MockComponentConfiguration { @@ -43,6 +46,36 @@ class MockComponentFunction : AbstractComponentFunction() { "assignment-params", "params".asJsonPrimitive()) } + override fun recover(runtimeException: RuntimeException, executionRequest: ExecutionServiceInput) { + log.info("Recovering component..") + } +} + +@Component("singleton-function") +@Scope(value = ConfigurableBeanFactory.SCOPE_SINGLETON) +class SingletonComponentFunction : AbstractComponentFunction() { + + private val log = LoggerFactory.getLogger(MockComponentFunction::class.java) + + override fun process(executionRequest: ExecutionServiceInput) { + log.info("Processing component : ${operationInputs}") + } + + override fun recover(runtimeException: RuntimeException, executionRequest: ExecutionServiceInput) { + log.info("Recovering component..") + } +} + +@Component("prototype-function") +@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) +class PrototypeComponentFunction : AbstractComponentFunction() { + + private val log = LoggerFactory.getLogger(MockComponentFunction::class.java) + + override fun process(executionRequest: ExecutionServiceInput) { + log.info("Processing component : ${operationInputs}") + } + override fun recover(runtimeException: RuntimeException, executionRequest: ExecutionServiceInput) { log.info("Recovering component..") } diff --git a/ms/blueprintsprocessor/parent/pom.xml b/ms/blueprintsprocessor/parent/pom.xml index 3ad3fef3e..796aef160 100644 --- a/ms/blueprintsprocessor/parent/pom.xml +++ b/ms/blueprintsprocessor/parent/pom.xml @@ -206,6 +206,16 @@ resource-resolution ${project.version} + + org.onap.ccsdk.apps.blueprintsprocessor.functions + python-executor + ${project.version} + + + org.onap.ccsdk.apps.blueprintsprocessor.functions + netconf-executor + ${project.version} + -- cgit 1.2.3-korg