summaryrefslogtreecommitdiffstats
path: root/ms
diff options
context:
space:
mode:
Diffstat (limited to 'ms')
-rwxr-xr-xms/blueprintsprocessor/application/pom.xml23
-rw-r--r--ms/blueprintsprocessor/application/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/BlueprintDatabaseConfiguration.kt6
-rw-r--r--ms/blueprintsprocessor/application/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/BlueprintProcessorApplication.kt5
-rw-r--r--ms/blueprintsprocessor/application/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/BlueprintProcessorExceptionHandler.kt25
-rw-r--r--ms/blueprintsprocessor/application/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/logging/ColorMarker.kt (renamed from ms/blueprintsprocessor/application/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/logging/ColorMarker.kt)0
-rw-r--r--ms/blueprintsprocessor/application/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/logging/LogColor.kt (renamed from ms/blueprintsprocessor/application/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/logging/LogColor.kt)0
-rw-r--r--ms/blueprintsprocessor/application/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/logging/MockInvocationLogger.kt (renamed from ms/blueprintsprocessor/application/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/logging/MockInvocationLogger.kt)0
-rw-r--r--ms/blueprintsprocessor/application/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/utils/InvalidUatDefinition.kt22
-rw-r--r--ms/blueprintsprocessor/application/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/utils/JsonNormalizer.kt (renamed from ms/blueprintsprocessor/application/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/utils/JsonNormalizer.kt)0
-rw-r--r--ms/blueprintsprocessor/application/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/utils/PathDeserializer.kt (renamed from ms/blueprintsprocessor/application/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/utils/PathDeserializer.kt)0
-rw-r--r--ms/blueprintsprocessor/application/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/utils/RequiredMapEntriesMatcher.kt (renamed from ms/blueprintsprocessor/application/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/utils/RequiredMapEntriesMatcher.kt)0
-rw-r--r--ms/blueprintsprocessor/application/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/utils/UatDefinition.kt (renamed from ms/blueprintsprocessor/application/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/utils/UatDefinition.kt)24
-rw-r--r--ms/blueprintsprocessor/application/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/utils/UatExecutor.kt (renamed from ms/blueprintsprocessor/application/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/utils/UatExecutor.kt)159
-rw-r--r--ms/blueprintsprocessor/application/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/utils/UatServices.kt (renamed from ms/blueprintsprocessor/application/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/utils/UatServices.kt)0
-rwxr-xr-xms/blueprintsprocessor/application/src/main/resources/application-dev.properties7
-rw-r--r--ms/blueprintsprocessor/application/src/main/resources/application-local.yml4
-rwxr-xr-xms/blueprintsprocessor/application/src/main/resources/application.properties8
-rw-r--r--ms/blueprintsprocessor/application/src/main/resources/error-messages_en.properties91
-rw-r--r--ms/blueprintsprocessor/application/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/ErrorCatalogTestConfiguration.kt28
-rw-r--r--ms/blueprintsprocessor/application/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/UatServicesTest.kt23
-rw-r--r--ms/blueprintsprocessor/application/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/error/ErrorCatalogServiceTest.kt97
-rw-r--r--ms/blueprintsprocessor/application/src/test/resources/application-test.properties6
-rw-r--r--ms/blueprintsprocessor/application/src/test/resources/application.properties5
-rw-r--r--ms/blueprintsprocessor/application/src/test/resources/error-messages_en.properties91
-rw-r--r--ms/blueprintsprocessor/functions/message-prioritizaion/pom.xml1
-rw-r--r--ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/ComponentNetconfExecutor.kt3
-rwxr-xr-xms/blueprintsprocessor/functions/pom.xml2
-rw-r--r--ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceResolutionComponent.kt4
-rw-r--r--ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceResolutionComponentDSL.kt11
-rw-r--r--ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceResolutionConstants.kt1
-rw-r--r--ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceResolutionService.kt30
-rw-r--r--ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/db/ResourceResolutionDBService.kt23
-rw-r--r--ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/db/ResourceResolutionRepository.kt9
-rw-r--r--ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/CapabilityResourceResolutionProcessor.kt2
-rw-r--r--ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/DatabaseResourceAssignmentProcessor.kt6
-rw-r--r--ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/RestResourceResolutionProcessor.kt7
-rw-r--r--ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/utils/ResourceAssignmentUtils.kt77
-rw-r--r--ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceResolutionComponentDSLTest.kt1
-rw-r--r--ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceResolutionServiceTest.kt98
-rw-r--r--ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/db/ResourceResolutionDBServiceTest.kt12
-rw-r--r--ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/CapabilityResourceResolutionProcessorTest.kt8
-rw-r--r--ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/utils/ResourceAssignmentUtilsTest.kt70
-rw-r--r--ms/blueprintsprocessor/functions/restconf-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/restconf/executor/RestconfExecutorExtensions.kt17
-rw-r--r--ms/blueprintsprocessor/functions/restful-executor/pom.xml (renamed from ms/blueprintsprocessor/functions/nrm-restful/pom.xml)12
-rw-r--r--ms/blueprintsprocessor/functions/restful-executor/src/main/kotlin/internal/scripts/TestRestfulConfigure.kt42
-rw-r--r--ms/blueprintsprocessor/functions/restful-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/restful/executor/ComponentRestfulExecutor.kt69
-rw-r--r--ms/blueprintsprocessor/functions/restful-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/restful/executor/RestfulCMComponentFunction.kt126
-rw-r--r--ms/blueprintsprocessor/functions/restful-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/restful/executor/nrmfunction/RestfulNRMServiceClient.kt (renamed from ms/blueprintsprocessor/functions/nrm-restful/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/nrm/restful/RestfulNRMServiceClient.kt)2
-rw-r--r--ms/blueprintsprocessor/functions/restful-executor/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/restful/executor/ComponentRestfulExecutorTest.kt105
-rw-r--r--ms/blueprintsprocessor/functions/restful-executor/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/restful/executor/nrmfunction/RestfulNRMServiceClientTest.kt (renamed from ms/blueprintsprocessor/functions/nrm-restful/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/nrm/restful/RestfulNRMServiceClientTest.kt)2
-rw-r--r--ms/blueprintsprocessor/modules/blueprints/blueprint-core/pom.xml10
-rw-r--r--ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/BluePrintConstants.kt5
-rw-r--r--ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/BluePrintException.kt27
-rw-r--r--ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/BluePrintProcessorException.kt110
-rw-r--r--ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/interfaces/BluePrintScriptsService.kt2
-rw-r--r--ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/scripts/BluePrintCompileService.kt13
-rw-r--r--ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/scripts/BluePrintScriptsServiceImpl.kt7
-rw-r--r--ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/service/BluePrintTemplateService.kt8
-rwxr-xr-xms/blueprintsprocessor/modules/blueprints/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/utils/BluePrintArchiveUtils.kt186
-rw-r--r--ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/utils/JacksonUtils.kt8
-rw-r--r--ms/blueprintsprocessor/modules/blueprints/blueprint-proto/pom.xml4
-rw-r--r--ms/blueprintsprocessor/modules/blueprints/pom.xml1
-rw-r--r--ms/blueprintsprocessor/modules/blueprints/resource-dict/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/resource/dict/ResourceDefinition.kt31
-rw-r--r--ms/blueprintsprocessor/modules/commons/nats-lib/pom.xml1
-rw-r--r--ms/blueprintsprocessor/modules/commons/processor-core/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/core/cluster/HazlecastClusterService.kt7
-rw-r--r--ms/blueprintsprocessor/modules/commons/processor-core/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/core/cluster/HazlecastClusterServiceTest.kt4
-rw-r--r--ms/blueprintsprocessor/modules/commons/processor-core/src/test/resources/hazelcast/hazelcast-5679.yaml21
-rw-r--r--ms/blueprintsprocessor/modules/commons/processor-core/src/test/resources/hazelcast/hazelcast-5680.yaml21
-rw-r--r--ms/blueprintsprocessor/modules/commons/processor-core/src/test/resources/hazelcast/hazelcast-5681.yaml21
-rw-r--r--ms/blueprintsprocessor/modules/commons/processor-core/src/test/resources/hazelcast/hazelcast-5682.yaml9
-rw-r--r--ms/blueprintsprocessor/modules/commons/processor-core/src/test/resources/hazelcast/hazelcast-cluster.yaml23
-rw-r--r--ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/service/BasicAuthRestClientService.kt4
-rw-r--r--ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/BlueprintModelController.kt39
-rw-r--r--ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/DesignerApiData.kt32
-rw-r--r--ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/ErrorHandling.kt40
-rw-r--r--ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/handler/BluePrintModelHandler.kt69
-rw-r--r--ms/blueprintsprocessor/modules/inbounds/resource-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/resource/api/ErrorHandling.kt36
-rw-r--r--ms/blueprintsprocessor/modules/inbounds/resource-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/resource/api/ResourceController.kt22
-rw-r--r--ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/ErrorHandling.kt44
-rw-r--r--ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/ExecutionServiceController.kt6
-rw-r--r--ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/ComponentFunctionScriptingService.kt6
-rw-r--r--ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/ComponentScriptExecutor.kt2
-rw-r--r--ms/blueprintsprocessor/modules/services/workflow-service/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/workflow/BlueprintSvcLogicService.kt4
-rwxr-xr-xms/blueprintsprocessor/parent/pom.xml108
-rwxr-xr-xms/error-catalog/README.md40
-rw-r--r--ms/error-catalog/application/pom.xml30
-rw-r--r--ms/error-catalog/core/pom.xml30
-rw-r--r--ms/error-catalog/core/src/main/kotlin/org/onap/ccsdk/cds/error/catalog/core/ErrorCatalogException.kt112
-rw-r--r--ms/error-catalog/core/src/main/kotlin/org/onap/ccsdk/cds/error/catalog/core/ErrorCatalogExtensions.kt32
-rw-r--r--ms/error-catalog/core/src/main/kotlin/org/onap/ccsdk/cds/error/catalog/core/ErrorCodes.kt88
-rw-r--r--ms/error-catalog/core/src/main/kotlin/org/onap/ccsdk/cds/error/catalog/core/ErrorLibData.kt94
-rw-r--r--ms/error-catalog/core/src/main/kotlin/org/onap/ccsdk/cds/error/catalog/core/ErrorMessageLibConstants.kt31
-rw-r--r--ms/error-catalog/pom.xml157
-rw-r--r--ms/error-catalog/services/pom.xml37
-rw-r--r--ms/error-catalog/services/src/main/kotlin/org/onap/ccsdk/cds/error/catalog/services/ErrorCatalogConfiguration.kt34
-rw-r--r--ms/error-catalog/services/src/main/kotlin/org/onap/ccsdk/cds/error/catalog/services/ErrorCatalogDBService.kt98
-rw-r--r--ms/error-catalog/services/src/main/kotlin/org/onap/ccsdk/cds/error/catalog/services/ErrorCatalogExceptionHandler.kt31
-rw-r--r--ms/error-catalog/services/src/main/kotlin/org/onap/ccsdk/cds/error/catalog/services/ErrorCatalogLoadService.kt147
-rw-r--r--ms/error-catalog/services/src/main/kotlin/org/onap/ccsdk/cds/error/catalog/services/ErrorCatalogService.kt91
-rw-r--r--ms/error-catalog/services/src/main/kotlin/org/onap/ccsdk/cds/error/catalog/services/ErrorCatalogServiceExtensions.kt25
-rwxr-xr-xms/error-catalog/services/src/main/kotlin/org/onap/ccsdk/cds/error/catalog/services/domain/Domain.kt76
-rw-r--r--ms/error-catalog/services/src/main/kotlin/org/onap/ccsdk/cds/error/catalog/services/domain/ErrorMessageModel.kt69
-rw-r--r--ms/error-catalog/services/src/main/kotlin/org/onap/ccsdk/cds/error/catalog/services/repository/DomainRepository.kt45
-rw-r--r--ms/error-catalog/services/src/main/kotlin/org/onap/ccsdk/cds/error/catalog/services/repository/ErrorMessageModelRepository.kt36
-rw-r--r--ms/error-catalog/services/src/main/kotlin/org/onap/ccsdk/cds/error/catalog/services/utils/ErrorCatalogUtils.kt39
-rw-r--r--ms/pom.xml20
-rw-r--r--ms/py-executor/pom.xml1
-rw-r--r--ms/py-executor/resource_resolution/README63
-rw-r--r--ms/py-executor/resource_resolution/authorization.py64
-rw-r--r--ms/py-executor/resource_resolution/client.py31
-rw-r--r--ms/py-executor/resource_resolution/resource_resolution.py294
-rw-r--r--ms/py-executor/resource_resolution/tests/authorization_interceptor_test.py50
-rw-r--r--ms/py-executor/resource_resolution/tests/resource_resolution_test.py105
-rw-r--r--ms/sdclistener/application/pom.xml6
-rw-r--r--ms/sdclistener/application/src/main/resources/application.yaml2
-rw-r--r--ms/sdclistener/application/src/test/java/org/onap/ccsdk/cds/sdclistener/SdcListenerConfigurationTest.java2
-rwxr-xr-xms/sdclistener/parent/pom.xml2
117 files changed, 3894 insertions, 383 deletions
diff --git a/ms/blueprintsprocessor/application/pom.xml b/ms/blueprintsprocessor/application/pom.xml
index b007ac7fb..18a61e0e6 100755
--- a/ms/blueprintsprocessor/application/pom.xml
+++ b/ms/blueprintsprocessor/application/pom.xml
@@ -46,9 +46,9 @@
<dependencies>
<dependency>
- <groupId>org.onap.ccsdk.cds.blueprintsprocessor</groupId>
- <artifactId>blueprint-core</artifactId>
- <exclusions>
+ <groupId>org.onap.ccsdk.cds.blueprintsprocessor</groupId>
+ <artifactId>blueprint-core</artifactId>
+ <exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
@@ -66,6 +66,12 @@
</exclusions>
</dependency>
+ <!-- Error Catalog Services -->
+ <dependency>
+ <groupId>org.onap.ccsdk.cds.error.catalog</groupId>
+ <artifactId>error-catalog-services</artifactId>
+ </dependency>
+
<!-- North Bound -->
<dependency>
<groupId>org.onap.ccsdk.cds.blueprintsprocessor</groupId>
@@ -99,6 +105,10 @@
</dependency>
<dependency>
<groupId>org.onap.ccsdk.cds.blueprintsprocessor.functions</groupId>
+ <artifactId>restful-executor</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.onap.ccsdk.cds.blueprintsprocessor.functions</groupId>
<artifactId>ansible-awx-executor</artifactId>
</dependency>
<dependency>
@@ -153,6 +163,9 @@
<dependency>
<groupId>com.nhaarman.mockitokotlin2</groupId>
<artifactId>mockito-kotlin</artifactId>
+ <!-- It's unusual but 'compile' here is the right scope since mockito is being used at runtime by
+ the UatServices (/api/v1/uat/spy and /api/v1/uat/verify endpoints) -->
+ <scope>compile</scope>
</dependency>
<dependency>
<groupId>com.schibsted.spt.data</groupId>
@@ -299,6 +312,10 @@
<target>1.8</target>
</configuration>
</plugin>
+ <plugin>
+ <groupId>pl.project13.maven</groupId>
+ <artifactId>git-commit-id-plugin</artifactId>
+ </plugin>
</plugins>
</build>
diff --git a/ms/blueprintsprocessor/application/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/BlueprintDatabaseConfiguration.kt b/ms/blueprintsprocessor/application/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/BlueprintDatabaseConfiguration.kt
index 58464cb10..e9557aed9 100644
--- a/ms/blueprintsprocessor/application/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/BlueprintDatabaseConfiguration.kt
+++ b/ms/blueprintsprocessor/application/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/BlueprintDatabaseConfiguration.kt
@@ -31,7 +31,8 @@ import javax.sql.DataSource
@Configuration
@Import(BluePrintDBLibConfiguration::class)
@EnableJpaRepositories(
- basePackages = ["org.onap.ccsdk.cds.controllerblueprints", "org.onap.ccsdk.cds.blueprintsprocessor"],
+ basePackages = ["org.onap.ccsdk.cds.controllerblueprints", "org.onap.ccsdk.cds.blueprintsprocessor",
+ "org.onap.ccsdk.cds.error.catalog"],
entityManagerFactoryRef = "primaryEntityManager",
transactionManagerRef = "primaryTransactionManager"
)
@@ -43,7 +44,8 @@ open class BlueprintDatabaseConfiguration(primaryDataSourceProperties: PrimaryDa
open fun primaryEntityManager(): LocalContainerEntityManagerFactoryBean {
return primaryEntityManager(
"org.onap.ccsdk.cds.controllerblueprints",
- "org.onap.ccsdk.cds.blueprintsprocessor"
+ "org.onap.ccsdk.cds.blueprintsprocessor",
+ "org.onap.ccsdk.cds.error.catalog"
)
}
diff --git a/ms/blueprintsprocessor/application/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/BlueprintProcessorApplication.kt b/ms/blueprintsprocessor/application/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/BlueprintProcessorApplication.kt
index 1d1baeeef..97b7d28b0 100644
--- a/ms/blueprintsprocessor/application/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/BlueprintProcessorApplication.kt
+++ b/ms/blueprintsprocessor/application/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/BlueprintProcessorApplication.kt
@@ -30,7 +30,10 @@ import org.springframework.context.annotation.ComponentScan
*/
@SpringBootApplication
@EnableAutoConfiguration(exclude = [DataSourceAutoConfiguration::class, HazelcastAutoConfiguration::class])
-@ComponentScan(basePackages = ["org.onap.ccsdk.cds.blueprintsprocessor", "org.onap.ccsdk.cds.controllerblueprints"])
+@ComponentScan(
+ basePackages = ["org.onap.ccsdk.cds.error.catalog",
+ "org.onap.ccsdk.cds.blueprintsprocessor", "org.onap.ccsdk.cds.controllerblueprints"]
+)
open class BlueprintProcessorApplication
fun main(args: Array<String>) {
diff --git a/ms/blueprintsprocessor/application/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/BlueprintProcessorExceptionHandler.kt b/ms/blueprintsprocessor/application/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/BlueprintProcessorExceptionHandler.kt
new file mode 100644
index 000000000..f241e3f42
--- /dev/null
+++ b/ms/blueprintsprocessor/application/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/BlueprintProcessorExceptionHandler.kt
@@ -0,0 +1,25 @@
+/*
+ * Copyright © 2018-2019 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.cds.blueprintsprocessor
+
+import org.onap.ccsdk.cds.error.catalog.services.ErrorCatalogExceptionHandler
+import org.onap.ccsdk.cds.error.catalog.services.ErrorCatalogService
+import org.springframework.web.bind.annotation.RestControllerAdvice
+
+@RestControllerAdvice("org.onap.ccsdk.cds")
+open class BlueprintProcessorExceptionHandler(private val errorCatalogService: ErrorCatalogService) :
+ ErrorCatalogExceptionHandler(errorCatalogService)
diff --git a/ms/blueprintsprocessor/application/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/logging/ColorMarker.kt b/ms/blueprintsprocessor/application/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/logging/ColorMarker.kt
index 9ae3ff805..9ae3ff805 100644
--- a/ms/blueprintsprocessor/application/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/logging/ColorMarker.kt
+++ b/ms/blueprintsprocessor/application/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/logging/ColorMarker.kt
diff --git a/ms/blueprintsprocessor/application/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/logging/LogColor.kt b/ms/blueprintsprocessor/application/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/logging/LogColor.kt
index f0cba2670..f0cba2670 100644
--- a/ms/blueprintsprocessor/application/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/logging/LogColor.kt
+++ b/ms/blueprintsprocessor/application/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/logging/LogColor.kt
diff --git a/ms/blueprintsprocessor/application/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/logging/MockInvocationLogger.kt b/ms/blueprintsprocessor/application/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/logging/MockInvocationLogger.kt
index f8e6bd486..f8e6bd486 100644
--- a/ms/blueprintsprocessor/application/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/logging/MockInvocationLogger.kt
+++ b/ms/blueprintsprocessor/application/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/logging/MockInvocationLogger.kt
diff --git a/ms/blueprintsprocessor/application/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/utils/InvalidUatDefinition.kt b/ms/blueprintsprocessor/application/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/utils/InvalidUatDefinition.kt
new file mode 100644
index 000000000..4a756411f
--- /dev/null
+++ b/ms/blueprintsprocessor/application/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/utils/InvalidUatDefinition.kt
@@ -0,0 +1,22 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2020 Nordix Foundation.
+ * ================================================================================
+ * 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.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+package org.onap.ccsdk.cds.blueprintsprocessor.uat.utils
+
+class InvalidUatDefinition(message: String) : RuntimeException(message)
diff --git a/ms/blueprintsprocessor/application/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/utils/JsonNormalizer.kt b/ms/blueprintsprocessor/application/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/utils/JsonNormalizer.kt
index 39caa0178..39caa0178 100644
--- a/ms/blueprintsprocessor/application/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/utils/JsonNormalizer.kt
+++ b/ms/blueprintsprocessor/application/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/utils/JsonNormalizer.kt
diff --git a/ms/blueprintsprocessor/application/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/utils/PathDeserializer.kt b/ms/blueprintsprocessor/application/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/utils/PathDeserializer.kt
index 6c5759155..6c5759155 100644
--- a/ms/blueprintsprocessor/application/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/utils/PathDeserializer.kt
+++ b/ms/blueprintsprocessor/application/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/utils/PathDeserializer.kt
diff --git a/ms/blueprintsprocessor/application/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/utils/RequiredMapEntriesMatcher.kt b/ms/blueprintsprocessor/application/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/utils/RequiredMapEntriesMatcher.kt
index 0f98d7213..0f98d7213 100644
--- a/ms/blueprintsprocessor/application/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/utils/RequiredMapEntriesMatcher.kt
+++ b/ms/blueprintsprocessor/application/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/utils/RequiredMapEntriesMatcher.kt
diff --git a/ms/blueprintsprocessor/application/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/utils/UatDefinition.kt b/ms/blueprintsprocessor/application/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/utils/UatDefinition.kt
index c45ac45c6..17b79f588 100644
--- a/ms/blueprintsprocessor/application/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/utils/UatDefinition.kt
+++ b/ms/blueprintsprocessor/application/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/utils/UatDefinition.kt
@@ -47,18 +47,30 @@ data class RequestDefinition(
)
@JsonInclude(JsonInclude.Include.NON_EMPTY)
-data class ResponseDefinition(val status: Int = 200, val body: JsonNode? = null) {
+data class ResponseDefinition(val status: Int = 200, val body: JsonNode? = null, val headers: Map<String, String> = mapOf("Content-Type" to "application/json")) {
companion object {
- val DEFAULT_RESPONSE = ResponseDefinition()
+ val DEFAULT_RESPONSES = listOf(ResponseDefinition())
}
}
@JsonInclude(JsonInclude.Include.NON_EMPTY)
-data class ExpectationDefinition(
+class ExpectationDefinition(
val request: RequestDefinition,
- val response: ResponseDefinition = ResponseDefinition.DEFAULT_RESPONSE
-)
+ response: ResponseDefinition?,
+ responses: List<ResponseDefinition>? = null,
+ val times: String = ">= 1"
+) {
+ val responses: List<ResponseDefinition> = resolveOneOrMany(response, responses, ResponseDefinition.DEFAULT_RESPONSES)
+
+ companion object {
+ fun <T> resolveOneOrMany(one: T?, many: List<T>?, defaultMany: List<T>): List<T> = when {
+ many != null -> many
+ one != null -> listOf(one)
+ else -> defaultMany
+ }
+ }
+}
@JsonInclude(JsonInclude.Include.NON_EMPTY)
data class ServiceDefinition(val selector: String, val expectations: List<ExpectationDefinition>)
@@ -97,6 +109,6 @@ data class UatDefinition(
companion object {
fun load(mapper: ObjectMapper, spec: String): UatDefinition =
- mapper.convertValue(Yaml().load(spec), UatDefinition::class.java)
+ mapper.convertValue(Yaml().load(spec), UatDefinition::class.java)
}
}
diff --git a/ms/blueprintsprocessor/application/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/utils/UatExecutor.kt b/ms/blueprintsprocessor/application/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/utils/UatExecutor.kt
index a904fa9b6..d120e71d6 100644
--- a/ms/blueprintsprocessor/application/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/utils/UatExecutor.kt
+++ b/ms/blueprintsprocessor/application/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/utils/UatExecutor.kt
@@ -24,9 +24,10 @@ import com.fasterxml.jackson.databind.ObjectMapper
import com.nhaarman.mockitokotlin2.any
import com.nhaarman.mockitokotlin2.argThat
import com.nhaarman.mockitokotlin2.atLeast
-import com.nhaarman.mockitokotlin2.atLeastOnce
+import com.nhaarman.mockitokotlin2.atMost
import com.nhaarman.mockitokotlin2.eq
import com.nhaarman.mockitokotlin2.mock
+import com.nhaarman.mockitokotlin2.times
import com.nhaarman.mockitokotlin2.verify
import com.nhaarman.mockitokotlin2.verifyNoMoreInteractions
import com.nhaarman.mockitokotlin2.whenever
@@ -44,6 +45,7 @@ import org.hamcrest.CoreMatchers.equalTo
import org.hamcrest.CoreMatchers.notNullValue
import org.hamcrest.MatcherAssert.assertThat
import org.mockito.Answers
+import org.mockito.verification.VerificationMode
import org.onap.ccsdk.cds.blueprintsprocessor.rest.service.BluePrintRestLibPropertyService
import org.onap.ccsdk.cds.blueprintsprocessor.rest.service.BlueprintWebClientService
import org.onap.ccsdk.cds.blueprintsprocessor.rest.service.BlueprintWebClientService.WebClientResponse
@@ -77,7 +79,8 @@ class UatExecutor(
companion object {
private const val NOOP_PASSWORD_PREFIX = "{noop}"
-
+ private const val PROPERTY_IN_UAT = "IN_UAT"
+ private val TIMES_SPEC_REGEX = "([<>]=?)?\\s*(\\d+)".toRegex()
private val log: Logger = LoggerFactory.getLogger(UatExecutor::class.java)
private val mockLoggingListener = MockInvocationLogger(markerOf(COLOR_MOCKITO))
}
@@ -103,23 +106,24 @@ class UatExecutor(
fun execute(uat: UatDefinition, cbaBytes: ByteArray): UatDefinition {
val defaultHeaders = listOf(BasicHeader(HttpHeaders.AUTHORIZATION, clientAuthToken()))
val httpClient = HttpClientBuilder.create()
- .setDefaultHeaders(defaultHeaders)
- .build()
+ .setDefaultHeaders(defaultHeaders)
+ .build()
// Only if externalServices are defined
val mockInterceptor = MockPreInterceptor()
// Always defined and used, whatever the case
val spyInterceptor = SpyPostInterceptor(mapper)
restClientFactory.setInterceptors(mockInterceptor, spyInterceptor)
try {
- // Configure mocked external services and save their expected requests for further validation
- val requestsPerClient = uat.externalServices.associateBy(
- { service ->
- createRestClientMock(service.expectations).also { restClient ->
- // side-effect: register restClient to override real instance
- mockInterceptor.registerMock(service.selector, restClient)
- }
- },
- { service -> service.expectations.map { it.request } }
+ markUatBegin()
+ // Configure mocked external services and save their expectations for further validation
+ val expectationsPerClient = uat.externalServices.associateBy(
+ { service ->
+ createRestClientMock(service.expectations).also { restClient ->
+ // side-effect: register restClient to override real instance
+ mockInterceptor.registerMock(service.selector, restClient)
+ }
+ },
+ { service -> service.expectations }
)
val newProcesses = httpClient.use { client ->
@@ -130,26 +134,27 @@ class UatExecutor(
log.info("Executing process '${process.name}'")
val responseNormalizer = JsonNormalizer.getNormalizer(mapper, process.responseNormalizerSpec)
val actualResponse = processBlueprint(
- client, process.request,
- process.expectedResponse, responseNormalizer
+ client, process.request,
+ process.expectedResponse, responseNormalizer
)
ProcessDefinition(
- process.name,
- process.request,
- actualResponse,
- process.responseNormalizerSpec
+ process.name,
+ process.request,
+ actualResponse,
+ process.responseNormalizerSpec
)
}
}
// Validate requests to external services
- for ((mockClient, requests) in requestsPerClient) {
- requests.forEach { request ->
- verify(mockClient, atLeastOnce()).exchangeResource(
- eq(request.method),
- eq(request.path),
- argThat { assertJsonEquals(request.body, this) },
- argThat(RequiredMapEntriesMatcher(request.headers))
+ for ((mockClient, expectations) in expectationsPerClient) {
+ expectations.forEach { expectation ->
+ val request = expectation.request
+ verify(mockClient, evalVerificationMode(expectation.times)).exchangeResource(
+ eq(request.method),
+ eq(request.path),
+ argThat { assertJsonEquals(request.body, this) },
+ argThat(RequiredMapEntriesMatcher(request.headers))
)
}
// Don't mind the invocations to the overloaded exchangeResource(String, String, String)
@@ -158,40 +163,51 @@ class UatExecutor(
}
val newExternalServices = spyInterceptor.getSpies()
- .map(SpyService::asServiceDefinition)
+ .map(SpyService::asServiceDefinition)
return UatDefinition(newProcesses, newExternalServices)
} finally {
restClientFactory.clearInterceptors()
+ markUatEnd()
}
}
+ private fun markUatBegin() {
+ System.setProperty(PROPERTY_IN_UAT, "1")
+ }
+
+ private fun markUatEnd() {
+ System.clearProperty(PROPERTY_IN_UAT)
+ }
+
private fun createRestClientMock(restExpectations: List<ExpectationDefinition>):
BlueprintWebClientService {
val restClient = mock<BlueprintWebClientService>(
- defaultAnswer = Answers.RETURNS_SMART_NULLS,
- // our custom verboseLogging handler
- invocationListeners = arrayOf(mockLoggingListener)
+ defaultAnswer = Answers.RETURNS_SMART_NULLS,
+ // our custom verboseLogging handler
+ invocationListeners = arrayOf(mockLoggingListener)
)
// Delegates to overloaded exchangeResource(String, String, String, Map<String, String>)
whenever(restClient.exchangeResource(any(), any(), any()))
- .thenAnswer { invocation ->
- val method = invocation.arguments[0] as String
- val path = invocation.arguments[1] as String
- val request = invocation.arguments[2] as String
- restClient.exchangeResource(method, path, request, emptyMap())
- }
+ .thenAnswer { invocation ->
+ val method = invocation.arguments[0] as String
+ val path = invocation.arguments[1] as String
+ val request = invocation.arguments[2] as String
+ restClient.exchangeResource(method, path, request, emptyMap())
+ }
for (expectation in restExpectations) {
- whenever(
- restClient.exchangeResource(
- eq(expectation.request.method),
- eq(expectation.request.path),
- any(),
- any()
- )
+ var stubbing = whenever(
+ restClient.exchangeResource(
+ eq(expectation.request.method),
+ eq(expectation.request.path),
+ any(),
+ any()
+ )
)
- .thenReturn(WebClientResponse(expectation.response.status, expectation.response.body.toString()))
+ for (response in expectation.responses) {
+ stubbing = stubbing.thenReturn(WebClientResponse(response.status, response.body.toString()))
+ }
}
return restClient
}
@@ -199,9 +215,9 @@ class UatExecutor(
@Throws(AssertionError::class)
private fun uploadBlueprint(client: HttpClient, cbaBytes: ByteArray) {
val multipartEntity = MultipartEntityBuilder.create()
- .setMode(HttpMultipartMode.BROWSER_COMPATIBLE)
- .addBinaryBody("file", cbaBytes, ContentType.DEFAULT_BINARY, "cba.zip")
- .build()
+ .setMode(HttpMultipartMode.BROWSER_COMPATIBLE)
+ .addBinaryBody("file", cbaBytes, ContentType.DEFAULT_BINARY, "cba.zip")
+ .build()
val request = HttpPost("$baseUrl/api/v1/blueprint-model/publish").apply {
entity = multipartEntity
}
@@ -236,6 +252,19 @@ class UatExecutor(
return mapper.readTree(actualResponse)!!
}
+ private fun evalVerificationMode(times: String): VerificationMode {
+ val matchResult = TIMES_SPEC_REGEX.matchEntire(times) ?: throw InvalidUatDefinition(
+ "Time specification '$times' does not follow expected format $TIMES_SPEC_REGEX")
+ val counter = matchResult.groups[2]!!.value.toInt()
+ return when (matchResult.groups[1]?.value) {
+ ">=" -> atLeast(counter)
+ ">" -> atLeast(counter + 1)
+ "<=" -> atMost(counter)
+ "<" -> atMost(counter - 1)
+ else -> times(counter)
+ }
+ }
+
@Throws(AssertionError::class)
private fun assertJsonEquals(expected: JsonNode?, actual: String): Boolean {
// special case
@@ -249,15 +278,15 @@ class UatExecutor(
}
private fun localServerPort(): Int =
- (environment.getProperty("local.server.port")
- ?: environment.getRequiredProperty("blueprint.httpPort")).toInt()
+ (environment.getProperty("local.server.port")
+ ?: environment.getRequiredProperty("blueprint.httpPort")).toInt()
private fun clientAuthToken(): String {
val username = environment.getRequiredProperty("security.user.name")
val password = environment.getRequiredProperty("security.user.password")
val plainPassword = when {
password.startsWith(NOOP_PASSWORD_PREFIX) -> password.substring(
- NOOP_PASSWORD_PREFIX.length)
+ NOOP_PASSWORD_PREFIX.length)
else -> username
}
return "Basic " + Base64Utils.encodeToString("$username:$plainPassword".toByteArray())
@@ -271,7 +300,7 @@ class UatExecutor(
}
override fun getInstance(selector: String): BlueprintWebClientService? =
- mocks[selector]
+ mocks[selector]
fun registerMock(selector: String, client: BlueprintWebClientService) {
mocks[selector] = client
@@ -293,7 +322,7 @@ class UatExecutor(
}
fun getSpies(): List<SpyService> =
- spies.values.toList()
+ spies.values.toList()
}
private class SpyService(
@@ -301,14 +330,14 @@ class UatExecutor(
val selector: String,
private val realService: BlueprintWebClientService
) :
- BlueprintWebClientService by realService {
+ BlueprintWebClientService by realService {
private val expectations: MutableList<ExpectationDefinition> = mutableListOf()
override fun exchangeResource(methodType: String, path: String, request: String): WebClientResponse<String> =
- exchangeResource(methodType, path, request,
- DEFAULT_HEADERS
- )
+ exchangeResource(methodType, path, request,
+ DEFAULT_HEADERS
+ )
override fun exchangeResource(
methodType: String,
@@ -317,7 +346,7 @@ class UatExecutor(
headers: Map<String, String>
): WebClientResponse<String> {
val requestDefinition =
- RequestDefinition(methodType, path, headers, toJson(request))
+ RequestDefinition(methodType, path, headers, toJson(request))
val realAnswer = realService.exchangeResource(methodType, path, request, headers)
val responseBody = when {
// TODO: confirm if we need to normalize the response here
@@ -325,12 +354,12 @@ class UatExecutor(
else -> null
}
val responseDefinition =
- ResponseDefinition(realAnswer.status, responseBody)
+ ResponseDefinition(realAnswer.status, responseBody)
expectations.add(
- ExpectationDefinition(
- requestDefinition,
- responseDefinition
- )
+ ExpectationDefinition(
+ requestDefinition,
+ responseDefinition
+ )
)
return realAnswer
}
@@ -340,7 +369,7 @@ class UatExecutor(
}
fun asServiceDefinition() =
- ServiceDefinition(selector, expectations)
+ ServiceDefinition(selector, expectations)
private fun toJson(str: String): JsonNode? {
return when {
@@ -351,8 +380,8 @@ class UatExecutor(
companion object {
private val DEFAULT_HEADERS = mapOf(
- HttpHeaders.CONTENT_TYPE to MediaType.APPLICATION_JSON_VALUE,
- HttpHeaders.ACCEPT to MediaType.APPLICATION_JSON_VALUE
+ HttpHeaders.CONTENT_TYPE to MediaType.APPLICATION_JSON_VALUE,
+ HttpHeaders.ACCEPT to MediaType.APPLICATION_JSON_VALUE
)
}
}
diff --git a/ms/blueprintsprocessor/application/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/utils/UatServices.kt b/ms/blueprintsprocessor/application/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/utils/UatServices.kt
index f40b903de..f40b903de 100644
--- a/ms/blueprintsprocessor/application/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/utils/UatServices.kt
+++ b/ms/blueprintsprocessor/application/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/utils/UatServices.kt
diff --git a/ms/blueprintsprocessor/application/src/main/resources/application-dev.properties b/ms/blueprintsprocessor/application/src/main/resources/application-dev.properties
index fffc2f4c6..5beebd8e8 100755
--- a/ms/blueprintsprocessor/application/src/main/resources/application-dev.properties
+++ b/ms/blueprintsprocessor/application/src/main/resources/application-dev.properties
@@ -27,6 +27,11 @@ server.port=8081
security.user.password: {bcrypt}$2a$10$duaUzVUVW0YPQCSIbGEkQOXwafZGwQ/b32/Ys4R1iwSSawFgz7QNu
security.user.name: ccsdkapps
+# Error Managements
+error.catalog.applicationId=cds
+error.catalog.type=properties
+error.catalog.errorDefinitionDir=./src/main/resources/
+
### START -Controller Blueprints Properties
# Load Resource Source Mappings
resourceSourceMappings=processor-db=source-db,input=source-input,default=source-default,sdnc=source-rest,aai-data=source-rest,capability=source-capability,vault-data=source-rest,rest=source-rest,script=source-capability
@@ -137,4 +142,4 @@ blueprintsprocessor.messageproducer.self-service-api.topic=producer.t
#blueprintsprocessor.messageconsumer.prioritize-input.type=kafka-streams-basic-auth
#blueprintsprocessor.messageconsumer.prioritize-input.bootstrapServers=127.0.0.1:9092
#blueprintsprocessor.messageconsumer.prioritize-input.applicationId=cds-controller
-#blueprintsprocessor.messageconsumer.prioritize-input.topic=prioritize-input-topic \ No newline at end of file
+#blueprintsprocessor.messageconsumer.prioritize-input.topic=prioritize-input-topic
diff --git a/ms/blueprintsprocessor/application/src/main/resources/application-local.yml b/ms/blueprintsprocessor/application/src/main/resources/application-local.yml
index de2cf4e52..f2843322c 100644
--- a/ms/blueprintsprocessor/application/src/main/resources/application-local.yml
+++ b/ms/blueprintsprocessor/application/src/main/resources/application-local.yml
@@ -38,10 +38,10 @@ blueprintsprocessor:
remoteScriptCommand:
enabled: true
restclient:
- sdncodl:
+ sdnc:
password: Kp8bJ4SXszM0WXlhak3eHlcse2gAw84vaoGGmJvUy2U
type: basic-auth
- url: http://localhost:8282/
+ url: http://localhost:8282
username: admin
restconfEnabled: true
controllerblueprints:
diff --git a/ms/blueprintsprocessor/application/src/main/resources/application.properties b/ms/blueprintsprocessor/application/src/main/resources/application.properties
index d6082bfa9..74549b0ae 100755
--- a/ms/blueprintsprocessor/application/src/main/resources/application.properties
+++ b/ms/blueprintsprocessor/application/src/main/resources/application.properties
@@ -60,6 +60,11 @@ blueprints.processor.functions.python.executor.modulePaths=/opt/app/onap/scripts
security.user.password: {bcrypt}$2a$10$duaUzVUVW0YPQCSIbGEkQOXwafZGwQ/b32/Ys4R1iwSSawFgz7QNu
security.user.name: ccsdkapps
+# Error Managements
+error.catalog.applicationId=cds
+error.catalog.type=properties
+error.catalog.errorDefinitionDir=/opt/app/onap/config/
+
# Used in Health Check
#endpoints.user.name=ccsdkapps
#endpoints.user.password=ccsdkapps
@@ -130,5 +135,4 @@ cdslistener.healthcheck.mapping-service-name-with-service-link=[SDC Listener ser
#Actuator properties
management.endpoints.web.exposure.include=*
management.endpoint.health.show-details=always
-
-
+management.info.git.mode=full
diff --git a/ms/blueprintsprocessor/application/src/main/resources/error-messages_en.properties b/ms/blueprintsprocessor/application/src/main/resources/error-messages_en.properties
new file mode 100644
index 000000000..71196ce16
--- /dev/null
+++ b/ms/blueprintsprocessor/application/src/main/resources/error-messages_en.properties
@@ -0,0 +1,91 @@
+#
+# Copyright © 2020 IBM, Bell Canada
+#
+# 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.
+#
+org.onap.ccsdk.cds.blueprintsprocessor.generic_failure=cause=Internal error in Blueprint Processor run time.,action=Contact CDS administrator team.
+org.onap.ccsdk.cds.blueprintsprocessor.resource_path_missing=cause=Resource path missing or wrong.,action=Please reload your artifact in run time.
+org.onap.ccsdk.cds.blueprintsprocessor.resource_writing_fail=cause=Fail to write resources files.,action=Please reload your files and make sure it is in the right format.
+org.onap.ccsdk.cds.blueprintsprocessor.io_file_interrupt=cause=IO file system interruption.,action=Please reload your file and make sure it is in the right format.
+org.onap.ccsdk.cds.blueprintsprocessor.invalid_request_format=cause=bad request provided.,action=Verify the request payload.
+org.onap.ccsdk.cds.blueprintsprocessor.unauthorized_request=cause=The request requires user authentication.,action=Please provide the right credentials.
+org.onap.ccsdk.cds.blueprintsprocessor.request_not_found=cause=Request mapping doesn't exist.,action=Please verify your request.
+org.onap.ccsdk.cds.blueprintsprocessor.conflict_adding_resource=cause=Duplicated entry while saving resource.,action=Please make the saving model doesn't exist.
+org.onap.ccsdk.cds.blueprintsprocessor.duplicate_data=cause=Duplicated data - was expecting one result, got more than one.,action=Please provide single resource at a time.
+org.onap.ccsdk.cds.blueprintsprocessor.resource_not_found=cause=No response was found for this request in the server.,action=Provide the ID to find the resource.
+org.onap.ccsdk.cds.blueprintsprocessor.unsupported_media_type=cause=An invalid media was provided.,action=Please make sure your media or artifact is in the proper structure or format.
+
+# Self Service API
+org.onap.ccsdk.cds.blueprintsprocessor.selfservice.api.generic_failure=cause=Internal error in Self Service API.,action=Verify the request and try again.
+org.onap.ccsdk.cds.blueprintsprocessor.selfservice.api.generic_process_failure=cause=Internal error while processing REST call to the Self Service API.,action=Verify the request and try again.
+org.onap.ccsdk.cds.blueprintsprocessor.selfservice.api.invalid_file_extension=cause=Failed trying to upload a non ZIP file format.,action=Please reload your file and make sure it is in ZIP format.
+org.onap.ccsdk.cds.blueprintsprocessor.selfservice.api.resource_path_missing=cause=Resource path missing or wrong.,action=Please reload your artifact in run time.
+org.onap.ccsdk.cds.blueprintsprocessor.selfservice.api.resource_writing_fail=cause=Fail to write resources files.,action=Please reload your files and make sure it is in the right format.
+org.onap.ccsdk.cds.blueprintsprocessor.selfservice.api.io_file_interrupt=cause=IO file system interruption.,action=Please reload your file and make sure it is in the right format.
+org.onap.ccsdk.cds.blueprintsprocessor.selfservice.api.invalid_request_format=cause=bad request provided.,action=Verify the request payload.
+org.onap.ccsdk.cds.blueprintsprocessor.selfservice.api.unauthorized_request=cause=The request requires user authentication.,action=Please provide the right credentials.
+org.onap.ccsdk.cds.blueprintsprocessor.selfservice.api.request_not_found=cause=Request mapping doesn't exist.,action=Please verify your request.
+org.onap.ccsdk.cds.blueprintsprocessor.selfservice.api.conflict_adding_resource=cause=Duplicated entry while saving resource.,action=Please make the saving model doesn't exist.
+org.onap.ccsdk.cds.blueprintsprocessor.selfservice.api.duplicate_data=cause=Duplicated data - was expecting one result, got more than one.,action=Please provide single resource at a time.
+org.onap.ccsdk.cds.blueprintsprocessor.selfservice.api.resource_not_found=cause=No response was found for this request in the server.,action=Provide the ID to find the resource.
+org.onap.ccsdk.cds.blueprintsprocessor.selfservice.api.unsupported_media_type=cause=An invalid media was provided.,action=Please make sure your media or artifact is in the proper structure or format.
+
+# Designer API
+org.onap.ccsdk.cds.blueprintsprocessor.designer.api.generic_failure=cause=Internal error while processing REST call to the Designer API.,action=Verify the request and try again.
+org.onap.ccsdk.cds.blueprintsprocessor.designer.api.invalid_file_extension=cause=Failed trying to upload a non ZIP file format.,action=Please reload your file and make sure it is in ZIP format.
+org.onap.ccsdk.cds.blueprintsprocessor.designer.api.resource_path_missing=cause=Resource path missing or wrong.,action=Please reload your artifact in run time.
+org.onap.ccsdk.cds.blueprintsprocessor.designer.api.resource_writing_fail=cause=Fail to write resources files.,action=Please reload your files and make sure it is in the right format.
+org.onap.ccsdk.cds.blueprintsprocessor.designer.api.io_file_interrupt=cause=IO file system interruption.,action=Please reload your file and make sure it is in the right format.
+org.onap.ccsdk.cds.blueprintsprocessor.designer.api.invalid_request_format=cause=bad request provided.,action=Verify the request payload.
+org.onap.ccsdk.cds.blueprintsprocessor.designer.api.unauthorized_request=cause=The request requires user authentication.,action=Please provide the right credentials.
+org.onap.ccsdk.cds.blueprintsprocessor.designer.api.request_not_found=cause=Request mapping doesn't exist.,action=Please verify your request.
+org.onap.ccsdk.cds.blueprintsprocessor.designer.api.conflict_adding_resource=cause=Duplicated entry while saving resource.,action=Please make the saving model doesn't exist.
+org.onap.ccsdk.cds.blueprintsprocessor.designer.api.duplicate_data=cause=Duplicated data - was expecting one result, got more than one.,action=Please provide single resource at a time.
+org.onap.ccsdk.cds.blueprintsprocessor.designer.api.resource_not_found=cause=No response was found for this request in the server.,action=Provide the ID to find the resource.
+org.onap.ccsdk.cds.blueprintsprocessor.designer.api.unsupported_media_type=cause=An invalid media was provided.,action=Please make sure your media or artifact is in the proper structure or format.
+
+# Resource API
+org.onap.ccsdk.cds.blueprintsprocessor.resource.api.generic_failure=cause=Internal error while processing REST call to the Resource API.,action=Verify the request and try again.
+org.onap.ccsdk.cds.blueprintsprocessor.resource.api.invalid_file_extension=cause=Failed trying to upload a non ZIP file format.,action=Please reload your file and make sure it is in ZIP format.
+org.onap.ccsdk.cds.blueprintsprocessor.resource.api.resource_path_missing=cause=Resource path missing or wrong.,action=Please reload your artifact in run time.
+org.onap.ccsdk.cds.blueprintsprocessor.resource.api.resource_writing_fail=cause=Fail to write resources files.,action=Please reload your files and make sure it is in the right format.
+org.onap.ccsdk.cds.blueprintsprocessor.resource.api.io_file_interrupt=cause=IO file system interruption.,action=Please reload your file and make sure it is in the right format.
+org.onap.ccsdk.cds.blueprintsprocessor.resource.api.invalid_request_format=cause=bad request provided.,action=Verify the request payload.
+org.onap.ccsdk.cds.blueprintsprocessor.resource.api.unauthorized_request=cause=The request requires user authentication.,action=Please provide the right credentials.
+org.onap.ccsdk.cds.blueprintsprocessor.resource.api.request_not_found=cause=Request mapping doesn't exist.,action=Please verify your request.
+org.onap.ccsdk.cds.blueprintsprocessor.resource.api.conflict_adding_resource=cause=Duplicated entry while saving resource.,action=Please make the saving model doesn't exist.
+org.onap.ccsdk.cds.blueprintsprocessor.resource.api.duplicate_data=cause=Duplicated data - was expecting one result, got more than one.,action=Please provide single resource at a time.
+org.onap.ccsdk.cds.blueprintsprocessor.resource.api.resource_not_found=cause=No response was found for this request in the server.,action=Provide the ID to find the resource.
+org.onap.ccsdk.cds.blueprintsprocessor.resource.api.unsupported_media_type=cause=An invalid media was provided.,action=Please make sure your media or artifact is in the proper structure or format.
+
+
+# Configs API
+org.onap.ccsdk.cds.blueprintsprocessor.configs.api.generic_failure=cause=Internal error while processing REST call to the Configs API.,action=Verify the request and try again.
+org.onap.ccsdk.cds.blueprintsprocessor.configs.api.resource_path_missing=cause=Resource path missing or wrong.,action=Please reload your artifact in run time.
+org.onap.ccsdk.cds.blueprintsprocessor.configs.api.io_file_interrupt=cause=IO file system interruption.,action=Please reload your file and make sure it is in the right format.
+org.onap.ccsdk.cds.blueprintsprocessor.configs.api.invalid_request_format=cause=bad request provided.,action=Verify the request payload.
+org.onap.ccsdk.cds.blueprintsprocessor.configs.api.unauthorized_request=cause=The request requires user authentication.,action=Please provide the right credentials.
+org.onap.ccsdk.cds.blueprintsprocessor.configs.api.request_not_found=cause=Request mapping doesn't exist.,action=Please verify your request.
+org.onap.ccsdk.cds.blueprintsprocessor.configs.api.conflict_adding_resource=cause=Duplicated entry while saving resource.,action=Please make the saving model doesn't exist.
+org.onap.ccsdk.cds.blueprintsprocessor.configs.api.duplicate_data=cause=Duplicated data - was expecting one result, got more than one.,action=Please provide single resource at a time.
+org.onap.ccsdk.cds.blueprintsprocessor.configs.api.resource_not_found=cause=No response was found for this request in the server.,action=Provide the ID to find the resource.
+
+# Python Executor
+org.onap.ccsdk.cds.blueprintsprocessor.functions.python.executor.generic_failure=cause=Internal error in Blueprint Processor run time.,action=Contact CDS administrator team.
+
+# Resource resolution
+org.onap.ccsdk.cds.blueprintsprocessor.resource.resolution.invalid_request_format=cause=bad request provided.,action=Verify the request payload.
+org.onap.ccsdk.cds.blueprintsprocessor.resource.resolution.resource_not_found=cause=No response was found for this resolution in CDS.,action=Verify definition of the resource in CBA.
+org.onap.ccsdk.cds.blueprintsprocessor.resource.resolution.internal_error=cause=Internal error while processing Resource Resolution.,action=Verify the payload.
+
+org.onap.ccsdk.cds.sdclistener.generic_failure=cause=Internal error in SDC Listener.,action=Contact CDS administrator team.
diff --git a/ms/blueprintsprocessor/application/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/ErrorCatalogTestConfiguration.kt b/ms/blueprintsprocessor/application/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/ErrorCatalogTestConfiguration.kt
new file mode 100644
index 000000000..c9d55c18a
--- /dev/null
+++ b/ms/blueprintsprocessor/application/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/ErrorCatalogTestConfiguration.kt
@@ -0,0 +1,28 @@
+/*
+ * Copyright © 2020 IBM, Bell Canada.
+ *
+ * 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.uat
+
+import org.springframework.boot.autoconfigure.EnableAutoConfiguration
+import org.springframework.context.annotation.ComponentScan
+import org.springframework.context.annotation.Configuration
+
+@Configuration
+@ComponentScan(
+ basePackages = ["org.onap.ccsdk.cds.error.catalog"]
+)
+@EnableAutoConfiguration
+open class ErrorCatalogTestConfiguration
diff --git a/ms/blueprintsprocessor/application/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/UatServicesTest.kt b/ms/blueprintsprocessor/application/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/UatServicesTest.kt
index aebda8c07..4e7d4ce40 100644
--- a/ms/blueprintsprocessor/application/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/UatServicesTest.kt
+++ b/ms/blueprintsprocessor/application/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/UatServicesTest.kt
@@ -30,6 +30,8 @@ import com.github.tomakehurst.wiremock.client.WireMock.equalToJson
import com.github.tomakehurst.wiremock.client.WireMock.request
import com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo
import com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig
+import com.github.tomakehurst.wiremock.http.HttpHeader
+import com.github.tomakehurst.wiremock.http.HttpHeaders
import org.apache.http.HttpStatus
import org.apache.http.client.methods.HttpPost
import org.apache.http.entity.ContentType
@@ -55,8 +57,6 @@ import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.web.server.LocalServerPort
import org.springframework.core.env.ConfigurableEnvironment
import org.springframework.core.env.MapPropertySource
-import org.springframework.http.HttpHeaders
-import org.springframework.http.MediaType
import org.springframework.test.context.ActiveProfiles
import org.springframework.test.context.support.TestPropertySourceUtils.INLINED_PROPERTIES_PROPERTY_SOURCE_NAME
import org.yaml.snakeyaml.Yaml
@@ -211,7 +211,6 @@ class UatServicesTest : BaseUatTest() {
service.expectations.forEach { expectation ->
val request = expectation.request
- val response = expectation.response
// WebTestClient always use absolute path, prefixing with "/" if necessary
val urlPattern = urlEqualTo(request.path.prefixIfNot("/"))
val mappingBuilder: MappingBuilder = request(request.method, urlPattern)
@@ -222,15 +221,19 @@ class UatServicesTest : BaseUatTest() {
mappingBuilder.withRequestBody(equalToJson(mapper.writeValueAsString(request.body), true, true))
}
- val responseDefinitionBuilder: ResponseDefinitionBuilder = aResponse()
- .withStatus(response.status)
- if (response.body != null) {
- responseDefinitionBuilder.withBody(mapper.writeValueAsBytes(response.body))
- .withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE)
+ for (response in expectation.responses) {
+ val responseDefinitionBuilder: ResponseDefinitionBuilder = aResponse()
+ .withStatus(response.status)
+ if (response.body != null) {
+ responseDefinitionBuilder.withBody(mapper.writeValueAsBytes(response.body))
+ .withHeaders(HttpHeaders(
+ response.headers.entries.map { e -> HttpHeader(e.key, e.value) }))
+ }
+
+ // TODO: MockServer verification for multiple responses should be done using Wiremock scenarios
+ mappingBuilder.willReturn(responseDefinitionBuilder)
}
- mappingBuilder.willReturn(responseDefinitionBuilder)
-
mockServer.stubFor(mappingBuilder)
}
return mockServer
diff --git a/ms/blueprintsprocessor/application/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/error/ErrorCatalogServiceTest.kt b/ms/blueprintsprocessor/application/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/error/ErrorCatalogServiceTest.kt
new file mode 100644
index 000000000..4f7ef0ec2
--- /dev/null
+++ b/ms/blueprintsprocessor/application/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/error/ErrorCatalogServiceTest.kt
@@ -0,0 +1,97 @@
+/*
+ * Copyright © 2020 IBM, Bell Canada.
+ *
+ * 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.uat.error
+
+import org.junit.runner.RunWith
+import org.onap.ccsdk.cds.blueprintsprocessor.uat.ErrorCatalogTestConfiguration
+import org.onap.ccsdk.cds.controllerblueprints.core.grpcProcessorException
+import org.onap.ccsdk.cds.controllerblueprints.core.httpProcessorException
+import org.onap.ccsdk.cds.error.catalog.core.ErrorCatalog
+import org.onap.ccsdk.cds.error.catalog.core.ErrorCatalogCodes
+import org.onap.ccsdk.cds.error.catalog.core.ErrorMessage
+import org.onap.ccsdk.cds.error.catalog.core.ErrorPayload
+import org.onap.ccsdk.cds.error.catalog.services.ErrorCatalogService
+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
+import kotlin.test.BeforeTest
+import kotlin.test.Test
+import kotlin.test.assertTrue
+
+@RunWith(SpringRunner::class)
+@ContextConfiguration(
+ classes = [ErrorCatalogTestConfiguration::class]
+)
+@TestPropertySource(locations = ["classpath:application-test.properties"])
+class ErrorCatalogServiceTest {
+ @Autowired
+ lateinit var errorCatalogService: ErrorCatalogService
+
+ private val domain = "org.onap.ccsdk.cds.blueprintsprocessor"
+ private lateinit var errorType: String
+ private lateinit var errorCatalogHttp: ErrorCatalog
+ private lateinit var errorCatalogGrpc: ErrorCatalog
+ private lateinit var errorPayloadHttp: ErrorPayload
+ private lateinit var errorPayloadGrpc: ErrorPayload
+
+ @BeforeTest
+ fun setup() {
+ errorType = ErrorCatalogCodes.GENERIC_FAILURE
+ errorCatalogHttp = ErrorCatalog(errorType, domain, 500,
+ "Contact CDS administrator team.", "Internal error in Blueprint Processor run time.")
+ errorCatalogGrpc = ErrorCatalog(errorType, domain, 2,
+ "Contact CDS administrator team.", "Internal error in Blueprint Processor run time.")
+
+ errorPayloadHttp = ErrorPayload(500, ErrorCatalogCodes.GENERIC_FAILURE,
+ "Cause: Internal error in Blueprint Processor run time. \n Action : Contact CDS administrator team.",
+ errorMessage = ErrorMessage("org.onap.ccsdk.cds.blueprintsprocessor",
+ "Internal error in Blueprint Processor run time.", ""))
+ errorPayloadGrpc = ErrorPayload(2, ErrorCatalogCodes.GENERIC_FAILURE,
+ "Cause: Internal error in Blueprint Processor run time. \n Action : Contact CDS administrator team.",
+ errorMessage = ErrorMessage("org.onap.ccsdk.cds.blueprintsprocessor",
+ "Internal error in Blueprint Processor run time.", ""))
+ }
+
+ @Test
+ fun errorPayloadHttp() {
+ val errorPayload = errorCatalogService.errorPayload(httpProcessorException(errorType, domain,
+ "Internal error in Blueprint Processor run time."))
+ assertTrue { errorPayload.isEqualTo(errorPayloadHttp) }
+ }
+
+ @Test
+ fun errorPayloadGrpc() {
+ val errorPayload = errorCatalogService.errorPayload(grpcProcessorException(errorType, domain,
+ "Internal error in Blueprint Processor run time."))
+ assertTrue { errorPayload.isEqualTo(errorPayloadGrpc) }
+ }
+
+ @Test
+ fun getErrorCatalogHttp() {
+ val errorCatalog = errorCatalogService.getErrorCatalog(httpProcessorException(errorType, domain,
+ "Internal error in Blueprint Processor run time."))
+ assertTrue { errorCatalog == errorCatalogHttp }
+ }
+
+ @Test
+ fun getErrorCatalogGrpc() {
+ val errorCatalog = errorCatalogService.getErrorCatalog(grpcProcessorException(errorType, domain,
+ "Internal error in Blueprint Processor run time."))
+ assertTrue { errorCatalog == errorCatalogGrpc }
+ }
+}
diff --git a/ms/blueprintsprocessor/application/src/test/resources/application-test.properties b/ms/blueprintsprocessor/application/src/test/resources/application-test.properties
index 1d2565be3..d2170c7c1 100644
--- a/ms/blueprintsprocessor/application/src/test/resources/application-test.properties
+++ b/ms/blueprintsprocessor/application/src/test/resources/application-test.properties
@@ -16,6 +16,11 @@
spring.http.log-request-details=true
+# Error Managements
+error.catalog.applicationId=cds
+error.catalog.type=properties
+error.catalog.errorDefinitionDir=./src/test/resources/
+
blueprintsprocessor.httpPort=0
blueprintsprocessor.grpcEnable=true
blueprintsprocessor.grpcPort=0
@@ -61,4 +66,3 @@ blueprintprocessor.healthcheck.mapping-service-name-with-service-link=[Execution
#BaseUrls for health check Cds Listener services
cdslistener.healthcheck.baseUrl=http://cds-sdc-listener:8080/
cdslistener.healthcheck.mapping-service-name-with-service-link=[SDC Listener service,/api/v1/sdclistener/healthcheck]
-
diff --git a/ms/blueprintsprocessor/application/src/test/resources/application.properties b/ms/blueprintsprocessor/application/src/test/resources/application.properties
index ea14c493a..cb3419397 100644
--- a/ms/blueprintsprocessor/application/src/test/resources/application.properties
+++ b/ms/blueprintsprocessor/application/src/test/resources/application.properties
@@ -61,6 +61,11 @@ blueprints.processor.functions.python.executor.modulePaths=/opt/app/onap/scripts
security.user.password:{bcrypt}$2a$10$duaUzVUVW0YPQCSIbGEkQOXwafZGwQ/b32/Ys4R1iwSSawFgz7QNu
security.user.name:ccsdkapps
+# Error Managements
+error.catalog.applicationId=cds
+error.catalog.type=properties
+error.catalog.errorDefinitionDir=./src/test/resources/
+
# Executor Options
blueprintsprocessor.resourceResolution.enabled=true
blueprintsprocessor.netconfExecutor.enabled=true
diff --git a/ms/blueprintsprocessor/application/src/test/resources/error-messages_en.properties b/ms/blueprintsprocessor/application/src/test/resources/error-messages_en.properties
new file mode 100644
index 000000000..71196ce16
--- /dev/null
+++ b/ms/blueprintsprocessor/application/src/test/resources/error-messages_en.properties
@@ -0,0 +1,91 @@
+#
+# Copyright © 2020 IBM, Bell Canada
+#
+# 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.
+#
+org.onap.ccsdk.cds.blueprintsprocessor.generic_failure=cause=Internal error in Blueprint Processor run time.,action=Contact CDS administrator team.
+org.onap.ccsdk.cds.blueprintsprocessor.resource_path_missing=cause=Resource path missing or wrong.,action=Please reload your artifact in run time.
+org.onap.ccsdk.cds.blueprintsprocessor.resource_writing_fail=cause=Fail to write resources files.,action=Please reload your files and make sure it is in the right format.
+org.onap.ccsdk.cds.blueprintsprocessor.io_file_interrupt=cause=IO file system interruption.,action=Please reload your file and make sure it is in the right format.
+org.onap.ccsdk.cds.blueprintsprocessor.invalid_request_format=cause=bad request provided.,action=Verify the request payload.
+org.onap.ccsdk.cds.blueprintsprocessor.unauthorized_request=cause=The request requires user authentication.,action=Please provide the right credentials.
+org.onap.ccsdk.cds.blueprintsprocessor.request_not_found=cause=Request mapping doesn't exist.,action=Please verify your request.
+org.onap.ccsdk.cds.blueprintsprocessor.conflict_adding_resource=cause=Duplicated entry while saving resource.,action=Please make the saving model doesn't exist.
+org.onap.ccsdk.cds.blueprintsprocessor.duplicate_data=cause=Duplicated data - was expecting one result, got more than one.,action=Please provide single resource at a time.
+org.onap.ccsdk.cds.blueprintsprocessor.resource_not_found=cause=No response was found for this request in the server.,action=Provide the ID to find the resource.
+org.onap.ccsdk.cds.blueprintsprocessor.unsupported_media_type=cause=An invalid media was provided.,action=Please make sure your media or artifact is in the proper structure or format.
+
+# Self Service API
+org.onap.ccsdk.cds.blueprintsprocessor.selfservice.api.generic_failure=cause=Internal error in Self Service API.,action=Verify the request and try again.
+org.onap.ccsdk.cds.blueprintsprocessor.selfservice.api.generic_process_failure=cause=Internal error while processing REST call to the Self Service API.,action=Verify the request and try again.
+org.onap.ccsdk.cds.blueprintsprocessor.selfservice.api.invalid_file_extension=cause=Failed trying to upload a non ZIP file format.,action=Please reload your file and make sure it is in ZIP format.
+org.onap.ccsdk.cds.blueprintsprocessor.selfservice.api.resource_path_missing=cause=Resource path missing or wrong.,action=Please reload your artifact in run time.
+org.onap.ccsdk.cds.blueprintsprocessor.selfservice.api.resource_writing_fail=cause=Fail to write resources files.,action=Please reload your files and make sure it is in the right format.
+org.onap.ccsdk.cds.blueprintsprocessor.selfservice.api.io_file_interrupt=cause=IO file system interruption.,action=Please reload your file and make sure it is in the right format.
+org.onap.ccsdk.cds.blueprintsprocessor.selfservice.api.invalid_request_format=cause=bad request provided.,action=Verify the request payload.
+org.onap.ccsdk.cds.blueprintsprocessor.selfservice.api.unauthorized_request=cause=The request requires user authentication.,action=Please provide the right credentials.
+org.onap.ccsdk.cds.blueprintsprocessor.selfservice.api.request_not_found=cause=Request mapping doesn't exist.,action=Please verify your request.
+org.onap.ccsdk.cds.blueprintsprocessor.selfservice.api.conflict_adding_resource=cause=Duplicated entry while saving resource.,action=Please make the saving model doesn't exist.
+org.onap.ccsdk.cds.blueprintsprocessor.selfservice.api.duplicate_data=cause=Duplicated data - was expecting one result, got more than one.,action=Please provide single resource at a time.
+org.onap.ccsdk.cds.blueprintsprocessor.selfservice.api.resource_not_found=cause=No response was found for this request in the server.,action=Provide the ID to find the resource.
+org.onap.ccsdk.cds.blueprintsprocessor.selfservice.api.unsupported_media_type=cause=An invalid media was provided.,action=Please make sure your media or artifact is in the proper structure or format.
+
+# Designer API
+org.onap.ccsdk.cds.blueprintsprocessor.designer.api.generic_failure=cause=Internal error while processing REST call to the Designer API.,action=Verify the request and try again.
+org.onap.ccsdk.cds.blueprintsprocessor.designer.api.invalid_file_extension=cause=Failed trying to upload a non ZIP file format.,action=Please reload your file and make sure it is in ZIP format.
+org.onap.ccsdk.cds.blueprintsprocessor.designer.api.resource_path_missing=cause=Resource path missing or wrong.,action=Please reload your artifact in run time.
+org.onap.ccsdk.cds.blueprintsprocessor.designer.api.resource_writing_fail=cause=Fail to write resources files.,action=Please reload your files and make sure it is in the right format.
+org.onap.ccsdk.cds.blueprintsprocessor.designer.api.io_file_interrupt=cause=IO file system interruption.,action=Please reload your file and make sure it is in the right format.
+org.onap.ccsdk.cds.blueprintsprocessor.designer.api.invalid_request_format=cause=bad request provided.,action=Verify the request payload.
+org.onap.ccsdk.cds.blueprintsprocessor.designer.api.unauthorized_request=cause=The request requires user authentication.,action=Please provide the right credentials.
+org.onap.ccsdk.cds.blueprintsprocessor.designer.api.request_not_found=cause=Request mapping doesn't exist.,action=Please verify your request.
+org.onap.ccsdk.cds.blueprintsprocessor.designer.api.conflict_adding_resource=cause=Duplicated entry while saving resource.,action=Please make the saving model doesn't exist.
+org.onap.ccsdk.cds.blueprintsprocessor.designer.api.duplicate_data=cause=Duplicated data - was expecting one result, got more than one.,action=Please provide single resource at a time.
+org.onap.ccsdk.cds.blueprintsprocessor.designer.api.resource_not_found=cause=No response was found for this request in the server.,action=Provide the ID to find the resource.
+org.onap.ccsdk.cds.blueprintsprocessor.designer.api.unsupported_media_type=cause=An invalid media was provided.,action=Please make sure your media or artifact is in the proper structure or format.
+
+# Resource API
+org.onap.ccsdk.cds.blueprintsprocessor.resource.api.generic_failure=cause=Internal error while processing REST call to the Resource API.,action=Verify the request and try again.
+org.onap.ccsdk.cds.blueprintsprocessor.resource.api.invalid_file_extension=cause=Failed trying to upload a non ZIP file format.,action=Please reload your file and make sure it is in ZIP format.
+org.onap.ccsdk.cds.blueprintsprocessor.resource.api.resource_path_missing=cause=Resource path missing or wrong.,action=Please reload your artifact in run time.
+org.onap.ccsdk.cds.blueprintsprocessor.resource.api.resource_writing_fail=cause=Fail to write resources files.,action=Please reload your files and make sure it is in the right format.
+org.onap.ccsdk.cds.blueprintsprocessor.resource.api.io_file_interrupt=cause=IO file system interruption.,action=Please reload your file and make sure it is in the right format.
+org.onap.ccsdk.cds.blueprintsprocessor.resource.api.invalid_request_format=cause=bad request provided.,action=Verify the request payload.
+org.onap.ccsdk.cds.blueprintsprocessor.resource.api.unauthorized_request=cause=The request requires user authentication.,action=Please provide the right credentials.
+org.onap.ccsdk.cds.blueprintsprocessor.resource.api.request_not_found=cause=Request mapping doesn't exist.,action=Please verify your request.
+org.onap.ccsdk.cds.blueprintsprocessor.resource.api.conflict_adding_resource=cause=Duplicated entry while saving resource.,action=Please make the saving model doesn't exist.
+org.onap.ccsdk.cds.blueprintsprocessor.resource.api.duplicate_data=cause=Duplicated data - was expecting one result, got more than one.,action=Please provide single resource at a time.
+org.onap.ccsdk.cds.blueprintsprocessor.resource.api.resource_not_found=cause=No response was found for this request in the server.,action=Provide the ID to find the resource.
+org.onap.ccsdk.cds.blueprintsprocessor.resource.api.unsupported_media_type=cause=An invalid media was provided.,action=Please make sure your media or artifact is in the proper structure or format.
+
+
+# Configs API
+org.onap.ccsdk.cds.blueprintsprocessor.configs.api.generic_failure=cause=Internal error while processing REST call to the Configs API.,action=Verify the request and try again.
+org.onap.ccsdk.cds.blueprintsprocessor.configs.api.resource_path_missing=cause=Resource path missing or wrong.,action=Please reload your artifact in run time.
+org.onap.ccsdk.cds.blueprintsprocessor.configs.api.io_file_interrupt=cause=IO file system interruption.,action=Please reload your file and make sure it is in the right format.
+org.onap.ccsdk.cds.blueprintsprocessor.configs.api.invalid_request_format=cause=bad request provided.,action=Verify the request payload.
+org.onap.ccsdk.cds.blueprintsprocessor.configs.api.unauthorized_request=cause=The request requires user authentication.,action=Please provide the right credentials.
+org.onap.ccsdk.cds.blueprintsprocessor.configs.api.request_not_found=cause=Request mapping doesn't exist.,action=Please verify your request.
+org.onap.ccsdk.cds.blueprintsprocessor.configs.api.conflict_adding_resource=cause=Duplicated entry while saving resource.,action=Please make the saving model doesn't exist.
+org.onap.ccsdk.cds.blueprintsprocessor.configs.api.duplicate_data=cause=Duplicated data - was expecting one result, got more than one.,action=Please provide single resource at a time.
+org.onap.ccsdk.cds.blueprintsprocessor.configs.api.resource_not_found=cause=No response was found for this request in the server.,action=Provide the ID to find the resource.
+
+# Python Executor
+org.onap.ccsdk.cds.blueprintsprocessor.functions.python.executor.generic_failure=cause=Internal error in Blueprint Processor run time.,action=Contact CDS administrator team.
+
+# Resource resolution
+org.onap.ccsdk.cds.blueprintsprocessor.resource.resolution.invalid_request_format=cause=bad request provided.,action=Verify the request payload.
+org.onap.ccsdk.cds.blueprintsprocessor.resource.resolution.resource_not_found=cause=No response was found for this resolution in CDS.,action=Verify definition of the resource in CBA.
+org.onap.ccsdk.cds.blueprintsprocessor.resource.resolution.internal_error=cause=Internal error while processing Resource Resolution.,action=Verify the payload.
+
+org.onap.ccsdk.cds.sdclistener.generic_failure=cause=Internal error in SDC Listener.,action=Contact CDS administrator team.
diff --git a/ms/blueprintsprocessor/functions/message-prioritizaion/pom.xml b/ms/blueprintsprocessor/functions/message-prioritizaion/pom.xml
index ac46b3635..c7dbaf174 100644
--- a/ms/blueprintsprocessor/functions/message-prioritizaion/pom.xml
+++ b/ms/blueprintsprocessor/functions/message-prioritizaion/pom.xml
@@ -14,7 +14,6 @@
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
-
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
diff --git a/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/ComponentNetconfExecutor.kt b/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/ComponentNetconfExecutor.kt
index 1262e8500..307e73e6b 100644
--- a/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/ComponentNetconfExecutor.kt
+++ b/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/ComponentNetconfExecutor.kt
@@ -65,6 +65,9 @@ open class ComponentNetconfExecutor(private var componentFunctionScriptingServic
// Handles both script processing and error handling
scriptComponent.executeScript(executionServiceInput)
+
+ componentFunctionScriptingService.cleanupInstance(bluePrintRuntimeService.bluePrintContext(),
+ scriptType)
}
override suspend fun recoverNB(runtimeException: RuntimeException, executionRequest: ExecutionServiceInput) {
diff --git a/ms/blueprintsprocessor/functions/pom.xml b/ms/blueprintsprocessor/functions/pom.xml
index abd186bcf..3097c1b98 100755
--- a/ms/blueprintsprocessor/functions/pom.xml
+++ b/ms/blueprintsprocessor/functions/pom.xml
@@ -33,7 +33,7 @@
<modules>
<module>resource-resolution</module>
- <module>nrm-restful</module>
+ <module>restful-executor</module>
<module>ansible-awx-executor</module>
<module>python-executor</module>
<module>netconf-executor</module>
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 db0a6f0ed..3c95ea7bb 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
@@ -43,6 +43,7 @@ open class ResourceResolutionComponent(private val resourceResolutionService: Re
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_RESOLUTION_SUMMARY = "resolution-summary"
const val INPUT_STORE_RESULT = "store-result"
const val INPUT_OCCURRENCE = "occurrence"
@@ -64,6 +65,8 @@ open class ResourceResolutionComponent(private val resourceResolutionService: Re
val resourceType =
getOptionalOperationInput(ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_RESOURCE_TYPE)?.returnNullIfMissing()?.textValue() ?: ""
+ val resolutionSummary =
+ getOptionalOperationInput(ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_RESOLUTION_SUMMARY)?.asBoolean() ?: false
val properties: MutableMap<String, Any> = mutableMapOf()
properties[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_STORE_RESULT] = storeResult
@@ -71,6 +74,7 @@ open class ResourceResolutionComponent(private val resourceResolutionService: Re
properties[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_RESOURCE_ID] = resourceId
properties[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_RESOURCE_TYPE] = resourceType
properties[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_OCCURRENCE] = occurrence
+ properties[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_RESOLUTION_SUMMARY] = resolutionSummary
val jsonResponse = JsonNodeFactory.instance.objectNode()
// Initialize Output Attribute to empty JSON
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
index 6573d0e9a..fd104d3ad 100644
--- 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
@@ -82,6 +82,11 @@ fun BluePrintTypes.nodeTypeComponentResourceResolution(): NodeType {
)
property(
+ ResourceResolutionComponent.INPUT_RESOLUTION_SUMMARY, BluePrintConstants.DATA_TYPE_BOOLEAN,
+ false, "Enables ResolutionSummary output"
+ )
+
+ property(
ResourceResolutionComponent.INPUT_OCCURRENCE, BluePrintConstants.DATA_TYPE_INTEGER,
false, "Number of time to perform the resolution."
) {
@@ -176,6 +181,12 @@ class ComponentResourceResolutionNodeTemplateBuilder(id: String, description: St
property(ResourceResolutionComponent.INPUT_RESOLUTION_KEY, resolutionKey)
}
+ fun resolutionSummary(resolutionSummary: Boolean) = resolutionSummary(resolutionSummary.asJsonPrimitive())
+
+ fun resolutionSummary(resolutionSummary: JsonNode) {
+ property(ResourceResolutionComponent.INPUT_RESOLUTION_SUMMARY, resolutionSummary)
+ }
+
fun dynamicProperties(dynamicProperties: String) = dynamicProperties(dynamicProperties.asJsonType())
fun dynamicProperties(dynamicProperties: JsonNode) {
diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceResolutionConstants.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceResolutionConstants.kt
index c39933dc8..8f6069160 100644
--- a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceResolutionConstants.kt
+++ b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceResolutionConstants.kt
@@ -29,4 +29,5 @@ object ResourceResolutionConstants {
const val RESOURCE_RESOLUTION_INPUT_OCCURRENCE = "occurrence"
const val RESOURCE_RESOLUTION_INPUT_RESOURCE_ID = "resource-id"
const val RESOURCE_RESOLUTION_INPUT_RESOURCE_TYPE = "resource-type"
+ const val RESOURCE_RESOLUTION_INPUT_RESOLUTION_SUMMARY = "resolution-summary"
}
diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceResolutionService.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceResolutionService.kt
index 7272a3d63..dff00c7eb 100644
--- a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceResolutionService.kt
+++ b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceResolutionService.kt
@@ -147,7 +147,7 @@ open class ResourceResolutionServiceImpl(
properties: Map<String, Any>
): String {
- // Velocity Artifact Definition Name
+ // Template Artifact Definition Name
val artifactTemplate = "$artifactPrefix-template"
// Resource Assignment Artifact Definition Name
val artifactMapping = "$artifactPrefix-mapping"
@@ -185,22 +185,28 @@ open class ResourceResolutionServiceImpl(
properties
)
+ val resolutionSummary = properties.getOrDefault(ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_RESOLUTION_SUMMARY, false) as Boolean
val resolvedParamJsonContent =
ResourceAssignmentUtils.generateResourceDataForAssignments(resourceAssignments.toList())
-
val artifactTemplateDefinition = bluePrintRuntimeService.bluePrintContext().checkNodeTemplateArtifact(nodeTemplateName, artifactTemplate)
- val resolvedContent = if (artifactTemplateDefinition != null) {
- blueprintTemplateService.generateContent(
- bluePrintRuntimeService, nodeTemplateName,
- artifactTemplate, resolvedParamJsonContent, false,
- mutableMapOf(
- ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_OCCURRENCE to
- properties[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_OCCURRENCE].asJsonPrimitive()
+ val resolvedContent = when {
+ artifactTemplateDefinition != null -> {
+ blueprintTemplateService.generateContent(
+ bluePrintRuntimeService, nodeTemplateName,
+ artifactTemplate, resolvedParamJsonContent, false,
+ mutableMapOf(
+ ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_OCCURRENCE to
+ properties[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_OCCURRENCE].asJsonPrimitive()
+ )
)
- )
- } else {
- resolvedParamJsonContent
+ }
+ resolutionSummary -> {
+ ResourceAssignmentUtils.generateResolutionSummaryData(resourceAssignments, resourceDefinitions)
+ }
+ else -> {
+ resolvedParamJsonContent
+ }
}
if (isToStore(properties)) {
diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/db/ResourceResolutionDBService.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/db/ResourceResolutionDBService.kt
index f8bf7bd09..dc1553747 100644
--- a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/db/ResourceResolutionDBService.kt
+++ b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/db/ResourceResolutionDBService.kt
@@ -198,4 +198,27 @@ class ResourceResolutionDBService(private val resourceResolutionRepository: Reso
throw BluePrintException("Failed to store resource resolution result.", ex)
}
}
+
+ /**
+ * This is a deleteByBlueprintNameAndBlueprintVersionAndArtifactNameAndResolutionKey method to delete resources
+ * associated to a specific resolution-key
+ *
+ * @param blueprintName name of the CBA
+ * @param blueprintVersion version of the CBA
+ * @param artifactName name of the artifact
+ * @param resolutionKey value of the resolution-key
+ */
+ suspend fun deleteByBlueprintNameAndBlueprintVersionAndArtifactNameAndResolutionKey(
+ blueprintName: String,
+ blueprintVersion: String,
+ artifactName: String,
+ resolutionKey: String
+ ) {
+ resourceResolutionRepository.deleteByBlueprintNameAndBlueprintVersionAndArtifactNameAndResolutionKey(
+ blueprintName,
+ blueprintVersion,
+ artifactName,
+ resolutionKey
+ )
+ }
}
diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/db/ResourceResolutionRepository.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/db/ResourceResolutionRepository.kt
index a2a3a753b..c2d630e5e 100644
--- a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/db/ResourceResolutionRepository.kt
+++ b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/db/ResourceResolutionRepository.kt
@@ -17,6 +17,7 @@ package org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.db
import org.springframework.data.jpa.repository.JpaRepository
import org.springframework.stereotype.Repository
+import javax.transaction.Transactional
@Repository
interface ResourceResolutionRepository : JpaRepository<ResourceResolution, String> {
@@ -59,4 +60,12 @@ interface ResourceResolutionRepository : JpaRepository<ResourceResolution, Strin
resourceType: String,
occurrence: Int
): List<ResourceResolution>
+
+ @Transactional
+ fun deleteByBlueprintNameAndBlueprintVersionAndArtifactNameAndResolutionKey(
+ blueprintName: String?,
+ blueprintVersion: String?,
+ artifactName: String,
+ resolutionKey: String
+ )
}
diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/CapabilityResourceResolutionProcessor.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/CapabilityResourceResolutionProcessor.kt
index feef4c2fe..868f919c1 100644
--- a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/CapabilityResourceResolutionProcessor.kt
+++ b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/CapabilityResourceResolutionProcessor.kt
@@ -81,6 +81,8 @@ open class CapabilityResourceResolutionProcessor(private var componentFunctionSc
// Invoke componentResourceAssignmentProcessor
componentResourceAssignmentProcessor!!.executeScript(resourceAssignment)
+
+ componentFunctionScriptingService.cleanupInstance(raRuntimeService.bluePrintContext(), scriptType)
}
}
diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/DatabaseResourceAssignmentProcessor.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/DatabaseResourceAssignmentProcessor.kt
index e43b45e7d..0bfd7e4e2 100644
--- a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/DatabaseResourceAssignmentProcessor.kt
+++ b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/DatabaseResourceAssignmentProcessor.kt
@@ -28,6 +28,7 @@ import org.onap.ccsdk.cds.controllerblueprints.core.checkNotEmpty
import org.onap.ccsdk.cds.controllerblueprints.core.isNotEmpty
import org.onap.ccsdk.cds.controllerblueprints.core.nullToEmpty
import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils
+import org.onap.ccsdk.cds.controllerblueprints.resource.dict.KeyIdentifier
import org.onap.ccsdk.cds.controllerblueprints.resource.dict.ResourceAssignment
import org.onap.ccsdk.cds.controllerblueprints.resource.dict.ResourceDictionaryConstants
import org.slf4j.LoggerFactory
@@ -91,6 +92,11 @@ open class DatabaseResourceAssignmentProcessor(
"failed to get input-key-mappings for $dName under $dSource properties"
}
+ sourceProperties.inputKeyMapping
+ ?.mapValues { raRuntimeService.getDictionaryStore(it.value) }
+ ?.map { KeyIdentifier(it.key, it.value) }
+ ?.let { resourceAssignment.keyIdentifiers.addAll(it) }
+
logger.info(
"DatabaseResource ($dSource) dictionary information: " +
"Query:($sql), input-key-mapping:($inputKeyMapping), output-key-mapping:(${sourceProperties.outputKeyMapping})"
diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/RestResourceResolutionProcessor.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/RestResourceResolutionProcessor.kt
index 2ff5c441e..5d9226876 100644
--- a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/RestResourceResolutionProcessor.kt
+++ b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/RestResourceResolutionProcessor.kt
@@ -27,6 +27,7 @@ import org.onap.ccsdk.cds.controllerblueprints.core.checkNotEmpty
import org.onap.ccsdk.cds.controllerblueprints.core.isNotEmpty
import org.onap.ccsdk.cds.controllerblueprints.core.nullToEmpty
import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils
+import org.onap.ccsdk.cds.controllerblueprints.resource.dict.KeyIdentifier
import org.onap.ccsdk.cds.controllerblueprints.resource.dict.ResourceAssignment
import org.slf4j.LoggerFactory
import org.springframework.beans.factory.config.ConfigurableBeanFactory
@@ -75,8 +76,14 @@ open class RestResourceResolutionProcessor(private val blueprintRestLibPropertyS
checkNotNull(sourceProperties.inputKeyMapping) { "failed to get input-key-mappings for $dName under $dSource properties" }
val resolvedInputKeyMapping = resolveInputKeyMappingVariables(inputKeyMapping).toMutableMap()
+ sourceProperties.inputKeyMapping
+ ?.mapValues { raRuntimeService.getDictionaryStore(it.value) }
+ ?.map { KeyIdentifier(it.key, it.value) }
+ ?.let { resourceAssignment.keyIdentifiers.addAll(it) }
+
// Resolving content Variables
val payload = resolveFromInputKeyMapping(nullToEmpty(sourceProperties.payload), resolvedInputKeyMapping)
+ resourceSourceProperties["resolved-payload"] = JacksonUtils.jsonNode(payload)
val urlPath =
resolveFromInputKeyMapping(checkNotNull(sourceProperties.urlPath), resolvedInputKeyMapping)
val verb = resolveFromInputKeyMapping(nullToEmpty(sourceProperties.verb), resolvedInputKeyMapping)
diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/utils/ResourceAssignmentUtils.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/utils/ResourceAssignmentUtils.kt
index 7ffc6db39..7bb757b8e 100644
--- a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/utils/ResourceAssignmentUtils.kt
+++ b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/utils/ResourceAssignmentUtils.kt
@@ -42,6 +42,9 @@ import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintRuntimeServ
import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonReactorUtils
import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils
import org.onap.ccsdk.cds.controllerblueprints.core.utils.PropertyDefinitionUtils.Companion.hasLogProtect
+import org.onap.ccsdk.cds.controllerblueprints.resource.dict.DictionaryMetadataEntry
+import org.onap.ccsdk.cds.controllerblueprints.resource.dict.KeyIdentifier
+import org.onap.ccsdk.cds.controllerblueprints.resource.dict.ResolutionSummary
import org.onap.ccsdk.cds.controllerblueprints.resource.dict.ResourceAssignment
import org.onap.ccsdk.cds.controllerblueprints.resource.dict.ResourceDefinition
import org.slf4j.LoggerFactory
@@ -196,6 +199,29 @@ class ResourceAssignmentUtils {
return data
}
+ fun generateResolutionSummaryData(
+ resourceAssignments: List<ResourceAssignment>,
+ resourceDefinitions: Map<String, ResourceDefinition>
+ ): String {
+ val resolutionSummaryList = resourceAssignments.map {
+ val definition = resourceDefinitions[it.name]
+ val payload = definition?.sources?.get(it.dictionarySource)
+ ?.properties?.get("resolved-payload")
+ val metadata = definition?.property?.metadata
+ ?.map { e -> DictionaryMetadataEntry(e.key, e.value) }
+ ?.toMutableList() ?: mutableListOf()
+ val description = definition?.property?.description
+ ResolutionSummary(
+ it.name, it.property?.value, it.property?.required, it.property?.type,
+ it.keyIdentifiers, description, metadata, it.dictionaryName,
+ it.dictionarySource, payload, it.status, it.message
+ )
+ }
+ // Wrapper needed for integration with SDNC
+ val data = mapOf("resolution-summary" to resolutionSummaryList)
+ return JacksonUtils.getJson(data, includeNull = true)
+ }
+
private fun useDefaultValueIfNull(
resourceAssignment: ResourceAssignment,
resourceAssignmentName: String
@@ -263,7 +289,7 @@ class ResourceAssignmentUtils {
return when (type) {
in BluePrintTypes.validPrimitiveTypes() -> {
// Primitive Types
- parseResponseNodeForPrimitiveTypes(responseNode, outputKeyMapping)
+ parseResponseNodeForPrimitiveTypes(responseNode, resourceAssignment, outputKeyMapping)
}
in BluePrintTypes.validCollectionTypes() -> {
// Array Types
@@ -282,6 +308,7 @@ class ResourceAssignmentUtils {
private fun parseResponseNodeForPrimitiveTypes(
responseNode: JsonNode,
+ resourceAssignment: ResourceAssignment,
outputKeyMapping: MutableMap<String, String>
): JsonNode {
// Return responseNode if is not a Complex Type
@@ -306,11 +333,16 @@ class ResourceAssignmentUtils {
if (returnNode.isNullOrMissing() || returnNode!!.isComplexType() && !returnNode.has(outputKeyMapping[outputKey])) {
throw BluePrintProcessorException("Fail to find output key mapping ($outputKey) in the responseNode.")
}
- return if (returnNode.isComplexType()) {
+
+ val returnValue = if (returnNode.isComplexType()) {
returnNode[outputKeyMapping[outputKey]]
} else {
returnNode
}
+
+ outputKey?.let { KeyIdentifier(it, returnValue) }
+ ?.let { resourceAssignment.keyIdentifiers.add(it) }
+ return returnValue
}
private fun parseResponseNodeForCollection(
@@ -337,7 +369,7 @@ class ResourceAssignmentUtils {
val responseArrayNode = responseNode.toList()
for (responseSingleJsonNode in responseArrayNode) {
val arrayChildNode = parseSingleElementOfArrayResponseNode(
- entrySchemaType,
+ entrySchemaType, resourceAssignment,
outputKeyMapping, raRuntimeService, responseSingleJsonNode, metadata
)
arrayNode.add(arrayChildNode)
@@ -347,7 +379,10 @@ class ResourceAssignmentUtils {
is ObjectNode -> {
val responseArrayNode = responseNode.rootFieldsToMap()
resultNode =
- parseObjectResponseNode(entrySchemaType, outputKeyMapping, responseArrayNode, metadata)
+ parseObjectResponseNode(
+ resourceAssignment, entrySchemaType, outputKeyMapping,
+ responseArrayNode, metadata
+ )
}
else -> {
throw BluePrintProcessorException("Key-value response expected to match the responseNode.")
@@ -387,6 +422,7 @@ class ResourceAssignmentUtils {
private fun parseSingleElementOfArrayResponseNode(
entrySchemaType: String,
+ resourceAssignment: ResourceAssignment,
outputKeyMapping: MutableMap<String, String>,
raRuntimeService: ResourceAssignmentRuntimeService,
responseNode: JsonNode,
@@ -397,7 +433,13 @@ class ResourceAssignmentUtils {
in BluePrintTypes.validPrimitiveTypes() -> {
if (outputKeyMappingHasOnlyOneElement) {
val outputKeyMap = outputKeyMapping.entries.first()
+ if (resourceAssignment.keyIdentifiers.none { it.name == outputKeyMap.key }) {
+ resourceAssignment.keyIdentifiers.add(
+ KeyIdentifier(outputKeyMap.key, JacksonUtils.objectMapper.createArrayNode())
+ )
+ }
return parseSingleElementNodeWithOneOutputKeyMapping(
+ resourceAssignment,
responseNode,
outputKeyMap.key,
outputKeyMap.value,
@@ -416,6 +458,7 @@ class ResourceAssignmentUtils {
raRuntimeService
) -> {
parseSingleElementNodeWithAllOutputKeyMapping(
+ resourceAssignment,
responseNode,
outputKeyMapping,
entrySchemaType,
@@ -425,6 +468,7 @@ class ResourceAssignmentUtils {
outputKeyMappingHasOnlyOneElement -> {
val outputKeyMap = outputKeyMapping.entries.first()
parseSingleElementNodeWithOneOutputKeyMapping(
+ resourceAssignment,
responseNode,
outputKeyMap.key,
outputKeyMap.value,
@@ -441,6 +485,7 @@ class ResourceAssignmentUtils {
}
private fun parseObjectResponseNode(
+ resourceAssignment: ResourceAssignment,
entrySchemaType: String,
outputKeyMapping: MutableMap<String, String>,
responseArrayNode: MutableMap<String, JsonNode>,
@@ -449,19 +494,21 @@ class ResourceAssignmentUtils {
val outputKeyMappingHasOnlyOneElement = checkIfOutputKeyMappingProvideOneElement(outputKeyMapping)
if (outputKeyMappingHasOnlyOneElement) {
val outputKeyMap = outputKeyMapping.entries.first()
- return parseObjectResponseNodeWithOneOutputKeyMapping(
+ val returnValue = parseObjectResponseNodeWithOneOutputKeyMapping(
responseArrayNode, outputKeyMap.key, outputKeyMap.value,
entrySchemaType, metadata
)
+ resourceAssignment.keyIdentifiers.add(KeyIdentifier(outputKeyMap.key, returnValue))
+ return returnValue
} else {
throw BluePrintProcessorException("Output-key-mapping do not map the Data Type $entrySchemaType")
}
}
private fun parseSingleElementNodeWithOneOutputKeyMapping(
+ resourceAssignment: ResourceAssignment,
responseSingleJsonNode: JsonNode,
- outputKeyMappingKey:
- String,
+ outputKeyMappingKey: String,
outputKeyMappingValue: String,
type: String,
metadata: MutableMap<String, String>?
@@ -476,11 +523,19 @@ class ResourceAssignmentUtils {
logKeyValueResolvedResource(metadata, outputKeyMappingKey, responseKeyValue, type)
JacksonUtils.populateJsonNodeValues(outputKeyMappingKey, responseKeyValue, type, arrayChildNode)
-
+ resourceAssignment.keyIdentifiers.find { it.name == outputKeyMappingKey && it.value.isArray }
+ .let {
+ if (it != null)
+ (it.value as ArrayNode).add(responseKeyValue)
+ else
+ resourceAssignment.keyIdentifiers.add(
+ KeyIdentifier(outputKeyMappingKey, responseKeyValue))
+ }
return arrayChildNode
}
private fun parseSingleElementNodeWithAllOutputKeyMapping(
+ resourceAssignment: ResourceAssignment,
responseSingleJsonNode: JsonNode,
outputKeyMapping: MutableMap<String, String>,
type: String,
@@ -496,6 +551,7 @@ class ResourceAssignmentUtils {
logKeyValueResolvedResource(metadata, it.key, responseKeyValue, type)
JacksonUtils.populateJsonNodeValues(it.key, responseKeyValue, type, arrayChildNode)
+ resourceAssignment.keyIdentifiers.add(KeyIdentifier(it.key, responseKeyValue))
}
return arrayChildNode
}
@@ -541,6 +597,7 @@ class ResourceAssignmentUtils {
raRuntimeService
) -> {
parseSingleElementNodeWithAllOutputKeyMapping(
+ resourceAssignment,
responseNode,
outputKeyMapping,
entrySchemaType,
@@ -550,8 +607,8 @@ class ResourceAssignmentUtils {
outputKeyMappingHasOnlyOneElement -> {
val outputKeyMap = outputKeyMapping.entries.first()
parseSingleElementNodeWithOneOutputKeyMapping(
- responseNode, outputKeyMap.key, outputKeyMap.value,
- entrySchemaType, metadata
+ resourceAssignment, responseNode, outputKeyMap.key,
+ outputKeyMap.value, entrySchemaType, metadata
)
}
else -> {
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
index ae9b4208f..d1347113a 100644
--- 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
@@ -41,6 +41,7 @@ class ResourceResolutionComponentDSLTest {
occurrence(2)
resourceType("vnf")
storeResult(false)
+ resolutionSummary(true)
artifactPrefixNames(arrayListOf("template1", "template2"))
dynamicProperties(
"""{
diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceResolutionServiceTest.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceResolutionServiceTest.kt
index 2f338a3a1..d5c43184e 100644
--- a/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceResolutionServiceTest.kt
+++ b/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceResolutionServiceTest.kt
@@ -36,6 +36,7 @@ import org.onap.ccsdk.cds.controllerblueprints.core.asJsonPrimitive
import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintContext
import org.onap.ccsdk.cds.controllerblueprints.core.utils.BluePrintMetadataUtils
import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils
+import org.onap.ccsdk.cds.controllerblueprints.resource.dict.ResolutionSummary
import org.slf4j.LoggerFactory
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.autoconfigure.EnableAutoConfiguration
@@ -44,6 +45,7 @@ import org.springframework.context.annotation.ComponentScan
import org.springframework.test.context.ContextConfiguration
import org.springframework.test.context.TestPropertySource
import org.springframework.test.context.junit4.SpringRunner
+import kotlin.test.assertEquals
import kotlin.test.assertNotNull
import kotlin.test.assertTrue
@@ -79,6 +81,7 @@ class ResourceResolutionServiceTest {
props[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_RESOURCE_ID] = resourceId
props[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_RESOURCE_TYPE] = resourceType
props[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_OCCURRENCE] = occurrence
+ props[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_RESOLUTION_SUMMARY] = false
}
@Test
@@ -214,6 +217,101 @@ class ResourceResolutionServiceTest {
}
@Test
+ @Throws(Exception::class)
+ fun testResolveResourcesResolutionSummary() {
+ runBlocking {
+ props[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_RESOLUTION_SUMMARY] = true
+ Assert.assertNotNull("failed to create ResourceResolutionService", resourceResolutionService)
+
+ val bluePrintRuntimeService = BluePrintMetadataUtils.getBluePrintRuntime(
+ "1234",
+ "./../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration"
+ )
+
+ val executionServiceInput =
+ JacksonUtils.readValueFromClassPathFile(
+ "payload/requests/sample-resourceresolution-request.json",
+ ExecutionServiceInput::class.java
+ )!!
+
+ val resourceAssignmentRuntimeService =
+ ResourceAssignmentUtils.transformToRARuntimeService(
+ bluePrintRuntimeService,
+ "testResolveResourcesWithMappingAndTemplate"
+ )
+
+ val artifactPrefix = "notemplate"
+
+ // Prepare Inputs
+ PayloadUtils.prepareInputsFromWorkflowPayload(
+ bluePrintRuntimeService,
+ executionServiceInput.payload,
+ "resource-assignment"
+ )
+
+ resourceResolutionService.resolveResources(
+ resourceAssignmentRuntimeService,
+ "resource-assignment",
+ artifactPrefix,
+ props
+ )
+ }.let {
+ val summaries = JacksonUtils.jsonNode(it)["resolution-summary"]
+ val list = JacksonUtils.getListFromJsonNode(summaries, ResolutionSummary::class.java)
+ assertEquals(list.size, 3)
+ }
+ }
+
+ @Test
+ @Throws(Exception::class)
+ fun testResolveResourcesWithoutTemplate() {
+ runBlocking {
+ Assert.assertNotNull("failed to create ResourceResolutionService", resourceResolutionService)
+
+ val bluePrintRuntimeService = BluePrintMetadataUtils.getBluePrintRuntime(
+ "1234",
+ "./../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration"
+ )
+
+ val executionServiceInput =
+ JacksonUtils.readValueFromClassPathFile(
+ "payload/requests/sample-resourceresolution-request.json",
+ ExecutionServiceInput::class.java
+ )!!
+
+ val resourceAssignmentRuntimeService =
+ ResourceAssignmentUtils.transformToRARuntimeService(
+ bluePrintRuntimeService,
+ "testResolveResourcesWithMappingAndTemplate"
+ )
+
+ val artifactPrefix = "notemplate"
+
+ // Prepare Inputs
+ PayloadUtils.prepareInputsFromWorkflowPayload(
+ bluePrintRuntimeService,
+ executionServiceInput.payload,
+ "resource-assignment"
+ )
+
+ resourceResolutionService.resolveResources(
+ resourceAssignmentRuntimeService,
+ "resource-assignment",
+ artifactPrefix,
+ props
+ )
+ }.let {
+ assertEquals("""
+ {
+ "service-instance-id" : "siid_1234",
+ "vnf-id" : "vnf_1234",
+ "vnf_name" : "temp_vnf"
+ }
+ """.trimIndent(), it)
+ }
+ }
+
+ @Test
fun testResolveResourcesWithResourceIdAndResourceType() {
props[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_RESOLUTION_KEY] = ""
runBlocking {
diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/db/ResourceResolutionDBServiceTest.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/db/ResourceResolutionDBServiceTest.kt
index 4f864a49c..e667cd16f 100644
--- a/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/db/ResourceResolutionDBServiceTest.kt
+++ b/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/db/ResourceResolutionDBServiceTest.kt
@@ -223,4 +223,16 @@ open class ResourceResolutionDBServiceTest {
assertEquals(resourceResolution, res)
}
}
+
+ @Test
+ fun deleteByBlueprintNameAndBlueprintVersionAndArtifactNameAndResolutionKeyTest() {
+ every {
+ resourceResolutionRepository.deleteByBlueprintNameAndBlueprintVersionAndArtifactNameAndResolutionKey(any(), any(), any(), any())
+ } returns Unit
+ runBlocking {
+ val res = resourceResolutionDBService.deleteByBlueprintNameAndBlueprintVersionAndArtifactNameAndResolutionKey(
+ blueprintName, blueprintVersion, artifactPrefix, resolutionKey)
+ assertEquals(Unit, res)
+ }
+ }
}
diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/CapabilityResourceResolutionProcessorTest.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/CapabilityResourceResolutionProcessorTest.kt
index d84488d76..5fbe32e07 100644
--- a/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/CapabilityResourceResolutionProcessorTest.kt
+++ b/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/CapabilityResourceResolutionProcessorTest.kt
@@ -52,6 +52,10 @@ class CapabilityResourceResolutionProcessorTest {
.scriptInstance<ResourceAssignmentProcessor>(any(), any(), any())
} returns MockCapabilityScriptRA()
+ coEvery {
+ componentFunctionScriptingService.cleanupInstance(any(), any())
+ } returns mockk()
+
val raRuntimeService = mockk<ResourceAssignmentRuntimeService>()
every { raRuntimeService.bluePrintContext() } returns mockk<BluePrintContext>()
every { raRuntimeService.getInputValue("test-property") } returns NullNode.getInstance()
@@ -96,6 +100,10 @@ class CapabilityResourceResolutionProcessorTest {
.scriptInstance<ResourceAssignmentProcessor>(any(), BluePrintConstants.SCRIPT_JYTHON, any())
} returns MockCapabilityScriptRA()
+ coEvery {
+ componentFunctionScriptingService.cleanupInstance(any(), any())
+ } returns mockk()
+
val resourceAssignmentRuntimeService = ResourceAssignmentRuntimeService("1234", bluePrintContext)
val capabilityResourceResolutionProcessor =
diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/utils/ResourceAssignmentUtilsTest.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/utils/ResourceAssignmentUtilsTest.kt
index 3251dcacb..9df8fb7d7 100644
--- a/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/utils/ResourceAssignmentUtilsTest.kt
+++ b/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/utils/ResourceAssignmentUtilsTest.kt
@@ -33,10 +33,12 @@ import org.onap.ccsdk.cds.controllerblueprints.core.asJsonPrimitive
import org.onap.ccsdk.cds.controllerblueprints.core.asJsonType
import org.onap.ccsdk.cds.controllerblueprints.core.data.DataType
import org.onap.ccsdk.cds.controllerblueprints.core.data.EntrySchema
+import org.onap.ccsdk.cds.controllerblueprints.core.data.NodeTemplate
import org.onap.ccsdk.cds.controllerblueprints.core.data.PropertyDefinition
import org.onap.ccsdk.cds.controllerblueprints.core.utils.BluePrintMetadataUtils
import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils
import org.onap.ccsdk.cds.controllerblueprints.resource.dict.ResourceAssignment
+import org.onap.ccsdk.cds.controllerblueprints.resource.dict.ResourceDefinition
import kotlin.test.assertEquals
data class IpAddress(val port: String, val ip: String)
@@ -46,6 +48,7 @@ data class ExpectedResponseIpAddress(val ipAddress: IpAddress)
class ResourceAssignmentUtilsTest {
private lateinit var resourceAssignmentRuntimeService: ResourceAssignmentRuntimeService
+ private lateinit var resourceAssignment: ResourceAssignment
private lateinit var inputMapToTestPrimitiveTypeWithValue: JsonNode
private lateinit var inputMapToTestPrimitiveTypeWithKeyValue: JsonNode
@@ -156,6 +159,46 @@ class ResourceAssignmentUtilsTest {
assertEquals(expected, outcome.replace("\r\n", "\n"), "unexpected outcome generated")
}
+ @Test
+ fun generate() {
+ val resourceAssignment = createResourceAssignmentForTest(null)
+ val resourceDefinition = ResourceDefinition()
+ val nodeTemplate = NodeTemplate().apply {
+ properties = mutableMapOf("resolved-payload" to JacksonUtils.jsonNode("{\"mock\": true}"))
+ }
+ resourceDefinition.sources = mutableMapOf("input" to nodeTemplate)
+ resourceDefinition.property = PropertyDefinition().apply {
+ this.description = "pnf-id"
+ this.metadata = mutableMapOf("aai-path" to "//path/in/aai")
+ }
+
+ val result = ResourceAssignmentUtils.generateResolutionSummaryData(
+ listOf(resourceAssignment), mapOf("pnf-id" to resourceDefinition))
+
+ assertEquals("""
+ {
+ "resolution-summary":[
+ {
+ "name":"pnf-id",
+ "value":null,
+ "required":null,
+ "type":"string",
+ "key-identifiers":[],
+ "dictionary-description":"pnf-id",
+ "dictionary-metadata":[
+ {"name":"aai-path","value":"//path/in/aai"}
+ ],
+ "dictionary-name":"pnf-id",
+ "dictionary-source":"input",
+ "request-payload":{"mock":true},
+ "status":null,
+ "message":null
+ }
+ ]
+ }
+ """.replace("\n|\\s".toRegex(), ""), result)
+ }
+
private fun createResourceAssignmentForTest(resourceValue: String?): ResourceAssignment {
val valueForTest = if (resourceValue == null) null else TextNode(resourceValue)
val resourceAssignmentForTest = ResourceAssignment().apply {
@@ -181,6 +224,7 @@ class ResourceAssignmentUtilsTest {
outcome,
"Unexpected outcome returned for primitive type of simple String"
)
+ assertEquals(0, resourceAssignment.keyIdentifiers.size)
outcome = prepareResponseNodeForTest(
"sample-key-value", "string", "",
@@ -191,6 +235,10 @@ class ResourceAssignmentUtilsTest {
outcome,
"Unexpected outcome returned for primitive type of key-value String"
)
+ assertEquals(
+ expectedValueToTestPrimitiveType,
+ resourceAssignment.keyIdentifiers[0].value
+ )
}
@Test
@@ -204,6 +252,13 @@ class ResourceAssignmentUtilsTest {
outcome,
"unexpected outcome returned for list of String"
)
+
+ val expectedKeyIdentifierValue = JacksonUtils.getJsonNode(outcome.map { it["ip"] })
+ assertEquals(
+ expectedKeyIdentifierValue,
+ resourceAssignment.keyIdentifiers[0].value
+ )
+
// FIXME("Map is not collection type, It is known complex type")
// outcome = prepareResponseNodeForTest(
// "mapOfString", "map", "string",
@@ -250,6 +305,9 @@ class ResourceAssignmentUtilsTest {
outcome,
"Unexpected outcome returned for complex type"
)
+ assertEquals(
+ expectedValueToTestComplexTypeWithOneOutputKeyMapping["host"],
+ resourceAssignment.keyIdentifiers[0].value)
}
@Test
@@ -263,6 +321,16 @@ class ResourceAssignmentUtilsTest {
outcome,
"Unexpected outcome returned for complex type"
)
+ assertEquals(2, resourceAssignment.keyIdentifiers.size)
+ assertEquals(
+ expectedValueToTestComplexTypeWithAllOutputKeyMapping["name"],
+ resourceAssignment.keyIdentifiers[0].value
+ )
+
+ assertEquals(
+ expectedValueToTestComplexTypeWithAllOutputKeyMapping["ipAddress"],
+ resourceAssignment.keyIdentifiers[1].value
+ )
}
private fun initInputMapAndExpectedValuesForPrimitiveType() {
@@ -359,7 +427,7 @@ class ResourceAssignmentUtilsTest {
response: Any
): JsonNode {
- val resourceAssignment = when (sourceType) {
+ resourceAssignment = when (sourceType) {
"list" -> {
prepareRADataDictionaryCollection(dictionary_source, sourceType, entrySchema)
}
diff --git a/ms/blueprintsprocessor/functions/restconf-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/restconf/executor/RestconfExecutorExtensions.kt b/ms/blueprintsprocessor/functions/restconf-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/restconf/executor/RestconfExecutorExtensions.kt
index 906bef9a4..408eaf45b 100644
--- a/ms/blueprintsprocessor/functions/restconf-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/restconf/executor/RestconfExecutorExtensions.kt
+++ b/ms/blueprintsprocessor/functions/restconf-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/restconf/executor/RestconfExecutorExtensions.kt
@@ -45,12 +45,12 @@ suspend fun AbstractScriptComponentFunction.restconfMountDevice(
headers: Map<String, String> = mutableMapOf("Content-Type" to "application/xml")
) {
- val mountUrl = "restconf/config/network-topology:network-topology/topology/topology-netconf/node/$deviceId"
+ val mountUrl = "/restconf/config/network-topology:network-topology/topology/topology-netconf/node/$deviceId"
log.info("sending mount request, url: $mountUrl")
webClientService.exchangeResource("PUT", mountUrl, payload as String, headers)
/** Check device has mounted */
- val mountCheckUrl = "restconf/operational/network-topology:network-topology/topology/topology-netconf/node/$deviceId"
+ val mountCheckUrl = "/restconf/operational/network-topology:network-topology/topology/topology-netconf/node/$deviceId"
val expectedResult = """"netconf-node-topology:connection-status":"connected""""
val mountCheckExecutionBlock: suspend (Int) -> String = { tryCount: Int ->
@@ -69,6 +69,7 @@ suspend fun AbstractScriptComponentFunction.restconfMountDevice(
/**
* Generic Configure function
+ * @return The WebClientResponse from the request
*/
suspend fun AbstractScriptComponentFunction.restconfApplyDeviceConfig(
webClientService: BlueprintWebClientService,
@@ -76,14 +77,12 @@ suspend fun AbstractScriptComponentFunction.restconfApplyDeviceConfig(
configletResourcePath: String,
configletToApply: Any,
additionalHeaders: Map<String, String> = mutableMapOf("Content-Type" to "application/yang.patch+xml")
-) {
-
+): BlueprintWebClientService.WebClientResponse<String> {
log.debug("headers: $additionalHeaders")
log.info("configuring device: $deviceId, Configlet: $configletToApply")
- val applyConfigUrl = "restconf/config/network-topology:network-topology/topology/topology-netconf/node/" +
+ val applyConfigUrl = "/restconf/config/network-topology:network-topology/topology/topology-netconf/node/" +
"$deviceId/$configletResourcePath"
- val result: Any = webClientService.exchangeResource("PATCH", applyConfigUrl, configletToApply as String, additionalHeaders)
- log.info("Configuration application result: $result")
+ return webClientService.exchangeResource("PATCH", applyConfigUrl, configletToApply as String, additionalHeaders)
}
suspend fun AbstractScriptComponentFunction.restconfDeviceConfig(
@@ -93,7 +92,7 @@ suspend fun AbstractScriptComponentFunction.restconfDeviceConfig(
):
BlueprintWebClientService.WebClientResponse<String> {
- val configPathUrl = "restconf/config/network-topology:network-topology/topology/topology-netconf/node/" +
+ val configPathUrl = "/restconf/config/network-topology:network-topology/topology/topology-netconf/node/" +
"$deviceId/$configletResourcePath"
log.debug("sending GET request, url: $configPathUrl")
return webClientService.exchangeResource("GET", configPathUrl, "")
@@ -107,7 +106,7 @@ suspend fun AbstractScriptComponentFunction.restconfUnMountDevice(
deviceId: String,
payload: String
) {
- val unMountUrl = "restconf/config/network-topology:network-topology/topology/topology-netconf/node/$deviceId"
+ val unMountUrl = "/restconf/config/network-topology:network-topology/topology/topology-netconf/node/$deviceId"
log.info("sending unMount request, url: $unMountUrl")
webClientService.exchangeResource("DELETE", unMountUrl, "")
}
diff --git a/ms/blueprintsprocessor/functions/nrm-restful/pom.xml b/ms/blueprintsprocessor/functions/restful-executor/pom.xml
index 337e71e15..4ac52c4b8 100644
--- a/ms/blueprintsprocessor/functions/nrm-restful/pom.xml
+++ b/ms/blueprintsprocessor/functions/restful-executor/pom.xml
@@ -24,11 +24,10 @@
</parent>
<groupId>org.onap.ccsdk.cds.blueprintsprocessor.functions</groupId>
- <artifactId>nrm-restful</artifactId>
- <packaging>jar</packaging>
+ <artifactId>restful-executor</artifactId>
- <name>Blueprints Processor Function - NRM Restful</name>
- <description>Blueprints Processor Function - NRM Restful</description>
+ <name>Blueprints Processor Function - NRM Restful executor</name>
+ <description>Blueprints Processor Function - NRM Restful executor</description>
<dependencies>
<dependency>
@@ -48,5 +47,10 @@
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
</dependency>
+ <dependency>
+ <groupId>com.h2database</groupId>
+ <artifactId>h2</artifactId>
+ <scope>test</scope>
+ </dependency>
</dependencies>
</project>
diff --git a/ms/blueprintsprocessor/functions/restful-executor/src/main/kotlin/internal/scripts/TestRestfulConfigure.kt b/ms/blueprintsprocessor/functions/restful-executor/src/main/kotlin/internal/scripts/TestRestfulConfigure.kt
new file mode 100644
index 000000000..5f867b93f
--- /dev/null
+++ b/ms/blueprintsprocessor/functions/restful-executor/src/main/kotlin/internal/scripts/TestRestfulConfigure.kt
@@ -0,0 +1,42 @@
+/*
+ * Copyright © 2020 Huawei.
+ *
+ * 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.
+ */
+@file:Suppress("unused")
+
+package internal.scripts
+
+import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.ExecutionServiceInput
+import org.onap.ccsdk.cds.blueprintsprocessor.functions.restful.executor.RestfulCMComponentFunction
+import org.slf4j.LoggerFactory
+
+/**
+ * This is for used for Testing only
+ */
+open class TestRestfulConfigure : RestfulCMComponentFunction() {
+
+ val log = LoggerFactory.getLogger(TestRestfulConfigure::class.java)!!
+
+ override fun getName(): String {
+ return "TestRestfulConfigure"
+ }
+
+ override suspend fun processNB(executionRequest: ExecutionServiceInput) {
+ log.info("processing request..")
+ }
+
+ override suspend fun recoverNB(runtimeException: RuntimeException, executionRequest: ExecutionServiceInput) {
+ log.info("recovering..")
+ }
+}
diff --git a/ms/blueprintsprocessor/functions/restful-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/restful/executor/ComponentRestfulExecutor.kt b/ms/blueprintsprocessor/functions/restful-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/restful/executor/ComponentRestfulExecutor.kt
new file mode 100644
index 000000000..e1643b576
--- /dev/null
+++ b/ms/blueprintsprocessor/functions/restful-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/restful/executor/ComponentRestfulExecutor.kt
@@ -0,0 +1,69 @@
+/*
+ * Copyright © 2020 Huawei 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.cds.blueprintsprocessor.functions.restful.executor
+
+import com.fasterxml.jackson.databind.node.ArrayNode
+import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.ExecutionServiceInput
+import org.onap.ccsdk.cds.blueprintsprocessor.rest.RestLibConstants
+import org.onap.ccsdk.cds.blueprintsprocessor.services.execution.AbstractComponentFunction
+import org.onap.ccsdk.cds.blueprintsprocessor.services.execution.ComponentFunctionScriptingService
+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
+
+@Component("component-restful-executor")
+@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
+open class ComponentRestfulExecutor(private var componentFunctionScriptingService: ComponentFunctionScriptingService) : AbstractComponentFunction() {
+
+ lateinit var scriptComponent: RestfulCMComponentFunction
+
+ companion object {
+ const val SCRIPT_TYPE = "script-type"
+ const val SCRIPT_CLASS_REFERENCE = "script-class-reference"
+ const val INSTANCE_DEPENDENCIES = "instance-dependencies"
+ }
+
+ override suspend fun processNB(executionRequest: ExecutionServiceInput) {
+
+ val scriptType = operationInputs.getAsString(SCRIPT_TYPE)
+ val scriptClassReference = operationInputs.getAsString(SCRIPT_CLASS_REFERENCE)
+ val instanceDependenciesNode = operationInputs.get(INSTANCE_DEPENDENCIES) as? ArrayNode
+
+ val scriptDependencies: MutableList<String> = arrayListOf()
+ scriptDependencies.add(RestLibConstants.SERVICE_BLUEPRINT_REST_LIB_PROPERTY)
+
+ instanceDependenciesNode?.forEach { instanceName ->
+ scriptDependencies.add(instanceName.textValue())
+ }
+ /**
+ * Populate the Script Instance based on the Type
+ */
+ scriptComponent = componentFunctionScriptingService
+ .scriptInstance<RestfulCMComponentFunction>(this, scriptType,
+ scriptClassReference, scriptDependencies)
+
+ checkNotNull(scriptComponent) { "failed to get restfulCM script component" }
+
+ // Handles both script processing and error handling
+ scriptComponent.executeScript(executionServiceInput)
+ }
+
+ override suspend fun recoverNB(runtimeException: RuntimeException, executionRequest: ExecutionServiceInput) {
+ bluePrintRuntimeService.getBluePrintError()
+ .addError("Failed in ComponentRestfulExecutor : ${runtimeException.message}")
+ }
+}
diff --git a/ms/blueprintsprocessor/functions/restful-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/restful/executor/RestfulCMComponentFunction.kt b/ms/blueprintsprocessor/functions/restful-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/restful/executor/RestfulCMComponentFunction.kt
new file mode 100644
index 000000000..46fec3126
--- /dev/null
+++ b/ms/blueprintsprocessor/functions/restful-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/restful/executor/RestfulCMComponentFunction.kt
@@ -0,0 +1,126 @@
+/*
+ * Copyright © 2020 Huawei.
+ *
+ * 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.restful.executor
+
+import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.ExecutionServiceInput
+import org.onap.ccsdk.cds.blueprintsprocessor.services.execution.AbstractScriptComponentFunction
+import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintException
+import com.fasterxml.jackson.databind.JsonNode
+import com.fasterxml.jackson.databind.ObjectMapper
+import com.fasterxml.jackson.databind.node.ObjectNode
+import com.fasterxml.jackson.databind.node.ArrayNode
+import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils
+import org.onap.ccsdk.cds.blueprintsprocessor.rest.RestLibConstants
+import org.onap.ccsdk.cds.blueprintsprocessor.rest.service.BluePrintRestLibPropertyService
+import org.onap.ccsdk.cds.blueprintsprocessor.rest.service.BlueprintWebClientService
+import org.onap.ccsdk.cds.blueprintsprocessor.functions.restful.executor.nrmfunction.RestfulNRMServiceClient
+import org.slf4j.LoggerFactory
+
+abstract class RestfulCMComponentFunction : AbstractScriptComponentFunction() {
+
+ private val log = LoggerFactory.getLogger(RestfulCMComponentFunction::class.java)
+ override suspend fun processNB(executionRequest: ExecutionServiceInput) {
+ throw BluePrintException("Not Implemented required")
+ }
+
+ override suspend fun recoverNB(runtimeException: RuntimeException, executionRequest: ExecutionServiceInput) {
+ throw BluePrintException("Not Implemented required")
+ }
+
+ open fun bluePrintRestLibPropertyService(): BluePrintRestLibPropertyService =
+ functionDependencyInstanceAsType(RestLibConstants.SERVICE_BLUEPRINT_REST_LIB_PROPERTY)
+
+ fun restClientService(clientInfo: JsonNode): BlueprintWebClientService {
+ return bluePrintRestLibPropertyService().blueprintWebClientService(clientInfo)
+ }
+
+ fun processNRM(executionRequest: ExecutionServiceInput, input_params: ArrayNode): String {
+ // process the managed object instances
+ log.info("Processing NRM Object")
+ operationInputs = executionServiceInput.stepData!!.properties
+ val dynamic_properties = operationInputs.get("dynamic-properties")
+ // instantiate one restClientService instance
+ val hostname = dynamic_properties?.get("hostname").toString().replace("\"", "")
+ val port = dynamic_properties?.get("port").toString().replace("\"", "")
+ val username = dynamic_properties?.get("username").toString().replace("\"", "")
+ val password = dynamic_properties?.get("password").toString().replace("\"", "")
+ val url = "http://" + hostname + ":" + port
+ val RestInfo: String = "{\n" +
+ " \"type\" : \"basic-auth\",\n" +
+ " \"url\" : \"" + url + "\",\n" +
+ " \"username\" : \"" + username + "\",\n" +
+ " \"password\" : \"" + password + "\"\n" +
+ "}"
+ val mapper = ObjectMapper()
+ val jsonRestInfo: JsonNode = mapper.readTree(RestInfo)
+ val web_client_service = restClientService(jsonRestInfo)
+ val managed_object_instances = input_params
+ var response = JacksonUtils.jsonNode("{}") as ObjectNode
+ // Invoke the corresponding function according to the workflowname
+ when (this.workflowName) {
+ "config-deploy" -> {
+ for (managed_object_instance in managed_object_instances) {
+ // invoke createMOI for each managed-object-instance
+ log.info("invoke createMOI for each managed-object-instance")
+ var NRM_Restful_client = RestfulNRMServiceClient()
+ val MOI_id = NRM_Restful_client.generateMOIid()
+ var httpresponse = NRM_Restful_client.createMOI(web_client_service, MOI_id, managed_object_instance)
+ var MOIname = managed_object_instance.get("className").toString().replace("\"", "")
+ response.put("/$MOIname/$MOI_id", httpresponse)
+ }
+ }
+ "config-get" -> {
+ for (managed_object_instance in managed_object_instances) {
+ // invoke getMOIAttributes for each managed-object-instance
+ log.info("invoke getMOIAttributes for each managed-object-instance")
+ var NRM_Restful_client = RestfulNRMServiceClient()
+ val MOI_id = managed_object_instance.get("id").toString().replace("\"", "")
+ var httpresponse = NRM_Restful_client.getMOIAttributes(web_client_service, MOI_id, managed_object_instance)
+ var MOIname = managed_object_instance.get("className").toString().replace("\"", "")
+ response.put("/$MOIname/$MOI_id", httpresponse)
+ }
+ }
+ "config-modify" -> {
+ for (managed_object_instance in managed_object_instances) {
+ // invoke modifyMOIAttributes for each managed-object-instance
+ log.info("invoke modifyMOIAttributes for each managed-object-instance")
+ var NRM_Restful_client = RestfulNRMServiceClient()
+ val MOI_id = managed_object_instance.get("id").toString().replace("\"", "")
+ var httpresponse = NRM_Restful_client.modifyMOIAttributes(web_client_service, MOI_id, managed_object_instance)
+ var MOIname = managed_object_instance.get("className").toString().replace("\"", "")
+ response.put("/$MOIname/$MOI_id", httpresponse)
+ }
+ }
+ "config-delete" -> {
+ for (managed_object_instance in managed_object_instances) {
+ // invoke deleteMOI for each managed-object-instance
+ log.info("invoke deleteMOI for each managed-object-instance")
+ var NRM_Restful_client = RestfulNRMServiceClient()
+ val MOI_id = managed_object_instance.get("id").toString().replace("\"", "")
+ var httpresponse = NRM_Restful_client.deleteMOI(web_client_service, MOI_id, managed_object_instance)
+ var MOIname = managed_object_instance.get("className").toString().replace("\"", "")
+ response.put("/$MOIname/$MOI_id", httpresponse)
+ }
+ }
+ else -> {
+ print("not Implemented")
+ response.put(this.workflowName, "Not Implemented")
+ }
+ }
+ val strresponse = "$response"
+ return strresponse
+ }
+}
diff --git a/ms/blueprintsprocessor/functions/nrm-restful/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/nrm/restful/RestfulNRMServiceClient.kt b/ms/blueprintsprocessor/functions/restful-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/restful/executor/nrmfunction/RestfulNRMServiceClient.kt
index eb14d255b..31ad377c9 100644
--- a/ms/blueprintsprocessor/functions/nrm-restful/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/nrm/restful/RestfulNRMServiceClient.kt
+++ b/ms/blueprintsprocessor/functions/restful-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/restful/executor/nrmfunction/RestfulNRMServiceClient.kt
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package org.onap.ccsdk.cds.blueprintsprocessor.functions.nrm.restful
+package org.onap.ccsdk.cds.blueprintsprocessor.functions.restful.executor.nrmfunction
import com.fasterxml.jackson.databind.JsonNode
import com.fasterxml.jackson.databind.ObjectMapper
diff --git a/ms/blueprintsprocessor/functions/restful-executor/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/restful/executor/ComponentRestfulExecutorTest.kt b/ms/blueprintsprocessor/functions/restful-executor/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/restful/executor/ComponentRestfulExecutorTest.kt
new file mode 100644
index 000000000..ad70ac021
--- /dev/null
+++ b/ms/blueprintsprocessor/functions/restful-executor/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/restful/executor/ComponentRestfulExecutorTest.kt
@@ -0,0 +1,105 @@
+/*
+ * Copyright © 2020 Huawei 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.cds.blueprintsprocessor.functions.restful.executor
+
+import com.fasterxml.jackson.databind.JsonNode
+import com.fasterxml.jackson.databind.node.ObjectNode
+import io.mockk.every
+import io.mockk.mockk
+import kotlinx.coroutines.runBlocking
+import org.junit.Test
+import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.ActionIdentifiers
+import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.CommonHeader
+import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.ExecutionServiceInput
+import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.StepData
+import org.onap.ccsdk.cds.blueprintsprocessor.services.execution.ComponentFunctionScriptingService
+import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants
+import org.onap.ccsdk.cds.controllerblueprints.core.asJsonPrimitive
+import org.onap.ccsdk.cds.controllerblueprints.core.data.Implementation
+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.springframework.context.ApplicationContext
+
+class ComponentRestfulExecutorTest {
+
+ @Test
+ fun testComponentRestfulExecutor() {
+ runBlocking {
+
+ val applicationContext = mockk<ApplicationContext>()
+ every { applicationContext.getBean(any()) } returns mockk()
+
+ val componentFunctionScriptingService = ComponentFunctionScriptingService(applicationContext, mockk())
+
+ val componentRestfulExecutor = ComponentRestfulExecutor(componentFunctionScriptingService)
+
+ val executionServiceInput = ExecutionServiceInput().apply {
+ commonHeader = CommonHeader().apply {
+ requestId = "1234"
+ }
+ actionIdentifiers = ActionIdentifiers().apply {
+ actionName = "config-deploy"
+ }
+ payload = JacksonUtils.jsonNode("{}") as ObjectNode
+ }
+
+ val blueprintContext = mockk<BluePrintContext>()
+ every {
+ blueprintContext.nodeTemplateOperationImplementation(
+ any(), any(), any()
+ )
+ } returns Implementation()
+
+ val bluePrintRuntime = mockk<DefaultBluePrintRuntimeService>("1234")
+ every { bluePrintRuntime.bluePrintContext() } returns blueprintContext
+
+ componentRestfulExecutor.bluePrintRuntimeService = bluePrintRuntime
+ componentRestfulExecutor.stepName = "sample-step"
+
+ val operationInputs = hashMapOf<String, JsonNode>()
+ operationInputs[BluePrintConstants.PROPERTY_CURRENT_NODE_TEMPLATE] = "config-deploy-process".asJsonPrimitive()
+ operationInputs[BluePrintConstants.PROPERTY_CURRENT_INTERFACE] = "interfaceName".asJsonPrimitive()
+ operationInputs[BluePrintConstants.PROPERTY_CURRENT_OPERATION] = "operationName".asJsonPrimitive()
+ operationInputs["script-type"] = BluePrintConstants.SCRIPT_INTERNAL.asJsonPrimitive()
+ operationInputs["script-class-reference"] = "internal.scripts.TestRestfulConfigure".asJsonPrimitive()
+
+ val stepInputData = StepData().apply {
+ name = "call-config-deploy-process"
+ properties = operationInputs
+ }
+ executionServiceInput.stepData = stepInputData
+
+ every {
+ bluePrintRuntime.resolveNodeTemplateInterfaceOperationInputs(
+ "config-deploy-process",
+ "interfaceName", "operationName"
+ )
+ } returns operationInputs
+
+ val operationOutputs = hashMapOf<String, JsonNode>()
+ every {
+ bluePrintRuntime.resolveNodeTemplateInterfaceOperationOutputs(
+ "config-deploy-process",
+ "interfaceName", "operationName"
+ )
+ } returns operationOutputs
+
+ componentRestfulExecutor.applyNB(executionServiceInput)
+ }
+ }
+}
diff --git a/ms/blueprintsprocessor/functions/nrm-restful/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/nrm/restful/RestfulNRMServiceClientTest.kt b/ms/blueprintsprocessor/functions/restful-executor/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/restful/executor/nrmfunction/RestfulNRMServiceClientTest.kt
index 8dcb7975d..e7f04a5d4 100644
--- a/ms/blueprintsprocessor/functions/nrm-restful/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/nrm/restful/RestfulNRMServiceClientTest.kt
+++ b/ms/blueprintsprocessor/functions/restful-executor/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/restful/executor/nrmfunction/RestfulNRMServiceClientTest.kt
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package org.onap.ccsdk.cds.blueprintsprocessor.functions.nrm.restful
+package org.onap.ccsdk.cds.blueprintsprocessor.functions.restful.executor.nrmfunction
import com.fasterxml.jackson.databind.node.ObjectNode
import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils
diff --git a/ms/blueprintsprocessor/modules/blueprints/blueprint-core/pom.xml b/ms/blueprintsprocessor/modules/blueprints/blueprint-core/pom.xml
index 4700c6337..fb2daab3a 100644
--- a/ms/blueprintsprocessor/modules/blueprints/blueprint-core/pom.xml
+++ b/ms/blueprintsprocessor/modules/blueprints/blueprint-core/pom.xml
@@ -76,6 +76,12 @@
<dependency>
<groupId>org.apache.velocity</groupId>
<artifactId>velocity</artifactId>
+ <exclusions>
+ <exclusion>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-api</artifactId>
+ </exclusion>
+ </exclusions>
</dependency>
<dependency>
<groupId>com.hubspot.jinjava</groupId>
@@ -85,6 +91,10 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.apache.commons</groupId>
+ <artifactId>commons-compress</artifactId>
+ </dependency>
<!--Testing dependencies-->
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
diff --git a/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/BluePrintConstants.kt b/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/BluePrintConstants.kt
index 20aef3498..e26af2b66 100644
--- a/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/BluePrintConstants.kt
+++ b/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/BluePrintConstants.kt
@@ -218,9 +218,6 @@ object BluePrintConstants {
const val DEFAULT_STEP_OPERATION = "process"
const val DEFAULT_STEP_INTERFACE = "ComponentInterface"
- const val ARTIFACT_VELOCITY_TYPE_NAME = "artifact-template-velocity"
- const val ARTIFACT_JINJA_TYPE_NAME = "artifact-template-jinja"
-
const val MODEL_TYPE_ARTIFACT_TEMPLATE_VELOCITY = "artifact-template-velocity"
const val MODEL_TYPE_ARTIFACT_TEMPLATE_JINJA = "artifact-template-jinja"
const val MODEL_TYPE_ARTIFACT_MAPPING_RESOURCE = "artifact-mapping-resource"
@@ -229,6 +226,8 @@ object BluePrintConstants {
const val MODEL_TYPE_ARTIFACT_DIRECTED_GRAPH = "artifact-directed-graph"
const val MODEL_TYPE_ARTIFACT_COMPONENT_JAR = "artifact-component-jar"
+ const val TOSCA_SPEC = "TOSCA"
+
val USE_SCRIPT_COMPILE_CACHE: Boolean = (System.getenv("USE_SCRIPT_COMPILE_CACHE") ?: "true").toBoolean()
const val LOG_PROTECT: String = "log-protect"
diff --git a/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/BluePrintException.kt b/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/BluePrintException.kt
index a2435da13..74e6bb6bd 100644
--- a/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/BluePrintException.kt
+++ b/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/BluePrintException.kt
@@ -1,5 +1,6 @@
/*
* Copyright © 2017-2018 AT&T Intellectual Property.
+ * Modifications Copyright © 2018 - 2020 IBM, Bell Canada.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -21,29 +22,13 @@ package org.onap.ccsdk.cds.controllerblueprints.core
*
* @author Brinda Santh
*/
-class BluePrintException : Exception {
-
- var code: Int = 100
+class BluePrintException : BluePrintProcessorException {
constructor(cause: Throwable) : super(cause)
constructor(message: String) : super(message)
constructor(message: String, cause: Throwable) : super(message, cause)
- constructor(cause: Throwable, message: String, vararg args: Any?) : super(String.format(message, *args), cause)
-
- constructor(code: Int, cause: Throwable) : super(cause) {
- this.code = code
- }
-
- constructor(code: Int, message: String) : super(message) {
- this.code = code
- }
-
- constructor(code: Int, message: String, cause: Throwable) : super(message, cause) {
- this.code = code
- }
-
- constructor(code: Int, cause: Throwable, message: String, vararg args: Any?) :
- super(String.format(message, *args), cause) {
- this.code = code
- }
+ constructor(cause: Throwable, message: String, vararg args: Any?) : super(cause, message, args)
+ constructor(code: Int, cause: Throwable) : super(code, cause)
+ constructor(code: Int, message: String) : super(code, message)
+ constructor(code: Int, message: String, cause: Throwable) : super(code, message, cause)
}
diff --git a/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/BluePrintProcessorException.kt b/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/BluePrintProcessorException.kt
index b0b217051..acb158d89 100644
--- a/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/BluePrintProcessorException.kt
+++ b/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/BluePrintProcessorException.kt
@@ -1,6 +1,6 @@
/*
* Copyright © 2017-2018 AT&T Intellectual Property.
- * Modifications Copyright © 2018 IBM.
+ * Modifications Copyright © 2018 - 2020 IBM, Bell Canada.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -17,35 +17,55 @@
package org.onap.ccsdk.cds.controllerblueprints.core
+import org.onap.ccsdk.cds.error.catalog.core.ErrorCatalogException
+import org.onap.ccsdk.cds.error.catalog.core.ErrorCatalogExceptionFluent
+import org.onap.ccsdk.cds.error.catalog.core.ErrorMessage
+
/**
*
*
* @author Brinda Santh
*/
-class BluePrintProcessorException : RuntimeException {
-
- var code: Int = 100
+open class BluePrintProcessorException : ErrorCatalogException, ErrorCatalogExceptionFluent<BluePrintProcessorException> {
constructor(message: String, cause: Throwable) : super(message, cause)
constructor(message: String) : super(message)
constructor(cause: Throwable) : super(cause)
- constructor(cause: Throwable, message: String, vararg args: Any?) : super(format(message, *args), cause)
+ constructor(cause: Throwable, message: String, vararg args: Any?) : super(cause, message, args)
+ constructor(code: Int, cause: Throwable) : super(code, cause)
+ constructor(code: Int, message: String) : super(code, message)
+ constructor(code: Int, message: String, cause: Throwable) : super(code, message, cause)
+
+ override fun code(code: Int): BluePrintProcessorException {
+ return this.updateCode(code)
+ }
+
+ override fun domain(domain: String): BluePrintProcessorException {
+ return this.updateDomain(domain)
+ }
+
+ override fun action(action: String): BluePrintProcessorException {
+ return this.updateAction(action)
+ }
- constructor(code: Int, cause: Throwable) : super(cause) {
- this.code = code
+ override fun http(type: String): BluePrintProcessorException {
+ return this.updateHttp(type)
}
- constructor(code: Int, message: String) : super(message) {
- this.code = code
+ override fun grpc(type: String): BluePrintProcessorException {
+ return this.updateGrpc(type)
}
- constructor(code: Int, message: String, cause: Throwable) : super(message, cause) {
- this.code = code
+ override fun payloadMessage(message: String): BluePrintProcessorException {
+ return this.updatePayloadMessage(message)
}
- constructor(code: Int, cause: Throwable, message: String, vararg args: Any?) :
- super(String.format(message, *args), cause) {
- this.code = code
+ override fun addErrorPayloadMessage(message: String): BluePrintProcessorException {
+ return this.updateErrorPayloadMessage(message)
+ }
+
+ override fun addSubError(errorMessage: ErrorMessage): BluePrintProcessorException {
+ return this.updateSubError(errorMessage)
}
}
@@ -55,3 +75,65 @@ class BluePrintRetryException : RuntimeException {
constructor(cause: Throwable) : super(cause)
constructor(cause: Throwable, message: String, vararg args: Any?) : super(format(message, *args), cause)
}
+
+/** Extension Functions */
+
+fun processorException(message: String): BluePrintProcessorException {
+ return BluePrintProcessorException(message)
+}
+
+fun processorException(code: Int, message: String): BluePrintProcessorException {
+ return processorException(message).code(code)
+}
+
+fun httpProcessorException(type: String, message: String): BluePrintProcessorException {
+ return processorException(message).http(type)
+}
+
+fun grpcProcessorException(type: String, message: String): BluePrintProcessorException {
+ return processorException(message).grpc(type)
+}
+
+fun httpProcessorException(type: String, domain: String, message: String): BluePrintProcessorException {
+ val bluePrintProcessorException = processorException(message).http(type)
+ return bluePrintProcessorException.addDomainAndErrorMessage(domain, message)
+}
+
+fun grpcProcessorException(type: String, domain: String, message: String): BluePrintProcessorException {
+ val bluePrintProcessorException = processorException(message).grpc(type)
+ return bluePrintProcessorException.addDomainAndErrorMessage(domain, message)
+}
+
+fun httpProcessorException(type: String, domain: String, message: String, cause: Throwable):
+ BluePrintProcessorException {
+ val bluePrintProcessorException = processorException(message).http(type)
+ return bluePrintProcessorException.addDomainAndErrorMessage(domain, message, cause)
+}
+
+fun grpcProcessorException(type: String, domain: String, message: String, cause: Throwable):
+ BluePrintProcessorException {
+ val bluePrintProcessorException = processorException(message).grpc(type)
+ return bluePrintProcessorException.addDomainAndErrorMessage(domain, message, cause)
+}
+
+fun BluePrintProcessorException.updateErrorMessage(domain: String, message: String, cause: Throwable):
+ BluePrintProcessorException {
+ return this.addDomainAndErrorMessage(domain, message, cause).domain(domain)
+ .addErrorPayloadMessage(message)
+ .payloadMessage(message)
+}
+
+fun BluePrintProcessorException.updateErrorMessage(domain: String, message: String): BluePrintProcessorException {
+ return this.addDomainAndErrorMessage(domain, message).domain(domain)
+ .addErrorPayloadMessage(message)
+ .payloadMessage(message)
+}
+
+private fun BluePrintProcessorException.addDomainAndErrorMessage(
+ domain: String,
+ message: String,
+ cause: Throwable = Throwable()
+): BluePrintProcessorException {
+ return this.addSubError(ErrorMessage(domain, message, cause.message
+ ?: "")).domain(domain)
+}
diff --git a/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/interfaces/BluePrintScriptsService.kt b/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/interfaces/BluePrintScriptsService.kt
index aa61b0c4d..0f7cb79f2 100644
--- a/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/interfaces/BluePrintScriptsService.kt
+++ b/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/interfaces/BluePrintScriptsService.kt
@@ -36,4 +36,6 @@ interface BluePrintScriptsService {
suspend fun <T> scriptInstance(cacheKey: String, scriptClassName: String): T
suspend fun <T> scriptInstance(scriptClassName: String): T
+
+ suspend fun cleanupInstance(blueprintBasePath: String)
}
diff --git a/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/scripts/BluePrintCompileService.kt b/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/scripts/BluePrintCompileService.kt
index a8c630387..a9684a14d 100644
--- a/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/scripts/BluePrintCompileService.kt
+++ b/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/scripts/BluePrintCompileService.kt
@@ -25,11 +25,9 @@ import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity
import org.jetbrains.kotlin.cli.common.messages.MessageCollector
import org.jetbrains.kotlin.cli.jvm.K2JVMCompiler
import org.jetbrains.kotlin.config.Services
-import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants
import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintException
import org.onap.ccsdk.cds.controllerblueprints.core.checkFileExists
import org.onap.ccsdk.cds.controllerblueprints.core.logger
-import org.onap.ccsdk.cds.controllerblueprints.core.utils.BluePrintFileUtils
import java.io.File
import java.net.URLClassLoader
import java.util.ArrayList
@@ -58,13 +56,7 @@ open class BluePrintCompileService {
compile(bluePrintSourceCode)
}
- val classLoaderWithDependencies = if (BluePrintConstants.USE_SCRIPT_COMPILE_CACHE) {
- /** Get the class loader with compiled jar from cache */
- BluePrintCompileCache.classLoader(bluePrintSourceCode.cacheKey)
- } else {
- /** Get the class loader with compiled jar from disk */
- BluePrintFileUtils.getURLClassLoaderFromDirectory(bluePrintSourceCode.cacheKey)
- }
+ val classLoaderWithDependencies = BluePrintCompileCache.classLoader(bluePrintSourceCode.cacheKey)
/** Create the instance from the class loader */
return instance(classLoaderWithDependencies, kClassName, args)
@@ -126,9 +118,6 @@ open class BluePrintCompileService {
.single().newInstance(*args.toArray())
} ?: throw BluePrintException("failed to create class($kClassName) instance for constructor argument($args).")
- if (!BluePrintConstants.USE_SCRIPT_COMPILE_CACHE) {
- classLoader.close()
- }
return instance as T
}
}
diff --git a/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/scripts/BluePrintScriptsServiceImpl.kt b/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/scripts/BluePrintScriptsServiceImpl.kt
index f3eb1a2b9..fa8ca2719 100644
--- a/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/scripts/BluePrintScriptsServiceImpl.kt
+++ b/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/scripts/BluePrintScriptsServiceImpl.kt
@@ -79,4 +79,11 @@ open class BluePrintScriptsServiceImpl : BluePrintScriptsService {
return Thread.currentThread().contextClassLoader.loadClass(scriptClassName).constructors
.single().newInstance(*args.toArray()) as T
}
+
+ override suspend fun cleanupInstance(blueprintBasePath: String) {
+ if (!BluePrintConstants.USE_SCRIPT_COMPILE_CACHE) {
+ log.info("Invalidating compile cache for blueprint ($blueprintBasePath)")
+ BluePrintCompileCache.cleanClassLoader(blueprintBasePath)
+ }
+ }
}
diff --git a/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/service/BluePrintTemplateService.kt b/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/service/BluePrintTemplateService.kt
index db733bda1..51a6e10ee 100644
--- a/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/service/BluePrintTemplateService.kt
+++ b/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/service/BluePrintTemplateService.kt
@@ -40,7 +40,7 @@ class BluePrintTemplateService(private val bluePrintLoadConfiguration: BluePrint
val template = bluePrintRuntimeService.resolveNodeTemplateArtifact(nodeTemplateName, artifactName)
return when (templateType) {
- BluePrintConstants.ARTIFACT_JINJA_TYPE_NAME -> {
+ BluePrintConstants.MODEL_TYPE_ARTIFACT_TEMPLATE_JINJA -> {
BluePrintJinjaTemplateService.generateContent(
template,
jsonData,
@@ -51,13 +51,13 @@ class BluePrintTemplateService(private val bluePrintLoadConfiguration: BluePrint
bluePrintRuntimeService.bluePrintContext().version()
)
}
- BluePrintConstants.ARTIFACT_VELOCITY_TYPE_NAME -> {
+ BluePrintConstants.MODEL_TYPE_ARTIFACT_TEMPLATE_VELOCITY -> {
BluePrintVelocityTemplateService.generateContent(template, jsonData, ignoreJsonNull, additionalContext)
}
else -> {
throw BluePrintProcessorException(
- "Unknown Artifact type, expecting ${BluePrintConstants.ARTIFACT_JINJA_TYPE_NAME}" +
- "or ${BluePrintConstants.ARTIFACT_VELOCITY_TYPE_NAME}"
+ "Unknown Artifact type, expecting ${BluePrintConstants.MODEL_TYPE_ARTIFACT_TEMPLATE_JINJA}" +
+ "or ${BluePrintConstants.MODEL_TYPE_ARTIFACT_TEMPLATE_VELOCITY}"
)
}
}
diff --git a/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/utils/BluePrintArchiveUtils.kt b/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/utils/BluePrintArchiveUtils.kt
index 9ccf856b5..595dbce6b 100755
--- a/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/utils/BluePrintArchiveUtils.kt
+++ b/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/utils/BluePrintArchiveUtils.kt
@@ -22,22 +22,39 @@ import com.google.common.base.Predicates
import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintProcessorException
import org.slf4j.LoggerFactory
import java.io.BufferedInputStream
+import java.io.ByteArrayInputStream
import java.io.ByteArrayOutputStream
+import java.io.Closeable
import java.io.File
import java.io.FileOutputStream
+import java.io.InputStream
+import java.io.InputStreamReader
import java.io.IOException
import java.io.OutputStream
-import java.nio.charset.Charset
import java.nio.file.FileVisitResult
import java.nio.file.Files
import java.nio.file.Path
import java.nio.file.SimpleFileVisitor
import java.nio.file.attribute.BasicFileAttributes
import java.util.function.Predicate
+import org.apache.commons.compress.archivers.ArchiveEntry
+import org.apache.commons.compress.archivers.ArchiveInputStream
+import org.apache.commons.compress.archivers.ArchiveOutputStream
+import org.apache.commons.compress.archivers.tar.TarArchiveEntry
+import org.apache.commons.compress.archivers.tar.TarArchiveInputStream
+import org.apache.commons.compress.archivers.tar.TarArchiveOutputStream
+import org.apache.commons.compress.archivers.zip.ZipArchiveEntry
+import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream
+import org.apache.commons.compress.archivers.zip.ZipFile
+import org.apache.commons.compress.compressors.gzip.GzipCompressorInputStream
+import org.apache.commons.compress.compressors.gzip.GzipCompressorOutputStream
+import java.util.Enumeration
import java.util.zip.Deflater
-import java.util.zip.ZipEntry
-import java.util.zip.ZipFile
-import java.util.zip.ZipOutputStream
+
+enum class ArchiveType {
+ TarGz,
+ Zip
+}
class BluePrintArchiveUtils {
@@ -51,7 +68,7 @@ class BluePrintArchiveUtils {
* @param destination the output filename
* @return True if OK
*/
- fun compress(source: File, destination: File): Boolean {
+ fun compress(source: File, destination: File, archiveType: ArchiveType = ArchiveType.Zip): Boolean {
try {
if (!destination.parentFile.exists()) {
destination.parentFile.mkdirs()
@@ -59,7 +76,7 @@ class BluePrintArchiveUtils {
destination.createNewFile()
val ignoreZipFiles = Predicate<Path> { path -> !path.endsWith(".zip") && !path.endsWith(".ZIP") }
FileOutputStream(destination).use { out ->
- compressFolder(source.toPath(), out, pathFilter = ignoreZipFiles)
+ compressFolder(source.toPath(), out, archiveType, pathFilter = ignoreZipFiles)
}
} catch (e: Exception) {
log.error("Fail to compress folder($source) to path(${destination.path})", e)
@@ -71,8 +88,12 @@ class BluePrintArchiveUtils {
/**
* In-memory compress an entire folder.
*/
- fun compressToBytes(baseDir: Path, compressionLevel: Int = Deflater.NO_COMPRESSION): ByteArray {
- return compressFolder(baseDir, ByteArrayOutputStream(), compressionLevel = compressionLevel)
+ fun compressToBytes(
+ baseDir: Path,
+ archiveType: ArchiveType = ArchiveType.Zip,
+ compressionLevel: Int = Deflater.NO_COMPRESSION
+ ): ByteArray {
+ return compressFolder(baseDir, ByteArrayOutputStream(), archiveType, compressionLevel = compressionLevel)
.toByteArray()
}
@@ -89,38 +110,51 @@ class BluePrintArchiveUtils {
private fun <T> compressFolder(
baseDir: Path,
output: T,
+ archiveType: ArchiveType,
pathFilter: Predicate<Path> = Predicates.alwaysTrue(),
compressionLevel: Int = Deflater.DEFAULT_COMPRESSION,
fixedModificationTime: Long? = null
): T
where T : OutputStream {
- ZipOutputStream(output)
- .apply { setLevel(compressionLevel) }
- .use { zos ->
+ val stream: ArchiveOutputStream = if (archiveType == ArchiveType.Zip)
+ ZipArchiveOutputStream(output).apply { setLevel(compressionLevel) }
+ else
+ TarArchiveOutputStream(GzipCompressorOutputStream(output))
+ stream
+ .use { aos ->
Files.walkFileTree(baseDir, object : SimpleFileVisitor<Path>() {
@Throws(IOException::class)
override fun visitFile(file: Path, attrs: BasicFileAttributes): FileVisitResult {
if (pathFilter.test(file)) {
- val zipEntry = ZipEntry(baseDir.relativize(file).toString())
- fixedModificationTime?.let {
- zipEntry.time = it
+ var archiveEntry: ArchiveEntry = aos.createArchiveEntry(file.toFile(),
+ baseDir.relativize(file).toString())
+ if (archiveType == ArchiveType.Zip) {
+ val entry = archiveEntry as ZipArchiveEntry
+ fixedModificationTime?.let {
+ entry.time = it
+ }
+ entry.time = 0
}
- zipEntry.time = 0
- zos.putNextEntry(zipEntry)
- Files.copy(file, zos)
- zos.closeEntry()
+ aos.putArchiveEntry(archiveEntry)
+ Files.copy(file, aos)
+ aos.closeArchiveEntry()
}
return FileVisitResult.CONTINUE
}
@Throws(IOException::class)
override fun preVisitDirectory(dir: Path, attrs: BasicFileAttributes): FileVisitResult {
- val zipEntry = ZipEntry(baseDir.relativize(dir).toString() + "/")
- fixedModificationTime?.let {
- zipEntry.time = it
- }
- zos.putNextEntry(zipEntry)
- zos.closeEntry()
+ var archiveEntry: ArchiveEntry?
+ if (archiveType == ArchiveType.Zip) {
+ val entry = ZipArchiveEntry(baseDir.relativize(dir).toString() + "/")
+ fixedModificationTime?.let {
+ entry.time = it
+ }
+ archiveEntry = entry
+ } else
+ archiveEntry = TarArchiveEntry(baseDir.relativize(dir).toString() + "/")
+ aos.putArchiveEntry(archiveEntry)
+ aos.closeArchiveEntry()
return FileVisitResult.CONTINUE
}
})
@@ -128,31 +162,111 @@ class BluePrintArchiveUtils {
return output
}
- fun deCompress(zipFile: File, targetPath: String): File {
- val zip = ZipFile(zipFile, Charset.defaultCharset())
- val enumeration = zip.entries()
- while (enumeration.hasMoreElements()) {
- val entry = enumeration.nextElement()
- val destFilePath = File(targetPath, entry.name)
- destFilePath.parentFile.mkdirs()
+ private fun getDefaultEncoding(): String? {
+ val bytes = byteArrayOf('D'.toByte())
+ val inputStream: InputStream = ByteArrayInputStream(bytes)
+ val reader = InputStreamReader(inputStream)
+ return reader.encoding
+ }
- if (entry.isDirectory)
- continue
+ fun deCompress(archiveFile: File, targetPath: String, archiveType: ArchiveType = ArchiveType.Zip): File {
+ var enumeration: ArchiveEnumerator? = null
+ if (archiveType == ArchiveType.Zip) {
+ val zipArchive = ZipFile(archiveFile, getDefaultEncoding())
+ enumeration = ArchiveEnumerator(zipArchive)
+ } else { // Tar Gz
+ var tarGzArchiveIs: InputStream = BufferedInputStream(archiveFile.inputStream())
+ tarGzArchiveIs = GzipCompressorInputStream(tarGzArchiveIs)
+ val tarGzArchive: ArchiveInputStream = TarArchiveInputStream(tarGzArchiveIs)
+ enumeration = ArchiveEnumerator(tarGzArchive)
+ }
+
+ enumeration.use {
+ while (enumeration!!.hasMoreElements()) {
+ val entry: ArchiveEntry? = enumeration.nextElement()
+ val destFilePath = File(targetPath, entry!!.name)
+ destFilePath.parentFile.mkdirs()
- val bufferedIs = BufferedInputStream(zip.getInputStream(entry))
- bufferedIs.use {
+ if (entry!!.isDirectory)
+ continue
+
+ val bufferedIs = BufferedInputStream(enumeration.getInputStream(entry))
destFilePath.outputStream().buffered(1024).use { bos ->
bufferedIs.copyTo(bos)
}
+
+ if (!enumeration.getHasSharedEntryInputStream())
+ bufferedIs.close()
}
}
val destinationDir = File(targetPath)
check(destinationDir.isDirectory && destinationDir.exists()) {
- throw BluePrintProcessorException("failed to decompress blueprint(${zipFile.absolutePath}) to ($targetPath) ")
+ throw BluePrintProcessorException("failed to decompress blueprint(${archiveFile.absolutePath}) to ($targetPath) ")
}
return destinationDir
}
}
+
+ class ArchiveEnumerator : Enumeration<ArchiveEntry>, Closeable {
+ private val zipArchive: ZipFile?
+ private val zipEnumeration: Enumeration<ZipArchiveEntry>?
+ private val archiveStream: ArchiveInputStream?
+ private var nextEntry: ArchiveEntry? = null
+ private val hasSharedEntryInputStream: Boolean
+
+ constructor(zipFile: ZipFile) {
+ zipArchive = zipFile
+ zipEnumeration = zipFile.entries
+ archiveStream = null
+ hasSharedEntryInputStream = false
+ }
+
+ constructor(archiveStream: ArchiveInputStream) {
+ this.archiveStream = archiveStream
+ zipArchive = null
+ zipEnumeration = null
+ hasSharedEntryInputStream = true
+ }
+
+ fun getHasSharedEntryInputStream(): Boolean {
+ return hasSharedEntryInputStream
+ }
+
+ fun getInputStream(entry: ArchiveEntry): InputStream? {
+ return if (zipArchive != null)
+ zipArchive?.getInputStream(entry as ZipArchiveEntry?)
+ else
+ archiveStream
+ }
+
+ override fun hasMoreElements(): Boolean {
+ if (zipEnumeration != null)
+ return zipEnumeration?.hasMoreElements()
+ else if (archiveStream != null) {
+ nextEntry = archiveStream.nextEntry
+ if (nextEntry != null && !archiveStream.canReadEntryData(nextEntry))
+ return hasMoreElements()
+ return nextEntry != null
+ }
+ return false
+ }
+
+ override fun nextElement(): ArchiveEntry? {
+ if (zipEnumeration != null)
+ nextEntry = zipEnumeration.nextElement()
+ else if (archiveStream != null) {
+ if (nextEntry == null)
+ nextEntry = archiveStream.nextEntry
+ }
+ return nextEntry
+ }
+
+ override fun close() {
+ if (zipArchive != null)
+ zipArchive.close()
+ else archiveStream?.close()
+ }
+ }
}
diff --git a/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/utils/JacksonUtils.kt b/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/utils/JacksonUtils.kt
index 3db1f84cd..573fc17d2 100644
--- a/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/utils/JacksonUtils.kt
+++ b/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/utils/JacksonUtils.kt
@@ -133,9 +133,13 @@ class JacksonUtils {
return getJson(wrapperMap, pretty)
}
- fun getJson(any: kotlin.Any, pretty: Boolean = false): String {
+ fun getJson(any: kotlin.Any, pretty: Boolean = false, includeNull: Boolean = false): String {
val objectMapper = jacksonObjectMapper()
- objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL)
+ if (includeNull) {
+ objectMapper.setSerializationInclusion(JsonInclude.Include.ALWAYS)
+ } else {
+ objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL)
+ }
if (pretty) {
objectMapper.enable(SerializationFeature.INDENT_OUTPUT)
}
diff --git a/ms/blueprintsprocessor/modules/blueprints/blueprint-proto/pom.xml b/ms/blueprintsprocessor/modules/blueprints/blueprint-proto/pom.xml
index b208cbda5..1e90cca76 100644
--- a/ms/blueprintsprocessor/modules/blueprints/blueprint-proto/pom.xml
+++ b/ms/blueprintsprocessor/modules/blueprints/blueprint-proto/pom.xml
@@ -28,6 +28,10 @@
<name>Controller Blueprints Proto</name>
<description>Controller Blueprints Proto</description>
+ <properties>
+ <sonar.skip>true</sonar.skip>
+ </properties>
+
<dependencies>
<dependency>
<groupId>com.github.marcoferrer.krotoplus</groupId>
diff --git a/ms/blueprintsprocessor/modules/blueprints/pom.xml b/ms/blueprintsprocessor/modules/blueprints/pom.xml
index cd6a17e88..527a5bf98 100644
--- a/ms/blueprintsprocessor/modules/blueprints/pom.xml
+++ b/ms/blueprintsprocessor/modules/blueprints/pom.xml
@@ -14,7 +14,6 @@
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
-
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
diff --git a/ms/blueprintsprocessor/modules/blueprints/resource-dict/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/resource/dict/ResourceDefinition.kt b/ms/blueprintsprocessor/modules/blueprints/resource-dict/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/resource/dict/ResourceDefinition.kt
index 4ed98ddd0..77025c5a4 100644
--- a/ms/blueprintsprocessor/modules/blueprints/resource-dict/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/resource/dict/ResourceDefinition.kt
+++ b/ms/blueprintsprocessor/modules/blueprints/resource-dict/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/resource/dict/ResourceDefinition.kt
@@ -19,6 +19,7 @@ package org.onap.ccsdk.cds.controllerblueprints.resource.dict
import com.fasterxml.jackson.annotation.JsonFormat
import com.fasterxml.jackson.annotation.JsonProperty
+import com.fasterxml.jackson.databind.JsonNode
import org.onap.ccsdk.cds.controllerblueprints.core.data.NodeTemplate
import org.onap.ccsdk.cds.controllerblueprints.core.data.PropertyDefinition
import java.io.Serializable
@@ -87,6 +88,9 @@ open class ResourceAssignment {
@JsonProperty("updated-by")
var updatedBy: String? = null
+ /** input & output key-mapping with their resolved values **/
+ var keyIdentifiers: MutableList<KeyIdentifier> = mutableListOf()
+
override fun toString(): String {
return """
[
@@ -101,6 +105,33 @@ open class ResourceAssignment {
}
}
+data class KeyIdentifier(val name: String, val value: JsonNode)
+data class DictionaryMetadataEntry(val name: String, val value: String)
+/**
+ * Data class for exposing summary of resource resolution
+ */
+data class ResolutionSummary(
+ val name: String,
+ val value: JsonNode?,
+ val required: Boolean?,
+ val type: String?,
+ @JsonProperty("key-identifiers")
+ val keyIdentifiers: MutableList<KeyIdentifier>,
+ @JsonProperty("dictionary-description")
+ val dictionaryDescription: String?,
+ @JsonProperty("dictionary-metadata")
+ val dictionaryMetadata: MutableList<DictionaryMetadataEntry>,
+ @JsonProperty("dictionary-name")
+ val dictionaryName: String?,
+ @JsonProperty("dictionary-source")
+ val dictionarySource: String?,
+ @JsonProperty("request-payload")
+ val requestPayload: JsonNode?,
+ @JsonProperty("status")
+ val status: String?,
+ @JsonProperty("message")
+ val message: String?
+)
/**
* Interface for Source Definitions (ex Input Source,
* Default Source, Database Source, Rest Sources, etc)
diff --git a/ms/blueprintsprocessor/modules/commons/nats-lib/pom.xml b/ms/blueprintsprocessor/modules/commons/nats-lib/pom.xml
index f4e7f4d98..f28a7132e 100644
--- a/ms/blueprintsprocessor/modules/commons/nats-lib/pom.xml
+++ b/ms/blueprintsprocessor/modules/commons/nats-lib/pom.xml
@@ -14,7 +14,6 @@
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
-
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
diff --git a/ms/blueprintsprocessor/modules/commons/processor-core/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/core/cluster/HazlecastClusterService.kt b/ms/blueprintsprocessor/modules/commons/processor-core/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/core/cluster/HazlecastClusterService.kt
index 6be3334bb..a58c077fa 100644
--- a/ms/blueprintsprocessor/modules/commons/processor-core/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/core/cluster/HazlecastClusterService.kt
+++ b/ms/blueprintsprocessor/modules/commons/processor-core/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/core/cluster/HazlecastClusterService.kt
@@ -243,8 +243,11 @@ open class ClusterLockImpl(private val hazelcast: HazelcastInstance, private val
}
override suspend fun unLock() {
- distributedLock.unlock()
- log.trace("Cluster unlock(${name()}) successfully..")
+ // Added condition to avoid failures like - "Current thread is not owner of the lock!"
+ if (distributedLock.isLockedByCurrentThread) {
+ distributedLock.unlock()
+ log.trace("Cluster unlock(${name()}) successfully..")
+ }
}
override fun isLocked(): Boolean {
diff --git a/ms/blueprintsprocessor/modules/commons/processor-core/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/core/cluster/HazlecastClusterServiceTest.kt b/ms/blueprintsprocessor/modules/commons/processor-core/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/core/cluster/HazlecastClusterServiceTest.kt
index b298eacae..80cf41558 100644
--- a/ms/blueprintsprocessor/modules/commons/processor-core/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/core/cluster/HazlecastClusterServiceTest.kt
+++ b/ms/blueprintsprocessor/modules/commons/processor-core/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/core/cluster/HazlecastClusterServiceTest.kt
@@ -113,7 +113,7 @@ class HazlecastClusterServiceTest {
} else {
ClusterInfo(
id = "test-cluster", nodeId = nodeId, joinAsClient = false,
- configFile = "./src/test/resources/hazelcast/hazelcast-$port.yaml",
+ configFile = "./src/test/resources/hazelcast/hazelcast-cluster.yaml",
properties = properties
)
}
@@ -162,7 +162,7 @@ class HazlecastClusterServiceTest {
executeLock(bluePrintClusterServices[0], "first", lockName)
}
val deferred2 = async {
- executeLock(bluePrintClusterServices[0], "second", lockName)
+ executeLock(bluePrintClusterServices[1], "second", lockName)
}
val deferred3 = async {
executeLock(bluePrintClusterServices[2], "third", lockName)
diff --git a/ms/blueprintsprocessor/modules/commons/processor-core/src/test/resources/hazelcast/hazelcast-5679.yaml b/ms/blueprintsprocessor/modules/commons/processor-core/src/test/resources/hazelcast/hazelcast-5679.yaml
deleted file mode 100644
index e7ac273ed..000000000
--- a/ms/blueprintsprocessor/modules/commons/processor-core/src/test/resources/hazelcast/hazelcast-5679.yaml
+++ /dev/null
@@ -1,21 +0,0 @@
-hazelcast:
- cluster-name: ${CLUSTER_ID}
- instance-name: node-5679
- lite-member:
- enabled: false
- cp-subsystem:
- cp-member-count: 3
- group-size: 3
- session-time-to-live-seconds: 60
- session-heartbeat-interval-seconds: 5
- missing-cp-member-auto-removal-seconds: 120
-# network:
-# join:
-# multicast:
-# enabled: false
-# kubernetes:
-# enabled: true
-# namespace: MY-KUBERNETES-NAMESPACE
-# service-name: MY-SERVICE-NAME
-# service-label-name: MY-SERVICE-LABEL-NAME
-# service-label-value: MY-SERVICE-LABEL-VALUE \ No newline at end of file
diff --git a/ms/blueprintsprocessor/modules/commons/processor-core/src/test/resources/hazelcast/hazelcast-5680.yaml b/ms/blueprintsprocessor/modules/commons/processor-core/src/test/resources/hazelcast/hazelcast-5680.yaml
deleted file mode 100644
index cb493d169..000000000
--- a/ms/blueprintsprocessor/modules/commons/processor-core/src/test/resources/hazelcast/hazelcast-5680.yaml
+++ /dev/null
@@ -1,21 +0,0 @@
-hazelcast:
- cluster-name: ${CLUSTER_ID}
- instance-name: node-5680
- lite-member:
- enabled: false
- cp-subsystem:
- cp-member-count: 3
- group-size: 3
- session-time-to-live-seconds: 60
- session-heartbeat-interval-seconds: 5
- missing-cp-member-auto-removal-seconds: 120
-# network:
-# join:
-# multicast:
-# enabled: false
-# kubernetes:
-# enabled: true
-# namespace: MY-KUBERNETES-NAMESPACE
-# service-name: MY-SERVICE-NAME
-# service-label-name: MY-SERVICE-LABEL-NAME
-# service-label-value: MY-SERVICE-LABEL-VALUE \ No newline at end of file
diff --git a/ms/blueprintsprocessor/modules/commons/processor-core/src/test/resources/hazelcast/hazelcast-5681.yaml b/ms/blueprintsprocessor/modules/commons/processor-core/src/test/resources/hazelcast/hazelcast-5681.yaml
deleted file mode 100644
index e60b0c506..000000000
--- a/ms/blueprintsprocessor/modules/commons/processor-core/src/test/resources/hazelcast/hazelcast-5681.yaml
+++ /dev/null
@@ -1,21 +0,0 @@
-hazelcast:
- cluster-name: ${CLUSTER_ID}
- instance-name: node-5681
- lite-member:
- enabled: false
- cp-subsystem:
- cp-member-count: 3
- group-size: 3
- session-time-to-live-seconds: 60
- session-heartbeat-interval-seconds: 5
- missing-cp-member-auto-removal-seconds: 120
-# network:
-# join:
-# multicast:
-# enabled: false
-# kubernetes:
-# enabled: true
-# namespace: MY-KUBERNETES-NAMESPACE
-# service-name: MY-SERVICE-NAME
-# service-label-name: MY-SERVICE-LABEL-NAME
-# service-label-value: MY-SERVICE-LABEL-VALUE \ No newline at end of file
diff --git a/ms/blueprintsprocessor/modules/commons/processor-core/src/test/resources/hazelcast/hazelcast-5682.yaml b/ms/blueprintsprocessor/modules/commons/processor-core/src/test/resources/hazelcast/hazelcast-5682.yaml
index 3cb10a08b..859ea3328 100644
--- a/ms/blueprintsprocessor/modules/commons/processor-core/src/test/resources/hazelcast/hazelcast-5682.yaml
+++ b/ms/blueprintsprocessor/modules/commons/processor-core/src/test/resources/hazelcast/hazelcast-5682.yaml
@@ -9,10 +9,11 @@ hazelcast:
session-time-to-live-seconds: 60
session-heartbeat-interval-seconds: 5
missing-cp-member-auto-removal-seconds: 120
-# network:
-# join:
-# multicast:
-# enabled: false
+ network:
+ join:
+ multicast:
+ enabled: true
+ multicast-group: 224.0.0.1
# kubernetes:
# enabled: true
# namespace: MY-KUBERNETES-NAMESPACE
diff --git a/ms/blueprintsprocessor/modules/commons/processor-core/src/test/resources/hazelcast/hazelcast-cluster.yaml b/ms/blueprintsprocessor/modules/commons/processor-core/src/test/resources/hazelcast/hazelcast-cluster.yaml
new file mode 100644
index 000000000..de6047a90
--- /dev/null
+++ b/ms/blueprintsprocessor/modules/commons/processor-core/src/test/resources/hazelcast/hazelcast-cluster.yaml
@@ -0,0 +1,23 @@
+hazelcast:
+ lite-member:
+ enabled: false
+ cp-subsystem:
+ cp-member-count: 3
+ group-size: 3
+ session-time-to-live-seconds: 60
+ session-heartbeat-interval-seconds: 5
+ missing-cp-member-auto-removal-seconds: 120
+ network:
+ join:
+ multicast:
+ enabled: true
+ # Specify 224.0.0.1 instead of default 224.2.2.3 since there's some issue
+ # on macOs with docker installed and multicast address different than 224.0.0.1
+ # https://stackoverflow.com/questions/46341715/hazelcast-multicast-does-not-work-because-of-vboxnet-which-is-used-by-docker-mac
+ multicast-group: 224.0.0.1
+ # kubernetes:
+ # enabled: true
+ # namespace: MY-KUBERNETES-NAMESPACE
+ # service-name: MY-SERVICE-NAME
+ # service-label-name: MY-SERVICE-LABEL-NAME
+ # service-label-value: MY-SERVICE-LABEL-VALUE
diff --git a/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/service/BasicAuthRestClientService.kt b/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/service/BasicAuthRestClientService.kt
index 540b3d9ad..bfc0a5cd4 100644
--- a/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/service/BasicAuthRestClientService.kt
+++ b/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/service/BasicAuthRestClientService.kt
@@ -20,6 +20,7 @@ import org.apache.http.message.BasicHeader
import org.onap.ccsdk.cds.blueprintsprocessor.rest.BasicAuthRestClientProperties
import org.springframework.http.HttpHeaders
import org.springframework.http.MediaType
+import java.net.URI
import java.nio.charset.Charset
import java.util.Base64
@@ -43,7 +44,8 @@ class BasicAuthRestClientService(
}
override fun host(uri: String): String {
- return restClientProperties.url + uri
+ val uri: URI = URI.create(restClientProperties.url + uri)
+ return uri.resolve(uri).toString()
}
override fun convertToBasicHeaders(headers: Map<String, String>):
diff --git a/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/BlueprintModelController.kt b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/BlueprintModelController.kt
index bb824ce4d..1f01d1ce3 100644
--- a/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/BlueprintModelController.kt
+++ b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/BlueprintModelController.kt
@@ -26,6 +26,7 @@ import org.onap.ccsdk.cds.blueprintsprocessor.designer.api.handler.BluePrintMode
import org.onap.ccsdk.cds.blueprintsprocessor.designer.api.utils.BlueprintSortByOption
import org.onap.ccsdk.cds.blueprintsprocessor.rest.service.mdcWebCoroutineScope
import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintException
+import org.onap.ccsdk.cds.controllerblueprints.core.asJsonString
import org.springframework.core.io.Resource
import org.springframework.data.domain.Page
import org.springframework.data.domain.PageRequest
@@ -208,4 +209,42 @@ open class BlueprintModelController(private val bluePrintModelHandler: BluePrint
) = mdcWebCoroutineScope {
bluePrintModelHandler.deleteBlueprintModel(name, version)
}
+
+ @PostMapping(
+ path = arrayOf("/workflow-spec"), produces = arrayOf(
+ MediaType
+ .APPLICATION_JSON_VALUE
+ ),
+ consumes = arrayOf(MediaType.APPLICATION_JSON_VALUE)
+ )
+ @ResponseBody
+ @Throws(BluePrintException::class)
+ @PreAuthorize("hasRole('USER')")
+ suspend fun workflowSpec(@RequestBody workFlowSpecReq: WorkFlowSpecRequest):
+ ResponseEntity<String> = mdcWebCoroutineScope {
+ var json = bluePrintModelHandler.prepareWorkFlowSpec(workFlowSpecReq)
+ .asJsonString()
+ ResponseEntity(json, HttpStatus.OK)
+ }
+
+ @GetMapping(
+ path = arrayOf(
+ "/workflows/blueprint-name/{name}/version/{version" +
+ "}"
+ ),
+ produces = arrayOf(MediaType.APPLICATION_JSON_VALUE)
+ )
+ @ResponseBody
+ @Throws(BluePrintException::class)
+ @PreAuthorize("hasRole('USER')")
+ suspend fun getWorkflowList(
+ @ApiParam(value = "Name of the CBA.", required = true)
+ @PathVariable(value = "name") name: String,
+ @ApiParam(value = "Version of the CBA.", required = true)
+ @PathVariable(value = "version") version: String
+ ): ResponseEntity<String> = mdcWebCoroutineScope {
+ var json = bluePrintModelHandler.getWorkflowNames(name, version)
+ .asJsonString()
+ ResponseEntity(json, HttpStatus.OK)
+ }
}
diff --git a/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/DesignerApiData.kt b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/DesignerApiData.kt
index d0cb67315..369844445 100644
--- a/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/DesignerApiData.kt
+++ b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/DesignerApiData.kt
@@ -22,6 +22,11 @@ import com.fasterxml.jackson.annotation.JsonInclude
import com.fasterxml.jackson.annotation.JsonTypeInfo
import com.fasterxml.jackson.annotation.JsonTypeName
import org.onap.ccsdk.cds.blueprintsprocessor.designer.api.domain.ResourceDictionary
+import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants.DATA_TYPE_JSON
+import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants.DEFAULT_VERSION_NUMBER
+import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants.TOSCA_SPEC
+import org.onap.ccsdk.cds.controllerblueprints.core.data.DataType
+import org.onap.ccsdk.cds.controllerblueprints.core.data.PropertyDefinition
import org.onap.ccsdk.cds.controllerblueprints.resource.dict.ResourceAssignment
import java.io.Serializable
import java.util.Date
@@ -32,6 +37,33 @@ class BootstrapRequest {
var loadCBA: Boolean = false
}
+class WorkFlowsResponse {
+ lateinit var blueprintName: String
+ var version: String = DEFAULT_VERSION_NUMBER
+ var workflows: MutableSet<String> = mutableSetOf()
+}
+
+class WorkFlowSpecRequest {
+ lateinit var blueprintName: String
+ var version: String = DEFAULT_VERSION_NUMBER
+ var returnContent: String = DATA_TYPE_JSON
+ lateinit var workflowName: String
+ var specType: String = TOSCA_SPEC
+}
+
+class WorkFlowSpecResponse {
+ lateinit var blueprintName: String
+ var version: String = DEFAULT_VERSION_NUMBER
+ lateinit var workFlowData: WorkFlowData
+ var dataTypes: MutableMap<String, DataType>? = mutableMapOf()
+}
+
+class WorkFlowData {
+ lateinit var workFlowName: String
+ var inputs: MutableMap<String, PropertyDefinition>? = null
+ var outputs: MutableMap<String, PropertyDefinition>? = null
+}
+
/**
* ArtifactRequest.java Purpose: Provide Configuration Generator ArtifactRequest Model
*
diff --git a/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/ErrorHandling.kt b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/ErrorHandling.kt
new file mode 100644
index 000000000..ae91246fe
--- /dev/null
+++ b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/ErrorHandling.kt
@@ -0,0 +1,40 @@
+/*
+ * Copyright © 2018-2019 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.cds.blueprintsprocessor.designer.api
+
+object DesignerApiDomains {
+ // Designer Api Domains Constants
+ const val DESIGNER_API = "org.onap.ccsdk.cds.blueprintsprocessor.designer.api"
+ const val DESIGNER_API_ENHANCER = "org.onap.ccsdk.cds.blueprintsprocessor.designer.api.enhancer"
+ const val DESIGNER_API_HANDLER = "org.onap.ccsdk.cds.blueprintsprocessor.designer.api.handler"
+ const val DESIGNER_API_LOAD = "org.onap.ccsdk.cds.blueprintsprocessor.designer.api.load"
+ const val DESIGNER_API_SERVICE = "org.onap.ccsdk.cds.blueprintsprocessor.designer.api.service"
+}
+
+object DesignerApiHttpErrorCodes {
+ init {
+ // Register HttpErrorCodes
+ // HttpErrorCodes.register("", 200)
+ }
+}
+
+object DesignerGrpcErrorCodes {
+ init {
+ // Register GrpcErrorCodes
+ // GrpcErrorCodes.register("", 3)
+ }
+}
diff --git a/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/handler/BluePrintModelHandler.kt b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/handler/BluePrintModelHandler.kt
index 274650ae4..e9839328b 100644
--- a/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/handler/BluePrintModelHandler.kt
+++ b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/handler/BluePrintModelHandler.kt
@@ -25,10 +25,15 @@ import org.onap.ccsdk.cds.blueprintsprocessor.db.primary.repository.BlueprintMod
import org.onap.ccsdk.cds.blueprintsprocessor.db.primary.repository.BlueprintModelRepository
import org.onap.ccsdk.cds.blueprintsprocessor.db.primary.repository.BlueprintModelSearchRepository
import org.onap.ccsdk.cds.blueprintsprocessor.designer.api.BootstrapRequest
+import org.onap.ccsdk.cds.blueprintsprocessor.designer.api.WorkFlowData
+import org.onap.ccsdk.cds.blueprintsprocessor.designer.api.WorkFlowSpecRequest
+import org.onap.ccsdk.cds.blueprintsprocessor.designer.api.WorkFlowSpecResponse
+import org.onap.ccsdk.cds.blueprintsprocessor.designer.api.WorkFlowsResponse
import org.onap.ccsdk.cds.blueprintsprocessor.designer.api.load.BluePrintDatabaseLoadService
import org.onap.ccsdk.cds.blueprintsprocessor.designer.api.utils.BluePrintEnhancerUtils
import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintException
import org.onap.ccsdk.cds.controllerblueprints.core.config.BluePrintLoadConfiguration
+import org.onap.ccsdk.cds.controllerblueprints.core.data.DataType
import org.onap.ccsdk.cds.controllerblueprints.core.data.ErrorCode
import org.onap.ccsdk.cds.controllerblueprints.core.deleteNBDir
import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BluePrintCatalogService
@@ -37,7 +42,9 @@ import org.onap.ccsdk.cds.controllerblueprints.core.logger
import org.onap.ccsdk.cds.controllerblueprints.core.normalizedFile
import org.onap.ccsdk.cds.controllerblueprints.core.normalizedPathName
import org.onap.ccsdk.cds.controllerblueprints.core.scripts.BluePrintCompileCache
+import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintContext
import org.onap.ccsdk.cds.controllerblueprints.core.utils.BluePrintFileUtils
+import org.onap.ccsdk.cds.controllerblueprints.core.utils.BluePrintMetadataUtils
import org.springframework.core.io.ByteArrayResource
import org.springframework.core.io.Resource
import org.springframework.data.domain.Page
@@ -89,6 +96,68 @@ open class BluePrintModelHandler(
}
}
+ @Throws(BluePrintException::class)
+ open suspend fun prepareWorkFlowSpec(req: WorkFlowSpecRequest):
+ WorkFlowSpecResponse {
+ val basePath = blueprintsProcessorCatalogService.getFromDatabase(req
+ .blueprintName, req.version)
+ log.info("blueprint base path $basePath")
+
+ val blueprintContext = BluePrintMetadataUtils.getBluePrintContext(basePath.toString())
+ val workFlow = blueprintContext.workflowByName(req.workflowName)
+
+ val wfRes = WorkFlowSpecResponse()
+ wfRes.blueprintName = req.blueprintName
+ wfRes.version = req.version
+
+ val workFlowData = WorkFlowData()
+ workFlowData.workFlowName = req.workflowName
+ workFlowData.inputs = workFlow.inputs
+ workFlowData.outputs = workFlow.outputs
+
+ for ((k, v) in workFlow.inputs!!) {
+ addDataType(v.type, blueprintContext, wfRes)
+ }
+
+ for ((k, v) in workFlow.outputs!!) {
+ addDataType(v.type, blueprintContext, wfRes)
+ }
+ wfRes.workFlowData = workFlowData
+ return wfRes
+ }
+
+ private fun addDataType(name: String, ctx: BluePrintContext, res: WorkFlowSpecResponse) {
+ var data = ctx.dataTypeByName(name)
+ if (data != null) {
+ res.dataTypes?.put(name, data)
+ addParentDataType(data, ctx, res)
+ }
+ }
+
+ private fun addParentDataType(data: DataType, ctx: BluePrintContext, res: WorkFlowSpecResponse) {
+ for ((k, v) in data.properties!!) {
+ addDataType(v.type, ctx, res)
+ }
+ }
+
+ @Throws(BluePrintException::class)
+ open suspend fun getWorkflowNames(name: String, version: String): WorkFlowsResponse {
+ val basePath = blueprintsProcessorCatalogService.getFromDatabase(
+ name, version)
+ log.info("blueprint base path $basePath")
+
+ var res = WorkFlowsResponse()
+ res.blueprintName = name
+ res.version = version
+
+ val blueprintContext = BluePrintMetadataUtils.getBluePrintContext(
+ basePath.toString())
+ if (blueprintContext.workflows() != null) {
+ res.workflows = blueprintContext.workflows()!!.keys
+ }
+ return res
+ }
+
/**
* This is a getAllBlueprintModel method to retrieve all the BlueprintModel in Database
*
diff --git a/ms/blueprintsprocessor/modules/inbounds/resource-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/resource/api/ErrorHandling.kt b/ms/blueprintsprocessor/modules/inbounds/resource-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/resource/api/ErrorHandling.kt
new file mode 100644
index 000000000..b37cd0eda
--- /dev/null
+++ b/ms/blueprintsprocessor/modules/inbounds/resource-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/resource/api/ErrorHandling.kt
@@ -0,0 +1,36 @@
+/*
+ * Copyright © 2018-2019 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.cds.blueprintsprocessor.resource.api
+
+object ResourceApiDomains {
+ // Resource Api Domains Constants
+ const val RESOURCE_API = "org.onap.ccsdk.cds.blueprintsprocessor.resource.api"
+}
+
+object ResourceApiHttpErrorCodes {
+ init {
+ // Register HttpErrorCodes
+ // HttpErrorCodes.register("", 200)
+ }
+}
+
+object ResourceGrpcErrorCodes {
+ init {
+ // Register GrpcErrorCodes
+ // GrpcErrorCodes.register("", 3)
+ }
+}
diff --git a/ms/blueprintsprocessor/modules/inbounds/resource-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/resource/api/ResourceController.kt b/ms/blueprintsprocessor/modules/inbounds/resource-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/resource/api/ResourceController.kt
index b49ca68ed..264cd23ff 100644
--- a/ms/blueprintsprocessor/modules/inbounds/resource-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/resource/api/ResourceController.kt
+++ b/ms/blueprintsprocessor/modules/inbounds/resource-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/resource/api/ResourceController.kt
@@ -103,6 +103,28 @@ open class ResourceController(private var resourceResolutionDBService: ResourceR
}
@RequestMapping(
+ path = [""],
+ method = [RequestMethod.DELETE], produces = [MediaType.APPLICATION_JSON_VALUE]
+ )
+ @ApiOperation(value = "Delete resources using resolution key",
+ notes = "Delete all the resources associated to a resolution-key using blueprint metadata, artifact name and the resolution-key.",
+ produces = MediaType.APPLICATION_JSON_VALUE)
+ @PreAuthorize("hasRole('USER')")
+ fun deleteByBlueprintNameAndBlueprintVersionAndArtifactNameAndResolutionKey(
+ @ApiParam(value = "Name of the CBA.", required = true)
+ @RequestParam(value = "bpName", required = true) bpName: String,
+ @ApiParam(value = "Version of the CBA.", required = true)
+ @RequestParam(value = "bpVersion", required = true) bpVersion: String,
+ @ApiParam(value = "Artifact name for which to retrieve a resolved resource.", required = true)
+ @RequestParam(value = "artifactName", required = false, defaultValue = "") artifactName: String,
+ @ApiParam(value = "Resolution Key associated with the resolution.", required = true)
+ @RequestParam(value = "resolutionKey", required = true) resolutionKey: String
+ ) = runBlocking {
+ ResponseEntity.ok()
+ .body(resourceResolutionDBService.deleteByBlueprintNameAndBlueprintVersionAndArtifactNameAndResolutionKey(bpName, bpVersion, artifactName, resolutionKey))
+ }
+
+ @RequestMapping(
path = ["/resource"],
method = [RequestMethod.GET],
produces = [MediaType.APPLICATION_JSON_VALUE]
diff --git a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/ErrorHandling.kt b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/ErrorHandling.kt
new file mode 100644
index 000000000..b76bc263a
--- /dev/null
+++ b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/ErrorHandling.kt
@@ -0,0 +1,44 @@
+/*
+ * Copyright © 2018-2019 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.cds.blueprintsprocessor.selfservice.api
+
+object SelfServiceApiDomains {
+ // SelfServiceApi Domains Constants
+ const val BLUEPRINT_PROCESSOR = "org.onap.ccsdk.cds.blueprintsprocessor"
+ const val SELF_SERVICE_API = "org.onap.ccsdk.cds.blueprintsprocessor.resource.api"
+ const val SELF_SERVICE_API_VALIDATOR = "org.onap.ccsdk.cds.blueprintsprocessor.resource.api.validator"
+ const val NETCONF_EXECUTOR = "org.onap.ccsdk.cds.blueprintsprocessor.functions.netconf.executor"
+ const val RESOURCE_RESOLUTION = "org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution"
+ const val RESTCONF_EXECUTOR = "org.onap.ccsdk.cds.blueprintsprocessor.functions.restconf.executor"
+ const val CLI_EXECUTOR = "org.onap.ccsdk.cds.blueprintsprocessor.functions.cli.executor"
+ const val PYTHON_EXECUTOR = "org.onap.ccsdk.cds.blueprintsprocessor.functions.python.executor"
+ const val SDC_LISTENER = "org.onap.ccsdk.cds.sdclistener"
+}
+
+object SelfServiceApiHttpErrorCodes {
+ init {
+ // Register HttpErrorCodes
+ // HttpErrorCodes.register("", 200)
+ }
+}
+
+object SelfServiceGrpcErrorCodes {
+ init {
+ // Register GrpcErrorCodes
+ // GrpcErrorCodes.register("", 3)
+ }
+}
diff --git a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/ExecutionServiceController.kt b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/ExecutionServiceController.kt
index 8b268d6f8..e5daecede 100644
--- a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/ExecutionServiceController.kt
+++ b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/ExecutionServiceController.kt
@@ -27,7 +27,9 @@ import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.ExecutionServiceOutp
import org.onap.ccsdk.cds.blueprintsprocessor.rest.service.mdcWebCoroutineScope
import org.onap.ccsdk.cds.blueprintsprocessor.selfservice.api.utils.determineHttpStatusCode
import org.onap.ccsdk.cds.controllerblueprints.core.asJsonPrimitive
+import org.onap.ccsdk.cds.controllerblueprints.core.httpProcessorException
import org.onap.ccsdk.cds.controllerblueprints.core.logger
+import org.onap.ccsdk.cds.error.catalog.core.ErrorCatalogCodes
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.http.MediaType
import org.springframework.http.ResponseEntity
@@ -81,7 +83,9 @@ open class ExecutionServiceController {
): ResponseEntity<ExecutionServiceOutput> = mdcWebCoroutineScope {
if (executionServiceInput.actionIdentifiers.mode == ACTION_MODE_ASYNC) {
- throw IllegalStateException("Can't process async request through the REST endpoint. Use gRPC for async processing.")
+ throw httpProcessorException(ErrorCatalogCodes.GENERIC_FAILURE,
+ SelfServiceApiDomains.BLUEPRINT_PROCESSOR,
+ "Can't process async request through the REST endpoint. Use gRPC for async processing.")
}
ph.register()
val processResult = executionServiceHandler.doProcess(executionServiceInput)
diff --git a/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/ComponentFunctionScriptingService.kt b/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/ComponentFunctionScriptingService.kt
index 4c7d5d0ec..34b18091f 100644
--- a/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/ComponentFunctionScriptingService.kt
+++ b/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/ComponentFunctionScriptingService.kt
@@ -101,4 +101,10 @@ class ComponentFunctionScriptingService(
}
return scriptComponent
}
+
+ suspend fun cleanupInstance(bluePrintContext: BluePrintContext, scriptType: String) {
+ if (scriptType == BluePrintConstants.SCRIPT_KOTLIN) {
+ BluePrintScriptsServiceImpl().cleanupInstance(bluePrintContext.rootPath)
+ }
+ }
}
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 09eee6717..2a63297be 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
@@ -60,6 +60,8 @@ open class ComponentScriptExecutor(private var componentFunctionScriptingService
// Handles both script processing and error handling
scriptComponentFunction.executeScript(executionServiceInput)
+
+ componentFunctionScriptingService.cleanupInstance(bluePrintRuntimeService.bluePrintContext(), scriptType)
}
override suspend fun recoverNB(runtimeException: RuntimeException, executionRequest: ExecutionServiceInput) {
diff --git a/ms/blueprintsprocessor/modules/services/workflow-service/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/workflow/BlueprintSvcLogicService.kt b/ms/blueprintsprocessor/modules/services/workflow-service/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/workflow/BlueprintSvcLogicService.kt
index 9cc325d94..4efe9f12d 100644
--- a/ms/blueprintsprocessor/modules/services/workflow-service/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/workflow/BlueprintSvcLogicService.kt
+++ b/ms/blueprintsprocessor/modules/services/workflow-service/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/workflow/BlueprintSvcLogicService.kt
@@ -49,6 +49,10 @@ interface BlueprintSvcLogicService : SvcLogicServiceBase {
suspend fun execute(graph: SvcLogicGraph, bluePrintRuntimeService: BluePrintRuntimeService<*>, input: Any): Any
+ override fun execute(module: String, rpc: String, version: String, mode: String, ctx: SvcLogicContext): SvcLogicContext {
+ TODO("not implemented")
+ }
+
@Deprecated("Populate Graph Dynamically from Blueprints, No need to get from Database Store ")
override fun getStore(): SvcLogicStore {
TODO("not implemented")
diff --git a/ms/blueprintsprocessor/parent/pom.xml b/ms/blueprintsprocessor/parent/pom.xml
index 4ee3f3656..ce78c55fa 100755
--- a/ms/blueprintsprocessor/parent/pom.xml
+++ b/ms/blueprintsprocessor/parent/pom.xml
@@ -35,6 +35,7 @@
<sli.version>${ccsdk.sli.core.version}</sli.version>
<!-- Override CDS version from parent to be project.version -->
<ccsdk.cds.version>${project.version}</ccsdk.cds.version>
+ <error.catalog.version>${project.version}</error.catalog.version>
<dmaap.client.version>1.1.5</dmaap.client.version>
<!-- Should be using released artifact as soon as available: -->
<!-- https://github.com/springfox/springfox/milestone/44 -->
@@ -55,14 +56,12 @@
<jslt.version>0.1.8</jslt.version>
<jython.version>2.7.1</jython.version>
<jinja.version>2.5.1</jinja.version>
- <velocity.version>1.7</velocity.version>
<guava.version>27.0.1-jre</guava.version>
- <jsoup.version>1.10.3</jsoup.version>
<json-patch.version>1.9</json-patch.version>
<json-smart.version>2.3</json-smart.version>
<commons-io-version>2.6</commons-io-version>
- <commons-lang3-version>3.2.1</commons-lang3-version>
+ <commons-compress-version>1.20</commons-compress-version>
<commons-collections-version>3.2.2</commons-collections-version>
</properties>
@@ -78,12 +77,6 @@
</dependency>
<dependency>
- <groupId>org.jsoup</groupId>
- <artifactId>jsoup</artifactId>
- <version>${jsoup.version}</version>
- </dependency>
-
- <dependency>
<groupId>org.springframework.kafka</groupId>
<artifactId>spring-kafka</artifactId>
<version>${spring-kafka.version}</version>
@@ -129,11 +122,6 @@
<!-- Common Utils Dependencies -->
<dependency>
- <groupId>org.apache.commons</groupId>
- <artifactId>commons-lang3</artifactId>
- <version>${commons-lang3-version}</version>
- </dependency>
- <dependency>
<groupId>commons-collections</groupId>
<artifactId>commons-collections</artifactId>
<version>${commons-collections-version}</version>
@@ -144,15 +132,9 @@
<version>${commons-io-version}</version>
</dependency>
<dependency>
- <groupId>org.apache.velocity</groupId>
- <artifactId>velocity</artifactId>
- <version>${velocity.version}</version>
- <exclusions>
- <exclusion>
- <groupId>org.slf4j</groupId>
- <artifactId>slf4j-api</artifactId>
- </exclusion>
- </exclusions>
+ <groupId>org.apache.commons</groupId>
+ <artifactId>commons-compress</artifactId>
+ <version>${commons-compress-version}</version>
</dependency>
<dependency>
<groupId>com.hubspot.jinjava</groupId>
@@ -251,47 +233,6 @@
<version>${kotlin.version}</version>
</dependency>
- <!-- GRPC Dependencies -->
- <dependency>
- <groupId>io.grpc</groupId>
- <artifactId>grpc-core</artifactId>
- <version>${grpc.version}</version>
- </dependency>
- <dependency>
- <groupId>io.grpc</groupId>
- <artifactId>grpc-netty</artifactId>
- <version>${grpc.version}</version>
- </dependency>
- <dependency>
- <groupId>io.grpc</groupId>
- <artifactId>grpc-protobuf</artifactId>
- <version>${grpc.version}</version>
- </dependency>
- <dependency>
- <groupId>io.grpc</groupId>
- <artifactId>grpc-stub</artifactId>
- <version>${grpc.version}</version>
- </dependency>
- <dependency>
- <groupId>io.grpc</groupId>
- <artifactId>grpc-netty-shaded</artifactId>
- <version>${grpc.version}</version>
- </dependency>
- <dependency>
- <groupId>io.grpc</groupId>
- <artifactId>grpc-grpclb</artifactId>
- <version>${grpc.version}</version>
- </dependency>
- <dependency>
- <groupId>com.google.protobuf</groupId>
- <artifactId>protobuf-java</artifactId>
- <version>${protobuff.java.version}</version>
- </dependency>
- <dependency>
- <groupId>com.google.protobuf</groupId>
- <artifactId>protobuf-java-util</artifactId>
- <version>${protobuff.java.utils.version}</version>
- </dependency>
<dependency>
<groupId>com.github.marcoferrer.krotoplus</groupId>
<artifactId>kroto-plus-coroutines</artifactId>
@@ -351,6 +292,30 @@
<version>${kafka.version}</version>
</dependency>
+ <!-- Error Catalog -->
+ <dependency>
+ <groupId>org.onap.ccsdk.cds.error.catalog</groupId>
+ <artifactId>error-catalog-core</artifactId>
+ <version>${error.catalog.version}</version>
+ <exclusions>
+ <exclusion>
+ <groupId>*</groupId>
+ <artifactId>*</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
+ <groupId>org.onap.ccsdk.cds.error.catalog</groupId>
+ <artifactId>error-catalog-services</artifactId>
+ <version>${error.catalog.version}</version>
+ <exclusions>
+ <exclusion>
+ <groupId>*</groupId>
+ <artifactId>*</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+
<!-- SLI Version -->
<dependency>
<groupId>org.onap.ccsdk.sli.core</groupId>
@@ -485,7 +450,7 @@
</dependency>
<dependency>
<groupId>org.onap.ccsdk.cds.blueprintsprocessor.functions</groupId>
- <artifactId>nrm-restful</artifactId>
+ <artifactId>restful-executor</artifactId>
<version>${ccsdk.cds.version}</version>
</dependency>
<dependency>
@@ -614,13 +579,6 @@
<scope>test</scope>
</dependency>
- <dependency>
- <groupId>io.grpc</groupId>
- <artifactId>grpc-testing</artifactId>
- <version>${grpc.version}</version>
- <scope>test</scope>
- </dependency>
-
<!-- Spring Kafka -->
<dependency>
<groupId>org.springframework.kafka</groupId>
@@ -628,7 +586,6 @@
<version>${spring-kafka.version}</version>
<scope>test</scope>
</dependency>
-
</dependencies>
</dependencyManagement>
<dependencies>
@@ -757,6 +714,11 @@
<groupId>io.netty</groupId>
<artifactId>netty-tcnative-boringssl-static</artifactId>
</dependency>
+
+ <dependency>
+ <groupId>org.onap.ccsdk.cds.error.catalog</groupId>
+ <artifactId>error-catalog-core</artifactId>
+ </dependency>
</dependencies>
<repositories>
diff --git a/ms/error-catalog/README.md b/ms/error-catalog/README.md
new file mode 100755
index 000000000..1df859574
--- /dev/null
+++ b/ms/error-catalog/README.md
@@ -0,0 +1,40 @@
+## How to use library
+
+##### 1. Set Error Catalog service type (Database or properties file service) in application.properties file
+
+```
+##### Error Managements #####
+## For database service type ##
+# error.catalog.type=DB
+## For database service type ##
+# error.catalog.type=properties
+error.catalog.applicationId=cds
+error.catalog.type=properties
+error.catalog.errorDefinitionDir=/opt/app/onap/config
+```
+
+##### 2. Generate exception
+
+- HTTP Error Exception
+```
+errorCatalogException: ErrorCatalogException = httpProcessorException(ErrorCatalogCodes.ERROR_TYPE,
+"Error message here...")
+```
+
+- GRPC Error Exception
+```
+errorCatalogException: ErrorCatalogException = grpcProcessorException(ErrorCatalogCodes.ERROR_TYPE,
+"Error message here...")
+```
+
+##### 3. Update an existing exception
+```
+e = errorCatalogException.code(500)
+e = errorCatalogException.action("message")
+...
+```
+
+##### 4. Add a HTTP REST Exception handler
+@RestControllerAdvice("domain.here")
+open class ExceptionHandler(private val errorCatalogService: ErrorCatalogService) :
+ ErrorCatalogExceptionHandler(errorCatalogService) \ No newline at end of file
diff --git a/ms/error-catalog/application/pom.xml b/ms/error-catalog/application/pom.xml
new file mode 100644
index 000000000..4e1a6f3f1
--- /dev/null
+++ b/ms/error-catalog/application/pom.xml
@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ Copyright © 2018-2019 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.
+ -->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.onap.ccsdk.cds.error.catalog</groupId>
+ <artifactId>error-catalog</artifactId>
+ <version>0.7.0-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>error-catalog-application</artifactId>
+
+ <name>Error Catalog Application</name>
+ <description>Error Catalog Application</description>
+</project>
diff --git a/ms/error-catalog/core/pom.xml b/ms/error-catalog/core/pom.xml
new file mode 100644
index 000000000..f117aa83f
--- /dev/null
+++ b/ms/error-catalog/core/pom.xml
@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ Copyright © 2018-2019 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.
+ -->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.onap.ccsdk.cds.error.catalog</groupId>
+ <artifactId>error-catalog</artifactId>
+ <version>0.7.0-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>error-catalog-core</artifactId>
+
+ <name>Error Catalog Core</name>
+ <description>Error Catalog Core</description>
+</project>
diff --git a/ms/error-catalog/core/src/main/kotlin/org/onap/ccsdk/cds/error/catalog/core/ErrorCatalogException.kt b/ms/error-catalog/core/src/main/kotlin/org/onap/ccsdk/cds/error/catalog/core/ErrorCatalogException.kt
new file mode 100644
index 000000000..032feb62c
--- /dev/null
+++ b/ms/error-catalog/core/src/main/kotlin/org/onap/ccsdk/cds/error/catalog/core/ErrorCatalogException.kt
@@ -0,0 +1,112 @@
+/*
+ * Copyright © 2020 IBM, Bell Canada.
+ * Modifications Copyright © 2019-2020 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.cds.error.catalog.core
+
+interface ErrorCatalogExceptionFluent<T> {
+ fun code(code: Int): T
+ fun domain(domain: String): T
+ fun action(action: String): T
+ fun http(type: String): T
+ fun grpc(type: String): T
+ fun payloadMessage(message: String): T
+ fun addErrorPayloadMessage(message: String): T
+ fun addSubError(errorMessage: ErrorMessage): T
+}
+
+open class ErrorCatalogException : RuntimeException {
+ var code: Int = -1
+ var domain: String = ""
+ var name: String = ErrorCatalogCodes.GENERIC_FAILURE
+ var action: String = ""
+ var errorPayload: ErrorPayload? = null
+ var protocol: String = ""
+ var errorPayloadMessages: MutableList<String>? = null
+
+ val messageSeparator = "${System.lineSeparator()} -> "
+
+ constructor(message: String, cause: Throwable) : super(message, cause)
+ constructor(message: String) : super(message)
+ constructor(cause: Throwable) : super(cause)
+ constructor(cause: Throwable, message: String, vararg args: Any?) : super(format(message, *args), cause)
+
+ constructor(code: Int, cause: Throwable) : super(cause) {
+ this.code = code
+ }
+
+ constructor(code: Int, message: String) : super(message) {
+ this.code = code
+ }
+
+ constructor(code: Int, message: String, cause: Throwable) : super(message, cause) {
+ this.code = code
+ }
+
+ constructor(code: Int, cause: Throwable, message: String, vararg args: Any?) :
+ super(String.format(message, *args), cause) {
+ this.code = code
+ }
+
+ open fun <T : ErrorCatalogException> updateCode(code: Int): T {
+ this.code = code
+ return this as T
+ }
+
+ open fun <T : ErrorCatalogException> updateDomain(domain: String): T {
+ this.domain = domain
+ return this as T
+ }
+
+ open fun <T : ErrorCatalogException> updateAction(action: String): T {
+ this.action = action
+ return this as T
+ }
+
+ fun <T : ErrorCatalogException> updateHttp(type: String): T {
+ this.protocol = ErrorMessageLibConstants.ERROR_CATALOG_PROTOCOL_HTTP
+ this.code = HttpErrorCodes.code(type)
+ return this as T
+ }
+
+ fun <T : ErrorCatalogException> updateGrpc(type: String): T {
+ this.protocol = ErrorMessageLibConstants.ERROR_CATALOG_PROTOCOL_GRPC
+ this.code = GrpcErrorCodes.code(type)
+ return this as T
+ }
+
+ fun <T : ErrorCatalogException> updatePayloadMessage(message: String): T {
+ if (this.errorPayloadMessages == null) this.errorPayloadMessages = arrayListOf()
+ this.errorPayloadMessages!!.add(message)
+ return this as T
+ }
+
+ fun <T : ErrorCatalogException> updateErrorPayloadMessage(message: String): T {
+ if (errorPayload == null) {
+ errorPayload = ErrorPayload()
+ }
+ errorPayload!!.message = "${errorPayload!!.message} $messageSeparator $message"
+ return this as T
+ }
+
+ fun <T : ErrorCatalogException> updateSubError(errorMessage: ErrorMessage): T {
+ if (errorPayload == null) {
+ errorPayload = ErrorPayload()
+ }
+ errorPayload!!.subErrors.add(errorMessage)
+ return this as T
+ }
+}
diff --git a/ms/error-catalog/core/src/main/kotlin/org/onap/ccsdk/cds/error/catalog/core/ErrorCatalogExtensions.kt b/ms/error-catalog/core/src/main/kotlin/org/onap/ccsdk/cds/error/catalog/core/ErrorCatalogExtensions.kt
new file mode 100644
index 000000000..65c547245
--- /dev/null
+++ b/ms/error-catalog/core/src/main/kotlin/org/onap/ccsdk/cds/error/catalog/core/ErrorCatalogExtensions.kt
@@ -0,0 +1,32 @@
+/*
+ * Copyright © 2018-2019 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.cds.error.catalog.core
+
+import org.slf4j.LoggerFactory
+import org.slf4j.helpers.MessageFormatter
+import kotlin.reflect.KClass
+
+fun <T : Any> logger(clazz: T) = LoggerFactory.getLogger(clazz.javaClass)!!
+
+fun <T : KClass<*>> logger(clazz: T) = LoggerFactory.getLogger(clazz.java)!!
+
+fun format(message: String, vararg args: Any?): String {
+ if (args != null && args.isNotEmpty()) {
+ return MessageFormatter.arrayFormat(message, args).message
+ }
+ return message
+}
diff --git a/ms/error-catalog/core/src/main/kotlin/org/onap/ccsdk/cds/error/catalog/core/ErrorCodes.kt b/ms/error-catalog/core/src/main/kotlin/org/onap/ccsdk/cds/error/catalog/core/ErrorCodes.kt
new file mode 100644
index 000000000..86483e3e9
--- /dev/null
+++ b/ms/error-catalog/core/src/main/kotlin/org/onap/ccsdk/cds/error/catalog/core/ErrorCodes.kt
@@ -0,0 +1,88 @@
+/*
+ * Copyright © 2018-2019 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.cds.error.catalog.core
+
+object ErrorCatalogCodes {
+ const val GENERIC_FAILURE = "GENERIC_FAILURE"
+ const val GENERIC_PROCESS_FAILURE = "GENERIC_PROCESS_FAILURE"
+ const val INVALID_FILE_EXTENSION = "INVALID_FILE_EXTENSION"
+ const val RESOURCE_NOT_FOUND = "RESOURCE_NOT_FOUND"
+ const val RESOURCE_PATH_MISSING = "RESOURCE_PATH_MISSING"
+ const val RESOURCE_WRITING_FAIL = "RESOURCE_WRITING_FAIL"
+ const val IO_FILE_INTERRUPT = "IO_FILE_INTERRUPT"
+ const val INVALID_REQUEST_FORMAT = "INVALID_REQUEST_FORMAT"
+ const val UNAUTHORIZED_REQUEST = "UNAUTHORIZED_REQUEST"
+ const val REQUEST_NOT_FOUND = "REQUEST_NOT_FOUND"
+ const val CONFLICT_ADDING_RESOURCE = "CONFLICT_ADDING_RESOURCE"
+ const val DUPLICATE_DATA = "DUPLICATE_DATA"
+}
+
+object HttpErrorCodes {
+ private val store: MutableMap<String, Int> = mutableMapOf()
+
+ init {
+ store[ErrorCatalogCodes.GENERIC_FAILURE] = 500
+ store[ErrorCatalogCodes.GENERIC_PROCESS_FAILURE] = 500
+ store[ErrorCatalogCodes.INVALID_FILE_EXTENSION] = 415
+ store[ErrorCatalogCodes.RESOURCE_NOT_FOUND] = 404
+ store[ErrorCatalogCodes.RESOURCE_PATH_MISSING] = 503
+ store[ErrorCatalogCodes.RESOURCE_WRITING_FAIL] = 503
+ store[ErrorCatalogCodes.IO_FILE_INTERRUPT] = 503
+ store[ErrorCatalogCodes.INVALID_REQUEST_FORMAT] = 400
+ store[ErrorCatalogCodes.UNAUTHORIZED_REQUEST] = 401
+ store[ErrorCatalogCodes.REQUEST_NOT_FOUND] = 404
+ store[ErrorCatalogCodes.CONFLICT_ADDING_RESOURCE] = 409
+ store[ErrorCatalogCodes.DUPLICATE_DATA] = 409
+ }
+
+ fun register(type: String, code: Int) {
+ store[type] = code
+ }
+
+ fun code(type: String): Int {
+ // FIXME("Return Default Error Code , If missing")
+ return store[type]!!
+ }
+}
+
+object GrpcErrorCodes {
+ private val store: MutableMap<String, Int> = mutableMapOf()
+
+ init {
+ store[ErrorCatalogCodes.GENERIC_FAILURE] = 2
+ store[ErrorCatalogCodes.GENERIC_PROCESS_FAILURE] = 2
+ store[ErrorCatalogCodes.INVALID_FILE_EXTENSION] = 3
+ store[ErrorCatalogCodes.RESOURCE_NOT_FOUND] = 5
+ store[ErrorCatalogCodes.RESOURCE_PATH_MISSING] = 3
+ store[ErrorCatalogCodes.RESOURCE_WRITING_FAIL] = 9
+ store[ErrorCatalogCodes.IO_FILE_INTERRUPT] = 3
+ store[ErrorCatalogCodes.INVALID_REQUEST_FORMAT] = 3
+ store[ErrorCatalogCodes.UNAUTHORIZED_REQUEST] = 16
+ store[ErrorCatalogCodes.REQUEST_NOT_FOUND] = 8
+ store[ErrorCatalogCodes.CONFLICT_ADDING_RESOURCE] = 10
+ store[ErrorCatalogCodes.DUPLICATE_DATA] = 11
+ }
+
+ fun register(type: String, code: Int) {
+ store[type] = code
+ }
+
+ fun code(type: String): Int {
+ // FIXME("Return Default Error Code , If missing")
+ return store[type]!!
+ }
+}
diff --git a/ms/error-catalog/core/src/main/kotlin/org/onap/ccsdk/cds/error/catalog/core/ErrorLibData.kt b/ms/error-catalog/core/src/main/kotlin/org/onap/ccsdk/cds/error/catalog/core/ErrorLibData.kt
new file mode 100644
index 000000000..2c0772e31
--- /dev/null
+++ b/ms/error-catalog/core/src/main/kotlin/org/onap/ccsdk/cds/error/catalog/core/ErrorLibData.kt
@@ -0,0 +1,94 @@
+/*
+ * Copyright © 2020 IBM, Bell Canada.
+ *
+ * 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.error.catalog.core
+
+import com.fasterxml.jackson.annotation.JsonFormat
+import org.slf4j.event.Level
+import org.onap.ccsdk.cds.error.catalog.core.ErrorMessageLibConstants.ERROR_CATALOG_DEFAULT_ERROR_CODE
+import java.time.LocalDateTime
+
+open class ErrorPayload {
+ var code: Int = ERROR_CATALOG_DEFAULT_ERROR_CODE
+ var status: String = ""
+ @get:JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'")
+ var timestamp: LocalDateTime = LocalDateTime.now()
+ var message: String = ""
+ var debugMessage: String = ""
+ var logLevel: String = Level.ERROR.name
+ val subErrors: ArrayList<ErrorMessage> = ArrayList()
+
+ constructor()
+
+ constructor(
+ code: Int = ERROR_CATALOG_DEFAULT_ERROR_CODE,
+ status: String,
+ message: String,
+ logLevel: String = Level.ERROR.name,
+ debugMessage: String = ""
+ ) {
+ this.code = code
+ this.status = status
+ this.message = message
+ this.logLevel = logLevel
+ this.debugMessage = debugMessage
+ }
+
+ constructor(
+ code: Int = ERROR_CATALOG_DEFAULT_ERROR_CODE,
+ status: String,
+ message: String,
+ logLevel: String = Level.ERROR.name,
+ debugMessage: String = "",
+ errorMessage: ErrorMessage
+ ) {
+ this.code = code
+ this.status = status
+ this.message = message
+ this.logLevel = logLevel
+ this.debugMessage = debugMessage
+ this.subErrors.add(errorMessage)
+ }
+
+ fun isEqualTo(errorPayload: ErrorPayload): Boolean {
+ return (this.code == errorPayload.code && this.status == errorPayload.status && this.message == errorPayload.message &&
+ this.logLevel == errorPayload.logLevel && this.debugMessage == errorPayload.debugMessage &&
+ this.subErrors == errorPayload.subErrors)
+ }
+}
+
+/**
+ *
+ *
+ * @author Steve Siani
+ */
+data class ErrorMessage(
+ val domainId: String,
+ val message: String,
+ val cause: String
+)
+
+data class ErrorCatalog(
+ val errorId: String,
+ val domainId: String,
+ val code: Int,
+ val action: String,
+ val cause: String
+) {
+ fun getMessage(): String {
+ return "Cause: $cause ${System.lineSeparator()} Action : $action"
+ }
+}
diff --git a/ms/error-catalog/core/src/main/kotlin/org/onap/ccsdk/cds/error/catalog/core/ErrorMessageLibConstants.kt b/ms/error-catalog/core/src/main/kotlin/org/onap/ccsdk/cds/error/catalog/core/ErrorMessageLibConstants.kt
new file mode 100644
index 000000000..6570e3e66
--- /dev/null
+++ b/ms/error-catalog/core/src/main/kotlin/org/onap/ccsdk/cds/error/catalog/core/ErrorMessageLibConstants.kt
@@ -0,0 +1,31 @@
+/*
+ * Copyright © 2020 IBM, Bell Canada.
+ *
+ * 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.error.catalog.core
+
+object ErrorMessageLibConstants {
+ const val ERROR_CATALOG_DOMAIN = "org.onap.ccsdk.cds.error.catalog"
+ const val ERROR_CATALOG_TYPE = "error.catalog.type"
+ const val ERROR_CATALOG_TYPE_PROPERTIES = "properties"
+ const val ERROR_CATALOG_TYPE_DB = "DB"
+ const val ERROR_CATALOG_PROPERTIES_FILENAME = "error-messages_en.properties"
+ const val ERROR_CATALOG_PROPERTIES_DIRECTORY = "/opt/app/onap/config/"
+ const val ERROR_CATALOG_MODELS = "org.onap.ccsdk.cds.error.catalog.domain"
+ const val ERROR_CATALOG_REPOSITORY = "org.onap.ccsdk.cds.error.catalog.repository"
+ const val ERROR_CATALOG_DEFAULT_ERROR_CODE = 500
+ const val ERROR_CATALOG_PROTOCOL_HTTP = "http"
+ const val ERROR_CATALOG_PROTOCOL_GRPC = "grpc"
+}
diff --git a/ms/error-catalog/pom.xml b/ms/error-catalog/pom.xml
new file mode 100644
index 000000000..1e6707a75
--- /dev/null
+++ b/ms/error-catalog/pom.xml
@@ -0,0 +1,157 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ Copyright © 2018-2019 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.
+ -->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.onap.ccsdk.cds</groupId>
+ <artifactId>ms</artifactId>
+ <version>0.7.0-SNAPSHOT</version>
+ <relativePath>..</relativePath>
+ </parent>
+
+ <groupId>org.onap.ccsdk.cds.error.catalog</groupId>
+ <artifactId>error-catalog</artifactId>
+ <packaging>pom</packaging>
+
+ <name>Error Catalog Lib</name>
+ <description>Error Catalog Lib for ONAP Components</description>
+
+ <modules>
+ <module>application</module>
+ <module>core</module>
+ <module>services</module>
+ </modules>
+
+ <dependencyManagement>
+ <dependencies>
+ <dependency>
+ <groupId>org.onap.ccsdk.cds.error.catalog</groupId>
+ <artifactId>error-catalog-core</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.onap.ccsdk.cds.error.catalog</groupId>
+ <artifactId>error-catalog-services</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ </dependencies>
+ </dependencyManagement>
+ <dependencies>
+ <!-- Kotlin Dependencies -->
+ <dependency>
+ <groupId>org.jetbrains.kotlin</groupId>
+ <artifactId>kotlin-stdlib</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.jetbrains.kotlin</groupId>
+ <artifactId>kotlin-stdlib-common</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.jetbrains.kotlin</groupId>
+ <artifactId>kotlin-script-util</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.jetbrains.kotlin</groupId>
+ <artifactId>kotlin-stdlib-jdk8</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.jetbrains.kotlinx</groupId>
+ <artifactId>kotlinx-coroutines-core</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.jetbrains.kotlinx</groupId>
+ <artifactId>kotlinx-coroutines-reactor</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>com.fasterxml.jackson.module</groupId>
+ <artifactId>jackson-module-kotlin</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.jetbrains.kotlin</groupId>
+ <artifactId>kotlin-compiler-embeddable</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.jetbrains.kotlin</groupId>
+ <artifactId>kotlin-scripting-jvm-host</artifactId>
+ <!--Use kotlin-compiler-embeddable as koltin-compiler wrap-->
+ <!--guava dependency creating classpath issues at runtime-->
+ <exclusions>
+ <exclusion>
+ <groupId>org.jetbrains.kotlin</groupId>
+ <artifactId>kotlin-compiler</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-starter-webflux</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>javax.persistence</groupId>
+ <artifactId>javax.persistence-api</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-starter-data-jpa</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-starter-test</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>io.projectreactor</groupId>
+ <artifactId>reactor-test</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.jetbrains.kotlin</groupId>
+ <artifactId>kotlin-maven-plugin</artifactId>
+ <version>${kotlin.maven.version}</version>
+ <executions>
+ <execution>
+ <id>compile</id>
+ <goals>
+ <goal>compile</goal>
+ </goals>
+ <configuration>
+ <sourceDirs>
+ <sourceDir>src/main/kotlin</sourceDir>
+ </sourceDirs>
+ </configuration>
+ </execution>
+ <execution>
+ <id>test-compile</id>
+ <goals>
+ <goal>test-compile</goal>
+ </goals>
+ <configuration>
+ <sourceDirs>
+ <sourceDir>${project.basedir}/src/test/kotlin</sourceDir>
+ </sourceDirs>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+</project>
diff --git a/ms/error-catalog/services/pom.xml b/ms/error-catalog/services/pom.xml
new file mode 100644
index 000000000..6fcf158f5
--- /dev/null
+++ b/ms/error-catalog/services/pom.xml
@@ -0,0 +1,37 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ Copyright © 2018-2019 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.
+ -->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.onap.ccsdk.cds.error.catalog</groupId>
+ <artifactId>error-catalog</artifactId>
+ <version>0.7.0-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>error-catalog-services</artifactId>
+
+ <name>Error Catalog Service</name>
+ <description>Error Catalog Service</description>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.onap.ccsdk.cds.error.catalog</groupId>
+ <artifactId>error-catalog-core</artifactId>
+ </dependency>
+ </dependencies>
+</project>
diff --git a/ms/error-catalog/services/src/main/kotlin/org/onap/ccsdk/cds/error/catalog/services/ErrorCatalogConfiguration.kt b/ms/error-catalog/services/src/main/kotlin/org/onap/ccsdk/cds/error/catalog/services/ErrorCatalogConfiguration.kt
new file mode 100644
index 000000000..f0a75e087
--- /dev/null
+++ b/ms/error-catalog/services/src/main/kotlin/org/onap/ccsdk/cds/error/catalog/services/ErrorCatalogConfiguration.kt
@@ -0,0 +1,34 @@
+/*
+ * Copyright © 2020 IBM, Bell Canada.
+ * Modifications Copyright © 2019-2020 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.cds.error.catalog.services
+
+import org.springframework.boot.context.properties.ConfigurationProperties
+import org.springframework.boot.context.properties.EnableConfigurationProperties
+import org.springframework.context.annotation.Configuration
+import org.springframework.stereotype.Component
+
+@Configuration
+@EnableConfigurationProperties(ErrorCatalogProperties::class)
+open class ErrorCatalogConfiguration
+
+@Component
+@ConfigurationProperties(prefix = "error.catalog")
+open class ErrorCatalogProperties {
+ lateinit var type: String
+ lateinit var applicationId: String
+ var errorDefinitionDir: String? = null
+}
diff --git a/ms/error-catalog/services/src/main/kotlin/org/onap/ccsdk/cds/error/catalog/services/ErrorCatalogDBService.kt b/ms/error-catalog/services/src/main/kotlin/org/onap/ccsdk/cds/error/catalog/services/ErrorCatalogDBService.kt
new file mode 100644
index 000000000..95b44e683
--- /dev/null
+++ b/ms/error-catalog/services/src/main/kotlin/org/onap/ccsdk/cds/error/catalog/services/ErrorCatalogDBService.kt
@@ -0,0 +1,98 @@
+/*
+ * Copyright © 2020 IBM, Bell Canada.
+ * Modifications Copyright © 2019-2020 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.cds.error.catalog.services
+
+import org.onap.ccsdk.cds.error.catalog.core.ErrorMessageLibConstants
+import org.onap.ccsdk.cds.error.catalog.services.domain.Domain
+import org.onap.ccsdk.cds.error.catalog.services.domain.ErrorMessageModel
+import org.onap.ccsdk.cds.error.catalog.services.repository.DomainRepository
+import org.onap.ccsdk.cds.error.catalog.services.repository.ErrorMessageModelRepository
+import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty
+import org.springframework.data.domain.Page
+import org.springframework.data.domain.Pageable
+import org.springframework.stereotype.Service
+
+@Service
+@ConditionalOnProperty(
+ name = [ErrorMessageLibConstants.ERROR_CATALOG_TYPE],
+ havingValue = ErrorMessageLibConstants.ERROR_CATALOG_TYPE_DB
+)
+open class ErrorCatalogDBService(
+ private val domainRepository: DomainRepository,
+ private val errorMessageModelRepository: ErrorMessageModelRepository
+) {
+
+ /**
+ * This is a getAllDomains method to retrieve all the Domain in Error Catalog Database by pages
+ *
+ * @return Page<Domain> list of the domains by page
+ </Domain> */
+ open fun getAllDomains(pageRequest: Pageable): Page<Domain> {
+ return domainRepository.findAll(pageRequest)
+ }
+
+ /**
+ * This is a getAllDomains method to retrieve all the Domain in Error Catalog Database
+ *
+ * @return List<Domain> list of the domains
+ </Domain> */
+ open fun getAllDomains(): List<Domain> {
+ return domainRepository.findAll()
+ }
+
+ /**
+ * This is a getAllDomainsByApplication method to retrieve all the Domain that belong to an application in Error Catalog Database
+ *
+ * @return List<Domain> list of the domains
+ </Domain> */
+ open fun getAllDomainsByApplication(applicationId: String): List<Domain> {
+ return domainRepository.findAllByApplicationId(applicationId)
+ }
+
+ /**
+ * This is a getAllErrorMessagesByApplication method to retrieve all the Messages that belong to an application in Error Catalog Database
+ *
+ * @return MutableMap<String, ErrorCode> list of the abstractErrorModel
+ </Domain> */
+ open fun getAllErrorMessagesByApplication(applicationId: String): MutableMap<String, ErrorMessageModel> {
+ val domains = domainRepository.findAllByApplicationId(applicationId)
+ val errorMessages = mutableMapOf<String, ErrorMessageModel>()
+ for (domain in domains) {
+ val errorMessagesFound = errorMessageModelRepository.findByDomainsId(domain.id)
+ for (errorMessageFound in errorMessagesFound) {
+ errorMessages["${domain.name}$MESSAGE_KEY_SEPARATOR${errorMessageFound.messageID}"] = errorMessageFound
+ }
+ }
+ return errorMessages
+ }
+
+ open fun saveDomain(
+ domain: String,
+ applicationId: String,
+ description: String = "",
+ errorMessageList: List<ErrorMessageModel>
+ ) {
+ val domainModel = Domain(domain, applicationId, description)
+ domainModel.errorMessages.addAll(errorMessageList)
+ domainRepository.saveAndFlush(domainModel)
+ }
+
+ companion object {
+ private const val MESSAGE_KEY_SEPARATOR = "."
+ }
+}
diff --git a/ms/error-catalog/services/src/main/kotlin/org/onap/ccsdk/cds/error/catalog/services/ErrorCatalogExceptionHandler.kt b/ms/error-catalog/services/src/main/kotlin/org/onap/ccsdk/cds/error/catalog/services/ErrorCatalogExceptionHandler.kt
new file mode 100644
index 000000000..88e2f4522
--- /dev/null
+++ b/ms/error-catalog/services/src/main/kotlin/org/onap/ccsdk/cds/error/catalog/services/ErrorCatalogExceptionHandler.kt
@@ -0,0 +1,31 @@
+/*
+ * Copyright © 2020 IBM, Bell Canada.
+ *
+ * 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.error.catalog.services
+
+import org.onap.ccsdk.cds.error.catalog.core.ErrorCatalogException
+import org.onap.ccsdk.cds.error.catalog.core.ErrorPayload
+import org.springframework.http.ResponseEntity
+import org.springframework.web.bind.annotation.ExceptionHandler
+
+abstract class ErrorCatalogExceptionHandler(private val errorCatalogService: ErrorCatalogService) {
+
+ @ExceptionHandler(ErrorCatalogException::class)
+ fun errorCatalogException(e: ErrorCatalogException): ResponseEntity<ErrorPayload> {
+ val errorPayload = errorCatalogService.errorPayload(e)
+ return errorPayload.toResponseEntity()
+ }
+}
diff --git a/ms/error-catalog/services/src/main/kotlin/org/onap/ccsdk/cds/error/catalog/services/ErrorCatalogLoadService.kt b/ms/error-catalog/services/src/main/kotlin/org/onap/ccsdk/cds/error/catalog/services/ErrorCatalogLoadService.kt
new file mode 100644
index 000000000..ca7d72b50
--- /dev/null
+++ b/ms/error-catalog/services/src/main/kotlin/org/onap/ccsdk/cds/error/catalog/services/ErrorCatalogLoadService.kt
@@ -0,0 +1,147 @@
+/*
+ * Copyright © 2020 IBM, Bell Canada.
+ * Modifications Copyright © 2019-2020 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.cds.error.catalog.services
+
+import org.onap.ccsdk.cds.error.catalog.core.ErrorMessageLibConstants
+import org.onap.ccsdk.cds.error.catalog.core.logger
+import org.onap.ccsdk.cds.error.catalog.services.domain.ErrorMessageModel
+import org.springframework.boot.autoconfigure.condition.ConditionalOnBean
+import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty
+import org.springframework.stereotype.Service
+import java.io.File
+import java.io.FileNotFoundException
+import java.io.IOException
+import java.io.InputStream
+import java.nio.file.Paths
+import java.util.Properties
+
+interface ErrorCatalogLoadService {
+
+ suspend fun loadErrorCatalog()
+
+ fun getErrorMessage(domain: String, key: String): String?
+
+ fun getErrorMessage(attribute: String): String?
+}
+
+/**
+ * Representation of Blueprint Error Message lib from database service to load the properties
+ */
+@Service
+@ConditionalOnBean(ErrorCatalogDBService::class)
+open class ErrorCatalogLoadDBService(
+ private var errorCatalogProperties: ErrorCatalogProperties,
+ private var errorCatalogDBService: ErrorCatalogDBService
+) : ErrorCatalogLoadService {
+
+ private var log = logger(ErrorCatalogLoadDBService::class)
+
+ lateinit var errorMessageInDB: Map<String, ErrorMessageModel>
+
+ override suspend fun loadErrorCatalog() {
+ log.info("Application ID: ${errorCatalogProperties.applicationId} > Initializing error catalog message from database...")
+ errorMessageInDB = getErrorMessagesFromDB()
+ }
+
+ override fun getErrorMessage(domain: String, key: String): String? {
+ return getErrorMessage("$domain.${key.toLowerCase()}")
+ }
+
+ override fun getErrorMessage(attribute: String): String? {
+ val errorMessage = findErrorMessage(attribute)
+ return prepareErrorMessage(errorMessage)
+ }
+
+ /**
+ * Parses the error-messages.properties file which contains error messages
+ */
+ private suspend fun getErrorMessagesFromDB(): Map<String, ErrorMessageModel> {
+ return errorCatalogDBService.getAllErrorMessagesByApplication(errorCatalogProperties.applicationId)
+ }
+
+ private fun findErrorMessage(attribute: String): ErrorMessageModel? {
+ return if (errorMessageInDB.containsKey(attribute)) {
+ errorMessageInDB[attribute]
+ } else {
+ null
+ }
+ }
+
+ private fun prepareErrorMessage(errorMessage: ErrorMessageModel?): String? {
+ return if (errorMessage != null) {
+ "cause=${errorMessage.cause}, action=${errorMessage.action}"
+ } else {
+ null
+ }
+ }
+}
+
+/**
+ * Representation of Blueprint Error Message lib property service to load the properties
+ */
+@Service
+@ConditionalOnProperty(
+ name = [ErrorMessageLibConstants.ERROR_CATALOG_TYPE],
+ havingValue = ErrorMessageLibConstants.ERROR_CATALOG_TYPE_PROPERTIES
+)
+open class ErrorCatalogLoadPropertyService(private var errorCatalogProperties: ErrorCatalogProperties) :
+ ErrorCatalogLoadService {
+
+ private val propertyFileName = ErrorMessageLibConstants.ERROR_CATALOG_PROPERTIES_FILENAME
+ private lateinit var propertyFile: File
+
+ private var log = logger(ErrorCatalogLoadPropertyService::class)
+
+ lateinit var properties: Properties
+
+ override suspend fun loadErrorCatalog() {
+ log.info("Application ID: ${errorCatalogProperties.applicationId} > Initializing error catalog message from properties...")
+ val propertyDir = errorCatalogProperties.errorDefinitionDir ?: ErrorMessageLibConstants.ERROR_CATALOG_PROPERTIES_DIRECTORY
+ propertyFile = Paths.get(propertyDir, propertyFileName).toFile().normalize()
+ properties = parseErrorMessagesProps()
+ }
+
+ override fun getErrorMessage(domain: String, key: String): String? {
+ return getErrorMessage("$domain.${key.toLowerCase()}")
+ }
+
+ override fun getErrorMessage(attribute: String): String? {
+ return properties.getProperty(attribute)
+ }
+
+ /**
+ * Parses the error-messages.properties file which contains error messages
+ */
+ private fun parseErrorMessagesProps(): Properties {
+ var inputStream: InputStream? = null
+ val props = Properties()
+ try {
+ inputStream = propertyFile.inputStream()
+ props.load(inputStream)
+ } catch (e: FileNotFoundException) {
+ log.error("Application ID: ${errorCatalogProperties.applicationId} > Property File '$propertyFileName' " +
+ "not found in the application directory.")
+ } catch (e: IOException) {
+ log.error("Application ID: ${errorCatalogProperties.applicationId} > Fail to load property file " +
+ "'$propertyFileName' for message errors.")
+ } finally {
+ inputStream!!.close()
+ }
+ return props
+ }
+}
diff --git a/ms/error-catalog/services/src/main/kotlin/org/onap/ccsdk/cds/error/catalog/services/ErrorCatalogService.kt b/ms/error-catalog/services/src/main/kotlin/org/onap/ccsdk/cds/error/catalog/services/ErrorCatalogService.kt
new file mode 100644
index 000000000..91f817133
--- /dev/null
+++ b/ms/error-catalog/services/src/main/kotlin/org/onap/ccsdk/cds/error/catalog/services/ErrorCatalogService.kt
@@ -0,0 +1,91 @@
+/*
+ * Copyright © 2020 IBM, Bell Canada.
+ * Modifications Copyright © 2019-2020 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.cds.error.catalog.services
+
+import kotlinx.coroutines.runBlocking
+import org.onap.ccsdk.cds.error.catalog.core.ErrorCatalog
+import org.onap.ccsdk.cds.error.catalog.core.ErrorCatalogException
+import org.onap.ccsdk.cds.error.catalog.core.ErrorMessageLibConstants
+import org.onap.ccsdk.cds.error.catalog.core.ErrorPayload
+import org.onap.ccsdk.cds.error.catalog.core.GrpcErrorCodes
+import org.onap.ccsdk.cds.error.catalog.core.HttpErrorCodes
+import org.onap.ccsdk.cds.error.catalog.services.utils.ErrorCatalogUtils
+import org.springframework.boot.autoconfigure.condition.ConditionalOnBean
+import org.springframework.stereotype.Service
+import javax.annotation.PostConstruct
+
+@Service
+@ConditionalOnBean(ErrorCatalogLoadService::class)
+open class ErrorCatalogService(private var errorCatalogLoadService: ErrorCatalogLoadService) {
+
+ @PostConstruct
+ open fun init() = runBlocking {
+ errorCatalogLoadService.loadErrorCatalog()
+ }
+
+ fun errorPayload(errorCatalogException: ErrorCatalogException): ErrorPayload {
+ val errorCatalog = getErrorCatalog(errorCatalogException)
+ val errorPayload = ErrorPayload(errorCatalog.code, errorCatalog.errorId, errorCatalog.getMessage())
+ errorPayload.subErrors.addAll(errorCatalogException.errorPayload!!.subErrors)
+ if (errorCatalogException.cause != null) {
+ errorPayload.debugMessage = errorCatalogException.cause!!.printStackTrace().toString()
+ }
+ return errorPayload
+ }
+
+ fun getErrorCatalog(errorCatalogException: ErrorCatalogException): ErrorCatalog {
+ val errorMessage = getMessage(errorCatalogException.domain, errorCatalogException.name)
+ val errorCode =
+ if (errorCatalogException.code == -1) {
+ getProtocolErrorCode(
+ errorCatalogException.protocol,
+ errorCatalogException.name
+ )
+ } else {
+ errorCatalogException.code
+ }
+ val action: String
+ val errorCause: String
+ if (errorMessage.isNullOrEmpty()) {
+ action = errorCatalogException.action
+ errorCause = errorCatalogException.message ?: ""
+ } else {
+ action = ErrorCatalogUtils.readErrorActionFromMessage(errorMessage)
+ errorCause = errorCatalogException.message ?: ErrorCatalogUtils.readErrorCauseFromMessage(errorMessage)
+ }
+
+ return ErrorCatalog(
+ errorCatalogException.name,
+ errorCatalogException.domain,
+ errorCode,
+ action,
+ errorCause
+ )
+ }
+
+ private fun getProtocolErrorCode(protocol: String, type: String): Int {
+ return when (protocol) {
+ ErrorMessageLibConstants.ERROR_CATALOG_PROTOCOL_GRPC -> GrpcErrorCodes.code(type)
+ else -> HttpErrorCodes.code(type)
+ }
+ }
+
+ private fun getMessage(domain: String, key: String): String? {
+ return errorCatalogLoadService.getErrorMessage(domain, key)
+ }
+}
diff --git a/ms/error-catalog/services/src/main/kotlin/org/onap/ccsdk/cds/error/catalog/services/ErrorCatalogServiceExtensions.kt b/ms/error-catalog/services/src/main/kotlin/org/onap/ccsdk/cds/error/catalog/services/ErrorCatalogServiceExtensions.kt
new file mode 100644
index 000000000..bb4a8f15e
--- /dev/null
+++ b/ms/error-catalog/services/src/main/kotlin/org/onap/ccsdk/cds/error/catalog/services/ErrorCatalogServiceExtensions.kt
@@ -0,0 +1,25 @@
+/*
+ * Copyright © 2018-2019 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.cds.error.catalog.services
+
+import org.onap.ccsdk.cds.error.catalog.core.ErrorPayload
+import org.springframework.http.HttpStatus
+import org.springframework.http.ResponseEntity
+
+fun ErrorPayload.toResponseEntity(): ResponseEntity<ErrorPayload> {
+ return ResponseEntity(this, HttpStatus.resolve(this.code)!!)
+}
diff --git a/ms/error-catalog/services/src/main/kotlin/org/onap/ccsdk/cds/error/catalog/services/domain/Domain.kt b/ms/error-catalog/services/src/main/kotlin/org/onap/ccsdk/cds/error/catalog/services/domain/Domain.kt
new file mode 100755
index 000000000..7ade1c2a2
--- /dev/null
+++ b/ms/error-catalog/services/src/main/kotlin/org/onap/ccsdk/cds/error/catalog/services/domain/Domain.kt
@@ -0,0 +1,76 @@
+/*
+ * Copyright © 2020 IBM, Bell Canada.
+ *
+ * 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.error.catalog.services.domain
+
+import java.io.Serializable
+import javax.persistence.CascadeType
+import javax.persistence.Column
+import javax.persistence.Entity
+import javax.persistence.FetchType
+import javax.persistence.Id
+import javax.persistence.Lob
+import javax.persistence.ManyToMany
+import javax.persistence.Table
+import javax.persistence.UniqueConstraint
+import java.util.UUID
+import javax.persistence.JoinTable
+import javax.persistence.JoinColumn
+
+/**
+ * Provide ErrorCode Entity
+ *
+ * @author Steve Siani
+ * @version 1.0
+ */
+
+@Entity
+@Table(name = "ERROR_DOMAINS", uniqueConstraints = [UniqueConstraint(columnNames = ["name", "application_id"])])
+class Domain : Serializable {
+ @Id
+ var id: String = UUID.randomUUID().toString()
+
+ @Column(name = "name")
+ lateinit var name: String
+
+ @Column(name = "application_id")
+ lateinit var applicationId: String
+
+ @Lob
+ @Column(name = "description")
+ var description: String = ""
+
+ @ManyToMany(fetch = FetchType.EAGER, cascade = [CascadeType.ALL])
+ @JoinTable(
+ name = "ERROR_DOMAINS_ERROR_MESSAGES",
+ joinColumns = [JoinColumn(name = "domain_id", referencedColumnName = "id")],
+ inverseJoinColumns = [JoinColumn(name = "message_id", referencedColumnName = "id")]
+ )
+ @Column(name = "error_msg")
+ val errorMessages: MutableSet<ErrorMessageModel> = mutableSetOf()
+
+ constructor()
+
+ constructor(name: String, applicationId: String, description: String) {
+ this.name = name
+ this.description = description
+ this.applicationId = applicationId
+ }
+
+ companion object {
+ private const val serialVersionUID = 1L
+ }
+}
diff --git a/ms/error-catalog/services/src/main/kotlin/org/onap/ccsdk/cds/error/catalog/services/domain/ErrorMessageModel.kt b/ms/error-catalog/services/src/main/kotlin/org/onap/ccsdk/cds/error/catalog/services/domain/ErrorMessageModel.kt
new file mode 100644
index 000000000..a4e92af48
--- /dev/null
+++ b/ms/error-catalog/services/src/main/kotlin/org/onap/ccsdk/cds/error/catalog/services/domain/ErrorMessageModel.kt
@@ -0,0 +1,69 @@
+/*
+ * Copyright © 2020 IBM, Bell Canada.
+ *
+ * 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.error.catalog.services.domain
+
+import java.io.Serializable
+import java.util.UUID
+import javax.persistence.CascadeType
+import javax.persistence.Column
+import javax.persistence.Entity
+import javax.persistence.FetchType
+import javax.persistence.Id
+import javax.persistence.Lob
+import javax.persistence.ManyToMany
+import javax.persistence.Table
+import javax.persistence.UniqueConstraint
+
+/**
+ * Provide Error Message Model Entity
+ *
+ * @author Steve Siani
+ * @version 1.0
+ */
+@Entity
+@Table(name = "ERROR_MESSAGES", uniqueConstraints = [UniqueConstraint(columnNames = ["message_id"])])
+class ErrorMessageModel : Serializable {
+
+ @Id
+ var id: String = UUID.randomUUID().toString()
+
+ @Column(name = "message_id", nullable = false)
+ lateinit var messageID: String
+
+ @Lob
+ @Column(name = "cause")
+ var cause: String = ""
+
+ @Lob
+ @Column(name = "action")
+ lateinit var action: String
+
+ @ManyToMany(mappedBy = "errorMessages", fetch = FetchType.EAGER, cascade = [CascadeType.PERSIST])
+ val domains: MutableSet<Domain> = mutableSetOf()
+
+ companion object {
+ private const val serialVersionUID = 1L
+ }
+
+ constructor()
+
+ constructor(messageId: String, cause: String, action: String) {
+ this.messageID = messageId
+ this.cause = cause
+ this.action = action
+ }
+}
diff --git a/ms/error-catalog/services/src/main/kotlin/org/onap/ccsdk/cds/error/catalog/services/repository/DomainRepository.kt b/ms/error-catalog/services/src/main/kotlin/org/onap/ccsdk/cds/error/catalog/services/repository/DomainRepository.kt
new file mode 100644
index 000000000..197e385e0
--- /dev/null
+++ b/ms/error-catalog/services/src/main/kotlin/org/onap/ccsdk/cds/error/catalog/services/repository/DomainRepository.kt
@@ -0,0 +1,45 @@
+/*
+ * Copyright © 2020 IBM, Bell Canada.
+ *
+ * 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.error.catalog.services.repository
+
+import org.onap.ccsdk.cds.error.catalog.services.domain.Domain
+import org.springframework.data.jpa.repository.JpaRepository
+import org.springframework.stereotype.Repository
+
+/**
+ * @param <T> Model
+ */
+@Repository
+interface DomainRepository : JpaRepository<Domain, String> {
+
+ /**
+ * This is a findByNameAndApplicationId method
+ *
+ * @param name name
+ * @param applicationId applicationId
+ * @return Optional<T>
+ */
+ fun findByNameAndApplicationId(name: String, applicationId: String): Domain?
+
+ /**
+ * This is a findAllByApplicationId method
+ *
+ * @param applicationId applicationId
+ * @return List<T>
+ */
+ fun findAllByApplicationId(applicationId: String): List<Domain>
+}
diff --git a/ms/error-catalog/services/src/main/kotlin/org/onap/ccsdk/cds/error/catalog/services/repository/ErrorMessageModelRepository.kt b/ms/error-catalog/services/src/main/kotlin/org/onap/ccsdk/cds/error/catalog/services/repository/ErrorMessageModelRepository.kt
new file mode 100644
index 000000000..4a0f78672
--- /dev/null
+++ b/ms/error-catalog/services/src/main/kotlin/org/onap/ccsdk/cds/error/catalog/services/repository/ErrorMessageModelRepository.kt
@@ -0,0 +1,36 @@
+/*
+ * Copyright © 2020 IBM, Bell Canada.
+ *
+ * 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.error.catalog.services.repository
+
+import org.onap.ccsdk.cds.error.catalog.services.domain.ErrorMessageModel
+import org.springframework.data.jpa.repository.JpaRepository
+import org.springframework.stereotype.Repository
+
+/**
+ * @param <T> Model
+ */
+@Repository
+interface ErrorMessageModelRepository : JpaRepository<ErrorMessageModel, String> {
+
+ /**
+ * This is a findByDomains method
+ *
+ * @param domainId domainId
+ * @return List<T>
+ */
+ fun findByDomainsId(domainId: String): List<ErrorMessageModel>
+}
diff --git a/ms/error-catalog/services/src/main/kotlin/org/onap/ccsdk/cds/error/catalog/services/utils/ErrorCatalogUtils.kt b/ms/error-catalog/services/src/main/kotlin/org/onap/ccsdk/cds/error/catalog/services/utils/ErrorCatalogUtils.kt
new file mode 100644
index 000000000..967d3560c
--- /dev/null
+++ b/ms/error-catalog/services/src/main/kotlin/org/onap/ccsdk/cds/error/catalog/services/utils/ErrorCatalogUtils.kt
@@ -0,0 +1,39 @@
+/*
+ * Copyright © 2020 IBM, Bell Canada.
+ *
+ * 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.error.catalog.services.utils
+
+object ErrorCatalogUtils {
+ private const val REGEX_PATTERN = "^cause=(.*),action=(.*)"
+ private val regex = REGEX_PATTERN.toRegex()
+
+ fun readErrorCauseFromMessage(message: String): String {
+ val matchResults = regex.matchEntire(message)
+ return matchResults!!.groupValues[1]
+ }
+
+ fun readErrorActionFromMessage(message: String): String {
+ val matchResults = regex.matchEntire(message)
+ return matchResults!!.groupValues[2]
+ }
+}
+
+fun Exception.errorCauseOrDefault(): Throwable {
+ return this.cause ?: Throwable()
+}
+
+fun Exception.errorMessageOrDefault(): String {
+ return this.message ?: ""
+}
diff --git a/ms/pom.xml b/ms/pom.xml
index 7ec3f39a2..7a0168f5b 100644
--- a/ms/pom.xml
+++ b/ms/pom.xml
@@ -32,9 +32,29 @@
<description>Micro-services</description>
<modules>
+ <module>error-catalog</module>
<module>blueprintsprocessor</module>
<module>py-executor</module>
<module>command-executor</module>
<module>sdclistener</module>
</modules>
+
+ <build>
+ <pluginManagement>
+ <plugins>
+ <plugin>
+ <groupId>pl.project13.maven</groupId>
+ <artifactId>git-commit-id-plugin</artifactId>
+ <version>4.0.0</version>
+ <configuration>
+ <includeOnlyProperties>
+ <includeOnlyProperty>^git.build.(time|version)$</includeOnlyProperty>
+ <includeOnlyProperty>^git.commit.id.(abbrev|full)$</includeOnlyProperty>
+ </includeOnlyProperties>
+ <commitIdGenerationMode>full</commitIdGenerationMode>
+ </configuration>
+ </plugin>
+ </plugins>
+ </pluginManagement>
+ </build>
</project>
diff --git a/ms/py-executor/pom.xml b/ms/py-executor/pom.xml
index 9ede1b21b..5c8ac17cf 100644
--- a/ms/py-executor/pom.xml
+++ b/ms/py-executor/pom.xml
@@ -36,6 +36,7 @@
<ccsdk.project.version>${project.version}</ccsdk.project.version>
<ccsdk.build.timestamp>${maven.build.timestamp}</ccsdk.build.timestamp>
<maven.build.timestamp.format>yyyyMMdd'T'HHmmss'Z'</maven.build.timestamp.format>
+ <sonar.skip>true</sonar.skip>
</properties>
<build>
diff --git a/ms/py-executor/resource_resolution/README b/ms/py-executor/resource_resolution/README
index 222dae499..353600445 100644
--- a/ms/py-executor/resource_resolution/README
+++ b/ms/py-executor/resource_resolution/README
@@ -77,4 +77,67 @@ if __name__ == "__main__":
for response in client.process(generate_messages()):
print(response)
+```
+
+### Authorizarion header
+
+```
+from proto.BluePrintCommon_pb2 import ActionIdentifiers, CommonHeader
+from proto.BluePrintProcessing_pb2 import ExecutionServiceInput
+from resource_resolution.client import Client as ResourceResolutionClient
+
+
+def generate_messages():
+ commonHeader = CommonHeader()
+ commonHeader.requestId = "1234"
+ commonHeader.subRequestId = "1234-1"
+ commonHeader.originatorId = "CDS"
+
+ actionIdentifiers = ActionIdentifiers()
+ actionIdentifiers.blueprintName = "sample-cba"
+ actionIdentifiers.blueprintVersion = "1.0.0"
+ actionIdentifiers.actionName = "SampleScript"
+
+ input = ExecutionServiceInput(commonHeader=commonHeader, actionIdentifiers=actionIdentifiers)
+
+ commonHeader2 = CommonHeader()
+ commonHeader2.requestId = "1235"
+ commonHeader2.subRequestId = "1234-2"
+ commonHeader2.originatorId = "CDS"
+
+ input2 = ExecutionServiceInput(commonHeader=commonHeader2, actionIdentifiers=actionIdentifiers)
+
+ yield from [input, input2]
+
+
+if __name__ == "__main__":
+ with ResourceResolutionClient("127.0.0.1:9111", use_header_auth=True, header_auth_token="Token test") as client:
+ for response in client.process(generate_messages()):
+ print(response)
+
+```
+
+# ResourceResoulution helper class
+
+## How to use examples
+
+### Insecure channel
+
+```
+from resource_resolution.resource_resolution import ResourceResolution, WorkflowExecution, WorkflowExecutionResult
+
+
+if __name__ == "__main__":
+ with ResourceResolution(use_header_auth=True, header_auth_token="Basic token") as rr:
+ for response in rr.execute_workflows( # type: WorkflowExecutionResult
+ WorkflowExecution(
+ blueprint_name="blueprintName",
+ blueprint_version="1.0",
+ workflow_name="resource-assignment"
+ )
+ ):
+ if response.has_error:
+ print(response.error_message)
+ else:
+ print(response.payload)
``` \ No newline at end of file
diff --git a/ms/py-executor/resource_resolution/authorization.py b/ms/py-executor/resource_resolution/authorization.py
new file mode 100644
index 000000000..ae5954ecc
--- /dev/null
+++ b/ms/py-executor/resource_resolution/authorization.py
@@ -0,0 +1,64 @@
+"""Copyright 2020 Deutsche Telekom.
+
+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.
+"""
+from collections import namedtuple
+from typing import Any, Callable, List
+
+from grpc import ClientCallDetails, StreamStreamClientInterceptor
+
+
+class NewClientCallDetails(
+ namedtuple("_ClientCallDetails", ("method", "timeout", "metadata", "credentials")), ClientCallDetails
+):
+ """Namedtuple class to store metadata.
+
+ It's impossible to change original metadata in ClientCallDetails object
+ passed as a parameter to intercept method, so this class is going to get
+ original metadata tuple and add the authorization one.
+ """
+
+ pass
+
+
+class AuthTokenInterceptor(StreamStreamClientInterceptor):
+ """Interceptor class to set authorization header.
+
+ Set authorization header (but it can be any header also) for a gRPC call.
+ """
+
+ def __init__(self, token: str, header: str = "authorization") -> None:
+ """Initialize interceptor.
+
+ Set token and header which should be set into call. By default header is "authorization".
+ Header have to be lowercase.
+
+ Args:
+ token (str): Token value to be set.
+ header (str, optional): Header name. It must be lowercase. Defaults to "authorization".
+ """
+ self.token: str = token
+ if not header.islower():
+ raise ValueError("Header must be lowercase.")
+ self.header: str = header
+
+ def intercept_stream_stream(
+ self, continuation: Callable, client_call_details: ClientCallDetails, request_iterator: Any
+ ) -> Any:
+ """Add header into metadata."""
+ metadata: List = list(client_call_details.metadata) if client_call_details.metadata is not None else []
+ metadata.append((self.header, self.token,))
+ new_client_call_details: NewClientCallDetails = NewClientCallDetails(
+ client_call_details.method, client_call_details.timeout, metadata, client_call_details.credentials
+ )
+ return continuation(new_client_call_details, request_iterator)
diff --git a/ms/py-executor/resource_resolution/client.py b/ms/py-executor/resource_resolution/client.py
index 89087745c..fee168628 100644
--- a/ms/py-executor/resource_resolution/client.py
+++ b/ms/py-executor/resource_resolution/client.py
@@ -14,12 +14,20 @@ limitations under the License.
"""
from logging import Logger, getLogger
from types import TracebackType
-from typing import Iterable, List, Optional, Type
-
-from grpc import Channel, insecure_channel, secure_channel, ssl_channel_credentials
+from typing import Iterable, Optional, Type
+
+from grpc import (
+ Channel,
+ insecure_channel,
+ intercept_channel,
+ secure_channel,
+ ssl_channel_credentials,
+)
from proto.BluePrintProcessing_pb2 import ExecutionServiceInput, ExecutionServiceOutput
from proto.BluePrintProcessing_pb2_grpc import BluePrintProcessingServiceStub
+from .authorization import AuthTokenInterceptor
+
class Client:
"""Resource resoulution client class."""
@@ -28,20 +36,29 @@ class Client:
self,
server_address: str,
*,
+ # TLS/SSL configuration
use_ssl: bool = False,
root_certificates: bytes = None,
private_key: bytes = None,
certificate_chain: bytes = None,
+ # Authentication header configuration
+ use_header_auth: bool = False,
+ header_auth_token: str = None,
) -> None:
"""Client class initialization.
:param server_address: Address to server to connect.
:param use_ssl: Boolean flag to determine if secure channel should be created or not. Keyword argument.
:param root_certificates: The PEM-encoded root certificates. None if it shouldn't be used. Keyword argument.
- :param private_key: The PEM-encoded private key as a byte string, or None if no private key should be used. Keyword argument.
- :param certificate_chain: The PEM-encoded certificate chain as a byte string to use or or None if no certificate chain should be used. Keyword argument.
+ :param private_key: The PEM-encoded private key as a byte string, or None if no private key should be used.
+ Keyword argument.
+ :param certificate_chain: The PEM-encoded certificate chain as a byte string to use or or None if
+ no certificate chain should be used. Keyword argument.
+ :param use_header_auth: Boolean flag to determine if authorization headed shoud be added for every call or not.
+ Keyword argument.
+ :param header_auth_token: Authorization token value. Keyword argument.
"""
- self.logger = getLogger(__name__)
+ self.logger: Logger = getLogger(__name__)
if use_ssl:
self.channel: Channel = secure_channel(
server_address, ssl_channel_credentials(root_certificates, private_key, certificate_chain)
@@ -50,6 +67,8 @@ class Client:
else:
self.channel: Channel = insecure_channel(server_address)
self.logger.debug(f"Create insecure channel to connect to {server_address}")
+ if use_header_auth:
+ self.channel: Channel = intercept_channel(self.channel, AuthTokenInterceptor(header_auth_token))
self.stub: BluePrintProcessingServiceStub = BluePrintProcessingServiceStub(self.channel)
def close(self) -> None:
diff --git a/ms/py-executor/resource_resolution/resource_resolution.py b/ms/py-executor/resource_resolution/resource_resolution.py
new file mode 100644
index 000000000..e4f162f8f
--- /dev/null
+++ b/ms/py-executor/resource_resolution/resource_resolution.py
@@ -0,0 +1,294 @@
+"""Copyright 2020 Deutsche Telekom.
+
+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.
+"""
+
+from enum import Enum, unique
+from logging import Logger, getLogger
+from types import TracebackType
+from typing import Any, Dict, Generator, Optional, Type
+
+from google.protobuf import json_format
+
+from proto.BluePrintProcessing_pb2 import ExecutionServiceInput, ExecutionServiceOutput
+
+from .client import Client
+
+
+@unique
+class WorkflowMode(Enum):
+ """Workflow mode enumerator.
+
+ Workflow can be executed in two modes: synchronously and asynchronously.
+ This enumerator stores valid values to set the mode: SYNC for synchronously mode and ASYNC for asynchronously.
+ """
+
+ SYNC = "sync"
+ ASYNC = "async"
+
+
+class WorkflowExecution:
+ """Wokflow execution class.
+
+ Describes workflow to call. Set blueprint name and version and workflow name to execute.
+ Workflow inputs are optional, by default set to empty directory.
+ Workflow mode is also optional. It is set by default to call workflow synchronously.
+ """
+
+ def __init__(
+ self,
+ blueprint_name: str,
+ blueprint_version: str,
+ workflow_name: str,
+ workflow_inputs: Dict[str, Any] = None,
+ workflow_mode: WorkflowMode = WorkflowMode.SYNC,
+ ) -> None:
+ """Initialize workflow execution.
+
+ Get all needed information to execute workflow.
+
+ Args:
+ blueprint_name (str): Blueprint name to execute workflow from.
+ blueprint_version (str): Blueprint version.
+ workflow_name (str): Name of the workflow to execute
+ workflow_inputs (Dict[str, Any], optional): Key-value workflow inputs. Defaults to None.
+ workflow_mode (WorkflowMode, optional): Workflow execution mode. It can be run synchronously or
+ asynchronously. Defaults to WorkflowMode.SYNC.
+ """
+ self.blueprint_name: str = blueprint_name
+ self.blueprint_version: str = blueprint_version
+ self.workflow_name: str = workflow_name
+ if workflow_inputs is None:
+ workflow_inputs = {}
+ self.workflow_inputs: Dict[str, Any] = workflow_inputs
+ self.workflow_mode: WorkflowMode = workflow_mode
+
+ @property
+ def message(self) -> ExecutionServiceInput:
+ """Workflow execution protobuf message.
+
+ This message is going to be sent to gRPC server to execute workflow.
+
+ Returns:
+ ExecutionServiceInput: Properly filled protobuf message.
+ """
+ execution_msg: ExecutionServiceInput = ExecutionServiceInput()
+ execution_msg.actionIdentifiers.mode = self.workflow_mode.value
+ execution_msg.actionIdentifiers.blueprintName = self.blueprint_name
+ execution_msg.actionIdentifiers.blueprintVersion = self.blueprint_version
+ execution_msg.actionIdentifiers.actionName = self.workflow_name
+ execution_msg.payload.update({f"{self.workflow_name}-request": self.workflow_inputs})
+ return execution_msg
+
+
+class WorkflowExecutionResult:
+ """Result of workflow execution.
+
+ Store both workflow data and the result returns by server.
+ """
+
+ def __init__(self, workflow_execution: WorkflowExecution, execution_output: ExecutionServiceOutput) -> None:
+ """Initialize workflow execution result object.
+
+ Stores workflow execution data and execution result.
+
+ Args:
+ workflow_execution (WorkflowExecution): WorkflowExecution object which was used to call request.
+ execution_output (ExecutionServiceOutput): gRPC server response.
+ """
+ self.workflow_execution: WorkflowExecution = workflow_execution
+ self.execution_output: ExecutionServiceOutput = execution_output
+
+ @property
+ def blueprint_name(self) -> str:
+ """Name of blueprint used to call workflow.
+
+ This value is taken from server response not request (should be the same).
+
+ Returns:
+ str: Blueprint name
+ """
+ return self.execution_output.actionIdentifiers.blueprintName
+
+ @property
+ def blueprint_version(self) -> str:
+ """Blueprint version.
+
+ This value is taken from server response not request (should be the same).
+
+ Returns:
+ str: Blueprint version
+ """
+ return self.execution_output.actionIdentifiers.blueprintVersion
+
+ @property
+ def workflow_name(self) -> str:
+ """Workflow name.
+
+ This value is taken from server response not request (should be the same).
+
+ Returns:
+ str: Workflow name
+ """
+ return self.execution_output.actionIdentifiers.actionName
+
+ @property
+ def has_error(self) -> bool:
+ """Returns bool if request returns error or not.
+
+ Returns:
+ bool: True if response has status code different than 200
+ """
+ return self.execution_output.status.code != 200
+
+ @property
+ def error_message(self) -> str:
+ """Error message.
+
+ This property is available only if response has error. Otherwise AttributeError will be raised.
+
+ Raises:
+ AttributeError: Response has 200 response code and hasn't error message.
+
+ Returns:
+ str: Error message returned by server
+ """
+ if self.has_error:
+ return self.execution_output.status.errorMessage
+ raise AttributeError("Execution does not finish with error")
+
+ @property
+ def payload(self) -> dict:
+ """Response payload.
+
+ Payload retured by the server is migrated to Python dict.
+
+ Returns:
+ dict: Response's payload.
+ """
+ return json_format.MessageToDict(self.execution_output.payload)
+
+
+class ResourceResolution:
+ """Resource resolution class.
+
+ Helper class to connect to blueprintprocessor's gRPC server, send request to execute workflow and parse responses.
+ Blueprint with workflow must be deployed before workflow request.
+ It's possible to create both secre or unsecure connection (without SSL/TLS).
+ """
+
+ def __init__(
+ self,
+ *,
+ server_address: str = "127.0.0.1",
+ server_port: int = "9111",
+ use_ssl: bool = False,
+ root_certificates: bytes = None,
+ private_key: bytes = None,
+ certificate_chain: bytes = None,
+ # Authentication header configuration
+ use_header_auth: bool = False,
+ header_auth_token: str = None,
+ ) -> None:
+ """Resource resolution object initialization.
+
+ Args:
+ server_address (str, optional): gRPC server address. Defaults to "127.0.0.1".
+ server_port (int, optional): gRPC server address port. Defaults to "9111".
+ use_ssl (bool, optional): Boolean flag to determine if secure channel should be created or not.
+ Defaults to False.
+ root_certificates (bytes, optional): The PEM-encoded root certificates. None if it shouldn't be used.
+ Defaults to None.
+ private_key (bytes, optional): The PEM-encoded private key as a byte string, or None if no private key
+ should be used. Defaults to None.
+ certificate_chain (bytes, optional): The PEM-encoded certificate chain as a byte string to use or or None if
+ no certificate chain should be used. Defaults to None.
+ use_header_auth (bool, optional): Boolean flag to determine if authorization headed shoud be added for
+ every call or not. Defaults to False.
+ header_auth_token (str, optional): Authorization token value. Defaults to None.
+ """
+ # Logger
+ self.logger: Logger = getLogger(__name__)
+ # Client settings
+ self.client_server_address: str = server_address
+ self.client_server_port: str = server_port
+ self.client_use_ssl: bool = use_ssl
+ self.client_root_certificates: bytes = root_certificates
+ self.client_private_key: bytes = private_key
+ self.client_certificate_chain: bytes = certificate_chain
+ self.client_use_header_auth: bool = use_header_auth
+ self.client_header_auth_token: str = header_auth_token
+ self.client: Client = None
+
+ def __enter__(self) -> "ResourceResolution":
+ """Enter ResourceResolution instance context.
+
+ Client connection is created.
+ """
+ self.client = Client(
+ server_address=f"{self.client_server_address}:{self.client_server_port}",
+ use_ssl=self.client_use_ssl,
+ root_certificates=self.client_root_certificates,
+ private_key=self.client_private_key,
+ certificate_chain=self.client_certificate_chain,
+ use_header_auth=self.client_use_header_auth,
+ header_auth_token=self.client_header_auth_token,
+ )
+ return self
+
+ def __exit__(
+ self,
+ unused_exc_type: Optional[Type[BaseException]],
+ unused_exc_value: Optional[BaseException],
+ unused_traceback: Optional[TracebackType],
+ ) -> None:
+ """Exit ResourceResolution instance context.
+
+ Client connection is closed.
+ """
+ self.client.close()
+
+ def execute_workflows(self, *workflows: WorkflowExecution) -> Generator[WorkflowExecutionResult, None, None]:
+ """Execute provided workflows.
+
+ Workflows are going to be execured using one gRPC API call. Depends of implementation that may has
+ some consequences. In some cases if any request fails all requests after that won't be called.
+
+ Responses and zipped with workflows and WorkflowExecutionResult object is initialized and yielded.
+
+ Raises:
+ AttributeError: Raises if client object is not created. It occurs only if you not uses context manager.
+ Then user have to create client instance for ResourceResolution object by himself calling:
+ ```
+ resource_resoulution.client = Client(
+ server_address=f"{resource_resoulution.client_server_address}:{resource_resoulution.client_server_port}",
+ use_ssl=resource_resoulution.client_use_ssl,
+ root_certificates=resource_resoulution.client_root_certificates,
+ private_key=resource_resoulution.client_private_key,
+ certificate_chain=resource_resoulution.client_certificate_chain,
+ use_header_auth=resource_resoulution.client_use_header_auth,
+ header_auth_token=resource_resoulution.client_header_auth_token,
+ )
+ ```
+ Remeber also to close client connection.
+
+ Returns:
+ Generator[WorkflowExecutionResult, None, None]: WorkflowExecutionResult object
+ with both WorkflowExection object and server response for it's request.
+ """
+ self.logger.debug("Execute workflows")
+ if not self.client:
+ raise AttributeError("gRPC client not connected")
+
+ for response, workflow in zip(self.client.process((workflow.message for workflow in workflows)), workflows):
+ yield WorkflowExecutionResult(workflow, response)
diff --git a/ms/py-executor/resource_resolution/tests/authorization_interceptor_test.py b/ms/py-executor/resource_resolution/tests/authorization_interceptor_test.py
new file mode 100644
index 000000000..4b03f0b36
--- /dev/null
+++ b/ms/py-executor/resource_resolution/tests/authorization_interceptor_test.py
@@ -0,0 +1,50 @@
+"""Copyright 2020 Deutsche Telekom.
+
+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.
+"""
+
+from unittest.mock import MagicMock, _Call
+
+import pytest
+
+from resource_resolution.authorization import AuthTokenInterceptor, NewClientCallDetails
+
+
+def test_resource_resolution_auth_token_interceptor():
+ """Test AuthTokenInterceptor class.
+
+ - Checks if it's correctly set default value.
+ - Checks if it's correctly set passed values.
+ - Checks if it's correctly checked if all header characters are lowercase.
+ - Checks if continuation function is called with headers setted
+ """
+ interceptor: AuthTokenInterceptor = AuthTokenInterceptor("test_token", header="header")
+ assert interceptor.token == "test_token"
+ assert interceptor.header == "header"
+
+ interceptor: AuthTokenInterceptor = AuthTokenInterceptor("test_token")
+ assert interceptor.token == "test_token"
+ assert interceptor.header == "authorization"
+
+ with pytest.raises(ValueError):
+ AuthTokenInterceptor("test_token", header="Auth")
+
+ continuation_mock: MagicMock = MagicMock()
+ client_call_details: MagicMock = MagicMock()
+ request_iterator: MagicMock = MagicMock()
+
+ interceptor.intercept_stream_stream(continuation_mock, client_call_details, request_iterator)
+ continuation_mock.assert_called_once()
+ client_call_details_argument: _Call = continuation_mock.call_args_list[0][0][0] # Get NewClientCallDetails instance
+ assert isinstance(client_call_details_argument, NewClientCallDetails)
+ assert client_call_details_argument.metadata[0] == (interceptor.header, interceptor.token)
diff --git a/ms/py-executor/resource_resolution/tests/resource_resolution_test.py b/ms/py-executor/resource_resolution/tests/resource_resolution_test.py
new file mode 100644
index 000000000..8a41357e6
--- /dev/null
+++ b/ms/py-executor/resource_resolution/tests/resource_resolution_test.py
@@ -0,0 +1,105 @@
+"""Copyright 2020 Deutsche Telekom.
+
+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.
+"""
+
+from google.protobuf import json_format
+from pytest import raises
+
+from resource_resolution.resource_resolution import (
+ ExecutionServiceInput,
+ ExecutionServiceOutput,
+ WorkflowExecution,
+ WorkflowExecutionResult,
+ WorkflowMode,
+)
+
+
+def test_workflow_execution_class():
+ """Workflow execution class tests.
+
+ - Test initialization and default values
+ - Test request message formatting
+ """
+ # Without inputs
+ workflow_execution: WorkflowExecution = WorkflowExecution("test blueprint", "test version", "test workflow")
+ assert workflow_execution.blueprint_name == "test blueprint"
+ assert workflow_execution.blueprint_version == "test version"
+ assert workflow_execution.workflow_name == "test workflow"
+ assert workflow_execution.workflow_inputs == {}
+ assert workflow_execution.workflow_mode == WorkflowMode.SYNC
+
+ msg: ExecutionServiceInput = workflow_execution.message
+ msg_dict: dict = json_format.MessageToDict(msg)
+ assert msg_dict["actionIdentifiers"]["blueprintName"] == "test blueprint"
+ assert msg_dict["actionIdentifiers"]["blueprintVersion"] == "test version"
+ assert msg_dict["actionIdentifiers"]["actionName"] == "test workflow"
+ assert msg_dict["actionIdentifiers"]["mode"] == "sync"
+ assert list(msg_dict["payload"].keys())[0] == "test workflow-request"
+ assert msg_dict["payload"]["test workflow-request"] == {}
+
+ # With inputs
+ workflow_execution: WorkflowExecution = WorkflowExecution(
+ "test blueprint2",
+ "test version2",
+ "test workflow2",
+ workflow_inputs={"test": "test"},
+ workflow_mode=WorkflowMode.ASYNC,
+ )
+ assert workflow_execution.blueprint_name == "test blueprint2"
+ assert workflow_execution.blueprint_version == "test version2"
+ assert workflow_execution.workflow_name == "test workflow2"
+ assert workflow_execution.workflow_inputs == {"test": "test"}
+ assert workflow_execution.workflow_mode == WorkflowMode.ASYNC
+
+ msg: ExecutionServiceInput = workflow_execution.message
+ msg_dict: dict = json_format.MessageToDict(msg)
+ assert msg_dict["actionIdentifiers"]["blueprintName"] == "test blueprint2"
+ assert msg_dict["actionIdentifiers"]["blueprintVersion"] == "test version2"
+ assert msg_dict["actionIdentifiers"]["actionName"] == "test workflow2"
+ assert msg_dict["actionIdentifiers"]["mode"] == "async"
+ assert list(msg_dict["payload"].keys())[0] == "test workflow2-request"
+ assert msg_dict["payload"]["test workflow2-request"] == {"test": "test"}
+
+
+def test_workflow_execution_result_class():
+ """Workflow execution result class tests.
+
+ - Test initizalization and default values
+ - Test `has_error` property
+ - Test `error_message` property
+ - Test payload formatting
+ """
+ workflow_execution: WorkflowExecution = WorkflowExecution("test blueprint", "test version", "test workflow")
+ execution_output: ExecutionServiceOutput = ExecutionServiceOutput()
+ execution_output.actionIdentifiers.blueprintName = "test blueprint"
+ execution_output.actionIdentifiers.blueprintVersion = "test version"
+ execution_output.actionIdentifiers.actionName = "test workflow"
+ execution_output.status.code = 200
+
+ execution_result: WorkflowExecutionResult = WorkflowExecutionResult(workflow_execution, execution_output)
+ assert not execution_result.has_error
+ with raises(AttributeError):
+ execution_result.error_message
+ assert execution_result.payload == {}
+ assert execution_result.blueprint_name == "test blueprint"
+ assert execution_result.blueprint_version == "test version"
+ assert execution_result.workflow_name == "test workflow"
+
+ execution_output.payload.update({"test_key": "test_value"})
+ execution_result: WorkflowExecutionResult = WorkflowExecutionResult(workflow_execution, execution_output)
+ assert execution_result.payload == {"test_key": "test_value"}
+
+ execution_output.status.code = 500
+ assert execution_result.has_error
+ assert execution_result.error_message == ""
diff --git a/ms/sdclistener/application/pom.xml b/ms/sdclistener/application/pom.xml
index 88d8d1b2f..72f552cdd 100644
--- a/ms/sdclistener/application/pom.xml
+++ b/ms/sdclistener/application/pom.xml
@@ -63,7 +63,6 @@
<dependency>
<groupId>org.onap.sdc.sdc-distribution-client</groupId>
<artifactId>sdc-distribution-client</artifactId>
- <version>1.3.0</version>
</dependency>
<dependency>
@@ -112,6 +111,11 @@
</dependency>
<dependency>
+ <groupId>ch.qos.logback</groupId>
+ <artifactId>logback-classic</artifactId>
+ </dependency>
+
+ <dependency>
<groupId>io.projectreactor</groupId>
<artifactId>reactor-core</artifactId>
<scope>compile</scope>
diff --git a/ms/sdclistener/application/src/main/resources/application.yaml b/ms/sdclistener/application/src/main/resources/application.yaml
index 424f0a5c0..d07d8ae61 100644
--- a/ms/sdclistener/application/src/main/resources/application.yaml
+++ b/ms/sdclistener/application/src/main/resources/application.yaml
@@ -2,7 +2,7 @@ listenerservice:
config:
asdcAddress: ${asdcAddress:localhost:8443}
messageBusAddress: ${messageBusAddress:localhost}
- user: ${sdcusername:vid}
+ user: ${sdcusername:cds}
password: ${password:Kp8bJ4SXszM0WXlhak3eHlcse2gAw84vaoGGmJvUy2U}
pollingInterval: ${pollingInterval:15}
pollingTimeout: ${pollingTimeout:60}
diff --git a/ms/sdclistener/application/src/test/java/org/onap/ccsdk/cds/sdclistener/SdcListenerConfigurationTest.java b/ms/sdclistener/application/src/test/java/org/onap/ccsdk/cds/sdclistener/SdcListenerConfigurationTest.java
index 26757a657..8275bc084 100644
--- a/ms/sdclistener/application/src/test/java/org/onap/ccsdk/cds/sdclistener/SdcListenerConfigurationTest.java
+++ b/ms/sdclistener/application/src/test/java/org/onap/ccsdk/cds/sdclistener/SdcListenerConfigurationTest.java
@@ -37,7 +37,7 @@ public class SdcListenerConfigurationTest {
public void testCdsSdcListenerConfiguration() {
assertEquals(listenerConfiguration.getAsdcAddress(), "localhost:8443");
assertEquals(listenerConfiguration.getMsgBusAddress().stream().findFirst().get(), "localhost");
- assertEquals(listenerConfiguration.getUser(), "vid");
+ assertEquals(listenerConfiguration.getUser(), "cds");
assertEquals(listenerConfiguration.getPassword(), "Kp8bJ4SXszM0WXlhak3eHlcse2gAw84vaoGGmJvUy2U");
assertEquals(listenerConfiguration.getPollingInterval(), 15);
assertEquals(listenerConfiguration.getPollingTimeout(), 60);
diff --git a/ms/sdclistener/parent/pom.xml b/ms/sdclistener/parent/pom.xml
index eaa1d60f4..2cbc79dcc 100755
--- a/ms/sdclistener/parent/pom.xml
+++ b/ms/sdclistener/parent/pom.xml
@@ -40,7 +40,7 @@
<mockk.version>1.9</mockk.version>
<dmaap.client.version>1.1.5</dmaap.client.version>
<mockkserver.version>5.5.1</mockkserver.version>
- <sdc-distribution-client.version>1.3.0</sdc-distribution-client.version>
+ <sdc-distribution-client.version>1.4.0</sdc-distribution-client.version>
<jmockit.version>1.19</jmockit.version>
<reactorcore.version>3.2.6.RELEASE</reactorcore.version>
</properties>