diff options
Diffstat (limited to 'ms/blueprintsprocessor')
21 files changed, 656 insertions, 193 deletions
diff --git a/ms/blueprintsprocessor/functions/cli-executor/src/main/kotlin/internal/scripts/InternalSimpleCli.kt b/ms/blueprintsprocessor/functions/cli-executor/src/main/kotlin/internal/scripts/InternalSimpleCli.kt index 4c1d92ae6..cf27cc2de 100644 --- a/ms/blueprintsprocessor/functions/cli-executor/src/main/kotlin/internal/scripts/InternalSimpleCli.kt +++ b/ms/blueprintsprocessor/functions/cli-executor/src/main/kotlin/internal/scripts/InternalSimpleCli.kt @@ -71,7 +71,7 @@ open class Check : AbstractScriptComponentFunction() { sshClientService.closeSessionNB() // Set the Response Data - setAttribute(ComponentScriptExecutor.RESPONSE_DATA, responseLog.asJsonPrimitive()) + setAttribute(ComponentScriptExecutor.ATTRIBUTE_RESPONSE_DATA, responseLog.asJsonPrimitive()) log.info("Executing process") } diff --git a/ms/blueprintsprocessor/functions/cli-executor/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/cli/executor/ComponentCliExecutorTest.kt b/ms/blueprintsprocessor/functions/cli-executor/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/cli/executor/ComponentCliExecutorTest.kt index 30e7c8906..9c0258db0 100644 --- a/ms/blueprintsprocessor/functions/cli-executor/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/cli/executor/ComponentCliExecutorTest.kt +++ b/ms/blueprintsprocessor/functions/cli-executor/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/cli/executor/ComponentCliExecutorTest.kt @@ -34,11 +34,11 @@ import org.onap.ccsdk.cds.blueprintsprocessor.services.execution.ExecutionServic import org.onap.ccsdk.cds.blueprintsprocessor.ssh.BluePrintSshLibConfiguration import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants import org.onap.ccsdk.cds.controllerblueprints.core.asJsonPrimitive +import org.onap.ccsdk.cds.controllerblueprints.core.scripts.BluePrintScriptsServiceImpl import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintContext import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintDependencyService import org.onap.ccsdk.cds.controllerblueprints.core.service.DefaultBluePrintRuntimeService import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils -import org.onap.ccsdk.cds.controllerblueprints.core.scripts.BluePrintScriptsServiceImpl import org.springframework.beans.factory.annotation.Autowired import org.springframework.test.annotation.DirtiesContext import org.springframework.test.context.ContextConfiguration @@ -79,8 +79,8 @@ class ComponentCliExecutorTest { operationInputs[BluePrintConstants.PROPERTY_CURRENT_NODE_TEMPLATE] = "activate-cli".asJsonPrimitive() operationInputs[BluePrintConstants.PROPERTY_CURRENT_INTERFACE] = "interfaceName".asJsonPrimitive() operationInputs[BluePrintConstants.PROPERTY_CURRENT_OPERATION] = "operationName".asJsonPrimitive() - operationInputs[ComponentScriptExecutor.SCRIPT_TYPE] = BluePrintConstants.SCRIPT_INTERNAL.asJsonPrimitive() - operationInputs[ComponentScriptExecutor.SCRIPT_CLASS_REFERENCE] = + operationInputs[ComponentScriptExecutor.INPUT_SCRIPT_TYPE] = BluePrintConstants.SCRIPT_INTERNAL.asJsonPrimitive() + operationInputs[ComponentScriptExecutor.INPUT_SCRIPT_CLASS_REFERENCE] = "internal.scripts.TestCliScriptFunction".asJsonPrimitive() val stepInputData = StepData().apply { diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceResolutionComponent.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceResolutionComponent.kt index df7e0482c..875b9ae32 100644 --- a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceResolutionComponent.kt +++ b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceResolutionComponent.kt @@ -33,6 +33,23 @@ import org.springframework.stereotype.Component @Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) open class ResourceResolutionComponent(private val resourceResolutionService: ResourceResolutionService) : AbstractComponentFunction() { + companion object{ + const val INPUT_REQUEST_ID = "request-id" + const val INPUT_RESOURCE_ID = "resource-id" + const val INPUT_ACTION_NAME = "action-name" + const val INPUT_DYNAMIC_PROPERTIES = "dynamic-properties" + const val INPUT_RESOURCE_TYPE = "resource-type" + const val INPUT_ARTIFACT_PREFIX_NAMES = "artifact-prefix-names" + const val INPUT_RESOLUTION_KEY = "resolution-key" + const val INPUT_STORE_RESULT = "store-result" + const val INPUT_OCCURRENCE = "occurrence" + + const val ATTRIBUTE_ASSIGNMENT_PARAM = "assignment-params" + const val ATTRIBUTE_STATUS = "status" + + const val OUTPUT_RESOURCE_ASSIGNMENT_PARAMS = "resource-assignment-params" + const val OUTPUT_STATUS = "status" + } override suspend fun processNB(executionRequest: ExecutionServiceInput) { diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceResolutionComponentDSL.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceResolutionComponentDSL.kt new file mode 100644 index 000000000..c71541efd --- /dev/null +++ b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceResolutionComponentDSL.kt @@ -0,0 +1,189 @@ +/* + * Copyright © 2019 IBM. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution + +import com.fasterxml.jackson.databind.JsonNode +import org.onap.ccsdk.cds.controllerblueprints.core.* +import org.onap.ccsdk.cds.controllerblueprints.core.data.NodeTemplate +import org.onap.ccsdk.cds.controllerblueprints.core.data.NodeType +import org.onap.ccsdk.cds.controllerblueprints.core.dsl.AbstractNodeTemplateImplBuilder +import org.onap.ccsdk.cds.controllerblueprints.core.dsl.PropertiesAssignmentBuilder +import org.onap.ccsdk.cds.controllerblueprints.core.dsl.nodeType + +/** Component Extensions **/ +fun BluePrintTypes.nodeTypeComponentResourceResolution(): NodeType { + return nodeType(id = "component-resource-resolution", version = BluePrintConstants.DEFAULT_VERSION_NUMBER, + derivedFrom = BluePrintConstants.MODEL_TYPE_NODE_COMPONENT, + description = "Resource Assignment Component") { + + attribute(ResourceResolutionComponent.ATTRIBUTE_ASSIGNMENT_PARAM, BluePrintConstants.DATA_TYPE_STRING, + true) + attribute(ResourceResolutionComponent.ATTRIBUTE_STATUS, BluePrintConstants.DATA_TYPE_STRING, + true) + + operation("ResourceResolutionComponent", "ResourceResolutionComponent Operation") { + inputs { + property(ResourceResolutionComponent.INPUT_REQUEST_ID, BluePrintConstants.DATA_TYPE_STRING, + true, "Request Id, Unique Id for the request.") + + property(ResourceResolutionComponent.INPUT_RESOURCE_ID, BluePrintConstants.DATA_TYPE_STRING, + false, "Resource Id.") + + property(ResourceResolutionComponent.INPUT_ACTION_NAME, BluePrintConstants.DATA_TYPE_STRING, + false, "Action Name of the process") + + property(ResourceResolutionComponent.INPUT_DYNAMIC_PROPERTIES, BluePrintConstants.DATA_TYPE_JSON, + false, "Dynamic Json Content or DSL Json reference.") + + property(ResourceResolutionComponent.INPUT_RESOLUTION_KEY, BluePrintConstants.DATA_TYPE_STRING, + false, "Key for service instance related correlation.") + + property(ResourceResolutionComponent.INPUT_OCCURRENCE, BluePrintConstants.DATA_TYPE_INTEGER, + false, "Number of time to perform the resolution.") { + defaultValue(1) + } + + property(ResourceResolutionComponent.INPUT_STORE_RESULT, BluePrintConstants.DATA_TYPE_BOOLEAN, + false, "Whether or not to store the output.") + + property(ResourceResolutionComponent.INPUT_RESOURCE_TYPE, BluePrintConstants.DATA_TYPE_STRING, + false, "Request type.") + + property(ResourceResolutionComponent.INPUT_ARTIFACT_PREFIX_NAMES, BluePrintConstants.DATA_TYPE_LIST, + true, "Template , Resource Assignment Artifact Prefix names") { + entrySchema(BluePrintConstants.DATA_TYPE_STRING) + } + } + outputs { + property(ResourceResolutionComponent.OUTPUT_RESOURCE_ASSIGNMENT_PARAMS, BluePrintConstants.DATA_TYPE_STRING, + true, "Output Response") + property(ResourceResolutionComponent.OUTPUT_STATUS, BluePrintConstants.DATA_TYPE_STRING, + true, "Status of the Component Execution ( success or failure )") + } + } + } +} + +/** Component Builder */ +fun BluePrintTypes.nodeTemplateComponentResourceResolution(id: String, + description: String, + block: ComponentResourceResolutionNodeTemplateImplBuilder.() -> Unit) + : NodeTemplate { + return ComponentResourceResolutionNodeTemplateImplBuilder(id, description).apply(block).build() +} + +class ComponentResourceResolutionNodeTemplateImplBuilder(id: String, description: String) : + AbstractNodeTemplateImplBuilder<ComponentResourceResolutionInputAssignmentBuilder, + ComponentResourceResolutionOutputAssignmentBuilder>(id, "component-script-executor", + "ComponentResourceResolution", + description) + +class ComponentResourceResolutionInputAssignmentBuilder : PropertiesAssignmentBuilder() { + + fun requestId(requestId: String) { + requestId(requestId.asJsonPrimitive()) + } + + fun requestId(requestId: JsonNode) { + property(ResourceResolutionComponent.INPUT_REQUEST_ID, requestId) + } + + fun resourceId(resourceId: String) { + resourceId(resourceId.asJsonPrimitive()) + } + + fun resourceId(resourceId: JsonNode) { + property(ResourceResolutionComponent.INPUT_RESOURCE_ID, resourceId) + } + + fun actionName(actionName: String) { + actionName(actionName.asJsonPrimitive()) + } + + fun actionName(actionName: JsonNode) { + property(ResourceResolutionComponent.INPUT_ACTION_NAME, actionName) + } + + fun resolutionKey(resolutionKey: String) { + resolutionKey(resolutionKey.asJsonPrimitive()) + } + + fun resolutionKey(resolutionKey: JsonNode) { + property(ResourceResolutionComponent.INPUT_RESOLUTION_KEY, resolutionKey) + } + + fun dynamicProperty(dynamicProperty: String) { + dynamicProperty(dynamicProperty.asJsonType()) + } + + fun dynamicProperty(dynamicProperty: JsonNode) { + property(ResourceResolutionComponent.INPUT_DYNAMIC_PROPERTIES, dynamicProperty) + } + + fun occurrence(occurrence: Int) { + occurrence(occurrence.asJsonPrimitive()) + } + + fun occurrence(resolutionKey: JsonNode) { + property(ResourceResolutionComponent.INPUT_OCCURRENCE, resolutionKey) + } + + fun storeResult(storeResult: Boolean) { + storeResult(storeResult.asJsonPrimitive()) + } + + fun storeResult(storeResult: JsonNode) { + property(ResourceResolutionComponent.INPUT_STORE_RESULT, storeResult) + } + + fun resourceType(resourceType: String) { + resourceType(resourceType.asJsonPrimitive()) + } + + fun resourceType(resourceType: JsonNode) { + property(ResourceResolutionComponent.INPUT_RESOURCE_TYPE, resourceType) + } + + fun artifactPrefixNames(artifactPrefixNames: String) = artifactPrefixNames(artifactPrefixNames.jsonAsJsonType()) + + fun artifactPrefixNames(artifactPrefixNameList: List<String>) { + artifactPrefixNames(artifactPrefixNameList.asJsonString()) + } + + fun artifactPrefixNames(artifactPrefixNames: JsonNode) { + property(ResourceResolutionComponent.INPUT_ARTIFACT_PREFIX_NAMES, artifactPrefixNames) + } +} + +class ComponentResourceResolutionOutputAssignmentBuilder : PropertiesAssignmentBuilder() { + + fun status(status: String) { + status(status.asJsonPrimitive()) + } + + fun status(status: JsonNode) { + property(ResourceResolutionComponent.OUTPUT_STATUS, status) + } + + fun resourceAssignmentParams(resourceAssignmentParams: String) { + resourceAssignmentParams(resourceAssignmentParams.asJsonType()) + } + + fun resourceAssignmentParams(resourceAssignmentParams: JsonNode) { + property(ResourceResolutionComponent.OUTPUT_RESOURCE_ASSIGNMENT_PARAMS, resourceAssignmentParams) + } +}
\ No newline at end of file diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceResolutionComponentDSLTest.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceResolutionComponentDSLTest.kt new file mode 100644 index 000000000..16052ae74 --- /dev/null +++ b/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceResolutionComponentDSLTest.kt @@ -0,0 +1,60 @@ +/* + * Copyright © 2019 IBM. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution + +import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintTypes +import org.onap.ccsdk.cds.controllerblueprints.core.dsl.getAttribute +import kotlin.test.Test +import kotlin.test.assertNotNull + +class ResourceResolutionComponentDSLTest { + + @Test + fun testNodeTypeComponentResourceResolution() { + val nodeType = BluePrintTypes.nodeTypeComponentResourceResolution() + //println(nodeType.asJsonString(true)) + assertNotNull(nodeType, "failed to generate nodeTypeComponentResourceResolution") + } + + @Test + fun testNodeTemplateComponentResourceResolution() { + val nodeTemplate = BluePrintTypes.nodeTemplateComponentResourceResolution("resource-resolve", "") { + operation("Resolve resources") { + inputs { + actionName("resolve") + requestId("1234") + resolutionKey("vnf-1234") + occurrence(2) + resourceType("vnf") + storeResult(false) + artifactPrefixNames(arrayListOf("template1", "template2")) + dynamicProperty("""{ + "prop1" : "1234", + "prop2" : true, + "prop3" : 23 + }""".trimIndent()) + } + outputs { + resourceAssignmentParams(getAttribute("assignment-params")) + status("success") + } + } + } + //println(nodeTemplate.asJsonString(true)) + assertNotNull(nodeTemplate, "failed to generate nodeTemplateComponentResourceResolution") + } +}
\ No newline at end of file diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/mock/MockDatabaseConfiguration.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/mock/MockDatabaseConfiguration.kt index 22e043b11..7644df37a 100644 --- a/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/mock/MockDatabaseConfiguration.kt +++ b/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/mock/MockDatabaseConfiguration.kt @@ -15,9 +15,11 @@ */ package org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.mock +import io.mockk.every import io.mockk.mockk import org.onap.ccsdk.cds.blueprintsprocessor.db.BluePrintDBLibGenericService import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BluePrintValidatorService +import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintRuntimeService import org.springframework.context.annotation.Bean import org.springframework.context.annotation.Configuration @@ -33,9 +35,12 @@ open class MockDatabaseConfiguration { @Configuration open class MockBlueprintProcessorCatalogServiceImpl { - @Bean(name = ["blueprintProcessorCatalogServiceImpl"]) - open fun createBlueprintProcessorCatalogServiceImpl(): BluePrintValidatorService { - return mockk<BluePrintValidatorService>() + @Bean(name = ["bluePrintRuntimeValidatorService"]) + open fun bluePrintRuntimeValidatorService(): BluePrintValidatorService { + val bluePrintValidatorService = mockk<BluePrintValidatorService>() + every { bluePrintValidatorService.validateBluePrints(any<String>()) } returns true + every { bluePrintValidatorService.validateBluePrints(any<BluePrintRuntimeService<*>>()) } returns true + return bluePrintValidatorService } diff --git a/ms/blueprintsprocessor/functions/restconf-executor/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/restconf/executor/ComponentRestconfExecutorTest.kt b/ms/blueprintsprocessor/functions/restconf-executor/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/restconf/executor/ComponentRestconfExecutorTest.kt index fb47b6ad1..2b2b83e4c 100644 --- a/ms/blueprintsprocessor/functions/restconf-executor/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/restconf/executor/ComponentRestconfExecutorTest.kt +++ b/ms/blueprintsprocessor/functions/restconf-executor/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/restconf/executor/ComponentRestconfExecutorTest.kt @@ -79,8 +79,8 @@ class ComponentRestconfExecutorTest { operationInputs[BluePrintConstants.PROPERTY_CURRENT_NODE_TEMPLATE] = "activate-restconf".asJsonPrimitive() operationInputs[BluePrintConstants.PROPERTY_CURRENT_INTERFACE] = "interfaceName".asJsonPrimitive() operationInputs[BluePrintConstants.PROPERTY_CURRENT_OPERATION] = "operationName".asJsonPrimitive() - operationInputs[ComponentScriptExecutor.SCRIPT_TYPE] = BluePrintConstants.SCRIPT_INTERNAL.asJsonPrimitive() - operationInputs[ComponentScriptExecutor.SCRIPT_CLASS_REFERENCE] = + operationInputs[ComponentScriptExecutor.INPUT_SCRIPT_TYPE] = BluePrintConstants.SCRIPT_INTERNAL.asJsonPrimitive() + operationInputs[ComponentScriptExecutor.INPUT_SCRIPT_CLASS_REFERENCE] = "internal.scripts.TestRestconfConfigure".asJsonPrimitive() val stepInputData = StepData().apply { diff --git a/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/BlueprintProcessorCatalogServiceImpl.kt b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/BlueprintProcessorCatalogServiceImpl.kt index 9faf879f0..9d5d630de 100755 --- a/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/BlueprintProcessorCatalogServiceImpl.kt +++ b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/BlueprintProcessorCatalogServiceImpl.kt @@ -39,7 +39,7 @@ import java.util.* /** * Similar/Duplicate implementation in [org.onap.ccsdk.cds.controllerblueprints.service.load.ControllerBlueprintCatalogServiceImpl] */ -@Service +@Service("blueprintsProcessorCatalogService") class BlueprintProcessorCatalogServiceImpl(bluePrintRuntimeValidatorService: BluePrintValidatorService, private val bluePrintPathConfiguration: BluePrintPathConfiguration, private val blueprintModelRepository: BlueprintProcessorModelRepository) diff --git a/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/PrimaryDatabaseConfiguration.kt b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/PrimaryDatabaseConfiguration.kt index 4ea407ada..a62867053 100644 --- a/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/PrimaryDatabaseConfiguration.kt +++ b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/primary/PrimaryDatabaseConfiguration.kt @@ -21,6 +21,7 @@ import org.slf4j.LoggerFactory import org.springframework.context.annotation.Bean import org.springframework.context.annotation.Configuration import org.springframework.context.annotation.Primary +import org.springframework.data.jpa.repository.config.EnableJpaAuditing import org.springframework.data.jpa.repository.config.EnableJpaRepositories import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate import org.springframework.jdbc.datasource.DriverManagerDataSource @@ -33,10 +34,12 @@ import javax.sql.DataSource @Configuration @EnableJpaRepositories( - basePackages = ["org.onap.ccsdk.cds.blueprintsprocessor.*"], - entityManagerFactoryRef = "primaryEntityManager", - transactionManagerRef = "primaryTransactionManager" + basePackages = ["org.onap.ccsdk.cds.blueprintsprocessor.*", + "org.onap.ccsdk.cds.controllerblueprints.*"], + entityManagerFactoryRef = "primaryEntityManager", + transactionManagerRef = "primaryTransactionManager" ) +@EnableJpaAuditing open class PrimaryDatabaseConfiguration(private val primaryDataSourceProperties: PrimaryDataSourceProperties) { val log = LoggerFactory.getLogger(PrimaryDatabaseConfiguration::class.java)!! @@ -45,7 +48,8 @@ open class PrimaryDatabaseConfiguration(private val primaryDataSourceProperties: open fun primaryEntityManager(): LocalContainerEntityManagerFactoryBean { val em = LocalContainerEntityManagerFactoryBean() em.dataSource = primaryDataSource() - em.setPackagesToScan("org.onap.ccsdk.cds.blueprintsprocessor.*") + em.setPackagesToScan("org.onap.ccsdk.cds.blueprintsprocessor.*", + "org.onap.ccsdk.cds.controllerblueprints.*") em.jpaVendorAdapter = HibernateJpaVendorAdapter() val properties = HashMap<String, Any>() properties["hibernate.hbm2ddl.auto"] = primaryDataSourceProperties.hibernateHbm2ddlAuto diff --git a/ms/blueprintsprocessor/modules/commons/db-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/BlueprintProcessorCatalogServiceImplTest.kt b/ms/blueprintsprocessor/modules/commons/db-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/BlueprintProcessorCatalogServiceImplTest.kt index e40efd0c4..fe8172b85 100644 --- a/ms/blueprintsprocessor/modules/commons/db-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/BlueprintProcessorCatalogServiceImplTest.kt +++ b/ms/blueprintsprocessor/modules/commons/db-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/BlueprintProcessorCatalogServiceImplTest.kt @@ -20,14 +20,14 @@ package org.onap.ccsdk.cds.blueprintsprocessor.db import kotlinx.coroutines.runBlocking import org.junit.Test import org.junit.runner.RunWith -import org.onap.ccsdk.cds.controllerblueprints.core.deleteDir -import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BluePrintCatalogService -import org.onap.ccsdk.cds.controllerblueprints.core.normalizedFile import org.onap.ccsdk.cds.blueprintsprocessor.core.BluePrintCoreConfiguration import org.onap.ccsdk.cds.blueprintsprocessor.db.mock.MockBlueprintProcessorCatalogServiceImpl import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants +import org.onap.ccsdk.cds.controllerblueprints.core.deleteDir +import org.onap.ccsdk.cds.controllerblueprints.core.normalizedFile import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintRuntimeService import org.onap.ccsdk.cds.controllerblueprints.core.utils.BluePrintMetadataUtils +import org.onap.ccsdk.cds.controllerblueprints.db.resources.BlueprintCatalogServiceImpl import org.springframework.beans.factory.annotation.Autowired import org.springframework.boot.autoconfigure.EnableAutoConfiguration import org.springframework.context.annotation.ComponentScan @@ -41,17 +41,14 @@ import kotlin.test.assertTrue @RunWith(SpringRunner::class) @EnableAutoConfiguration -@ComponentScan(basePackages = ["org.onap.ccsdk.cds.blueprintsprocessor", "org.onap.ccsdk.cds.controllerblueprints"]) +@ComponentScan(basePackages = ["org.onap.ccsdk.cds.blueprintsprocessor"]) @ContextConfiguration(classes = [BlueprintProcessorCatalogServiceImpl::class, BluePrintCoreConfiguration::class, MockBlueprintProcessorCatalogServiceImpl::class]) @TestPropertySource(locations = ["classpath:application-test.properties"]) class BlueprintProcessorCatalogServiceImplTest { @Autowired - lateinit var blueprintCatalog: BluePrintCatalogService - - @Autowired - lateinit var blueprintProcessorCatalogServiceImpl: BlueprintProcessorCatalogServiceImpl + lateinit var blueprintsProcessorCatalogService: BlueprintCatalogServiceImpl @Autowired lateinit var blueprintCoreConfiguration: BluePrintCoreConfiguration @@ -64,7 +61,7 @@ class BlueprintProcessorCatalogServiceImplTest { fun setup() { deleteDir("target", "blueprints") bluePrintRuntimeService = BluePrintMetadataUtils.getBluePrintRuntime(blueprintId, - "./../../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration") + "./../../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration") } @AfterTest @@ -81,10 +78,10 @@ class BlueprintProcessorCatalogServiceImplTest { val file = normalizedFile("./src/test/resources/test-cba.zip") assertTrue(file.exists(), "couldn't get file ${file.absolutePath}") - blueprintCatalog.saveToDatabase("1234", file) - blueprintCatalog.getFromDatabase("baseconfiguration", "1.0.0") + blueprintsProcessorCatalogService.saveToDatabase("1234", file) + blueprintsProcessorCatalogService.getFromDatabase("baseconfiguration", "1.0.0") - blueprintCatalog.deleteFromDatabase("baseconfiguration", "1.0.0") + blueprintsProcessorCatalogService.deleteFromDatabase("baseconfiguration", "1.0.0") } } @@ -96,7 +93,7 @@ class BlueprintProcessorCatalogServiceImplTest { val metadata = bluePrintRuntimeService.bluePrintContext().metadata!! metadata[BluePrintConstants.PROPERTY_BLUEPRINT_PROCESS_ID] = blueprintId - blueprintProcessorCatalogServiceImpl.save(metadata, file) + blueprintsProcessorCatalogService.save(metadata, file) } } @@ -108,8 +105,8 @@ class BlueprintProcessorCatalogServiceImplTest { val metadata = bluePrintRuntimeService.bluePrintContext().metadata!! metadata[BluePrintConstants.PROPERTY_BLUEPRINT_PROCESS_ID] = blueprintId - blueprintProcessorCatalogServiceImpl.save(metadata, file) - blueprintProcessorCatalogServiceImpl.get("baseconfiguration", "1.0.0", true) + blueprintsProcessorCatalogService.save(metadata, file) + blueprintsProcessorCatalogService.get("baseconfiguration", "1.0.0", true) } assertTrue(File(blueprintCoreConfiguration.bluePrintPathConfiguration().blueprintArchivePath + @@ -121,7 +118,7 @@ class BlueprintProcessorCatalogServiceImplTest { @Test fun `test delete function`() { runBlocking { - blueprintProcessorCatalogServiceImpl.delete("baseconfiguration", "1.0.0") + blueprintsProcessorCatalogService.delete("baseconfiguration", "1.0.0") } } }
\ No newline at end of file diff --git a/ms/blueprintsprocessor/modules/commons/db-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/mock/MockBlueprintProcessorCatalogServiceImpl.kt b/ms/blueprintsprocessor/modules/commons/db-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/mock/MockBlueprintProcessorCatalogServiceImpl.kt index 08de33270..b98fc0c44 100644 --- a/ms/blueprintsprocessor/modules/commons/db-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/mock/MockBlueprintProcessorCatalogServiceImpl.kt +++ b/ms/blueprintsprocessor/modules/commons/db-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/mock/MockBlueprintProcessorCatalogServiceImpl.kt @@ -15,15 +15,21 @@ */ package org.onap.ccsdk.cds.blueprintsprocessor.db.mock +import io.mockk.every import io.mockk.mockk import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BluePrintValidatorService +import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintRuntimeService import org.springframework.context.annotation.Bean import org.springframework.context.annotation.Configuration + @Configuration open class MockBlueprintProcessorCatalogServiceImpl { - @Bean(name = ["blueprintProcessorCatalogServiceImpl"]) - open fun createBlueprintProcessorCatalogServiceImpl(): BluePrintValidatorService { - return mockk<BluePrintValidatorService>() + @Bean(name = ["bluePrintRuntimeValidatorService"]) + open fun bluePrintRuntimeValidatorService(): BluePrintValidatorService { + val bluePrintValidatorService = mockk<BluePrintValidatorService>() + every { bluePrintValidatorService.validateBluePrints(any<String>()) } returns true + every { bluePrintValidatorService.validateBluePrints(any<BluePrintRuntimeService<*>>()) } returns true + return bluePrintValidatorService } }
\ No newline at end of file diff --git a/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/BluePrintRestLibConfiguration.kt b/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/BluePrintRestLibConfiguration.kt index 25d1de881..b68627fec 100644 --- a/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/BluePrintRestLibConfiguration.kt +++ b/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/BluePrintRestLibConfiguration.kt @@ -51,6 +51,7 @@ fun BluePrintDependencyService.restClientService(jsonNode: JsonNode): BlueprintW class RestLibConstants { companion object { const val SERVICE_BLUEPRINT_REST_LIB_PROPERTY = "blueprint-rest-lib-property-service" + const val PROPERTY_TYPE = "type" const val TYPE_TOKEN_AUTH = "token-auth" const val TYPE_BASIC_AUTH = "basic-auth" const val TYPE_SSL_BASIC_AUTH = "ssl-basic-auth" diff --git a/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/BluePrintRestLibData.kt b/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/BluePrintRestLibData.kt index 70ec9501a..75a9409fd 100644 --- a/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/BluePrintRestLibData.kt +++ b/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/BluePrintRestLibData.kt @@ -30,10 +30,12 @@ open class SSLRestClientProperties : RestClientProperties() { var sslKeyPassword: String? = null } +// FIXME("Define basic auth userName and password properties") open class SSLBasicAuthRestClientProperties : SSLRestClientProperties() { var basicAuth: BasicAuthRestClientProperties? = null } +// FIXME("Define token properties") open class SSLTokenAuthRestClientProperties : SSLRestClientProperties() { var tokenAuth: TokenAuthRestClientProperties? = null } diff --git a/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/RestClientPropertiesDSL.kt b/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/RestClientPropertiesDSL.kt new file mode 100644 index 000000000..a3da44f61 --- /dev/null +++ b/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/RestClientPropertiesDSL.kt @@ -0,0 +1,137 @@ +/* + * Copyright © 2019 IBM. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.ccsdk.cds.blueprintsprocessor.rest + +import com.fasterxml.jackson.databind.JsonNode +import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintTypes +import org.onap.ccsdk.cds.controllerblueprints.core.asJsonPrimitive +import org.onap.ccsdk.cds.controllerblueprints.core.asJsonType +import org.onap.ccsdk.cds.controllerblueprints.core.dsl.PropertiesAssignmentBuilder + +fun BluePrintTypes.dslBasicAuthRestClientProperties(block: BasicAuthRestClientPropertiesBuilder.() -> Unit): JsonNode { + val assignments = BasicAuthRestClientPropertiesBuilder().apply(block).build() + assignments[RestLibConstants.PROPERTY_TYPE] = RestLibConstants.TYPE_BASIC_AUTH.asJsonPrimitive() + return assignments.asJsonType() +} + +fun BluePrintTypes.dslTokenAuthRestClientProperties(block: TokenAuthRestClientPropertiesBuilder.() -> Unit): JsonNode { + val assignments = TokenAuthRestClientPropertiesBuilder().apply(block).build() + assignments[RestLibConstants.PROPERTY_TYPE] = RestLibConstants.TYPE_TOKEN_AUTH.asJsonPrimitive() + return assignments.asJsonType() +} + +fun BluePrintTypes.dslSSLRestClientProperties(block: SSLRestClientPropertiesBuilder.() -> Unit): JsonNode { + val assignments = SSLRestClientPropertiesBuilder().apply(block).build() + assignments[RestLibConstants.PROPERTY_TYPE] = RestLibConstants.TYPE_SSL_NO_AUTH.asJsonPrimitive() + return assignments.asJsonType() +} + +open class RestClientPropertiesBuilder : PropertiesAssignmentBuilder() { + fun type(type: String) { + type(type.asJsonPrimitive()) + } + + fun type(type: JsonNode) { + property(RestLibConstants.PROPERTY_TYPE, type) + } + + open fun url(url: String) { + url(url.asJsonPrimitive()) + } + + open fun url(url: JsonNode) { + property("url", url) + } +} + +open class BasicAuthRestClientPropertiesBuilder : RestClientPropertiesBuilder() { + open fun password(password: String) { + password(password.asJsonPrimitive()) + } + + open fun password(password: JsonNode) { + property("password", password) + } + + open fun username(username: String) { + username(username.asJsonPrimitive()) + } + + open fun username(username: JsonNode) { + property("username", username) + } +} + +open class TokenAuthRestClientPropertiesBuilder : RestClientPropertiesBuilder() { + open fun token(token: String) { + token(token.asJsonPrimitive()) + } + + open fun token(token: JsonNode) { + property("token", token) + } +} + +open class SSLRestClientPropertiesBuilder : RestClientPropertiesBuilder() { + open fun keyStoreInstance(keyStoreInstance: String) { + keyStoreInstance(keyStoreInstance.asJsonPrimitive()) + } + + open fun keyStoreInstance(keyStoreInstance: JsonNode) { + property("keyStoreInstance", keyStoreInstance) + } + + open fun sslTrust(sslTrust: String) { + sslTrust(sslTrust.asJsonPrimitive()) + } + + open fun sslTrust(sslTrust: JsonNode) { + property("sslTrust", sslTrust) + } + + open fun sslTrustPassword(sslTrustPassword: String) { + sslTrustPassword(sslTrustPassword.asJsonPrimitive()) + } + + open fun sslTrustPassword(sslTrustPassword: JsonNode) { + property("sslTrustPassword", sslTrustPassword) + } + + open fun sslKey(sslKey: String) { + sslKey(sslKey.asJsonPrimitive()) + } + + open fun sslKey(sslKey: JsonNode) { + property("sslKey", sslKey) + } + + open fun sslKeyPassword(sslKeyPassword: String) { + sslKeyPassword(sslKeyPassword.asJsonPrimitive()) + } + + open fun sslKeyPassword(sslKeyPassword: JsonNode) { + property("sslKeyPassword", sslKeyPassword) + } +} + +open class SSLBasicAuthRestClientPropertiesBuilder : SSLRestClientPropertiesBuilder() { + //TODO() +} + +open class SSLTokenAuthRestClientPropertiesBuilder : SSLRestClientPropertiesBuilder() { + //TODO() +}
\ No newline at end of file diff --git a/ms/blueprintsprocessor/modules/commons/rest-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/service/RestClientPropertiesDSLTest.kt b/ms/blueprintsprocessor/modules/commons/rest-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/service/RestClientPropertiesDSLTest.kt new file mode 100644 index 000000000..15133fa8a --- /dev/null +++ b/ms/blueprintsprocessor/modules/commons/rest-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/service/RestClientPropertiesDSLTest.kt @@ -0,0 +1,59 @@ +/* + * Copyright © 2019 IBM. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.ccsdk.cds.blueprintsprocessor.rest.service + +import org.junit.Test +import org.onap.ccsdk.cds.blueprintsprocessor.rest.dslBasicAuthRestClientProperties +import org.onap.ccsdk.cds.blueprintsprocessor.rest.dslSSLRestClientProperties +import org.onap.ccsdk.cds.blueprintsprocessor.rest.dslTokenAuthRestClientProperties +import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintTypes +import kotlin.test.assertNotNull + +class RestClientPropertiesDSLTest { + + @Test + fun testBasicAuthRestClientProperties() { + val properties = BluePrintTypes.dslBasicAuthRestClientProperties { + url("http://localhost:8080") + username("xxxxx") + password("******") + } + assertNotNull(properties, "failed to get dslBasicAuthRestClientProperties") + } + + @Test + fun testBasicTokenAuthRestClientProperties() { + val properties = BluePrintTypes.dslTokenAuthRestClientProperties { + url("http://localhost:8080") + token("sdfgfsadgsgf") + } + assertNotNull(properties, "failed to get dslTokenAuthRestClientProperties") + } + + @Test + fun testDslSSLRestClientProperties() { + val properties = BluePrintTypes.dslSSLRestClientProperties { + url("http://localhost:8080") + keyStoreInstance("instance") + sslTrust("sample-trust") + sslTrustPassword("sample-trust-password") + sslKey("sample-sslkey") + sslKeyPassword("sample-key-password") + } + assertNotNull(properties, "failed to get dslSSLRestClientProperties") + } +}
\ No newline at end of file diff --git a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/BluePrintManagementGRPCHandler.kt b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/BluePrintManagementGRPCHandler.kt index 549d6cd9f..81f3ec309 100644 --- a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/BluePrintManagementGRPCHandler.kt +++ b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/BluePrintManagementGRPCHandler.kt @@ -41,7 +41,7 @@ import java.util.* @Service open class BluePrintManagementGRPCHandler(private val bluePrintPathConfiguration: BluePrintPathConfiguration, - private val bluePrintCatalogService: BluePrintCatalogService) + private val blueprintsProcessorCatalogService: BluePrintCatalogService) : BluePrintManagementServiceGrpc.BluePrintManagementServiceImplBase() { private val log = LoggerFactory.getLogger(BluePrintManagementGRPCHandler::class.java) @@ -58,7 +58,7 @@ open class BluePrintManagementGRPCHandler(private val bluePrintPathConfiguration saveToDisk(request, cbaFile) - val blueprintId = bluePrintCatalogService.saveToDatabase(uploadId, cbaFile) + val blueprintId = blueprintsProcessorCatalogService.saveToDatabase(uploadId, cbaFile) responseObserver.onNext(successStatus("Successfully uploaded CBA($blueprintId)...", request.commonHeader)) responseObserver.onCompleted() } catch (e: Exception) { @@ -83,7 +83,7 @@ open class BluePrintManagementGRPCHandler(private val bluePrintPathConfiguration try { - bluePrintCatalogService.deleteFromDatabase(blueprintName, blueprintVersion) + blueprintsProcessorCatalogService.deleteFromDatabase(blueprintName, blueprintVersion) responseObserver.onNext(successStatus("Successfully deleted $blueprint", request.commonHeader)) responseObserver.onCompleted() } catch (e: Exception) { diff --git a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/ExecutionServiceHandler.kt b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/ExecutionServiceHandler.kt index 347e5eac4..094fb68da 100644 --- a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/ExecutionServiceHandler.kt +++ b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/ExecutionServiceHandler.kt @@ -17,7 +17,6 @@ package org.onap.ccsdk.cds.blueprintsprocessor.selfservice.api -import com.fasterxml.jackson.databind.node.JsonNodeFactory import io.grpc.stub.StreamObserver import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.GlobalScope @@ -42,7 +41,7 @@ import java.util.stream.Collectors @Service class ExecutionServiceHandler(private val bluePrintPathConfiguration: BluePrintPathConfiguration, - private val bluePrintCatalogService: BluePrintCatalogService, + private val blueprintsProcessorCatalogService: BluePrintCatalogService, private val bluePrintWorkflowExecutionService : BluePrintWorkflowExecutionService<ExecutionServiceInput, ExecutionServiceOutput>) { @@ -59,7 +58,7 @@ class ExecutionServiceHandler(private val bluePrintPathConfiguration: BluePrintP // Copy the File Part to Local File copyFromFilePart(filePart, compressedFile) // Save the Copied file to Database - return bluePrintCatalogService.saveToDatabase(saveId, compressedFile, true) + return blueprintsProcessorCatalogService.saveToDatabase(saveId, compressedFile, true) } catch (e: IOException) { throw BluePrintException(ErrorCode.IO_FILE_INTERRUPT.value, "Error in Upload CBA: ${e.message}", e) @@ -70,7 +69,7 @@ class ExecutionServiceHandler(private val bluePrintPathConfiguration: BluePrintP } suspend fun remove(name: String, version: String) { - bluePrintCatalogService.deleteFromDatabase(name, version) + blueprintsProcessorCatalogService.deleteFromDatabase(name, version) } suspend fun process(executionServiceInput: ExecutionServiceInput, @@ -102,7 +101,7 @@ class ExecutionServiceHandler(private val bluePrintPathConfiguration: BluePrintP val blueprintName = actionIdentifiers.blueprintName val blueprintVersion = actionIdentifiers.blueprintVersion try { - val basePath = bluePrintCatalogService.getFromDatabase(blueprintName, blueprintVersion) + val basePath = blueprintsProcessorCatalogService.getFromDatabase(blueprintName, blueprintVersion) log.info("blueprint base path $basePath") val blueprintRuntimeService = BluePrintMetadataUtils.getBluePrintRuntime(requestId, basePath.toString()) diff --git a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/validation/BluePrintRuntimeValidatorService.kt b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/validation/BluePrintRuntimeValidatorService.kt index 707439ddb..ab0d4256c 100644 --- a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/validation/BluePrintRuntimeValidatorService.kt +++ b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/validation/BluePrintRuntimeValidatorService.kt @@ -21,7 +21,7 @@ import org.onap.ccsdk.cds.controllerblueprints.validation.BluePrintDesignTimeVal import org.onap.ccsdk.cds.controllerblueprints.validation.extension.ResourceDefinitionValidator import org.springframework.stereotype.Service -@Service +@Service("bluePrintRuntimeValidatorService") open class BluePrintRuntimeValidatorService(bluePrintTypeValidatorService: BluePrintTypeValidatorService, resourceDefinitionValidator: ResourceDefinitionValidator) : BluePrintDesignTimeValidatorService(bluePrintTypeValidatorService, resourceDefinitionValidator) diff --git a/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/ComponentScriptExecutor.kt b/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/ComponentScriptExecutor.kt index 95b2afc4c..c66c3e913 100644 --- a/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/ComponentScriptExecutor.kt +++ b/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/ComponentScriptExecutor.kt @@ -16,16 +16,8 @@ package org.onap.ccsdk.cds.blueprintsprocessor.services.execution -import com.fasterxml.jackson.databind.JsonNode import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.ExecutionServiceInput -import org.onap.ccsdk.cds.controllerblueprints.core.* -import org.onap.ccsdk.cds.controllerblueprints.core.data.ArtifactDefinition -import org.onap.ccsdk.cds.controllerblueprints.core.data.Implementation -import org.onap.ccsdk.cds.controllerblueprints.core.data.NodeTemplate -import org.onap.ccsdk.cds.controllerblueprints.core.data.NodeType -import org.onap.ccsdk.cds.controllerblueprints.core.dsl.ArtifactDefinitionBuilder -import org.onap.ccsdk.cds.controllerblueprints.core.dsl.nodeTemplate -import org.onap.ccsdk.cds.controllerblueprints.core.dsl.nodeType +import org.onap.ccsdk.cds.controllerblueprints.core.getAsString import org.springframework.beans.factory.config.ConfigurableBeanFactory import org.springframework.context.annotation.Scope import org.springframework.stereotype.Component @@ -40,19 +32,23 @@ open class ComponentScriptExecutor(private var componentFunctionScriptingService : AbstractComponentFunction() { companion object { - const val SCRIPT_TYPE = "script-type" - const val SCRIPT_CLASS_REFERENCE = "script-class-reference" - const val DYNAMIC_PROPERTIES = "dynamic-properties" - const val RESPONSE_DATA = "response-data" - const val STATUS = "status" + const val INPUT_SCRIPT_TYPE = "script-type" + const val INPUT_SCRIPT_CLASS_REFERENCE = "script-class-reference" + const val INPUT_DYNAMIC_PROPERTIES = "dynamic-properties" + + const val ATTRIBUTE_RESPONSE_DATA = "response-data" + const val ATTRIBUTE_STATUS = "status" + + const val OUTPUT_RESPONSE_DATA = "response-data" + const val OUTPUT_STATUS = "status" } lateinit var scriptComponentFunction: AbstractScriptComponentFunction override suspend fun processNB(executionRequest: ExecutionServiceInput) { - val scriptType = operationInputs.getAsString(SCRIPT_TYPE) - val scriptClassReference = operationInputs.getAsString(SCRIPT_CLASS_REFERENCE) + val scriptType = operationInputs.getAsString(INPUT_SCRIPT_TYPE) + val scriptClassReference = operationInputs.getAsString(INPUT_SCRIPT_CLASS_REFERENCE) val scriptDependencies: MutableList<String> = arrayListOf() populateScriptDependencies(scriptDependencies) @@ -73,136 +69,4 @@ open class ComponentScriptExecutor(private var componentFunctionScriptingService open fun populateScriptDependencies(scriptDependencies: MutableList<String>) { /** Place holder for Child to add extra dependencies */ } -} - -/** Component Extensions **/ - -fun BluePrintTypes.componentScriptExecutor(): NodeType { - return nodeType(id = "component-script-executor", version = BluePrintConstants.DEFAULT_VERSION_NUMBER, - derivedFrom = BluePrintConstants.MODEL_TYPE_NODE_COMPONENT, - description = "Generic Script Component Executor") { - attribute(ComponentScriptExecutor.RESPONSE_DATA, BluePrintConstants.DATA_TYPE_JSON, false) - attribute(ComponentScriptExecutor.STATUS, BluePrintConstants.DATA_TYPE_STRING, true) - - operation("ComponentScriptExecutor", "ComponentScriptExecutor Operation") { - inputs { - property(ComponentScriptExecutor.SCRIPT_TYPE, BluePrintConstants.DATA_TYPE_STRING, true, - "Script Type") { - defaultValue(BluePrintConstants.SCRIPT_INTERNAL) - constrain { - validValues(listOf(BluePrintConstants.SCRIPT_INTERNAL.asJsonPrimitive(), - BluePrintConstants.SCRIPT_JYTHON.asJsonPrimitive(), - BluePrintConstants.SCRIPT_KOTLIN.asJsonPrimitive())) - } - } - property(ComponentScriptExecutor.SCRIPT_CLASS_REFERENCE, BluePrintConstants.DATA_TYPE_STRING, - true, "Kotlin Script class name or jython script name.") - property(ComponentScriptExecutor.DYNAMIC_PROPERTIES, BluePrintConstants.DATA_TYPE_JSON, false, - "Dynamic Json Content or DSL Json reference.") - } - outputs { - property(ComponentScriptExecutor.RESPONSE_DATA, BluePrintConstants.DATA_TYPE_JSON, false, - "Output Response") - property(ComponentScriptExecutor.STATUS, BluePrintConstants.DATA_TYPE_STRING, true, - "Status of the Component Execution ( success or failure )") - } - } - } -} - -/** Component Builder */ - -fun componentScriptExecutor(id: String, description: String, - block: ComponentScriptExecutorBuilder.() -> Unit): NodeTemplate { - return ComponentScriptExecutorBuilder(id, description).apply(block).build() -} - -class ComponentScriptExecutorBuilder(private val id: String, private val description: String) { - private var implementation: Implementation? = null - private var inputs: MutableMap<String, JsonNode>? = null - private var outputs: MutableMap<String, JsonNode>? = null - private var artifacts: MutableMap<String, ArtifactDefinition>? = null - - fun implementation(timeout: Int, operationHost: String? = BluePrintConstants.PROPERTY_SELF) { - val implementation = Implementation().apply { - this.operationHost = operationHost!! - this.timeout = timeout - } - this.implementation = implementation - } - - fun inputs(block: InputAssignmentBuilder.() -> Unit) { - this.inputs = InputAssignmentBuilder().apply(block).build() - } - - fun outputs(block: OutputAssignmentBuilder.() -> Unit) { - this.outputs = OutputAssignmentBuilder().apply(block).build() - } - - fun artifact(id: String, type: String, file: String) { - if (artifacts == null) - artifacts = hashMapOf() - artifacts!![id] = ArtifactDefinitionBuilder(id, type, file).build() - } - - fun artifact(id: String, type: String, file: String, block: ArtifactDefinitionBuilder.() -> Unit) { - if (artifacts == null) - artifacts = hashMapOf() - artifacts!![id] = ArtifactDefinitionBuilder(id, type, file).apply(block).build() - } - - fun build(): NodeTemplate { - return nodeTemplate(id, "component-script-executor", description) { - operation("ComponentScriptExecutor") { - implementation(implementation) - inputs(inputs) - outputs(outputs) - } - artifacts(artifacts) - } - } - - class InputAssignmentBuilder { - val properties: MutableMap<String, JsonNode> = hashMapOf() - - fun type(type: String) { - properties[ComponentScriptExecutor.SCRIPT_TYPE] = type.asJsonPrimitive() - } - - fun scriptClassReference(scriptClassReference: String) { - properties[ComponentScriptExecutor.SCRIPT_CLASS_REFERENCE] = scriptClassReference.asJsonPrimitive() - } - - fun dynamicProperty(dynamicProperty: Any) { - dynamicProperty(dynamicProperty.asJsonType()) - } - - fun dynamicProperty(dynamicProperty: JsonNode) { - properties[ComponentScriptExecutor.DYNAMIC_PROPERTIES] = dynamicProperty - } - - fun build(): MutableMap<String, JsonNode> { - return properties - } - } - - class OutputAssignmentBuilder { - val properties: MutableMap<String, JsonNode> = hashMapOf() - - fun status(status: String) { - properties[ComponentScriptExecutor.STATUS] = status.asJsonPrimitive() - } - - fun responseData(responseData: Any) { - responseData(responseData.asJsonType()) - } - - fun responseData(responseData: JsonNode) { - properties[ComponentScriptExecutor.RESPONSE_DATA] = responseData - } - - fun build(): MutableMap<String, JsonNode> { - return properties - } - } }
\ No newline at end of file diff --git a/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/ComponentScriptExecutorDSL.kt b/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/ComponentScriptExecutorDSL.kt new file mode 100644 index 000000000..1b905fa60 --- /dev/null +++ b/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/ComponentScriptExecutorDSL.kt @@ -0,0 +1,123 @@ +/* + * Copyright © 2019 IBM. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.ccsdk.cds.blueprintsprocessor.services.execution + +import com.fasterxml.jackson.databind.JsonNode +import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants +import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintTypes +import org.onap.ccsdk.cds.controllerblueprints.core.asJsonPrimitive +import org.onap.ccsdk.cds.controllerblueprints.core.asJsonType +import org.onap.ccsdk.cds.controllerblueprints.core.data.NodeTemplate +import org.onap.ccsdk.cds.controllerblueprints.core.data.NodeType +import org.onap.ccsdk.cds.controllerblueprints.core.dsl.AbstractNodeTemplateImplBuilder +import org.onap.ccsdk.cds.controllerblueprints.core.dsl.PropertiesAssignmentBuilder +import org.onap.ccsdk.cds.controllerblueprints.core.dsl.nodeType + +/** Component Extensions **/ + +fun BluePrintTypes.nodeTypeComponentScriptExecutor(): NodeType { + return nodeType(id = "component-script-executor", version = BluePrintConstants.DEFAULT_VERSION_NUMBER, + derivedFrom = BluePrintConstants.MODEL_TYPE_NODE_COMPONENT, + description = "Generic Script Component Executor") { + attribute(ComponentScriptExecutor.ATTRIBUTE_RESPONSE_DATA, BluePrintConstants.DATA_TYPE_JSON, false) + attribute(ComponentScriptExecutor.ATTRIBUTE_STATUS, BluePrintConstants.DATA_TYPE_STRING, true) + + operation("ComponentScriptExecutor", "ComponentScriptExecutor Operation") { + inputs { + property(ComponentScriptExecutor.INPUT_SCRIPT_TYPE, BluePrintConstants.DATA_TYPE_STRING, + true, "Script Type") { + defaultValue(BluePrintConstants.SCRIPT_INTERNAL) + constrain { + validValues(listOf(BluePrintConstants.SCRIPT_INTERNAL.asJsonPrimitive(), + BluePrintConstants.SCRIPT_JYTHON.asJsonPrimitive(), + BluePrintConstants.SCRIPT_KOTLIN.asJsonPrimitive())) + } + } + property(ComponentScriptExecutor.INPUT_SCRIPT_CLASS_REFERENCE, BluePrintConstants.DATA_TYPE_STRING, + true, "Kotlin Script class name or jython script name.") + property(ComponentScriptExecutor.INPUT_DYNAMIC_PROPERTIES, BluePrintConstants.DATA_TYPE_JSON, + false, "Dynamic Json Content or DSL Json reference.") + } + outputs { + property(ComponentScriptExecutor.OUTPUT_RESPONSE_DATA, BluePrintConstants.DATA_TYPE_JSON, + false, "Output Response") + property(ComponentScriptExecutor.OUTPUT_STATUS, BluePrintConstants.DATA_TYPE_STRING, + true, "Status of the Component Execution ( success or failure )") + } + } + } +} + +/** Component Builder */ +fun BluePrintTypes.nodeTemplateComponentScriptExecutor(id: String, + description: String, + block: ComponentScriptExecutorNodeTemplateImplBuilder.() -> Unit) + : NodeTemplate { + return ComponentScriptExecutorNodeTemplateImplBuilder(id, description).apply(block).build() +} + +class ComponentScriptExecutorNodeTemplateImplBuilder(id: String, description: String) : + AbstractNodeTemplateImplBuilder<ComponentScriptExecutorInputAssignmentBuilder, + ComponentScriptExecutorOutputAssignmentBuilder>(id, "component-script-executor", + "ComponentScriptExecutor", + description) + +class ComponentScriptExecutorInputAssignmentBuilder : PropertiesAssignmentBuilder() { + + fun type(type: String) { + type(type.asJsonPrimitive()) + } + + fun type(type: JsonNode) { + property(ComponentScriptExecutor.INPUT_SCRIPT_TYPE, type) + } + + fun scriptClassReference(scriptClassReference: String) { + scriptClassReference(scriptClassReference.asJsonPrimitive()) + } + + fun scriptClassReference(scriptClassReference: JsonNode) { + property(ComponentScriptExecutor.INPUT_SCRIPT_CLASS_REFERENCE, scriptClassReference) + } + + fun dynamicProperty(dynamicProperty: String) { + dynamicProperty(dynamicProperty.asJsonType()) + } + + fun dynamicProperty(dynamicProperty: JsonNode) { + property(ComponentScriptExecutor.INPUT_DYNAMIC_PROPERTIES, dynamicProperty) + } +} + +class ComponentScriptExecutorOutputAssignmentBuilder : PropertiesAssignmentBuilder() { + + fun status(status: String) { + status(status.asJsonPrimitive()) + } + + fun status(status: JsonNode) { + property(ComponentScriptExecutor.OUTPUT_STATUS, status) + } + + fun responseData(responseData: String) { + responseData(responseData.asJsonType()) + } + + fun responseData(responseData: JsonNode) { + property(ComponentScriptExecutor.OUTPUT_RESPONSE_DATA, responseData) + } +}
\ No newline at end of file diff --git a/ms/blueprintsprocessor/modules/services/execution-service/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/scripts/AbstractComponentFunctionTest.kt b/ms/blueprintsprocessor/modules/services/execution-service/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/scripts/AbstractComponentFunctionTest.kt index 309db9df4..07be8c809 100644 --- a/ms/blueprintsprocessor/modules/services/execution-service/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/scripts/AbstractComponentFunctionTest.kt +++ b/ms/blueprintsprocessor/modules/services/execution-service/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/scripts/AbstractComponentFunctionTest.kt @@ -34,15 +34,15 @@ import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.ExecutionServiceInpu import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.StepData import org.onap.ccsdk.cds.blueprintsprocessor.services.execution.AbstractComponentFunction import org.onap.ccsdk.cds.blueprintsprocessor.services.execution.ComponentFunctionScriptingService -import org.onap.ccsdk.cds.blueprintsprocessor.services.execution.componentScriptExecutor +import org.onap.ccsdk.cds.blueprintsprocessor.services.execution.nodeTypeComponentScriptExecutor import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintTypes import org.onap.ccsdk.cds.controllerblueprints.core.asJsonPrimitive import org.onap.ccsdk.cds.controllerblueprints.core.normalizedPathName +import org.onap.ccsdk.cds.controllerblueprints.core.scripts.BluePrintScriptsServiceImpl import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintContext import org.onap.ccsdk.cds.controllerblueprints.core.service.DefaultBluePrintRuntimeService import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils -import org.onap.ccsdk.cds.controllerblueprints.core.scripts.BluePrintScriptsServiceImpl import org.springframework.beans.factory.annotation.Autowired import org.springframework.test.context.ContextConfiguration import org.springframework.test.context.junit4.SpringRunner @@ -187,7 +187,7 @@ class AbstractComponentFunctionTest { @Test fun testComponentScriptExecutorNodeType() { - val componentScriptExecutor = BluePrintTypes.componentScriptExecutor() + val componentScriptExecutor = BluePrintTypes.nodeTypeComponentScriptExecutor() assertNotNull(componentScriptExecutor.interfaces, "failed to get interface operations") } } |