From 280a0f6c73ab1c1aed9ee87fbd053d01d3838d70 Mon Sep 17 00:00:00 2001 From: "Singal, Kapil (ks220y)" Date: Wed, 12 Sep 2018 16:26:03 -0400 Subject: Controller Blueprints Nitrogen to Oxygen Migration Changing package structure from org.onap.ccsdk.config to org.onap.ccsdk.features Change-Id: I7d52b498f11ed892d547220cc4354298b6182c77 Issue-ID: CCSDK-560 Signed-off-by: Singal, Kapil (ks220y) --- .../plugin/assignment-provider/pom.xml | 10 +- .../assignment/ConfigAssignmentConstants.java | 37 -- .../assignment/data/ResourceAssignmentData.java | 163 -------- .../assignment/processor/DBResourceProcessor.java | 267 ------------- .../processor/DefaultResourceProcessor.java | 107 ----- .../processor/InputResourceProcessor.java | 96 ----- .../processor/MdsalResourceProcessor.java | 239 ------------ .../assignment/processor/ProcessorFactory.java | 52 --- .../processor/ResourceAssignmentProcessor.java | 120 ------ .../assignment/service/ConfigAssignmentNode.java | 231 ----------- .../service/ConfigAssignmentPersistService.java | 123 ------ .../service/ConfigAssignmentProcessService.java | 238 ------------ .../service/ConfigAssignmentService.java | 35 -- .../service/ConfigAssignmentServiceImpl.java | 79 ---- .../assignment/service/ConfigAssignmentUtils.java | 305 --------------- .../assignment/service/ConfigPreviewService.java | 119 ------ .../service/ResourceDictionaryService.java | 112 ------ .../assignment/service/ResourceModelService.java | 97 ----- .../assignment/ConfigAssignmentConstants.java | 37 ++ .../assignment/data/ResourceAssignmentData.java | 164 ++++++++ .../assignment/processor/DBResourceProcessor.java | 267 +++++++++++++ .../processor/DefaultResourceProcessor.java | 107 +++++ .../processor/InputResourceProcessor.java | 96 +++++ .../processor/MdsalResourceProcessor.java | 239 ++++++++++++ .../assignment/processor/ProcessorFactory.java | 52 +++ .../processor/ResourceAssignmentProcessor.java | 120 ++++++ .../assignment/service/ConfigAssignmentNode.java | 231 +++++++++++ .../service/ConfigAssignmentPersistService.java | 123 ++++++ .../service/ConfigAssignmentProcessService.java | 238 ++++++++++++ .../service/ConfigAssignmentService.java | 36 ++ .../service/ConfigAssignmentServiceImpl.java | 80 ++++ .../assignment/service/ConfigAssignmentUtils.java | 305 +++++++++++++++ .../assignment/service/ConfigPreviewService.java | 119 ++++++ .../service/ResourceDictionaryService.java | 112 ++++++ .../assignment/service/ResourceModelService.java | 97 +++++ .../org/opendaylight/blueprint/impl-blueprint.xml | 18 +- .../processor/DBResourceProcessorTest.java | 231 ----------- .../processor/DefaultResourceProcessorTest.java | 127 ------ .../processor/InputResourceProcessorTest.java | 178 --------- .../processor/MdsalResourceProcessorTest.java | 268 ------------- .../service/ConfigAssignmentNodeTest.java | 246 ------------ .../service/ConfigPreviewServiceTest.java | 111 ------ .../service/ConfigResourceAssignmentTestUtils.java | 182 --------- .../service/ResourceAssignmentGenerationTest.java | 110 ------ .../service/ResourceAssignmentValidation.java | 94 ----- .../assignment/service/TopologicalSortingTest.java | 60 --- .../processor/DBResourceProcessorTest.java | 232 +++++++++++ .../processor/DefaultResourceProcessorTest.java | 128 ++++++ .../processor/InputResourceProcessorTest.java | 179 +++++++++ .../processor/MdsalResourceProcessorTest.java | 269 +++++++++++++ .../service/ConfigAssignmentNodeTest.java | 247 ++++++++++++ .../service/ConfigPreviewServiceTest.java | 113 ++++++ .../service/ConfigResourceAssignmentTestUtils.java | 183 +++++++++ .../service/ResourceAssignmentGenerationTest.java | 111 ++++++ .../service/ResourceAssignmentValidation.java | 95 +++++ .../assignment/service/TopologicalSortingTest.java | 60 +++ .../service_templates/resource_assignment.json | 4 +- .../resource_assignment/resource_assignment.json | 4 +- .../vpe-201802-baseconfig.json | 4 +- .../plugin/generator-provider/pom.xml | 8 +- .../config/generator/ConfigGeneratorConstant.java | 49 --- .../config/generator/data/ConfigGeneratorInfo.java | 102 ----- .../generator/service/ConfigGeneratorNode.java | 140 ------- .../generator/service/ConfigGeneratorService.java | 33 -- .../service/ConfigGeneratorServiceImpl.java | 143 ------- .../generator/tool/CustomJsonNodeFactory.java | 30 -- .../config/generator/tool/CustomTextNode.java | 42 -- .../ccsdk/config/generator/tool/EscapeUtils.java | 82 ---- .../generator/ConfigGeneratorConstant.java | 49 +++ .../generator/data/ConfigGeneratorInfo.java | 102 +++++ .../generator/service/ConfigGeneratorNode.java | 140 +++++++ .../generator/service/ConfigGeneratorService.java | 33 ++ .../service/ConfigGeneratorServiceImpl.java | 143 +++++++ .../generator/tool/CustomJsonNodeFactory.java | 30 ++ .../features/generator/tool/CustomTextNode.java | 42 ++ .../ccsdk/features/generator/tool/EscapeUtils.java | 82 ++++ .../org/opendaylight/blueprint/impl-blueprint.xml | 12 +- .../generator/service/ConfigGeneratorNodeTest.java | 222 ----------- .../config/generator/tool/EscapeUtilsTest.java | 51 --- .../generator/service/ConfigGeneratorNodeTest.java | 223 +++++++++++ .../features/generator/tool/EscapeUtilsTest.java | 52 +++ .../service_templates/generate_configuration.json | 6 +- blueprints-processor/plugin/model-provider/pom.xml | 16 +- .../ccsdk/config/model/ConfigModelConstant.java | 147 ------- .../ccsdk/config/model/ConfigModelException.java | 50 --- .../org/onap/ccsdk/config/model/ValidTypes.java | 105 ----- .../config/model/data/ArtifactDefinition.java | 105 ----- .../onap/ccsdk/config/model/data/ArtifactType.java | 102 ----- .../config/model/data/CapabilityAssignment.java | 49 --- .../config/model/data/CapabilityDefinition.java | 88 ----- .../ccsdk/config/model/data/ConstraintClause.java | 150 ------- .../org/onap/ccsdk/config/model/data/DataType.java | 88 ----- .../onap/ccsdk/config/model/data/EntrySchema.java | 36 -- .../ccsdk/config/model/data/Implementation.java | 49 --- .../config/model/data/InterfaceAssignment.java | 58 --- .../config/model/data/InterfaceDefinition.java | 58 --- .../onap/ccsdk/config/model/data/NodeTemplate.java | 112 ------ .../org/onap/ccsdk/config/model/data/NodeType.java | 114 ------ .../config/model/data/OperationAssignment.java | 76 ---- .../config/model/data/OperationDefinition.java | 76 ---- .../config/model/data/PropertyDefinition.java | 125 ------ .../config/model/data/RelationshipTemplate.java | 56 --- .../config/model/data/RequirementAssignment.java | 67 ---- .../config/model/data/RequirementDefinition.java | 85 ---- .../config/model/data/ResourceAssignment.java | 165 -------- .../ccsdk/config/model/data/ServiceTemplate.java | 118 ------ .../ccsdk/config/model/data/TopologyTemplate.java | 97 ----- .../org/onap/ccsdk/config/model/data/Workflow.java | 39 -- .../config/model/data/api/ActionIdentifiers.java | 62 --- .../ccsdk/config/model/data/api/CommonHeader.java | 82 ---- .../onap/ccsdk/config/model/data/api/Flags.java | 40 -- .../onap/ccsdk/config/model/data/api/Status.java | 61 --- .../config/model/data/api/TransactionRequest.java | 45 --- .../config/model/data/api/TransactionResponse.java | 46 --- .../config/model/data/dict/ResourceDefinition.java | 103 ----- .../config/model/data/dict/SourcesDefinition.java | 46 --- .../config/model/data/dict/SourcesProperties.java | 125 ------ .../ccsdk/config/model/domain/ConfigModel.java | 231 ----------- .../config/model/domain/ConfigModelContent.java | 91 ----- .../config/model/domain/ResourceDictionary.java | 162 -------- .../ccsdk/config/model/service/ComponentNode.java | 41 -- .../model/service/ComponentNodeDelegate.java | 42 -- .../config/model/service/ComponentNodeService.java | 32 -- .../model/service/ComponentNodeServiceImpl.java | 174 --------- .../model/service/ConfigBlueprintService.java | 100 ----- .../config/model/service/ConfigModelNode.java | 24 -- .../config/model/service/ConfigModelService.java | 55 --- .../model/service/ConfigModelServiceImpl.java | 244 ------------ .../ccsdk/config/model/utils/ExpressionUtils.java | 191 --------- .../ccsdk/config/model/utils/JsonParserUtils.java | 59 --- .../onap/ccsdk/config/model/utils/JsonUtils.java | 109 ------ .../config/model/utils/NodePropertyUtils.java | 187 --------- .../config/model/utils/PrepareContextUtils.java | 63 --- .../model/utils/ResourceAssignmentUtils.java | 302 --------------- .../model/utils/ResourceDictionaryUtils.java | 119 ------ .../config/model/utils/ServiceTemplateUtils.java | 277 ------------- .../model/utils/TopologicalSortingUtils.java | 188 --------- .../config/model/utils/TransformationUtils.java | 429 --------------------- .../config/model/validator/DataTypeValidator.java | 109 ------ .../config/model/validator/NodeTypeValidator.java | 237 ------------ .../validator/PropertyDefinitionValidator.java | 89 ----- .../validator/ResourceAssignmentValidator.java | 163 -------- .../model/validator/ServiceTemplateValidator.java | 129 ------- .../model/validator/TopologyTemplateValidator.java | 203 ---------- .../ccsdk/features/model/ConfigModelConstant.java | 147 +++++++ .../ccsdk/features/model/ConfigModelException.java | 50 +++ .../org/onap/ccsdk/features/model/ValidTypes.java | 105 +++++ .../features/model/data/ArtifactDefinition.java | 105 +++++ .../ccsdk/features/model/data/ArtifactType.java | 102 +++++ .../features/model/data/CapabilityAssignment.java | 49 +++ .../features/model/data/CapabilityDefinition.java | 88 +++++ .../features/model/data/ConstraintClause.java | 150 +++++++ .../onap/ccsdk/features/model/data/DataType.java | 88 +++++ .../ccsdk/features/model/data/EntrySchema.java | 36 ++ .../ccsdk/features/model/data/Implementation.java | 49 +++ .../features/model/data/InterfaceAssignment.java | 58 +++ .../features/model/data/InterfaceDefinition.java | 58 +++ .../ccsdk/features/model/data/NodeTemplate.java | 112 ++++++ .../onap/ccsdk/features/model/data/NodeType.java | 114 ++++++ .../features/model/data/OperationAssignment.java | 76 ++++ .../features/model/data/OperationDefinition.java | 76 ++++ .../features/model/data/PropertyDefinition.java | 125 ++++++ .../features/model/data/RelationshipTemplate.java | 56 +++ .../features/model/data/RequirementAssignment.java | 67 ++++ .../features/model/data/RequirementDefinition.java | 85 ++++ .../features/model/data/ResourceAssignment.java | 165 ++++++++ .../ccsdk/features/model/data/ServiceTemplate.java | 118 ++++++ .../features/model/data/TopologyTemplate.java | 97 +++++ .../onap/ccsdk/features/model/data/Workflow.java | 39 ++ .../features/model/data/api/ActionIdentifiers.java | 62 +++ .../features/model/data/api/CommonHeader.java | 82 ++++ .../onap/ccsdk/features/model/data/api/Flags.java | 40 ++ .../onap/ccsdk/features/model/data/api/Status.java | 61 +++ .../model/data/api/TransactionRequest.java | 45 +++ .../model/data/api/TransactionResponse.java | 46 +++ .../model/data/dict/ResourceDefinition.java | 105 +++++ .../model/data/dict/SourcesDefinition.java | 46 +++ .../model/data/dict/SourcesProperties.java | 125 ++++++ .../ccsdk/features/model/domain/ConfigModel.java | 231 +++++++++++ .../features/model/domain/ConfigModelContent.java | 91 +++++ .../features/model/domain/ResourceDictionary.java | 162 ++++++++ .../features/model/service/ComponentNode.java | 41 ++ .../model/service/ComponentNodeDelegate.java | 42 ++ .../model/service/ComponentNodeService.java | 32 ++ .../model/service/ComponentNodeServiceImpl.java | 174 +++++++++ .../model/service/ConfigBlueprintService.java | 100 +++++ .../features/model/service/ConfigModelNode.java | 24 ++ .../features/model/service/ConfigModelService.java | 56 +++ .../model/service/ConfigModelServiceImpl.java | 244 ++++++++++++ .../features/model/utils/ExpressionUtils.java | 191 +++++++++ .../features/model/utils/JsonParserUtils.java | 59 +++ .../onap/ccsdk/features/model/utils/JsonUtils.java | 110 ++++++ .../features/model/utils/NodePropertyUtils.java | 187 +++++++++ .../features/model/utils/PrepareContextUtils.java | 64 +++ .../model/utils/ResourceAssignmentUtils.java | 303 +++++++++++++++ .../model/utils/ResourceDictionaryUtils.java | 120 ++++++ .../features/model/utils/ServiceTemplateUtils.java | 277 +++++++++++++ .../model/utils/TopologicalSortingUtils.java | 188 +++++++++ .../features/model/utils/TransformationUtils.java | 429 +++++++++++++++++++++ .../model/validator/DataTypeValidator.java | 109 ++++++ .../model/validator/NodeTypeValidator.java | 238 ++++++++++++ .../validator/PropertyDefinitionValidator.java | 89 +++++ .../validator/ResourceAssignmentValidator.java | 164 ++++++++ .../model/validator/ServiceTemplateValidator.java | 130 +++++++ .../model/validator/TopologyTemplateValidator.java | 204 ++++++++++ .../org/opendaylight/blueprint/impl-blueprint.xml | 20 +- .../config/model/ResourceDictionaryUtilsTest.java | 216 ----------- .../config/model/utils/JsonParserUtilsTest.java | 43 --- .../ccsdk/config/model/utils/JsonUtilsTest.java | 103 ----- .../model/utils/ResourceAssignmentUtilsTest.java | 198 ---------- .../model/utils/ServiceTemplateUtilsTest.java | 77 ---- .../model/utils/TransformationUtilsTest.java | 90 ----- .../validator/ServiceTemplateValidationTest.java | 47 --- .../config/params/service/ComponentNodeTest.java | 140 ------- .../params/service/ConfigModelServiceTest.java | 219 ----------- .../config/params/service/ExpressionUtilsTest.java | 76 ---- .../config/params/service/MockComponentNode.java | 62 --- .../params/service/ServiceTemplateCreateUtils.java | 193 --------- .../model/ResourceDictionaryUtilsTest.java | 218 +++++++++++ .../features/model/utils/JsonParserUtilsTest.java | 45 +++ .../ccsdk/features/model/utils/JsonUtilsTest.java | 105 +++++ .../model/utils/ResourceAssignmentUtilsTest.java | 200 ++++++++++ .../model/utils/ServiceTemplateUtilsTest.java | 78 ++++ .../model/utils/TransformationUtilsTest.java | 92 +++++ .../validator/ServiceTemplateValidationTest.java | 49 +++ .../features/params/service/ComponentNodeTest.java | 140 +++++++ .../params/service/ConfigModelServiceTest.java | 219 +++++++++++ .../params/service/ExpressionUtilsTest.java | 76 ++++ .../features/params/service/MockComponentNode.java | 63 +++ .../params/service/ServiceTemplateCreateUtils.java | 193 +++++++++ .../src/test/resources/componentnode/default.json | 4 +- .../test/resources/service_templates/default.json | 10 +- .../service_templates/resource_assignment.json | 4 +- .../resources/service_templates/vrr_config.json | 2 +- 234 files changed, 13361 insertions(+), 13321 deletions(-) delete mode 100644 blueprints-processor/plugin/assignment-provider/src/main/java/org/onap/ccsdk/config/assignment/ConfigAssignmentConstants.java delete mode 100644 blueprints-processor/plugin/assignment-provider/src/main/java/org/onap/ccsdk/config/assignment/data/ResourceAssignmentData.java delete mode 100644 blueprints-processor/plugin/assignment-provider/src/main/java/org/onap/ccsdk/config/assignment/processor/DBResourceProcessor.java delete mode 100644 blueprints-processor/plugin/assignment-provider/src/main/java/org/onap/ccsdk/config/assignment/processor/DefaultResourceProcessor.java delete mode 100644 blueprints-processor/plugin/assignment-provider/src/main/java/org/onap/ccsdk/config/assignment/processor/InputResourceProcessor.java delete mode 100644 blueprints-processor/plugin/assignment-provider/src/main/java/org/onap/ccsdk/config/assignment/processor/MdsalResourceProcessor.java delete mode 100644 blueprints-processor/plugin/assignment-provider/src/main/java/org/onap/ccsdk/config/assignment/processor/ProcessorFactory.java delete mode 100644 blueprints-processor/plugin/assignment-provider/src/main/java/org/onap/ccsdk/config/assignment/processor/ResourceAssignmentProcessor.java delete mode 100644 blueprints-processor/plugin/assignment-provider/src/main/java/org/onap/ccsdk/config/assignment/service/ConfigAssignmentNode.java delete mode 100644 blueprints-processor/plugin/assignment-provider/src/main/java/org/onap/ccsdk/config/assignment/service/ConfigAssignmentPersistService.java delete mode 100644 blueprints-processor/plugin/assignment-provider/src/main/java/org/onap/ccsdk/config/assignment/service/ConfigAssignmentProcessService.java delete mode 100644 blueprints-processor/plugin/assignment-provider/src/main/java/org/onap/ccsdk/config/assignment/service/ConfigAssignmentService.java delete mode 100644 blueprints-processor/plugin/assignment-provider/src/main/java/org/onap/ccsdk/config/assignment/service/ConfigAssignmentServiceImpl.java delete mode 100644 blueprints-processor/plugin/assignment-provider/src/main/java/org/onap/ccsdk/config/assignment/service/ConfigAssignmentUtils.java delete mode 100644 blueprints-processor/plugin/assignment-provider/src/main/java/org/onap/ccsdk/config/assignment/service/ConfigPreviewService.java delete mode 100644 blueprints-processor/plugin/assignment-provider/src/main/java/org/onap/ccsdk/config/assignment/service/ResourceDictionaryService.java delete mode 100644 blueprints-processor/plugin/assignment-provider/src/main/java/org/onap/ccsdk/config/assignment/service/ResourceModelService.java create mode 100644 blueprints-processor/plugin/assignment-provider/src/main/java/org/onap/ccsdk/features/assignment/ConfigAssignmentConstants.java create mode 100644 blueprints-processor/plugin/assignment-provider/src/main/java/org/onap/ccsdk/features/assignment/data/ResourceAssignmentData.java create mode 100644 blueprints-processor/plugin/assignment-provider/src/main/java/org/onap/ccsdk/features/assignment/processor/DBResourceProcessor.java create mode 100644 blueprints-processor/plugin/assignment-provider/src/main/java/org/onap/ccsdk/features/assignment/processor/DefaultResourceProcessor.java create mode 100644 blueprints-processor/plugin/assignment-provider/src/main/java/org/onap/ccsdk/features/assignment/processor/InputResourceProcessor.java create mode 100644 blueprints-processor/plugin/assignment-provider/src/main/java/org/onap/ccsdk/features/assignment/processor/MdsalResourceProcessor.java create mode 100644 blueprints-processor/plugin/assignment-provider/src/main/java/org/onap/ccsdk/features/assignment/processor/ProcessorFactory.java create mode 100644 blueprints-processor/plugin/assignment-provider/src/main/java/org/onap/ccsdk/features/assignment/processor/ResourceAssignmentProcessor.java create mode 100644 blueprints-processor/plugin/assignment-provider/src/main/java/org/onap/ccsdk/features/assignment/service/ConfigAssignmentNode.java create mode 100644 blueprints-processor/plugin/assignment-provider/src/main/java/org/onap/ccsdk/features/assignment/service/ConfigAssignmentPersistService.java create mode 100644 blueprints-processor/plugin/assignment-provider/src/main/java/org/onap/ccsdk/features/assignment/service/ConfigAssignmentProcessService.java create mode 100644 blueprints-processor/plugin/assignment-provider/src/main/java/org/onap/ccsdk/features/assignment/service/ConfigAssignmentService.java create mode 100644 blueprints-processor/plugin/assignment-provider/src/main/java/org/onap/ccsdk/features/assignment/service/ConfigAssignmentServiceImpl.java create mode 100644 blueprints-processor/plugin/assignment-provider/src/main/java/org/onap/ccsdk/features/assignment/service/ConfigAssignmentUtils.java create mode 100644 blueprints-processor/plugin/assignment-provider/src/main/java/org/onap/ccsdk/features/assignment/service/ConfigPreviewService.java create mode 100644 blueprints-processor/plugin/assignment-provider/src/main/java/org/onap/ccsdk/features/assignment/service/ResourceDictionaryService.java create mode 100644 blueprints-processor/plugin/assignment-provider/src/main/java/org/onap/ccsdk/features/assignment/service/ResourceModelService.java delete mode 100644 blueprints-processor/plugin/assignment-provider/src/test/java/org/onap/ccsdk/config/assignment/processor/DBResourceProcessorTest.java delete mode 100644 blueprints-processor/plugin/assignment-provider/src/test/java/org/onap/ccsdk/config/assignment/processor/DefaultResourceProcessorTest.java delete mode 100644 blueprints-processor/plugin/assignment-provider/src/test/java/org/onap/ccsdk/config/assignment/processor/InputResourceProcessorTest.java delete mode 100644 blueprints-processor/plugin/assignment-provider/src/test/java/org/onap/ccsdk/config/assignment/processor/MdsalResourceProcessorTest.java delete mode 100644 blueprints-processor/plugin/assignment-provider/src/test/java/org/onap/ccsdk/config/assignment/service/ConfigAssignmentNodeTest.java delete mode 100644 blueprints-processor/plugin/assignment-provider/src/test/java/org/onap/ccsdk/config/assignment/service/ConfigPreviewServiceTest.java delete mode 100644 blueprints-processor/plugin/assignment-provider/src/test/java/org/onap/ccsdk/config/assignment/service/ConfigResourceAssignmentTestUtils.java delete mode 100644 blueprints-processor/plugin/assignment-provider/src/test/java/org/onap/ccsdk/config/assignment/service/ResourceAssignmentGenerationTest.java delete mode 100644 blueprints-processor/plugin/assignment-provider/src/test/java/org/onap/ccsdk/config/assignment/service/ResourceAssignmentValidation.java delete mode 100644 blueprints-processor/plugin/assignment-provider/src/test/java/org/onap/ccsdk/config/assignment/service/TopologicalSortingTest.java create mode 100644 blueprints-processor/plugin/assignment-provider/src/test/java/org/onap/ccsdk/features/assignment/processor/DBResourceProcessorTest.java create mode 100644 blueprints-processor/plugin/assignment-provider/src/test/java/org/onap/ccsdk/features/assignment/processor/DefaultResourceProcessorTest.java create mode 100644 blueprints-processor/plugin/assignment-provider/src/test/java/org/onap/ccsdk/features/assignment/processor/InputResourceProcessorTest.java create mode 100644 blueprints-processor/plugin/assignment-provider/src/test/java/org/onap/ccsdk/features/assignment/processor/MdsalResourceProcessorTest.java create mode 100644 blueprints-processor/plugin/assignment-provider/src/test/java/org/onap/ccsdk/features/assignment/service/ConfigAssignmentNodeTest.java create mode 100644 blueprints-processor/plugin/assignment-provider/src/test/java/org/onap/ccsdk/features/assignment/service/ConfigPreviewServiceTest.java create mode 100644 blueprints-processor/plugin/assignment-provider/src/test/java/org/onap/ccsdk/features/assignment/service/ConfigResourceAssignmentTestUtils.java create mode 100644 blueprints-processor/plugin/assignment-provider/src/test/java/org/onap/ccsdk/features/assignment/service/ResourceAssignmentGenerationTest.java create mode 100644 blueprints-processor/plugin/assignment-provider/src/test/java/org/onap/ccsdk/features/assignment/service/ResourceAssignmentValidation.java create mode 100644 blueprints-processor/plugin/assignment-provider/src/test/java/org/onap/ccsdk/features/assignment/service/TopologicalSortingTest.java delete mode 100644 blueprints-processor/plugin/generator-provider/src/main/java/org/onap/ccsdk/config/generator/ConfigGeneratorConstant.java delete mode 100644 blueprints-processor/plugin/generator-provider/src/main/java/org/onap/ccsdk/config/generator/data/ConfigGeneratorInfo.java delete mode 100644 blueprints-processor/plugin/generator-provider/src/main/java/org/onap/ccsdk/config/generator/service/ConfigGeneratorNode.java delete mode 100644 blueprints-processor/plugin/generator-provider/src/main/java/org/onap/ccsdk/config/generator/service/ConfigGeneratorService.java delete mode 100644 blueprints-processor/plugin/generator-provider/src/main/java/org/onap/ccsdk/config/generator/service/ConfigGeneratorServiceImpl.java delete mode 100644 blueprints-processor/plugin/generator-provider/src/main/java/org/onap/ccsdk/config/generator/tool/CustomJsonNodeFactory.java delete mode 100644 blueprints-processor/plugin/generator-provider/src/main/java/org/onap/ccsdk/config/generator/tool/CustomTextNode.java delete mode 100644 blueprints-processor/plugin/generator-provider/src/main/java/org/onap/ccsdk/config/generator/tool/EscapeUtils.java create mode 100644 blueprints-processor/plugin/generator-provider/src/main/java/org/onap/ccsdk/features/generator/ConfigGeneratorConstant.java create mode 100644 blueprints-processor/plugin/generator-provider/src/main/java/org/onap/ccsdk/features/generator/data/ConfigGeneratorInfo.java create mode 100644 blueprints-processor/plugin/generator-provider/src/main/java/org/onap/ccsdk/features/generator/service/ConfigGeneratorNode.java create mode 100644 blueprints-processor/plugin/generator-provider/src/main/java/org/onap/ccsdk/features/generator/service/ConfigGeneratorService.java create mode 100644 blueprints-processor/plugin/generator-provider/src/main/java/org/onap/ccsdk/features/generator/service/ConfigGeneratorServiceImpl.java create mode 100644 blueprints-processor/plugin/generator-provider/src/main/java/org/onap/ccsdk/features/generator/tool/CustomJsonNodeFactory.java create mode 100644 blueprints-processor/plugin/generator-provider/src/main/java/org/onap/ccsdk/features/generator/tool/CustomTextNode.java create mode 100644 blueprints-processor/plugin/generator-provider/src/main/java/org/onap/ccsdk/features/generator/tool/EscapeUtils.java delete mode 100644 blueprints-processor/plugin/generator-provider/src/test/java/org/onap/ccsdk/config/generator/service/ConfigGeneratorNodeTest.java delete mode 100644 blueprints-processor/plugin/generator-provider/src/test/java/org/onap/ccsdk/config/generator/tool/EscapeUtilsTest.java create mode 100644 blueprints-processor/plugin/generator-provider/src/test/java/org/onap/ccsdk/features/generator/service/ConfigGeneratorNodeTest.java create mode 100644 blueprints-processor/plugin/generator-provider/src/test/java/org/onap/ccsdk/features/generator/tool/EscapeUtilsTest.java delete mode 100644 blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/ConfigModelConstant.java delete mode 100644 blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/ConfigModelException.java delete mode 100644 blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/ValidTypes.java delete mode 100644 blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/data/ArtifactDefinition.java delete mode 100644 blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/data/ArtifactType.java delete mode 100644 blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/data/CapabilityAssignment.java delete mode 100644 blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/data/CapabilityDefinition.java delete mode 100644 blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/data/ConstraintClause.java delete mode 100644 blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/data/DataType.java delete mode 100644 blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/data/EntrySchema.java delete mode 100644 blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/data/Implementation.java delete mode 100644 blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/data/InterfaceAssignment.java delete mode 100644 blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/data/InterfaceDefinition.java delete mode 100644 blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/data/NodeTemplate.java delete mode 100644 blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/data/NodeType.java delete mode 100644 blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/data/OperationAssignment.java delete mode 100644 blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/data/OperationDefinition.java delete mode 100644 blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/data/PropertyDefinition.java delete mode 100644 blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/data/RelationshipTemplate.java delete mode 100644 blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/data/RequirementAssignment.java delete mode 100644 blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/data/RequirementDefinition.java delete mode 100644 blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/data/ResourceAssignment.java delete mode 100644 blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/data/ServiceTemplate.java delete mode 100644 blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/data/TopologyTemplate.java delete mode 100644 blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/data/Workflow.java delete mode 100644 blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/data/api/ActionIdentifiers.java delete mode 100644 blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/data/api/CommonHeader.java delete mode 100644 blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/data/api/Flags.java delete mode 100644 blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/data/api/Status.java delete mode 100644 blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/data/api/TransactionRequest.java delete mode 100644 blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/data/api/TransactionResponse.java delete mode 100644 blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/data/dict/ResourceDefinition.java delete mode 100644 blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/data/dict/SourcesDefinition.java delete mode 100644 blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/data/dict/SourcesProperties.java delete mode 100644 blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/domain/ConfigModel.java delete mode 100644 blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/domain/ConfigModelContent.java delete mode 100644 blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/domain/ResourceDictionary.java delete mode 100644 blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/service/ComponentNode.java delete mode 100644 blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/service/ComponentNodeDelegate.java delete mode 100644 blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/service/ComponentNodeService.java delete mode 100644 blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/service/ComponentNodeServiceImpl.java delete mode 100644 blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/service/ConfigBlueprintService.java delete mode 100644 blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/service/ConfigModelNode.java delete mode 100644 blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/service/ConfigModelService.java delete mode 100644 blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/service/ConfigModelServiceImpl.java delete mode 100644 blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/utils/ExpressionUtils.java delete mode 100644 blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/utils/JsonParserUtils.java delete mode 100644 blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/utils/JsonUtils.java delete mode 100644 blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/utils/NodePropertyUtils.java delete mode 100644 blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/utils/PrepareContextUtils.java delete mode 100644 blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/utils/ResourceAssignmentUtils.java delete mode 100644 blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/utils/ResourceDictionaryUtils.java delete mode 100644 blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/utils/ServiceTemplateUtils.java delete mode 100644 blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/utils/TopologicalSortingUtils.java delete mode 100644 blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/utils/TransformationUtils.java delete mode 100644 blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/validator/DataTypeValidator.java delete mode 100644 blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/validator/NodeTypeValidator.java delete mode 100644 blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/validator/PropertyDefinitionValidator.java delete mode 100644 blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/validator/ResourceAssignmentValidator.java delete mode 100644 blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/validator/ServiceTemplateValidator.java delete mode 100644 blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/validator/TopologyTemplateValidator.java create mode 100644 blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/ConfigModelConstant.java create mode 100644 blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/ConfigModelException.java create mode 100644 blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/ValidTypes.java create mode 100644 blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/data/ArtifactDefinition.java create mode 100644 blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/data/ArtifactType.java create mode 100644 blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/data/CapabilityAssignment.java create mode 100644 blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/data/CapabilityDefinition.java create mode 100644 blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/data/ConstraintClause.java create mode 100644 blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/data/DataType.java create mode 100644 blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/data/EntrySchema.java create mode 100644 blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/data/Implementation.java create mode 100644 blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/data/InterfaceAssignment.java create mode 100644 blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/data/InterfaceDefinition.java create mode 100644 blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/data/NodeTemplate.java create mode 100644 blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/data/NodeType.java create mode 100644 blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/data/OperationAssignment.java create mode 100644 blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/data/OperationDefinition.java create mode 100644 blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/data/PropertyDefinition.java create mode 100644 blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/data/RelationshipTemplate.java create mode 100644 blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/data/RequirementAssignment.java create mode 100644 blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/data/RequirementDefinition.java create mode 100644 blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/data/ResourceAssignment.java create mode 100644 blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/data/ServiceTemplate.java create mode 100644 blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/data/TopologyTemplate.java create mode 100644 blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/data/Workflow.java create mode 100644 blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/data/api/ActionIdentifiers.java create mode 100644 blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/data/api/CommonHeader.java create mode 100644 blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/data/api/Flags.java create mode 100644 blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/data/api/Status.java create mode 100644 blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/data/api/TransactionRequest.java create mode 100644 blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/data/api/TransactionResponse.java create mode 100644 blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/data/dict/ResourceDefinition.java create mode 100644 blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/data/dict/SourcesDefinition.java create mode 100644 blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/data/dict/SourcesProperties.java create mode 100644 blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/domain/ConfigModel.java create mode 100644 blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/domain/ConfigModelContent.java create mode 100644 blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/domain/ResourceDictionary.java create mode 100644 blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/service/ComponentNode.java create mode 100644 blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/service/ComponentNodeDelegate.java create mode 100644 blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/service/ComponentNodeService.java create mode 100644 blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/service/ComponentNodeServiceImpl.java create mode 100644 blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/service/ConfigBlueprintService.java create mode 100644 blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/service/ConfigModelNode.java create mode 100644 blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/service/ConfigModelService.java create mode 100644 blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/service/ConfigModelServiceImpl.java create mode 100644 blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/utils/ExpressionUtils.java create mode 100644 blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/utils/JsonParserUtils.java create mode 100644 blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/utils/JsonUtils.java create mode 100644 blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/utils/NodePropertyUtils.java create mode 100644 blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/utils/PrepareContextUtils.java create mode 100644 blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/utils/ResourceAssignmentUtils.java create mode 100644 blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/utils/ResourceDictionaryUtils.java create mode 100644 blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/utils/ServiceTemplateUtils.java create mode 100644 blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/utils/TopologicalSortingUtils.java create mode 100644 blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/utils/TransformationUtils.java create mode 100644 blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/validator/DataTypeValidator.java create mode 100644 blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/validator/NodeTypeValidator.java create mode 100644 blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/validator/PropertyDefinitionValidator.java create mode 100644 blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/validator/ResourceAssignmentValidator.java create mode 100644 blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/validator/ServiceTemplateValidator.java create mode 100644 blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/validator/TopologyTemplateValidator.java delete mode 100644 blueprints-processor/plugin/model-provider/src/test/java/org/onap/ccsdk/config/model/ResourceDictionaryUtilsTest.java delete mode 100644 blueprints-processor/plugin/model-provider/src/test/java/org/onap/ccsdk/config/model/utils/JsonParserUtilsTest.java delete mode 100644 blueprints-processor/plugin/model-provider/src/test/java/org/onap/ccsdk/config/model/utils/JsonUtilsTest.java delete mode 100644 blueprints-processor/plugin/model-provider/src/test/java/org/onap/ccsdk/config/model/utils/ResourceAssignmentUtilsTest.java delete mode 100644 blueprints-processor/plugin/model-provider/src/test/java/org/onap/ccsdk/config/model/utils/ServiceTemplateUtilsTest.java delete mode 100644 blueprints-processor/plugin/model-provider/src/test/java/org/onap/ccsdk/config/model/utils/TransformationUtilsTest.java delete mode 100644 blueprints-processor/plugin/model-provider/src/test/java/org/onap/ccsdk/config/model/validator/ServiceTemplateValidationTest.java delete mode 100644 blueprints-processor/plugin/model-provider/src/test/java/org/onap/ccsdk/config/params/service/ComponentNodeTest.java delete mode 100644 blueprints-processor/plugin/model-provider/src/test/java/org/onap/ccsdk/config/params/service/ConfigModelServiceTest.java delete mode 100644 blueprints-processor/plugin/model-provider/src/test/java/org/onap/ccsdk/config/params/service/ExpressionUtilsTest.java delete mode 100644 blueprints-processor/plugin/model-provider/src/test/java/org/onap/ccsdk/config/params/service/MockComponentNode.java delete mode 100644 blueprints-processor/plugin/model-provider/src/test/java/org/onap/ccsdk/config/params/service/ServiceTemplateCreateUtils.java create mode 100644 blueprints-processor/plugin/model-provider/src/test/java/org/onap/ccsdk/features/model/ResourceDictionaryUtilsTest.java create mode 100644 blueprints-processor/plugin/model-provider/src/test/java/org/onap/ccsdk/features/model/utils/JsonParserUtilsTest.java create mode 100644 blueprints-processor/plugin/model-provider/src/test/java/org/onap/ccsdk/features/model/utils/JsonUtilsTest.java create mode 100644 blueprints-processor/plugin/model-provider/src/test/java/org/onap/ccsdk/features/model/utils/ResourceAssignmentUtilsTest.java create mode 100644 blueprints-processor/plugin/model-provider/src/test/java/org/onap/ccsdk/features/model/utils/ServiceTemplateUtilsTest.java create mode 100644 blueprints-processor/plugin/model-provider/src/test/java/org/onap/ccsdk/features/model/utils/TransformationUtilsTest.java create mode 100644 blueprints-processor/plugin/model-provider/src/test/java/org/onap/ccsdk/features/model/validator/ServiceTemplateValidationTest.java create mode 100644 blueprints-processor/plugin/model-provider/src/test/java/org/onap/ccsdk/features/params/service/ComponentNodeTest.java create mode 100644 blueprints-processor/plugin/model-provider/src/test/java/org/onap/ccsdk/features/params/service/ConfigModelServiceTest.java create mode 100644 blueprints-processor/plugin/model-provider/src/test/java/org/onap/ccsdk/features/params/service/ExpressionUtilsTest.java create mode 100644 blueprints-processor/plugin/model-provider/src/test/java/org/onap/ccsdk/features/params/service/MockComponentNode.java create mode 100644 blueprints-processor/plugin/model-provider/src/test/java/org/onap/ccsdk/features/params/service/ServiceTemplateCreateUtils.java (limited to 'blueprints-processor/plugin') diff --git a/blueprints-processor/plugin/assignment-provider/pom.xml b/blueprints-processor/plugin/assignment-provider/pom.xml index 4f6b2936e..5ca679baf 100644 --- a/blueprints-processor/plugin/assignment-provider/pom.xml +++ b/blueprints-processor/plugin/assignment-provider/pom.xml @@ -105,11 +105,11 @@ ${project.artifactId} ${project.groupId}.${project.artifactId} - org.onap.ccsdk.config.assignment, - org.onap.ccsdk.config.assignment.data, - org.onap.ccsdk.config.assignment.service, - org.onap.ccsdk.config.assignment.processor, - org.onap.ccsdk.config.assignment.processor.custom + org.onap.ccsdk.features.assignment, + org.onap.ccsdk.features.assignment.data, + org.onap.ccsdk.features.assignment.service, + org.onap.ccsdk.features.assignment.processor, + org.onap.ccsdk.features.assignment.processor.custom diff --git a/blueprints-processor/plugin/assignment-provider/src/main/java/org/onap/ccsdk/config/assignment/ConfigAssignmentConstants.java b/blueprints-processor/plugin/assignment-provider/src/main/java/org/onap/ccsdk/config/assignment/ConfigAssignmentConstants.java deleted file mode 100644 index 10e217b8c..000000000 --- a/blueprints-processor/plugin/assignment-provider/src/main/java/org/onap/ccsdk/config/assignment/ConfigAssignmentConstants.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2018 IBM. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.ccsdk.config.assignment; - -@SuppressWarnings("squid:S1118") -public class ConfigAssignmentConstants { - - public static final String OUTPUT_PARAM_STATUS = "status"; - public static final String OUTPUT_PARAM_RESOURCE_ASSIGNMENT_PARAMS = "resource-assignment-params"; - public static final String OUTPUT_PARAM_MASHED_DATA = "mashed-data"; - public static final String OUTPUT_PARAM_ERROR_MESSAGE = "error-message"; - public static final String OUTPUT_STATUS_SUCCESS = "success"; - public static final String OUTPUT_STATUS_FAILURE = "failure"; - - public static final String INPUT_PARAM_REQUEST_ID = "request-id"; - public static final String INPUT_PARAM_RESOURCE_ID = "resource-id"; - public static final String INPUT_PARAM_RESOURCE_TYPE = "resource-type"; - public static final String INPUT_PARAM_ACTION_NAME = "action-name"; - public static final String INPUT_PARAM_TEMPLATE_NAMES = "template-names"; - public static final String INPUT_PARAM_INPUT_DATA = "input-data"; - -} diff --git a/blueprints-processor/plugin/assignment-provider/src/main/java/org/onap/ccsdk/config/assignment/data/ResourceAssignmentData.java b/blueprints-processor/plugin/assignment-provider/src/main/java/org/onap/ccsdk/config/assignment/data/ResourceAssignmentData.java deleted file mode 100644 index 816c943f3..000000000 --- a/blueprints-processor/plugin/assignment-provider/src/main/java/org/onap/ccsdk/config/assignment/data/ResourceAssignmentData.java +++ /dev/null @@ -1,163 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2018 IBM. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.ccsdk.config.assignment.data; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import org.onap.ccsdk.config.model.data.ResourceAssignment; -import org.onap.ccsdk.sli.core.sli.SvcLogicContext; - -public class ResourceAssignmentData { - - private String requestId; - private boolean reloadModel; - private String resourceType; - private String resourceId; - private String serviceTemplateName; - private String serviceTemplateVersion; - private String actionName; - private String inputData; - private SvcLogicContext svcLogicContext; - private List templateNames; - private Map> templatesResourceAssignments = new HashMap<>(); - private Map templatesContents = new HashMap<>(); - private Map templatesMashedContents = new HashMap<>(); - private Map templatesData = new HashMap<>(); - private Map context = new HashMap<>(); - - public String getRequestId() { - return requestId; - } - - public void setRequestId(String requestId) { - this.requestId = requestId; - } - - public String getResourceType() { - return resourceType; - } - - public void setResourceType(String resourceType) { - this.resourceType = resourceType; - } - - public String getResourceId() { - return resourceId; - } - - public void setResourceId(String resourceId) { - this.resourceId = resourceId; - } - - public String getServiceTemplateName() { - return serviceTemplateName; - } - - public void setServiceTemplateName(String serviceTemplateName) { - this.serviceTemplateName = serviceTemplateName; - } - - public String getServiceTemplateVersion() { - return serviceTemplateVersion; - } - - public void setServiceTemplateVersion(String serviceTemplateVersion) { - this.serviceTemplateVersion = serviceTemplateVersion; - } - - public String getActionName() { - return actionName; - } - - public void setActionName(String actionName) { - this.actionName = actionName; - } - - public String getInputData() { - return inputData; - } - - public void setInputData(String inputData) { - this.inputData = inputData; - } - - public List getTemplateNames() { - return templateNames; - } - - public void setTemplateNames(List templateNames) { - this.templateNames = templateNames; - } - - public Map> getTemplatesResourceAssignments() { - return templatesResourceAssignments; - } - - public void setTemplatesResourceAssignments(Map> templatesResourceAssignments) { - this.templatesResourceAssignments = templatesResourceAssignments; - } - - public Map getTemplatesContents() { - return templatesContents; - } - - public void setTemplatesContents(Map templatesContents) { - this.templatesContents = templatesContents; - } - - public Map getTemplatesMashedContents() { - return templatesMashedContents; - } - - public void setTemplatesMashedContents(Map templatesMashedContents) { - this.templatesMashedContents = templatesMashedContents; - } - - public Map getTemplatesData() { - return templatesData; - } - - public void setTemplatesData(Map templatesData) { - this.templatesData = templatesData; - } - - public Map getContext() { - return context; - } - - public void setContext(Map context) { - this.context = context; - } - - public SvcLogicContext getSvcLogicContext() { - return svcLogicContext; - } - - public void setSvcLogicContext(SvcLogicContext svcLogicContext) { - this.svcLogicContext = svcLogicContext; - } - - public boolean isReloadModel() { - return reloadModel; - } - - public void setReloadModel(boolean reloadModel) { - this.reloadModel = reloadModel; - } -} diff --git a/blueprints-processor/plugin/assignment-provider/src/main/java/org/onap/ccsdk/config/assignment/processor/DBResourceProcessor.java b/blueprints-processor/plugin/assignment-provider/src/main/java/org/onap/ccsdk/config/assignment/processor/DBResourceProcessor.java deleted file mode 100644 index 5f3e6094c..000000000 --- a/blueprints-processor/plugin/assignment-provider/src/main/java/org/onap/ccsdk/config/assignment/processor/DBResourceProcessor.java +++ /dev/null @@ -1,267 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2018 IBM. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.ccsdk.config.assignment.processor; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import org.apache.commons.collections.CollectionUtils; -import org.apache.commons.collections.MapUtils; -import org.apache.commons.lang3.StringUtils; -import org.onap.ccsdk.config.assignment.service.ConfigAssignmentUtils; -import org.onap.ccsdk.config.data.adaptor.service.ConfigResourceService; -import org.onap.ccsdk.config.model.ConfigModelConstant; -import org.onap.ccsdk.config.model.ConfigModelException; -import org.onap.ccsdk.config.model.ValidTypes; -import org.onap.ccsdk.config.model.data.ResourceAssignment; -import org.onap.ccsdk.config.model.data.dict.ResourceDefinition; -import org.onap.ccsdk.config.model.data.dict.SourcesDefinition; -import org.onap.ccsdk.config.model.service.ComponentNode; -import org.onap.ccsdk.config.model.utils.JsonUtils; -import org.onap.ccsdk.config.model.utils.ResourceAssignmentUtils; -import org.onap.ccsdk.sli.core.sli.SvcLogicContext; -import org.onap.ccsdk.sli.core.sli.SvcLogicException; -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; -import com.fasterxml.jackson.databind.node.ArrayNode; -import com.fasterxml.jackson.databind.node.JsonNodeFactory; -import com.fasterxml.jackson.databind.node.ObjectNode; - -public class DBResourceProcessor implements ComponentNode { - - private static EELFLogger logger = EELFManager.getInstance().getLogger(DBResourceProcessor.class); - private ConfigResourceService configResourceService; - private Map dictionaries; - - public DBResourceProcessor(ConfigResourceService configResourceService) { - this.configResourceService = configResourceService; - } - - @Override - public Boolean preCondition(Map inParams, SvcLogicContext ctx, Map componentContext) - throws SvcLogicException { - return Boolean.TRUE; - } - - @Override - public void preProcess(Map inParams, SvcLogicContext ctx, Map componentContext) - throws SvcLogicException { - // Auto-generated method stub - } - - @Override - public void process(Map inParams, SvcLogicContext ctx) throws SvcLogicException { - // Auto-generated method stub - } - - @SuppressWarnings("unchecked") - @Override - public void process(Map inParams, SvcLogicContext ctx, Map componentContext) - throws SvcLogicException { - try { - List batchResourceAssignment = - (List) componentContext.get(ConfigModelConstant.PROPERTY_RESOURCE_ASSIGNMENTS); - dictionaries = - (Map) componentContext.get(ConfigModelConstant.PROPERTY_DICTIONARIES); - - if (CollectionUtils.isNotEmpty(batchResourceAssignment)) { - for (ResourceAssignment resourceAssignment : batchResourceAssignment) { - processResourceAssignment(ctx, componentContext, resourceAssignment); - } - } - } catch (Exception e) { - throw new SvcLogicException(String.format("DBResourceProcessor Exception : (%s)", e), e); - } - } - - private void processResourceAssignment(SvcLogicContext ctx, Map componentContext, - ResourceAssignment resourceAssignment) throws SvcLogicException, ConfigModelException { - if (resourceAssignment != null) { - try { - validate(resourceAssignment); - - // Check if It has Input - Object value = ConfigAssignmentUtils.getContextKeyValue(ctx, resourceAssignment.getName()); - if (value != null) { - logger.info("db source template key ({}) found from input and value is ({})", - resourceAssignment.getName(), value); - ResourceAssignmentUtils.setResourceDataValue(componentContext, resourceAssignment, value); - return; - } - - ResourceDefinition resourceDefinition = dictionaries.get(resourceAssignment.getDictionaryName()); - SourcesDefinition sourceDb = resourceDefinition.getSources().get("db"); - if (StringUtils.isBlank(sourceDb.getProperties().getQuery())) { - throw new SvcLogicException("db query property is missing"); - } - - String sql = sourceDb.getProperties().getQuery(); - Map inputKeyMapping = sourceDb.getProperties().getInputKeyMapping(); - - logger.info("Db dictionary information : ({}), ({}), ({})", sql, inputKeyMapping, - sourceDb.getProperties().getOutputKeyMapping()); - - Map namedParameters = populateNamedParameter(componentContext, inputKeyMapping); - - logger.info("Parameter information : ({})", namedParameters); - List> rows = configResourceService.query(sql, namedParameters); - if (rows != null && !rows.isEmpty()) { - processDBResults(ctx, componentContext, resourceAssignment, sourceDb, rows); - } else { - logger.warn("Failed to get db result for dictionary name ({}) the query ({})", - resourceAssignment.getDictionaryName(), sql); - } - - // Check the value has populated for mandatory case - ResourceAssignmentUtils.assertTemplateKeyValueNotNull(componentContext, resourceAssignment); - } catch (Exception e) { - ResourceAssignmentUtils.setFailedResourceDataValue(componentContext, resourceAssignment, - e.getMessage()); - throw new SvcLogicException( - String.format("Failed in template key (%s) assignments : (%s)", resourceAssignment, e), e); - } - } else { - // Do Nothing - } - } - - private void validate(ResourceAssignment resourceAssignment) throws SvcLogicException { - if (resourceAssignment == null) { - throw new SvcLogicException("resource assignment is not defined"); - } - - if (StringUtils.isBlank(resourceAssignment.getName())) { - throw new SvcLogicException("resource assignment template key is not defined"); - } - - if (StringUtils.isBlank(resourceAssignment.getDictionaryName())) { - throw new SvcLogicException( - String.format("resource assignment dictionary name is not defined for template key (%s)", - resourceAssignment.getName())); - } - - if (!ConfigModelConstant.SOURCE_DB.equalsIgnoreCase(resourceAssignment.getDictionarySource())) { - throw new SvcLogicException(String.format("resource assignment source is not db, it is (%s)", - resourceAssignment.getDictionarySource())); - } - - ResourceDefinition resourceDefinition = dictionaries.get(resourceAssignment.getDictionaryName()); - if (resourceDefinition == null) { - throw new SvcLogicException(String.format("missing resource dictionary definition for name (%s) ", - resourceAssignment.getDictionaryName())); - } - - if (resourceDefinition.getSources() == null || resourceDefinition.getSources().get("db") == null) { - throw new SvcLogicException(String.format("missing resource dictionary db source definition for name (%s) ", - resourceAssignment.getDictionaryName())); - } - - SourcesDefinition sourceDb = resourceDefinition.getSources().get("db"); - if (StringUtils.isBlank(sourceDb.getProperties().getQuery())) { - throw new SvcLogicException(String.format("Failed to get request Query for dictionary (%s)", - resourceAssignment.getDictionaryName())); - } - - } - - private Map populateNamedParameter(Map componentContext, - Map inputKeyMapping) { - Map namedParameters = new HashMap<>(); - if (MapUtils.isNotEmpty(inputKeyMapping)) { - - for (Map.Entry mapping : inputKeyMapping.entrySet()) { - ResourceDefinition referenceDictionaryDefinition = dictionaries.get(mapping.getValue()); - Object expressionValue = - ResourceAssignmentUtils.getDictionaryKeyValue(componentContext, referenceDictionaryDefinition); - logger.trace("Reference dictionary key ({}), value ({})", mapping.getKey(), expressionValue); - namedParameters.put(mapping.getKey(), expressionValue); - } - } - return namedParameters; - } - - @SuppressWarnings("squid:S3776") - private void processDBResults(SvcLogicContext ctx, Map componentContext, - ResourceAssignment resourceAssignment, SourcesDefinition sourceDb, List> rows) - throws SvcLogicException, ConfigModelException { - - Map outputKeyMapping = sourceDb.getProperties().getOutputKeyMapping(); - String type = resourceAssignment.getProperty().getType(); - String entrySchema = null; - logger.info("Response processing type({})", type); - // Primitive Types - if (ValidTypes.getPrimitivePropertType().contains(type)) { - - Map row = rows.get(0); - String dbColumnName = outputKeyMapping.get(resourceAssignment.getDictionaryName()); - Object dbColumnValue = row.get(dbColumnName); - ResourceAssignmentUtils.setResourceDataValue(componentContext, resourceAssignment, dbColumnValue); - - } else if (ValidTypes.getListPropertType().contains(type)) { - // Array Types - if (resourceAssignment.getProperty().getEntrySchema() != null) { - entrySchema = resourceAssignment.getProperty().getEntrySchema().getType(); - } - - if (StringUtils.isNotBlank(entrySchema)) { - ArrayNode arrayNode = JsonNodeFactory.instance.arrayNode(); - - for (Map row : rows) { - if (ValidTypes.getPrimitivePropertType().contains(entrySchema)) { - String dbColumnName = outputKeyMapping.get(resourceAssignment.getDictionaryName()); - Object dbColumnValue = row.get(dbColumnName); - // Add Array JSON - JsonUtils.populatePrimitiveValues(dbColumnValue, entrySchema, arrayNode); - } else { - ObjectNode arrayChildNode = JsonNodeFactory.instance.objectNode(); - for (Map.Entry mapping : outputKeyMapping.entrySet()) { - Object dbColumnValue = row.get(mapping.getKey()); - String propertyTypeForDataType = - ConfigAssignmentUtils.getPropertyType(ctx, entrySchema, mapping.getKey()); - JsonUtils.populatePrimitiveValues(mapping.getKey(), dbColumnValue, propertyTypeForDataType, - arrayChildNode); - } - arrayNode.add(arrayChildNode); - } - } - // Set the List of Complex Values - ResourceAssignmentUtils.setResourceDataValue(componentContext, resourceAssignment, arrayNode); - } else { - throw new SvcLogicException(String.format("Entry schema is not defined for dictionary (%s) info", - resourceAssignment.getDictionaryName())); - } - } else { - // Complex Types - Map row = rows.get(0); - ObjectNode objectNode = JsonNodeFactory.instance.objectNode(); - for (Map.Entry mapping : outputKeyMapping.entrySet()) { - Object dbColumnValue = row.get(mapping.getKey()); - String propertyTypeForDataType = ConfigAssignmentUtils.getPropertyType(ctx, type, mapping.getKey()); - JsonUtils.populatePrimitiveValues(mapping.getKey(), dbColumnValue, propertyTypeForDataType, objectNode); - } - ResourceAssignmentUtils.setResourceDataValue(componentContext, resourceAssignment, objectNode); - } - } - - @Override - public void postProcess(Map inParams, SvcLogicContext ctx, Map componentContext) - throws SvcLogicException { - // Auto-generated method stub - } - -} diff --git a/blueprints-processor/plugin/assignment-provider/src/main/java/org/onap/ccsdk/config/assignment/processor/DefaultResourceProcessor.java b/blueprints-processor/plugin/assignment-provider/src/main/java/org/onap/ccsdk/config/assignment/processor/DefaultResourceProcessor.java deleted file mode 100644 index aac13cb9d..000000000 --- a/blueprints-processor/plugin/assignment-provider/src/main/java/org/onap/ccsdk/config/assignment/processor/DefaultResourceProcessor.java +++ /dev/null @@ -1,107 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2018 IBM. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.ccsdk.config.assignment.processor; - -import java.util.List; -import java.util.Map; -import org.apache.commons.lang3.StringUtils; -import org.onap.ccsdk.config.assignment.service.ConfigAssignmentUtils; -import org.onap.ccsdk.config.data.adaptor.service.ConfigResourceService; -import org.onap.ccsdk.config.model.ConfigModelConstant; -import org.onap.ccsdk.config.model.ConfigModelException; -import org.onap.ccsdk.config.model.data.ResourceAssignment; -import org.onap.ccsdk.config.model.service.ComponentNode; -import org.onap.ccsdk.config.model.utils.ResourceAssignmentUtils; -import org.onap.ccsdk.sli.core.sli.SvcLogicContext; -import org.onap.ccsdk.sli.core.sli.SvcLogicException; - -public class DefaultResourceProcessor implements ComponentNode { - - public DefaultResourceProcessor(ConfigResourceService configResourceService) {} - - @Override - public Boolean preCondition(Map inParams, SvcLogicContext ctx, Map componentContext) - throws SvcLogicException { - return Boolean.TRUE; - } - - @Override - public void preProcess(Map inParams, SvcLogicContext ctx, Map componentContext) - throws SvcLogicException { - // Auto-generated method stub - } - - @Override - public void process(Map inParams, SvcLogicContext ctx) throws SvcLogicException { - // Auto-generated method stub - } - - @SuppressWarnings("unchecked") - @Override - public void process(Map inParams, SvcLogicContext ctx, Map componentContext) - throws SvcLogicException { - try { - List batchResourceAssignment = - (List) componentContext.get(ConfigModelConstant.PROPERTY_RESOURCE_ASSIGNMENTS); - - if (batchResourceAssignment != null && !batchResourceAssignment.isEmpty()) { - for (ResourceAssignment resourceAssignment : batchResourceAssignment) { - processResourceAssignment(ctx, componentContext, resourceAssignment); - } - } - } catch (Exception e) { - throw new SvcLogicException(String.format("DefaultResourceProcessor Exception : (%s)", e), e); - } - - } - - private void processResourceAssignment(SvcLogicContext ctx, Map componentContext, - ResourceAssignment resourceAssignment) throws ConfigModelException, SvcLogicException { - if (resourceAssignment != null && StringUtils.isNotBlank(resourceAssignment.getName()) - && resourceAssignment.getProperty() != null) { - try { - // Check if It has Input - Object value = ConfigAssignmentUtils.getContextKeyValue(ctx, resourceAssignment.getName()); - if (value == null) { - value = resourceAssignment.getProperty().getDefaultValue(); - } - - // if value is null don't call setResourceDataValue to populate the value - if (value != null) { - ResourceAssignmentUtils.setResourceDataValue(componentContext, resourceAssignment, value); - } - - // Check the value has populated for mandatory case - ResourceAssignmentUtils.assertTemplateKeyValueNotNull(componentContext, resourceAssignment); - } catch (Exception e) { - ResourceAssignmentUtils.setFailedResourceDataValue(componentContext, resourceAssignment, - e.getMessage()); - throw new SvcLogicException( - String.format("Failed in template key (%s) assignments with : (%s)", resourceAssignment, e), e); - } - } - } - - @Override - public void postProcess(Map inParams, SvcLogicContext ctx, Map componentContext) - throws SvcLogicException { - // Auto-generated method stub - - } - -} diff --git a/blueprints-processor/plugin/assignment-provider/src/main/java/org/onap/ccsdk/config/assignment/processor/InputResourceProcessor.java b/blueprints-processor/plugin/assignment-provider/src/main/java/org/onap/ccsdk/config/assignment/processor/InputResourceProcessor.java deleted file mode 100644 index e32e7af51..000000000 --- a/blueprints-processor/plugin/assignment-provider/src/main/java/org/onap/ccsdk/config/assignment/processor/InputResourceProcessor.java +++ /dev/null @@ -1,96 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2018 IBM. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.ccsdk.config.assignment.processor; - -import java.util.List; -import java.util.Map; -import org.apache.commons.lang3.StringUtils; -import org.onap.ccsdk.config.data.adaptor.service.ConfigResourceService; -import org.onap.ccsdk.config.model.ConfigModelConstant; -import org.onap.ccsdk.config.model.ConfigModelException; -import org.onap.ccsdk.config.model.data.ResourceAssignment; -import org.onap.ccsdk.config.model.service.ComponentNode; -import org.onap.ccsdk.config.model.utils.ResourceAssignmentUtils; -import org.onap.ccsdk.sli.core.sli.SvcLogicContext; -import org.onap.ccsdk.sli.core.sli.SvcLogicException; - -public class InputResourceProcessor implements ComponentNode { - - public InputResourceProcessor(ConfigResourceService configResourceService) {} - - @Override - public Boolean preCondition(Map inParams, SvcLogicContext ctx, Map componentContext) - throws SvcLogicException { - return Boolean.TRUE; - } - - @Override - public void preProcess(Map inParams, SvcLogicContext ctx, Map componentContext) - throws SvcLogicException { - // Auto-generated method stub - } - - @Override - public void process(Map inParams, SvcLogicContext ctx) throws SvcLogicException { - // Auto-generated method stub - } - - @SuppressWarnings("unchecked") - @Override - public void process(Map inParams, SvcLogicContext ctx, Map componentContext) - throws SvcLogicException { - try { - List batchResourceAssignment = - (List) componentContext.get(ConfigModelConstant.PROPERTY_RESOURCE_ASSIGNMENTS); - if (batchResourceAssignment != null && !batchResourceAssignment.isEmpty()) { - for (ResourceAssignment resourceAssignment : batchResourceAssignment) { - processResourceAssignment(ctx, componentContext, resourceAssignment); - } - } - } catch (Exception e) { - throw new SvcLogicException(String.format("InputResourceProcessor Exception : (%s)", e), e); - } - } - - private void processResourceAssignment(SvcLogicContext ctx, Map componentContext, - ResourceAssignment resourceAssignment) throws ConfigModelException, SvcLogicException { - try { - if (StringUtils.isNotBlank(resourceAssignment.getName())) { - String value = ctx.getAttribute(resourceAssignment.getName()); - // if value is null don't call setResourceDataValue to populate the value - if (StringUtils.isNotBlank(value)) { - ResourceAssignmentUtils.setResourceDataValue(componentContext, resourceAssignment, value); - } - } - - // Check the value has populated for mandatory case - ResourceAssignmentUtils.assertTemplateKeyValueNotNull(componentContext, resourceAssignment); - } catch (Exception e) { - ResourceAssignmentUtils.setFailedResourceDataValue(componentContext, resourceAssignment, e.getMessage()); - throw new SvcLogicException( - String.format("Failed in template key (%s) assignments with : (%s)", resourceAssignment, e), e); - } - } - - @Override - public void postProcess(Map inParams, SvcLogicContext ctx, Map componentContext) - throws SvcLogicException { - // Auto-generated method stub - } - -} diff --git a/blueprints-processor/plugin/assignment-provider/src/main/java/org/onap/ccsdk/config/assignment/processor/MdsalResourceProcessor.java b/blueprints-processor/plugin/assignment-provider/src/main/java/org/onap/ccsdk/config/assignment/processor/MdsalResourceProcessor.java deleted file mode 100644 index 15528e13e..000000000 --- a/blueprints-processor/plugin/assignment-provider/src/main/java/org/onap/ccsdk/config/assignment/processor/MdsalResourceProcessor.java +++ /dev/null @@ -1,239 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2018 IBM. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.ccsdk.config.assignment.processor; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import org.apache.commons.collections.CollectionUtils; -import org.apache.commons.collections.MapUtils; -import org.apache.commons.lang3.StringUtils; -import org.onap.ccsdk.config.assignment.service.ConfigAssignmentUtils; -import org.onap.ccsdk.config.model.ConfigModelConstant; -import org.onap.ccsdk.config.model.ConfigModelException; -import org.onap.ccsdk.config.model.data.ResourceAssignment; -import org.onap.ccsdk.config.model.data.dict.ResourceDefinition; -import org.onap.ccsdk.config.model.data.dict.SourcesDefinition; -import org.onap.ccsdk.config.model.service.ComponentNode; -import org.onap.ccsdk.config.model.utils.ResourceAssignmentUtils; -import org.onap.ccsdk.config.model.utils.TransformationUtils; -import org.onap.ccsdk.config.rest.adaptor.ConfigRestAdaptorConstants; -import org.onap.ccsdk.config.rest.adaptor.service.ConfigRestAdaptorService; -import org.onap.ccsdk.sli.core.sli.SvcLogicContext; -import org.onap.ccsdk.sli.core.sli.SvcLogicException; -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; -import com.fasterxml.jackson.databind.JsonNode; - -public class MdsalResourceProcessor implements ComponentNode { - - private static EELFLogger logger = EELFManager.getInstance().getLogger(MdsalResourceProcessor.class); - private ConfigRestAdaptorService configRestAdaptorService; - private Map dictionaries; - - public MdsalResourceProcessor(ConfigRestAdaptorService configRestAdaptorService) { - this.configRestAdaptorService = configRestAdaptorService; - } - - @Override - public Boolean preCondition(Map inParams, SvcLogicContext ctx, Map componentContext) - throws SvcLogicException { - return Boolean.TRUE; - } - - @Override - public void preProcess(Map inParams, SvcLogicContext ctx, Map componentContext) - throws SvcLogicException { - // Auto-generated method stub - } - - @Override - public void process(Map inParams, SvcLogicContext ctx) throws SvcLogicException { - // Auto-generated method stub - } - - @SuppressWarnings("unchecked") - @Override - public void process(Map inParams, SvcLogicContext ctx, Map componentContext) - throws SvcLogicException { - try { - List batchResourceAssignment = - (List) componentContext.get(ConfigModelConstant.PROPERTY_RESOURCE_ASSIGNMENTS); - dictionaries = - (Map) componentContext.get(ConfigModelConstant.PROPERTY_DICTIONARIES); - - if (CollectionUtils.isNotEmpty(batchResourceAssignment)) { - for (ResourceAssignment resourceAssignment : batchResourceAssignment) { - processResourceAssignmnet(ctx, componentContext, resourceAssignment); - } - } - } catch (Exception e) { - throw new SvcLogicException(String.format("MdsalResourceProcessor Exception : (%s) ", e), e); - } - } - - private void processResourceAssignmnet(SvcLogicContext ctx, Map componentContext, - ResourceAssignment resourceAssignment) throws ConfigModelException, SvcLogicException { - - try { - // Validating Resource Assignment and Dictionary Definition data - validate(resourceAssignment); - - // Check if It has Input - Object value = ConfigAssignmentUtils.getContextKeyValue(ctx, resourceAssignment.getName()); - if (value != null) { - logger.info("mdsal source template key ({}) found from input and value is ({})", - resourceAssignment.getName(), value); - ResourceAssignmentUtils.setResourceDataValue(componentContext, resourceAssignment, value); - return; - } - - ResourceDefinition resourceDefinition = dictionaries.get(resourceAssignment.getDictionaryName()); - SourcesDefinition sourceMdsal = resourceDefinition.getSources().get("mdsal"); - String urlPath = sourceMdsal.getProperties().getUrlPath(); - String path = sourceMdsal.getProperties().getPath(); - Map inputKeyMapping = sourceMdsal.getProperties().getInputKeyMapping(); - Map outputKeyMapping = sourceMdsal.getProperties().getOutputKeyMapping(); - - logger.info( - "mdsal dictionary information : urlpath ({}), path({}), inputKeyMapping ({}), outputKeyMapping ({})", - urlPath, path, inputKeyMapping, outputKeyMapping); - - // Resolving url Variables - Map urlVariables = populateUrlVariables(inputKeyMapping, componentContext); - for (Map.Entry entry : urlVariables.entrySet()) { - urlPath = urlPath.replaceAll("\\$" + entry.getKey(), entry.getValue().toString()); - } - - String restResponse = fetchResourceFromMDSAL(urlPath); - // if restResponse is null don't call processMdsalResults to populate the value - if (StringUtils.isNotBlank(restResponse)) { - // Processing MDSAL Response - processMdsalResults(ctx, componentContext, resourceAssignment, sourceMdsal, restResponse); - } else { - logger.warn("Coudn't get proper mdsal Response content ({}) for Resource Name ({}) for URI ({})", - restResponse, resourceAssignment.getDictionaryName(), urlPath); - } - - // Check the value has populated for mandatory case - ResourceAssignmentUtils.assertTemplateKeyValueNotNull(componentContext, resourceAssignment); - } catch (Exception e) { - ResourceAssignmentUtils.setFailedResourceDataValue(componentContext, resourceAssignment, e.getMessage()); - throw new SvcLogicException( - String.format("Failed in assignments for (%s) with (%s)", resourceAssignment, e), e); - } - } - - private String fetchResourceFromMDSAL(String urlPath) { - String response = null; - try { - response = configRestAdaptorService.getResource(ConfigRestAdaptorConstants.SELECTOR_RESTCONF, urlPath, - String.class); - } catch (Exception e) { - logger.warn("Fetching MDSAL data for URL ({}) failed with Error ({})", urlPath, e); - } - return response; - } - - private void validate(ResourceAssignment resourceAssignment) throws SvcLogicException { - if (resourceAssignment == null) { - throw new SvcLogicException("resource assignment is not defined"); - } - - if (StringUtils.isBlank(resourceAssignment.getName())) { - throw new SvcLogicException("resource assignment template key is not defined"); - } - - if (StringUtils.isBlank(resourceAssignment.getDictionaryName())) { - throw new SvcLogicException( - String.format("resource assignment dictionary name is not defined for template key (%s)", - resourceAssignment.getName())); - } - - if (!ConfigModelConstant.SOURCE_MDSAL.equalsIgnoreCase(resourceAssignment.getDictionarySource())) { - throw new SvcLogicException(String.format("resource assignment source is not mdsal, it is (%s)", - resourceAssignment.getDictionarySource())); - } - - ResourceDefinition resourceDefinition = dictionaries.get(resourceAssignment.getDictionaryName()); - if (resourceDefinition == null) { - throw new SvcLogicException(String.format("missing resource dictionary definition for name (%s) ", - resourceAssignment.getDictionaryName())); - } - - if (StringUtils.isBlank(resourceDefinition.getProperty().getType())) { - throw new SvcLogicException(String.format(String.format("Failed to get dictionary (%s) data type info.", - resourceAssignment.getDictionaryName()))); - } - - if (resourceDefinition.getSources() == null || resourceDefinition.getSources().get("mdsal") == null) { - throw new SvcLogicException( - String.format("missing resource dictionary mdsal source definition for name (%s) ", - resourceAssignment.getDictionaryName())); - } - - SourcesDefinition sourceMdsal = resourceDefinition.getSources().get("mdsal"); - if (StringUtils.isBlank(sourceMdsal.getProperties().getUrlPath())) { - throw new SvcLogicException(String.format("Failed to get request URL Path for dictionary (%s)", - resourceAssignment.getDictionaryName())); - } - - if (StringUtils.isBlank(sourceMdsal.getProperties().getPath())) { - throw new SvcLogicException(String.format("Failed to get request Path for dictionary (%s)", - resourceAssignment.getDictionaryName())); - } - } - - private Map populateUrlVariables(Map inputKeyMapping, - Map componentContext) { - Map urlVariables = new HashMap<>(); - if (MapUtils.isNotEmpty(inputKeyMapping)) { - - for (Map.Entry mapping : inputKeyMapping.entrySet()) { - ResourceDefinition referenceDictionaryDefinition = dictionaries.get(mapping.getValue()); - Object expressionValue = - ResourceAssignmentUtils.getDictionaryKeyValue(componentContext, referenceDictionaryDefinition); - logger.trace("Reference dictionary key ({}), value ({})", mapping.getKey(), expressionValue); - urlVariables.put(mapping.getKey(), expressionValue); - } - } - return urlVariables; - } - - private void processMdsalResults(SvcLogicContext ctx, Map componentContext, - ResourceAssignment resourceAssignment, SourcesDefinition sourceMdsal, String restResponse) - throws SvcLogicException, ConfigModelException { - - Map outputKeyMapping = sourceMdsal.getProperties().getOutputKeyMapping(); - JsonNode responseNode = TransformationUtils.getJsonNodeForString(restResponse); - if (StringUtils.isNotBlank(sourceMdsal.getProperties().getPath())) { - responseNode = responseNode.at(sourceMdsal.getProperties().getPath()); - } - if (responseNode != null) { - ConfigAssignmentUtils.populateValueForOutputMapping(ctx, componentContext, resourceAssignment, - outputKeyMapping, responseNode); - } - } - - @Override - public void postProcess(Map inParams, SvcLogicContext ctx, Map componentContext) - throws SvcLogicException { - // Do Nothing - } - -} diff --git a/blueprints-processor/plugin/assignment-provider/src/main/java/org/onap/ccsdk/config/assignment/processor/ProcessorFactory.java b/blueprints-processor/plugin/assignment-provider/src/main/java/org/onap/ccsdk/config/assignment/processor/ProcessorFactory.java deleted file mode 100644 index 5fcedd87f..000000000 --- a/blueprints-processor/plugin/assignment-provider/src/main/java/org/onap/ccsdk/config/assignment/processor/ProcessorFactory.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2018 IBM. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.ccsdk.config.assignment.processor; - -import org.onap.ccsdk.config.data.adaptor.service.ConfigResourceService; -import org.onap.ccsdk.config.model.ConfigModelConstant; -import org.onap.ccsdk.config.model.service.ComponentNode; -import org.onap.ccsdk.config.model.service.ComponentNodeService; -import org.onap.ccsdk.config.rest.adaptor.service.ConfigRestAdaptorService; - -public class ProcessorFactory { - - private ConfigResourceService configResourceService; - private ConfigRestAdaptorService configRestAdaptorService; - private ComponentNodeService componentNodeService; - - public ProcessorFactory(ConfigResourceService configResourceService, - ConfigRestAdaptorService configRestAdaptorService, ComponentNodeService componentNodeService) { - this.componentNodeService = componentNodeService; - this.configResourceService = configResourceService; - this.configRestAdaptorService = configRestAdaptorService; - } - - public ComponentNode getInstance(String source) { - - if (ConfigModelConstant.SOURCE_DEFAULT.equalsIgnoreCase(source)) { - return new DefaultResourceProcessor(configResourceService); - } else if (ConfigModelConstant.SOURCE_DB.equalsIgnoreCase(source)) { - return new DBResourceProcessor(configResourceService); - } else if (ConfigModelConstant.SOURCE_MDSAL.equalsIgnoreCase(source)) { - return new MdsalResourceProcessor(configRestAdaptorService); - } - // Default - return new InputResourceProcessor(configResourceService); - } - -} diff --git a/blueprints-processor/plugin/assignment-provider/src/main/java/org/onap/ccsdk/config/assignment/processor/ResourceAssignmentProcessor.java b/blueprints-processor/plugin/assignment-provider/src/main/java/org/onap/ccsdk/config/assignment/processor/ResourceAssignmentProcessor.java deleted file mode 100644 index 70d9abc68..000000000 --- a/blueprints-processor/plugin/assignment-provider/src/main/java/org/onap/ccsdk/config/assignment/processor/ResourceAssignmentProcessor.java +++ /dev/null @@ -1,120 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2018 IBM. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.ccsdk.config.assignment.processor; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import org.apache.commons.collections.CollectionUtils; -import org.onap.ccsdk.config.model.data.ResourceAssignment; -import org.onap.ccsdk.config.model.utils.TopologicalSortingUtils; -import org.onap.ccsdk.sli.core.sli.SvcLogicContext; -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; - -public class ResourceAssignmentProcessor { - private static EELFLogger logger = EELFManager.getInstance().getLogger(ResourceAssignmentProcessor.class); - - private List assignments; - private Map resourceAssignmentMap; - - @SuppressWarnings("squid:S1172") - public ResourceAssignmentProcessor(List assignments, SvcLogicContext ctx) { - this.assignments = assignments; - this.resourceAssignmentMap = new HashMap<>(); - } - - @SuppressWarnings("squid:S3776") - public List> process() { - List> sequenceBatchResourceAssignment = new ArrayList<>(); - if (this.assignments != null) { - logger.info("Assignments ({})", this.assignments); - this.assignments.forEach(resourceMapping -> { - if (resourceMapping != null) { - logger.trace("Processing Key ({})", resourceMapping.getName()); - resourceAssignmentMap.put(resourceMapping.getName(), resourceMapping); - } - }); - - TopologicalSortingUtils topologySorting = new TopologicalSortingUtils<>(); - this.resourceAssignmentMap.forEach((mappingKey, mapping) -> { - if (mapping != null) { - if (mapping.getDependencies() != null && !mapping.getDependencies().isEmpty()) { - for (String dependency : mapping.getDependencies()) { - topologySorting.add(resourceAssignmentMap.get(dependency), mapping); - } - } else { - topologySorting.add(null, mapping); - } - } - }); - - List sequencedResourceAssignments = topologySorting.topSort(); - logger.info("Sorted Sequenced Assignments ({})", sequencedResourceAssignments); - - List batchResourceAssignment = null; - List batchAssignmentName = null; - for (int i = 0; i < sequencedResourceAssignments.size(); i++) { - ResourceAssignment resourceAssignment = sequencedResourceAssignments.get(i); - ResourceAssignment previousResourceAssignment = null; - - if (i > 0) { - previousResourceAssignment = sequencedResourceAssignments.get(i - 1); - } - if (resourceAssignment != null) { - - boolean dependencyPresence = false; - if (batchAssignmentName != null && resourceAssignment.getDependencies() != null) { - dependencyPresence = - CollectionUtils.containsAny(batchAssignmentName, resourceAssignment.getDependencies()); - } - - logger.trace("({}) -> Checking ({}), with ({}), result ({})", resourceAssignment.getName(), - batchAssignmentName, resourceAssignment.getDependencies(), dependencyPresence); - - if (previousResourceAssignment != null && resourceAssignment.getDictionarySource() != null - && resourceAssignment.getDictionarySource() - .equalsIgnoreCase(previousResourceAssignment.getDictionarySource()) - && !dependencyPresence) { - batchResourceAssignment.add(resourceAssignment); - batchAssignmentName.add(resourceAssignment.getName()); - } else { - if (batchResourceAssignment != null) { - sequenceBatchResourceAssignment.add(batchResourceAssignment); - logger.trace("Created old Set ({})", batchAssignmentName); - } - batchResourceAssignment = new ArrayList<>(); - batchResourceAssignment.add(resourceAssignment); - - batchAssignmentName = new ArrayList<>(); - batchAssignmentName.add(resourceAssignment.getName()); - } - } - - if (i == (sequencedResourceAssignments.size() - 1)) { - logger.trace("Created old Set ({})", batchAssignmentName); - sequenceBatchResourceAssignment.add(batchResourceAssignment); - } - } - logger.info("Batched Sequence : ({})", sequenceBatchResourceAssignment); - } - return sequenceBatchResourceAssignment; - } - -} diff --git a/blueprints-processor/plugin/assignment-provider/src/main/java/org/onap/ccsdk/config/assignment/service/ConfigAssignmentNode.java b/blueprints-processor/plugin/assignment-provider/src/main/java/org/onap/ccsdk/config/assignment/service/ConfigAssignmentNode.java deleted file mode 100644 index 8ed0b71fc..000000000 --- a/blueprints-processor/plugin/assignment-provider/src/main/java/org/onap/ccsdk/config/assignment/service/ConfigAssignmentNode.java +++ /dev/null @@ -1,231 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2018 IBM. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.ccsdk.config.assignment.service; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import org.apache.commons.collections.MapUtils; -import org.apache.commons.lang3.StringUtils; -import org.onap.ccsdk.config.assignment.ConfigAssignmentConstants; -import org.onap.ccsdk.config.assignment.data.ResourceAssignmentData; -import org.onap.ccsdk.config.data.adaptor.service.ConfigResourceService; -import org.onap.ccsdk.config.generator.service.ConfigGeneratorService; -import org.onap.ccsdk.config.model.ConfigModelConstant; -import org.onap.ccsdk.config.model.service.ComponentNode; -import org.onap.ccsdk.config.model.service.ComponentNodeService; -import org.onap.ccsdk.config.model.service.ConfigModelService; -import org.onap.ccsdk.config.model.utils.TransformationUtils; -import org.onap.ccsdk.config.rest.adaptor.service.ConfigRestAdaptorService; -import org.onap.ccsdk.sli.core.sli.SvcLogicContext; -import org.onap.ccsdk.sli.core.sli.SvcLogicException; -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; - -public class ConfigAssignmentNode implements ComponentNode { - private static EELFLogger logger = EELFManager.getInstance().getLogger(ConfigAssignmentNode.class); - - private ComponentNodeService componentNodeService; - private ConfigResourceService configResourceService; - private ConfigModelService configModelService; - private ConfigRestAdaptorService configRestAdaptorService; - private ConfigGeneratorService configGeneratorService; - - public ConfigAssignmentNode(ConfigResourceService configResourceService, - ConfigRestAdaptorService configRestAdaptorService, ConfigModelService configModelService, - ComponentNodeService componentNodeService, ConfigGeneratorService configGeneratorService) { - logger.info("{} Constrctor Initiated", "ConfigAssignmentNode"); - this.componentNodeService = componentNodeService; - this.configResourceService = configResourceService; - this.configModelService = configModelService; - this.configRestAdaptorService = configRestAdaptorService; - this.configGeneratorService = configGeneratorService; - } - - @Override - public Boolean preCondition(Map inParams, SvcLogicContext ctx, Map componentContext) - throws SvcLogicException { - return Boolean.TRUE; - } - - @Override - public void preProcess(Map inParams, SvcLogicContext ctx, Map componentContext) - throws SvcLogicException { - // Auto-generated method stub - } - - /** - * This method is used to resolve the resources defined in the template. Generic Resource API DG - * calls this execute node. - * - * @param inParams This is the input parameter to process this node - * - *
-    request-id                  (string):           Tracking Id 
-    resource-type               (string):           Resource Type ( ex : vnf-type) 
-    resource-id                 (string):           Resource Id 
-    service-template-name       (string):           Blueprint Name 
-    service-template-version    (string):           Blueprint Version 
-    action-name                 (string): 
-    template-names              (List of string):   Template Names / Artifact Node Names to resolve. ["template1", "template2"] 
-    input-data                  (string):           Input Data in JSON String, for the substitution in the Template. 
-    prifix                      (string):           Return Value selector
-     *        
- * - * @param ctx This is the service logger context, Output will be stored ( - * .resource-assignment-params. : Output Data in JSON String. - * .status .error-message ) - * @throws SvcLogicException On processing error. - */ - - @Override - public void process(Map inParams, SvcLogicContext ctx) throws SvcLogicException { - - final String responsePrefix = StringUtils.isNotBlank(inParams.get(ConfigModelConstant.PROPERTY_SELECTOR)) - ? (inParams.get(ConfigModelConstant.PROPERTY_SELECTOR) + ".") - : ""; - try { - - ResourceAssignmentData resourceAssignmentData = populateResourceData(inParams); - resourceAssignmentData.setSvcLogicContext(ctx); - Map componentContext = new HashMap<>(); - resourceAssignmentData.setContext(componentContext); - resourceAssignmentData.setReloadModel(true); - - ConfigAssignmentProcessService configAssignmentProcessService = - new ConfigAssignmentProcessService(configResourceService, configRestAdaptorService, - configModelService, componentNodeService, configGeneratorService); - configAssignmentProcessService.resolveResources(resourceAssignmentData); - - if (MapUtils.isNotEmpty(resourceAssignmentData.getTemplatesMashedContents())) { - resourceAssignmentData.getTemplatesMashedContents().forEach((templateName, previewContent) -> { - logger.debug("For Template name : ({}),\n Preview Content is : ({})", templateName, previewContent); - ctx.setAttribute( - responsePrefix + ConfigAssignmentConstants.OUTPUT_PARAM_MASHED_DATA + "." + templateName, - previewContent); - }); - } - ctx.setAttribute(responsePrefix + ConfigAssignmentConstants.OUTPUT_PARAM_STATUS, - ConfigAssignmentConstants.OUTPUT_STATUS_SUCCESS); - } catch (Exception e) { - ctx.setAttribute(responsePrefix + ConfigAssignmentConstants.OUTPUT_PARAM_STATUS, - ConfigAssignmentConstants.OUTPUT_STATUS_FAILURE); - ctx.setAttribute(responsePrefix + ConfigAssignmentConstants.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage()); - throw new SvcLogicException(e.getMessage(), e); - } - } - - @Override - public void process(Map inParams, SvcLogicContext ctx, Map componentContext) - throws SvcLogicException { - - final String responsePrefix = StringUtils.isNotBlank(inParams.get(ConfigModelConstant.PROPERTY_SELECTOR)) - ? (inParams.get(ConfigModelConstant.PROPERTY_SELECTOR) + ".") - : ""; - try { - - ResourceAssignmentData resourceAssignmentData = populateResourceData(inParams); - resourceAssignmentData.setSvcLogicContext(ctx); - resourceAssignmentData.setContext(componentContext); - resourceAssignmentData.setReloadModel(false); - - ConfigAssignmentProcessService configAssignmentProcessService = - new ConfigAssignmentProcessService(configResourceService, configRestAdaptorService, - configModelService, componentNodeService, configGeneratorService); - configAssignmentProcessService.resolveResources(resourceAssignmentData); - ctx.setAttribute(responsePrefix + ConfigAssignmentConstants.OUTPUT_PARAM_STATUS, - ConfigAssignmentConstants.OUTPUT_STATUS_SUCCESS); - - } catch (Exception e) { - ctx.setAttribute(responsePrefix + ConfigAssignmentConstants.OUTPUT_PARAM_STATUS, - ConfigAssignmentConstants.OUTPUT_STATUS_FAILURE); - ctx.setAttribute(responsePrefix + ConfigAssignmentConstants.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage()); - throw new SvcLogicException(e.getMessage(), e); - } - } - - @Override - public void postProcess(Map inParams, SvcLogicContext ctx, Map componentContext) - throws SvcLogicException { - // Do Nothing - } - - private ResourceAssignmentData populateResourceData(Map inParams) throws SvcLogicException { - validateInputParams(inParams); - - String requestId = inParams.get(ConfigAssignmentConstants.INPUT_PARAM_REQUEST_ID); - String resourceId = inParams.get(ConfigAssignmentConstants.INPUT_PARAM_RESOURCE_ID); - String resourceType = inParams.get(ConfigAssignmentConstants.INPUT_PARAM_RESOURCE_TYPE); - String serviceTemplateName = inParams.get(ConfigModelConstant.SERVICE_TEMPLATE_KEY_ARTIFACT_NAME); - String serviceTemplateVersion = inParams.get(ConfigModelConstant.SERVICE_TEMPLATE_KEY_ARTIFACT_VERSION); - String actionName = inParams.get(ConfigModelConstant.PROPERTY_ACTION_NAME); - String inputData = inParams.get(ConfigAssignmentConstants.INPUT_PARAM_INPUT_DATA); - - String templateNamesStr = inParams.get(ConfigAssignmentConstants.INPUT_PARAM_TEMPLATE_NAMES); - List templateNames = TransformationUtils.getListfromJson(templateNamesStr, String.class); - - ResourceAssignmentData resourceAssignmentData = new ResourceAssignmentData(); - resourceAssignmentData.setRequestId(requestId); - resourceAssignmentData.setResourceId(resourceId); - resourceAssignmentData.setResourceType(resourceType); - resourceAssignmentData.setServiceTemplateName(serviceTemplateName); - resourceAssignmentData.setServiceTemplateVersion(serviceTemplateVersion); - resourceAssignmentData.setActionName(actionName); - resourceAssignmentData.setInputData(inputData); - resourceAssignmentData.setTemplateNames(templateNames); - - return resourceAssignmentData; - } - - private void validateInputParams(Map inParams) throws SvcLogicException { - if (inParams == null) { - throw new SvcLogicException("Input parameters missing"); - } - - String requestId = inParams.get(ConfigAssignmentConstants.INPUT_PARAM_REQUEST_ID); - if (StringUtils.isBlank(requestId)) { - throw new SvcLogicException("Request id parameters missing"); - } - String resourceId = inParams.get(ConfigAssignmentConstants.INPUT_PARAM_RESOURCE_ID); - if (StringUtils.isBlank(resourceId)) { - throw new SvcLogicException("Resource id parameter is missing"); - } - String resourceType = inParams.get(ConfigAssignmentConstants.INPUT_PARAM_RESOURCE_TYPE); - if (StringUtils.isBlank(resourceType)) { - throw new SvcLogicException("Resource type parameter is missing"); - } - String recipeName = inParams.get(ConfigAssignmentConstants.INPUT_PARAM_ACTION_NAME); - if (StringUtils.isBlank(recipeName)) { - throw new SvcLogicException("Action name is parameter is missing"); - } - String templateNames = inParams.get(ConfigAssignmentConstants.INPUT_PARAM_TEMPLATE_NAMES); - if (StringUtils.isBlank(templateNames)) { - throw new SvcLogicException("Template names parameter missing"); - } - String serviceTemplateName = inParams.get(ConfigModelConstant.SERVICE_TEMPLATE_KEY_ARTIFACT_NAME); - if (StringUtils.isBlank(serviceTemplateName)) { - throw new SvcLogicException("Service Template name parameter missing"); - } - String serviceTemplateVersion = inParams.get(ConfigModelConstant.SERVICE_TEMPLATE_KEY_ARTIFACT_VERSION); - if (StringUtils.isBlank(serviceTemplateVersion)) { - throw new SvcLogicException("Service Template version parameter missing"); - } - - } - -} diff --git a/blueprints-processor/plugin/assignment-provider/src/main/java/org/onap/ccsdk/config/assignment/service/ConfigAssignmentPersistService.java b/blueprints-processor/plugin/assignment-provider/src/main/java/org/onap/ccsdk/config/assignment/service/ConfigAssignmentPersistService.java deleted file mode 100644 index 320f4369b..000000000 --- a/blueprints-processor/plugin/assignment-provider/src/main/java/org/onap/ccsdk/config/assignment/service/ConfigAssignmentPersistService.java +++ /dev/null @@ -1,123 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2018 IBM. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.ccsdk.config.assignment.service; - -import java.util.List; -import org.apache.commons.collections.CollectionUtils; -import org.apache.commons.lang3.StringUtils; -import org.onap.ccsdk.config.data.adaptor.DataAdaptorConstants; -import org.onap.ccsdk.config.data.adaptor.domain.ConfigResource; -import org.onap.ccsdk.config.data.adaptor.domain.ResourceAssignmentData; -import org.onap.ccsdk.config.data.adaptor.domain.TransactionLog; -import org.onap.ccsdk.config.data.adaptor.service.ConfigResourceService; -import org.onap.ccsdk.config.model.ConfigModelConstant; -import org.onap.ccsdk.config.model.data.ResourceAssignment; -import org.onap.ccsdk.config.model.utils.ResourceAssignmentUtils; -import org.onap.ccsdk.config.model.utils.TransformationUtils; -import org.onap.ccsdk.sli.core.sli.SvcLogicException; -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; - -public class ConfigAssignmentPersistService { - - private static EELFLogger logger = EELFManager.getInstance().getLogger(ConfigAssignmentPersistService.class); - - private ConfigResourceService configResourceService; - - public ConfigAssignmentPersistService(ConfigResourceService configResourceService) { - this.configResourceService = configResourceService; - } - - public void saveResourceMapping(org.onap.ccsdk.config.assignment.data.ResourceAssignmentData resourceAssignmentData, - String templateName, List resourceAssignments) throws SvcLogicException { - try { - - if (resourceAssignmentData == null) { - throw new SvcLogicException("Resource assignment data is missing"); - } - - if (StringUtils.isBlank(resourceAssignmentData.getRequestId())) { - logger.warn("Request Id ({}) is missing, may be getting request for resource update.", - resourceAssignmentData.getRequestId()); - } - - if (StringUtils.isBlank(resourceAssignmentData.getResourceId())) { - throw new SvcLogicException("Resource Id is missing"); - } - - if (StringUtils.isBlank(resourceAssignmentData.getResourceType())) { - throw new SvcLogicException("Resource type is missing"); - } - - if (StringUtils.isBlank(resourceAssignmentData.getActionName())) { - throw new SvcLogicException("Action name is missing"); - } - - if (StringUtils.isBlank(templateName)) { - throw new SvcLogicException("template name is missing"); - } - - StringBuilder builder = new StringBuilder(); - builder.append("Resource Assignment for Template Name :"); - builder.append(templateName); - builder.append("\n"); - builder.append(TransformationUtils.getJson(resourceAssignments, true)); - - configResourceService.save(new TransactionLog(resourceAssignmentData.getRequestId(), - DataAdaptorConstants.LOG_MESSAGE_TYPE_LOG, builder.toString())); - - // Resource Data should be Regenerated based on the new Updates - String resourceData = ResourceAssignmentUtils.generateResourceDataForAssignments(resourceAssignments); - - List resourceAssignmentDataList = - ConfigAssignmentUtils.convertResoureAssignmentList(resourceAssignments); - - ConfigResource configResource = new ConfigResource(); - configResource.setRequestId(resourceAssignmentData.getRequestId()); - configResource.setServiceTemplateName(resourceAssignmentData.getServiceTemplateName()); - configResource.setServiceTemplateVersion(resourceAssignmentData.getServiceTemplateVersion()); - configResource.setRecipeName(resourceAssignmentData.getActionName()); - configResource.setResourceId(resourceAssignmentData.getResourceId()); - configResource.setResourceType(resourceAssignmentData.getResourceType()); - configResource.setResourceData(resourceData); - configResource.setTemplateName(templateName); - configResource.setStatus(ConfigModelConstant.STATUS_SUCCESS); - configResource.setUpdatedBy(ConfigModelConstant.USER_SYSTEM); - - if (CollectionUtils.isNotEmpty(resourceAssignmentDataList)) { - configResource.setResourceAssignments(resourceAssignmentDataList); - } - configResource = configResourceService.saveConfigResource(configResource); - logger.info("Resource data saved successfully for the template ({}) with resource id ({})", templateName, - configResource.getResourceId()); - - builder = new StringBuilder(); - builder.append("Resource Data Template Name :"); - builder.append(templateName); - builder.append("\n"); - builder.append(resourceData); - configResourceService.save(new TransactionLog(resourceAssignmentData.getRequestId(), - DataAdaptorConstants.LOG_MESSAGE_TYPE_LOG, builder.toString())); - - } catch (Exception e) { - throw new SvcLogicException("ConfigAssignmentPersistService : " + e.getMessage(), e); - } - - } - -} diff --git a/blueprints-processor/plugin/assignment-provider/src/main/java/org/onap/ccsdk/config/assignment/service/ConfigAssignmentProcessService.java b/blueprints-processor/plugin/assignment-provider/src/main/java/org/onap/ccsdk/config/assignment/service/ConfigAssignmentProcessService.java deleted file mode 100644 index 85ff82db6..000000000 --- a/blueprints-processor/plugin/assignment-provider/src/main/java/org/onap/ccsdk/config/assignment/service/ConfigAssignmentProcessService.java +++ /dev/null @@ -1,238 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2018 IBM. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.ccsdk.config.assignment.service; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import org.apache.commons.collections.CollectionUtils; -import org.apache.commons.lang3.StringUtils; -import org.onap.ccsdk.config.assignment.ConfigAssignmentConstants; -import org.onap.ccsdk.config.assignment.data.ResourceAssignmentData; -import org.onap.ccsdk.config.assignment.processor.ProcessorFactory; -import org.onap.ccsdk.config.assignment.processor.ResourceAssignmentProcessor; -import org.onap.ccsdk.config.data.adaptor.service.ConfigResourceService; -import org.onap.ccsdk.config.generator.service.ConfigGeneratorService; -import org.onap.ccsdk.config.model.ConfigModelConstant; -import org.onap.ccsdk.config.model.data.ResourceAssignment; -import org.onap.ccsdk.config.model.data.dict.ResourceDefinition; -import org.onap.ccsdk.config.model.service.ComponentNode; -import org.onap.ccsdk.config.model.service.ComponentNodeService; -import org.onap.ccsdk.config.model.service.ConfigModelService; -import org.onap.ccsdk.config.model.utils.ResourceAssignmentUtils; -import org.onap.ccsdk.config.model.utils.TransformationUtils; -import org.onap.ccsdk.config.rest.adaptor.service.ConfigRestAdaptorService; -import org.onap.ccsdk.sli.core.sli.SvcLogicContext; -import org.onap.ccsdk.sli.core.sli.SvcLogicException; -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; - -public class ConfigAssignmentProcessService { - - private static EELFLogger logger = EELFManager.getInstance().getLogger(ConfigAssignmentProcessService.class); - - private ComponentNodeService componentNodeService; - private ConfigResourceService configResourceService; - private ConfigModelService configModelService; - private ConfigRestAdaptorService configRestAdaptorService; - private ConfigGeneratorService configGeneratorService; - - public ConfigAssignmentProcessService(ConfigResourceService configResourceService, - ConfigRestAdaptorService configRestAdaptorService, ConfigModelService configModelService, - ComponentNodeService componentNodeService, ConfigGeneratorService configGeneratorService) { - this.componentNodeService = componentNodeService; - this.configResourceService = configResourceService; - this.configModelService = configModelService; - this.configRestAdaptorService = configRestAdaptorService; - this.configGeneratorService = configGeneratorService; - } - - @SuppressWarnings("squid:S1141") - public void resolveResources(ResourceAssignmentData resourceAssignmentData) throws SvcLogicException { - try { - validateInputParams(resourceAssignmentData); - - String serviceTemplateName = resourceAssignmentData.getServiceTemplateName(); - String serviceTemplateVersion = resourceAssignmentData.getServiceTemplateVersion(); - String actionName = resourceAssignmentData.getActionName(); - String inputData = resourceAssignmentData.getInputData(); - SvcLogicContext svcLogicContext = resourceAssignmentData.getSvcLogicContext(); - List templateNames = resourceAssignmentData.getTemplateNames(); - - if (resourceAssignmentData.isReloadModel()) { - Map context = new HashMap<>(); - context.put(ConfigModelConstant.PROPERTY_ACTION_NAME, actionName); - context = configModelService.prepareContext(context, inputData, serviceTemplateName, - serviceTemplateVersion); - context.forEach((key, value) -> svcLogicContext.setAttribute(key, value)); - logger.info("List of Resources provided in input: {}", svcLogicContext.toProperties()); - } - - Map componentContext = resourceAssignmentData.getContext(); - - if (CollectionUtils.isNotEmpty(templateNames)) { - // Get the Resource Assignments for templates and Validate the mappings - ResourceModelService resourceModelService = new ResourceModelService(configModelService); - - // Get the Resource Assignment - Map> templatesResourceAssignments = - resourceModelService.getTemplatesResourceAssignments(svcLogicContext, templateNames); - - // Get the Template Contents - Map templatesContents = - resourceModelService.getTemplatesContents(svcLogicContext, templateNames); - - // Process each template - for (String templateName : templateNames) { - List resourceAssignments = templatesResourceAssignments.get(templateName); - String templateContent = templatesContents.get(templateName); - if (resourceAssignments != null) { - String templateData = null; - try { - // Populate the Dictionary - ResourceDictionaryService resourceDictionaryService = - new ResourceDictionaryService(configRestAdaptorService); - Map dictionaries = - resourceDictionaryService.getDataDictionaryDefinitions(resourceAssignments); - - processResourceAssignments(resourceAssignmentData, svcLogicContext, componentContext, - templateName, resourceAssignments, dictionaries); - - logger.info("decrypting config data for templateName {}", templateName); - templateData = - ResourceAssignmentUtils.generateResourceDataForAssignments(resourceAssignments); - } finally { - saveResourceMapping(resourceAssignmentData, templateName, resourceAssignments); - } - - logger.info("generating config preview for templateName {}", templateName); - ConfigPreviewService configPreviewService = new ConfigPreviewService(configResourceService, - configModelService, configGeneratorService); - String mashedData = configPreviewService.generatePreview(templateContent, templateData); - resourceAssignmentData.getTemplatesMashedContents().put(templateName, mashedData); - resourceAssignmentData.getTemplatesData().put(templateName, templateData); - - } else { - // Do nothing for Mapping not found - logger.warn("No resource Assignment mappings to resolve for templateName {}", templateName); - } - } - } - - } catch (Exception e) { - throw new SvcLogicException(e.getMessage(), e); - } - } - - private void processResourceAssignments(ResourceAssignmentData resourceAssignmentData, SvcLogicContext ctx, - Map componentContext, String templateName, List resourceAssignments, - Map dictionaries) throws SvcLogicException { - - String recipeName = resourceAssignmentData.getActionName(); - - ResourceAssignmentProcessor resourceAssignmentProcessor = - new ResourceAssignmentProcessor(resourceAssignments, ctx); - List> sequenceBatchResourceAssignment = resourceAssignmentProcessor.process(); - - logger.debug("Resource dictionary Info ({})", dictionaries); - - if (sequenceBatchResourceAssignment != null) { - componentContext.put(ConfigModelConstant.PROPERTY_ACTION_NAME, recipeName); - componentContext.put(ConfigModelConstant.PROPERTY_TEMPLATE_NAME, templateName); - componentContext.put(ConfigModelConstant.PROPERTY_DICTIONARIES, dictionaries); - for (List batchResourceAssignment : sequenceBatchResourceAssignment) { - - processBatchResourceAssignments(resourceAssignmentData, ctx, componentContext, batchResourceAssignment); - - logger.debug("Batch Resource data status ({})", TransformationUtils.getJson(batchResourceAssignment)); - } - } - } - - private void processBatchResourceAssignments(ResourceAssignmentData resourceAssignmentData, SvcLogicContext ctx, - Map componentContext, List batchResourceAssignment) - throws SvcLogicException { - - if (CollectionUtils.isNotEmpty(batchResourceAssignment)) { - - ResourceAssignment batchFirstResourceAssignment = batchResourceAssignment.get(0); - if (batchFirstResourceAssignment != null - && StringUtils.isNotBlank(batchFirstResourceAssignment.getDictionarySource())) { - String source = batchFirstResourceAssignment.getDictionarySource(); - // Processing their Source - logger.info("Processing source ({}) with batch ({}) ", source, batchResourceAssignment); - componentContext.put(ConfigModelConstant.PROPERTY_RESOURCE_ASSIGNMENTS, batchResourceAssignment); - - ProcessorFactory factory = - new ProcessorFactory(configResourceService, configRestAdaptorService, componentNodeService); - - ComponentNode processor = factory.getInstance(source); - - Map inParams = new HashMap<>(); - inParams.put(ConfigAssignmentConstants.INPUT_PARAM_REQUEST_ID, resourceAssignmentData.getRequestId()); - inParams.put(ConfigAssignmentConstants.INPUT_PARAM_RESOURCE_ID, resourceAssignmentData.getResourceId()); - inParams.put(ConfigAssignmentConstants.INPUT_PARAM_RESOURCE_TYPE, - resourceAssignmentData.getResourceType()); - inParams.put(ConfigAssignmentConstants.INPUT_PARAM_ACTION_NAME, resourceAssignmentData.getActionName()); - inParams.put(ConfigAssignmentConstants.INPUT_PARAM_TEMPLATE_NAMES, - resourceAssignmentData.getTemplateNames().toString()); - processor.process(inParams, ctx, componentContext); - } - } - } - - private void saveResourceMapping(ResourceAssignmentData resourceAssignmentData, String templateName, - List resourceAssignments) throws SvcLogicException { - if (resourceAssignmentData != null && StringUtils.isNotBlank(templateName)) { - - ConfigAssignmentPersistService configAssignmentPersistService = - new ConfigAssignmentPersistService(configResourceService); - configAssignmentPersistService.saveResourceMapping(resourceAssignmentData, templateName, - resourceAssignments); - } - } - - private void validateInputParams(ResourceAssignmentData resourceAssignmentData) throws SvcLogicException { - if (resourceAssignmentData == null) { - throw new SvcLogicException("Input parameters missing"); - } - - String requestId = resourceAssignmentData.getRequestId(); - if (StringUtils.isBlank(requestId)) { - throw new SvcLogicException("Request id parameters missing"); - } - String resourceId = resourceAssignmentData.getResourceId(); - if (StringUtils.isBlank(resourceId)) { - throw new SvcLogicException("Resource id parameter is missing"); - } - String resourceType = resourceAssignmentData.getResourceType(); - if (StringUtils.isBlank(resourceType)) { - throw new SvcLogicException("Resource type parameter is missing"); - } - String actionName = resourceAssignmentData.getActionName(); - if (StringUtils.isBlank(actionName)) { - throw new SvcLogicException("Action name is parameter is missing"); - } - - List templatesNames = resourceAssignmentData.getTemplateNames(); - if (CollectionUtils.isEmpty(templatesNames)) { - throw new SvcLogicException("Template names parameter missing"); - } - } - -} diff --git a/blueprints-processor/plugin/assignment-provider/src/main/java/org/onap/ccsdk/config/assignment/service/ConfigAssignmentService.java b/blueprints-processor/plugin/assignment-provider/src/main/java/org/onap/ccsdk/config/assignment/service/ConfigAssignmentService.java deleted file mode 100644 index 4866f258b..000000000 --- a/blueprints-processor/plugin/assignment-provider/src/main/java/org/onap/ccsdk/config/assignment/service/ConfigAssignmentService.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2018 IBM. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.ccsdk.config.assignment.service; - -import java.util.List; -import org.onap.ccsdk.config.assignment.data.ResourceAssignmentData; -import org.onap.ccsdk.config.model.data.ResourceAssignment; -import org.onap.ccsdk.sli.core.sli.SvcLogicException; - -public interface ConfigAssignmentService { - - public void resolveResources(ResourceAssignmentData resourceAssignmentData) throws SvcLogicException; - - public void saveResourceMapping(ResourceAssignmentData resourceAssignmentData, String templateName, - List resourceAssignments) throws SvcLogicException; - - public ResourceAssignmentData generateTemplateResourceMash(ResourceAssignmentData resourceAssignmentData) - throws SvcLogicException; - -} diff --git a/blueprints-processor/plugin/assignment-provider/src/main/java/org/onap/ccsdk/config/assignment/service/ConfigAssignmentServiceImpl.java b/blueprints-processor/plugin/assignment-provider/src/main/java/org/onap/ccsdk/config/assignment/service/ConfigAssignmentServiceImpl.java deleted file mode 100644 index 9e2bdcf8d..000000000 --- a/blueprints-processor/plugin/assignment-provider/src/main/java/org/onap/ccsdk/config/assignment/service/ConfigAssignmentServiceImpl.java +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2018 IBM. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.ccsdk.config.assignment.service; - -import java.util.List; -import org.onap.ccsdk.config.assignment.data.ResourceAssignmentData; -import org.onap.ccsdk.config.data.adaptor.service.ConfigResourceService; -import org.onap.ccsdk.config.generator.service.ConfigGeneratorService; -import org.onap.ccsdk.config.model.data.ResourceAssignment; -import org.onap.ccsdk.config.model.service.ComponentNodeService; -import org.onap.ccsdk.config.model.service.ConfigModelService; -import org.onap.ccsdk.config.rest.adaptor.service.ConfigRestAdaptorService; -import org.onap.ccsdk.sli.core.sli.SvcLogicException; -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; - -public class ConfigAssignmentServiceImpl implements ConfigAssignmentService { - - private static EELFLogger logger = EELFManager.getInstance().getLogger(ConfigAssignmentServiceImpl.class); - - private ComponentNodeService componentNodeService; - private ConfigResourceService configResourceService; - private ConfigModelService configModelService; - private ConfigRestAdaptorService configRestAdaptorService; - private ConfigGeneratorService configGeneratorService; - - private static final String CLASS_NAME = "ConfigAssignmentServiceImpl"; - - public ConfigAssignmentServiceImpl(ConfigResourceService configResourceService, - ConfigRestAdaptorService configRestAdaptorService, ConfigModelService configModelService, - ComponentNodeService componentNodeService, ConfigGeneratorService configGeneratorService) { - logger.info("{} Constuctor Initated...", CLASS_NAME); - this.componentNodeService = componentNodeService; - this.configResourceService = configResourceService; - this.configModelService = configModelService; - this.configRestAdaptorService = configRestAdaptorService; - this.configGeneratorService = configGeneratorService; - } - - @Override - public void resolveResources(ResourceAssignmentData resourceAssignmentData) throws SvcLogicException { - ConfigAssignmentProcessService configAssignmentProcessService = - new ConfigAssignmentProcessService(configResourceService, configRestAdaptorService, configModelService, - componentNodeService, configGeneratorService); - configAssignmentProcessService.resolveResources(resourceAssignmentData); - } - - @Override - public void saveResourceMapping(ResourceAssignmentData resourceAssignmentData, String templateName, - List resourceAssignments) throws SvcLogicException { - ConfigAssignmentPersistService configAssignmentPersistService = - new ConfigAssignmentPersistService(configResourceService); - configAssignmentPersistService.saveResourceMapping(resourceAssignmentData, templateName, resourceAssignments); - } - - @Override - public ResourceAssignmentData generateTemplateResourceMash(ResourceAssignmentData resourceAssignmentData) - throws SvcLogicException { - ConfigPreviewService configPreviewService = - new ConfigPreviewService(configResourceService, configModelService, configGeneratorService); - return configPreviewService.generateTemplateResourceMash(resourceAssignmentData); - } - -} diff --git a/blueprints-processor/plugin/assignment-provider/src/main/java/org/onap/ccsdk/config/assignment/service/ConfigAssignmentUtils.java b/blueprints-processor/plugin/assignment-provider/src/main/java/org/onap/ccsdk/config/assignment/service/ConfigAssignmentUtils.java deleted file mode 100644 index 32adbe249..000000000 --- a/blueprints-processor/plugin/assignment-provider/src/main/java/org/onap/ccsdk/config/assignment/service/ConfigAssignmentUtils.java +++ /dev/null @@ -1,305 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2018 IBM. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.ccsdk.config.assignment.service; - -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import org.apache.commons.collections.CollectionUtils; -import org.apache.commons.collections.IteratorUtils; -import org.apache.commons.collections.MapUtils; -import org.apache.commons.lang3.StringUtils; -import org.onap.ccsdk.config.data.adaptor.domain.ResourceAssignmentData; -import org.onap.ccsdk.config.model.ConfigModelConstant; -import org.onap.ccsdk.config.model.ConfigModelException; -import org.onap.ccsdk.config.model.ValidTypes; -import org.onap.ccsdk.config.model.data.DataType; -import org.onap.ccsdk.config.model.data.EntrySchema; -import org.onap.ccsdk.config.model.data.PropertyDefinition; -import org.onap.ccsdk.config.model.data.ResourceAssignment; -import org.onap.ccsdk.config.model.data.dict.ResourceDefinition; -import org.onap.ccsdk.config.model.domain.ResourceDictionary; -import org.onap.ccsdk.config.model.utils.JsonUtils; -import org.onap.ccsdk.config.model.utils.ResourceAssignmentUtils; -import org.onap.ccsdk.config.model.utils.TransformationUtils; -import org.onap.ccsdk.sli.core.sli.SvcLogicContext; -import org.onap.ccsdk.sli.core.sli.SvcLogicException; -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; -import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.node.ArrayNode; -import com.fasterxml.jackson.databind.node.JsonNodeFactory; -import com.fasterxml.jackson.databind.node.ObjectNode; - -public class ConfigAssignmentUtils { - - private ConfigAssignmentUtils() { - - } - - private static EELFLogger logger = EELFManager.getInstance().getLogger(ConfigAssignmentUtils.class); - - public static synchronized Object getContextKeyValue(SvcLogicContext context, String key) { - Object value = null; - if (context != null && key != null) { - if (context.getAttributeKeySet().contains(key)) { - String strValue = context.getAttribute(key); - if (StringUtils.isNotBlank(strValue)) { - value = strValue; - } - } else { - // Do Nothing - } - } - return value; - } - - /* - * Populate the Field property type for the Data type - */ - public static synchronized String getPropertyType(SvcLogicContext ctx, String dataTypeName, String propertyName) - throws SvcLogicException { - String type = ValidTypes.DATA_TYPE_STRING; - try { - if (ctx != null && StringUtils.isNotBlank(dataTypeName) && StringUtils.isNotBlank(propertyName)) { - String dataTypeContent = ctx.getAttribute(ConfigModelConstant.PROPERTY_DATA_TYPES_DOT + dataTypeName); - if (StringUtils.isNotBlank(dataTypeContent)) { - DataType dataType = TransformationUtils.readValue(dataTypeContent, DataType.class); - if (dataType != null && dataType.getProperties() != null - && dataType.getProperties().containsKey(propertyName)) { - PropertyDefinition propertyDefinition = dataType.getProperties().get(propertyName); - if (StringUtils.isNotBlank(propertyDefinition.getType())) { - type = propertyDefinition.getType(); - logger.trace("Data type({})'s property ({}) is ({})", dataTypeName, propertyName, type); - } else { - throw new SvcLogicException(String.format("Couldn't get data type (%s) ", dataTypeName)); - } - } - } else { - throw new SvcLogicException(String.format("Couldn't get data type (%s) content", dataTypeName)); - } - } - } catch (Exception e) { - logger.error("couldn't get data type({})'s property ({}), type ({}), error message ({}).", dataTypeName, - propertyName, type, e.getMessage()); - throw new SvcLogicException(e.getMessage()); - } - return type; - } - - /* - * Populate the Field property type for the Data type - */ - public static synchronized PropertyDefinition getPropertyDefinition(SvcLogicContext ctx, String dataTypeName, - String propertyName) throws SvcLogicException { - PropertyDefinition propertyDefinition = null; - try { - if (ctx != null && StringUtils.isNotBlank(dataTypeName) && StringUtils.isNotBlank(propertyName)) { - String dataTypeContent = ctx.getAttribute(ConfigModelConstant.PROPERTY_DATA_TYPES_DOT + dataTypeName); - if (StringUtils.isNotBlank(dataTypeContent)) { - DataType dataType = TransformationUtils.readValue(dataTypeContent, DataType.class); - if (dataType != null && dataType.getProperties() != null - && dataType.getProperties().containsKey(propertyName)) { - propertyDefinition = dataType.getProperties().get(propertyName); - if (propertyDefinition == null) { - throw new SvcLogicException(String.format("couldn't get data type (%s) ", dataTypeName)); - } - } - } else { - throw new SvcLogicException(String.format("couldn't get data type (%s) content.", dataTypeName)); - } - } - } catch (Exception e) { - throw new SvcLogicException(e.getMessage()); - } - return propertyDefinition; - } - - public static synchronized ResourceDefinition getDictionaryDefinition(Map dictionaries, - String dictionaryName) { - ResourceDefinition resourceDefinition = null; - if (dictionaries != null && StringUtils.isNotBlank(dictionaryName)) { - ResourceDictionary resourceDictionary = dictionaries.get(dictionaryName); - if (resourceDictionary != null && StringUtils.isNotBlank(resourceDictionary.getDefinition())) { - resourceDefinition = - TransformationUtils.readValue(resourceDictionary.getDefinition(), ResourceDefinition.class); - } - } - return resourceDefinition; - } - - @SuppressWarnings("squid:S3776") - public static synchronized void populateValueForOutputMapping(SvcLogicContext ctx, - Map componentContext, ResourceAssignment resourceAssignment, - Map outputKeyMapping, JsonNode responseNode) - throws ConfigModelException, SvcLogicException { - if (resourceAssignment == null) { - throw new SvcLogicException("resourceAssignment is null."); - } - - if (ctx == null) { - throw new SvcLogicException("service logic context is null."); - } - - if (componentContext == null) { - throw new SvcLogicException("component context is null."); - } - - logger.info("populating value for output mapping ({}), from json ({})", outputKeyMapping, responseNode); - String dictionaryName = resourceAssignment.getDictionaryName(); - String type = resourceAssignment.getProperty().getType(); - - String entrySchema = null; - if (ValidTypes.getPrimitivePropertType().contains(type)) { - ResourceAssignmentUtils.setResourceDataValue(componentContext, resourceAssignment, responseNode); - } else if (ValidTypes.getListPropertType().contains(type)) { - // Array Types - if (resourceAssignment.getProperty().getEntrySchema() != null) { - entrySchema = resourceAssignment.getProperty().getEntrySchema().getType(); - } - - if (StringUtils.isNotBlank(entrySchema)) { - ArrayNode arrayNode = JsonNodeFactory.instance.arrayNode(); - if (ValidTypes.getPrimitivePropertType().contains(entrySchema)) { - arrayNode = (ArrayNode) responseNode; - } else if (MapUtils.isNotEmpty(outputKeyMapping)) { - List responseArrayNode = IteratorUtils.toList(responseNode.elements()); - for (JsonNode responseSingleJsonNode : responseArrayNode) { - if (responseSingleJsonNode != null) { - ObjectNode arrayChildNode = JsonNodeFactory.instance.objectNode(); - for (Map.Entry mapping : outputKeyMapping.entrySet()) { - JsonNode responseKeyValue = responseSingleJsonNode.get(mapping.getKey()); - - String propertyTypeForDataType = - ConfigAssignmentUtils.getPropertyType(ctx, entrySchema, mapping.getKey()); - logger.info("For List Type Resource: key ({}), value ({}), type ({})", - mapping.getKey(), responseKeyValue, propertyTypeForDataType); - JsonUtils.populateJsonNodeValues(mapping.getValue(), responseKeyValue, - propertyTypeForDataType, arrayChildNode); - } - arrayNode.add(arrayChildNode); - } - } - } else { - arrayNode = (ArrayNode) responseNode; - } - // Set the List of Complex Values - ResourceAssignmentUtils.setResourceDataValue(componentContext, resourceAssignment, arrayNode); - } else { - throw new SvcLogicException( - String.format("Entry schema is not defined for dictionary (%s) info", dictionaryName)); - } - } else { - // Complex Types - ObjectNode objectNode = null; - if (MapUtils.isNotEmpty(outputKeyMapping)) { - objectNode = JsonNodeFactory.instance.objectNode(); - for (Map.Entry mapping : outputKeyMapping.entrySet()) { - JsonNode responseKeyValue = responseNode.get(mapping.getKey()); - String propertyTypeForDataType = - ConfigAssignmentUtils.getPropertyType(ctx, entrySchema, mapping.getKey()); - logger.info("For Complex Type Resource: key ({}), value ({}), type ({})", mapping.getKey(), - responseKeyValue, propertyTypeForDataType); - JsonUtils.populateJsonNodeValues(mapping.getValue(), responseKeyValue, propertyTypeForDataType, - objectNode); - } - } else { - objectNode = (ObjectNode) responseNode; - } - ResourceAssignmentUtils.setResourceDataValue(componentContext, resourceAssignment, objectNode); - } - } - - @SuppressWarnings("squid:S3776") - public static synchronized List convertResoureAssignmentDataList( - List resourceAssignmentDataList) { - List assignments = new ArrayList<>(); - if (CollectionUtils.isNotEmpty(resourceAssignmentDataList)) { - for (ResourceAssignmentData resourceAssignmentData : resourceAssignmentDataList) { - if (resourceAssignmentData != null) { - ResourceAssignment resourceAssignment = new ResourceAssignment(); - resourceAssignment.setName(resourceAssignmentData.getTemplateKeyName()); - resourceAssignment.setVersion(resourceAssignmentData.getVersion()); - resourceAssignment.setUpdatedBy(resourceAssignmentData.getUpdatedBy()); - resourceAssignment.setUpdatedDate(resourceAssignmentData.getUpdatedDate()); - resourceAssignment.setDictionaryName(resourceAssignmentData.getResourceName()); - resourceAssignment.setDictionarySource(resourceAssignmentData.getSource()); - resourceAssignment.setStatus(resourceAssignmentData.getStatus()); - resourceAssignment.setMessage(resourceAssignmentData.getMessage()); - PropertyDefinition property = new PropertyDefinition(); - property.setType(resourceAssignmentData.getDataType()); - - if (StringUtils.isNotBlank(resourceAssignmentData.getResourceValue())) { - if (ValidTypes.getPrimitivePropertType().contains(resourceAssignmentData.getDataType())) { - property.setValue(resourceAssignmentData.getResourceValue()); - } else { - JsonNode valueNode = - TransformationUtils.getJsonNodeForString(resourceAssignmentData.getResourceValue()); - property.setValue(valueNode); - } - } - if (StringUtils.isNotBlank(resourceAssignmentData.getEntrySchema())) { - EntrySchema entrySchema = new EntrySchema(); - entrySchema.setType(resourceAssignmentData.getEntrySchema()); - property.setEntrySchema(entrySchema); - } else { - property.setEntrySchema(null); - } - resourceAssignment.setProperty(property); - assignments.add(resourceAssignment); - } - } - - } - return assignments; - } - - @SuppressWarnings("squid:S3776") - public static synchronized List convertResoureAssignmentList( - List assignments) { - List resourceAssignmentDataList = new ArrayList<>(); - if (CollectionUtils.isNotEmpty(assignments)) { - for (ResourceAssignment assignment : assignments) { - if (assignment != null) { - ResourceAssignmentData resourceAssignmentData = new ResourceAssignmentData(); - resourceAssignmentData.setTemplateKeyName(assignment.getName()); - resourceAssignmentData.setVersion(assignment.getVersion()); - resourceAssignmentData.setUpdatedBy(assignment.getUpdatedBy()); - resourceAssignmentData.setUpdatedDate(assignment.getUpdatedDate()); - if (assignment.getProperty() != null) { - resourceAssignmentData.setDataType(assignment.getProperty().getType()); - if (assignment.getProperty().getEntrySchema() != null) { - resourceAssignmentData.setEntrySchema(assignment.getProperty().getEntrySchema().getType()); - } - if (assignment.getProperty().getValue() != null) { - String valueContent = TransformationUtils.getJson(assignment.getProperty().getValue()); - resourceAssignmentData.setResourceValue(valueContent); - } - } - resourceAssignmentData.setResourceName(assignment.getDictionaryName()); - resourceAssignmentData.setSource(assignment.getDictionarySource()); - resourceAssignmentData.setStatus(assignment.getStatus()); - resourceAssignmentData.setMessage(assignment.getMessage()); - resourceAssignmentDataList.add(resourceAssignmentData); - } - } - } - return resourceAssignmentDataList; - } - -} diff --git a/blueprints-processor/plugin/assignment-provider/src/main/java/org/onap/ccsdk/config/assignment/service/ConfigPreviewService.java b/blueprints-processor/plugin/assignment-provider/src/main/java/org/onap/ccsdk/config/assignment/service/ConfigPreviewService.java deleted file mode 100644 index ae5c01c88..000000000 --- a/blueprints-processor/plugin/assignment-provider/src/main/java/org/onap/ccsdk/config/assignment/service/ConfigPreviewService.java +++ /dev/null @@ -1,119 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2018 IBM. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.ccsdk.config.assignment.service; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import org.apache.commons.collections.CollectionUtils; -import org.apache.commons.lang3.StringUtils; -import org.onap.ccsdk.config.assignment.data.ResourceAssignmentData; -import org.onap.ccsdk.config.data.adaptor.domain.ConfigResource; -import org.onap.ccsdk.config.data.adaptor.service.ConfigResourceService; -import org.onap.ccsdk.config.generator.data.ConfigGeneratorInfo; -import org.onap.ccsdk.config.generator.service.ConfigGeneratorService; -import org.onap.ccsdk.config.model.ConfigModelConstant; -import org.onap.ccsdk.config.model.service.ConfigModelService; -import org.onap.ccsdk.sli.core.sli.SvcLogicException; -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; - -public class ConfigPreviewService { - private static EELFLogger logger = EELFManager.getInstance().getLogger(ConfigAssignmentPersistService.class); - private ConfigResourceService configResourceService; - private ConfigModelService configModelService; - private ConfigGeneratorService configGeneratorService; - - public ConfigPreviewService(ConfigResourceService configResourceService, ConfigModelService configModelService, - ConfigGeneratorService configGeneratorService) { - this.configResourceService = configResourceService; - this.configModelService = configModelService; - this.configGeneratorService = configGeneratorService; - } - - public String generatePreview(String templateContent, String templateData) throws SvcLogicException { - String mashedData = ""; - ConfigGeneratorInfo configGeneratorInfo = - configGeneratorService.generateConfiguration(templateContent, templateData); - if (configGeneratorInfo != null) { - mashedData = configGeneratorInfo.getMashedData(); - } - return mashedData; - } - - public ResourceAssignmentData generateTemplateResourceMash(ResourceAssignmentData resourceAssignmentData) - throws SvcLogicException { - if (resourceAssignmentData == null) { - throw new SvcLogicException("Resource assignment data is missing"); - } - if (StringUtils.isBlank(resourceAssignmentData.getServiceTemplateName())) { - throw new SvcLogicException("Service template name is missing"); - } - if (StringUtils.isBlank(resourceAssignmentData.getServiceTemplateVersion())) { - throw new SvcLogicException("Service template version is missing"); - } - if (StringUtils.isBlank(resourceAssignmentData.getResourceType())) { - throw new SvcLogicException("Resource type is missing"); - } - if (StringUtils.isBlank(resourceAssignmentData.getResourceId())) { - throw new SvcLogicException("Resource Id is missing"); - } - if (StringUtils.isBlank(resourceAssignmentData.getActionName())) { - throw new SvcLogicException("Action name is missing"); - } - - String serviceTemplateName = resourceAssignmentData.getServiceTemplateName(); - String serviceTemplateVersion = resourceAssignmentData.getServiceTemplateVersion(); - String actionName = resourceAssignmentData.getActionName(); - String resourceId = resourceAssignmentData.getResourceId(); - String resourceType = resourceAssignmentData.getResourceType(); - String inputData = "{}"; - - Map context = new HashMap<>(); - context.put(ConfigModelConstant.PROPERTY_ACTION_NAME, actionName); - context = configModelService.prepareContext(context, inputData, serviceTemplateName, serviceTemplateVersion); - - ConfigResource configResourceQuery = new ConfigResource(); - configResourceQuery.setServiceTemplateVersion(serviceTemplateName); - configResourceQuery.setServiceTemplateVersion(serviceTemplateVersion); - configResourceQuery.setRecipeName(actionName); - configResourceQuery.setResourceId(resourceId); - configResourceQuery.setResourceType(resourceType); - - List configResources = configResourceService.getConfigResource(configResourceQuery); - if (CollectionUtils.isNotEmpty(configResources)) { - for (ConfigResource cr : configResources) { - String templateContent = context - .get(ConfigModelConstant.PROPERTY_NODE_TEMPLATES_DOT + cr.getTemplateName() + ".content"); - String templateData = cr.getResourceData(); - String previewContent = generatePreview(templateContent, templateData); - resourceAssignmentData.getTemplatesMashedContents().put(cr.getTemplateName(), previewContent); - logger.info("Preview generated for template name ({}) ", cr.getTemplateName()); - logger.trace("Preview generated for preview ({}) ", previewContent); - } - } else { - logger.info( - "Couldn't get config resource for service template name ({}) service template version ({})" - + " action ({}) resource id ({}) resource type ({})", - serviceTemplateName, serviceTemplateVersion, actionName, resourceId, resourceType); - } - return resourceAssignmentData; - - } - -} diff --git a/blueprints-processor/plugin/assignment-provider/src/main/java/org/onap/ccsdk/config/assignment/service/ResourceDictionaryService.java b/blueprints-processor/plugin/assignment-provider/src/main/java/org/onap/ccsdk/config/assignment/service/ResourceDictionaryService.java deleted file mode 100644 index 50562b0e8..000000000 --- a/blueprints-processor/plugin/assignment-provider/src/main/java/org/onap/ccsdk/config/assignment/service/ResourceDictionaryService.java +++ /dev/null @@ -1,112 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2018 IBM. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.ccsdk.config.assignment.service; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import org.apache.commons.lang3.StringUtils; -import org.onap.ccsdk.config.model.data.ResourceAssignment; -import org.onap.ccsdk.config.model.data.dict.ResourceDefinition; -import org.onap.ccsdk.config.model.domain.ResourceDictionary; -import org.onap.ccsdk.config.model.utils.TransformationUtils; -import org.onap.ccsdk.config.rest.adaptor.ConfigRestAdaptorConstants; -import org.onap.ccsdk.config.rest.adaptor.ConfigRestAdaptorException; -import org.onap.ccsdk.config.rest.adaptor.service.ConfigRestAdaptorService; -import org.onap.ccsdk.sli.core.sli.SvcLogicException; -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; - -public class ResourceDictionaryService { - - private static EELFLogger logger = EELFManager.getInstance().getLogger(ResourceDictionaryService.class); - private ConfigRestAdaptorService configRestAdaptorService; - - public ResourceDictionaryService(ConfigRestAdaptorService configRestAdaptorService) { - this.configRestAdaptorService = configRestAdaptorService; - } - - @SuppressWarnings("squid:S3776") - public Map getDataDictionaryDefinitions(List resourceAssignments) - throws SvcLogicException { - try { - Map dictionaries = new HashMap<>(); - if (resourceAssignments != null) { - List names = new ArrayList<>(); - for (ResourceAssignment resourceAssignment : resourceAssignments) { - if (resourceAssignment != null && StringUtils.isNotBlank(resourceAssignment.getDictionaryName())) { - - if (!names.contains(resourceAssignment.getDictionaryName())) { - names.add(resourceAssignment.getDictionaryName()); - } - - if (resourceAssignment.getDependencies() != null - && !resourceAssignment.getDependencies().isEmpty()) { - List dependencieNames = resourceAssignment.getDependencies(); - for (String dependencieName : dependencieNames) { - if (StringUtils.isNotBlank(dependencieName) && !names.contains(dependencieName)) { - names.add(dependencieName); - } - } - } - } - } - queryResourceDictionaryDefinitions(dictionaries, names); - } - return dictionaries; - } catch (Exception e) { - throw new SvcLogicException("Failed in getting resource data dictionary : " + e.getMessage()); - } - - } - - @SuppressWarnings("squid:S3776") - private void queryResourceDictionaryDefinitions(Map dictionaries, List names) - throws SvcLogicException, ConfigRestAdaptorException { - logger.info("Getting resource dictionary definition for the names ({})", names); - if (!names.isEmpty()) { - - String dictionaryContents = configRestAdaptorService.postResource( - ConfigRestAdaptorConstants.SELECTOR_MODEL_SERVICE, "dictionarybynames", names, String.class); - - if (StringUtils.isNotBlank(dictionaryContents)) { - List dataDictionaries = - TransformationUtils.getListfromJson(dictionaryContents, ResourceDictionary.class); - if (dataDictionaries != null) { - for (ResourceDictionary dataDictionary : dataDictionaries) { - if (dataDictionary != null && StringUtils.isNotBlank(dataDictionary.getName()) - && StringUtils.isNotBlank(dataDictionary.getDefinition())) { - ResourceDefinition resourceDefinition = TransformationUtils - .readValue(dataDictionary.getDefinition(), ResourceDefinition.class); - if (resourceDefinition != null && StringUtils.isNotBlank(resourceDefinition.getName())) { - dictionaries.put(resourceDefinition.getName(), resourceDefinition); - } else { - throw new SvcLogicException( - "Failed in getting resource data dictionary definition for : " - + dataDictionary.getName()); - } - } - } - } - } else { - logger.warn("No resource dictionary definition found for the names ({})", names); - } - } - } -} diff --git a/blueprints-processor/plugin/assignment-provider/src/main/java/org/onap/ccsdk/config/assignment/service/ResourceModelService.java b/blueprints-processor/plugin/assignment-provider/src/main/java/org/onap/ccsdk/config/assignment/service/ResourceModelService.java deleted file mode 100644 index 9f3013b73..000000000 --- a/blueprints-processor/plugin/assignment-provider/src/main/java/org/onap/ccsdk/config/assignment/service/ResourceModelService.java +++ /dev/null @@ -1,97 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2018 IBM. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.ccsdk.config.assignment.service; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import org.apache.commons.collections.CollectionUtils; -import org.apache.commons.lang3.StringUtils; -import org.onap.ccsdk.config.model.data.ResourceAssignment; -import org.onap.ccsdk.config.model.service.ConfigModelService; -import org.onap.ccsdk.config.model.utils.TransformationUtils; -import org.onap.ccsdk.config.model.validator.ResourceAssignmentValidator; -import org.onap.ccsdk.sli.core.sli.SvcLogicContext; -import org.onap.ccsdk.sli.core.sli.SvcLogicException; -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; - -public class ResourceModelService { - private static EELFLogger logger = EELFManager.getInstance().getLogger(ResourceModelService.class); - - private ConfigModelService configModelService; - - public ResourceModelService(ConfigModelService configModelService) { - this.configModelService = configModelService; - } - - public Map getTemplatesContents(SvcLogicContext ctx, List templateNames) - throws SvcLogicException { - Map templatesContents = new HashMap<>(); - try { - if (CollectionUtils.isNotEmpty(templateNames)) { - for (String templateName : templateNames) { - String templateContent = this.configModelService.getNodeTemplateContent(ctx, templateName); - logger.trace("Processing template ({}) with content : {}", templateName, templateContent); - templatesContents.put(templateName, templateContent); - } - } - } catch (Exception e) { - throw new SvcLogicException(e.getMessage()); - } - return templatesContents; - } - - public Map> getTemplatesResourceAssignments(SvcLogicContext ctx, - List templateNames) throws SvcLogicException { - Map> templatesResourceAssignments = new HashMap<>(); - try { - if (CollectionUtils.isNotEmpty(templateNames)) { - for (String templateName : templateNames) { - String resourceMappingContent = this.configModelService.getNodeTemplateMapping(ctx, templateName); - logger.info("Processing template ({}) with resource assignment content : {}", templateName, - resourceMappingContent); - - if (StringUtils.isNotBlank(resourceMappingContent)) { - - List resourceAssignments = - TransformationUtils.getListfromJson(resourceMappingContent, ResourceAssignment.class); - - if (resourceAssignments != null) { - ResourceAssignmentValidator resourceAssignmentValidator = - new ResourceAssignmentValidator(resourceAssignments); - resourceAssignmentValidator.validateResourceAssignment(); - logger.info("Resource assignment validated successfully for the template ({})", - templateName); - templatesResourceAssignments.put(templateName, resourceAssignments); - } else { - throw new SvcLogicException(String.format( - "Failed to convert assignment content (%s) to object", resourceMappingContent)); - } - } else { - // Do nothing, because som e templates may not have mappings - } - } - } - } catch (Exception e) { - throw new SvcLogicException(e.getMessage()); - } - - return templatesResourceAssignments; - } -} diff --git a/blueprints-processor/plugin/assignment-provider/src/main/java/org/onap/ccsdk/features/assignment/ConfigAssignmentConstants.java b/blueprints-processor/plugin/assignment-provider/src/main/java/org/onap/ccsdk/features/assignment/ConfigAssignmentConstants.java new file mode 100644 index 000000000..3052a8611 --- /dev/null +++ b/blueprints-processor/plugin/assignment-provider/src/main/java/org/onap/ccsdk/features/assignment/ConfigAssignmentConstants.java @@ -0,0 +1,37 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2018 IBM. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.ccsdk.features.assignment; + +@SuppressWarnings("squid:S1118") +public class ConfigAssignmentConstants { + + public static final String OUTPUT_PARAM_STATUS = "status"; + public static final String OUTPUT_PARAM_RESOURCE_ASSIGNMENT_PARAMS = "resource-assignment-params"; + public static final String OUTPUT_PARAM_MASHED_DATA = "mashed-data"; + public static final String OUTPUT_PARAM_ERROR_MESSAGE = "error-message"; + public static final String OUTPUT_STATUS_SUCCESS = "success"; + public static final String OUTPUT_STATUS_FAILURE = "failure"; + + public static final String INPUT_PARAM_REQUEST_ID = "request-id"; + public static final String INPUT_PARAM_RESOURCE_ID = "resource-id"; + public static final String INPUT_PARAM_RESOURCE_TYPE = "resource-type"; + public static final String INPUT_PARAM_ACTION_NAME = "action-name"; + public static final String INPUT_PARAM_TEMPLATE_NAMES = "template-names"; + public static final String INPUT_PARAM_INPUT_DATA = "input-data"; + +} diff --git a/blueprints-processor/plugin/assignment-provider/src/main/java/org/onap/ccsdk/features/assignment/data/ResourceAssignmentData.java b/blueprints-processor/plugin/assignment-provider/src/main/java/org/onap/ccsdk/features/assignment/data/ResourceAssignmentData.java new file mode 100644 index 000000000..2bd067461 --- /dev/null +++ b/blueprints-processor/plugin/assignment-provider/src/main/java/org/onap/ccsdk/features/assignment/data/ResourceAssignmentData.java @@ -0,0 +1,164 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2018 IBM. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.ccsdk.features.assignment.data; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.onap.ccsdk.features.model.data.ResourceAssignment; +import org.onap.ccsdk.sli.core.sli.SvcLogicContext; + +public class ResourceAssignmentData { + + private String requestId; + private boolean reloadModel; + private String resourceType; + private String resourceId; + private String serviceTemplateName; + private String serviceTemplateVersion; + private String actionName; + private String inputData; + private SvcLogicContext svcLogicContext; + private List templateNames; + private Map> templatesResourceAssignments = new HashMap<>(); + private Map templatesContents = new HashMap<>(); + private Map templatesMashedContents = new HashMap<>(); + private Map templatesData = new HashMap<>(); + private Map context = new HashMap<>(); + + public String getRequestId() { + return requestId; + } + + public void setRequestId(String requestId) { + this.requestId = requestId; + } + + public String getResourceType() { + return resourceType; + } + + public void setResourceType(String resourceType) { + this.resourceType = resourceType; + } + + public String getResourceId() { + return resourceId; + } + + public void setResourceId(String resourceId) { + this.resourceId = resourceId; + } + + public String getServiceTemplateName() { + return serviceTemplateName; + } + + public void setServiceTemplateName(String serviceTemplateName) { + this.serviceTemplateName = serviceTemplateName; + } + + public String getServiceTemplateVersion() { + return serviceTemplateVersion; + } + + public void setServiceTemplateVersion(String serviceTemplateVersion) { + this.serviceTemplateVersion = serviceTemplateVersion; + } + + public String getActionName() { + return actionName; + } + + public void setActionName(String actionName) { + this.actionName = actionName; + } + + public String getInputData() { + return inputData; + } + + public void setInputData(String inputData) { + this.inputData = inputData; + } + + public List getTemplateNames() { + return templateNames; + } + + public void setTemplateNames(List templateNames) { + this.templateNames = templateNames; + } + + public Map> getTemplatesResourceAssignments() { + return templatesResourceAssignments; + } + + public void setTemplatesResourceAssignments(Map> templatesResourceAssignments) { + this.templatesResourceAssignments = templatesResourceAssignments; + } + + public Map getTemplatesContents() { + return templatesContents; + } + + public void setTemplatesContents(Map templatesContents) { + this.templatesContents = templatesContents; + } + + public Map getTemplatesMashedContents() { + return templatesMashedContents; + } + + public void setTemplatesMashedContents(Map templatesMashedContents) { + this.templatesMashedContents = templatesMashedContents; + } + + public Map getTemplatesData() { + return templatesData; + } + + public void setTemplatesData(Map templatesData) { + this.templatesData = templatesData; + } + + public Map getContext() { + return context; + } + + public void setContext(Map context) { + this.context = context; + } + + public SvcLogicContext getSvcLogicContext() { + return svcLogicContext; + } + + public void setSvcLogicContext(SvcLogicContext svcLogicContext) { + this.svcLogicContext = svcLogicContext; + } + + public boolean isReloadModel() { + return reloadModel; + } + + public void setReloadModel(boolean reloadModel) { + this.reloadModel = reloadModel; + } +} diff --git a/blueprints-processor/plugin/assignment-provider/src/main/java/org/onap/ccsdk/features/assignment/processor/DBResourceProcessor.java b/blueprints-processor/plugin/assignment-provider/src/main/java/org/onap/ccsdk/features/assignment/processor/DBResourceProcessor.java new file mode 100644 index 000000000..132d03c4f --- /dev/null +++ b/blueprints-processor/plugin/assignment-provider/src/main/java/org/onap/ccsdk/features/assignment/processor/DBResourceProcessor.java @@ -0,0 +1,267 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2018 IBM. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.ccsdk.features.assignment.processor; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import org.apache.commons.collections.CollectionUtils; +import org.apache.commons.collections.MapUtils; +import org.apache.commons.lang3.StringUtils; +import org.onap.ccsdk.features.assignment.service.ConfigAssignmentUtils; +import org.onap.ccsdk.features.data.adaptor.service.ConfigResourceService; +import org.onap.ccsdk.features.model.ConfigModelConstant; +import org.onap.ccsdk.features.model.ConfigModelException; +import org.onap.ccsdk.features.model.ValidTypes; +import org.onap.ccsdk.features.model.data.ResourceAssignment; +import org.onap.ccsdk.features.model.data.dict.ResourceDefinition; +import org.onap.ccsdk.features.model.data.dict.SourcesDefinition; +import org.onap.ccsdk.features.model.service.ComponentNode; +import org.onap.ccsdk.features.model.utils.JsonUtils; +import org.onap.ccsdk.features.model.utils.ResourceAssignmentUtils; +import org.onap.ccsdk.sli.core.sli.SvcLogicContext; +import org.onap.ccsdk.sli.core.sli.SvcLogicException; +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; +import com.fasterxml.jackson.databind.node.ArrayNode; +import com.fasterxml.jackson.databind.node.JsonNodeFactory; +import com.fasterxml.jackson.databind.node.ObjectNode; + +public class DBResourceProcessor implements ComponentNode { + + private static EELFLogger logger = EELFManager.getInstance().getLogger(DBResourceProcessor.class); + private ConfigResourceService configResourceService; + private Map dictionaries; + + public DBResourceProcessor(ConfigResourceService configResourceService) { + this.configResourceService = configResourceService; + } + + @Override + public Boolean preCondition(Map inParams, SvcLogicContext ctx, Map componentContext) + throws SvcLogicException { + return Boolean.TRUE; + } + + @Override + public void preProcess(Map inParams, SvcLogicContext ctx, Map componentContext) + throws SvcLogicException { + // Auto-generated method stub + } + + @Override + public void process(Map inParams, SvcLogicContext ctx) throws SvcLogicException { + // Auto-generated method stub + } + + @SuppressWarnings("unchecked") + @Override + public void process(Map inParams, SvcLogicContext ctx, Map componentContext) + throws SvcLogicException { + try { + List batchResourceAssignment = + (List) componentContext.get(ConfigModelConstant.PROPERTY_RESOURCE_ASSIGNMENTS); + dictionaries = + (Map) componentContext.get(ConfigModelConstant.PROPERTY_DICTIONARIES); + + if (CollectionUtils.isNotEmpty(batchResourceAssignment)) { + for (ResourceAssignment resourceAssignment : batchResourceAssignment) { + processResourceAssignment(ctx, componentContext, resourceAssignment); + } + } + } catch (Exception e) { + throw new SvcLogicException(String.format("DBResourceProcessor Exception : (%s)", e), e); + } + } + + private void processResourceAssignment(SvcLogicContext ctx, Map componentContext, + ResourceAssignment resourceAssignment) throws SvcLogicException, ConfigModelException { + if (resourceAssignment != null) { + try { + validate(resourceAssignment); + + // Check if It has Input + Object value = ConfigAssignmentUtils.getContextKeyValue(ctx, resourceAssignment.getName()); + if (value != null) { + logger.info("db source template key ({}) found from input and value is ({})", + resourceAssignment.getName(), value); + ResourceAssignmentUtils.setResourceDataValue(componentContext, resourceAssignment, value); + return; + } + + ResourceDefinition resourceDefinition = dictionaries.get(resourceAssignment.getDictionaryName()); + SourcesDefinition sourceDb = resourceDefinition.getSources().get("db"); + if (StringUtils.isBlank(sourceDb.getProperties().getQuery())) { + throw new SvcLogicException("db query property is missing"); + } + + String sql = sourceDb.getProperties().getQuery(); + Map inputKeyMapping = sourceDb.getProperties().getInputKeyMapping(); + + logger.info("Db dictionary information : ({}), ({}), ({})", sql, inputKeyMapping, + sourceDb.getProperties().getOutputKeyMapping()); + + Map namedParameters = populateNamedParameter(componentContext, inputKeyMapping); + + logger.info("Parameter information : ({})", namedParameters); + List> rows = configResourceService.query(sql, namedParameters); + if (rows != null && !rows.isEmpty()) { + processDBResults(ctx, componentContext, resourceAssignment, sourceDb, rows); + } else { + logger.warn("Failed to get db result for dictionary name ({}) the query ({})", + resourceAssignment.getDictionaryName(), sql); + } + + // Check the value has populated for mandatory case + ResourceAssignmentUtils.assertTemplateKeyValueNotNull(componentContext, resourceAssignment); + } catch (Exception e) { + ResourceAssignmentUtils.setFailedResourceDataValue(componentContext, resourceAssignment, + e.getMessage()); + throw new SvcLogicException( + String.format("Failed in template key (%s) assignments : (%s)", resourceAssignment, e), e); + } + } else { + // Do Nothing + } + } + + private void validate(ResourceAssignment resourceAssignment) throws SvcLogicException { + if (resourceAssignment == null) { + throw new SvcLogicException("resource assignment is not defined"); + } + + if (StringUtils.isBlank(resourceAssignment.getName())) { + throw new SvcLogicException("resource assignment template key is not defined"); + } + + if (StringUtils.isBlank(resourceAssignment.getDictionaryName())) { + throw new SvcLogicException( + String.format("resource assignment dictionary name is not defined for template key (%s)", + resourceAssignment.getName())); + } + + if (!ConfigModelConstant.SOURCE_DB.equalsIgnoreCase(resourceAssignment.getDictionarySource())) { + throw new SvcLogicException(String.format("resource assignment source is not db, it is (%s)", + resourceAssignment.getDictionarySource())); + } + + ResourceDefinition resourceDefinition = dictionaries.get(resourceAssignment.getDictionaryName()); + if (resourceDefinition == null) { + throw new SvcLogicException(String.format("missing resource dictionary definition for name (%s) ", + resourceAssignment.getDictionaryName())); + } + + if (resourceDefinition.getSources() == null || resourceDefinition.getSources().get("db") == null) { + throw new SvcLogicException(String.format("missing resource dictionary db source definition for name (%s) ", + resourceAssignment.getDictionaryName())); + } + + SourcesDefinition sourceDb = resourceDefinition.getSources().get("db"); + if (StringUtils.isBlank(sourceDb.getProperties().getQuery())) { + throw new SvcLogicException(String.format("Failed to get request Query for dictionary (%s)", + resourceAssignment.getDictionaryName())); + } + + } + + private Map populateNamedParameter(Map componentContext, + Map inputKeyMapping) { + Map namedParameters = new HashMap<>(); + if (MapUtils.isNotEmpty(inputKeyMapping)) { + + for (Map.Entry mapping : inputKeyMapping.entrySet()) { + ResourceDefinition referenceDictionaryDefinition = dictionaries.get(mapping.getValue()); + Object expressionValue = + ResourceAssignmentUtils.getDictionaryKeyValue(componentContext, referenceDictionaryDefinition); + logger.trace("Reference dictionary key ({}), value ({})", mapping.getKey(), expressionValue); + namedParameters.put(mapping.getKey(), expressionValue); + } + } + return namedParameters; + } + + @SuppressWarnings("squid:S3776") + private void processDBResults(SvcLogicContext ctx, Map componentContext, + ResourceAssignment resourceAssignment, SourcesDefinition sourceDb, List> rows) + throws SvcLogicException, ConfigModelException { + + Map outputKeyMapping = sourceDb.getProperties().getOutputKeyMapping(); + String type = resourceAssignment.getProperty().getType(); + String entrySchema = null; + logger.info("Response processing type({})", type); + // Primitive Types + if (ValidTypes.getPrimitivePropertType().contains(type)) { + + Map row = rows.get(0); + String dbColumnName = outputKeyMapping.get(resourceAssignment.getDictionaryName()); + Object dbColumnValue = row.get(dbColumnName); + ResourceAssignmentUtils.setResourceDataValue(componentContext, resourceAssignment, dbColumnValue); + + } else if (ValidTypes.getListPropertType().contains(type)) { + // Array Types + if (resourceAssignment.getProperty().getEntrySchema() != null) { + entrySchema = resourceAssignment.getProperty().getEntrySchema().getType(); + } + + if (StringUtils.isNotBlank(entrySchema)) { + ArrayNode arrayNode = JsonNodeFactory.instance.arrayNode(); + + for (Map row : rows) { + if (ValidTypes.getPrimitivePropertType().contains(entrySchema)) { + String dbColumnName = outputKeyMapping.get(resourceAssignment.getDictionaryName()); + Object dbColumnValue = row.get(dbColumnName); + // Add Array JSON + JsonUtils.populatePrimitiveValues(dbColumnValue, entrySchema, arrayNode); + } else { + ObjectNode arrayChildNode = JsonNodeFactory.instance.objectNode(); + for (Map.Entry mapping : outputKeyMapping.entrySet()) { + Object dbColumnValue = row.get(mapping.getKey()); + String propertyTypeForDataType = + ConfigAssignmentUtils.getPropertyType(ctx, entrySchema, mapping.getKey()); + JsonUtils.populatePrimitiveValues(mapping.getKey(), dbColumnValue, propertyTypeForDataType, + arrayChildNode); + } + arrayNode.add(arrayChildNode); + } + } + // Set the List of Complex Values + ResourceAssignmentUtils.setResourceDataValue(componentContext, resourceAssignment, arrayNode); + } else { + throw new SvcLogicException(String.format("Entry schema is not defined for dictionary (%s) info", + resourceAssignment.getDictionaryName())); + } + } else { + // Complex Types + Map row = rows.get(0); + ObjectNode objectNode = JsonNodeFactory.instance.objectNode(); + for (Map.Entry mapping : outputKeyMapping.entrySet()) { + Object dbColumnValue = row.get(mapping.getKey()); + String propertyTypeForDataType = ConfigAssignmentUtils.getPropertyType(ctx, type, mapping.getKey()); + JsonUtils.populatePrimitiveValues(mapping.getKey(), dbColumnValue, propertyTypeForDataType, objectNode); + } + ResourceAssignmentUtils.setResourceDataValue(componentContext, resourceAssignment, objectNode); + } + } + + @Override + public void postProcess(Map inParams, SvcLogicContext ctx, Map componentContext) + throws SvcLogicException { + // Auto-generated method stub + } + +} diff --git a/blueprints-processor/plugin/assignment-provider/src/main/java/org/onap/ccsdk/features/assignment/processor/DefaultResourceProcessor.java b/blueprints-processor/plugin/assignment-provider/src/main/java/org/onap/ccsdk/features/assignment/processor/DefaultResourceProcessor.java new file mode 100644 index 000000000..563d5b523 --- /dev/null +++ b/blueprints-processor/plugin/assignment-provider/src/main/java/org/onap/ccsdk/features/assignment/processor/DefaultResourceProcessor.java @@ -0,0 +1,107 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2018 IBM. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.ccsdk.features.assignment.processor; + +import java.util.List; +import java.util.Map; +import org.apache.commons.lang3.StringUtils; +import org.onap.ccsdk.features.assignment.service.ConfigAssignmentUtils; +import org.onap.ccsdk.features.data.adaptor.service.ConfigResourceService; +import org.onap.ccsdk.features.model.ConfigModelConstant; +import org.onap.ccsdk.features.model.ConfigModelException; +import org.onap.ccsdk.features.model.data.ResourceAssignment; +import org.onap.ccsdk.features.model.service.ComponentNode; +import org.onap.ccsdk.features.model.utils.ResourceAssignmentUtils; +import org.onap.ccsdk.sli.core.sli.SvcLogicContext; +import org.onap.ccsdk.sli.core.sli.SvcLogicException; + +public class DefaultResourceProcessor implements ComponentNode { + + public DefaultResourceProcessor(ConfigResourceService configResourceService) {} + + @Override + public Boolean preCondition(Map inParams, SvcLogicContext ctx, Map componentContext) + throws SvcLogicException { + return Boolean.TRUE; + } + + @Override + public void preProcess(Map inParams, SvcLogicContext ctx, Map componentContext) + throws SvcLogicException { + // Auto-generated method stub + } + + @Override + public void process(Map inParams, SvcLogicContext ctx) throws SvcLogicException { + // Auto-generated method stub + } + + @SuppressWarnings("unchecked") + @Override + public void process(Map inParams, SvcLogicContext ctx, Map componentContext) + throws SvcLogicException { + try { + List batchResourceAssignment = + (List) componentContext.get(ConfigModelConstant.PROPERTY_RESOURCE_ASSIGNMENTS); + + if (batchResourceAssignment != null && !batchResourceAssignment.isEmpty()) { + for (ResourceAssignment resourceAssignment : batchResourceAssignment) { + processResourceAssignment(ctx, componentContext, resourceAssignment); + } + } + } catch (Exception e) { + throw new SvcLogicException(String.format("DefaultResourceProcessor Exception : (%s)", e), e); + } + + } + + private void processResourceAssignment(SvcLogicContext ctx, Map componentContext, + ResourceAssignment resourceAssignment) throws ConfigModelException, SvcLogicException { + if (resourceAssignment != null && StringUtils.isNotBlank(resourceAssignment.getName()) + && resourceAssignment.getProperty() != null) { + try { + // Check if It has Input + Object value = ConfigAssignmentUtils.getContextKeyValue(ctx, resourceAssignment.getName()); + if (value == null) { + value = resourceAssignment.getProperty().getDefaultValue(); + } + + // if value is null don't call setResourceDataValue to populate the value + if (value != null) { + ResourceAssignmentUtils.setResourceDataValue(componentContext, resourceAssignment, value); + } + + // Check the value has populated for mandatory case + ResourceAssignmentUtils.assertTemplateKeyValueNotNull(componentContext, resourceAssignment); + } catch (Exception e) { + ResourceAssignmentUtils.setFailedResourceDataValue(componentContext, resourceAssignment, + e.getMessage()); + throw new SvcLogicException( + String.format("Failed in template key (%s) assignments with : (%s)", resourceAssignment, e), e); + } + } + } + + @Override + public void postProcess(Map inParams, SvcLogicContext ctx, Map componentContext) + throws SvcLogicException { + // Auto-generated method stub + + } + +} diff --git a/blueprints-processor/plugin/assignment-provider/src/main/java/org/onap/ccsdk/features/assignment/processor/InputResourceProcessor.java b/blueprints-processor/plugin/assignment-provider/src/main/java/org/onap/ccsdk/features/assignment/processor/InputResourceProcessor.java new file mode 100644 index 000000000..6c73b08de --- /dev/null +++ b/blueprints-processor/plugin/assignment-provider/src/main/java/org/onap/ccsdk/features/assignment/processor/InputResourceProcessor.java @@ -0,0 +1,96 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2018 IBM. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.ccsdk.features.assignment.processor; + +import java.util.List; +import java.util.Map; +import org.apache.commons.lang3.StringUtils; +import org.onap.ccsdk.features.data.adaptor.service.ConfigResourceService; +import org.onap.ccsdk.features.model.ConfigModelConstant; +import org.onap.ccsdk.features.model.ConfigModelException; +import org.onap.ccsdk.features.model.data.ResourceAssignment; +import org.onap.ccsdk.features.model.service.ComponentNode; +import org.onap.ccsdk.features.model.utils.ResourceAssignmentUtils; +import org.onap.ccsdk.sli.core.sli.SvcLogicContext; +import org.onap.ccsdk.sli.core.sli.SvcLogicException; + +public class InputResourceProcessor implements ComponentNode { + + public InputResourceProcessor(ConfigResourceService configResourceService) {} + + @Override + public Boolean preCondition(Map inParams, SvcLogicContext ctx, Map componentContext) + throws SvcLogicException { + return Boolean.TRUE; + } + + @Override + public void preProcess(Map inParams, SvcLogicContext ctx, Map componentContext) + throws SvcLogicException { + // Auto-generated method stub + } + + @Override + public void process(Map inParams, SvcLogicContext ctx) throws SvcLogicException { + // Auto-generated method stub + } + + @SuppressWarnings("unchecked") + @Override + public void process(Map inParams, SvcLogicContext ctx, Map componentContext) + throws SvcLogicException { + try { + List batchResourceAssignment = + (List) componentContext.get(ConfigModelConstant.PROPERTY_RESOURCE_ASSIGNMENTS); + if (batchResourceAssignment != null && !batchResourceAssignment.isEmpty()) { + for (ResourceAssignment resourceAssignment : batchResourceAssignment) { + processResourceAssignment(ctx, componentContext, resourceAssignment); + } + } + } catch (Exception e) { + throw new SvcLogicException(String.format("InputResourceProcessor Exception : (%s)", e), e); + } + } + + private void processResourceAssignment(SvcLogicContext ctx, Map componentContext, + ResourceAssignment resourceAssignment) throws ConfigModelException, SvcLogicException { + try { + if (StringUtils.isNotBlank(resourceAssignment.getName())) { + String value = ctx.getAttribute(resourceAssignment.getName()); + // if value is null don't call setResourceDataValue to populate the value + if (StringUtils.isNotBlank(value)) { + ResourceAssignmentUtils.setResourceDataValue(componentContext, resourceAssignment, value); + } + } + + // Check the value has populated for mandatory case + ResourceAssignmentUtils.assertTemplateKeyValueNotNull(componentContext, resourceAssignment); + } catch (Exception e) { + ResourceAssignmentUtils.setFailedResourceDataValue(componentContext, resourceAssignment, e.getMessage()); + throw new SvcLogicException( + String.format("Failed in template key (%s) assignments with : (%s)", resourceAssignment, e), e); + } + } + + @Override + public void postProcess(Map inParams, SvcLogicContext ctx, Map componentContext) + throws SvcLogicException { + // Auto-generated method stub + } + +} diff --git a/blueprints-processor/plugin/assignment-provider/src/main/java/org/onap/ccsdk/features/assignment/processor/MdsalResourceProcessor.java b/blueprints-processor/plugin/assignment-provider/src/main/java/org/onap/ccsdk/features/assignment/processor/MdsalResourceProcessor.java new file mode 100644 index 000000000..dfc041cee --- /dev/null +++ b/blueprints-processor/plugin/assignment-provider/src/main/java/org/onap/ccsdk/features/assignment/processor/MdsalResourceProcessor.java @@ -0,0 +1,239 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2018 IBM. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.ccsdk.features.assignment.processor; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import org.apache.commons.collections.CollectionUtils; +import org.apache.commons.collections.MapUtils; +import org.apache.commons.lang3.StringUtils; +import org.onap.ccsdk.features.assignment.service.ConfigAssignmentUtils; +import org.onap.ccsdk.features.model.ConfigModelConstant; +import org.onap.ccsdk.features.model.ConfigModelException; +import org.onap.ccsdk.features.model.data.ResourceAssignment; +import org.onap.ccsdk.features.model.data.dict.ResourceDefinition; +import org.onap.ccsdk.features.model.data.dict.SourcesDefinition; +import org.onap.ccsdk.features.model.service.ComponentNode; +import org.onap.ccsdk.features.model.utils.ResourceAssignmentUtils; +import org.onap.ccsdk.features.model.utils.TransformationUtils; +import org.onap.ccsdk.features.rest.adaptor.ConfigRestAdaptorConstants; +import org.onap.ccsdk.features.rest.adaptor.service.ConfigRestAdaptorService; +import org.onap.ccsdk.sli.core.sli.SvcLogicContext; +import org.onap.ccsdk.sli.core.sli.SvcLogicException; +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; +import com.fasterxml.jackson.databind.JsonNode; + +public class MdsalResourceProcessor implements ComponentNode { + + private static EELFLogger logger = EELFManager.getInstance().getLogger(MdsalResourceProcessor.class); + private ConfigRestAdaptorService configRestAdaptorService; + private Map dictionaries; + + public MdsalResourceProcessor(ConfigRestAdaptorService configRestAdaptorService) { + this.configRestAdaptorService = configRestAdaptorService; + } + + @Override + public Boolean preCondition(Map inParams, SvcLogicContext ctx, Map componentContext) + throws SvcLogicException { + return Boolean.TRUE; + } + + @Override + public void preProcess(Map inParams, SvcLogicContext ctx, Map componentContext) + throws SvcLogicException { + // Auto-generated method stub + } + + @Override + public void process(Map inParams, SvcLogicContext ctx) throws SvcLogicException { + // Auto-generated method stub + } + + @SuppressWarnings("unchecked") + @Override + public void process(Map inParams, SvcLogicContext ctx, Map componentContext) + throws SvcLogicException { + try { + List batchResourceAssignment = + (List) componentContext.get(ConfigModelConstant.PROPERTY_RESOURCE_ASSIGNMENTS); + dictionaries = + (Map) componentContext.get(ConfigModelConstant.PROPERTY_DICTIONARIES); + + if (CollectionUtils.isNotEmpty(batchResourceAssignment)) { + for (ResourceAssignment resourceAssignment : batchResourceAssignment) { + processResourceAssignmnet(ctx, componentContext, resourceAssignment); + } + } + } catch (Exception e) { + throw new SvcLogicException(String.format("MdsalResourceProcessor Exception : (%s) ", e), e); + } + } + + private void processResourceAssignmnet(SvcLogicContext ctx, Map componentContext, + ResourceAssignment resourceAssignment) throws ConfigModelException, SvcLogicException { + + try { + // Validating Resource Assignment and Dictionary Definition data + validate(resourceAssignment); + + // Check if It has Input + Object value = ConfigAssignmentUtils.getContextKeyValue(ctx, resourceAssignment.getName()); + if (value != null) { + logger.info("mdsal source template key ({}) found from input and value is ({})", + resourceAssignment.getName(), value); + ResourceAssignmentUtils.setResourceDataValue(componentContext, resourceAssignment, value); + return; + } + + ResourceDefinition resourceDefinition = dictionaries.get(resourceAssignment.getDictionaryName()); + SourcesDefinition sourceMdsal = resourceDefinition.getSources().get("mdsal"); + String urlPath = sourceMdsal.getProperties().getUrlPath(); + String path = sourceMdsal.getProperties().getPath(); + Map inputKeyMapping = sourceMdsal.getProperties().getInputKeyMapping(); + Map outputKeyMapping = sourceMdsal.getProperties().getOutputKeyMapping(); + + logger.info( + "mdsal dictionary information : urlpath ({}), path({}), inputKeyMapping ({}), outputKeyMapping ({})", + urlPath, path, inputKeyMapping, outputKeyMapping); + + // Resolving url Variables + Map urlVariables = populateUrlVariables(inputKeyMapping, componentContext); + for (Map.Entry entry : urlVariables.entrySet()) { + urlPath = urlPath.replaceAll("\\$" + entry.getKey(), entry.getValue().toString()); + } + + String restResponse = fetchResourceFromMDSAL(urlPath); + // if restResponse is null don't call processMdsalResults to populate the value + if (StringUtils.isNotBlank(restResponse)) { + // Processing MDSAL Response + processMdsalResults(ctx, componentContext, resourceAssignment, sourceMdsal, restResponse); + } else { + logger.warn("Coudn't get proper mdsal Response content ({}) for Resource Name ({}) for URI ({})", + restResponse, resourceAssignment.getDictionaryName(), urlPath); + } + + // Check the value has populated for mandatory case + ResourceAssignmentUtils.assertTemplateKeyValueNotNull(componentContext, resourceAssignment); + } catch (Exception e) { + ResourceAssignmentUtils.setFailedResourceDataValue(componentContext, resourceAssignment, e.getMessage()); + throw new SvcLogicException( + String.format("Failed in assignments for (%s) with (%s)", resourceAssignment, e), e); + } + } + + private String fetchResourceFromMDSAL(String urlPath) { + String response = null; + try { + response = configRestAdaptorService.getResource(ConfigRestAdaptorConstants.SELECTOR_RESTCONF, urlPath, + String.class); + } catch (Exception e) { + logger.warn("Fetching MDSAL data for URL ({}) failed with Error ({})", urlPath, e); + } + return response; + } + + private void validate(ResourceAssignment resourceAssignment) throws SvcLogicException { + if (resourceAssignment == null) { + throw new SvcLogicException("resource assignment is not defined"); + } + + if (StringUtils.isBlank(resourceAssignment.getName())) { + throw new SvcLogicException("resource assignment template key is not defined"); + } + + if (StringUtils.isBlank(resourceAssignment.getDictionaryName())) { + throw new SvcLogicException( + String.format("resource assignment dictionary name is not defined for template key (%s)", + resourceAssignment.getName())); + } + + if (!ConfigModelConstant.SOURCE_MDSAL.equalsIgnoreCase(resourceAssignment.getDictionarySource())) { + throw new SvcLogicException(String.format("resource assignment source is not mdsal, it is (%s)", + resourceAssignment.getDictionarySource())); + } + + ResourceDefinition resourceDefinition = dictionaries.get(resourceAssignment.getDictionaryName()); + if (resourceDefinition == null) { + throw new SvcLogicException(String.format("missing resource dictionary definition for name (%s) ", + resourceAssignment.getDictionaryName())); + } + + if (StringUtils.isBlank(resourceDefinition.getProperty().getType())) { + throw new SvcLogicException(String.format(String.format("Failed to get dictionary (%s) data type info.", + resourceAssignment.getDictionaryName()))); + } + + if (resourceDefinition.getSources() == null || resourceDefinition.getSources().get("mdsal") == null) { + throw new SvcLogicException( + String.format("missing resource dictionary mdsal source definition for name (%s) ", + resourceAssignment.getDictionaryName())); + } + + SourcesDefinition sourceMdsal = resourceDefinition.getSources().get("mdsal"); + if (StringUtils.isBlank(sourceMdsal.getProperties().getUrlPath())) { + throw new SvcLogicException(String.format("Failed to get request URL Path for dictionary (%s)", + resourceAssignment.getDictionaryName())); + } + + if (StringUtils.isBlank(sourceMdsal.getProperties().getPath())) { + throw new SvcLogicException(String.format("Failed to get request Path for dictionary (%s)", + resourceAssignment.getDictionaryName())); + } + } + + private Map populateUrlVariables(Map inputKeyMapping, + Map componentContext) { + Map urlVariables = new HashMap<>(); + if (MapUtils.isNotEmpty(inputKeyMapping)) { + + for (Map.Entry mapping : inputKeyMapping.entrySet()) { + ResourceDefinition referenceDictionaryDefinition = dictionaries.get(mapping.getValue()); + Object expressionValue = + ResourceAssignmentUtils.getDictionaryKeyValue(componentContext, referenceDictionaryDefinition); + logger.trace("Reference dictionary key ({}), value ({})", mapping.getKey(), expressionValue); + urlVariables.put(mapping.getKey(), expressionValue); + } + } + return urlVariables; + } + + private void processMdsalResults(SvcLogicContext ctx, Map componentContext, + ResourceAssignment resourceAssignment, SourcesDefinition sourceMdsal, String restResponse) + throws SvcLogicException, ConfigModelException { + + Map outputKeyMapping = sourceMdsal.getProperties().getOutputKeyMapping(); + JsonNode responseNode = TransformationUtils.getJsonNodeForString(restResponse); + if (StringUtils.isNotBlank(sourceMdsal.getProperties().getPath())) { + responseNode = responseNode.at(sourceMdsal.getProperties().getPath()); + } + if (responseNode != null) { + ConfigAssignmentUtils.populateValueForOutputMapping(ctx, componentContext, resourceAssignment, + outputKeyMapping, responseNode); + } + } + + @Override + public void postProcess(Map inParams, SvcLogicContext ctx, Map componentContext) + throws SvcLogicException { + // Do Nothing + } + +} diff --git a/blueprints-processor/plugin/assignment-provider/src/main/java/org/onap/ccsdk/features/assignment/processor/ProcessorFactory.java b/blueprints-processor/plugin/assignment-provider/src/main/java/org/onap/ccsdk/features/assignment/processor/ProcessorFactory.java new file mode 100644 index 000000000..bb620a1a3 --- /dev/null +++ b/blueprints-processor/plugin/assignment-provider/src/main/java/org/onap/ccsdk/features/assignment/processor/ProcessorFactory.java @@ -0,0 +1,52 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2018 IBM. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.ccsdk.features.assignment.processor; + +import org.onap.ccsdk.features.data.adaptor.service.ConfigResourceService; +import org.onap.ccsdk.features.model.ConfigModelConstant; +import org.onap.ccsdk.features.model.service.ComponentNode; +import org.onap.ccsdk.features.model.service.ComponentNodeService; +import org.onap.ccsdk.features.rest.adaptor.service.ConfigRestAdaptorService; + +public class ProcessorFactory { + + private ConfigResourceService configResourceService; + private ConfigRestAdaptorService configRestAdaptorService; + private ComponentNodeService componentNodeService; + + public ProcessorFactory(ConfigResourceService configResourceService, + ConfigRestAdaptorService configRestAdaptorService, ComponentNodeService componentNodeService) { + this.componentNodeService = componentNodeService; + this.configResourceService = configResourceService; + this.configRestAdaptorService = configRestAdaptorService; + } + + public ComponentNode getInstance(String source) { + + if (ConfigModelConstant.SOURCE_DEFAULT.equalsIgnoreCase(source)) { + return new DefaultResourceProcessor(configResourceService); + } else if (ConfigModelConstant.SOURCE_DB.equalsIgnoreCase(source)) { + return new DBResourceProcessor(configResourceService); + } else if (ConfigModelConstant.SOURCE_MDSAL.equalsIgnoreCase(source)) { + return new MdsalResourceProcessor(configRestAdaptorService); + } + // Default + return new InputResourceProcessor(configResourceService); + } + +} diff --git a/blueprints-processor/plugin/assignment-provider/src/main/java/org/onap/ccsdk/features/assignment/processor/ResourceAssignmentProcessor.java b/blueprints-processor/plugin/assignment-provider/src/main/java/org/onap/ccsdk/features/assignment/processor/ResourceAssignmentProcessor.java new file mode 100644 index 000000000..3ee49f085 --- /dev/null +++ b/blueprints-processor/plugin/assignment-provider/src/main/java/org/onap/ccsdk/features/assignment/processor/ResourceAssignmentProcessor.java @@ -0,0 +1,120 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2018 IBM. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.ccsdk.features.assignment.processor; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import org.apache.commons.collections.CollectionUtils; +import org.onap.ccsdk.features.model.data.ResourceAssignment; +import org.onap.ccsdk.features.model.utils.TopologicalSortingUtils; +import org.onap.ccsdk.sli.core.sli.SvcLogicContext; +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; + +public class ResourceAssignmentProcessor { + private static EELFLogger logger = EELFManager.getInstance().getLogger(ResourceAssignmentProcessor.class); + + private List assignments; + private Map resourceAssignmentMap; + + @SuppressWarnings("squid:S1172") + public ResourceAssignmentProcessor(List assignments, SvcLogicContext ctx) { + this.assignments = assignments; + this.resourceAssignmentMap = new HashMap<>(); + } + + @SuppressWarnings("squid:S3776") + public List> process() { + List> sequenceBatchResourceAssignment = new ArrayList<>(); + if (this.assignments != null) { + logger.info("Assignments ({})", this.assignments); + this.assignments.forEach(resourceMapping -> { + if (resourceMapping != null) { + logger.trace("Processing Key ({})", resourceMapping.getName()); + resourceAssignmentMap.put(resourceMapping.getName(), resourceMapping); + } + }); + + TopologicalSortingUtils topologySorting = new TopologicalSortingUtils<>(); + this.resourceAssignmentMap.forEach((mappingKey, mapping) -> { + if (mapping != null) { + if (mapping.getDependencies() != null && !mapping.getDependencies().isEmpty()) { + for (String dependency : mapping.getDependencies()) { + topologySorting.add(resourceAssignmentMap.get(dependency), mapping); + } + } else { + topologySorting.add(null, mapping); + } + } + }); + + List sequencedResourceAssignments = topologySorting.topSort(); + logger.info("Sorted Sequenced Assignments ({})", sequencedResourceAssignments); + + List batchResourceAssignment = null; + List batchAssignmentName = null; + for (int i = 0; i < sequencedResourceAssignments.size(); i++) { + ResourceAssignment resourceAssignment = sequencedResourceAssignments.get(i); + ResourceAssignment previousResourceAssignment = null; + + if (i > 0) { + previousResourceAssignment = sequencedResourceAssignments.get(i - 1); + } + if (resourceAssignment != null) { + + boolean dependencyPresence = false; + if (batchAssignmentName != null && resourceAssignment.getDependencies() != null) { + dependencyPresence = + CollectionUtils.containsAny(batchAssignmentName, resourceAssignment.getDependencies()); + } + + logger.trace("({}) -> Checking ({}), with ({}), result ({})", resourceAssignment.getName(), + batchAssignmentName, resourceAssignment.getDependencies(), dependencyPresence); + + if (previousResourceAssignment != null && resourceAssignment.getDictionarySource() != null + && resourceAssignment.getDictionarySource() + .equalsIgnoreCase(previousResourceAssignment.getDictionarySource()) + && !dependencyPresence) { + batchResourceAssignment.add(resourceAssignment); + batchAssignmentName.add(resourceAssignment.getName()); + } else { + if (batchResourceAssignment != null) { + sequenceBatchResourceAssignment.add(batchResourceAssignment); + logger.trace("Created old Set ({})", batchAssignmentName); + } + batchResourceAssignment = new ArrayList<>(); + batchResourceAssignment.add(resourceAssignment); + + batchAssignmentName = new ArrayList<>(); + batchAssignmentName.add(resourceAssignment.getName()); + } + } + + if (i == (sequencedResourceAssignments.size() - 1)) { + logger.trace("Created old Set ({})", batchAssignmentName); + sequenceBatchResourceAssignment.add(batchResourceAssignment); + } + } + logger.info("Batched Sequence : ({})", sequenceBatchResourceAssignment); + } + return sequenceBatchResourceAssignment; + } + +} diff --git a/blueprints-processor/plugin/assignment-provider/src/main/java/org/onap/ccsdk/features/assignment/service/ConfigAssignmentNode.java b/blueprints-processor/plugin/assignment-provider/src/main/java/org/onap/ccsdk/features/assignment/service/ConfigAssignmentNode.java new file mode 100644 index 000000000..aaeadcabd --- /dev/null +++ b/blueprints-processor/plugin/assignment-provider/src/main/java/org/onap/ccsdk/features/assignment/service/ConfigAssignmentNode.java @@ -0,0 +1,231 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2018 IBM. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.ccsdk.features.assignment.service; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import org.apache.commons.collections.MapUtils; +import org.apache.commons.lang3.StringUtils; +import org.onap.ccsdk.features.assignment.ConfigAssignmentConstants; +import org.onap.ccsdk.features.assignment.data.ResourceAssignmentData; +import org.onap.ccsdk.features.data.adaptor.service.ConfigResourceService; +import org.onap.ccsdk.features.generator.service.ConfigGeneratorService; +import org.onap.ccsdk.features.model.ConfigModelConstant; +import org.onap.ccsdk.features.model.service.ComponentNode; +import org.onap.ccsdk.features.model.service.ComponentNodeService; +import org.onap.ccsdk.features.model.service.ConfigModelService; +import org.onap.ccsdk.features.model.utils.TransformationUtils; +import org.onap.ccsdk.features.rest.adaptor.service.ConfigRestAdaptorService; +import org.onap.ccsdk.sli.core.sli.SvcLogicContext; +import org.onap.ccsdk.sli.core.sli.SvcLogicException; +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; + +public class ConfigAssignmentNode implements ComponentNode { + private static EELFLogger logger = EELFManager.getInstance().getLogger(ConfigAssignmentNode.class); + + private ComponentNodeService componentNodeService; + private ConfigResourceService configResourceService; + private ConfigModelService configModelService; + private ConfigRestAdaptorService configRestAdaptorService; + private ConfigGeneratorService configGeneratorService; + + public ConfigAssignmentNode(ConfigResourceService configResourceService, + ConfigRestAdaptorService configRestAdaptorService, ConfigModelService configModelService, + ComponentNodeService componentNodeService, ConfigGeneratorService configGeneratorService) { + logger.info("{} Constrctor Initiated", "ConfigAssignmentNode"); + this.componentNodeService = componentNodeService; + this.configResourceService = configResourceService; + this.configModelService = configModelService; + this.configRestAdaptorService = configRestAdaptorService; + this.configGeneratorService = configGeneratorService; + } + + @Override + public Boolean preCondition(Map inParams, SvcLogicContext ctx, Map componentContext) + throws SvcLogicException { + return Boolean.TRUE; + } + + @Override + public void preProcess(Map inParams, SvcLogicContext ctx, Map componentContext) + throws SvcLogicException { + // Auto-generated method stub + } + + /** + * This method is used to resolve the resources defined in the template. Generic Resource API DG + * calls this execute node. + * + * @param inParams This is the input parameter to process this node + * + *
+    request-id                  (string):           Tracking Id 
+    resource-type               (string):           Resource Type ( ex : vnf-type) 
+    resource-id                 (string):           Resource Id 
+    service-template-name       (string):           Blueprint Name 
+    service-template-version    (string):           Blueprint Version 
+    action-name                 (string): 
+    template-names              (List of string):   Template Names / Artifact Node Names to resolve. ["template1", "template2"] 
+    input-data                  (string):           Input Data in JSON String, for the substitution in the Template. 
+    prifix                      (string):           Return Value selector
+     *        
+ * + * @param ctx This is the service logger context, Output will be stored ( + * .resource-assignment-params. : Output Data in JSON String. + * .status .error-message ) + * @throws SvcLogicException On processing error. + */ + + @Override + public void process(Map inParams, SvcLogicContext ctx) throws SvcLogicException { + + final String responsePrefix = StringUtils.isNotBlank(inParams.get(ConfigModelConstant.PROPERTY_SELECTOR)) + ? (inParams.get(ConfigModelConstant.PROPERTY_SELECTOR) + ".") + : ""; + try { + + ResourceAssignmentData resourceAssignmentData = populateResourceData(inParams); + resourceAssignmentData.setSvcLogicContext(ctx); + Map componentContext = new HashMap<>(); + resourceAssignmentData.setContext(componentContext); + resourceAssignmentData.setReloadModel(true); + + ConfigAssignmentProcessService configAssignmentProcessService = + new ConfigAssignmentProcessService(configResourceService, configRestAdaptorService, + configModelService, componentNodeService, configGeneratorService); + configAssignmentProcessService.resolveResources(resourceAssignmentData); + + if (MapUtils.isNotEmpty(resourceAssignmentData.getTemplatesMashedContents())) { + resourceAssignmentData.getTemplatesMashedContents().forEach((templateName, previewContent) -> { + logger.debug("For Template name : ({}),\n Preview Content is : ({})", templateName, previewContent); + ctx.setAttribute( + responsePrefix + ConfigAssignmentConstants.OUTPUT_PARAM_MASHED_DATA + "." + templateName, + previewContent); + }); + } + ctx.setAttribute(responsePrefix + ConfigAssignmentConstants.OUTPUT_PARAM_STATUS, + ConfigAssignmentConstants.OUTPUT_STATUS_SUCCESS); + } catch (Exception e) { + ctx.setAttribute(responsePrefix + ConfigAssignmentConstants.OUTPUT_PARAM_STATUS, + ConfigAssignmentConstants.OUTPUT_STATUS_FAILURE); + ctx.setAttribute(responsePrefix + ConfigAssignmentConstants.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage()); + throw new SvcLogicException(e.getMessage(), e); + } + } + + @Override + public void process(Map inParams, SvcLogicContext ctx, Map componentContext) + throws SvcLogicException { + + final String responsePrefix = StringUtils.isNotBlank(inParams.get(ConfigModelConstant.PROPERTY_SELECTOR)) + ? (inParams.get(ConfigModelConstant.PROPERTY_SELECTOR) + ".") + : ""; + try { + + ResourceAssignmentData resourceAssignmentData = populateResourceData(inParams); + resourceAssignmentData.setSvcLogicContext(ctx); + resourceAssignmentData.setContext(componentContext); + resourceAssignmentData.setReloadModel(false); + + ConfigAssignmentProcessService configAssignmentProcessService = + new ConfigAssignmentProcessService(configResourceService, configRestAdaptorService, + configModelService, componentNodeService, configGeneratorService); + configAssignmentProcessService.resolveResources(resourceAssignmentData); + ctx.setAttribute(responsePrefix + ConfigAssignmentConstants.OUTPUT_PARAM_STATUS, + ConfigAssignmentConstants.OUTPUT_STATUS_SUCCESS); + + } catch (Exception e) { + ctx.setAttribute(responsePrefix + ConfigAssignmentConstants.OUTPUT_PARAM_STATUS, + ConfigAssignmentConstants.OUTPUT_STATUS_FAILURE); + ctx.setAttribute(responsePrefix + ConfigAssignmentConstants.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage()); + throw new SvcLogicException(e.getMessage(), e); + } + } + + @Override + public void postProcess(Map inParams, SvcLogicContext ctx, Map componentContext) + throws SvcLogicException { + // Do Nothing + } + + private ResourceAssignmentData populateResourceData(Map inParams) throws SvcLogicException { + validateInputParams(inParams); + + String requestId = inParams.get(ConfigAssignmentConstants.INPUT_PARAM_REQUEST_ID); + String resourceId = inParams.get(ConfigAssignmentConstants.INPUT_PARAM_RESOURCE_ID); + String resourceType = inParams.get(ConfigAssignmentConstants.INPUT_PARAM_RESOURCE_TYPE); + String serviceTemplateName = inParams.get(ConfigModelConstant.SERVICE_TEMPLATE_KEY_ARTIFACT_NAME); + String serviceTemplateVersion = inParams.get(ConfigModelConstant.SERVICE_TEMPLATE_KEY_ARTIFACT_VERSION); + String actionName = inParams.get(ConfigModelConstant.PROPERTY_ACTION_NAME); + String inputData = inParams.get(ConfigAssignmentConstants.INPUT_PARAM_INPUT_DATA); + + String templateNamesStr = inParams.get(ConfigAssignmentConstants.INPUT_PARAM_TEMPLATE_NAMES); + List templateNames = TransformationUtils.getListfromJson(templateNamesStr, String.class); + + ResourceAssignmentData resourceAssignmentData = new ResourceAssignmentData(); + resourceAssignmentData.setRequestId(requestId); + resourceAssignmentData.setResourceId(resourceId); + resourceAssignmentData.setResourceType(resourceType); + resourceAssignmentData.setServiceTemplateName(serviceTemplateName); + resourceAssignmentData.setServiceTemplateVersion(serviceTemplateVersion); + resourceAssignmentData.setActionName(actionName); + resourceAssignmentData.setInputData(inputData); + resourceAssignmentData.setTemplateNames(templateNames); + + return resourceAssignmentData; + } + + private void validateInputParams(Map inParams) throws SvcLogicException { + if (inParams == null) { + throw new SvcLogicException("Input parameters missing"); + } + + String requestId = inParams.get(ConfigAssignmentConstants.INPUT_PARAM_REQUEST_ID); + if (StringUtils.isBlank(requestId)) { + throw new SvcLogicException("Request id parameters missing"); + } + String resourceId = inParams.get(ConfigAssignmentConstants.INPUT_PARAM_RESOURCE_ID); + if (StringUtils.isBlank(resourceId)) { + throw new SvcLogicException("Resource id parameter is missing"); + } + String resourceType = inParams.get(ConfigAssignmentConstants.INPUT_PARAM_RESOURCE_TYPE); + if (StringUtils.isBlank(resourceType)) { + throw new SvcLogicException("Resource type parameter is missing"); + } + String recipeName = inParams.get(ConfigAssignmentConstants.INPUT_PARAM_ACTION_NAME); + if (StringUtils.isBlank(recipeName)) { + throw new SvcLogicException("Action name is parameter is missing"); + } + String templateNames = inParams.get(ConfigAssignmentConstants.INPUT_PARAM_TEMPLATE_NAMES); + if (StringUtils.isBlank(templateNames)) { + throw new SvcLogicException("Template names parameter missing"); + } + String serviceTemplateName = inParams.get(ConfigModelConstant.SERVICE_TEMPLATE_KEY_ARTIFACT_NAME); + if (StringUtils.isBlank(serviceTemplateName)) { + throw new SvcLogicException("Service Template name parameter missing"); + } + String serviceTemplateVersion = inParams.get(ConfigModelConstant.SERVICE_TEMPLATE_KEY_ARTIFACT_VERSION); + if (StringUtils.isBlank(serviceTemplateVersion)) { + throw new SvcLogicException("Service Template version parameter missing"); + } + + } + +} diff --git a/blueprints-processor/plugin/assignment-provider/src/main/java/org/onap/ccsdk/features/assignment/service/ConfigAssignmentPersistService.java b/blueprints-processor/plugin/assignment-provider/src/main/java/org/onap/ccsdk/features/assignment/service/ConfigAssignmentPersistService.java new file mode 100644 index 000000000..c4083f86d --- /dev/null +++ b/blueprints-processor/plugin/assignment-provider/src/main/java/org/onap/ccsdk/features/assignment/service/ConfigAssignmentPersistService.java @@ -0,0 +1,123 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2018 IBM. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.ccsdk.features.assignment.service; + +import java.util.List; +import org.apache.commons.collections.CollectionUtils; +import org.apache.commons.lang3.StringUtils; +import org.onap.ccsdk.features.data.adaptor.DataAdaptorConstants; +import org.onap.ccsdk.features.data.adaptor.domain.ConfigResource; +import org.onap.ccsdk.features.data.adaptor.domain.ResourceAssignmentData; +import org.onap.ccsdk.features.data.adaptor.domain.TransactionLog; +import org.onap.ccsdk.features.data.adaptor.service.ConfigResourceService; +import org.onap.ccsdk.features.model.ConfigModelConstant; +import org.onap.ccsdk.features.model.data.ResourceAssignment; +import org.onap.ccsdk.features.model.utils.ResourceAssignmentUtils; +import org.onap.ccsdk.features.model.utils.TransformationUtils; +import org.onap.ccsdk.sli.core.sli.SvcLogicException; +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; + +public class ConfigAssignmentPersistService { + + private static EELFLogger logger = EELFManager.getInstance().getLogger(ConfigAssignmentPersistService.class); + + private ConfigResourceService configResourceService; + + public ConfigAssignmentPersistService(ConfigResourceService configResourceService) { + this.configResourceService = configResourceService; + } + + public void saveResourceMapping(org.onap.ccsdk.features.assignment.data.ResourceAssignmentData resourceAssignmentData, + String templateName, List resourceAssignments) throws SvcLogicException { + try { + + if (resourceAssignmentData == null) { + throw new SvcLogicException("Resource assignment data is missing"); + } + + if (StringUtils.isBlank(resourceAssignmentData.getRequestId())) { + logger.warn("Request Id ({}) is missing, may be getting request for resource update.", + resourceAssignmentData.getRequestId()); + } + + if (StringUtils.isBlank(resourceAssignmentData.getResourceId())) { + throw new SvcLogicException("Resource Id is missing"); + } + + if (StringUtils.isBlank(resourceAssignmentData.getResourceType())) { + throw new SvcLogicException("Resource type is missing"); + } + + if (StringUtils.isBlank(resourceAssignmentData.getActionName())) { + throw new SvcLogicException("Action name is missing"); + } + + if (StringUtils.isBlank(templateName)) { + throw new SvcLogicException("template name is missing"); + } + + StringBuilder builder = new StringBuilder(); + builder.append("Resource Assignment for Template Name :"); + builder.append(templateName); + builder.append("\n"); + builder.append(TransformationUtils.getJson(resourceAssignments, true)); + + configResourceService.save(new TransactionLog(resourceAssignmentData.getRequestId(), + DataAdaptorConstants.LOG_MESSAGE_TYPE_LOG, builder.toString())); + + // Resource Data should be Regenerated based on the new Updates + String resourceData = ResourceAssignmentUtils.generateResourceDataForAssignments(resourceAssignments); + + List resourceAssignmentDataList = + ConfigAssignmentUtils.convertResoureAssignmentList(resourceAssignments); + + ConfigResource configResource = new ConfigResource(); + configResource.setRequestId(resourceAssignmentData.getRequestId()); + configResource.setServiceTemplateName(resourceAssignmentData.getServiceTemplateName()); + configResource.setServiceTemplateVersion(resourceAssignmentData.getServiceTemplateVersion()); + configResource.setRecipeName(resourceAssignmentData.getActionName()); + configResource.setResourceId(resourceAssignmentData.getResourceId()); + configResource.setResourceType(resourceAssignmentData.getResourceType()); + configResource.setResourceData(resourceData); + configResource.setTemplateName(templateName); + configResource.setStatus(ConfigModelConstant.STATUS_SUCCESS); + configResource.setUpdatedBy(ConfigModelConstant.USER_SYSTEM); + + if (CollectionUtils.isNotEmpty(resourceAssignmentDataList)) { + configResource.setResourceAssignments(resourceAssignmentDataList); + } + configResource = configResourceService.saveConfigResource(configResource); + logger.info("Resource data saved successfully for the template ({}) with resource id ({})", templateName, + configResource.getResourceId()); + + builder = new StringBuilder(); + builder.append("Resource Data Template Name :"); + builder.append(templateName); + builder.append("\n"); + builder.append(resourceData); + configResourceService.save(new TransactionLog(resourceAssignmentData.getRequestId(), + DataAdaptorConstants.LOG_MESSAGE_TYPE_LOG, builder.toString())); + + } catch (Exception e) { + throw new SvcLogicException("ConfigAssignmentPersistService : " + e.getMessage(), e); + } + + } + +} diff --git a/blueprints-processor/plugin/assignment-provider/src/main/java/org/onap/ccsdk/features/assignment/service/ConfigAssignmentProcessService.java b/blueprints-processor/plugin/assignment-provider/src/main/java/org/onap/ccsdk/features/assignment/service/ConfigAssignmentProcessService.java new file mode 100644 index 000000000..61c035960 --- /dev/null +++ b/blueprints-processor/plugin/assignment-provider/src/main/java/org/onap/ccsdk/features/assignment/service/ConfigAssignmentProcessService.java @@ -0,0 +1,238 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2018 IBM. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.ccsdk.features.assignment.service; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import org.apache.commons.collections.CollectionUtils; +import org.apache.commons.lang3.StringUtils; +import org.onap.ccsdk.features.assignment.ConfigAssignmentConstants; +import org.onap.ccsdk.features.assignment.data.ResourceAssignmentData; +import org.onap.ccsdk.features.assignment.processor.ProcessorFactory; +import org.onap.ccsdk.features.assignment.processor.ResourceAssignmentProcessor; +import org.onap.ccsdk.features.data.adaptor.service.ConfigResourceService; +import org.onap.ccsdk.features.generator.service.ConfigGeneratorService; +import org.onap.ccsdk.features.model.ConfigModelConstant; +import org.onap.ccsdk.features.model.data.ResourceAssignment; +import org.onap.ccsdk.features.model.data.dict.ResourceDefinition; +import org.onap.ccsdk.features.model.service.ComponentNode; +import org.onap.ccsdk.features.model.service.ComponentNodeService; +import org.onap.ccsdk.features.model.service.ConfigModelService; +import org.onap.ccsdk.features.model.utils.ResourceAssignmentUtils; +import org.onap.ccsdk.features.model.utils.TransformationUtils; +import org.onap.ccsdk.features.rest.adaptor.service.ConfigRestAdaptorService; +import org.onap.ccsdk.sli.core.sli.SvcLogicContext; +import org.onap.ccsdk.sli.core.sli.SvcLogicException; +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; + +public class ConfigAssignmentProcessService { + + private static EELFLogger logger = EELFManager.getInstance().getLogger(ConfigAssignmentProcessService.class); + + private ComponentNodeService componentNodeService; + private ConfigResourceService configResourceService; + private ConfigModelService configModelService; + private ConfigRestAdaptorService configRestAdaptorService; + private ConfigGeneratorService configGeneratorService; + + public ConfigAssignmentProcessService(ConfigResourceService configResourceService, + ConfigRestAdaptorService configRestAdaptorService, ConfigModelService configModelService, + ComponentNodeService componentNodeService, ConfigGeneratorService configGeneratorService) { + this.componentNodeService = componentNodeService; + this.configResourceService = configResourceService; + this.configModelService = configModelService; + this.configRestAdaptorService = configRestAdaptorService; + this.configGeneratorService = configGeneratorService; + } + + @SuppressWarnings("squid:S1141") + public void resolveResources(ResourceAssignmentData resourceAssignmentData) throws SvcLogicException { + try { + validateInputParams(resourceAssignmentData); + + String serviceTemplateName = resourceAssignmentData.getServiceTemplateName(); + String serviceTemplateVersion = resourceAssignmentData.getServiceTemplateVersion(); + String actionName = resourceAssignmentData.getActionName(); + String inputData = resourceAssignmentData.getInputData(); + SvcLogicContext svcLogicContext = resourceAssignmentData.getSvcLogicContext(); + List templateNames = resourceAssignmentData.getTemplateNames(); + + if (resourceAssignmentData.isReloadModel()) { + Map context = new HashMap<>(); + context.put(ConfigModelConstant.PROPERTY_ACTION_NAME, actionName); + context = configModelService.prepareContext(context, inputData, serviceTemplateName, + serviceTemplateVersion); + context.forEach((key, value) -> svcLogicContext.setAttribute(key, value)); + logger.info("List of Resources provided in input: {}", svcLogicContext.toProperties()); + } + + Map componentContext = resourceAssignmentData.getContext(); + + if (CollectionUtils.isNotEmpty(templateNames)) { + // Get the Resource Assignments for templates and Validate the mappings + ResourceModelService resourceModelService = new ResourceModelService(configModelService); + + // Get the Resource Assignment + Map> templatesResourceAssignments = + resourceModelService.getTemplatesResourceAssignments(svcLogicContext, templateNames); + + // Get the Template Contents + Map templatesContents = + resourceModelService.getTemplatesContents(svcLogicContext, templateNames); + + // Process each template + for (String templateName : templateNames) { + List resourceAssignments = templatesResourceAssignments.get(templateName); + String templateContent = templatesContents.get(templateName); + if (resourceAssignments != null) { + String templateData = null; + try { + // Populate the Dictionary + ResourceDictionaryService resourceDictionaryService = + new ResourceDictionaryService(configRestAdaptorService); + Map dictionaries = + resourceDictionaryService.getDataDictionaryDefinitions(resourceAssignments); + + processResourceAssignments(resourceAssignmentData, svcLogicContext, componentContext, + templateName, resourceAssignments, dictionaries); + + logger.info("decrypting config data for templateName {}", templateName); + templateData = + ResourceAssignmentUtils.generateResourceDataForAssignments(resourceAssignments); + } finally { + saveResourceMapping(resourceAssignmentData, templateName, resourceAssignments); + } + + logger.info("generating config preview for templateName {}", templateName); + ConfigPreviewService configPreviewService = new ConfigPreviewService(configResourceService, + configModelService, configGeneratorService); + String mashedData = configPreviewService.generatePreview(templateContent, templateData); + resourceAssignmentData.getTemplatesMashedContents().put(templateName, mashedData); + resourceAssignmentData.getTemplatesData().put(templateName, templateData); + + } else { + // Do nothing for Mapping not found + logger.warn("No resource Assignment mappings to resolve for templateName {}", templateName); + } + } + } + + } catch (Exception e) { + throw new SvcLogicException(e.getMessage(), e); + } + } + + private void processResourceAssignments(ResourceAssignmentData resourceAssignmentData, SvcLogicContext ctx, + Map componentContext, String templateName, List resourceAssignments, + Map dictionaries) throws SvcLogicException { + + String recipeName = resourceAssignmentData.getActionName(); + + ResourceAssignmentProcessor resourceAssignmentProcessor = + new ResourceAssignmentProcessor(resourceAssignments, ctx); + List> sequenceBatchResourceAssignment = resourceAssignmentProcessor.process(); + + logger.debug("Resource dictionary Info ({})", dictionaries); + + if (sequenceBatchResourceAssignment != null) { + componentContext.put(ConfigModelConstant.PROPERTY_ACTION_NAME, recipeName); + componentContext.put(ConfigModelConstant.PROPERTY_TEMPLATE_NAME, templateName); + componentContext.put(ConfigModelConstant.PROPERTY_DICTIONARIES, dictionaries); + for (List batchResourceAssignment : sequenceBatchResourceAssignment) { + + processBatchResourceAssignments(resourceAssignmentData, ctx, componentContext, batchResourceAssignment); + + logger.debug("Batch Resource data status ({})", TransformationUtils.getJson(batchResourceAssignment)); + } + } + } + + private void processBatchResourceAssignments(ResourceAssignmentData resourceAssignmentData, SvcLogicContext ctx, + Map componentContext, List batchResourceAssignment) + throws SvcLogicException { + + if (CollectionUtils.isNotEmpty(batchResourceAssignment)) { + + ResourceAssignment batchFirstResourceAssignment = batchResourceAssignment.get(0); + if (batchFirstResourceAssignment != null + && StringUtils.isNotBlank(batchFirstResourceAssignment.getDictionarySource())) { + String source = batchFirstResourceAssignment.getDictionarySource(); + // Processing their Source + logger.info("Processing source ({}) with batch ({}) ", source, batchResourceAssignment); + componentContext.put(ConfigModelConstant.PROPERTY_RESOURCE_ASSIGNMENTS, batchResourceAssignment); + + ProcessorFactory factory = + new ProcessorFactory(configResourceService, configRestAdaptorService, componentNodeService); + + ComponentNode processor = factory.getInstance(source); + + Map inParams = new HashMap<>(); + inParams.put(ConfigAssignmentConstants.INPUT_PARAM_REQUEST_ID, resourceAssignmentData.getRequestId()); + inParams.put(ConfigAssignmentConstants.INPUT_PARAM_RESOURCE_ID, resourceAssignmentData.getResourceId()); + inParams.put(ConfigAssignmentConstants.INPUT_PARAM_RESOURCE_TYPE, + resourceAssignmentData.getResourceType()); + inParams.put(ConfigAssignmentConstants.INPUT_PARAM_ACTION_NAME, resourceAssignmentData.getActionName()); + inParams.put(ConfigAssignmentConstants.INPUT_PARAM_TEMPLATE_NAMES, + resourceAssignmentData.getTemplateNames().toString()); + processor.process(inParams, ctx, componentContext); + } + } + } + + private void saveResourceMapping(ResourceAssignmentData resourceAssignmentData, String templateName, + List resourceAssignments) throws SvcLogicException { + if (resourceAssignmentData != null && StringUtils.isNotBlank(templateName)) { + + ConfigAssignmentPersistService configAssignmentPersistService = + new ConfigAssignmentPersistService(configResourceService); + configAssignmentPersistService.saveResourceMapping(resourceAssignmentData, templateName, + resourceAssignments); + } + } + + private void validateInputParams(ResourceAssignmentData resourceAssignmentData) throws SvcLogicException { + if (resourceAssignmentData == null) { + throw new SvcLogicException("Input parameters missing"); + } + + String requestId = resourceAssignmentData.getRequestId(); + if (StringUtils.isBlank(requestId)) { + throw new SvcLogicException("Request id parameters missing"); + } + String resourceId = resourceAssignmentData.getResourceId(); + if (StringUtils.isBlank(resourceId)) { + throw new SvcLogicException("Resource id parameter is missing"); + } + String resourceType = resourceAssignmentData.getResourceType(); + if (StringUtils.isBlank(resourceType)) { + throw new SvcLogicException("Resource type parameter is missing"); + } + String actionName = resourceAssignmentData.getActionName(); + if (StringUtils.isBlank(actionName)) { + throw new SvcLogicException("Action name is parameter is missing"); + } + + List templatesNames = resourceAssignmentData.getTemplateNames(); + if (CollectionUtils.isEmpty(templatesNames)) { + throw new SvcLogicException("Template names parameter missing"); + } + } + +} diff --git a/blueprints-processor/plugin/assignment-provider/src/main/java/org/onap/ccsdk/features/assignment/service/ConfigAssignmentService.java b/blueprints-processor/plugin/assignment-provider/src/main/java/org/onap/ccsdk/features/assignment/service/ConfigAssignmentService.java new file mode 100644 index 000000000..969f84679 --- /dev/null +++ b/blueprints-processor/plugin/assignment-provider/src/main/java/org/onap/ccsdk/features/assignment/service/ConfigAssignmentService.java @@ -0,0 +1,36 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2018 IBM. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.ccsdk.features.assignment.service; + +import java.util.List; + +import org.onap.ccsdk.features.assignment.data.ResourceAssignmentData; +import org.onap.ccsdk.features.model.data.ResourceAssignment; +import org.onap.ccsdk.sli.core.sli.SvcLogicException; + +public interface ConfigAssignmentService { + + public void resolveResources(ResourceAssignmentData resourceAssignmentData) throws SvcLogicException; + + public void saveResourceMapping(ResourceAssignmentData resourceAssignmentData, String templateName, + List resourceAssignments) throws SvcLogicException; + + public ResourceAssignmentData generateTemplateResourceMash(ResourceAssignmentData resourceAssignmentData) + throws SvcLogicException; + +} diff --git a/blueprints-processor/plugin/assignment-provider/src/main/java/org/onap/ccsdk/features/assignment/service/ConfigAssignmentServiceImpl.java b/blueprints-processor/plugin/assignment-provider/src/main/java/org/onap/ccsdk/features/assignment/service/ConfigAssignmentServiceImpl.java new file mode 100644 index 000000000..560d0b1ff --- /dev/null +++ b/blueprints-processor/plugin/assignment-provider/src/main/java/org/onap/ccsdk/features/assignment/service/ConfigAssignmentServiceImpl.java @@ -0,0 +1,80 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2018 IBM. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.ccsdk.features.assignment.service; + +import java.util.List; + +import org.onap.ccsdk.features.assignment.data.ResourceAssignmentData; +import org.onap.ccsdk.features.data.adaptor.service.ConfigResourceService; +import org.onap.ccsdk.features.generator.service.ConfigGeneratorService; +import org.onap.ccsdk.features.model.data.ResourceAssignment; +import org.onap.ccsdk.features.model.service.ComponentNodeService; +import org.onap.ccsdk.features.model.service.ConfigModelService; +import org.onap.ccsdk.features.rest.adaptor.service.ConfigRestAdaptorService; +import org.onap.ccsdk.sli.core.sli.SvcLogicException; +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; + +public class ConfigAssignmentServiceImpl implements ConfigAssignmentService { + + private static EELFLogger logger = EELFManager.getInstance().getLogger(ConfigAssignmentServiceImpl.class); + + private ComponentNodeService componentNodeService; + private ConfigResourceService configResourceService; + private ConfigModelService configModelService; + private ConfigRestAdaptorService configRestAdaptorService; + private ConfigGeneratorService configGeneratorService; + + private static final String CLASS_NAME = "ConfigAssignmentServiceImpl"; + + public ConfigAssignmentServiceImpl(ConfigResourceService configResourceService, + ConfigRestAdaptorService configRestAdaptorService, ConfigModelService configModelService, + ComponentNodeService componentNodeService, ConfigGeneratorService configGeneratorService) { + logger.info("{} Constuctor Initated...", CLASS_NAME); + this.componentNodeService = componentNodeService; + this.configResourceService = configResourceService; + this.configModelService = configModelService; + this.configRestAdaptorService = configRestAdaptorService; + this.configGeneratorService = configGeneratorService; + } + + @Override + public void resolveResources(ResourceAssignmentData resourceAssignmentData) throws SvcLogicException { + ConfigAssignmentProcessService configAssignmentProcessService = + new ConfigAssignmentProcessService(configResourceService, configRestAdaptorService, configModelService, + componentNodeService, configGeneratorService); + configAssignmentProcessService.resolveResources(resourceAssignmentData); + } + + @Override + public void saveResourceMapping(ResourceAssignmentData resourceAssignmentData, String templateName, + List resourceAssignments) throws SvcLogicException { + ConfigAssignmentPersistService configAssignmentPersistService = + new ConfigAssignmentPersistService(configResourceService); + configAssignmentPersistService.saveResourceMapping(resourceAssignmentData, templateName, resourceAssignments); + } + + @Override + public ResourceAssignmentData generateTemplateResourceMash(ResourceAssignmentData resourceAssignmentData) + throws SvcLogicException { + ConfigPreviewService configPreviewService = + new ConfigPreviewService(configResourceService, configModelService, configGeneratorService); + return configPreviewService.generateTemplateResourceMash(resourceAssignmentData); + } + +} diff --git a/blueprints-processor/plugin/assignment-provider/src/main/java/org/onap/ccsdk/features/assignment/service/ConfigAssignmentUtils.java b/blueprints-processor/plugin/assignment-provider/src/main/java/org/onap/ccsdk/features/assignment/service/ConfigAssignmentUtils.java new file mode 100644 index 000000000..1d7df6b58 --- /dev/null +++ b/blueprints-processor/plugin/assignment-provider/src/main/java/org/onap/ccsdk/features/assignment/service/ConfigAssignmentUtils.java @@ -0,0 +1,305 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2018 IBM. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.ccsdk.features.assignment.service; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import org.apache.commons.collections.CollectionUtils; +import org.apache.commons.collections.IteratorUtils; +import org.apache.commons.collections.MapUtils; +import org.apache.commons.lang3.StringUtils; +import org.onap.ccsdk.features.data.adaptor.domain.ResourceAssignmentData; +import org.onap.ccsdk.features.model.ConfigModelConstant; +import org.onap.ccsdk.features.model.ConfigModelException; +import org.onap.ccsdk.features.model.ValidTypes; +import org.onap.ccsdk.features.model.data.DataType; +import org.onap.ccsdk.features.model.data.EntrySchema; +import org.onap.ccsdk.features.model.data.PropertyDefinition; +import org.onap.ccsdk.features.model.data.ResourceAssignment; +import org.onap.ccsdk.features.model.data.dict.ResourceDefinition; +import org.onap.ccsdk.features.model.domain.ResourceDictionary; +import org.onap.ccsdk.features.model.utils.JsonUtils; +import org.onap.ccsdk.features.model.utils.ResourceAssignmentUtils; +import org.onap.ccsdk.features.model.utils.TransformationUtils; +import org.onap.ccsdk.sli.core.sli.SvcLogicContext; +import org.onap.ccsdk.sli.core.sli.SvcLogicException; +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.node.ArrayNode; +import com.fasterxml.jackson.databind.node.JsonNodeFactory; +import com.fasterxml.jackson.databind.node.ObjectNode; + +public class ConfigAssignmentUtils { + + private ConfigAssignmentUtils() { + + } + + private static EELFLogger logger = EELFManager.getInstance().getLogger(ConfigAssignmentUtils.class); + + public static synchronized Object getContextKeyValue(SvcLogicContext context, String key) { + Object value = null; + if (context != null && key != null) { + if (context.getAttributeKeySet().contains(key)) { + String strValue = context.getAttribute(key); + if (StringUtils.isNotBlank(strValue)) { + value = strValue; + } + } else { + // Do Nothing + } + } + return value; + } + + /* + * Populate the Field property type for the Data type + */ + public static synchronized String getPropertyType(SvcLogicContext ctx, String dataTypeName, String propertyName) + throws SvcLogicException { + String type = ValidTypes.DATA_TYPE_STRING; + try { + if (ctx != null && StringUtils.isNotBlank(dataTypeName) && StringUtils.isNotBlank(propertyName)) { + String dataTypeContent = ctx.getAttribute(ConfigModelConstant.PROPERTY_DATA_TYPES_DOT + dataTypeName); + if (StringUtils.isNotBlank(dataTypeContent)) { + DataType dataType = TransformationUtils.readValue(dataTypeContent, DataType.class); + if (dataType != null && dataType.getProperties() != null + && dataType.getProperties().containsKey(propertyName)) { + PropertyDefinition propertyDefinition = dataType.getProperties().get(propertyName); + if (StringUtils.isNotBlank(propertyDefinition.getType())) { + type = propertyDefinition.getType(); + logger.trace("Data type({})'s property ({}) is ({})", dataTypeName, propertyName, type); + } else { + throw new SvcLogicException(String.format("Couldn't get data type (%s) ", dataTypeName)); + } + } + } else { + throw new SvcLogicException(String.format("Couldn't get data type (%s) content", dataTypeName)); + } + } + } catch (Exception e) { + logger.error("couldn't get data type({})'s property ({}), type ({}), error message ({}).", dataTypeName, + propertyName, type, e.getMessage()); + throw new SvcLogicException(e.getMessage()); + } + return type; + } + + /* + * Populate the Field property type for the Data type + */ + public static synchronized PropertyDefinition getPropertyDefinition(SvcLogicContext ctx, String dataTypeName, + String propertyName) throws SvcLogicException { + PropertyDefinition propertyDefinition = null; + try { + if (ctx != null && StringUtils.isNotBlank(dataTypeName) && StringUtils.isNotBlank(propertyName)) { + String dataTypeContent = ctx.getAttribute(ConfigModelConstant.PROPERTY_DATA_TYPES_DOT + dataTypeName); + if (StringUtils.isNotBlank(dataTypeContent)) { + DataType dataType = TransformationUtils.readValue(dataTypeContent, DataType.class); + if (dataType != null && dataType.getProperties() != null + && dataType.getProperties().containsKey(propertyName)) { + propertyDefinition = dataType.getProperties().get(propertyName); + if (propertyDefinition == null) { + throw new SvcLogicException(String.format("couldn't get data type (%s) ", dataTypeName)); + } + } + } else { + throw new SvcLogicException(String.format("couldn't get data type (%s) content.", dataTypeName)); + } + } + } catch (Exception e) { + throw new SvcLogicException(e.getMessage()); + } + return propertyDefinition; + } + + public static synchronized ResourceDefinition getDictionaryDefinition(Map dictionaries, + String dictionaryName) { + ResourceDefinition resourceDefinition = null; + if (dictionaries != null && StringUtils.isNotBlank(dictionaryName)) { + ResourceDictionary resourceDictionary = dictionaries.get(dictionaryName); + if (resourceDictionary != null && StringUtils.isNotBlank(resourceDictionary.getDefinition())) { + resourceDefinition = + TransformationUtils.readValue(resourceDictionary.getDefinition(), ResourceDefinition.class); + } + } + return resourceDefinition; + } + + @SuppressWarnings("squid:S3776") + public static synchronized void populateValueForOutputMapping(SvcLogicContext ctx, + Map componentContext, ResourceAssignment resourceAssignment, + Map outputKeyMapping, JsonNode responseNode) + throws ConfigModelException, SvcLogicException { + if (resourceAssignment == null) { + throw new SvcLogicException("resourceAssignment is null."); + } + + if (ctx == null) { + throw new SvcLogicException("service logic context is null."); + } + + if (componentContext == null) { + throw new SvcLogicException("component context is null."); + } + + logger.info("populating value for output mapping ({}), from json ({})", outputKeyMapping, responseNode); + String dictionaryName = resourceAssignment.getDictionaryName(); + String type = resourceAssignment.getProperty().getType(); + + String entrySchema = null; + if (ValidTypes.getPrimitivePropertType().contains(type)) { + ResourceAssignmentUtils.setResourceDataValue(componentContext, resourceAssignment, responseNode); + } else if (ValidTypes.getListPropertType().contains(type)) { + // Array Types + if (resourceAssignment.getProperty().getEntrySchema() != null) { + entrySchema = resourceAssignment.getProperty().getEntrySchema().getType(); + } + + if (StringUtils.isNotBlank(entrySchema)) { + ArrayNode arrayNode = JsonNodeFactory.instance.arrayNode(); + if (ValidTypes.getPrimitivePropertType().contains(entrySchema)) { + arrayNode = (ArrayNode) responseNode; + } else if (MapUtils.isNotEmpty(outputKeyMapping)) { + List responseArrayNode = IteratorUtils.toList(responseNode.elements()); + for (JsonNode responseSingleJsonNode : responseArrayNode) { + if (responseSingleJsonNode != null) { + ObjectNode arrayChildNode = JsonNodeFactory.instance.objectNode(); + for (Map.Entry mapping : outputKeyMapping.entrySet()) { + JsonNode responseKeyValue = responseSingleJsonNode.get(mapping.getKey()); + + String propertyTypeForDataType = + ConfigAssignmentUtils.getPropertyType(ctx, entrySchema, mapping.getKey()); + logger.info("For List Type Resource: key ({}), value ({}), type ({})", + mapping.getKey(), responseKeyValue, propertyTypeForDataType); + JsonUtils.populateJsonNodeValues(mapping.getValue(), responseKeyValue, + propertyTypeForDataType, arrayChildNode); + } + arrayNode.add(arrayChildNode); + } + } + } else { + arrayNode = (ArrayNode) responseNode; + } + // Set the List of Complex Values + ResourceAssignmentUtils.setResourceDataValue(componentContext, resourceAssignment, arrayNode); + } else { + throw new SvcLogicException( + String.format("Entry schema is not defined for dictionary (%s) info", dictionaryName)); + } + } else { + // Complex Types + ObjectNode objectNode = null; + if (MapUtils.isNotEmpty(outputKeyMapping)) { + objectNode = JsonNodeFactory.instance.objectNode(); + for (Map.Entry mapping : outputKeyMapping.entrySet()) { + JsonNode responseKeyValue = responseNode.get(mapping.getKey()); + String propertyTypeForDataType = + ConfigAssignmentUtils.getPropertyType(ctx, entrySchema, mapping.getKey()); + logger.info("For Complex Type Resource: key ({}), value ({}), type ({})", mapping.getKey(), + responseKeyValue, propertyTypeForDataType); + JsonUtils.populateJsonNodeValues(mapping.getValue(), responseKeyValue, propertyTypeForDataType, + objectNode); + } + } else { + objectNode = (ObjectNode) responseNode; + } + ResourceAssignmentUtils.setResourceDataValue(componentContext, resourceAssignment, objectNode); + } + } + + @SuppressWarnings("squid:S3776") + public static synchronized List convertResoureAssignmentDataList( + List resourceAssignmentDataList) { + List assignments = new ArrayList<>(); + if (CollectionUtils.isNotEmpty(resourceAssignmentDataList)) { + for (ResourceAssignmentData resourceAssignmentData : resourceAssignmentDataList) { + if (resourceAssignmentData != null) { + ResourceAssignment resourceAssignment = new ResourceAssignment(); + resourceAssignment.setName(resourceAssignmentData.getTemplateKeyName()); + resourceAssignment.setVersion(resourceAssignmentData.getVersion()); + resourceAssignment.setUpdatedBy(resourceAssignmentData.getUpdatedBy()); + resourceAssignment.setUpdatedDate(resourceAssignmentData.getUpdatedDate()); + resourceAssignment.setDictionaryName(resourceAssignmentData.getResourceName()); + resourceAssignment.setDictionarySource(resourceAssignmentData.getSource()); + resourceAssignment.setStatus(resourceAssignmentData.getStatus()); + resourceAssignment.setMessage(resourceAssignmentData.getMessage()); + PropertyDefinition property = new PropertyDefinition(); + property.setType(resourceAssignmentData.getDataType()); + + if (StringUtils.isNotBlank(resourceAssignmentData.getResourceValue())) { + if (ValidTypes.getPrimitivePropertType().contains(resourceAssignmentData.getDataType())) { + property.setValue(resourceAssignmentData.getResourceValue()); + } else { + JsonNode valueNode = + TransformationUtils.getJsonNodeForString(resourceAssignmentData.getResourceValue()); + property.setValue(valueNode); + } + } + if (StringUtils.isNotBlank(resourceAssignmentData.getEntrySchema())) { + EntrySchema entrySchema = new EntrySchema(); + entrySchema.setType(resourceAssignmentData.getEntrySchema()); + property.setEntrySchema(entrySchema); + } else { + property.setEntrySchema(null); + } + resourceAssignment.setProperty(property); + assignments.add(resourceAssignment); + } + } + + } + return assignments; + } + + @SuppressWarnings("squid:S3776") + public static synchronized List convertResoureAssignmentList( + List assignments) { + List resourceAssignmentDataList = new ArrayList<>(); + if (CollectionUtils.isNotEmpty(assignments)) { + for (ResourceAssignment assignment : assignments) { + if (assignment != null) { + ResourceAssignmentData resourceAssignmentData = new ResourceAssignmentData(); + resourceAssignmentData.setTemplateKeyName(assignment.getName()); + resourceAssignmentData.setVersion(assignment.getVersion()); + resourceAssignmentData.setUpdatedBy(assignment.getUpdatedBy()); + resourceAssignmentData.setUpdatedDate(assignment.getUpdatedDate()); + if (assignment.getProperty() != null) { + resourceAssignmentData.setDataType(assignment.getProperty().getType()); + if (assignment.getProperty().getEntrySchema() != null) { + resourceAssignmentData.setEntrySchema(assignment.getProperty().getEntrySchema().getType()); + } + if (assignment.getProperty().getValue() != null) { + String valueContent = TransformationUtils.getJson(assignment.getProperty().getValue()); + resourceAssignmentData.setResourceValue(valueContent); + } + } + resourceAssignmentData.setResourceName(assignment.getDictionaryName()); + resourceAssignmentData.setSource(assignment.getDictionarySource()); + resourceAssignmentData.setStatus(assignment.getStatus()); + resourceAssignmentData.setMessage(assignment.getMessage()); + resourceAssignmentDataList.add(resourceAssignmentData); + } + } + } + return resourceAssignmentDataList; + } + +} diff --git a/blueprints-processor/plugin/assignment-provider/src/main/java/org/onap/ccsdk/features/assignment/service/ConfigPreviewService.java b/blueprints-processor/plugin/assignment-provider/src/main/java/org/onap/ccsdk/features/assignment/service/ConfigPreviewService.java new file mode 100644 index 000000000..071b5a548 --- /dev/null +++ b/blueprints-processor/plugin/assignment-provider/src/main/java/org/onap/ccsdk/features/assignment/service/ConfigPreviewService.java @@ -0,0 +1,119 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2018 IBM. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.ccsdk.features.assignment.service; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import org.apache.commons.collections.CollectionUtils; +import org.apache.commons.lang3.StringUtils; +import org.onap.ccsdk.features.assignment.data.ResourceAssignmentData; +import org.onap.ccsdk.features.data.adaptor.domain.ConfigResource; +import org.onap.ccsdk.features.data.adaptor.service.ConfigResourceService; +import org.onap.ccsdk.features.generator.data.ConfigGeneratorInfo; +import org.onap.ccsdk.features.generator.service.ConfigGeneratorService; +import org.onap.ccsdk.features.model.ConfigModelConstant; +import org.onap.ccsdk.features.model.service.ConfigModelService; +import org.onap.ccsdk.sli.core.sli.SvcLogicException; +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; + +public class ConfigPreviewService { + private static EELFLogger logger = EELFManager.getInstance().getLogger(ConfigAssignmentPersistService.class); + private ConfigResourceService configResourceService; + private ConfigModelService configModelService; + private ConfigGeneratorService configGeneratorService; + + public ConfigPreviewService(ConfigResourceService configResourceService, ConfigModelService configModelService, + ConfigGeneratorService configGeneratorService) { + this.configResourceService = configResourceService; + this.configModelService = configModelService; + this.configGeneratorService = configGeneratorService; + } + + public String generatePreview(String templateContent, String templateData) throws SvcLogicException { + String mashedData = ""; + ConfigGeneratorInfo configGeneratorInfo = + configGeneratorService.generateConfiguration(templateContent, templateData); + if (configGeneratorInfo != null) { + mashedData = configGeneratorInfo.getMashedData(); + } + return mashedData; + } + + public ResourceAssignmentData generateTemplateResourceMash(ResourceAssignmentData resourceAssignmentData) + throws SvcLogicException { + if (resourceAssignmentData == null) { + throw new SvcLogicException("Resource assignment data is missing"); + } + if (StringUtils.isBlank(resourceAssignmentData.getServiceTemplateName())) { + throw new SvcLogicException("Service template name is missing"); + } + if (StringUtils.isBlank(resourceAssignmentData.getServiceTemplateVersion())) { + throw new SvcLogicException("Service template version is missing"); + } + if (StringUtils.isBlank(resourceAssignmentData.getResourceType())) { + throw new SvcLogicException("Resource type is missing"); + } + if (StringUtils.isBlank(resourceAssignmentData.getResourceId())) { + throw new SvcLogicException("Resource Id is missing"); + } + if (StringUtils.isBlank(resourceAssignmentData.getActionName())) { + throw new SvcLogicException("Action name is missing"); + } + + String serviceTemplateName = resourceAssignmentData.getServiceTemplateName(); + String serviceTemplateVersion = resourceAssignmentData.getServiceTemplateVersion(); + String actionName = resourceAssignmentData.getActionName(); + String resourceId = resourceAssignmentData.getResourceId(); + String resourceType = resourceAssignmentData.getResourceType(); + String inputData = "{}"; + + Map context = new HashMap<>(); + context.put(ConfigModelConstant.PROPERTY_ACTION_NAME, actionName); + context = configModelService.prepareContext(context, inputData, serviceTemplateName, serviceTemplateVersion); + + ConfigResource configResourceQuery = new ConfigResource(); + configResourceQuery.setServiceTemplateVersion(serviceTemplateName); + configResourceQuery.setServiceTemplateVersion(serviceTemplateVersion); + configResourceQuery.setRecipeName(actionName); + configResourceQuery.setResourceId(resourceId); + configResourceQuery.setResourceType(resourceType); + + List configResources = configResourceService.getConfigResource(configResourceQuery); + if (CollectionUtils.isNotEmpty(configResources)) { + for (ConfigResource cr : configResources) { + String templateContent = context + .get(ConfigModelConstant.PROPERTY_NODE_TEMPLATES_DOT + cr.getTemplateName() + ".content"); + String templateData = cr.getResourceData(); + String previewContent = generatePreview(templateContent, templateData); + resourceAssignmentData.getTemplatesMashedContents().put(cr.getTemplateName(), previewContent); + logger.info("Preview generated for template name ({}) ", cr.getTemplateName()); + logger.trace("Preview generated for preview ({}) ", previewContent); + } + } else { + logger.info( + "Couldn't get config resource for service template name ({}) service template version ({})" + + " action ({}) resource id ({}) resource type ({})", + serviceTemplateName, serviceTemplateVersion, actionName, resourceId, resourceType); + } + return resourceAssignmentData; + + } + +} diff --git a/blueprints-processor/plugin/assignment-provider/src/main/java/org/onap/ccsdk/features/assignment/service/ResourceDictionaryService.java b/blueprints-processor/plugin/assignment-provider/src/main/java/org/onap/ccsdk/features/assignment/service/ResourceDictionaryService.java new file mode 100644 index 000000000..ec586f493 --- /dev/null +++ b/blueprints-processor/plugin/assignment-provider/src/main/java/org/onap/ccsdk/features/assignment/service/ResourceDictionaryService.java @@ -0,0 +1,112 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2018 IBM. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.ccsdk.features.assignment.service; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import org.apache.commons.lang3.StringUtils; +import org.onap.ccsdk.features.model.data.ResourceAssignment; +import org.onap.ccsdk.features.model.data.dict.ResourceDefinition; +import org.onap.ccsdk.features.model.domain.ResourceDictionary; +import org.onap.ccsdk.features.model.utils.TransformationUtils; +import org.onap.ccsdk.features.rest.adaptor.ConfigRestAdaptorConstants; +import org.onap.ccsdk.features.rest.adaptor.ConfigRestAdaptorException; +import org.onap.ccsdk.features.rest.adaptor.service.ConfigRestAdaptorService; +import org.onap.ccsdk.sli.core.sli.SvcLogicException; +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; + +public class ResourceDictionaryService { + + private static EELFLogger logger = EELFManager.getInstance().getLogger(ResourceDictionaryService.class); + private ConfigRestAdaptorService configRestAdaptorService; + + public ResourceDictionaryService(ConfigRestAdaptorService configRestAdaptorService) { + this.configRestAdaptorService = configRestAdaptorService; + } + + @SuppressWarnings("squid:S3776") + public Map getDataDictionaryDefinitions(List resourceAssignments) + throws SvcLogicException { + try { + Map dictionaries = new HashMap<>(); + if (resourceAssignments != null) { + List names = new ArrayList<>(); + for (ResourceAssignment resourceAssignment : resourceAssignments) { + if (resourceAssignment != null && StringUtils.isNotBlank(resourceAssignment.getDictionaryName())) { + + if (!names.contains(resourceAssignment.getDictionaryName())) { + names.add(resourceAssignment.getDictionaryName()); + } + + if (resourceAssignment.getDependencies() != null + && !resourceAssignment.getDependencies().isEmpty()) { + List dependencieNames = resourceAssignment.getDependencies(); + for (String dependencieName : dependencieNames) { + if (StringUtils.isNotBlank(dependencieName) && !names.contains(dependencieName)) { + names.add(dependencieName); + } + } + } + } + } + queryResourceDictionaryDefinitions(dictionaries, names); + } + return dictionaries; + } catch (Exception e) { + throw new SvcLogicException("Failed in getting resource data dictionary : " + e.getMessage()); + } + + } + + @SuppressWarnings("squid:S3776") + private void queryResourceDictionaryDefinitions(Map dictionaries, List names) + throws SvcLogicException, ConfigRestAdaptorException { + logger.info("Getting resource dictionary definition for the names ({})", names); + if (!names.isEmpty()) { + + String dictionaryContents = configRestAdaptorService.postResource( + ConfigRestAdaptorConstants.SELECTOR_MODEL_SERVICE, "dictionarybynames", names, String.class); + + if (StringUtils.isNotBlank(dictionaryContents)) { + List dataDictionaries = + TransformationUtils.getListfromJson(dictionaryContents, ResourceDictionary.class); + if (dataDictionaries != null) { + for (ResourceDictionary dataDictionary : dataDictionaries) { + if (dataDictionary != null && StringUtils.isNotBlank(dataDictionary.getName()) + && StringUtils.isNotBlank(dataDictionary.getDefinition())) { + ResourceDefinition resourceDefinition = TransformationUtils + .readValue(dataDictionary.getDefinition(), ResourceDefinition.class); + if (resourceDefinition != null && StringUtils.isNotBlank(resourceDefinition.getName())) { + dictionaries.put(resourceDefinition.getName(), resourceDefinition); + } else { + throw new SvcLogicException( + "Failed in getting resource data dictionary definition for : " + + dataDictionary.getName()); + } + } + } + } + } else { + logger.warn("No resource dictionary definition found for the names ({})", names); + } + } + } +} diff --git a/blueprints-processor/plugin/assignment-provider/src/main/java/org/onap/ccsdk/features/assignment/service/ResourceModelService.java b/blueprints-processor/plugin/assignment-provider/src/main/java/org/onap/ccsdk/features/assignment/service/ResourceModelService.java new file mode 100644 index 000000000..befa36a34 --- /dev/null +++ b/blueprints-processor/plugin/assignment-provider/src/main/java/org/onap/ccsdk/features/assignment/service/ResourceModelService.java @@ -0,0 +1,97 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2018 IBM. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.ccsdk.features.assignment.service; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import org.apache.commons.collections.CollectionUtils; +import org.apache.commons.lang3.StringUtils; +import org.onap.ccsdk.features.model.data.ResourceAssignment; +import org.onap.ccsdk.features.model.service.ConfigModelService; +import org.onap.ccsdk.features.model.utils.TransformationUtils; +import org.onap.ccsdk.features.model.validator.ResourceAssignmentValidator; +import org.onap.ccsdk.sli.core.sli.SvcLogicContext; +import org.onap.ccsdk.sli.core.sli.SvcLogicException; +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; + +public class ResourceModelService { + private static EELFLogger logger = EELFManager.getInstance().getLogger(ResourceModelService.class); + + private ConfigModelService configModelService; + + public ResourceModelService(ConfigModelService configModelService) { + this.configModelService = configModelService; + } + + public Map getTemplatesContents(SvcLogicContext ctx, List templateNames) + throws SvcLogicException { + Map templatesContents = new HashMap<>(); + try { + if (CollectionUtils.isNotEmpty(templateNames)) { + for (String templateName : templateNames) { + String templateContent = this.configModelService.getNodeTemplateContent(ctx, templateName); + logger.trace("Processing template ({}) with content : {}", templateName, templateContent); + templatesContents.put(templateName, templateContent); + } + } + } catch (Exception e) { + throw new SvcLogicException(e.getMessage()); + } + return templatesContents; + } + + public Map> getTemplatesResourceAssignments(SvcLogicContext ctx, + List templateNames) throws SvcLogicException { + Map> templatesResourceAssignments = new HashMap<>(); + try { + if (CollectionUtils.isNotEmpty(templateNames)) { + for (String templateName : templateNames) { + String resourceMappingContent = this.configModelService.getNodeTemplateMapping(ctx, templateName); + logger.info("Processing template ({}) with resource assignment content : {}", templateName, + resourceMappingContent); + + if (StringUtils.isNotBlank(resourceMappingContent)) { + + List resourceAssignments = + TransformationUtils.getListfromJson(resourceMappingContent, ResourceAssignment.class); + + if (resourceAssignments != null) { + ResourceAssignmentValidator resourceAssignmentValidator = + new ResourceAssignmentValidator(resourceAssignments); + resourceAssignmentValidator.validateResourceAssignment(); + logger.info("Resource assignment validated successfully for the template ({})", + templateName); + templatesResourceAssignments.put(templateName, resourceAssignments); + } else { + throw new SvcLogicException(String.format( + "Failed to convert assignment content (%s) to object", resourceMappingContent)); + } + } else { + // Do nothing, because som e templates may not have mappings + } + } + } + } catch (Exception e) { + throw new SvcLogicException(e.getMessage()); + } + + return templatesResourceAssignments; + } +} diff --git a/blueprints-processor/plugin/assignment-provider/src/main/resources/org/opendaylight/blueprint/impl-blueprint.xml b/blueprints-processor/plugin/assignment-provider/src/main/resources/org/opendaylight/blueprint/impl-blueprint.xml index baa6bdbc5..f15429dfe 100644 --- a/blueprints-processor/plugin/assignment-provider/src/main/resources/org/opendaylight/blueprint/impl-blueprint.xml +++ b/blueprints-processor/plugin/assignment-provider/src/main/resources/org/opendaylight/blueprint/impl-blueprint.xml @@ -21,23 +21,23 @@ odl:use-default-for-reference-types="true"> + interface="org.onap.ccsdk.features.model.service.ComponentNodeService" /> + interface="org.onap.ccsdk.features.data.adaptor.service.ConfigResourceService" /> + interface="org.onap.ccsdk.features.model.service.ConfigModelService" /> + interface="org.onap.ccsdk.features.rest.adaptor.service.ConfigRestAdaptorService" /> + interface="org.onap.ccsdk.features.generator.service.ConfigGeneratorService" /> + class="org.onap.ccsdk.features.assignment.service.ConfigAssignmentNode"> @@ -46,10 +46,10 @@ + interface="org.onap.ccsdk.features.assignment.service.ConfigAssignmentNode" /> + class="org.onap.ccsdk.features.assignment.service.ConfigAssignmentServiceImpl"> @@ -58,6 +58,6 @@ + interface="org.onap.ccsdk.features.assignment.service.ConfigAssignmentService" /> diff --git a/blueprints-processor/plugin/assignment-provider/src/test/java/org/onap/ccsdk/config/assignment/processor/DBResourceProcessorTest.java b/blueprints-processor/plugin/assignment-provider/src/test/java/org/onap/ccsdk/config/assignment/processor/DBResourceProcessorTest.java deleted file mode 100644 index 5a704e995..000000000 --- a/blueprints-processor/plugin/assignment-provider/src/test/java/org/onap/ccsdk/config/assignment/processor/DBResourceProcessorTest.java +++ /dev/null @@ -1,231 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2018 IBM. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.ccsdk.config.assignment.processor; - -import static org.mockito.Matchers.any; -import java.io.File; -import java.nio.charset.Charset; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import org.apache.commons.io.FileUtils; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Matchers; -import org.mockito.Mock; -import org.mockito.Mockito; -import org.mockito.MockitoAnnotations; -import org.mockito.invocation.InvocationOnMock; -import org.mockito.runners.MockitoJUnitRunner; -import org.mockito.stubbing.Answer; -import org.onap.ccsdk.config.assignment.service.ConfigResourceAssignmentTestUtils; -import org.onap.ccsdk.config.data.adaptor.domain.TransactionLog; -import org.onap.ccsdk.config.data.adaptor.service.ConfigResourceService; -import org.onap.ccsdk.config.model.ConfigModelConstant; -import org.onap.ccsdk.config.model.data.ResourceAssignment; -import org.onap.ccsdk.config.model.data.dict.ResourceDefinition; -import org.onap.ccsdk.config.model.utils.TransformationUtils; -import org.onap.ccsdk.sli.core.sli.SvcLogicContext; -import org.onap.ccsdk.sli.core.sli.SvcLogicException; -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; - -@RunWith(MockitoJUnitRunner.class) -public class DBResourceProcessorTest { - - private static EELFLogger logger = EELFManager.getInstance().getLogger(DBResourceProcessorTest.class); - - @Mock - private ConfigResourceService configResourceService; - - @SuppressWarnings("unchecked") - @Before - public void before() { - MockitoAnnotations.initMocks(this); - - try { - Mockito.doAnswer(new Answer() { - @Override - public Void answer(InvocationOnMock invocationOnMock) throws Throwable { - Object[] args = invocationOnMock.getArguments(); - if (args != null) { - logger.trace("Transaction info " + Arrays.asList(args)); - } - return null; - } - }).when(configResourceService).save(any(TransactionLog.class)); - - } catch (SvcLogicException e) { - e.printStackTrace(); - } - } - - @Test - public void testDbSimpleProcess() throws Exception { - logger.info(" ******************************* testDbSimpleProcess ***************************"); - - Mockito.doAnswer(new Answer>>() { - @Override - public List> answer(InvocationOnMock invocationOnMock) throws Throwable { - Object[] args = invocationOnMock.getArguments(); - List> results = new ArrayList<>(); - if (args != null) { - logger.info("Query " + Arrays.asList(args)); - Map record = new HashMap<>(); - record.put("country", "US"); - results.add(record); - } - return results; - } - }).when(configResourceService).query(Matchers.anyString(), Matchers.>any()); - - String recipeName = "sample-recipe"; - - String resourceassignmentContent = FileUtils.readFileToString( - new File("src/test/resources/mapping/db/resource-assignments-simple.json"), Charset.defaultCharset()); - List batchResourceAssignment = - TransformationUtils.getListfromJson(resourceassignmentContent, ResourceAssignment.class); - - String dictionaryContent = FileUtils.readFileToString(new File("src/test/resources/mapping/db/db-simple.json"), - Charset.defaultCharset()); - Map dictionaries = - ConfigResourceAssignmentTestUtils.getMapfromJson(dictionaryContent); - DBResourceProcessor dbResourceProcessor = new DBResourceProcessor(configResourceService); - Map componentContext = new HashMap<>(); - componentContext.put(ConfigModelConstant.PROPERTY_RESOURCE_ASSIGNMENTS, batchResourceAssignment); - componentContext.put(ConfigModelConstant.PROPERTY_ACTION_NAME, recipeName); - componentContext.put(ConfigModelConstant.PROPERTY_TEMPLATE_NAME, "sample-template"); - componentContext.put(ConfigModelConstant.PROPERTY_DICTIONARIES, dictionaries); - - componentContext.put(ConfigModelConstant.PROPERTY_DICTIONARY_KEY_DOT + recipeName + ".profile_name", "sample"); - - Map inParams = new HashMap<>(); - SvcLogicContext ctx = new SvcLogicContext(); - dbResourceProcessor.process(inParams, ctx, componentContext); - - logger.info(" Context " + componentContext); - - } - - @Test - public void testDbComplexProcess() throws Exception { - logger.info(" ******************************* testDbComplexProcess ***************************"); - - Mockito.doAnswer(new Answer>>() { - @Override - public List> answer(InvocationOnMock invocationOnMock) throws Throwable { - Object[] args = invocationOnMock.getArguments(); - List> results = new ArrayList<>(); - if (args != null) { - logger.info("Query " + Arrays.asList(args)); - Map record = new HashMap<>(); - record.put("db-country", "US"); - record.put("db-state", "NJ"); - results.add(record); - } - return results; - } - }).when(configResourceService).query(Matchers.anyString(), Matchers.>any()); - - String recipeName = "sample-recipe"; - - String resourceassignmentContent = FileUtils.readFileToString( - new File("src/test/resources/mapping/db/resource-assignments-complex.json"), Charset.defaultCharset()); - List batchResourceAssignment = - TransformationUtils.getListfromJson(resourceassignmentContent, ResourceAssignment.class); - - String dictionaryContent = FileUtils.readFileToString(new File("src/test/resources/mapping/db/db-complex.json"), - Charset.defaultCharset()); - Map dictionaries = - ConfigResourceAssignmentTestUtils.getMapfromJson(dictionaryContent); - DBResourceProcessor dbResourceProcessor = new DBResourceProcessor(configResourceService); - Map componentContext = new HashMap<>(); - componentContext.put(ConfigModelConstant.PROPERTY_RESOURCE_ASSIGNMENTS, batchResourceAssignment); - componentContext.put(ConfigModelConstant.PROPERTY_ACTION_NAME, recipeName); - componentContext.put(ConfigModelConstant.PROPERTY_TEMPLATE_NAME, "sample-template"); - componentContext.put(ConfigModelConstant.PROPERTY_DICTIONARIES, dictionaries); - componentContext.put(ConfigModelConstant.PROPERTY_DICTIONARY_KEY_DOT + recipeName + ".profile_name", "sample"); - - Map inParams = new HashMap<>(); - SvcLogicContext ctx = new SvcLogicContext(); - String datatypeContent = FileUtils.readFileToString(new File("src/test/resources/mapping/db/dt-location.json"), - Charset.defaultCharset()); - ctx.setAttribute("data_types.dt-location", datatypeContent); - dbResourceProcessor.process(inParams, ctx, componentContext); - - } - - @Test - public void testDbArrayComplexProcess() throws Exception { - logger.info(" ******************************* testDbArrayComplexProcess ***************************"); - Mockito.doAnswer(new Answer>>() { - @Override - public List> answer(InvocationOnMock invocationOnMock) throws Throwable { - Object[] args = invocationOnMock.getArguments(); - List> results = new ArrayList<>(); - if (args != null) { - logger.info("Query " + Arrays.asList(args)); - Map record = new HashMap<>(); - record.put("db-country", "US"); - record.put("db-state", "NJ"); - results.add(record); - - Map record2 = new HashMap<>(); - record2.put("db-country", "INDIA"); - record2.put("db-state", "TN"); - results.add(record2); - } - return results; - } - }).when(configResourceService).query(Matchers.anyString(), Matchers.>any()); - - String recipeName = "sample-recipe"; - - String resourceassignmentContent = FileUtils.readFileToString( - new File("src/test/resources/mapping/db/resource-assignments-array.json"), Charset.defaultCharset()); - List batchResourceAssignment = - TransformationUtils.getListfromJson(resourceassignmentContent, ResourceAssignment.class); - - String dictionaryContent = FileUtils.readFileToString(new File("src/test/resources/mapping/db/db-array.json"), - Charset.defaultCharset()); - Map dictionaries = - ConfigResourceAssignmentTestUtils.getMapfromJson(dictionaryContent); - DBResourceProcessor dbResourceProcessor = new DBResourceProcessor(configResourceService); - Map componentContext = new HashMap<>(); - componentContext.put(ConfigModelConstant.PROPERTY_RESOURCE_ASSIGNMENTS, batchResourceAssignment); - componentContext.put(ConfigModelConstant.PROPERTY_ACTION_NAME, recipeName); - componentContext.put(ConfigModelConstant.PROPERTY_TEMPLATE_NAME, "sample-template"); - componentContext.put(ConfigModelConstant.PROPERTY_DICTIONARIES, dictionaries); - componentContext.put(ConfigModelConstant.PROPERTY_DICTIONARY_KEY_DOT + recipeName + ".profile_name", "sample"); - - Map inParams = new HashMap<>(); - SvcLogicContext ctx = new SvcLogicContext(); - String datatypeContent = FileUtils.readFileToString(new File("src/test/resources/mapping/db/dt-location.json"), - Charset.defaultCharset()); - ctx.setAttribute("data_types.dt-location", datatypeContent); - dbResourceProcessor.process(inParams, ctx, componentContext); - logger.info("Component Context = ({})", componentContext); - Assert.assertNotNull("faile dto populate Array Complex response ", componentContext); - - } - -} diff --git a/blueprints-processor/plugin/assignment-provider/src/test/java/org/onap/ccsdk/config/assignment/processor/DefaultResourceProcessorTest.java b/blueprints-processor/plugin/assignment-provider/src/test/java/org/onap/ccsdk/config/assignment/processor/DefaultResourceProcessorTest.java deleted file mode 100644 index 7e8d14201..000000000 --- a/blueprints-processor/plugin/assignment-provider/src/test/java/org/onap/ccsdk/config/assignment/processor/DefaultResourceProcessorTest.java +++ /dev/null @@ -1,127 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2018 IBM. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.ccsdk.config.assignment.processor; - -import static org.mockito.Matchers.any; -import java.io.File; -import java.nio.charset.Charset; -import java.util.Arrays; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import org.apache.commons.io.FileUtils; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mock; -import org.mockito.Mockito; -import org.mockito.MockitoAnnotations; -import org.mockito.invocation.InvocationOnMock; -import org.mockito.runners.MockitoJUnitRunner; -import org.mockito.stubbing.Answer; -import org.onap.ccsdk.config.assignment.service.ConfigResourceAssignmentTestUtils; -import org.onap.ccsdk.config.data.adaptor.domain.TransactionLog; -import org.onap.ccsdk.config.data.adaptor.service.ConfigResourceService; -import org.onap.ccsdk.config.model.ConfigModelConstant; -import org.onap.ccsdk.config.model.data.ResourceAssignment; -import org.onap.ccsdk.config.model.data.dict.ResourceDefinition; -import org.onap.ccsdk.config.model.utils.TransformationUtils; -import org.onap.ccsdk.sli.core.sli.SvcLogicContext; -import org.onap.ccsdk.sli.core.sli.SvcLogicException; -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; - -@RunWith(MockitoJUnitRunner.class) -public class DefaultResourceProcessorTest { - - private static EELFLogger logger = EELFManager.getInstance().getLogger(DefaultResourceProcessorTest.class); - - @Mock - private ConfigResourceService configResourceService; - - @SuppressWarnings("unchecked") - @Before - public void before() { - MockitoAnnotations.initMocks(this); - - try { - Mockito.doAnswer(new Answer() { - @Override - public Void answer(InvocationOnMock invocationOnMock) throws Throwable { - Object[] args = invocationOnMock.getArguments(); - if (args != null) { - logger.trace("Transaction info " + Arrays.asList(args)); - } - return null; - } - }).when(configResourceService).save(any(TransactionLog.class)); - - } catch (SvcLogicException e) { - e.printStackTrace(); - } - } - - @Test - public void testDefaultSimpleProcess() throws Exception { - logger.info(" ******************************* testDefaultSimpleProcess ***************************"); - - String recipeName = "sample-recipe"; - - String resourceassignmentContent = FileUtils.readFileToString( - new File("src/test/resources/mapping/default/resource-assignments-simple.json"), - Charset.defaultCharset()); - List batchResourceAssignment = - TransformationUtils.getListfromJson(resourceassignmentContent, ResourceAssignment.class); - - String dictionaryContent = FileUtils.readFileToString( - new File("src/test/resources/mapping/default/default-simple.json"), Charset.defaultCharset()); - Map dictionaries = - ConfigResourceAssignmentTestUtils.getMapfromJson(dictionaryContent); - - DefaultResourceProcessor defaultResourceProcessor = new DefaultResourceProcessor(configResourceService); - Map componentContext = new HashMap<>(); - componentContext.put(ConfigModelConstant.PROPERTY_RESOURCE_ASSIGNMENTS, batchResourceAssignment); - componentContext.put(ConfigModelConstant.PROPERTY_ACTION_NAME, recipeName); - componentContext.put(ConfigModelConstant.PROPERTY_TEMPLATE_NAME, "sample-template"); - componentContext.put(ConfigModelConstant.PROPERTY_DICTIONARIES, dictionaries); - componentContext.put(ConfigModelConstant.PROPERTY_DICTIONARY_KEY_DOT + recipeName + ".profile_name", "sample"); - - Map inParams = new HashMap<>(); - SvcLogicContext ctx = new SvcLogicContext(); - defaultResourceProcessor.process(inParams, ctx, componentContext); - logger.trace(" componentContext " + componentContext); - - Assert.assertEquals("Failed to populate default country value ", "US", - componentContext.get(ConfigModelConstant.PROPERTY_RECIPE_KEY_DOT + "sample-recipe.country")); - Assert.assertEquals("Failed to populate default country value ", "US", - componentContext.get(ConfigModelConstant.PROPERTY_DICTIONARY_KEY_DOT + "sample-recipe.country")); - - Assert.assertEquals("Failed to populate default port value ", 830, - componentContext.get(ConfigModelConstant.PROPERTY_RECIPE_KEY_DOT + "sample-recipe.port")); - Assert.assertEquals("Failed to populate default port value ", 830, - componentContext.get(ConfigModelConstant.PROPERTY_DICTIONARY_KEY_DOT + "sample-recipe.port")); - - Assert.assertEquals("Failed to populate default voip-enabled value ", true, - componentContext.get(ConfigModelConstant.PROPERTY_RECIPE_KEY_DOT + "sample-recipe.voip-enabled")); - Assert.assertEquals("Failed to populate default voip-enabled value ", true, - componentContext.get(ConfigModelConstant.PROPERTY_DICTIONARY_KEY_DOT + "sample-recipe.voip-enabled")); - - } - -} diff --git a/blueprints-processor/plugin/assignment-provider/src/test/java/org/onap/ccsdk/config/assignment/processor/InputResourceProcessorTest.java b/blueprints-processor/plugin/assignment-provider/src/test/java/org/onap/ccsdk/config/assignment/processor/InputResourceProcessorTest.java deleted file mode 100644 index 2aabdb3d9..000000000 --- a/blueprints-processor/plugin/assignment-provider/src/test/java/org/onap/ccsdk/config/assignment/processor/InputResourceProcessorTest.java +++ /dev/null @@ -1,178 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2018 IBM. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.ccsdk.config.assignment.processor; - -import static org.mockito.Matchers.any; -import java.io.File; -import java.nio.charset.Charset; -import java.util.Arrays; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import org.apache.commons.io.FileUtils; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mock; -import org.mockito.Mockito; -import org.mockito.MockitoAnnotations; -import org.mockito.invocation.InvocationOnMock; -import org.mockito.runners.MockitoJUnitRunner; -import org.mockito.stubbing.Answer; -import org.onap.ccsdk.config.assignment.service.ConfigResourceAssignmentTestUtils; -import org.onap.ccsdk.config.data.adaptor.domain.TransactionLog; -import org.onap.ccsdk.config.data.adaptor.service.ConfigResourceService; -import org.onap.ccsdk.config.model.ConfigModelConstant; -import org.onap.ccsdk.config.model.data.ResourceAssignment; -import org.onap.ccsdk.config.model.data.dict.ResourceDefinition; -import org.onap.ccsdk.config.model.utils.TransformationUtils; -import org.onap.ccsdk.sli.core.sli.SvcLogicContext; -import org.onap.ccsdk.sli.core.sli.SvcLogicException; -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; - -@RunWith(MockitoJUnitRunner.class) -public class InputResourceProcessorTest { - - private static EELFLogger logger = EELFManager.getInstance().getLogger(InputResourceProcessorTest.class); - - @Mock - private ConfigResourceService configResourceService; - - @SuppressWarnings("unchecked") - @Before - public void before() { - MockitoAnnotations.initMocks(this); - - try { - Mockito.doAnswer(new Answer() { - @Override - public Void answer(InvocationOnMock invocationOnMock) throws Throwable { - Object[] args = invocationOnMock.getArguments(); - if (args != null) { - logger.trace("Transaction info " + Arrays.asList(args)); - } - return null; - } - }).when(configResourceService).save(any(TransactionLog.class)); - - } catch (SvcLogicException e) { - e.printStackTrace(); - } - } - - @Test - public void testInputSimpleProcess() throws Exception { - logger.info(" ******************************* testInputSimpleProcess ***************************"); - - String recipeName = "sample-recipe"; - - String resourceassignmentContent = FileUtils.readFileToString( - new File("src/test/resources/mapping/input/resource-assignments-simple.json"), - Charset.defaultCharset()); - List batchResourceAssignment = - TransformationUtils.getListfromJson(resourceassignmentContent, ResourceAssignment.class); - - String dictionaryContent = FileUtils.readFileToString( - new File("src/test/resources/mapping/default/default-simple.json"), Charset.defaultCharset()); - Map dictionaries = - ConfigResourceAssignmentTestUtils.getMapfromJson(dictionaryContent); - - InputResourceProcessor inputResourceProcessor = new InputResourceProcessor(configResourceService); - Map componentContext = new HashMap<>(); - componentContext.put(ConfigModelConstant.PROPERTY_RESOURCE_ASSIGNMENTS, batchResourceAssignment); - componentContext.put(ConfigModelConstant.PROPERTY_ACTION_NAME, recipeName); - componentContext.put(ConfigModelConstant.PROPERTY_TEMPLATE_NAME, "sample-template"); - componentContext.put(ConfigModelConstant.PROPERTY_DICTIONARIES, dictionaries); - componentContext.put(ConfigModelConstant.PROPERTY_DICTIONARY_KEY_DOT + recipeName + ".profile_name", "sample"); - - Map inParams = new HashMap<>(); - SvcLogicContext ctx = new SvcLogicContext(); - ctx.setAttribute("country", "US"); - ctx.setAttribute("port", "830"); - ctx.setAttribute("voip-enabled", "true"); - - inputResourceProcessor.process(inParams, ctx, componentContext); - logger.trace(" componentContext " + componentContext); - - Assert.assertEquals("Failed to populate default recipe country value ", "US", - componentContext.get(ConfigModelConstant.PROPERTY_RECIPE_KEY_DOT + "sample-recipe.country")); - Assert.assertEquals("Failed to populate default dictionary country value ", "US", - componentContext.get(ConfigModelConstant.PROPERTY_DICTIONARY_KEY_DOT + "sample-recipe.country")); - - Assert.assertEquals("Failed to populate default recipe port value ", 830, - componentContext.get(ConfigModelConstant.PROPERTY_RECIPE_KEY_DOT + "sample-recipe.port")); - Assert.assertEquals("Failed to populate default dictionary port value ", 830, - componentContext.get(ConfigModelConstant.PROPERTY_DICTIONARY_KEY_DOT + "sample-recipe.port")); - - Assert.assertEquals("Failed to populate default recipe voip-enabled value ", true, - componentContext.get(ConfigModelConstant.PROPERTY_RECIPE_KEY_DOT + "sample-recipe.voip-enabled")); - Assert.assertEquals("Failed to populate default dictionary voip-enabled value ", true, - componentContext.get(ConfigModelConstant.PROPERTY_DICTIONARY_KEY_DOT + "sample-recipe.voip-enabled")); - - } - - @Test - public void testInputComplexProcess() throws Exception { - logger.info(" ******************************* testInputComplexProcess ***************************"); - - String recipeName = "sample-recipe"; - - String resourceassignmentContent = FileUtils.readFileToString( - new File("src/test/resources/mapping/input/resource-assignments-complex.json"), - Charset.defaultCharset()); - List batchResourceAssignment = - TransformationUtils.getListfromJson(resourceassignmentContent, ResourceAssignment.class); - - String dictionaryContent = FileUtils.readFileToString( - new File("src/test/resources/mapping/input/input-complex.json"), Charset.defaultCharset()); - Map dictionaries = - ConfigResourceAssignmentTestUtils.getMapfromJson(dictionaryContent); - - InputResourceProcessor inputResourceProcessor = new InputResourceProcessor(configResourceService); - Map componentContext = new HashMap<>(); - componentContext.put(ConfigModelConstant.PROPERTY_RESOURCE_ASSIGNMENTS, batchResourceAssignment); - componentContext.put(ConfigModelConstant.PROPERTY_ACTION_NAME, recipeName); - componentContext.put(ConfigModelConstant.PROPERTY_TEMPLATE_NAME, "sample-template"); - componentContext.put(ConfigModelConstant.PROPERTY_DICTIONARIES, dictionaries); - componentContext.put(ConfigModelConstant.PROPERTY_DICTIONARY_KEY_DOT + recipeName + ".profile_name", "sample"); - - Map inParams = new HashMap<>(); - SvcLogicContext ctx = new SvcLogicContext(); - String datatypeContent = FileUtils.readFileToString( - new File("src/test/resources/mapping/input/dt-location.json"), Charset.defaultCharset()); - ctx.setAttribute("data_types.dt-location", datatypeContent); - - String samplelocation = FileUtils.readFileToString( - new File("src/test/resources/mapping/input/sample-location.json"), Charset.defaultCharset()); - ctx.setAttribute("location", samplelocation); - - inputResourceProcessor.process(inParams, ctx, componentContext); - - logger.trace(" componentContext " + componentContext); - logger.trace(" Resource Mapping " + TransformationUtils.getJson(batchResourceAssignment, true)); - - Assert.assertNotNull("Failed to populate input recipe location value ", - componentContext.get(ConfigModelConstant.PROPERTY_RECIPE_KEY_DOT + "sample-recipe.location")); - Assert.assertNotNull("Failed to populate input dictionary location value ", - componentContext.get(ConfigModelConstant.PROPERTY_DICTIONARY_KEY_DOT + "sample-recipe.location")); - - } - -} diff --git a/blueprints-processor/plugin/assignment-provider/src/test/java/org/onap/ccsdk/config/assignment/processor/MdsalResourceProcessorTest.java b/blueprints-processor/plugin/assignment-provider/src/test/java/org/onap/ccsdk/config/assignment/processor/MdsalResourceProcessorTest.java deleted file mode 100644 index 2d651c836..000000000 --- a/blueprints-processor/plugin/assignment-provider/src/test/java/org/onap/ccsdk/config/assignment/processor/MdsalResourceProcessorTest.java +++ /dev/null @@ -1,268 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2018 IBM. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.ccsdk.config.assignment.processor; - -import java.io.File; -import java.nio.charset.Charset; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import org.apache.commons.io.FileUtils; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Matchers; -import org.mockito.Mock; -import org.mockito.Mockito; -import org.mockito.invocation.InvocationOnMock; -import org.mockito.runners.MockitoJUnitRunner; -import org.mockito.stubbing.Answer; -import org.onap.ccsdk.config.assignment.service.ConfigResourceAssignmentTestUtils; -import org.onap.ccsdk.config.model.ConfigModelConstant; -import org.onap.ccsdk.config.model.data.ResourceAssignment; -import org.onap.ccsdk.config.model.data.dict.ResourceDefinition; -import org.onap.ccsdk.config.model.utils.TransformationUtils; -import org.onap.ccsdk.config.rest.adaptor.service.ConfigRestAdaptorService; -import org.onap.ccsdk.sli.core.sli.SvcLogicContext; -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; - -@RunWith(MockitoJUnitRunner.class) -public class MdsalResourceProcessorTest { - - private static EELFLogger logger = EELFManager.getInstance().getLogger(MdsalResourceProcessorTest.class); - - @Mock - private ConfigRestAdaptorService configRestAdaptorService; - - @SuppressWarnings("unchecked") - @Before - public void before() { - - } - - @Test - @SuppressWarnings("unchecked") - public void testMdsalSimpleProcess() throws Exception { - logger.info(" ******************************* testMdsalSimpleProcess ***************************"); - - Mockito.doAnswer(new Answer() { - @Override - public String answer(InvocationOnMock invocationOnMock) throws Throwable { - Object[] args = invocationOnMock.getArguments(); - String response = null; - if (args != null) { - response = FileUtils.readFileToString( - new File("src/test/resources/mapping/Mdsal/simple-response.json"), - Charset.defaultCharset()); - logger.info(" Returning response :" + response); - } - return response; - } - }).when(configRestAdaptorService).getResource(Matchers.anyString(), Matchers.anyString(), - Matchers.any(Class.class)); - - String recipeName = "sample-recipe"; - - String resourceassignmentContent = FileUtils.readFileToString( - new File("src/test/resources/mapping/Mdsal/resource-assignments-simple.json"), - Charset.defaultCharset()); - List batchResourceAssignment = - TransformationUtils.getListfromJson(resourceassignmentContent, ResourceAssignment.class); - - String dictionaryContent = FileUtils.readFileToString( - new File("src/test/resources/mapping/Mdsal/mdsal-simple.json"), Charset.defaultCharset()); - Map dictionaries = - ConfigResourceAssignmentTestUtils.getMapfromJson(dictionaryContent); - MdsalResourceProcessor mdsalResourceProcessor = new MdsalResourceProcessor(configRestAdaptorService); - Map componentContext = new HashMap<>(); - componentContext.put(ConfigModelConstant.PROPERTY_RESOURCE_ASSIGNMENTS, batchResourceAssignment); - componentContext.put(ConfigModelConstant.PROPERTY_ACTION_NAME, recipeName); - componentContext.put(ConfigModelConstant.PROPERTY_TEMPLATE_NAME, "sample-template"); - componentContext.put(ConfigModelConstant.PROPERTY_DICTIONARIES, dictionaries); - - componentContext.put(ConfigModelConstant.PROPERTY_DICTIONARY_KEY_DOT + recipeName + ".profile_name", "sample"); - - Map inParams = new HashMap<>(); - SvcLogicContext ctx = new SvcLogicContext(); - mdsalResourceProcessor.process(inParams, ctx, componentContext); - - } - - @SuppressWarnings("unchecked") - @Test - public void testMDSALComplexProcess() throws Exception { - logger.info(" ******************************* testMDSALComplexProcess ***************************"); - - Mockito.doAnswer(new Answer() { - @Override - public String answer(InvocationOnMock invocationOnMock) throws Throwable { - Object[] args = invocationOnMock.getArguments(); - String response = null; - if (args != null) { - response = FileUtils.readFileToString( - new File("src/test/resources/mapping/Mdsal/complex-response.json"), - Charset.defaultCharset()); - } - return response; - } - }).when(configRestAdaptorService).getResource(Matchers.anyString(), Matchers.anyString(), - Matchers.any(Class.class)); - - String recipeName = "sample-recipe"; - - String resourceassignmentContent = FileUtils.readFileToString( - new File("src/test/resources/mapping/Mdsal/resource-assignments-complex.json"), - Charset.defaultCharset()); - List batchResourceAssignment = - TransformationUtils.getListfromJson(resourceassignmentContent, ResourceAssignment.class); - - String dictionaryContent = FileUtils.readFileToString( - new File("src/test/resources/mapping/Mdsal/mdsal-complex.json"), Charset.defaultCharset()); - Map dictionaries = - ConfigResourceAssignmentTestUtils.getMapfromJson(dictionaryContent); - MdsalResourceProcessor dbResourceProcessor = new MdsalResourceProcessor(configRestAdaptorService); - Map componentContext = new HashMap<>(); - componentContext.put(ConfigModelConstant.PROPERTY_RESOURCE_ASSIGNMENTS, batchResourceAssignment); - componentContext.put(ConfigModelConstant.PROPERTY_ACTION_NAME, recipeName); - componentContext.put(ConfigModelConstant.PROPERTY_TEMPLATE_NAME, "sample-template"); - componentContext.put(ConfigModelConstant.PROPERTY_DICTIONARIES, dictionaries); - componentContext.put(ConfigModelConstant.PROPERTY_DICTIONARY_KEY_DOT + recipeName + ".profile_name", "sample"); - - Map inParams = new HashMap<>(); - SvcLogicContext ctx = new SvcLogicContext(); - String datatypeContent = FileUtils.readFileToString( - new File("src/test/resources/mapping/Mdsal/dt-location.json"), Charset.defaultCharset()); - ctx.setAttribute("data_types.dt-location", datatypeContent); - dbResourceProcessor.process(inParams, ctx, componentContext); - - } - - @Test - @SuppressWarnings("unchecked") - public void testMDSALArrayComplexProcess() throws Exception { - logger.info(" ******************************* testMDSALArrayComplexProcess ***************************"); - - Mockito.doAnswer(new Answer() { - @Override - public String answer(InvocationOnMock invocationOnMock) throws Throwable { - Object[] args = invocationOnMock.getArguments(); - String response = null; - if (args != null) { - response = FileUtils.readFileToString( - new File("src/test/resources/mapping/Mdsal/array-complex-response.json"), - Charset.defaultCharset()); - } - return response; - } - }).when(configRestAdaptorService).getResource(Matchers.anyString(), Matchers.anyString(), - Matchers.any(Class.class)); - - String recipeName = "sample-recipe"; - - String resourceassignmentContent = FileUtils.readFileToString( - new File("src/test/resources/mapping/Mdsal/resource-assignments-array.json"), Charset.defaultCharset()); - List batchResourceAssignment = - TransformationUtils.getListfromJson(resourceassignmentContent, ResourceAssignment.class); - - String dictionaryContent = FileUtils.readFileToString( - new File("src/test/resources/mapping/Mdsal/mdsal-array.json"), Charset.defaultCharset()); - - Map dictionaries = - ConfigResourceAssignmentTestUtils.getMapfromJson(dictionaryContent); - MdsalResourceProcessor dbResourceProcessor = new MdsalResourceProcessor(configRestAdaptorService); - Map componentContext = new HashMap<>(); - componentContext.put(ConfigModelConstant.PROPERTY_RESOURCE_ASSIGNMENTS, batchResourceAssignment); - componentContext.put(ConfigModelConstant.PROPERTY_ACTION_NAME, recipeName); - componentContext.put(ConfigModelConstant.PROPERTY_TEMPLATE_NAME, "sample-template"); - componentContext.put(ConfigModelConstant.PROPERTY_DICTIONARIES, dictionaries); - componentContext.put(ConfigModelConstant.PROPERTY_DICTIONARY_KEY_DOT + recipeName + ".profile_name", "sample"); - - Map inParams = new HashMap<>(); - SvcLogicContext ctx = new SvcLogicContext(); - String datatypeContent = FileUtils.readFileToString( - new File("src/test/resources/mapping/Mdsal/dt-location.json"), Charset.defaultCharset()); - ctx.setAttribute("data_types.dt-location", datatypeContent); - dbResourceProcessor.process(inParams, ctx, componentContext); - logger.info("Component Context = ({})", componentContext); - Assert.assertNotNull("failed to populate Array Complex response ", componentContext); - - } - - @Test - @SuppressWarnings("unchecked") - public void testMDSALArraySimpleProcess() throws Exception { - logger.info(" ******************************* testMDSALArrayComplexProcess ***************************"); - - Mockito.doAnswer(new Answer() { - @Override - public String answer(InvocationOnMock invocationOnMock) throws Throwable { - Object[] args = invocationOnMock.getArguments(); - String response = null; - if (args != null) { - response = FileUtils.readFileToString( - new File("src/test/resources/mapping/Mdsal/array-complex-v4-assigned-response.json"), - Charset.defaultCharset()); - } - return response; - } - }).when(configRestAdaptorService).getResource(Matchers.anyString(), Matchers.anyString(), - Matchers.any(Class.class)); - - String recipeName = "sample-recipe"; - - String resourceassignmentContent = FileUtils.readFileToString( - new File("src/test/resources/mapping/Mdsal/resource-assignments-complex-simple.json"), - Charset.defaultCharset()); - List batchResourceAssignment = - TransformationUtils.getListfromJson(resourceassignmentContent, ResourceAssignment.class); - - String dictionaryContent = FileUtils.readFileToString( - new File("src/test/resources/mapping/Mdsal/mdsal-array-v4iplist.json"), Charset.defaultCharset()); - Map dictionaries = - ConfigResourceAssignmentTestUtils.getMapfromJson(dictionaryContent); - MdsalResourceProcessor mdsalResourceProcessor = new MdsalResourceProcessor(configRestAdaptorService); - Map componentContext = new HashMap<>(); - componentContext.put(ConfigModelConstant.PROPERTY_RESOURCE_ASSIGNMENTS, batchResourceAssignment); - componentContext.put(ConfigModelConstant.PROPERTY_ACTION_NAME, recipeName); - componentContext.put(ConfigModelConstant.PROPERTY_TEMPLATE_NAME, "sample-template"); - componentContext.put(ConfigModelConstant.PROPERTY_DICTIONARIES, dictionaries); - componentContext.put(ConfigModelConstant.PROPERTY_DICTIONARY_KEY_DOT + recipeName + ".service-instance-id", - "3c8d5a63-a793-4206-a67c-4b2e8e648196"); - componentContext.put(ConfigModelConstant.PROPERTY_DICTIONARY_KEY_DOT + recipeName + ".oam-network-role", - "sample"); - componentContext.put(ConfigModelConstant.PROPERTY_DICTIONARY_KEY_DOT + recipeName + ".oam-ipv4-ip-type", - "sample"); - componentContext.put(ConfigModelConstant.PROPERTY_DICTIONARY_KEY_DOT + recipeName + ".profile_name", "sample"); - componentContext.put(ConfigModelConstant.PROPERTY_DICTIONARY_KEY_DOT + recipeName + ".oam-vm-type", "sample"); - - Map inParams = new HashMap<>(); - SvcLogicContext ctx = new SvcLogicContext(); - // String datatypeContent = FileUtils.readFileToString(new - // File("src/test/resources/mapping/Mdsal/dt-v4-assigned-ip-list.json"), Charset.defaultCharset() ); - // ctx.setAttribute("data_types.dt-v4-assigned-ip-list", datatypeContent); - mdsalResourceProcessor.process(inParams, ctx, componentContext); - logger.info("Component Context = ({})", componentContext); - Assert.assertNotNull("failed to populate Array Complex response ", componentContext); - Assert.assertEquals("Compare String ", "10.66.1.152", - componentContext.get(ConfigModelConstant.PROPERTY_RECIPE_KEY_DOT + recipeName + ".v4-ip-prefix")); - - } - -} diff --git a/blueprints-processor/plugin/assignment-provider/src/test/java/org/onap/ccsdk/config/assignment/service/ConfigAssignmentNodeTest.java b/blueprints-processor/plugin/assignment-provider/src/test/java/org/onap/ccsdk/config/assignment/service/ConfigAssignmentNodeTest.java deleted file mode 100644 index 9ad94dcd0..000000000 --- a/blueprints-processor/plugin/assignment-provider/src/test/java/org/onap/ccsdk/config/assignment/service/ConfigAssignmentNodeTest.java +++ /dev/null @@ -1,246 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2018 IBM. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.ccsdk.config.assignment.service; - -import java.io.File; -import java.nio.charset.Charset; -import java.util.HashMap; -import java.util.Map; -import org.apache.commons.io.FileUtils; -import org.apache.commons.lang3.StringUtils; -import org.apache.sling.testing.mock.osgi.MockOsgi; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; -import org.junit.runner.RunWith; -import org.mockito.Mock; -import org.mockito.MockitoAnnotations; -import org.mockito.runners.MockitoJUnitRunner; -import org.onap.ccsdk.config.assignment.ConfigAssignmentConstants; -import org.onap.ccsdk.config.data.adaptor.service.ConfigResourceService; -import org.onap.ccsdk.config.generator.service.ConfigGeneratorService; -import org.onap.ccsdk.config.generator.service.ConfigGeneratorServiceImpl; -import org.onap.ccsdk.config.model.ConfigModelConstant; -import org.onap.ccsdk.config.model.service.ComponentNodeDelegate; -import org.onap.ccsdk.config.model.service.ComponentNodeService; -import org.onap.ccsdk.config.model.service.ComponentNodeServiceImpl; -import org.onap.ccsdk.config.model.service.ConfigModelService; -import org.onap.ccsdk.config.model.service.ConfigModelServiceImpl; -import org.onap.ccsdk.config.rest.adaptor.service.ConfigRestAdaptorService; -import org.onap.ccsdk.sli.core.sli.SvcLogicContext; -import org.osgi.framework.BundleContext; -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; - -@RunWith(MockitoJUnitRunner.class) -public class ConfigAssignmentNodeTest { - - private static EELFLogger logger = EELFManager.getInstance().getLogger(ConfigAssignmentNodeTest.class); - - @Rule - public ExpectedException thrown = ExpectedException.none(); - - @Mock - private ConfigResourceService configResourceService; - - @Mock - private ConfigRestAdaptorService configRestAdaptorService; - - private ConfigModelService configModelService; - - private ComponentNodeService componentNodeService; - - private ConfigGeneratorService configGeneratorService; - - BundleContext bundleContext = MockOsgi.newBundleContext(); - - @SuppressWarnings("unchecked") - @Before - public void before() throws Exception { - MockitoAnnotations.initMocks(this); - /* - * ConfigAssignmentNode configAssignmentNode = new ConfigAssignmentNode(componentNodeService, - * configResourceService, configModelService, configRestAdaptorService, configGeneratorService); - * bundleContext.registerService(ConfigAssignmentNode.class, configAssignmentNode, null); - */ - } - - @Test - public void testResourceAssignment() throws Exception { - ConfigResourceAssignmentTestUtils.injectTransactionLogSaveMock(configResourceService); - - ConfigResourceAssignmentTestUtils.injectConfigModelMock(configRestAdaptorService, "resource_assignment"); - - ConfigResourceAssignmentTestUtils.injectResourceDictionaryMock(configRestAdaptorService, - "assignments/empty-dictionary.json"); - - ConfigResourceAssignmentTestUtils.injectConfigResourceSaveMock(configResourceService); - - componentNodeService = - new ComponentNodeServiceImpl(bundleContext, configResourceService, configRestAdaptorService); - configModelService = new ConfigModelServiceImpl(configRestAdaptorService); - configGeneratorService = new ConfigGeneratorServiceImpl(configResourceService); - - ConfigAssignmentNode configAssignmentNode = new ConfigAssignmentNode(configResourceService, - configRestAdaptorService, configModelService, componentNodeService, configGeneratorService); - - String inputContent = FileUtils.readFileToString( - new File("src/test/resources/service_templates/input/input.json"), Charset.defaultCharset()); - - Map inParams = new HashMap<>(); - inParams.put(ConfigModelConstant.PROPERTY_SELECTOR, "test"); - inParams.put(ConfigAssignmentConstants.INPUT_PARAM_REQUEST_ID, "1234"); - inParams.put(ConfigAssignmentConstants.INPUT_PARAM_RESOURCE_ID, "resourceid-1234"); - inParams.put(ConfigAssignmentConstants.INPUT_PARAM_RESOURCE_TYPE, "vnf-type"); - inParams.put(ConfigModelConstant.SERVICE_TEMPLATE_KEY_ARTIFACT_NAME, "vpe-201802-baseconfig"); - inParams.put(ConfigModelConstant.SERVICE_TEMPLATE_KEY_ARTIFACT_VERSION, "1.0.0"); - inParams.put(ConfigModelConstant.PROPERTY_ACTION_NAME, "resource-assignment-action"); - inParams.put(ConfigAssignmentConstants.INPUT_PARAM_INPUT_DATA, inputContent); - inParams.put(ConfigAssignmentConstants.INPUT_PARAM_TEMPLATE_NAMES, "[\"base-config-template\"]"); - - // Populate the SvcContext ( Simulation) - SvcLogicContext svcLogicContext = new SvcLogicContext(); - Map context = new HashMap<>(); - context.put(ConfigModelConstant.PROPERTY_ACTION_NAME, "resource-assignment-action"); - context = configModelService.prepareContext(context, inputContent, "vpe-201802-baseconfig", "1.0.0"); - context.forEach((key, value) -> svcLogicContext.setAttribute(key, value)); - - Map componentContext = new HashMap<>(); - configAssignmentNode.process(inParams, svcLogicContext, componentContext); - Assert.assertNotNull("Failed to get response status", svcLogicContext.getAttribute("test.status")); - - } - - @Test - public void testSimplePreview() throws Exception { - ConfigResourceAssignmentTestUtils.injectTransactionLogSaveMock(configResourceService); - - ConfigResourceAssignmentTestUtils.injectConfigModelMock(configRestAdaptorService, "resource_assignment"); - - ConfigResourceAssignmentTestUtils.injectResourceDictionaryMock(configRestAdaptorService, - "assignments/empty-dictionary.json"); - - ConfigResourceAssignmentTestUtils.injectConfigResourceSaveMock(configResourceService); - - componentNodeService = - new ComponentNodeServiceImpl(bundleContext, configResourceService, configRestAdaptorService); - configModelService = new ConfigModelServiceImpl(configRestAdaptorService); - configGeneratorService = new ConfigGeneratorServiceImpl(configResourceService); - - ConfigAssignmentNode configAssignmentNode = new ConfigAssignmentNode(configResourceService, - configRestAdaptorService, configModelService, componentNodeService, configGeneratorService); - - String inputContent = FileUtils.readFileToString( - new File("src/test/resources/service_templates/input/input.json"), Charset.defaultCharset()); - - Map inParams = new HashMap<>(); - inParams.put(ConfigModelConstant.PROPERTY_SELECTOR, "test"); - inParams.put(ConfigAssignmentConstants.INPUT_PARAM_REQUEST_ID, "1234"); - inParams.put(ConfigAssignmentConstants.INPUT_PARAM_RESOURCE_ID, "resourceid-1234"); - inParams.put(ConfigAssignmentConstants.INPUT_PARAM_RESOURCE_TYPE, "vnf-type"); - inParams.put(ConfigModelConstant.SERVICE_TEMPLATE_KEY_ARTIFACT_NAME, "vpe-201802-baseconfig"); - inParams.put(ConfigModelConstant.SERVICE_TEMPLATE_KEY_ARTIFACT_VERSION, "1.0.0"); - inParams.put(ConfigModelConstant.PROPERTY_ACTION_NAME, "resource-assignment-action"); - inParams.put(ConfigAssignmentConstants.INPUT_PARAM_INPUT_DATA, inputContent); - inParams.put(ConfigAssignmentConstants.INPUT_PARAM_TEMPLATE_NAMES, "[\"base-config-template\"]"); - SvcLogicContext ctx = new SvcLogicContext(); - configAssignmentNode.process(inParams, ctx); - Assert.assertNotNull("Failed to get response mashed Content", - ctx.getAttribute("test.mashed-data.base-config-template")); - } - - @Test - public void testComplexPreview() throws Exception { - ConfigResourceAssignmentTestUtils.injectTransactionLogSaveMock(configResourceService); - - ConfigResourceAssignmentTestUtils.injectConfigModelMock(configRestAdaptorService, "vpe-201802-baseconfig"); - - ConfigResourceAssignmentTestUtils.injectResourceDictionaryMock(configRestAdaptorService, - "service_templates/vpe-201802-baseconfig/dict.json"); - - ConfigResourceAssignmentTestUtils.injectConfigResourceSaveMock(configResourceService); - - componentNodeService = - new ComponentNodeServiceImpl(bundleContext, configResourceService, configRestAdaptorService); - configModelService = new ConfigModelServiceImpl(configRestAdaptorService); - configGeneratorService = new ConfigGeneratorServiceImpl(configResourceService); - - ConfigAssignmentNode configAssignmentNode = new ConfigAssignmentNode(configResourceService, - configRestAdaptorService, configModelService, componentNodeService, configGeneratorService); - - String inputContent = FileUtils.readFileToString( - new File("src/test/resources/service_templates/vpe-201802-baseconfig/input-complex.json"), - Charset.defaultCharset()); - - Map inParams = new HashMap<>(); - inParams.put(ConfigModelConstant.PROPERTY_SELECTOR, "complex-test"); - inParams.put(ConfigAssignmentConstants.INPUT_PARAM_REQUEST_ID, "request-1234"); - inParams.put(ConfigAssignmentConstants.INPUT_PARAM_RESOURCE_ID, "resourceid-1234"); - inParams.put(ConfigAssignmentConstants.INPUT_PARAM_RESOURCE_TYPE, "vnf-type"); - inParams.put(ConfigModelConstant.SERVICE_TEMPLATE_KEY_ARTIFACT_NAME, "vpe-201802-baseconfig"); - inParams.put(ConfigModelConstant.SERVICE_TEMPLATE_KEY_ARTIFACT_VERSION, "1.0.0"); - inParams.put(ConfigModelConstant.PROPERTY_ACTION_NAME, "resource-assignment-action"); - inParams.put(ConfigAssignmentConstants.INPUT_PARAM_INPUT_DATA, inputContent); - inParams.put(ConfigAssignmentConstants.INPUT_PARAM_TEMPLATE_NAMES, "[\"base-config-template\"]"); - SvcLogicContext ctx = new SvcLogicContext(); - configAssignmentNode.process(inParams, ctx); - Assert.assertNotNull("Failed to get response mashed Content", - ctx.getAttribute("complex-test.mashed-data.base-config-template")); - - } - - @Test - public void inputValidator() { - SvcLogicContext ctx = new SvcLogicContext(); - try { - - logger.info(" ******************************* inputValidator ***************************"); - String serviceTemplateContent = FileUtils.readFileToString( - new File("src/test/resources/service_templates/resource_assignment.json"), - Charset.defaultCharset()); - - String inputcontent = FileUtils.readFileToString( - new File("src/test/resources/service_templates/input/inputValidateTest.json"), - Charset.defaultCharset()); - - Map context = new HashMap<>(); - configModelService.prepareContext(context, inputcontent, serviceTemplateContent); - - // TransformationUtils.printMap(context); - - context.forEach((name, value) -> { - if (StringUtils.isNotBlank(name) && StringUtils.isNotBlank(value)) { - ctx.setAttribute(name, value); - } - }); - - ComponentNodeDelegate componentNodeDelegate = new ComponentNodeDelegate(componentNodeService); - Map inParams = new HashMap<>(); - inParams.put(ConfigModelConstant.PROPERTY_SELECTOR, "resource-assignment"); - componentNodeDelegate.process(inParams, ctx); - Assert.fail(); - } catch (Exception e) { - logger.error("Failed in inputValidator" + e.getMessage()); - logger.info("** ctx.getAttribute Check for **" + ctx.getAttribute("resource-assignment.error-message")); - } - - } - -} diff --git a/blueprints-processor/plugin/assignment-provider/src/test/java/org/onap/ccsdk/config/assignment/service/ConfigPreviewServiceTest.java b/blueprints-processor/plugin/assignment-provider/src/test/java/org/onap/ccsdk/config/assignment/service/ConfigPreviewServiceTest.java deleted file mode 100644 index 75b7f2e28..000000000 --- a/blueprints-processor/plugin/assignment-provider/src/test/java/org/onap/ccsdk/config/assignment/service/ConfigPreviewServiceTest.java +++ /dev/null @@ -1,111 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2018 IBM. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.ccsdk.config.assignment.service; - -import java.io.File; -import java.nio.charset.Charset; -import org.apache.commons.io.FileUtils; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; -import org.junit.runner.RunWith; -import org.mockito.Mock; -import org.mockito.MockitoAnnotations; -import org.mockito.runners.MockitoJUnitRunner; -import org.onap.ccsdk.config.assignment.data.ResourceAssignmentData; -import org.onap.ccsdk.config.data.adaptor.domain.ConfigResource; -import org.onap.ccsdk.config.data.adaptor.service.ConfigResourceService; -import org.onap.ccsdk.config.generator.service.ConfigGeneratorService; -import org.onap.ccsdk.config.generator.service.ConfigGeneratorServiceImpl; -import org.onap.ccsdk.config.model.service.ConfigModelService; -import org.onap.ccsdk.config.model.service.ConfigModelServiceImpl; -import org.onap.ccsdk.config.rest.adaptor.service.ConfigRestAdaptorService; -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; - -@RunWith(MockitoJUnitRunner.class) -public class ConfigPreviewServiceTest { - - private static EELFLogger logger = EELFManager.getInstance().getLogger(ConfigPreviewServiceTest.class); - - @Rule - public ExpectedException thrown = ExpectedException.none(); - - @Mock - private ConfigResourceService configResourceService; - - @Mock - private ConfigRestAdaptorService configRestAdaptorService; - - private ConfigModelService configModelService; - private ConfigGeneratorService configGeneratorService; - - @SuppressWarnings("unchecked") - @Before - public void before() throws Exception { - MockitoAnnotations.initMocks(this); - } - - @Test - public void testGenerateTemplateResourceMash() throws Exception { - - ConfigResourceAssignmentTestUtils.injectTransactionLogSaveMock(configResourceService); - - ConfigResourceAssignmentTestUtils.injectConfigModelMock(configRestAdaptorService, "resource_assignment"); - - ConfigResourceAssignmentTestUtils.injectResourceDictionaryMock(configRestAdaptorService, - "assignments/empty-dictionary.json"); - - ConfigResource configResourceQuery = new ConfigResource(); - configResourceQuery.setServiceTemplateVersion("sample-serviceTemplateName"); - configResourceQuery.setServiceTemplateVersion("1.0.0"); - configResourceQuery.setRecipeName("sample-action"); - configResourceQuery.setResourceId("123-resourceId"); - configResourceQuery.setResourceType("sample-resourceType"); - configResourceQuery.setTemplateName("base-config-template"); - String inputContent = FileUtils.readFileToString( - new File("src/test/resources/service_templates/input/input.json"), Charset.defaultCharset()); - configResourceQuery.setResourceData(inputContent); - - ConfigResourceAssignmentTestUtils.injectGetConfigResourceMock(configResourceService, configResourceQuery); - - configModelService = new ConfigModelServiceImpl(configRestAdaptorService); - configGeneratorService = new ConfigGeneratorServiceImpl(configResourceService); - - ConfigPreviewService configPreviewService = - new ConfigPreviewService(configResourceService, configModelService, configGeneratorService); - - ResourceAssignmentData resourceAssignmentData = new ResourceAssignmentData(); - resourceAssignmentData.setResourceId("123-resourceId"); - resourceAssignmentData.setResourceType("sample-resourceType"); - resourceAssignmentData.setServiceTemplateName("sample-serviceTemplateName"); - resourceAssignmentData.setServiceTemplateVersion("1.0.0"); - resourceAssignmentData.setActionName("sample-action"); - - resourceAssignmentData = configPreviewService.generateTemplateResourceMash(resourceAssignmentData); - - Assert.assertNotNull("Failed to get GenerateTemplateResourceMash response.", resourceAssignmentData); - Assert.assertNotNull("Failed to get template mashed contents.", - resourceAssignmentData.getTemplatesMashedContents()); - - Assert.assertNotNull("Failed to get base-config template mashed contents.", - resourceAssignmentData.getTemplatesMashedContents().get("base-config-template")); - } -} diff --git a/blueprints-processor/plugin/assignment-provider/src/test/java/org/onap/ccsdk/config/assignment/service/ConfigResourceAssignmentTestUtils.java b/blueprints-processor/plugin/assignment-provider/src/test/java/org/onap/ccsdk/config/assignment/service/ConfigResourceAssignmentTestUtils.java deleted file mode 100644 index ee1c076ae..000000000 --- a/blueprints-processor/plugin/assignment-provider/src/test/java/org/onap/ccsdk/config/assignment/service/ConfigResourceAssignmentTestUtils.java +++ /dev/null @@ -1,182 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2018 IBM. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.ccsdk.config.assignment.service; - -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyString; -import java.io.File; -import java.nio.charset.Charset; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.List; -import java.util.Map; -import org.apache.commons.io.FileUtils; -import org.apache.commons.io.FilenameUtils; -import org.apache.commons.io.IOUtils; -import org.mockito.Matchers; -import org.mockito.Mockito; -import org.mockito.invocation.InvocationOnMock; -import org.mockito.stubbing.Answer; -import org.onap.ccsdk.config.data.adaptor.domain.ConfigResource; -import org.onap.ccsdk.config.data.adaptor.domain.TransactionLog; -import org.onap.ccsdk.config.data.adaptor.service.ConfigResourceService; -import org.onap.ccsdk.config.model.ConfigModelConstant; -import org.onap.ccsdk.config.model.data.dict.ResourceDefinition; -import org.onap.ccsdk.config.model.domain.ConfigModel; -import org.onap.ccsdk.config.model.domain.ConfigModelContent; -import org.onap.ccsdk.config.rest.adaptor.service.ConfigRestAdaptorService; -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; -import com.fasterxml.jackson.core.type.TypeReference; -import com.fasterxml.jackson.databind.ObjectMapper; - -public class ConfigResourceAssignmentTestUtils { - - private static EELFLogger logger = EELFManager.getInstance().getLogger(ConfigResourceAssignmentTestUtils.class); - - public static void injectTransactionLogSaveMock(ConfigResourceService configResourceService) throws Exception { - Mockito.doAnswer(new Answer() { - @Override - public Void answer(InvocationOnMock invocationOnMock) throws Throwable { - Object[] args = invocationOnMock.getArguments(); - if (args != null) { - logger.trace("Transaction info " + Arrays.asList(args)); - } - return null; - } - }).when(configResourceService).save(any(TransactionLog.class)); - } - - public static void injectConfigModelMock(ConfigRestAdaptorService configRestAdaptorService, - String serviceTemplateName) throws Exception { - - Mockito.doAnswer(new Answer() { - @Override - public org.onap.ccsdk.config.model.domain.ConfigModel answer(InvocationOnMock invocationOnMock) - throws Throwable { - Object[] args = invocationOnMock.getArguments(); - org.onap.ccsdk.config.model.domain.ConfigModel serviceArtifact = null; - if (args != null && args.length == 3) { - - logger.info("Artifact info " + Arrays.asList(args)); - String modelContent = IOUtils.toString( - ConfigResourceAssignmentTestUtils.class.getClassLoader().getResourceAsStream( - "service_templates/" + serviceTemplateName + "/" + serviceTemplateName + ".json"), - Charset.defaultCharset()); - - ConfigModelContent configModelContent = new ConfigModelContent(); - configModelContent.setContent(modelContent); - configModelContent.setContentType(ConfigModelConstant.MODEL_CONTENT_TYPE_TOSCA_JSON); - - List configModelContents = new ArrayList<>(); - configModelContents.add(configModelContent); - - String velocityDir = ConfigResourceAssignmentTestUtils.class.getClassLoader() - .getResource("service_templates/" + serviceTemplateName + "/velocity").getPath(); - - Collection templateFiles = - FileUtils.listFiles(new File(velocityDir), new String[] {"vtl"}, true); - logger.info("Template Files info " + templateFiles); - for (File templateFile : templateFiles) { - String templateContent = FileUtils.readFileToString(templateFile, Charset.defaultCharset()); - ConfigModelContent configModelTemplateContent = new ConfigModelContent(); - configModelTemplateContent.setContent(templateContent); - configModelTemplateContent.setName(FilenameUtils.getBaseName(templateFile.getName())); - configModelTemplateContent.setContentType(ConfigModelConstant.MODEL_CONTENT_TYPE_TEMPLATE); - configModelContents.add(configModelTemplateContent); - } - - serviceArtifact = new org.onap.ccsdk.config.model.domain.ConfigModel(); - serviceArtifact.setArtifactName(String.valueOf(args[0])); - serviceArtifact.setArtifactVersion(String.valueOf(args[1])); - serviceArtifact.setPublished("Y"); - serviceArtifact.setConfigModelContents(configModelContents); - } - - return serviceArtifact; - } - }).when(configRestAdaptorService).getResource(anyString(), anyString(), Matchers.any(Class.class)); - } - - public static void injectResourceDictionaryMock(ConfigRestAdaptorService configRestAdaptorService, - String dictionaryFileName) throws Exception { - - Mockito.doAnswer(new Answer() { - @Override - public String answer(InvocationOnMock invocationOnMock) throws Throwable { - Object[] args = invocationOnMock.getArguments(); - String dictionaties = "[]"; - if (args != null) { - logger.info("getResourceDictionaryByNames " + Arrays.asList(args)); - dictionaties = IOUtils.toString( - ConfigAssignmentNodeTest.class.getClassLoader().getResourceAsStream(dictionaryFileName), - Charset.defaultCharset()); - } - return dictionaties; - } - }).when(configRestAdaptorService).postResource(Matchers.any(), Matchers.any(), Matchers.any(), - Matchers.any(Class.class)); - } - - public static void injectConfigResourceSaveMock(ConfigResourceService configResourceService) throws Exception { - Mockito.doAnswer(new Answer() { - @Override - public ConfigResource answer(InvocationOnMock invocationOnMock) throws Throwable { - Object[] args = invocationOnMock.getArguments(); - ConfigResource configResource = null; - if (args != null) { - configResource = (ConfigResource) args[0]; - logger.info("Config Resource Save info " + configResource); - return configResource; - } - return configResource; - } - }).when(configResourceService).saveConfigResource(any(ConfigResource.class)); - } - - public static void injectGetConfigResourceMock(ConfigResourceService configResourceService, - ConfigResource configResource) throws Exception { - Mockito.doAnswer(new Answer>() { - @Override - public List answer(InvocationOnMock invocationOnMock) throws Throwable { - Object[] args = invocationOnMock.getArguments(); - List configResources = new ArrayList<>(); - if (args != null) { - configResources.add(configResource); - } - return configResources; - } - }).when(configResourceService).getConfigResource(any(ConfigResource.class)); - } - - public static String getFileContent(String filePath) throws Exception { - return IOUtils.toString(ConfigResourceAssignmentTestUtils.class.getClassLoader().getResourceAsStream(filePath), - Charset.defaultCharset()); - } - - public static Map getMapfromJson(String content) { - try { - ObjectMapper mapper = new ObjectMapper(); - return mapper.readValue(content, new TypeReference>() {}); - } catch (Exception e) { - logger.info("getMapfromJson Exception ({})", e); - } - return null; - } -} diff --git a/blueprints-processor/plugin/assignment-provider/src/test/java/org/onap/ccsdk/config/assignment/service/ResourceAssignmentGenerationTest.java b/blueprints-processor/plugin/assignment-provider/src/test/java/org/onap/ccsdk/config/assignment/service/ResourceAssignmentGenerationTest.java deleted file mode 100644 index 3dc7da7eb..000000000 --- a/blueprints-processor/plugin/assignment-provider/src/test/java/org/onap/ccsdk/config/assignment/service/ResourceAssignmentGenerationTest.java +++ /dev/null @@ -1,110 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2018 IBM. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.ccsdk.config.assignment.service; - -import java.nio.charset.Charset; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import org.apache.commons.io.IOUtils; -import org.junit.Assert; -import org.junit.Test; -import org.onap.ccsdk.config.model.ConfigModelConstant; -import org.onap.ccsdk.config.model.ValidTypes; -import org.onap.ccsdk.config.model.data.ResourceAssignment; -import org.onap.ccsdk.config.model.utils.ResourceAssignmentUtils; -import org.onap.ccsdk.config.model.utils.TransformationUtils; -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; -import com.fasterxml.jackson.databind.JsonNode; - -public class ResourceAssignmentGenerationTest { - - private static EELFLogger logger = EELFManager.getInstance().getLogger(ResourceAssignmentGenerationTest.class); - - @Test - public void testResourceDataSetting() { - try { - logger.info(" **************** testResourceDataSetting *****************"); - String resourceAssignmentContents = IOUtils.toString(TopologicalSortingTest.class.getClassLoader() - .getResourceAsStream("assignments/alltype-empty-value-mapping.json"), Charset.defaultCharset()); - - List assignments = - TransformationUtils.getListfromJson(resourceAssignmentContents, ResourceAssignment.class); - if (assignments != null) { - Map componentContext = new HashMap<>(); - componentContext.put(ConfigModelConstant.PROPERTY_ACTION_NAME, "sample-recipe"); - for (ResourceAssignment resourceAssignment : assignments) { - if (resourceAssignment != null && resourceAssignment.getProperty() != null) { - String type = resourceAssignment.getProperty().getType(); - Object value = null; - if (ValidTypes.DATA_TYPE_STRING.equals(type)) { - value = new String("abcdef"); - } else if (ValidTypes.DATA_TYPE_INTEGER.equals(type)) { - value = new Integer(1234); - } else if (ValidTypes.DATA_TYPE_BOOLEAN.equals(type)) { - value = new Boolean(true); - } else if (ValidTypes.DATA_TYPE_LIST.equals(type)) { - String entityType = resourceAssignment.getProperty().getEntrySchema().getType(); - if (ValidTypes.DATA_TYPE_STRING.equals(entityType)) { - value = "[\"abcd-array\"]"; - } else { - String content = "[{\"name\" : \"abcd-array-complex\"}]"; - JsonNode node = TransformationUtils.getJsonNodeForString(content); - value = node; - } - } else { - String content = "{\"name\" : \"abcd-complex\"}"; - JsonNode node = TransformationUtils.getJsonNodeForString(content); - value = node; - } - ResourceAssignmentUtils.setResourceDataValue(componentContext, resourceAssignment, value); - } - } - String generatedData = ResourceAssignmentUtils.generateResourceDataForAssignments(assignments); - logger.trace("Generated Data " + generatedData); - - Assert.assertNotNull("Failed to generate resource data", generatedData); - } - } catch (Exception e) { - e.printStackTrace(); - } - } - - @Test - public void testGenerateResourceData() { - try { - logger.info(" **************** testGenerateResourceData *****************"); - String resourceAssignmentContents = IOUtils.toString(TopologicalSortingTest.class.getClassLoader() - .getResourceAsStream("assignments/alltype-mapping.json"), Charset.defaultCharset()); - - List assignments = - TransformationUtils.getListfromJson(resourceAssignmentContents, ResourceAssignment.class); - if (assignments != null) { - - String generatedData = ResourceAssignmentUtils.generateResourceDataForAssignments(assignments); - logger.trace("Generated Data " + generatedData); - - Assert.assertNotNull("Failed to generate resource data", generatedData); - } - } catch (Exception e) { - e.printStackTrace(); - } - } - -} diff --git a/blueprints-processor/plugin/assignment-provider/src/test/java/org/onap/ccsdk/config/assignment/service/ResourceAssignmentValidation.java b/blueprints-processor/plugin/assignment-provider/src/test/java/org/onap/ccsdk/config/assignment/service/ResourceAssignmentValidation.java deleted file mode 100644 index d708404f5..000000000 --- a/blueprints-processor/plugin/assignment-provider/src/test/java/org/onap/ccsdk/config/assignment/service/ResourceAssignmentValidation.java +++ /dev/null @@ -1,94 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2018 IBM. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.ccsdk.config.assignment.service; - -import java.io.IOException; -import java.nio.charset.Charset; -import java.util.List; -import org.apache.commons.io.IOUtils; -import org.junit.Assert; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; -import org.onap.ccsdk.config.model.ConfigModelException; -import org.onap.ccsdk.config.model.data.ResourceAssignment; -import org.onap.ccsdk.config.model.utils.TransformationUtils; -import org.onap.ccsdk.config.model.validator.ResourceAssignmentValidator; -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; - -public class ResourceAssignmentValidation { - private static EELFLogger logger = EELFManager.getInstance().getLogger(ResourceAssignmentValidation.class); - - @Rule - public final ExpectedException exception = ExpectedException.none(); - - @Test - public void testValidateSuccess() { - try { - logger.info(" **************** testValidateSuccess *****************"); - String resourceMapping = IOUtils.toString( - TopologicalSortingTest.class.getClassLoader().getResourceAsStream("validation/success.json"), - Charset.defaultCharset()); - - List assignments = - TransformationUtils.getListfromJson(resourceMapping, ResourceAssignment.class); - if (assignments != null) { - ResourceAssignmentValidator resourceAssignmentValidator = new ResourceAssignmentValidator(assignments); - - boolean result = resourceAssignmentValidator.validateResourceAssignment(); - Assert.assertTrue("Failed to Validate", result); - } - } catch (Exception e) { - e.printStackTrace(); - } - } - - @Test(expected = ConfigModelException.class) - public void testValidateDuplicate() throws IOException, ConfigModelException { - logger.info(" **************** testValidateDuplicate *****************"); - String resourceMapping = IOUtils.toString( - TopologicalSortingTest.class.getClassLoader().getResourceAsStream("validation/duplicate.json"), - Charset.defaultCharset()); - - List assignments = - TransformationUtils.getListfromJson(resourceMapping, ResourceAssignment.class); - if (assignments != null) { - ResourceAssignmentValidator resourceAssignmentValidator = new ResourceAssignmentValidator(assignments); - resourceAssignmentValidator.validateResourceAssignment(); - } - - } - - @Test(expected = ConfigModelException.class) - public void testValidateCyclic() throws IOException, ConfigModelException { - logger.info(" **************** testValidateCyclic *****************"); - String resourceMapping = IOUtils.toString( - TopologicalSortingTest.class.getClassLoader().getResourceAsStream("validation/cyclic.json"), - Charset.defaultCharset()); - - List assignments = - TransformationUtils.getListfromJson(resourceMapping, ResourceAssignment.class); - if (assignments != null) { - ResourceAssignmentValidator resourceAssignmentValidator = new ResourceAssignmentValidator(assignments); - - resourceAssignmentValidator.validateResourceAssignment(); - } - - } -} diff --git a/blueprints-processor/plugin/assignment-provider/src/test/java/org/onap/ccsdk/config/assignment/service/TopologicalSortingTest.java b/blueprints-processor/plugin/assignment-provider/src/test/java/org/onap/ccsdk/config/assignment/service/TopologicalSortingTest.java deleted file mode 100644 index e4b7f5dee..000000000 --- a/blueprints-processor/plugin/assignment-provider/src/test/java/org/onap/ccsdk/config/assignment/service/TopologicalSortingTest.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2018 IBM. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.ccsdk.config.assignment.service; - -import java.nio.charset.Charset; -import java.util.List; -import org.apache.commons.io.IOUtils; -import org.junit.Assert; -import org.junit.Test; -import org.onap.ccsdk.config.assignment.processor.ResourceAssignmentProcessor; -import org.onap.ccsdk.config.model.data.ResourceAssignment; -import org.onap.ccsdk.config.model.utils.TransformationUtils; -import org.onap.ccsdk.sli.core.sli.SvcLogicContext; -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; - -public class TopologicalSortingTest { - private static EELFLogger logger = EELFManager.getInstance().getLogger(TopologicalSortingTest.class); - - @Test - public void testBulkSequencingMapping() { - try { - logger.info(" **************** Bulk Sequencing Default *****************"); - String resourceMapping = IOUtils.toString( - TopologicalSortingTest.class.getClassLoader().getResourceAsStream("mapping/dependency.json"), - Charset.defaultCharset()); - - List assignments = - TransformationUtils.getListfromJson(resourceMapping, ResourceAssignment.class); - if (assignments != null) { - SvcLogicContext ctx = new SvcLogicContext(); - ResourceAssignmentProcessor resourceAssignmentProcessor = - new ResourceAssignmentProcessor(assignments, ctx); - List> sequenceBatchResourceAssignment = resourceAssignmentProcessor.process(); - - Assert.assertNotNull("Failed to populate Sequence Bulk Mappings", sequenceBatchResourceAssignment); - Assert.assertNotEquals("Failed to populate Sequence Bulk Mappings size ", - (sequenceBatchResourceAssignment.size() > 0)); - } - } catch (Exception e) { - e.printStackTrace(); - } - } - -} diff --git a/blueprints-processor/plugin/assignment-provider/src/test/java/org/onap/ccsdk/features/assignment/processor/DBResourceProcessorTest.java b/blueprints-processor/plugin/assignment-provider/src/test/java/org/onap/ccsdk/features/assignment/processor/DBResourceProcessorTest.java new file mode 100644 index 000000000..43a4881d5 --- /dev/null +++ b/blueprints-processor/plugin/assignment-provider/src/test/java/org/onap/ccsdk/features/assignment/processor/DBResourceProcessorTest.java @@ -0,0 +1,232 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2018 IBM. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.ccsdk.features.assignment.processor; + +import static org.mockito.Matchers.any; +import java.io.File; +import java.nio.charset.Charset; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import org.apache.commons.io.FileUtils; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Matchers; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.MockitoAnnotations; +import org.mockito.invocation.InvocationOnMock; +import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.stubbing.Answer; +import org.onap.ccsdk.features.assignment.processor.DBResourceProcessor; +import org.onap.ccsdk.features.assignment.service.ConfigResourceAssignmentTestUtils; +import org.onap.ccsdk.features.data.adaptor.domain.TransactionLog; +import org.onap.ccsdk.features.data.adaptor.service.ConfigResourceService; +import org.onap.ccsdk.features.model.ConfigModelConstant; +import org.onap.ccsdk.features.model.data.ResourceAssignment; +import org.onap.ccsdk.features.model.data.dict.ResourceDefinition; +import org.onap.ccsdk.features.model.utils.TransformationUtils; +import org.onap.ccsdk.sli.core.sli.SvcLogicContext; +import org.onap.ccsdk.sli.core.sli.SvcLogicException; +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; + +@RunWith(MockitoJUnitRunner.class) +public class DBResourceProcessorTest { + + private static EELFLogger logger = EELFManager.getInstance().getLogger(DBResourceProcessorTest.class); + + @Mock + private ConfigResourceService configResourceService; + + @SuppressWarnings("unchecked") + @Before + public void before() { + MockitoAnnotations.initMocks(this); + + try { + Mockito.doAnswer(new Answer() { + @Override + public Void answer(InvocationOnMock invocationOnMock) throws Throwable { + Object[] args = invocationOnMock.getArguments(); + if (args != null) { + logger.trace("Transaction info " + Arrays.asList(args)); + } + return null; + } + }).when(configResourceService).save(any(TransactionLog.class)); + + } catch (SvcLogicException e) { + e.printStackTrace(); + } + } + + @Test + public void testDbSimpleProcess() throws Exception { + logger.info(" ******************************* testDbSimpleProcess ***************************"); + + Mockito.doAnswer(new Answer>>() { + @Override + public List> answer(InvocationOnMock invocationOnMock) throws Throwable { + Object[] args = invocationOnMock.getArguments(); + List> results = new ArrayList<>(); + if (args != null) { + logger.info("Query " + Arrays.asList(args)); + Map record = new HashMap<>(); + record.put("country", "US"); + results.add(record); + } + return results; + } + }).when(configResourceService).query(Matchers.anyString(), Matchers.>any()); + + String recipeName = "sample-recipe"; + + String resourceassignmentContent = FileUtils.readFileToString( + new File("src/test/resources/mapping/db/resource-assignments-simple.json"), Charset.defaultCharset()); + List batchResourceAssignment = + TransformationUtils.getListfromJson(resourceassignmentContent, ResourceAssignment.class); + + String dictionaryContent = FileUtils.readFileToString(new File("src/test/resources/mapping/db/db-simple.json"), + Charset.defaultCharset()); + Map dictionaries = + ConfigResourceAssignmentTestUtils.getMapfromJson(dictionaryContent); + DBResourceProcessor dbResourceProcessor = new DBResourceProcessor(configResourceService); + Map componentContext = new HashMap<>(); + componentContext.put(ConfigModelConstant.PROPERTY_RESOURCE_ASSIGNMENTS, batchResourceAssignment); + componentContext.put(ConfigModelConstant.PROPERTY_ACTION_NAME, recipeName); + componentContext.put(ConfigModelConstant.PROPERTY_TEMPLATE_NAME, "sample-template"); + componentContext.put(ConfigModelConstant.PROPERTY_DICTIONARIES, dictionaries); + + componentContext.put(ConfigModelConstant.PROPERTY_DICTIONARY_KEY_DOT + recipeName + ".profile_name", "sample"); + + Map inParams = new HashMap<>(); + SvcLogicContext ctx = new SvcLogicContext(); + dbResourceProcessor.process(inParams, ctx, componentContext); + + logger.info(" Context " + componentContext); + + } + + @Test + public void testDbComplexProcess() throws Exception { + logger.info(" ******************************* testDbComplexProcess ***************************"); + + Mockito.doAnswer(new Answer>>() { + @Override + public List> answer(InvocationOnMock invocationOnMock) throws Throwable { + Object[] args = invocationOnMock.getArguments(); + List> results = new ArrayList<>(); + if (args != null) { + logger.info("Query " + Arrays.asList(args)); + Map record = new HashMap<>(); + record.put("db-country", "US"); + record.put("db-state", "NJ"); + results.add(record); + } + return results; + } + }).when(configResourceService).query(Matchers.anyString(), Matchers.>any()); + + String recipeName = "sample-recipe"; + + String resourceassignmentContent = FileUtils.readFileToString( + new File("src/test/resources/mapping/db/resource-assignments-complex.json"), Charset.defaultCharset()); + List batchResourceAssignment = + TransformationUtils.getListfromJson(resourceassignmentContent, ResourceAssignment.class); + + String dictionaryContent = FileUtils.readFileToString(new File("src/test/resources/mapping/db/db-complex.json"), + Charset.defaultCharset()); + Map dictionaries = + ConfigResourceAssignmentTestUtils.getMapfromJson(dictionaryContent); + DBResourceProcessor dbResourceProcessor = new DBResourceProcessor(configResourceService); + Map componentContext = new HashMap<>(); + componentContext.put(ConfigModelConstant.PROPERTY_RESOURCE_ASSIGNMENTS, batchResourceAssignment); + componentContext.put(ConfigModelConstant.PROPERTY_ACTION_NAME, recipeName); + componentContext.put(ConfigModelConstant.PROPERTY_TEMPLATE_NAME, "sample-template"); + componentContext.put(ConfigModelConstant.PROPERTY_DICTIONARIES, dictionaries); + componentContext.put(ConfigModelConstant.PROPERTY_DICTIONARY_KEY_DOT + recipeName + ".profile_name", "sample"); + + Map inParams = new HashMap<>(); + SvcLogicContext ctx = new SvcLogicContext(); + String datatypeContent = FileUtils.readFileToString(new File("src/test/resources/mapping/db/dt-location.json"), + Charset.defaultCharset()); + ctx.setAttribute("data_types.dt-location", datatypeContent); + dbResourceProcessor.process(inParams, ctx, componentContext); + + } + + @Test + public void testDbArrayComplexProcess() throws Exception { + logger.info(" ******************************* testDbArrayComplexProcess ***************************"); + Mockito.doAnswer(new Answer>>() { + @Override + public List> answer(InvocationOnMock invocationOnMock) throws Throwable { + Object[] args = invocationOnMock.getArguments(); + List> results = new ArrayList<>(); + if (args != null) { + logger.info("Query " + Arrays.asList(args)); + Map record = new HashMap<>(); + record.put("db-country", "US"); + record.put("db-state", "NJ"); + results.add(record); + + Map record2 = new HashMap<>(); + record2.put("db-country", "INDIA"); + record2.put("db-state", "TN"); + results.add(record2); + } + return results; + } + }).when(configResourceService).query(Matchers.anyString(), Matchers.>any()); + + String recipeName = "sample-recipe"; + + String resourceassignmentContent = FileUtils.readFileToString( + new File("src/test/resources/mapping/db/resource-assignments-array.json"), Charset.defaultCharset()); + List batchResourceAssignment = + TransformationUtils.getListfromJson(resourceassignmentContent, ResourceAssignment.class); + + String dictionaryContent = FileUtils.readFileToString(new File("src/test/resources/mapping/db/db-array.json"), + Charset.defaultCharset()); + Map dictionaries = + ConfigResourceAssignmentTestUtils.getMapfromJson(dictionaryContent); + DBResourceProcessor dbResourceProcessor = new DBResourceProcessor(configResourceService); + Map componentContext = new HashMap<>(); + componentContext.put(ConfigModelConstant.PROPERTY_RESOURCE_ASSIGNMENTS, batchResourceAssignment); + componentContext.put(ConfigModelConstant.PROPERTY_ACTION_NAME, recipeName); + componentContext.put(ConfigModelConstant.PROPERTY_TEMPLATE_NAME, "sample-template"); + componentContext.put(ConfigModelConstant.PROPERTY_DICTIONARIES, dictionaries); + componentContext.put(ConfigModelConstant.PROPERTY_DICTIONARY_KEY_DOT + recipeName + ".profile_name", "sample"); + + Map inParams = new HashMap<>(); + SvcLogicContext ctx = new SvcLogicContext(); + String datatypeContent = FileUtils.readFileToString(new File("src/test/resources/mapping/db/dt-location.json"), + Charset.defaultCharset()); + ctx.setAttribute("data_types.dt-location", datatypeContent); + dbResourceProcessor.process(inParams, ctx, componentContext); + logger.info("Component Context = ({})", componentContext); + Assert.assertNotNull("faile dto populate Array Complex response ", componentContext); + + } + +} diff --git a/blueprints-processor/plugin/assignment-provider/src/test/java/org/onap/ccsdk/features/assignment/processor/DefaultResourceProcessorTest.java b/blueprints-processor/plugin/assignment-provider/src/test/java/org/onap/ccsdk/features/assignment/processor/DefaultResourceProcessorTest.java new file mode 100644 index 000000000..df3800387 --- /dev/null +++ b/blueprints-processor/plugin/assignment-provider/src/test/java/org/onap/ccsdk/features/assignment/processor/DefaultResourceProcessorTest.java @@ -0,0 +1,128 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2018 IBM. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.ccsdk.features.assignment.processor; + +import static org.mockito.Matchers.any; +import java.io.File; +import java.nio.charset.Charset; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import org.apache.commons.io.FileUtils; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.MockitoAnnotations; +import org.mockito.invocation.InvocationOnMock; +import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.stubbing.Answer; +import org.onap.ccsdk.features.assignment.processor.DefaultResourceProcessor; +import org.onap.ccsdk.features.assignment.service.ConfigResourceAssignmentTestUtils; +import org.onap.ccsdk.features.data.adaptor.domain.TransactionLog; +import org.onap.ccsdk.features.data.adaptor.service.ConfigResourceService; +import org.onap.ccsdk.features.model.ConfigModelConstant; +import org.onap.ccsdk.features.model.data.ResourceAssignment; +import org.onap.ccsdk.features.model.data.dict.ResourceDefinition; +import org.onap.ccsdk.features.model.utils.TransformationUtils; +import org.onap.ccsdk.sli.core.sli.SvcLogicContext; +import org.onap.ccsdk.sli.core.sli.SvcLogicException; +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; + +@RunWith(MockitoJUnitRunner.class) +public class DefaultResourceProcessorTest { + + private static EELFLogger logger = EELFManager.getInstance().getLogger(DefaultResourceProcessorTest.class); + + @Mock + private ConfigResourceService configResourceService; + + @SuppressWarnings("unchecked") + @Before + public void before() { + MockitoAnnotations.initMocks(this); + + try { + Mockito.doAnswer(new Answer() { + @Override + public Void answer(InvocationOnMock invocationOnMock) throws Throwable { + Object[] args = invocationOnMock.getArguments(); + if (args != null) { + logger.trace("Transaction info " + Arrays.asList(args)); + } + return null; + } + }).when(configResourceService).save(any(TransactionLog.class)); + + } catch (SvcLogicException e) { + e.printStackTrace(); + } + } + + @Test + public void testDefaultSimpleProcess() throws Exception { + logger.info(" ******************************* testDefaultSimpleProcess ***************************"); + + String recipeName = "sample-recipe"; + + String resourceassignmentContent = FileUtils.readFileToString( + new File("src/test/resources/mapping/default/resource-assignments-simple.json"), + Charset.defaultCharset()); + List batchResourceAssignment = + TransformationUtils.getListfromJson(resourceassignmentContent, ResourceAssignment.class); + + String dictionaryContent = FileUtils.readFileToString( + new File("src/test/resources/mapping/default/default-simple.json"), Charset.defaultCharset()); + Map dictionaries = + ConfigResourceAssignmentTestUtils.getMapfromJson(dictionaryContent); + + DefaultResourceProcessor defaultResourceProcessor = new DefaultResourceProcessor(configResourceService); + Map componentContext = new HashMap<>(); + componentContext.put(ConfigModelConstant.PROPERTY_RESOURCE_ASSIGNMENTS, batchResourceAssignment); + componentContext.put(ConfigModelConstant.PROPERTY_ACTION_NAME, recipeName); + componentContext.put(ConfigModelConstant.PROPERTY_TEMPLATE_NAME, "sample-template"); + componentContext.put(ConfigModelConstant.PROPERTY_DICTIONARIES, dictionaries); + componentContext.put(ConfigModelConstant.PROPERTY_DICTIONARY_KEY_DOT + recipeName + ".profile_name", "sample"); + + Map inParams = new HashMap<>(); + SvcLogicContext ctx = new SvcLogicContext(); + defaultResourceProcessor.process(inParams, ctx, componentContext); + logger.trace(" componentContext " + componentContext); + + Assert.assertEquals("Failed to populate default country value ", "US", + componentContext.get(ConfigModelConstant.PROPERTY_RECIPE_KEY_DOT + "sample-recipe.country")); + Assert.assertEquals("Failed to populate default country value ", "US", + componentContext.get(ConfigModelConstant.PROPERTY_DICTIONARY_KEY_DOT + "sample-recipe.country")); + + Assert.assertEquals("Failed to populate default port value ", 830, + componentContext.get(ConfigModelConstant.PROPERTY_RECIPE_KEY_DOT + "sample-recipe.port")); + Assert.assertEquals("Failed to populate default port value ", 830, + componentContext.get(ConfigModelConstant.PROPERTY_DICTIONARY_KEY_DOT + "sample-recipe.port")); + + Assert.assertEquals("Failed to populate default voip-enabled value ", true, + componentContext.get(ConfigModelConstant.PROPERTY_RECIPE_KEY_DOT + "sample-recipe.voip-enabled")); + Assert.assertEquals("Failed to populate default voip-enabled value ", true, + componentContext.get(ConfigModelConstant.PROPERTY_DICTIONARY_KEY_DOT + "sample-recipe.voip-enabled")); + + } + +} diff --git a/blueprints-processor/plugin/assignment-provider/src/test/java/org/onap/ccsdk/features/assignment/processor/InputResourceProcessorTest.java b/blueprints-processor/plugin/assignment-provider/src/test/java/org/onap/ccsdk/features/assignment/processor/InputResourceProcessorTest.java new file mode 100644 index 000000000..cd0b7828e --- /dev/null +++ b/blueprints-processor/plugin/assignment-provider/src/test/java/org/onap/ccsdk/features/assignment/processor/InputResourceProcessorTest.java @@ -0,0 +1,179 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2018 IBM. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.ccsdk.features.assignment.processor; + +import static org.mockito.Matchers.any; +import java.io.File; +import java.nio.charset.Charset; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import org.apache.commons.io.FileUtils; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.MockitoAnnotations; +import org.mockito.invocation.InvocationOnMock; +import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.stubbing.Answer; +import org.onap.ccsdk.features.assignment.processor.InputResourceProcessor; +import org.onap.ccsdk.features.assignment.service.ConfigResourceAssignmentTestUtils; +import org.onap.ccsdk.features.data.adaptor.domain.TransactionLog; +import org.onap.ccsdk.features.data.adaptor.service.ConfigResourceService; +import org.onap.ccsdk.features.model.ConfigModelConstant; +import org.onap.ccsdk.features.model.data.ResourceAssignment; +import org.onap.ccsdk.features.model.data.dict.ResourceDefinition; +import org.onap.ccsdk.features.model.utils.TransformationUtils; +import org.onap.ccsdk.sli.core.sli.SvcLogicContext; +import org.onap.ccsdk.sli.core.sli.SvcLogicException; +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; + +@RunWith(MockitoJUnitRunner.class) +public class InputResourceProcessorTest { + + private static EELFLogger logger = EELFManager.getInstance().getLogger(InputResourceProcessorTest.class); + + @Mock + private ConfigResourceService configResourceService; + + @SuppressWarnings("unchecked") + @Before + public void before() { + MockitoAnnotations.initMocks(this); + + try { + Mockito.doAnswer(new Answer() { + @Override + public Void answer(InvocationOnMock invocationOnMock) throws Throwable { + Object[] args = invocationOnMock.getArguments(); + if (args != null) { + logger.trace("Transaction info " + Arrays.asList(args)); + } + return null; + } + }).when(configResourceService).save(any(TransactionLog.class)); + + } catch (SvcLogicException e) { + e.printStackTrace(); + } + } + + @Test + public void testInputSimpleProcess() throws Exception { + logger.info(" ******************************* testInputSimpleProcess ***************************"); + + String recipeName = "sample-recipe"; + + String resourceassignmentContent = FileUtils.readFileToString( + new File("src/test/resources/mapping/input/resource-assignments-simple.json"), + Charset.defaultCharset()); + List batchResourceAssignment = + TransformationUtils.getListfromJson(resourceassignmentContent, ResourceAssignment.class); + + String dictionaryContent = FileUtils.readFileToString( + new File("src/test/resources/mapping/default/default-simple.json"), Charset.defaultCharset()); + Map dictionaries = + ConfigResourceAssignmentTestUtils.getMapfromJson(dictionaryContent); + + InputResourceProcessor inputResourceProcessor = new InputResourceProcessor(configResourceService); + Map componentContext = new HashMap<>(); + componentContext.put(ConfigModelConstant.PROPERTY_RESOURCE_ASSIGNMENTS, batchResourceAssignment); + componentContext.put(ConfigModelConstant.PROPERTY_ACTION_NAME, recipeName); + componentContext.put(ConfigModelConstant.PROPERTY_TEMPLATE_NAME, "sample-template"); + componentContext.put(ConfigModelConstant.PROPERTY_DICTIONARIES, dictionaries); + componentContext.put(ConfigModelConstant.PROPERTY_DICTIONARY_KEY_DOT + recipeName + ".profile_name", "sample"); + + Map inParams = new HashMap<>(); + SvcLogicContext ctx = new SvcLogicContext(); + ctx.setAttribute("country", "US"); + ctx.setAttribute("port", "830"); + ctx.setAttribute("voip-enabled", "true"); + + inputResourceProcessor.process(inParams, ctx, componentContext); + logger.trace(" componentContext " + componentContext); + + Assert.assertEquals("Failed to populate default recipe country value ", "US", + componentContext.get(ConfigModelConstant.PROPERTY_RECIPE_KEY_DOT + "sample-recipe.country")); + Assert.assertEquals("Failed to populate default dictionary country value ", "US", + componentContext.get(ConfigModelConstant.PROPERTY_DICTIONARY_KEY_DOT + "sample-recipe.country")); + + Assert.assertEquals("Failed to populate default recipe port value ", 830, + componentContext.get(ConfigModelConstant.PROPERTY_RECIPE_KEY_DOT + "sample-recipe.port")); + Assert.assertEquals("Failed to populate default dictionary port value ", 830, + componentContext.get(ConfigModelConstant.PROPERTY_DICTIONARY_KEY_DOT + "sample-recipe.port")); + + Assert.assertEquals("Failed to populate default recipe voip-enabled value ", true, + componentContext.get(ConfigModelConstant.PROPERTY_RECIPE_KEY_DOT + "sample-recipe.voip-enabled")); + Assert.assertEquals("Failed to populate default dictionary voip-enabled value ", true, + componentContext.get(ConfigModelConstant.PROPERTY_DICTIONARY_KEY_DOT + "sample-recipe.voip-enabled")); + + } + + @Test + public void testInputComplexProcess() throws Exception { + logger.info(" ******************************* testInputComplexProcess ***************************"); + + String recipeName = "sample-recipe"; + + String resourceassignmentContent = FileUtils.readFileToString( + new File("src/test/resources/mapping/input/resource-assignments-complex.json"), + Charset.defaultCharset()); + List batchResourceAssignment = + TransformationUtils.getListfromJson(resourceassignmentContent, ResourceAssignment.class); + + String dictionaryContent = FileUtils.readFileToString( + new File("src/test/resources/mapping/input/input-complex.json"), Charset.defaultCharset()); + Map dictionaries = + ConfigResourceAssignmentTestUtils.getMapfromJson(dictionaryContent); + + InputResourceProcessor inputResourceProcessor = new InputResourceProcessor(configResourceService); + Map componentContext = new HashMap<>(); + componentContext.put(ConfigModelConstant.PROPERTY_RESOURCE_ASSIGNMENTS, batchResourceAssignment); + componentContext.put(ConfigModelConstant.PROPERTY_ACTION_NAME, recipeName); + componentContext.put(ConfigModelConstant.PROPERTY_TEMPLATE_NAME, "sample-template"); + componentContext.put(ConfigModelConstant.PROPERTY_DICTIONARIES, dictionaries); + componentContext.put(ConfigModelConstant.PROPERTY_DICTIONARY_KEY_DOT + recipeName + ".profile_name", "sample"); + + Map inParams = new HashMap<>(); + SvcLogicContext ctx = new SvcLogicContext(); + String datatypeContent = FileUtils.readFileToString( + new File("src/test/resources/mapping/input/dt-location.json"), Charset.defaultCharset()); + ctx.setAttribute("data_types.dt-location", datatypeContent); + + String samplelocation = FileUtils.readFileToString( + new File("src/test/resources/mapping/input/sample-location.json"), Charset.defaultCharset()); + ctx.setAttribute("location", samplelocation); + + inputResourceProcessor.process(inParams, ctx, componentContext); + + logger.trace(" componentContext " + componentContext); + logger.trace(" Resource Mapping " + TransformationUtils.getJson(batchResourceAssignment, true)); + + Assert.assertNotNull("Failed to populate input recipe location value ", + componentContext.get(ConfigModelConstant.PROPERTY_RECIPE_KEY_DOT + "sample-recipe.location")); + Assert.assertNotNull("Failed to populate input dictionary location value ", + componentContext.get(ConfigModelConstant.PROPERTY_DICTIONARY_KEY_DOT + "sample-recipe.location")); + + } + +} diff --git a/blueprints-processor/plugin/assignment-provider/src/test/java/org/onap/ccsdk/features/assignment/processor/MdsalResourceProcessorTest.java b/blueprints-processor/plugin/assignment-provider/src/test/java/org/onap/ccsdk/features/assignment/processor/MdsalResourceProcessorTest.java new file mode 100644 index 000000000..5f73f32e3 --- /dev/null +++ b/blueprints-processor/plugin/assignment-provider/src/test/java/org/onap/ccsdk/features/assignment/processor/MdsalResourceProcessorTest.java @@ -0,0 +1,269 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2018 IBM. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.ccsdk.features.assignment.processor; + +import java.io.File; +import java.nio.charset.Charset; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import org.apache.commons.io.FileUtils; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Matchers; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.invocation.InvocationOnMock; +import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.stubbing.Answer; +import org.onap.ccsdk.features.assignment.processor.MdsalResourceProcessor; +import org.onap.ccsdk.features.assignment.service.ConfigResourceAssignmentTestUtils; +import org.onap.ccsdk.features.model.ConfigModelConstant; +import org.onap.ccsdk.features.model.data.ResourceAssignment; +import org.onap.ccsdk.features.model.data.dict.ResourceDefinition; +import org.onap.ccsdk.features.model.utils.TransformationUtils; +import org.onap.ccsdk.features.rest.adaptor.service.ConfigRestAdaptorService; +import org.onap.ccsdk.sli.core.sli.SvcLogicContext; +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; + +@RunWith(MockitoJUnitRunner.class) +public class MdsalResourceProcessorTest { + + private static EELFLogger logger = EELFManager.getInstance().getLogger(MdsalResourceProcessorTest.class); + + @Mock + private ConfigRestAdaptorService configRestAdaptorService; + + @SuppressWarnings("unchecked") + @Before + public void before() { + + } + + @Test + @SuppressWarnings("unchecked") + public void testMdsalSimpleProcess() throws Exception { + logger.info(" ******************************* testMdsalSimpleProcess ***************************"); + + Mockito.doAnswer(new Answer() { + @Override + public String answer(InvocationOnMock invocationOnMock) throws Throwable { + Object[] args = invocationOnMock.getArguments(); + String response = null; + if (args != null) { + response = FileUtils.readFileToString( + new File("src/test/resources/mapping/Mdsal/simple-response.json"), + Charset.defaultCharset()); + logger.info(" Returning response :" + response); + } + return response; + } + }).when(configRestAdaptorService).getResource(Matchers.anyString(), Matchers.anyString(), + Matchers.any(Class.class)); + + String recipeName = "sample-recipe"; + + String resourceassignmentContent = FileUtils.readFileToString( + new File("src/test/resources/mapping/Mdsal/resource-assignments-simple.json"), + Charset.defaultCharset()); + List batchResourceAssignment = + TransformationUtils.getListfromJson(resourceassignmentContent, ResourceAssignment.class); + + String dictionaryContent = FileUtils.readFileToString( + new File("src/test/resources/mapping/Mdsal/mdsal-simple.json"), Charset.defaultCharset()); + Map dictionaries = + ConfigResourceAssignmentTestUtils.getMapfromJson(dictionaryContent); + MdsalResourceProcessor mdsalResourceProcessor = new MdsalResourceProcessor(configRestAdaptorService); + Map componentContext = new HashMap<>(); + componentContext.put(ConfigModelConstant.PROPERTY_RESOURCE_ASSIGNMENTS, batchResourceAssignment); + componentContext.put(ConfigModelConstant.PROPERTY_ACTION_NAME, recipeName); + componentContext.put(ConfigModelConstant.PROPERTY_TEMPLATE_NAME, "sample-template"); + componentContext.put(ConfigModelConstant.PROPERTY_DICTIONARIES, dictionaries); + + componentContext.put(ConfigModelConstant.PROPERTY_DICTIONARY_KEY_DOT + recipeName + ".profile_name", "sample"); + + Map inParams = new HashMap<>(); + SvcLogicContext ctx = new SvcLogicContext(); + mdsalResourceProcessor.process(inParams, ctx, componentContext); + + } + + @SuppressWarnings("unchecked") + @Test + public void testMDSALComplexProcess() throws Exception { + logger.info(" ******************************* testMDSALComplexProcess ***************************"); + + Mockito.doAnswer(new Answer() { + @Override + public String answer(InvocationOnMock invocationOnMock) throws Throwable { + Object[] args = invocationOnMock.getArguments(); + String response = null; + if (args != null) { + response = FileUtils.readFileToString( + new File("src/test/resources/mapping/Mdsal/complex-response.json"), + Charset.defaultCharset()); + } + return response; + } + }).when(configRestAdaptorService).getResource(Matchers.anyString(), Matchers.anyString(), + Matchers.any(Class.class)); + + String recipeName = "sample-recipe"; + + String resourceassignmentContent = FileUtils.readFileToString( + new File("src/test/resources/mapping/Mdsal/resource-assignments-complex.json"), + Charset.defaultCharset()); + List batchResourceAssignment = + TransformationUtils.getListfromJson(resourceassignmentContent, ResourceAssignment.class); + + String dictionaryContent = FileUtils.readFileToString( + new File("src/test/resources/mapping/Mdsal/mdsal-complex.json"), Charset.defaultCharset()); + Map dictionaries = + ConfigResourceAssignmentTestUtils.getMapfromJson(dictionaryContent); + MdsalResourceProcessor dbResourceProcessor = new MdsalResourceProcessor(configRestAdaptorService); + Map componentContext = new HashMap<>(); + componentContext.put(ConfigModelConstant.PROPERTY_RESOURCE_ASSIGNMENTS, batchResourceAssignment); + componentContext.put(ConfigModelConstant.PROPERTY_ACTION_NAME, recipeName); + componentContext.put(ConfigModelConstant.PROPERTY_TEMPLATE_NAME, "sample-template"); + componentContext.put(ConfigModelConstant.PROPERTY_DICTIONARIES, dictionaries); + componentContext.put(ConfigModelConstant.PROPERTY_DICTIONARY_KEY_DOT + recipeName + ".profile_name", "sample"); + + Map inParams = new HashMap<>(); + SvcLogicContext ctx = new SvcLogicContext(); + String datatypeContent = FileUtils.readFileToString( + new File("src/test/resources/mapping/Mdsal/dt-location.json"), Charset.defaultCharset()); + ctx.setAttribute("data_types.dt-location", datatypeContent); + dbResourceProcessor.process(inParams, ctx, componentContext); + + } + + @Test + @SuppressWarnings("unchecked") + public void testMDSALArrayComplexProcess() throws Exception { + logger.info(" ******************************* testMDSALArrayComplexProcess ***************************"); + + Mockito.doAnswer(new Answer() { + @Override + public String answer(InvocationOnMock invocationOnMock) throws Throwable { + Object[] args = invocationOnMock.getArguments(); + String response = null; + if (args != null) { + response = FileUtils.readFileToString( + new File("src/test/resources/mapping/Mdsal/array-complex-response.json"), + Charset.defaultCharset()); + } + return response; + } + }).when(configRestAdaptorService).getResource(Matchers.anyString(), Matchers.anyString(), + Matchers.any(Class.class)); + + String recipeName = "sample-recipe"; + + String resourceassignmentContent = FileUtils.readFileToString( + new File("src/test/resources/mapping/Mdsal/resource-assignments-array.json"), Charset.defaultCharset()); + List batchResourceAssignment = + TransformationUtils.getListfromJson(resourceassignmentContent, ResourceAssignment.class); + + String dictionaryContent = FileUtils.readFileToString( + new File("src/test/resources/mapping/Mdsal/mdsal-array.json"), Charset.defaultCharset()); + + Map dictionaries = + ConfigResourceAssignmentTestUtils.getMapfromJson(dictionaryContent); + MdsalResourceProcessor dbResourceProcessor = new MdsalResourceProcessor(configRestAdaptorService); + Map componentContext = new HashMap<>(); + componentContext.put(ConfigModelConstant.PROPERTY_RESOURCE_ASSIGNMENTS, batchResourceAssignment); + componentContext.put(ConfigModelConstant.PROPERTY_ACTION_NAME, recipeName); + componentContext.put(ConfigModelConstant.PROPERTY_TEMPLATE_NAME, "sample-template"); + componentContext.put(ConfigModelConstant.PROPERTY_DICTIONARIES, dictionaries); + componentContext.put(ConfigModelConstant.PROPERTY_DICTIONARY_KEY_DOT + recipeName + ".profile_name", "sample"); + + Map inParams = new HashMap<>(); + SvcLogicContext ctx = new SvcLogicContext(); + String datatypeContent = FileUtils.readFileToString( + new File("src/test/resources/mapping/Mdsal/dt-location.json"), Charset.defaultCharset()); + ctx.setAttribute("data_types.dt-location", datatypeContent); + dbResourceProcessor.process(inParams, ctx, componentContext); + logger.info("Component Context = ({})", componentContext); + Assert.assertNotNull("failed to populate Array Complex response ", componentContext); + + } + + @Test + @SuppressWarnings("unchecked") + public void testMDSALArraySimpleProcess() throws Exception { + logger.info(" ******************************* testMDSALArrayComplexProcess ***************************"); + + Mockito.doAnswer(new Answer() { + @Override + public String answer(InvocationOnMock invocationOnMock) throws Throwable { + Object[] args = invocationOnMock.getArguments(); + String response = null; + if (args != null) { + response = FileUtils.readFileToString( + new File("src/test/resources/mapping/Mdsal/array-complex-v4-assigned-response.json"), + Charset.defaultCharset()); + } + return response; + } + }).when(configRestAdaptorService).getResource(Matchers.anyString(), Matchers.anyString(), + Matchers.any(Class.class)); + + String recipeName = "sample-recipe"; + + String resourceassignmentContent = FileUtils.readFileToString( + new File("src/test/resources/mapping/Mdsal/resource-assignments-complex-simple.json"), + Charset.defaultCharset()); + List batchResourceAssignment = + TransformationUtils.getListfromJson(resourceassignmentContent, ResourceAssignment.class); + + String dictionaryContent = FileUtils.readFileToString( + new File("src/test/resources/mapping/Mdsal/mdsal-array-v4iplist.json"), Charset.defaultCharset()); + Map dictionaries = + ConfigResourceAssignmentTestUtils.getMapfromJson(dictionaryContent); + MdsalResourceProcessor mdsalResourceProcessor = new MdsalResourceProcessor(configRestAdaptorService); + Map componentContext = new HashMap<>(); + componentContext.put(ConfigModelConstant.PROPERTY_RESOURCE_ASSIGNMENTS, batchResourceAssignment); + componentContext.put(ConfigModelConstant.PROPERTY_ACTION_NAME, recipeName); + componentContext.put(ConfigModelConstant.PROPERTY_TEMPLATE_NAME, "sample-template"); + componentContext.put(ConfigModelConstant.PROPERTY_DICTIONARIES, dictionaries); + componentContext.put(ConfigModelConstant.PROPERTY_DICTIONARY_KEY_DOT + recipeName + ".service-instance-id", + "3c8d5a63-a793-4206-a67c-4b2e8e648196"); + componentContext.put(ConfigModelConstant.PROPERTY_DICTIONARY_KEY_DOT + recipeName + ".oam-network-role", + "sample"); + componentContext.put(ConfigModelConstant.PROPERTY_DICTIONARY_KEY_DOT + recipeName + ".oam-ipv4-ip-type", + "sample"); + componentContext.put(ConfigModelConstant.PROPERTY_DICTIONARY_KEY_DOT + recipeName + ".profile_name", "sample"); + componentContext.put(ConfigModelConstant.PROPERTY_DICTIONARY_KEY_DOT + recipeName + ".oam-vm-type", "sample"); + + Map inParams = new HashMap<>(); + SvcLogicContext ctx = new SvcLogicContext(); + // String datatypeContent = FileUtils.readFileToString(new + // File("src/test/resources/mapping/Mdsal/dt-v4-assigned-ip-list.json"), Charset.defaultCharset() ); + // ctx.setAttribute("data_types.dt-v4-assigned-ip-list", datatypeContent); + mdsalResourceProcessor.process(inParams, ctx, componentContext); + logger.info("Component Context = ({})", componentContext); + Assert.assertNotNull("failed to populate Array Complex response ", componentContext); + Assert.assertEquals("Compare String ", "10.66.1.152", + componentContext.get(ConfigModelConstant.PROPERTY_RECIPE_KEY_DOT + recipeName + ".v4-ip-prefix")); + + } + +} diff --git a/blueprints-processor/plugin/assignment-provider/src/test/java/org/onap/ccsdk/features/assignment/service/ConfigAssignmentNodeTest.java b/blueprints-processor/plugin/assignment-provider/src/test/java/org/onap/ccsdk/features/assignment/service/ConfigAssignmentNodeTest.java new file mode 100644 index 000000000..41911e91d --- /dev/null +++ b/blueprints-processor/plugin/assignment-provider/src/test/java/org/onap/ccsdk/features/assignment/service/ConfigAssignmentNodeTest.java @@ -0,0 +1,247 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2018 IBM. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.ccsdk.features.assignment.service; + +import java.io.File; +import java.nio.charset.Charset; +import java.util.HashMap; +import java.util.Map; +import org.apache.commons.io.FileUtils; +import org.apache.commons.lang3.StringUtils; +import org.apache.sling.testing.mock.osgi.MockOsgi; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; +import org.mockito.runners.MockitoJUnitRunner; +import org.onap.ccsdk.features.assignment.ConfigAssignmentConstants; +import org.onap.ccsdk.features.assignment.service.ConfigAssignmentNode; +import org.onap.ccsdk.features.data.adaptor.service.ConfigResourceService; +import org.onap.ccsdk.features.generator.service.ConfigGeneratorService; +import org.onap.ccsdk.features.generator.service.ConfigGeneratorServiceImpl; +import org.onap.ccsdk.features.model.ConfigModelConstant; +import org.onap.ccsdk.features.model.service.ComponentNodeDelegate; +import org.onap.ccsdk.features.model.service.ComponentNodeService; +import org.onap.ccsdk.features.model.service.ComponentNodeServiceImpl; +import org.onap.ccsdk.features.model.service.ConfigModelService; +import org.onap.ccsdk.features.model.service.ConfigModelServiceImpl; +import org.onap.ccsdk.features.rest.adaptor.service.ConfigRestAdaptorService; +import org.onap.ccsdk.sli.core.sli.SvcLogicContext; +import org.osgi.framework.BundleContext; +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; + +@RunWith(MockitoJUnitRunner.class) +public class ConfigAssignmentNodeTest { + + private static EELFLogger logger = EELFManager.getInstance().getLogger(ConfigAssignmentNodeTest.class); + + @Rule + public ExpectedException thrown = ExpectedException.none(); + + @Mock + private ConfigResourceService configResourceService; + + @Mock + private ConfigRestAdaptorService configRestAdaptorService; + + private ConfigModelService configModelService; + + private ComponentNodeService componentNodeService; + + private ConfigGeneratorService configGeneratorService; + + BundleContext bundleContext = MockOsgi.newBundleContext(); + + @SuppressWarnings("unchecked") + @Before + public void before() throws Exception { + MockitoAnnotations.initMocks(this); + /* + * ConfigAssignmentNode configAssignmentNode = new ConfigAssignmentNode(componentNodeService, + * configResourceService, configModelService, configRestAdaptorService, configGeneratorService); + * bundleContext.registerService(ConfigAssignmentNode.class, configAssignmentNode, null); + */ + } + + @Test + public void testResourceAssignment() throws Exception { + ConfigResourceAssignmentTestUtils.injectTransactionLogSaveMock(configResourceService); + + ConfigResourceAssignmentTestUtils.injectConfigModelMock(configRestAdaptorService, "resource_assignment"); + + ConfigResourceAssignmentTestUtils.injectResourceDictionaryMock(configRestAdaptorService, + "assignments/empty-dictionary.json"); + + ConfigResourceAssignmentTestUtils.injectConfigResourceSaveMock(configResourceService); + + componentNodeService = + new ComponentNodeServiceImpl(bundleContext, configResourceService, configRestAdaptorService); + configModelService = new ConfigModelServiceImpl(configRestAdaptorService); + configGeneratorService = new ConfigGeneratorServiceImpl(configResourceService); + + ConfigAssignmentNode configAssignmentNode = new ConfigAssignmentNode(configResourceService, + configRestAdaptorService, configModelService, componentNodeService, configGeneratorService); + + String inputContent = FileUtils.readFileToString( + new File("src/test/resources/service_templates/input/input.json"), Charset.defaultCharset()); + + Map inParams = new HashMap<>(); + inParams.put(ConfigModelConstant.PROPERTY_SELECTOR, "test"); + inParams.put(ConfigAssignmentConstants.INPUT_PARAM_REQUEST_ID, "1234"); + inParams.put(ConfigAssignmentConstants.INPUT_PARAM_RESOURCE_ID, "resourceid-1234"); + inParams.put(ConfigAssignmentConstants.INPUT_PARAM_RESOURCE_TYPE, "vnf-type"); + inParams.put(ConfigModelConstant.SERVICE_TEMPLATE_KEY_ARTIFACT_NAME, "vpe-201802-baseconfig"); + inParams.put(ConfigModelConstant.SERVICE_TEMPLATE_KEY_ARTIFACT_VERSION, "1.0.0"); + inParams.put(ConfigModelConstant.PROPERTY_ACTION_NAME, "resource-assignment-action"); + inParams.put(ConfigAssignmentConstants.INPUT_PARAM_INPUT_DATA, inputContent); + inParams.put(ConfigAssignmentConstants.INPUT_PARAM_TEMPLATE_NAMES, "[\"base-config-template\"]"); + + // Populate the SvcContext ( Simulation) + SvcLogicContext svcLogicContext = new SvcLogicContext(); + Map context = new HashMap<>(); + context.put(ConfigModelConstant.PROPERTY_ACTION_NAME, "resource-assignment-action"); + context = configModelService.prepareContext(context, inputContent, "vpe-201802-baseconfig", "1.0.0"); + context.forEach((key, value) -> svcLogicContext.setAttribute(key, value)); + + Map componentContext = new HashMap<>(); + configAssignmentNode.process(inParams, svcLogicContext, componentContext); + Assert.assertNotNull("Failed to get response status", svcLogicContext.getAttribute("test.status")); + + } + + @Test + public void testSimplePreview() throws Exception { + ConfigResourceAssignmentTestUtils.injectTransactionLogSaveMock(configResourceService); + + ConfigResourceAssignmentTestUtils.injectConfigModelMock(configRestAdaptorService, "resource_assignment"); + + ConfigResourceAssignmentTestUtils.injectResourceDictionaryMock(configRestAdaptorService, + "assignments/empty-dictionary.json"); + + ConfigResourceAssignmentTestUtils.injectConfigResourceSaveMock(configResourceService); + + componentNodeService = + new ComponentNodeServiceImpl(bundleContext, configResourceService, configRestAdaptorService); + configModelService = new ConfigModelServiceImpl(configRestAdaptorService); + configGeneratorService = new ConfigGeneratorServiceImpl(configResourceService); + + ConfigAssignmentNode configAssignmentNode = new ConfigAssignmentNode(configResourceService, + configRestAdaptorService, configModelService, componentNodeService, configGeneratorService); + + String inputContent = FileUtils.readFileToString( + new File("src/test/resources/service_templates/input/input.json"), Charset.defaultCharset()); + + Map inParams = new HashMap<>(); + inParams.put(ConfigModelConstant.PROPERTY_SELECTOR, "test"); + inParams.put(ConfigAssignmentConstants.INPUT_PARAM_REQUEST_ID, "1234"); + inParams.put(ConfigAssignmentConstants.INPUT_PARAM_RESOURCE_ID, "resourceid-1234"); + inParams.put(ConfigAssignmentConstants.INPUT_PARAM_RESOURCE_TYPE, "vnf-type"); + inParams.put(ConfigModelConstant.SERVICE_TEMPLATE_KEY_ARTIFACT_NAME, "vpe-201802-baseconfig"); + inParams.put(ConfigModelConstant.SERVICE_TEMPLATE_KEY_ARTIFACT_VERSION, "1.0.0"); + inParams.put(ConfigModelConstant.PROPERTY_ACTION_NAME, "resource-assignment-action"); + inParams.put(ConfigAssignmentConstants.INPUT_PARAM_INPUT_DATA, inputContent); + inParams.put(ConfigAssignmentConstants.INPUT_PARAM_TEMPLATE_NAMES, "[\"base-config-template\"]"); + SvcLogicContext ctx = new SvcLogicContext(); + configAssignmentNode.process(inParams, ctx); + Assert.assertNotNull("Failed to get response mashed Content", + ctx.getAttribute("test.mashed-data.base-config-template")); + } + + @Test + public void testComplexPreview() throws Exception { + ConfigResourceAssignmentTestUtils.injectTransactionLogSaveMock(configResourceService); + + ConfigResourceAssignmentTestUtils.injectConfigModelMock(configRestAdaptorService, "vpe-201802-baseconfig"); + + ConfigResourceAssignmentTestUtils.injectResourceDictionaryMock(configRestAdaptorService, + "service_templates/vpe-201802-baseconfig/dict.json"); + + ConfigResourceAssignmentTestUtils.injectConfigResourceSaveMock(configResourceService); + + componentNodeService = + new ComponentNodeServiceImpl(bundleContext, configResourceService, configRestAdaptorService); + configModelService = new ConfigModelServiceImpl(configRestAdaptorService); + configGeneratorService = new ConfigGeneratorServiceImpl(configResourceService); + + ConfigAssignmentNode configAssignmentNode = new ConfigAssignmentNode(configResourceService, + configRestAdaptorService, configModelService, componentNodeService, configGeneratorService); + + String inputContent = FileUtils.readFileToString( + new File("src/test/resources/service_templates/vpe-201802-baseconfig/input-complex.json"), + Charset.defaultCharset()); + + Map inParams = new HashMap<>(); + inParams.put(ConfigModelConstant.PROPERTY_SELECTOR, "complex-test"); + inParams.put(ConfigAssignmentConstants.INPUT_PARAM_REQUEST_ID, "request-1234"); + inParams.put(ConfigAssignmentConstants.INPUT_PARAM_RESOURCE_ID, "resourceid-1234"); + inParams.put(ConfigAssignmentConstants.INPUT_PARAM_RESOURCE_TYPE, "vnf-type"); + inParams.put(ConfigModelConstant.SERVICE_TEMPLATE_KEY_ARTIFACT_NAME, "vpe-201802-baseconfig"); + inParams.put(ConfigModelConstant.SERVICE_TEMPLATE_KEY_ARTIFACT_VERSION, "1.0.0"); + inParams.put(ConfigModelConstant.PROPERTY_ACTION_NAME, "resource-assignment-action"); + inParams.put(ConfigAssignmentConstants.INPUT_PARAM_INPUT_DATA, inputContent); + inParams.put(ConfigAssignmentConstants.INPUT_PARAM_TEMPLATE_NAMES, "[\"base-config-template\"]"); + SvcLogicContext ctx = new SvcLogicContext(); + configAssignmentNode.process(inParams, ctx); + Assert.assertNotNull("Failed to get response mashed Content", + ctx.getAttribute("complex-test.mashed-data.base-config-template")); + + } + + @Test + public void inputValidator() { + SvcLogicContext ctx = new SvcLogicContext(); + try { + + logger.info(" ******************************* inputValidator ***************************"); + String serviceTemplateContent = FileUtils.readFileToString( + new File("src/test/resources/service_templates/resource_assignment.json"), + Charset.defaultCharset()); + + String inputcontent = FileUtils.readFileToString( + new File("src/test/resources/service_templates/input/inputValidateTest.json"), + Charset.defaultCharset()); + + Map context = new HashMap<>(); + configModelService.prepareContext(context, inputcontent, serviceTemplateContent); + + // TransformationUtils.printMap(context); + + context.forEach((name, value) -> { + if (StringUtils.isNotBlank(name) && StringUtils.isNotBlank(value)) { + ctx.setAttribute(name, value); + } + }); + + ComponentNodeDelegate componentNodeDelegate = new ComponentNodeDelegate(componentNodeService); + Map inParams = new HashMap<>(); + inParams.put(ConfigModelConstant.PROPERTY_SELECTOR, "resource-assignment"); + componentNodeDelegate.process(inParams, ctx); + Assert.fail(); + } catch (Exception e) { + logger.error("Failed in inputValidator" + e.getMessage()); + logger.info("** ctx.getAttribute Check for **" + ctx.getAttribute("resource-assignment.error-message")); + } + + } + +} diff --git a/blueprints-processor/plugin/assignment-provider/src/test/java/org/onap/ccsdk/features/assignment/service/ConfigPreviewServiceTest.java b/blueprints-processor/plugin/assignment-provider/src/test/java/org/onap/ccsdk/features/assignment/service/ConfigPreviewServiceTest.java new file mode 100644 index 000000000..1e0b4a299 --- /dev/null +++ b/blueprints-processor/plugin/assignment-provider/src/test/java/org/onap/ccsdk/features/assignment/service/ConfigPreviewServiceTest.java @@ -0,0 +1,113 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2018 IBM. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.ccsdk.features.assignment.service; + +import java.io.File; +import java.nio.charset.Charset; +import org.apache.commons.io.FileUtils; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; +import org.mockito.runners.MockitoJUnitRunner; +import org.onap.ccsdk.features.assignment.data.ResourceAssignmentData; +import org.onap.ccsdk.features.assignment.service.ConfigPreviewService; +import org.onap.ccsdk.features.data.adaptor.domain.ConfigResource; +import org.onap.ccsdk.features.data.adaptor.service.ConfigResourceService; +import org.onap.ccsdk.features.generator.service.ConfigGeneratorService; +import org.onap.ccsdk.features.generator.service.ConfigGeneratorServiceImpl; +import org.onap.ccsdk.features.model.service.ConfigModelService; +import org.onap.ccsdk.features.model.service.ConfigModelServiceImpl; +import org.onap.ccsdk.features.rest.adaptor.service.ConfigRestAdaptorService; + +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; + +@RunWith(MockitoJUnitRunner.class) +public class ConfigPreviewServiceTest { + + private static EELFLogger logger = EELFManager.getInstance().getLogger(ConfigPreviewServiceTest.class); + + @Rule + public ExpectedException thrown = ExpectedException.none(); + + @Mock + private ConfigResourceService configResourceService; + + @Mock + private ConfigRestAdaptorService configRestAdaptorService; + + private ConfigModelService configModelService; + private ConfigGeneratorService configGeneratorService; + + @SuppressWarnings("unchecked") + @Before + public void before() throws Exception { + MockitoAnnotations.initMocks(this); + } + + @Test + public void testGenerateTemplateResourceMash() throws Exception { + + ConfigResourceAssignmentTestUtils.injectTransactionLogSaveMock(configResourceService); + + ConfigResourceAssignmentTestUtils.injectConfigModelMock(configRestAdaptorService, "resource_assignment"); + + ConfigResourceAssignmentTestUtils.injectResourceDictionaryMock(configRestAdaptorService, + "assignments/empty-dictionary.json"); + + ConfigResource configResourceQuery = new ConfigResource(); + configResourceQuery.setServiceTemplateVersion("sample-serviceTemplateName"); + configResourceQuery.setServiceTemplateVersion("1.0.0"); + configResourceQuery.setRecipeName("sample-action"); + configResourceQuery.setResourceId("123-resourceId"); + configResourceQuery.setResourceType("sample-resourceType"); + configResourceQuery.setTemplateName("base-config-template"); + String inputContent = FileUtils.readFileToString( + new File("src/test/resources/service_templates/input/input.json"), Charset.defaultCharset()); + configResourceQuery.setResourceData(inputContent); + + ConfigResourceAssignmentTestUtils.injectGetConfigResourceMock(configResourceService, configResourceQuery); + + configModelService = new ConfigModelServiceImpl(configRestAdaptorService); + configGeneratorService = new ConfigGeneratorServiceImpl(configResourceService); + + ConfigPreviewService configPreviewService = + new ConfigPreviewService(configResourceService, configModelService, configGeneratorService); + + ResourceAssignmentData resourceAssignmentData = new ResourceAssignmentData(); + resourceAssignmentData.setResourceId("123-resourceId"); + resourceAssignmentData.setResourceType("sample-resourceType"); + resourceAssignmentData.setServiceTemplateName("sample-serviceTemplateName"); + resourceAssignmentData.setServiceTemplateVersion("1.0.0"); + resourceAssignmentData.setActionName("sample-action"); + + resourceAssignmentData = configPreviewService.generateTemplateResourceMash(resourceAssignmentData); + + Assert.assertNotNull("Failed to get GenerateTemplateResourceMash response.", resourceAssignmentData); + Assert.assertNotNull("Failed to get template mashed contents.", + resourceAssignmentData.getTemplatesMashedContents()); + + Assert.assertNotNull("Failed to get base-config template mashed contents.", + resourceAssignmentData.getTemplatesMashedContents().get("base-config-template")); + } +} diff --git a/blueprints-processor/plugin/assignment-provider/src/test/java/org/onap/ccsdk/features/assignment/service/ConfigResourceAssignmentTestUtils.java b/blueprints-processor/plugin/assignment-provider/src/test/java/org/onap/ccsdk/features/assignment/service/ConfigResourceAssignmentTestUtils.java new file mode 100644 index 000000000..5ce2c9a1d --- /dev/null +++ b/blueprints-processor/plugin/assignment-provider/src/test/java/org/onap/ccsdk/features/assignment/service/ConfigResourceAssignmentTestUtils.java @@ -0,0 +1,183 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2018 IBM. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.ccsdk.features.assignment.service; + +import static org.mockito.Matchers.any; +import static org.mockito.Matchers.anyString; +import java.io.File; +import java.nio.charset.Charset; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.List; +import java.util.Map; +import org.apache.commons.io.FileUtils; +import org.apache.commons.io.FilenameUtils; +import org.apache.commons.io.IOUtils; +import org.mockito.Matchers; +import org.mockito.Mockito; +import org.mockito.invocation.InvocationOnMock; +import org.mockito.stubbing.Answer; +import org.onap.ccsdk.features.data.adaptor.domain.ConfigResource; +import org.onap.ccsdk.features.data.adaptor.domain.TransactionLog; +import org.onap.ccsdk.features.data.adaptor.service.ConfigResourceService; +import org.onap.ccsdk.features.model.ConfigModelConstant; +import org.onap.ccsdk.features.model.data.dict.ResourceDefinition; +import org.onap.ccsdk.features.model.domain.ConfigModel; +import org.onap.ccsdk.features.model.domain.ConfigModelContent; +import org.onap.ccsdk.features.rest.adaptor.service.ConfigRestAdaptorService; + +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; +import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.ObjectMapper; + +public class ConfigResourceAssignmentTestUtils { + + private static EELFLogger logger = EELFManager.getInstance().getLogger(ConfigResourceAssignmentTestUtils.class); + + public static void injectTransactionLogSaveMock(ConfigResourceService configResourceService) throws Exception { + Mockito.doAnswer(new Answer() { + @Override + public Void answer(InvocationOnMock invocationOnMock) throws Throwable { + Object[] args = invocationOnMock.getArguments(); + if (args != null) { + logger.trace("Transaction info " + Arrays.asList(args)); + } + return null; + } + }).when(configResourceService).save(any(TransactionLog.class)); + } + + public static void injectConfigModelMock(ConfigRestAdaptorService configRestAdaptorService, + String serviceTemplateName) throws Exception { + + Mockito.doAnswer(new Answer() { + @Override + public org.onap.ccsdk.features.model.domain.ConfigModel answer(InvocationOnMock invocationOnMock) + throws Throwable { + Object[] args = invocationOnMock.getArguments(); + org.onap.ccsdk.features.model.domain.ConfigModel serviceArtifact = null; + if (args != null && args.length == 3) { + + logger.info("Artifact info " + Arrays.asList(args)); + String modelContent = IOUtils.toString( + ConfigResourceAssignmentTestUtils.class.getClassLoader().getResourceAsStream( + "service_templates/" + serviceTemplateName + "/" + serviceTemplateName + ".json"), + Charset.defaultCharset()); + + ConfigModelContent configModelContent = new ConfigModelContent(); + configModelContent.setContent(modelContent); + configModelContent.setContentType(ConfigModelConstant.MODEL_CONTENT_TYPE_TOSCA_JSON); + + List configModelContents = new ArrayList<>(); + configModelContents.add(configModelContent); + + String velocityDir = ConfigResourceAssignmentTestUtils.class.getClassLoader() + .getResource("service_templates/" + serviceTemplateName + "/velocity").getPath(); + + Collection templateFiles = + FileUtils.listFiles(new File(velocityDir), new String[] {"vtl"}, true); + logger.info("Template Files info " + templateFiles); + for (File templateFile : templateFiles) { + String templateContent = FileUtils.readFileToString(templateFile, Charset.defaultCharset()); + ConfigModelContent configModelTemplateContent = new ConfigModelContent(); + configModelTemplateContent.setContent(templateContent); + configModelTemplateContent.setName(FilenameUtils.getBaseName(templateFile.getName())); + configModelTemplateContent.setContentType(ConfigModelConstant.MODEL_CONTENT_TYPE_TEMPLATE); + configModelContents.add(configModelTemplateContent); + } + + serviceArtifact = new org.onap.ccsdk.features.model.domain.ConfigModel(); + serviceArtifact.setArtifactName(String.valueOf(args[0])); + serviceArtifact.setArtifactVersion(String.valueOf(args[1])); + serviceArtifact.setPublished("Y"); + serviceArtifact.setConfigModelContents(configModelContents); + } + + return serviceArtifact; + } + }).when(configRestAdaptorService).getResource(anyString(), anyString(), Matchers.any(Class.class)); + } + + public static void injectResourceDictionaryMock(ConfigRestAdaptorService configRestAdaptorService, + String dictionaryFileName) throws Exception { + + Mockito.doAnswer(new Answer() { + @Override + public String answer(InvocationOnMock invocationOnMock) throws Throwable { + Object[] args = invocationOnMock.getArguments(); + String dictionaties = "[]"; + if (args != null) { + logger.info("getResourceDictionaryByNames " + Arrays.asList(args)); + dictionaties = IOUtils.toString( + ConfigAssignmentNodeTest.class.getClassLoader().getResourceAsStream(dictionaryFileName), + Charset.defaultCharset()); + } + return dictionaties; + } + }).when(configRestAdaptorService).postResource(Matchers.any(), Matchers.any(), Matchers.any(), + Matchers.any(Class.class)); + } + + public static void injectConfigResourceSaveMock(ConfigResourceService configResourceService) throws Exception { + Mockito.doAnswer(new Answer() { + @Override + public ConfigResource answer(InvocationOnMock invocationOnMock) throws Throwable { + Object[] args = invocationOnMock.getArguments(); + ConfigResource configResource = null; + if (args != null) { + configResource = (ConfigResource) args[0]; + logger.info("Config Resource Save info " + configResource); + return configResource; + } + return configResource; + } + }).when(configResourceService).saveConfigResource(any(ConfigResource.class)); + } + + public static void injectGetConfigResourceMock(ConfigResourceService configResourceService, + ConfigResource configResource) throws Exception { + Mockito.doAnswer(new Answer>() { + @Override + public List answer(InvocationOnMock invocationOnMock) throws Throwable { + Object[] args = invocationOnMock.getArguments(); + List configResources = new ArrayList<>(); + if (args != null) { + configResources.add(configResource); + } + return configResources; + } + }).when(configResourceService).getConfigResource(any(ConfigResource.class)); + } + + public static String getFileContent(String filePath) throws Exception { + return IOUtils.toString(ConfigResourceAssignmentTestUtils.class.getClassLoader().getResourceAsStream(filePath), + Charset.defaultCharset()); + } + + public static Map getMapfromJson(String content) { + try { + ObjectMapper mapper = new ObjectMapper(); + return mapper.readValue(content, new TypeReference>() {}); + } catch (Exception e) { + logger.info("getMapfromJson Exception ({})", e); + } + return null; + } +} diff --git a/blueprints-processor/plugin/assignment-provider/src/test/java/org/onap/ccsdk/features/assignment/service/ResourceAssignmentGenerationTest.java b/blueprints-processor/plugin/assignment-provider/src/test/java/org/onap/ccsdk/features/assignment/service/ResourceAssignmentGenerationTest.java new file mode 100644 index 000000000..04147d90f --- /dev/null +++ b/blueprints-processor/plugin/assignment-provider/src/test/java/org/onap/ccsdk/features/assignment/service/ResourceAssignmentGenerationTest.java @@ -0,0 +1,111 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2018 IBM. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.ccsdk.features.assignment.service; + +import java.nio.charset.Charset; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import org.apache.commons.io.IOUtils; +import org.junit.Assert; +import org.junit.Test; +import org.onap.ccsdk.features.model.ConfigModelConstant; +import org.onap.ccsdk.features.model.ValidTypes; +import org.onap.ccsdk.features.model.data.ResourceAssignment; +import org.onap.ccsdk.features.model.utils.ResourceAssignmentUtils; +import org.onap.ccsdk.features.model.utils.TransformationUtils; + +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; +import com.fasterxml.jackson.databind.JsonNode; + +public class ResourceAssignmentGenerationTest { + + private static EELFLogger logger = EELFManager.getInstance().getLogger(ResourceAssignmentGenerationTest.class); + + @Test + public void testResourceDataSetting() { + try { + logger.info(" **************** testResourceDataSetting *****************"); + String resourceAssignmentContents = IOUtils.toString(TopologicalSortingTest.class.getClassLoader() + .getResourceAsStream("assignments/alltype-empty-value-mapping.json"), Charset.defaultCharset()); + + List assignments = + TransformationUtils.getListfromJson(resourceAssignmentContents, ResourceAssignment.class); + if (assignments != null) { + Map componentContext = new HashMap<>(); + componentContext.put(ConfigModelConstant.PROPERTY_ACTION_NAME, "sample-recipe"); + for (ResourceAssignment resourceAssignment : assignments) { + if (resourceAssignment != null && resourceAssignment.getProperty() != null) { + String type = resourceAssignment.getProperty().getType(); + Object value = null; + if (ValidTypes.DATA_TYPE_STRING.equals(type)) { + value = new String("abcdef"); + } else if (ValidTypes.DATA_TYPE_INTEGER.equals(type)) { + value = new Integer(1234); + } else if (ValidTypes.DATA_TYPE_BOOLEAN.equals(type)) { + value = new Boolean(true); + } else if (ValidTypes.DATA_TYPE_LIST.equals(type)) { + String entityType = resourceAssignment.getProperty().getEntrySchema().getType(); + if (ValidTypes.DATA_TYPE_STRING.equals(entityType)) { + value = "[\"abcd-array\"]"; + } else { + String content = "[{\"name\" : \"abcd-array-complex\"}]"; + JsonNode node = TransformationUtils.getJsonNodeForString(content); + value = node; + } + } else { + String content = "{\"name\" : \"abcd-complex\"}"; + JsonNode node = TransformationUtils.getJsonNodeForString(content); + value = node; + } + ResourceAssignmentUtils.setResourceDataValue(componentContext, resourceAssignment, value); + } + } + String generatedData = ResourceAssignmentUtils.generateResourceDataForAssignments(assignments); + logger.trace("Generated Data " + generatedData); + + Assert.assertNotNull("Failed to generate resource data", generatedData); + } + } catch (Exception e) { + e.printStackTrace(); + } + } + + @Test + public void testGenerateResourceData() { + try { + logger.info(" **************** testGenerateResourceData *****************"); + String resourceAssignmentContents = IOUtils.toString(TopologicalSortingTest.class.getClassLoader() + .getResourceAsStream("assignments/alltype-mapping.json"), Charset.defaultCharset()); + + List assignments = + TransformationUtils.getListfromJson(resourceAssignmentContents, ResourceAssignment.class); + if (assignments != null) { + + String generatedData = ResourceAssignmentUtils.generateResourceDataForAssignments(assignments); + logger.trace("Generated Data " + generatedData); + + Assert.assertNotNull("Failed to generate resource data", generatedData); + } + } catch (Exception e) { + e.printStackTrace(); + } + } + +} diff --git a/blueprints-processor/plugin/assignment-provider/src/test/java/org/onap/ccsdk/features/assignment/service/ResourceAssignmentValidation.java b/blueprints-processor/plugin/assignment-provider/src/test/java/org/onap/ccsdk/features/assignment/service/ResourceAssignmentValidation.java new file mode 100644 index 000000000..a3be02920 --- /dev/null +++ b/blueprints-processor/plugin/assignment-provider/src/test/java/org/onap/ccsdk/features/assignment/service/ResourceAssignmentValidation.java @@ -0,0 +1,95 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2018 IBM. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.ccsdk.features.assignment.service; + +import java.io.IOException; +import java.nio.charset.Charset; +import java.util.List; +import org.apache.commons.io.IOUtils; +import org.junit.Assert; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; +import org.onap.ccsdk.features.model.ConfigModelException; +import org.onap.ccsdk.features.model.data.ResourceAssignment; +import org.onap.ccsdk.features.model.utils.TransformationUtils; +import org.onap.ccsdk.features.model.validator.ResourceAssignmentValidator; + +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; + +public class ResourceAssignmentValidation { + private static EELFLogger logger = EELFManager.getInstance().getLogger(ResourceAssignmentValidation.class); + + @Rule + public final ExpectedException exception = ExpectedException.none(); + + @Test + public void testValidateSuccess() { + try { + logger.info(" **************** testValidateSuccess *****************"); + String resourceMapping = IOUtils.toString( + TopologicalSortingTest.class.getClassLoader().getResourceAsStream("validation/success.json"), + Charset.defaultCharset()); + + List assignments = + TransformationUtils.getListfromJson(resourceMapping, ResourceAssignment.class); + if (assignments != null) { + ResourceAssignmentValidator resourceAssignmentValidator = new ResourceAssignmentValidator(assignments); + + boolean result = resourceAssignmentValidator.validateResourceAssignment(); + Assert.assertTrue("Failed to Validate", result); + } + } catch (Exception e) { + e.printStackTrace(); + } + } + + @Test(expected = ConfigModelException.class) + public void testValidateDuplicate() throws IOException, ConfigModelException { + logger.info(" **************** testValidateDuplicate *****************"); + String resourceMapping = IOUtils.toString( + TopologicalSortingTest.class.getClassLoader().getResourceAsStream("validation/duplicate.json"), + Charset.defaultCharset()); + + List assignments = + TransformationUtils.getListfromJson(resourceMapping, ResourceAssignment.class); + if (assignments != null) { + ResourceAssignmentValidator resourceAssignmentValidator = new ResourceAssignmentValidator(assignments); + resourceAssignmentValidator.validateResourceAssignment(); + } + + } + + @Test(expected = ConfigModelException.class) + public void testValidateCyclic() throws IOException, ConfigModelException { + logger.info(" **************** testValidateCyclic *****************"); + String resourceMapping = IOUtils.toString( + TopologicalSortingTest.class.getClassLoader().getResourceAsStream("validation/cyclic.json"), + Charset.defaultCharset()); + + List assignments = + TransformationUtils.getListfromJson(resourceMapping, ResourceAssignment.class); + if (assignments != null) { + ResourceAssignmentValidator resourceAssignmentValidator = new ResourceAssignmentValidator(assignments); + + resourceAssignmentValidator.validateResourceAssignment(); + } + + } +} diff --git a/blueprints-processor/plugin/assignment-provider/src/test/java/org/onap/ccsdk/features/assignment/service/TopologicalSortingTest.java b/blueprints-processor/plugin/assignment-provider/src/test/java/org/onap/ccsdk/features/assignment/service/TopologicalSortingTest.java new file mode 100644 index 000000000..f6e8871a6 --- /dev/null +++ b/blueprints-processor/plugin/assignment-provider/src/test/java/org/onap/ccsdk/features/assignment/service/TopologicalSortingTest.java @@ -0,0 +1,60 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2018 IBM. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.ccsdk.features.assignment.service; + +import java.nio.charset.Charset; +import java.util.List; +import org.apache.commons.io.IOUtils; +import org.junit.Assert; +import org.junit.Test; +import org.onap.ccsdk.features.assignment.processor.ResourceAssignmentProcessor; +import org.onap.ccsdk.features.model.data.ResourceAssignment; +import org.onap.ccsdk.features.model.utils.TransformationUtils; +import org.onap.ccsdk.sli.core.sli.SvcLogicContext; +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; + +public class TopologicalSortingTest { + private static EELFLogger logger = EELFManager.getInstance().getLogger(TopologicalSortingTest.class); + + @Test + public void testBulkSequencingMapping() { + try { + logger.info(" **************** Bulk Sequencing Default *****************"); + String resourceMapping = IOUtils.toString( + TopologicalSortingTest.class.getClassLoader().getResourceAsStream("mapping/dependency.json"), + Charset.defaultCharset()); + + List assignments = + TransformationUtils.getListfromJson(resourceMapping, ResourceAssignment.class); + if (assignments != null) { + SvcLogicContext ctx = new SvcLogicContext(); + ResourceAssignmentProcessor resourceAssignmentProcessor = + new ResourceAssignmentProcessor(assignments, ctx); + List> sequenceBatchResourceAssignment = resourceAssignmentProcessor.process(); + + Assert.assertNotNull("Failed to populate Sequence Bulk Mappings", sequenceBatchResourceAssignment); + Assert.assertNotEquals("Failed to populate Sequence Bulk Mappings size ", + (sequenceBatchResourceAssignment.size() > 0)); + } + } catch (Exception e) { + e.printStackTrace(); + } + } + +} diff --git a/blueprints-processor/plugin/assignment-provider/src/test/resources/service_templates/resource_assignment.json b/blueprints-processor/plugin/assignment-provider/src/test/resources/service_templates/resource_assignment.json index 0e29fe160..cbea6a82c 100644 --- a/blueprints-processor/plugin/assignment-provider/src/test/resources/service_templates/resource_assignment.json +++ b/blueprints-processor/plugin/assignment-provider/src/test/resources/service_templates/resource_assignment.json @@ -139,7 +139,7 @@ "resource-assignment": { "type": "component-resource-assignment", "interfaces": { - "org-onap-ccsdk-config-assignment-service-ConfigAssignmentNode": { + "org-onap-ccsdk-features-assignment-service-ConfigAssignmentNode": { "operations": { "process": { "inputs": { @@ -243,7 +243,7 @@ } }, "interfaces": { - "org-onap-ccsdk-config-assignment-service-ConfigAssignmentNode": { + "org-onap-ccsdk-features-assignment-service-ConfigAssignmentNode": { "operations": { "process": { "inputs": { diff --git a/blueprints-processor/plugin/assignment-provider/src/test/resources/service_templates/resource_assignment/resource_assignment.json b/blueprints-processor/plugin/assignment-provider/src/test/resources/service_templates/resource_assignment/resource_assignment.json index 6347f4223..4cbb8fa25 100644 --- a/blueprints-processor/plugin/assignment-provider/src/test/resources/service_templates/resource_assignment/resource_assignment.json +++ b/blueprints-processor/plugin/assignment-provider/src/test/resources/service_templates/resource_assignment/resource_assignment.json @@ -139,7 +139,7 @@ "resource-assignment": { "type": "component-resource-assignment", "interfaces": { - "org-onap-ccsdk-config-assignment-service-ConfigAssignmentNode": { + "org-onap-ccsdk-features-assignment-service-ConfigAssignmentNode": { "operations": { "process": { "inputs": { @@ -245,7 +245,7 @@ } }, "interfaces": { - "org-onap-ccsdk-config-assignment-service-ConfigAssignmentNode": { + "org-onap-ccsdk-features-assignment-service-ConfigAssignmentNode": { "operations": { "process": { "inputs": { diff --git a/blueprints-processor/plugin/assignment-provider/src/test/resources/service_templates/vpe-201802-baseconfig/vpe-201802-baseconfig.json b/blueprints-processor/plugin/assignment-provider/src/test/resources/service_templates/vpe-201802-baseconfig/vpe-201802-baseconfig.json index 20207a87b..7113b70c2 100644 --- a/blueprints-processor/plugin/assignment-provider/src/test/resources/service_templates/vpe-201802-baseconfig/vpe-201802-baseconfig.json +++ b/blueprints-processor/plugin/assignment-provider/src/test/resources/service_templates/vpe-201802-baseconfig/vpe-201802-baseconfig.json @@ -224,7 +224,7 @@ "resource-assignment": { "type": "component-resource-assignment", "interfaces": { - "org-onap-ccsdk-config-assignment-service-ConfigAssignmentNode": { + "org-onap-ccsdk-features-assignment-service-ConfigAssignmentNode": { "operations": { "process": { "inputs": { @@ -328,7 +328,7 @@ } }, "interfaces": { - "org-onap-ccsdk-config-assignment-service-ConfigAssignmentNode": { + "org-onap-ccsdk-features-assignment-service-ConfigAssignmentNode": { "operations": { "process": { "inputs": { diff --git a/blueprints-processor/plugin/generator-provider/pom.xml b/blueprints-processor/plugin/generator-provider/pom.xml index 006e378a2..e8a2ab026 100644 --- a/blueprints-processor/plugin/generator-provider/pom.xml +++ b/blueprints-processor/plugin/generator-provider/pom.xml @@ -108,10 +108,10 @@ ${project.artifactId} ${project.groupId}.${project.artifactId} - org.onap.ccsdk.config.generator, - org.onap.ccsdk.config.generator.data, - org.onap.ccsdk.config.generator.service, - org.onap.ccsdk.config.generator.tool + org.onap.ccsdk.features.generator, + org.onap.ccsdk.features.generator.data, + org.onap.ccsdk.features.generator.service, + org.onap.ccsdk.features.generator.tool diff --git a/blueprints-processor/plugin/generator-provider/src/main/java/org/onap/ccsdk/config/generator/ConfigGeneratorConstant.java b/blueprints-processor/plugin/generator-provider/src/main/java/org/onap/ccsdk/config/generator/ConfigGeneratorConstant.java deleted file mode 100644 index b859b69cd..000000000 --- a/blueprints-processor/plugin/generator-provider/src/main/java/org/onap/ccsdk/config/generator/ConfigGeneratorConstant.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2018 IBM. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.ccsdk.config.generator; - -public class ConfigGeneratorConstant { - - private ConfigGeneratorConstant() { - - } - - public static final String STRING_ENCODING = "utf-8"; - public static final String Y = "Y"; - public static final String N = "N"; - public static final String DATA_TYPE_TEXT = "TEXT"; - public static final String DATA_TYPE_JSON = "JSON"; - public static final String DATA_TYPE_XML = "XML"; - public static final String DATA_TYPE_SQL = "SQL"; - - public static final String INPUT_PARAM_REQUEST_ID = "request-id"; - public static final String INPUT_PARAM_RESOURCE_ID = "resource-id"; - public static final String INPUT_PARAM_RESOURCE_TYPE = "resource-type"; - public static final String INPUT_PARAM_ACTION_NAME = "action-name"; - public static final String INPUT_PARAM_TEMPLATE_NAME = "template-name"; - public static final String INPUT_PARAM_TEMPLATE_CONTENT = "template-content"; - public static final String INPUT_PARAM_TEMPLATE_DATA = "template-data"; - - public static final String OUTPUT_PARAM_GENERATED_CONFIG = "generated-config"; - public static final String OUTPUT_PARAM_MASK_INFO = "mask-info"; - public static final String OUTPUT_PARAM_STATUS = "status"; - public static final String OUTPUT_PARAM_ERROR_MESSAGE = "error-message"; - public static final String OUTPUT_STATUS_SUCCESS = "success"; - public static final String OUTPUT_STATUS_FAILURE = "failure"; - -} diff --git a/blueprints-processor/plugin/generator-provider/src/main/java/org/onap/ccsdk/config/generator/data/ConfigGeneratorInfo.java b/blueprints-processor/plugin/generator-provider/src/main/java/org/onap/ccsdk/config/generator/data/ConfigGeneratorInfo.java deleted file mode 100644 index ec461549a..000000000 --- a/blueprints-processor/plugin/generator-provider/src/main/java/org/onap/ccsdk/config/generator/data/ConfigGeneratorInfo.java +++ /dev/null @@ -1,102 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2018 IBM. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.ccsdk.config.generator.data; - -public class ConfigGeneratorInfo { - - private String requestId; - private String resourceId; - private String resourceType; - private String templateName; - private String recipeName; - private String resourceData; - private String templateContent; - private String mashedData; - - public String getRequestId() { - return requestId; - } - - public void setRequestId(String requestId) { - this.requestId = requestId; - } - - public String getResourceId() { - return resourceId; - } - - public void setResourceId(String resourceId) { - this.resourceId = resourceId; - } - - public String getResourceType() { - return resourceType; - } - - public void setResourceType(String resourceType) { - this.resourceType = resourceType; - } - - public String getTemplateName() { - return templateName; - } - - public void setTemplateName(String templateName) { - this.templateName = templateName; - } - - public String getRecipeName() { - return recipeName; - } - - public void setRecipeName(String recipeName) { - this.recipeName = recipeName; - } - - public String getResourceData() { - return resourceData; - } - - public void setResourceData(String resourceData) { - this.resourceData = resourceData; - } - - public String getTemplateContent() { - return templateContent; - } - - public void setTemplateContent(String templateContent) { - this.templateContent = templateContent; - } - - public String getMashedData() { - return mashedData; - } - - public void setMashedData(String mashedData) { - this.mashedData = mashedData; - } - - @Override - public String toString() { - return "ConfigGeneratorInfo [requestId=" + requestId + ", resourceId=" + resourceId + ", resourceType=" - + resourceType + ", templateName=" + templateName + ", recipeName=" + recipeName + ", resourceData=" - + resourceData + ", templateContent=" + templateContent + ", mashedData=" + mashedData + "]"; - } - -} diff --git a/blueprints-processor/plugin/generator-provider/src/main/java/org/onap/ccsdk/config/generator/service/ConfigGeneratorNode.java b/blueprints-processor/plugin/generator-provider/src/main/java/org/onap/ccsdk/config/generator/service/ConfigGeneratorNode.java deleted file mode 100644 index 136ba7f25..000000000 --- a/blueprints-processor/plugin/generator-provider/src/main/java/org/onap/ccsdk/config/generator/service/ConfigGeneratorNode.java +++ /dev/null @@ -1,140 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2018 IBM. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.ccsdk.config.generator.service; - -import java.util.Map; -import org.apache.commons.lang3.StringUtils; -import org.onap.ccsdk.config.data.adaptor.service.ConfigResourceService; -import org.onap.ccsdk.config.generator.ConfigGeneratorConstant; -import org.onap.ccsdk.config.generator.data.ConfigGeneratorInfo; -import org.onap.ccsdk.config.model.ConfigModelConstant; -import org.onap.ccsdk.config.model.service.ComponentNode; -import org.onap.ccsdk.config.model.service.ConfigModelService; -import org.onap.ccsdk.sli.core.sli.SvcLogicContext; -import org.onap.ccsdk.sli.core.sli.SvcLogicException; -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; - -public class ConfigGeneratorNode implements ComponentNode { - - private static EELFLogger logger = EELFManager.getInstance().getLogger(ConfigGeneratorNode.class); - - private ConfigModelService configModelService; - private ConfigResourceService configResourceService; - private ConfigGeneratorService configGeneratorService; - - public ConfigGeneratorNode(ConfigResourceService configResourceService, ConfigModelService configModelService) { - this.configResourceService = configResourceService; - this.configModelService = configModelService; - this.configGeneratorService = new ConfigGeneratorServiceImpl(this.configResourceService); - } - - @Override - public Boolean preCondition(Map inParams, SvcLogicContext ctx, Map componentContext) - throws SvcLogicException { - logger.trace("Received generateConfiguration preCondition call with params : ({})", inParams); - return Boolean.TRUE; - } - - @Override - public void preProcess(Map inParams, SvcLogicContext ctx, Map componentContext) - throws SvcLogicException { - logger.trace("Received generateConfiguration preProcess call with params : ({})", inParams); - } - - @Override - public void process(Map inParams, SvcLogicContext ctx) throws SvcLogicException { - logger.trace("Received generateConfiguration process call with params : ({})", inParams); - } - - @SuppressWarnings("squid:S3776") - @Override - public void process(Map inParams, SvcLogicContext ctx, Map componentContext) - throws SvcLogicException { - logger.trace("Received generateConfiguration process with params : ({})", inParams); - String prifix = inParams.get(ConfigModelConstant.PROPERTY_SELECTOR); - try { - prifix = StringUtils.isNotBlank(prifix) ? (prifix + ".") : ""; - - String templateContent = inParams.get(ConfigGeneratorConstant.INPUT_PARAM_TEMPLATE_CONTENT); - String templateData = inParams.get(ConfigGeneratorConstant.INPUT_PARAM_TEMPLATE_DATA); - String requestId = inParams.get(ConfigGeneratorConstant.INPUT_PARAM_REQUEST_ID); - String resourceId = inParams.get(ConfigGeneratorConstant.INPUT_PARAM_RESOURCE_ID); - String resourceType = inParams.get(ConfigGeneratorConstant.INPUT_PARAM_RESOURCE_TYPE); - String recipeName = inParams.get(ConfigGeneratorConstant.INPUT_PARAM_ACTION_NAME); - String templateName = inParams.get(ConfigGeneratorConstant.INPUT_PARAM_TEMPLATE_NAME); - - ConfigGeneratorInfo configGeneratorInfo = null; - if (StringUtils.isNotBlank(templateContent) && StringUtils.isNotBlank(templateData)) { - configGeneratorInfo = this.configGeneratorService.generateConfiguration(templateContent, templateData); - } else { - if (StringUtils.isBlank(requestId)) { - throw new SvcLogicException("Config Generator Request Id is missing."); - } - if (StringUtils.isBlank(resourceId)) { - throw new SvcLogicException("Config Generator Resource Id is missing."); - } - if (StringUtils.isBlank(resourceType)) { - throw new SvcLogicException("Config Generator Resource Type is missing."); - } - if (StringUtils.isBlank(recipeName)) { - throw new SvcLogicException("Config Generator Action Name is missing."); - } - if (StringUtils.isBlank(templateName)) { - throw new SvcLogicException("Config Generator Template Name Id is missing."); - } - - templateContent = configModelService.getNodeTemplateContent(ctx, templateName); - - if (StringUtils.isBlank(templateContent)) { - throw new SvcLogicException( - "Failed to get the Template Content for the Temaple Name :" + templateName); - } - - configGeneratorInfo = new ConfigGeneratorInfo(); - configGeneratorInfo.setRequestId(requestId); - configGeneratorInfo.setResourceId(resourceId); - configGeneratorInfo.setResourceType(resourceType); - configGeneratorInfo.setRecipeName(recipeName); - configGeneratorInfo.setTemplateName(templateName); - configGeneratorInfo.setTemplateContent(templateContent); - - this.configGeneratorService.generateConfiguration(configGeneratorInfo); - } - if (configGeneratorInfo != null) { - ctx.setAttribute(prifix + ConfigGeneratorConstant.OUTPUT_PARAM_GENERATED_CONFIG, - configGeneratorInfo.getMashedData()); - } - ctx.setAttribute(prifix + ConfigGeneratorConstant.OUTPUT_PARAM_STATUS, - ConfigGeneratorConstant.OUTPUT_STATUS_SUCCESS); - } catch (Exception e) { - ctx.setAttribute(prifix + ConfigGeneratorConstant.OUTPUT_PARAM_STATUS, - ConfigGeneratorConstant.OUTPUT_STATUS_FAILURE); - ctx.setAttribute(prifix + ConfigGeneratorConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage()); - logger.error("Failed in generateConfiguration ({})", e); - throw new SvcLogicException(e.getMessage()); - } - } - - @Override - public void postProcess(Map inParams, SvcLogicContext ctx, Map componentContext) - throws SvcLogicException { - logger.info("Received generateConfiguration postProcess with params : ({})", inParams); - } - -} diff --git a/blueprints-processor/plugin/generator-provider/src/main/java/org/onap/ccsdk/config/generator/service/ConfigGeneratorService.java b/blueprints-processor/plugin/generator-provider/src/main/java/org/onap/ccsdk/config/generator/service/ConfigGeneratorService.java deleted file mode 100644 index 710d47d25..000000000 --- a/blueprints-processor/plugin/generator-provider/src/main/java/org/onap/ccsdk/config/generator/service/ConfigGeneratorService.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2018 IBM. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.ccsdk.config.generator.service; - -import org.onap.ccsdk.config.generator.data.ConfigGeneratorInfo; -import org.onap.ccsdk.sli.core.sli.SvcLogicException; - -public interface ConfigGeneratorService { - - public ConfigGeneratorInfo generateConfiguration(String templateContent, String templateData) - throws SvcLogicException; - - public ConfigGeneratorInfo generateConfiguration(String templateContent, String templateData, boolean ignoreNull) - throws SvcLogicException; - - public ConfigGeneratorInfo generateConfiguration(ConfigGeneratorInfo configGeneratorInfo) throws SvcLogicException; - -} diff --git a/blueprints-processor/plugin/generator-provider/src/main/java/org/onap/ccsdk/config/generator/service/ConfigGeneratorServiceImpl.java b/blueprints-processor/plugin/generator-provider/src/main/java/org/onap/ccsdk/config/generator/service/ConfigGeneratorServiceImpl.java deleted file mode 100644 index 472f5b291..000000000 --- a/blueprints-processor/plugin/generator-provider/src/main/java/org/onap/ccsdk/config/generator/service/ConfigGeneratorServiceImpl.java +++ /dev/null @@ -1,143 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2018 IBM. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.ccsdk.config.generator.service; - -import java.io.StringWriter; -import java.util.Iterator; -import java.util.List; -import org.apache.commons.collections.CollectionUtils; -import org.apache.commons.lang3.StringUtils; -import org.apache.velocity.VelocityContext; -import org.apache.velocity.app.Velocity; -import org.onap.ccsdk.config.data.adaptor.domain.ConfigResource; -import org.onap.ccsdk.config.data.adaptor.service.ConfigResourceService; -import org.onap.ccsdk.config.generator.data.ConfigGeneratorInfo; -import org.onap.ccsdk.config.generator.tool.CustomJsonNodeFactory; -import org.onap.ccsdk.config.model.utils.TransformationUtils; -import org.onap.ccsdk.sli.core.sli.SvcLogicException; -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; -import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.ObjectMapper; - -public class ConfigGeneratorServiceImpl implements ConfigGeneratorService { - - private static EELFLogger logger = EELFManager.getInstance().getLogger(ConfigGeneratorServiceImpl.class); - private static final String CLASS_NAME = "ConfigGeneratorServiceImpl"; - - private ConfigResourceService configResourceService; - - public ConfigGeneratorServiceImpl(ConfigResourceService configResourceService) { - logger.info("{} Constuctor Initated...", CLASS_NAME); - this.configResourceService = configResourceService; - } - - @Override - public ConfigGeneratorInfo generateConfiguration(ConfigGeneratorInfo configGeneratorInfo) throws SvcLogicException { - - if (configGeneratorInfo != null && StringUtils.isNotBlank(configGeneratorInfo.getResourceId()) - && StringUtils.isNotBlank(configGeneratorInfo.getResourceType()) - && StringUtils.isNotBlank(configGeneratorInfo.getRecipeName()) - && StringUtils.isNotBlank(configGeneratorInfo.getTemplateName()) - && StringUtils.isNotBlank(configGeneratorInfo.getTemplateContent())) { - - ConfigResource configResourceQuery = new ConfigResource(); - configResourceQuery.setResourceId(configGeneratorInfo.getResourceId()); - configResourceQuery.setResourceType(configGeneratorInfo.getResourceType()); - configResourceQuery.setTemplateName(configGeneratorInfo.getTemplateName()); - - List configResourceList = configResourceService.getConfigResource(configResourceQuery); - - if (CollectionUtils.isEmpty(configResourceList)) { - throw new SvcLogicException("No Config Resource found"); - } else if (configResourceList.size() > 1) { - throw new SvcLogicException("More than one Config Resource found for specified parameter for" - + " resourceId " + configGeneratorInfo.getResourceId() + ", resourceType " - + configGeneratorInfo.getResourceType() + ", recipeName " + configGeneratorInfo.getRecipeName() - + ", templateName " + configGeneratorInfo.getTemplateName()); - } - - ConfigResource configResource = configResourceList.get(0); - - if (configResource != null && StringUtils.isNotBlank(configResource.getResourceData())) { - configGeneratorInfo.setResourceData(configResource.getResourceData()); - logger.debug("Retrieve ConfigResource Data : ({})", configResource.getResourceData()); - ConfigGeneratorInfo generatorInfo = generateConfiguration(configGeneratorInfo.getTemplateContent(), - configResource.getResourceData()); - if (generatorInfo != null) { - configGeneratorInfo.setMashedData(generatorInfo.getMashedData()); - } - } else { - throw new SvcLogicException( - "Failed to get the Resource Data for the Resource Id :" + configGeneratorInfo.getResourceId() - + " of template :" + configGeneratorInfo.getTemplateName()); - } - } - return configGeneratorInfo; - } - - @Override - public ConfigGeneratorInfo generateConfiguration(String templateContent, String templateData) - throws SvcLogicException { - return generateConfiguration(templateContent, templateData, true); - } - - @Override - public ConfigGeneratorInfo generateConfiguration(String templateContent, String templateData, boolean ignoreNull) - throws SvcLogicException { - ConfigGeneratorInfo configGeneratorInfo = null; - try { - if (StringUtils.isNotBlank(templateContent) && StringUtils.isNotBlank(templateData)) { - configGeneratorInfo = new ConfigGeneratorInfo(); - - Velocity.init(); - - ObjectMapper mapper = new ObjectMapper(); - CustomJsonNodeFactory f = new CustomJsonNodeFactory(); - mapper.setNodeFactory(f); - - JsonNode jsonObj = mapper.readValue(templateData, JsonNode.class); - if (ignoreNull) { - TransformationUtils.removeJsonNullNode(jsonObj); - } - - VelocityContext context = new VelocityContext(); - context.put("StringUtils", org.apache.commons.lang3.StringUtils.class); - context.put("BooleanUtils", org.apache.commons.lang3.BooleanUtils.class); - - Iterator ii = jsonObj.fieldNames(); - while (ii.hasNext()) { - String key = ii.next(); - JsonNode node = jsonObj.get(key); - logger.info("Adding key ({}) with value ({})", key, node); - context.put(key, node); - } - - StringWriter writer = new StringWriter(); - Velocity.evaluate(context, writer, "TemplateData", templateContent); - writer.flush(); - configGeneratorInfo.setMashedData(writer.toString()); - } - } catch (Exception e) { - logger.error("Failed to generate Configuration ({})", e.getMessage()); - throw new SvcLogicException(e.getMessage(), e); - } - return configGeneratorInfo; - } - -} diff --git a/blueprints-processor/plugin/generator-provider/src/main/java/org/onap/ccsdk/config/generator/tool/CustomJsonNodeFactory.java b/blueprints-processor/plugin/generator-provider/src/main/java/org/onap/ccsdk/config/generator/tool/CustomJsonNodeFactory.java deleted file mode 100644 index 3e69ef355..000000000 --- a/blueprints-processor/plugin/generator-provider/src/main/java/org/onap/ccsdk/config/generator/tool/CustomJsonNodeFactory.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2018 IBM. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.ccsdk.config.generator.tool; - -import com.fasterxml.jackson.databind.node.JsonNodeFactory; -import com.fasterxml.jackson.databind.node.TextNode; - -public class CustomJsonNodeFactory extends JsonNodeFactory { - - @Override - public TextNode textNode(String text) { - return new CustomTextNode(text); - } - -} diff --git a/blueprints-processor/plugin/generator-provider/src/main/java/org/onap/ccsdk/config/generator/tool/CustomTextNode.java b/blueprints-processor/plugin/generator-provider/src/main/java/org/onap/ccsdk/config/generator/tool/CustomTextNode.java deleted file mode 100644 index cf42c552b..000000000 --- a/blueprints-processor/plugin/generator-provider/src/main/java/org/onap/ccsdk/config/generator/tool/CustomTextNode.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2018 IBM. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.ccsdk.config.generator.tool; - -import com.fasterxml.jackson.core.io.CharTypes; -import com.fasterxml.jackson.databind.node.TextNode; - -public class CustomTextNode extends TextNode { - - public CustomTextNode(String v) { - super(v); - } - - @Override - public String toString() { - int len = textValue().length(); - len = len + 2 + (len >> 4); - StringBuilder sb = new StringBuilder(len); - appendQuoted(sb, textValue()); - return sb.toString(); - } - - protected static void appendQuoted(StringBuilder sb, String content) { - CharTypes.appendQuoted(sb, content); - } - -} diff --git a/blueprints-processor/plugin/generator-provider/src/main/java/org/onap/ccsdk/config/generator/tool/EscapeUtils.java b/blueprints-processor/plugin/generator-provider/src/main/java/org/onap/ccsdk/config/generator/tool/EscapeUtils.java deleted file mode 100644 index 3009f87f9..000000000 --- a/blueprints-processor/plugin/generator-provider/src/main/java/org/onap/ccsdk/config/generator/tool/EscapeUtils.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2018 IBM. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.ccsdk.config.generator.tool; - -import org.apache.commons.lang3.StringUtils; - -@SuppressWarnings("squid:S1118") -public class EscapeUtils { - - public static String escapeSql(String str) { - if (str == null) { - return null; - } - String[] searchList = new String[] {"'", "\\"}; - String[] replacementList = new String[] {"''", "\\\\"}; - return StringUtils.replaceEach(str, searchList, replacementList); - } - - // For Generic Purpose - public static String escapeSequence(String s) { - if (s == null) { - return null; - } - - int length = s.length(); - int newLength = length; - for (int i = 0; i < length; i++) { - char c = s.charAt(i); - switch (c) { - case '\\': - case '\"': - case '\'': - case '\0': - newLength += 1; - break; - default: - // do nothing - } - } - if (length == newLength) { - // nothing to escape in the string - return s; - } - StringBuilder sb = new StringBuilder(newLength); - for (int i = 0; i < length; i++) { - char c = s.charAt(i); - switch (c) { - case '\\': - sb.append("\\\\"); - break; - case '\"': - sb.append("\\\""); - break; - case '\'': - sb.append("\\\'"); - break; - case '\0': - sb.append("\\0"); - break; - default: - sb.append(c); - } - } - return sb.toString(); - } - -} diff --git a/blueprints-processor/plugin/generator-provider/src/main/java/org/onap/ccsdk/features/generator/ConfigGeneratorConstant.java b/blueprints-processor/plugin/generator-provider/src/main/java/org/onap/ccsdk/features/generator/ConfigGeneratorConstant.java new file mode 100644 index 000000000..06c423b5e --- /dev/null +++ b/blueprints-processor/plugin/generator-provider/src/main/java/org/onap/ccsdk/features/generator/ConfigGeneratorConstant.java @@ -0,0 +1,49 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2018 IBM. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.ccsdk.features.generator; + +public class ConfigGeneratorConstant { + + private ConfigGeneratorConstant() { + + } + + public static final String STRING_ENCODING = "utf-8"; + public static final String Y = "Y"; + public static final String N = "N"; + public static final String DATA_TYPE_TEXT = "TEXT"; + public static final String DATA_TYPE_JSON = "JSON"; + public static final String DATA_TYPE_XML = "XML"; + public static final String DATA_TYPE_SQL = "SQL"; + + public static final String INPUT_PARAM_REQUEST_ID = "request-id"; + public static final String INPUT_PARAM_RESOURCE_ID = "resource-id"; + public static final String INPUT_PARAM_RESOURCE_TYPE = "resource-type"; + public static final String INPUT_PARAM_ACTION_NAME = "action-name"; + public static final String INPUT_PARAM_TEMPLATE_NAME = "template-name"; + public static final String INPUT_PARAM_TEMPLATE_CONTENT = "template-content"; + public static final String INPUT_PARAM_TEMPLATE_DATA = "template-data"; + + public static final String OUTPUT_PARAM_GENERATED_CONFIG = "generated-config"; + public static final String OUTPUT_PARAM_MASK_INFO = "mask-info"; + public static final String OUTPUT_PARAM_STATUS = "status"; + public static final String OUTPUT_PARAM_ERROR_MESSAGE = "error-message"; + public static final String OUTPUT_STATUS_SUCCESS = "success"; + public static final String OUTPUT_STATUS_FAILURE = "failure"; + +} diff --git a/blueprints-processor/plugin/generator-provider/src/main/java/org/onap/ccsdk/features/generator/data/ConfigGeneratorInfo.java b/blueprints-processor/plugin/generator-provider/src/main/java/org/onap/ccsdk/features/generator/data/ConfigGeneratorInfo.java new file mode 100644 index 000000000..0b7ea0435 --- /dev/null +++ b/blueprints-processor/plugin/generator-provider/src/main/java/org/onap/ccsdk/features/generator/data/ConfigGeneratorInfo.java @@ -0,0 +1,102 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2018 IBM. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.ccsdk.features.generator.data; + +public class ConfigGeneratorInfo { + + private String requestId; + private String resourceId; + private String resourceType; + private String templateName; + private String recipeName; + private String resourceData; + private String templateContent; + private String mashedData; + + public String getRequestId() { + return requestId; + } + + public void setRequestId(String requestId) { + this.requestId = requestId; + } + + public String getResourceId() { + return resourceId; + } + + public void setResourceId(String resourceId) { + this.resourceId = resourceId; + } + + public String getResourceType() { + return resourceType; + } + + public void setResourceType(String resourceType) { + this.resourceType = resourceType; + } + + public String getTemplateName() { + return templateName; + } + + public void setTemplateName(String templateName) { + this.templateName = templateName; + } + + public String getRecipeName() { + return recipeName; + } + + public void setRecipeName(String recipeName) { + this.recipeName = recipeName; + } + + public String getResourceData() { + return resourceData; + } + + public void setResourceData(String resourceData) { + this.resourceData = resourceData; + } + + public String getTemplateContent() { + return templateContent; + } + + public void setTemplateContent(String templateContent) { + this.templateContent = templateContent; + } + + public String getMashedData() { + return mashedData; + } + + public void setMashedData(String mashedData) { + this.mashedData = mashedData; + } + + @Override + public String toString() { + return "ConfigGeneratorInfo [requestId=" + requestId + ", resourceId=" + resourceId + ", resourceType=" + + resourceType + ", templateName=" + templateName + ", recipeName=" + recipeName + ", resourceData=" + + resourceData + ", templateContent=" + templateContent + ", mashedData=" + mashedData + "]"; + } + +} diff --git a/blueprints-processor/plugin/generator-provider/src/main/java/org/onap/ccsdk/features/generator/service/ConfigGeneratorNode.java b/blueprints-processor/plugin/generator-provider/src/main/java/org/onap/ccsdk/features/generator/service/ConfigGeneratorNode.java new file mode 100644 index 000000000..421692b89 --- /dev/null +++ b/blueprints-processor/plugin/generator-provider/src/main/java/org/onap/ccsdk/features/generator/service/ConfigGeneratorNode.java @@ -0,0 +1,140 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2018 IBM. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.ccsdk.features.generator.service; + +import java.util.Map; +import org.apache.commons.lang3.StringUtils; +import org.onap.ccsdk.features.data.adaptor.service.ConfigResourceService; +import org.onap.ccsdk.features.generator.ConfigGeneratorConstant; +import org.onap.ccsdk.features.generator.data.ConfigGeneratorInfo; +import org.onap.ccsdk.features.model.ConfigModelConstant; +import org.onap.ccsdk.features.model.service.ComponentNode; +import org.onap.ccsdk.features.model.service.ConfigModelService; +import org.onap.ccsdk.sli.core.sli.SvcLogicContext; +import org.onap.ccsdk.sli.core.sli.SvcLogicException; +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; + +public class ConfigGeneratorNode implements ComponentNode { + + private static EELFLogger logger = EELFManager.getInstance().getLogger(ConfigGeneratorNode.class); + + private ConfigModelService configModelService; + private ConfigResourceService configResourceService; + private ConfigGeneratorService configGeneratorService; + + public ConfigGeneratorNode(ConfigResourceService configResourceService, ConfigModelService configModelService) { + this.configResourceService = configResourceService; + this.configModelService = configModelService; + this.configGeneratorService = new ConfigGeneratorServiceImpl(this.configResourceService); + } + + @Override + public Boolean preCondition(Map inParams, SvcLogicContext ctx, Map componentContext) + throws SvcLogicException { + logger.trace("Received generateConfiguration preCondition call with params : ({})", inParams); + return Boolean.TRUE; + } + + @Override + public void preProcess(Map inParams, SvcLogicContext ctx, Map componentContext) + throws SvcLogicException { + logger.trace("Received generateConfiguration preProcess call with params : ({})", inParams); + } + + @Override + public void process(Map inParams, SvcLogicContext ctx) throws SvcLogicException { + logger.trace("Received generateConfiguration process call with params : ({})", inParams); + } + + @SuppressWarnings("squid:S3776") + @Override + public void process(Map inParams, SvcLogicContext ctx, Map componentContext) + throws SvcLogicException { + logger.trace("Received generateConfiguration process with params : ({})", inParams); + String prifix = inParams.get(ConfigModelConstant.PROPERTY_SELECTOR); + try { + prifix = StringUtils.isNotBlank(prifix) ? (prifix + ".") : ""; + + String templateContent = inParams.get(ConfigGeneratorConstant.INPUT_PARAM_TEMPLATE_CONTENT); + String templateData = inParams.get(ConfigGeneratorConstant.INPUT_PARAM_TEMPLATE_DATA); + String requestId = inParams.get(ConfigGeneratorConstant.INPUT_PARAM_REQUEST_ID); + String resourceId = inParams.get(ConfigGeneratorConstant.INPUT_PARAM_RESOURCE_ID); + String resourceType = inParams.get(ConfigGeneratorConstant.INPUT_PARAM_RESOURCE_TYPE); + String recipeName = inParams.get(ConfigGeneratorConstant.INPUT_PARAM_ACTION_NAME); + String templateName = inParams.get(ConfigGeneratorConstant.INPUT_PARAM_TEMPLATE_NAME); + + ConfigGeneratorInfo configGeneratorInfo = null; + if (StringUtils.isNotBlank(templateContent) && StringUtils.isNotBlank(templateData)) { + configGeneratorInfo = this.configGeneratorService.generateConfiguration(templateContent, templateData); + } else { + if (StringUtils.isBlank(requestId)) { + throw new SvcLogicException("Config Generator Request Id is missing."); + } + if (StringUtils.isBlank(resourceId)) { + throw new SvcLogicException("Config Generator Resource Id is missing."); + } + if (StringUtils.isBlank(resourceType)) { + throw new SvcLogicException("Config Generator Resource Type is missing."); + } + if (StringUtils.isBlank(recipeName)) { + throw new SvcLogicException("Config Generator Action Name is missing."); + } + if (StringUtils.isBlank(templateName)) { + throw new SvcLogicException("Config Generator Template Name Id is missing."); + } + + templateContent = configModelService.getNodeTemplateContent(ctx, templateName); + + if (StringUtils.isBlank(templateContent)) { + throw new SvcLogicException( + "Failed to get the Template Content for the Temaple Name :" + templateName); + } + + configGeneratorInfo = new ConfigGeneratorInfo(); + configGeneratorInfo.setRequestId(requestId); + configGeneratorInfo.setResourceId(resourceId); + configGeneratorInfo.setResourceType(resourceType); + configGeneratorInfo.setRecipeName(recipeName); + configGeneratorInfo.setTemplateName(templateName); + configGeneratorInfo.setTemplateContent(templateContent); + + this.configGeneratorService.generateConfiguration(configGeneratorInfo); + } + if (configGeneratorInfo != null) { + ctx.setAttribute(prifix + ConfigGeneratorConstant.OUTPUT_PARAM_GENERATED_CONFIG, + configGeneratorInfo.getMashedData()); + } + ctx.setAttribute(prifix + ConfigGeneratorConstant.OUTPUT_PARAM_STATUS, + ConfigGeneratorConstant.OUTPUT_STATUS_SUCCESS); + } catch (Exception e) { + ctx.setAttribute(prifix + ConfigGeneratorConstant.OUTPUT_PARAM_STATUS, + ConfigGeneratorConstant.OUTPUT_STATUS_FAILURE); + ctx.setAttribute(prifix + ConfigGeneratorConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage()); + logger.error("Failed in generateConfiguration ({})", e); + throw new SvcLogicException(e.getMessage()); + } + } + + @Override + public void postProcess(Map inParams, SvcLogicContext ctx, Map componentContext) + throws SvcLogicException { + logger.info("Received generateConfiguration postProcess with params : ({})", inParams); + } + +} diff --git a/blueprints-processor/plugin/generator-provider/src/main/java/org/onap/ccsdk/features/generator/service/ConfigGeneratorService.java b/blueprints-processor/plugin/generator-provider/src/main/java/org/onap/ccsdk/features/generator/service/ConfigGeneratorService.java new file mode 100644 index 000000000..b8a943083 --- /dev/null +++ b/blueprints-processor/plugin/generator-provider/src/main/java/org/onap/ccsdk/features/generator/service/ConfigGeneratorService.java @@ -0,0 +1,33 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2018 IBM. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.ccsdk.features.generator.service; + +import org.onap.ccsdk.features.generator.data.ConfigGeneratorInfo; +import org.onap.ccsdk.sli.core.sli.SvcLogicException; + +public interface ConfigGeneratorService { + + public ConfigGeneratorInfo generateConfiguration(String templateContent, String templateData) + throws SvcLogicException; + + public ConfigGeneratorInfo generateConfiguration(String templateContent, String templateData, boolean ignoreNull) + throws SvcLogicException; + + public ConfigGeneratorInfo generateConfiguration(ConfigGeneratorInfo configGeneratorInfo) throws SvcLogicException; + +} diff --git a/blueprints-processor/plugin/generator-provider/src/main/java/org/onap/ccsdk/features/generator/service/ConfigGeneratorServiceImpl.java b/blueprints-processor/plugin/generator-provider/src/main/java/org/onap/ccsdk/features/generator/service/ConfigGeneratorServiceImpl.java new file mode 100644 index 000000000..6292b8def --- /dev/null +++ b/blueprints-processor/plugin/generator-provider/src/main/java/org/onap/ccsdk/features/generator/service/ConfigGeneratorServiceImpl.java @@ -0,0 +1,143 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2018 IBM. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.ccsdk.features.generator.service; + +import java.io.StringWriter; +import java.util.Iterator; +import java.util.List; +import org.apache.commons.collections.CollectionUtils; +import org.apache.commons.lang3.StringUtils; +import org.apache.velocity.VelocityContext; +import org.apache.velocity.app.Velocity; +import org.onap.ccsdk.features.data.adaptor.domain.ConfigResource; +import org.onap.ccsdk.features.data.adaptor.service.ConfigResourceService; +import org.onap.ccsdk.features.generator.data.ConfigGeneratorInfo; +import org.onap.ccsdk.features.generator.tool.CustomJsonNodeFactory; +import org.onap.ccsdk.features.model.utils.TransformationUtils; +import org.onap.ccsdk.sli.core.sli.SvcLogicException; +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; + +public class ConfigGeneratorServiceImpl implements ConfigGeneratorService { + + private static EELFLogger logger = EELFManager.getInstance().getLogger(ConfigGeneratorServiceImpl.class); + private static final String CLASS_NAME = "ConfigGeneratorServiceImpl"; + + private ConfigResourceService configResourceService; + + public ConfigGeneratorServiceImpl(ConfigResourceService configResourceService) { + logger.info("{} Constuctor Initated...", CLASS_NAME); + this.configResourceService = configResourceService; + } + + @Override + public ConfigGeneratorInfo generateConfiguration(ConfigGeneratorInfo configGeneratorInfo) throws SvcLogicException { + + if (configGeneratorInfo != null && StringUtils.isNotBlank(configGeneratorInfo.getResourceId()) + && StringUtils.isNotBlank(configGeneratorInfo.getResourceType()) + && StringUtils.isNotBlank(configGeneratorInfo.getRecipeName()) + && StringUtils.isNotBlank(configGeneratorInfo.getTemplateName()) + && StringUtils.isNotBlank(configGeneratorInfo.getTemplateContent())) { + + ConfigResource configResourceQuery = new ConfigResource(); + configResourceQuery.setResourceId(configGeneratorInfo.getResourceId()); + configResourceQuery.setResourceType(configGeneratorInfo.getResourceType()); + configResourceQuery.setTemplateName(configGeneratorInfo.getTemplateName()); + + List configResourceList = configResourceService.getConfigResource(configResourceQuery); + + if (CollectionUtils.isEmpty(configResourceList)) { + throw new SvcLogicException("No Config Resource found"); + } else if (configResourceList.size() > 1) { + throw new SvcLogicException("More than one Config Resource found for specified parameter for" + + " resourceId " + configGeneratorInfo.getResourceId() + ", resourceType " + + configGeneratorInfo.getResourceType() + ", recipeName " + configGeneratorInfo.getRecipeName() + + ", templateName " + configGeneratorInfo.getTemplateName()); + } + + ConfigResource configResource = configResourceList.get(0); + + if (configResource != null && StringUtils.isNotBlank(configResource.getResourceData())) { + configGeneratorInfo.setResourceData(configResource.getResourceData()); + logger.debug("Retrieve ConfigResource Data : ({})", configResource.getResourceData()); + ConfigGeneratorInfo generatorInfo = generateConfiguration(configGeneratorInfo.getTemplateContent(), + configResource.getResourceData()); + if (generatorInfo != null) { + configGeneratorInfo.setMashedData(generatorInfo.getMashedData()); + } + } else { + throw new SvcLogicException( + "Failed to get the Resource Data for the Resource Id :" + configGeneratorInfo.getResourceId() + + " of template :" + configGeneratorInfo.getTemplateName()); + } + } + return configGeneratorInfo; + } + + @Override + public ConfigGeneratorInfo generateConfiguration(String templateContent, String templateData) + throws SvcLogicException { + return generateConfiguration(templateContent, templateData, true); + } + + @Override + public ConfigGeneratorInfo generateConfiguration(String templateContent, String templateData, boolean ignoreNull) + throws SvcLogicException { + ConfigGeneratorInfo configGeneratorInfo = null; + try { + if (StringUtils.isNotBlank(templateContent) && StringUtils.isNotBlank(templateData)) { + configGeneratorInfo = new ConfigGeneratorInfo(); + + Velocity.init(); + + ObjectMapper mapper = new ObjectMapper(); + CustomJsonNodeFactory f = new CustomJsonNodeFactory(); + mapper.setNodeFactory(f); + + JsonNode jsonObj = mapper.readValue(templateData, JsonNode.class); + if (ignoreNull) { + TransformationUtils.removeJsonNullNode(jsonObj); + } + + VelocityContext context = new VelocityContext(); + context.put("StringUtils", org.apache.commons.lang3.StringUtils.class); + context.put("BooleanUtils", org.apache.commons.lang3.BooleanUtils.class); + + Iterator ii = jsonObj.fieldNames(); + while (ii.hasNext()) { + String key = ii.next(); + JsonNode node = jsonObj.get(key); + logger.info("Adding key ({}) with value ({})", key, node); + context.put(key, node); + } + + StringWriter writer = new StringWriter(); + Velocity.evaluate(context, writer, "TemplateData", templateContent); + writer.flush(); + configGeneratorInfo.setMashedData(writer.toString()); + } + } catch (Exception e) { + logger.error("Failed to generate Configuration ({})", e.getMessage()); + throw new SvcLogicException(e.getMessage(), e); + } + return configGeneratorInfo; + } + +} diff --git a/blueprints-processor/plugin/generator-provider/src/main/java/org/onap/ccsdk/features/generator/tool/CustomJsonNodeFactory.java b/blueprints-processor/plugin/generator-provider/src/main/java/org/onap/ccsdk/features/generator/tool/CustomJsonNodeFactory.java new file mode 100644 index 000000000..f20cef2a6 --- /dev/null +++ b/blueprints-processor/plugin/generator-provider/src/main/java/org/onap/ccsdk/features/generator/tool/CustomJsonNodeFactory.java @@ -0,0 +1,30 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2018 IBM. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.ccsdk.features.generator.tool; + +import com.fasterxml.jackson.databind.node.JsonNodeFactory; +import com.fasterxml.jackson.databind.node.TextNode; + +public class CustomJsonNodeFactory extends JsonNodeFactory { + + @Override + public TextNode textNode(String text) { + return new CustomTextNode(text); + } + +} diff --git a/blueprints-processor/plugin/generator-provider/src/main/java/org/onap/ccsdk/features/generator/tool/CustomTextNode.java b/blueprints-processor/plugin/generator-provider/src/main/java/org/onap/ccsdk/features/generator/tool/CustomTextNode.java new file mode 100644 index 000000000..1a62dd6a9 --- /dev/null +++ b/blueprints-processor/plugin/generator-provider/src/main/java/org/onap/ccsdk/features/generator/tool/CustomTextNode.java @@ -0,0 +1,42 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2018 IBM. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.ccsdk.features.generator.tool; + +import com.fasterxml.jackson.core.io.CharTypes; +import com.fasterxml.jackson.databind.node.TextNode; + +public class CustomTextNode extends TextNode { + + public CustomTextNode(String v) { + super(v); + } + + @Override + public String toString() { + int len = textValue().length(); + len = len + 2 + (len >> 4); + StringBuilder sb = new StringBuilder(len); + appendQuoted(sb, textValue()); + return sb.toString(); + } + + protected static void appendQuoted(StringBuilder sb, String content) { + CharTypes.appendQuoted(sb, content); + } + +} diff --git a/blueprints-processor/plugin/generator-provider/src/main/java/org/onap/ccsdk/features/generator/tool/EscapeUtils.java b/blueprints-processor/plugin/generator-provider/src/main/java/org/onap/ccsdk/features/generator/tool/EscapeUtils.java new file mode 100644 index 000000000..d3246e045 --- /dev/null +++ b/blueprints-processor/plugin/generator-provider/src/main/java/org/onap/ccsdk/features/generator/tool/EscapeUtils.java @@ -0,0 +1,82 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2018 IBM. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.ccsdk.features.generator.tool; + +import org.apache.commons.lang3.StringUtils; + +@SuppressWarnings("squid:S1118") +public class EscapeUtils { + + public static String escapeSql(String str) { + if (str == null) { + return null; + } + String[] searchList = new String[] {"'", "\\"}; + String[] replacementList = new String[] {"''", "\\\\"}; + return StringUtils.replaceEach(str, searchList, replacementList); + } + + // For Generic Purpose + public static String escapeSequence(String s) { + if (s == null) { + return null; + } + + int length = s.length(); + int newLength = length; + for (int i = 0; i < length; i++) { + char c = s.charAt(i); + switch (c) { + case '\\': + case '\"': + case '\'': + case '\0': + newLength += 1; + break; + default: + // do nothing + } + } + if (length == newLength) { + // nothing to escape in the string + return s; + } + StringBuilder sb = new StringBuilder(newLength); + for (int i = 0; i < length; i++) { + char c = s.charAt(i); + switch (c) { + case '\\': + sb.append("\\\\"); + break; + case '\"': + sb.append("\\\""); + break; + case '\'': + sb.append("\\\'"); + break; + case '\0': + sb.append("\\0"); + break; + default: + sb.append(c); + } + } + return sb.toString(); + } + +} diff --git a/blueprints-processor/plugin/generator-provider/src/main/resources/org/opendaylight/blueprint/impl-blueprint.xml b/blueprints-processor/plugin/generator-provider/src/main/resources/org/opendaylight/blueprint/impl-blueprint.xml index 7bf65fa4e..78cb28189 100644 --- a/blueprints-processor/plugin/generator-provider/src/main/resources/org/opendaylight/blueprint/impl-blueprint.xml +++ b/blueprints-processor/plugin/generator-provider/src/main/resources/org/opendaylight/blueprint/impl-blueprint.xml @@ -21,29 +21,29 @@ odl:use-default-for-reference-types="true"> + interface="org.onap.ccsdk.features.model.service.ConfigModelService" /> + interface="org.onap.ccsdk.features.data.adaptor.service.ConfigResourceService" /> + class="org.onap.ccsdk.features.generator.service.ConfigGeneratorServiceImpl"> + interface="org.onap.ccsdk.features.generator.service.ConfigGeneratorService" /> + class="org.onap.ccsdk.features.generator.service.ConfigGeneratorNode"> + interface="org.onap.ccsdk.features.generator.service.ConfigGeneratorNode" /> diff --git a/blueprints-processor/plugin/generator-provider/src/test/java/org/onap/ccsdk/config/generator/service/ConfigGeneratorNodeTest.java b/blueprints-processor/plugin/generator-provider/src/test/java/org/onap/ccsdk/config/generator/service/ConfigGeneratorNodeTest.java deleted file mode 100644 index 941387347..000000000 --- a/blueprints-processor/plugin/generator-provider/src/test/java/org/onap/ccsdk/config/generator/service/ConfigGeneratorNodeTest.java +++ /dev/null @@ -1,222 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2018 IBM. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.ccsdk.config.generator.service; - -import static org.mockito.Matchers.any; -import java.nio.charset.Charset; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import org.apache.commons.io.IOUtils; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mock; -import org.mockito.Mockito; -import org.mockito.MockitoAnnotations; -import org.mockito.invocation.InvocationOnMock; -import org.mockito.runners.MockitoJUnitRunner; -import org.mockito.stubbing.Answer; -import org.onap.ccsdk.config.data.adaptor.domain.ConfigResource; -import org.onap.ccsdk.config.data.adaptor.domain.TransactionLog; -import org.onap.ccsdk.config.data.adaptor.service.ConfigResourceService; -import org.onap.ccsdk.config.generator.ConfigGeneratorConstant; -import org.onap.ccsdk.config.model.ConfigModelConstant; -import org.onap.ccsdk.config.model.service.ConfigModelService; -import org.onap.ccsdk.config.model.service.ConfigModelServiceImpl; -import org.onap.ccsdk.config.model.utils.TransformationUtils; -import org.onap.ccsdk.config.rest.adaptor.service.ConfigRestAdaptorService; -import org.onap.ccsdk.sli.core.sli.SvcLogicContext; -import org.onap.ccsdk.sli.core.sli.SvcLogicException; -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; - -@RunWith(MockitoJUnitRunner.class) -public class ConfigGeneratorNodeTest { - - private static EELFLogger logger = EELFManager.getInstance().getLogger(ConfigGeneratorNodeTest.class); - - @Mock - private ConfigResourceService configResourceService; - - @Mock - private ConfigRestAdaptorService configRestAdaptorService; - - private ConfigModelService configModelService; - - @Before - public void setUp() throws Exception { - - configModelService = new ConfigModelServiceImpl(configRestAdaptorService); - - MockitoAnnotations.initMocks(this); - - try { - Mockito.doAnswer(new Answer() { - @Override - public Void answer(InvocationOnMock invocationOnMock) throws Throwable { - Object[] args = invocationOnMock.getArguments(); - if (args != null) { - logger.trace("Transaction info " + Arrays.asList(args)); - } - return null; - } - }).when(configResourceService).save(any(TransactionLog.class)); - - Mockito.doAnswer(new Answer>() { - @Override - public List answer(InvocationOnMock invocationOnMock) throws Throwable { - List configResources = new ArrayList<>(); - Object[] args = invocationOnMock.getArguments(); - if (args != null) { - logger.trace("Transaction info " + Arrays.asList(args)); - String resourceData = IOUtils.toString(ConfigGeneratorNodeTest.class.getClassLoader() - .getResourceAsStream("service_templates/configdata.json"), Charset.defaultCharset()); - ConfigResource configResource = (ConfigResource) args[0]; - configResource.setRecipeName("Sample-recipe"); - configResource.setResourceData(resourceData); - configResources.add(configResource); - } - return configResources; - } - }).when(configResourceService).getConfigResource(any(ConfigResource.class)); - - } catch (SvcLogicException e) { - e.printStackTrace(); - } - } - - @Test - public void testInputTemplateContentNData() throws Exception { - - ConfigGeneratorNode configGeneratorNode = new ConfigGeneratorNode(configResourceService, configModelService); - - Map inParams = new HashMap(); - inParams.put(ConfigModelConstant.PROPERTY_SELECTOR, "test"); - - String jsonData = IOUtils.toString( - ConfigGeneratorNodeTest.class.getClassLoader().getResourceAsStream("service_templates/configdata.json"), - Charset.defaultCharset()); - inParams.put(ConfigGeneratorConstant.INPUT_PARAM_TEMPLATE_DATA, jsonData); - - String templateData = IOUtils.toString(ConfigGeneratorNodeTest.class.getClassLoader() - .getResourceAsStream("service_templates/velocity/base-config-template.vtl"), Charset.defaultCharset()); - inParams.put(ConfigGeneratorConstant.INPUT_PARAM_TEMPLATE_CONTENT, templateData); - - SvcLogicContext ctx = new SvcLogicContext(); - Map componentContext = new HashMap<>(); - configGeneratorNode.process(inParams, ctx, componentContext); - Assert.assertEquals("Failed to generate Configuration Status as Failure", - ConfigGeneratorConstant.OUTPUT_STATUS_SUCCESS, - ctx.getAttribute("test." + ConfigGeneratorConstant.OUTPUT_PARAM_STATUS)); - Assert.assertNotNull("Failed to generate Configuration", - ctx.getAttribute("test." + ConfigGeneratorConstant.OUTPUT_PARAM_GENERATED_CONFIG)); - - logger.trace("Generated Configuration:\n " - + ctx.getAttribute("test." + ConfigGeneratorConstant.OUTPUT_PARAM_GENERATED_CONFIG)); - logger.trace("Generated Configuration:\n " - + ctx.getAttribute("test." + ConfigGeneratorConstant.OUTPUT_PARAM_MASK_INFO)); - - } - - @Test - public void testInputTemplateWithNullData() throws Exception { - - ConfigGeneratorNode configGeneratorNode = new ConfigGeneratorNode(configResourceService, configModelService); - - Map inParams = new HashMap(); - inParams.put(ConfigModelConstant.PROPERTY_SELECTOR, "test"); - - String jsonData = IOUtils.toString(ConfigGeneratorNodeTest.class.getClassLoader() - .getResourceAsStream("service_templates/configdata_with_null.json"), Charset.defaultCharset()); - inParams.put(ConfigGeneratorConstant.INPUT_PARAM_TEMPLATE_DATA, jsonData); - - String templateData = IOUtils.toString(ConfigGeneratorNodeTest.class.getClassLoader() - .getResourceAsStream("service_templates/velocity/base-config-template.vtl"), Charset.defaultCharset()); - inParams.put(ConfigGeneratorConstant.INPUT_PARAM_TEMPLATE_CONTENT, templateData); - - SvcLogicContext ctx = new SvcLogicContext(); - Map componentContext = new HashMap<>(); - configGeneratorNode.process(inParams, ctx, componentContext); - Assert.assertEquals("Failed to generate Configuration Status as Failure", - ConfigGeneratorConstant.OUTPUT_STATUS_SUCCESS, - ctx.getAttribute("test." + ConfigGeneratorConstant.OUTPUT_PARAM_STATUS)); - Assert.assertNotNull("Failed to generate Configuration", - ctx.getAttribute("test." + ConfigGeneratorConstant.OUTPUT_PARAM_GENERATED_CONFIG)); - - logger.trace("Generated Configuration:\n " - + ctx.getAttribute("test." + ConfigGeneratorConstant.OUTPUT_PARAM_GENERATED_CONFIG)); - logger.trace("Generated Configuration:\n " - + ctx.getAttribute("test." + ConfigGeneratorConstant.OUTPUT_PARAM_MASK_INFO)); - - } - - @Test - public void testDBTemplateContentNData() throws Exception { - - String fileContent = IOUtils.toString(ConfigGeneratorNodeTest.class.getClassLoader() - .getResourceAsStream("service_templates/generate_configuration.json"), Charset.defaultCharset()); - - String baseConfigTemplateContent = IOUtils.toString(ConfigGeneratorNodeTest.class.getClassLoader() - .getResourceAsStream("service_templates/velocity/base-config-template.vtl"), Charset.defaultCharset()); - - Map context = new HashMap<>(); - context = configModelService.convertServiceTemplate2Properties(fileContent, context); - - context.put("node_templates.base-config-template.content", baseConfigTemplateContent); - - Assert.assertNotNull("Failed to Prepare Context : ", context); - - context.put("request-id", "12345"); - context.put("vnf-id", "vnf12345"); - context.put("action-name", "config-generator-action"); - - Map inparams = new HashMap(); - inparams.put(ConfigModelConstant.PROPERTY_SELECTOR, "generate-configuration"); - - SvcLogicContext inputContext = new SvcLogicContext(); - context.forEach((name, value) -> { - inputContext.setAttribute(name, value); - }); - - TransformationUtils.printMap(context); - configModelService.assignInParamsFromModel(inputContext, inparams); - ConfigGeneratorNode configGeneratorNode = new ConfigGeneratorNode(configResourceService, configModelService); - - Map componentContext = new HashMap<>(); - configGeneratorNode.process(inparams, inputContext, componentContext); - - Assert.assertEquals("Failed to generate Configuration Status as Failure", - ConfigGeneratorConstant.OUTPUT_STATUS_SUCCESS, - inputContext.getAttribute("generate-configuration." + ConfigGeneratorConstant.OUTPUT_PARAM_STATUS)); - Assert.assertNotNull("Failed to generate Configuration", inputContext - .getAttribute("generate-configuration." + ConfigGeneratorConstant.OUTPUT_PARAM_GENERATED_CONFIG)); - - logger.trace("Generated Configuration:\n " + inputContext - .getAttribute("generate-configuration." + ConfigGeneratorConstant.OUTPUT_PARAM_GENERATED_CONFIG)); - } - - @Test - public void testTemplateContentNDataForMask() throws Exception { - - } - -} diff --git a/blueprints-processor/plugin/generator-provider/src/test/java/org/onap/ccsdk/config/generator/tool/EscapeUtilsTest.java b/blueprints-processor/plugin/generator-provider/src/test/java/org/onap/ccsdk/config/generator/tool/EscapeUtilsTest.java deleted file mode 100644 index 0bd2384bf..000000000 --- a/blueprints-processor/plugin/generator-provider/src/test/java/org/onap/ccsdk/config/generator/tool/EscapeUtilsTest.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2018 IBM. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.ccsdk.config.generator.tool; - -import org.junit.Assert; -import org.junit.Test; - -public class EscapeUtilsTest { - - @Test - public void testEscapeSql() { - Assert.assertEquals("", EscapeUtils.escapeSql("")); - Assert.assertEquals("text", EscapeUtils.escapeSql("text")); - - Assert.assertEquals("''", EscapeUtils.escapeSql("'")); - Assert.assertEquals("\\\\", EscapeUtils.escapeSql("\\")); - - Assert.assertEquals("text''text", EscapeUtils.escapeSql("text'text")); - Assert.assertEquals("text\\\\text", EscapeUtils.escapeSql("text\\text")); - } - - @Test - public void testEscapeSequence() { - Assert.assertEquals("", EscapeUtils.escapeSequence("")); - Assert.assertEquals("text", EscapeUtils.escapeSequence("text")); - - Assert.assertEquals("\\\'", EscapeUtils.escapeSequence("'")); - Assert.assertEquals("\\\"", EscapeUtils.escapeSequence("\"")); - Assert.assertEquals("\\\\", EscapeUtils.escapeSequence("\\")); - - Assert.assertEquals("text\\\'text", EscapeUtils.escapeSequence("text'text")); - Assert.assertEquals("text\\\"text", EscapeUtils.escapeSequence("text\"text")); - Assert.assertEquals("text\\\\text", EscapeUtils.escapeSequence("text\\text")); - } - -} diff --git a/blueprints-processor/plugin/generator-provider/src/test/java/org/onap/ccsdk/features/generator/service/ConfigGeneratorNodeTest.java b/blueprints-processor/plugin/generator-provider/src/test/java/org/onap/ccsdk/features/generator/service/ConfigGeneratorNodeTest.java new file mode 100644 index 000000000..58a22ac14 --- /dev/null +++ b/blueprints-processor/plugin/generator-provider/src/test/java/org/onap/ccsdk/features/generator/service/ConfigGeneratorNodeTest.java @@ -0,0 +1,223 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2018 IBM. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.ccsdk.features.generator.service; + +import static org.mockito.Matchers.any; +import java.nio.charset.Charset; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import org.apache.commons.io.IOUtils; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.MockitoAnnotations; +import org.mockito.invocation.InvocationOnMock; +import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.stubbing.Answer; +import org.onap.ccsdk.features.data.adaptor.domain.ConfigResource; +import org.onap.ccsdk.features.data.adaptor.domain.TransactionLog; +import org.onap.ccsdk.features.data.adaptor.service.ConfigResourceService; +import org.onap.ccsdk.features.generator.ConfigGeneratorConstant; +import org.onap.ccsdk.features.generator.service.ConfigGeneratorNode; +import org.onap.ccsdk.features.model.ConfigModelConstant; +import org.onap.ccsdk.features.model.service.ConfigModelService; +import org.onap.ccsdk.features.model.service.ConfigModelServiceImpl; +import org.onap.ccsdk.features.model.utils.TransformationUtils; +import org.onap.ccsdk.features.rest.adaptor.service.ConfigRestAdaptorService; +import org.onap.ccsdk.sli.core.sli.SvcLogicContext; +import org.onap.ccsdk.sli.core.sli.SvcLogicException; +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; + +@RunWith(MockitoJUnitRunner.class) +public class ConfigGeneratorNodeTest { + + private static EELFLogger logger = EELFManager.getInstance().getLogger(ConfigGeneratorNodeTest.class); + + @Mock + private ConfigResourceService configResourceService; + + @Mock + private ConfigRestAdaptorService configRestAdaptorService; + + private ConfigModelService configModelService; + + @Before + public void setUp() throws Exception { + + configModelService = new ConfigModelServiceImpl(configRestAdaptorService); + + MockitoAnnotations.initMocks(this); + + try { + Mockito.doAnswer(new Answer() { + @Override + public Void answer(InvocationOnMock invocationOnMock) throws Throwable { + Object[] args = invocationOnMock.getArguments(); + if (args != null) { + logger.trace("Transaction info " + Arrays.asList(args)); + } + return null; + } + }).when(configResourceService).save(any(TransactionLog.class)); + + Mockito.doAnswer(new Answer>() { + @Override + public List answer(InvocationOnMock invocationOnMock) throws Throwable { + List configResources = new ArrayList<>(); + Object[] args = invocationOnMock.getArguments(); + if (args != null) { + logger.trace("Transaction info " + Arrays.asList(args)); + String resourceData = IOUtils.toString(ConfigGeneratorNodeTest.class.getClassLoader() + .getResourceAsStream("service_templates/configdata.json"), Charset.defaultCharset()); + ConfigResource configResource = (ConfigResource) args[0]; + configResource.setRecipeName("Sample-recipe"); + configResource.setResourceData(resourceData); + configResources.add(configResource); + } + return configResources; + } + }).when(configResourceService).getConfigResource(any(ConfigResource.class)); + + } catch (SvcLogicException e) { + e.printStackTrace(); + } + } + + @Test + public void testInputTemplateContentNData() throws Exception { + + ConfigGeneratorNode configGeneratorNode = new ConfigGeneratorNode(configResourceService, configModelService); + + Map inParams = new HashMap(); + inParams.put(ConfigModelConstant.PROPERTY_SELECTOR, "test"); + + String jsonData = IOUtils.toString( + ConfigGeneratorNodeTest.class.getClassLoader().getResourceAsStream("service_templates/configdata.json"), + Charset.defaultCharset()); + inParams.put(ConfigGeneratorConstant.INPUT_PARAM_TEMPLATE_DATA, jsonData); + + String templateData = IOUtils.toString(ConfigGeneratorNodeTest.class.getClassLoader() + .getResourceAsStream("service_templates/velocity/base-config-template.vtl"), Charset.defaultCharset()); + inParams.put(ConfigGeneratorConstant.INPUT_PARAM_TEMPLATE_CONTENT, templateData); + + SvcLogicContext ctx = new SvcLogicContext(); + Map componentContext = new HashMap<>(); + configGeneratorNode.process(inParams, ctx, componentContext); + Assert.assertEquals("Failed to generate Configuration Status as Failure", + ConfigGeneratorConstant.OUTPUT_STATUS_SUCCESS, + ctx.getAttribute("test." + ConfigGeneratorConstant.OUTPUT_PARAM_STATUS)); + Assert.assertNotNull("Failed to generate Configuration", + ctx.getAttribute("test." + ConfigGeneratorConstant.OUTPUT_PARAM_GENERATED_CONFIG)); + + logger.trace("Generated Configuration:\n " + + ctx.getAttribute("test." + ConfigGeneratorConstant.OUTPUT_PARAM_GENERATED_CONFIG)); + logger.trace("Generated Configuration:\n " + + ctx.getAttribute("test." + ConfigGeneratorConstant.OUTPUT_PARAM_MASK_INFO)); + + } + + @Test + public void testInputTemplateWithNullData() throws Exception { + + ConfigGeneratorNode configGeneratorNode = new ConfigGeneratorNode(configResourceService, configModelService); + + Map inParams = new HashMap(); + inParams.put(ConfigModelConstant.PROPERTY_SELECTOR, "test"); + + String jsonData = IOUtils.toString(ConfigGeneratorNodeTest.class.getClassLoader() + .getResourceAsStream("service_templates/configdata_with_null.json"), Charset.defaultCharset()); + inParams.put(ConfigGeneratorConstant.INPUT_PARAM_TEMPLATE_DATA, jsonData); + + String templateData = IOUtils.toString(ConfigGeneratorNodeTest.class.getClassLoader() + .getResourceAsStream("service_templates/velocity/base-config-template.vtl"), Charset.defaultCharset()); + inParams.put(ConfigGeneratorConstant.INPUT_PARAM_TEMPLATE_CONTENT, templateData); + + SvcLogicContext ctx = new SvcLogicContext(); + Map componentContext = new HashMap<>(); + configGeneratorNode.process(inParams, ctx, componentContext); + Assert.assertEquals("Failed to generate Configuration Status as Failure", + ConfigGeneratorConstant.OUTPUT_STATUS_SUCCESS, + ctx.getAttribute("test." + ConfigGeneratorConstant.OUTPUT_PARAM_STATUS)); + Assert.assertNotNull("Failed to generate Configuration", + ctx.getAttribute("test." + ConfigGeneratorConstant.OUTPUT_PARAM_GENERATED_CONFIG)); + + logger.trace("Generated Configuration:\n " + + ctx.getAttribute("test." + ConfigGeneratorConstant.OUTPUT_PARAM_GENERATED_CONFIG)); + logger.trace("Generated Configuration:\n " + + ctx.getAttribute("test." + ConfigGeneratorConstant.OUTPUT_PARAM_MASK_INFO)); + + } + + @Test + public void testDBTemplateContentNData() throws Exception { + + String fileContent = IOUtils.toString(ConfigGeneratorNodeTest.class.getClassLoader() + .getResourceAsStream("service_templates/generate_configuration.json"), Charset.defaultCharset()); + + String baseConfigTemplateContent = IOUtils.toString(ConfigGeneratorNodeTest.class.getClassLoader() + .getResourceAsStream("service_templates/velocity/base-config-template.vtl"), Charset.defaultCharset()); + + Map context = new HashMap<>(); + context = configModelService.convertServiceTemplate2Properties(fileContent, context); + + context.put("node_templates.base-config-template.content", baseConfigTemplateContent); + + Assert.assertNotNull("Failed to Prepare Context : ", context); + + context.put("request-id", "12345"); + context.put("vnf-id", "vnf12345"); + context.put("action-name", "config-generator-action"); + + Map inparams = new HashMap(); + inparams.put(ConfigModelConstant.PROPERTY_SELECTOR, "generate-configuration"); + + SvcLogicContext inputContext = new SvcLogicContext(); + context.forEach((name, value) -> { + inputContext.setAttribute(name, value); + }); + + TransformationUtils.printMap(context); + configModelService.assignInParamsFromModel(inputContext, inparams); + ConfigGeneratorNode configGeneratorNode = new ConfigGeneratorNode(configResourceService, configModelService); + + Map componentContext = new HashMap<>(); + configGeneratorNode.process(inparams, inputContext, componentContext); + + Assert.assertEquals("Failed to generate Configuration Status as Failure", + ConfigGeneratorConstant.OUTPUT_STATUS_SUCCESS, + inputContext.getAttribute("generate-configuration." + ConfigGeneratorConstant.OUTPUT_PARAM_STATUS)); + Assert.assertNotNull("Failed to generate Configuration", inputContext + .getAttribute("generate-configuration." + ConfigGeneratorConstant.OUTPUT_PARAM_GENERATED_CONFIG)); + + logger.trace("Generated Configuration:\n " + inputContext + .getAttribute("generate-configuration." + ConfigGeneratorConstant.OUTPUT_PARAM_GENERATED_CONFIG)); + } + + @Test + public void testTemplateContentNDataForMask() throws Exception { + + } + +} diff --git a/blueprints-processor/plugin/generator-provider/src/test/java/org/onap/ccsdk/features/generator/tool/EscapeUtilsTest.java b/blueprints-processor/plugin/generator-provider/src/test/java/org/onap/ccsdk/features/generator/tool/EscapeUtilsTest.java new file mode 100644 index 000000000..58918685d --- /dev/null +++ b/blueprints-processor/plugin/generator-provider/src/test/java/org/onap/ccsdk/features/generator/tool/EscapeUtilsTest.java @@ -0,0 +1,52 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2018 IBM. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.ccsdk.features.generator.tool; + +import org.junit.Assert; +import org.junit.Test; +import org.onap.ccsdk.features.generator.tool.EscapeUtils; + +public class EscapeUtilsTest { + + @Test + public void testEscapeSql() { + Assert.assertEquals("", EscapeUtils.escapeSql("")); + Assert.assertEquals("text", EscapeUtils.escapeSql("text")); + + Assert.assertEquals("''", EscapeUtils.escapeSql("'")); + Assert.assertEquals("\\\\", EscapeUtils.escapeSql("\\")); + + Assert.assertEquals("text''text", EscapeUtils.escapeSql("text'text")); + Assert.assertEquals("text\\\\text", EscapeUtils.escapeSql("text\\text")); + } + + @Test + public void testEscapeSequence() { + Assert.assertEquals("", EscapeUtils.escapeSequence("")); + Assert.assertEquals("text", EscapeUtils.escapeSequence("text")); + + Assert.assertEquals("\\\'", EscapeUtils.escapeSequence("'")); + Assert.assertEquals("\\\"", EscapeUtils.escapeSequence("\"")); + Assert.assertEquals("\\\\", EscapeUtils.escapeSequence("\\")); + + Assert.assertEquals("text\\\'text", EscapeUtils.escapeSequence("text'text")); + Assert.assertEquals("text\\\"text", EscapeUtils.escapeSequence("text\"text")); + Assert.assertEquals("text\\\\text", EscapeUtils.escapeSequence("text\\text")); + } + +} diff --git a/blueprints-processor/plugin/generator-provider/src/test/resources/service_templates/generate_configuration.json b/blueprints-processor/plugin/generator-provider/src/test/resources/service_templates/generate_configuration.json index 0d569ef85..326d2e8ec 100644 --- a/blueprints-processor/plugin/generator-provider/src/test/resources/service_templates/generate_configuration.json +++ b/blueprints-processor/plugin/generator-provider/src/test/resources/service_templates/generate_configuration.json @@ -67,7 +67,7 @@ "generate-configuration": { "type": "component-config-generator", "interfaces": { - "org-onap-ccsdk-config-generator-service-ConfigGeneratorNode": { + "org-onap-ccsdk-features-generator-service-ConfigGeneratorNode": { "operations": { "process": { "inputs": { @@ -164,7 +164,7 @@ } }, "interfaces": { - "org-onap-ccsdk-config-generator-service-ConfigGeneratorNode": { + "org-onap-ccsdk-features-generator-service-ConfigGeneratorNode": { "operations": { "process": { "inputs": { @@ -211,7 +211,7 @@ "type": "string" }, "mask-info": { - "description": "If template contains mask encription keys, then this mask-info field will be generated, This JSON Content alligns to the bean org.onap.ccsdk.config.model.data.custom.MaskInfo ", + "description": "If template contains mask encription keys, then this mask-info field will be generated, This JSON Content alligns to the bean org.onap.ccsdk.features.model.data.custom.MaskInfo ", "required": false, "type": "string" }, diff --git a/blueprints-processor/plugin/model-provider/pom.xml b/blueprints-processor/plugin/model-provider/pom.xml index e548c2e2e..1092b486f 100644 --- a/blueprints-processor/plugin/model-provider/pom.xml +++ b/blueprints-processor/plugin/model-provider/pom.xml @@ -120,14 +120,14 @@ ${project.artifactId} ${project.groupId}.${project.artifactId} - org.onap.ccsdk.config.model, - org.onap.ccsdk.config.model.data, - org.onap.ccsdk.config.model.data.api, - org.onap.ccsdk.config.model.data.dict, - org.onap.ccsdk.config.model.domain, - org.onap.ccsdk.config.model.service, - org.onap.ccsdk.config.model.utils, - org.onap.ccsdk.config.model.validator + org.onap.ccsdk.features.model, + org.onap.ccsdk.features.model.data, + org.onap.ccsdk.features.model.data.api, + org.onap.ccsdk.features.model.data.dict, + org.onap.ccsdk.features.model.domain, + org.onap.ccsdk.features.model.service, + org.onap.ccsdk.features.model.utils, + org.onap.ccsdk.features.model.validator diff --git a/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/ConfigModelConstant.java b/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/ConfigModelConstant.java deleted file mode 100644 index a9a3b2546..000000000 --- a/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/ConfigModelConstant.java +++ /dev/null @@ -1,147 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2018 IBM. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.ccsdk.config.model; - -public class ConfigModelConstant { - - private ConfigModelConstant() { - - } - - public static final String STATUS_CODE_SUCCESS = "200"; - public static final String STATUS_CODE_FAILURE = "400"; - - public static final String STATUS_SUCCESS = "success"; - public static final String STATUS_FAILURE = "failure"; - public static final String STATUS_SKIPPED = "skipped"; - - public static final String CONFIG_STATUS_PENDING = "pending"; - public static final String CONFIG_STATUS_FAILED = "failed"; - public static final String CONFIG_STATUS_SUCCESS = "success"; - - public static final String USER_SYSTEM = "System"; - public static final String PROTOCOL_NETCONF = "netconf"; - - public static final String MODEL_CONTENT_TYPE_TOSCA_JSON = "TOSCA_JSON"; - public static final String MODEL_CONTENT_TYPE_TOSCA_YAML = "TOSCA_YAML"; - public static final String MODEL_CONTENT_TYPE_TEMPLATE = "TEMPLATE"; - public static final String MODEL_CONTENT_TYPE_YANG = "YANG"; - public static final String MODEL_CONTENT_TYPE_SCHEMA = "SCHEMA"; - - public static final String SERVICE_TEMPLATE_KEY_ARTIFACT_AUTHOR = "author"; - public static final String SERVICE_TEMPLATE_KEY_ARTIFACT_NAME = "service-template-name"; - public static final String SERVICE_TEMPLATE_KEY_ARTIFACT_VERSION = "service-template-version"; - - public static final String MODEL_DEFINITION_TYPE_NODE_TYPE = "node_type"; - public static final String MODEL_DEFINITION_TYPE_CAPABILITY_TYPE = "capability_type"; - public static final String MODEL_DEFINITION_TYPE_RELATIONSHIP_TYPE = "relationship_type"; - public static final String MODEL_DEFINITION_TYPE_DATA_TYPE = "data_type"; - public static final String MODEL_DEFINITION_TYPE_ARTIFACT_TYPE = "artifact_type"; - - public static final String MODEL_TYPE_DATA_TYPE = "tosca.datatypes.Root"; - public static final String MODEL_TYPE_DATA_TYPE_DYNAMIC = "tosca.datatypes.Dynamic"; - public static final String MODEL_TYPE_NODE_TYPE = "tosca.nodes.Root"; - - public static final String MODEL_TYPE_NODE_DG = "tosca.nodes.DG"; - public static final String MODEL_TYPE_NODE_COMPONENT = "tosca.nodes.Component"; - public static final String MODEL_TYPE_NODE_COMPONENT_PYTHON = "tosca.nodes.Component.Python"; - public static final String MODEL_TYPE_NODE_VNF = "tosca.nodes.Vnf"; - public static final String MODEL_TYPE_NODE_ARTIFACT = "tosca.nodes.Artifact"; - - public static final String MODEL_TYPE_ARTIFACT_TEMPLATE = "tosca.artifact.Template"; - public static final String MODEL_TYPE_ARTIFACT_LICENCE = "tosca.artifacts.Licence"; - - public static final String MODEL_TYPE_RELATIONSHIPS_DEPENDS_ON = "tosca.relationships.DependsOn"; - public static final String MODEL_TYPE_RELATIONSHIPS_HOSTED_ON = "tosca.relationships.HostedOn"; - public static final String MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO = "tosca.relationships.ConnectsTo"; - public static final String MODEL_TYPE_RELATIONSHIPS_ATTACH_TO = "tosca.relationships.AttachesTo"; - public static final String MODEL_TYPE_RELATIONSHIPS_ROUTES_TO = "tosca.relationships.RoutesTo"; - - public static final String NODE_TEMPLATE_TYPE_ARTIFACT_CONFIG_TEMPLATE = "artifact-config-template"; - - public static final String CAPABILITY_PROPERTY_MAPPING = "mapping"; - public static final String CAPABILITY_PROPERTY_CONTENT = "content"; - - public static final String SOURCE_INPUT = "input"; - public static final String SOURCE_DEFAULT = "default"; - public static final String SOURCE_MDSAL = "mdsal"; - public static final String SOURCE_DB = "db"; - public static final String SOURCE_COMPONENT = "component"; - - public static final String PROPERTY_STATUS = "status"; - public static final String PROPERTY_ERROR_CODE = "error-code"; - public static final String PROPERTY_ERROR_MESSAGE = "error-message"; - - public static final String PROPERTY_REQUEST_INPUT = "request-input"; - public static final String PROPERTY_REQUEST_HEADER = "request-header"; - public static final String PROPERTY_REQUEST_PAYLOAD = "request-payload"; - - public static final String PROPERTY_RESPONSE_PAYLOAD = "response-payload"; - public static final String PROPERTY_RESPONSE_JSON_NODE = "response-json-node"; - - public static final String PROPERTY_PAYLOAD = "payload"; - public static final String PROPERTY_INPUTS = "inputs"; - public static final String PROPERTY_ORGINATOR_ID = "originator-id"; - public static final String PROPERTY_API_VERSION = "api-ver"; - public static final String PROPERTY_REQUEST_ID = "request-id"; - public static final String PROPERTY_SUB_REQUEST_ID = "sub-request-id"; - public static final String PROPERTY_REQUEST = "request"; - public static final String PROPERTY_RECIPE = "action"; - - public static final String PROPERTY_SELECTOR = "prifix"; - public static final String PROPERTY_NODE_TEMPLATES = "node_templates"; - public static final String PROPERTY_NODE_TYPES = "node_types"; - public static final String PROPERTY_DATA_TYPES = "data_types"; - public static final String PROPERTY_ACTION_NAME = "action-name"; - public static final String PROPERTY_ACTION_PREFIX = "action-prefix"; - public static final String PROPERTY_TEMPLATE_NAME = "template-name"; - - public static final String PROPERTY_CURRENT_INTERFACE = "current-interface"; - public static final String PROPERTY_CURRENT_OPERATION = "current-operation"; - public static final String PROPERTY_CURRENT_IMPLEMENTATION = "current-implementation"; - public static final String PROPERTY_CURRENT_NODETYPE_DERIVED_FROM = "current-node-type-derived-from"; - public static final String PROPERTY_CURRENT_RESOURCE_ASSIGNMENT = "current-resource-assignment"; - public static final String PROPERTY_CURRENT_DICTIONARY_DEFINITION = "current-dictionary-definition"; - public static final String PROPERTY_RESOURCE_ASSIGNMENTS_DATA = "resource-assignments-data"; - - public static final String PROPERTY_RECIPE_NAMES = "action-names"; - public static final String PROPERTY_DICTIONARIES = "dictionaries"; - public static final String PROPERTY_RESOURCE_ASSIGNMENTS = "resource-assignments"; - public static final String PROPERTY_RESOURCE_KEY = "resource-key"; - public static final String PROPERTY_RESOURCE_NAME = "resource-name"; - public static final String PROPERTY_RESERVATION_ID = "reservation-id"; - - public static final String PROPERTY_NODE_TEMPLATES_DOT = "node_templates."; - public static final String PROPERTY_NODE_TYPES_DOT = "node_types."; - public static final String PROPERTY_DATA_TYPES_DOT = "data_types."; - public static final String PROPERTY_INPUTS_DOT = "inputs."; - public static final String PROPERTY_ARTIFACTS_DOT = "artifacts."; - public static final String PROPERTY_DICTIONARY_KEY_DOT = "dictionary-key."; - public static final String PROPERTY_TEMPLATE_KEY_DOT = "template-key."; - public static final String PROPERTY_RECIPE_KEY_DOT = "recipe-key."; - - public static final String PROPERTY_DOT_STATUS = ".status"; - public static final String PROPERTY_DOT_ERROR_MESSAGE = ".error-message"; - - public static final String EXPRESSION_GET_INPUT = "get_input"; - public static final String EXPRESSION_GET_ATTRIBUTE = "get_attribute"; - public static final String EXPRESSION_SET_VALUE = "set_value"; - - public static final String CONFIG_PROPERTY_MAP_KEY_PREFIX = "org.onap.ccsdk.sli.adaptors."; - -} diff --git a/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/ConfigModelException.java b/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/ConfigModelException.java deleted file mode 100644 index 4936c3b23..000000000 --- a/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/ConfigModelException.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2018 IBM. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.ccsdk.config.model; - -/** - * ConfigGeneratorException.java Purpose: Provide Configuration Generator ConfigGeneratorException - * - * @version 1.0 - */ -public class ConfigModelException extends Exception { - - /** - * - */ - private static final long serialVersionUID = 1L; - - /** - * This is a ConfigGeneratorException constructor - * - * @param message - */ - public ConfigModelException(String message) { - super(message); - } - - /** - * This is a ConfigGeneratorException constructor - * - * @param message - */ - public ConfigModelException(String message, Throwable cause) { - super(message, cause); - } - -} diff --git a/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/ValidTypes.java b/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/ValidTypes.java deleted file mode 100644 index 6cadcc8a0..000000000 --- a/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/ValidTypes.java +++ /dev/null @@ -1,105 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2018 IBM. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.ccsdk.config.model; - -import java.util.ArrayList; -import java.util.List; - -/** - * ValidTypes.java Purpose: Provide Configuration Generator ValidTypes - * - * @version 1.0 - */ -public class ValidTypes { - - public static final String DATA_TYPE_STRING = "string"; - public static final String DATA_TYPE_INTEGER = "integer"; - public static final String DATA_TYPE_FLOAT = "float"; - public static final String DATA_TYPE_BOOLEAN = "boolean"; - public static final String DATA_TYPE_TIMESTAMP = "timestamp"; - public static final String DATA_TYPE_NULL = "null"; - public static final String DATA_TYPE_LIST = "list"; - public static final String DATA_TYPE_LONGTEXT = "longtext"; - - private ValidTypes() { - - } - - public static List getValidModelTypes() { - List validTypes = new ArrayList<>(); - validTypes.add(ConfigModelConstant.MODEL_DEFINITION_TYPE_DATA_TYPE); - validTypes.add(ConfigModelConstant.MODEL_DEFINITION_TYPE_NODE_TYPE); - validTypes.add(ConfigModelConstant.MODEL_DEFINITION_TYPE_CAPABILITY_TYPE); - validTypes.add(ConfigModelConstant.MODEL_DEFINITION_TYPE_RELATIONSHIP_TYPE); - return validTypes; - } - - public static List getValidNodeTypes() { - List validTypes = new ArrayList<>(); - validTypes.add(ConfigModelConstant.MODEL_TYPE_NODE_DG); - validTypes.add(ConfigModelConstant.MODEL_TYPE_NODE_COMPONENT); - validTypes.add(ConfigModelConstant.MODEL_TYPE_NODE_VNF); - validTypes.add(ConfigModelConstant.MODEL_TYPE_NODE_ARTIFACT); - return validTypes; - } - - public static List getValidDerivedFrom() { - List validTypes = new ArrayList<>(); - validTypes.add(ConfigModelConstant.MODEL_TYPE_DATA_TYPE_DYNAMIC); - validTypes.add(ConfigModelConstant.MODEL_TYPE_DATA_TYPE); - validTypes.add(ConfigModelConstant.MODEL_TYPE_NODE_TYPE); - return validTypes; - } - - public static List getValidDataTypeDerivedFrom() { - List validTypes = new ArrayList<>(); - validTypes.add(ConfigModelConstant.MODEL_TYPE_DATA_TYPE_DYNAMIC); - validTypes.add(ConfigModelConstant.MODEL_TYPE_DATA_TYPE); - return validTypes; - } - - public static List getValidPropertType() { - List validTypes = new ArrayList<>(); - validTypes.add(DATA_TYPE_STRING); - validTypes.add(DATA_TYPE_INTEGER); - validTypes.add(DATA_TYPE_FLOAT); - validTypes.add(DATA_TYPE_BOOLEAN); - validTypes.add(DATA_TYPE_TIMESTAMP); - validTypes.add(DATA_TYPE_NULL); - validTypes.add(DATA_TYPE_LIST); - return validTypes; - } - - public static List getPrimitivePropertType() { - List validTypes = new ArrayList<>(); - validTypes.add(DATA_TYPE_STRING); - validTypes.add(DATA_TYPE_INTEGER); - validTypes.add(DATA_TYPE_FLOAT); - validTypes.add(DATA_TYPE_BOOLEAN); - validTypes.add(DATA_TYPE_TIMESTAMP); - validTypes.add(DATA_TYPE_NULL); - return validTypes; - } - - public static List getListPropertType() { - List validTypes = new ArrayList<>(); - validTypes.add(DATA_TYPE_LIST); - return validTypes; - } - -} diff --git a/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/data/ArtifactDefinition.java b/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/data/ArtifactDefinition.java deleted file mode 100644 index 7fcd79066..000000000 --- a/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/data/ArtifactDefinition.java +++ /dev/null @@ -1,105 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2018 IBM. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.ccsdk.config.model.data; - -import com.fasterxml.jackson.annotation.JsonIgnore; -import com.fasterxml.jackson.annotation.JsonProperty; - -/** - * ArtifactDefinition.java Purpose: Provide ArtifactDefinition TOSCO Model POJO bean. - * - * @version 1.0 - */ -public class ArtifactDefinition { - @JsonIgnore - private String id; - private String type; - private String file; - private String repository; - private String description; - @JsonProperty("deploy_Path") - private String deployPath; - // Used for Template Type - private String content; - private String mappingContent; - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - public String getType() { - return type; - } - - public void setType(String type) { - this.type = type; - } - - public String getFile() { - return file; - } - - public void setFile(String file) { - this.file = file; - } - - public String getRepository() { - return repository; - } - - public void setRepository(String repository) { - this.repository = repository; - } - - public String getDescription() { - return description; - } - - public void setDescription(String description) { - this.description = description; - } - - public String getDeployPath() { - return deployPath; - } - - public void setDeployPath(String deployPath) { - this.deployPath = deployPath; - } - - public String getContent() { - return content; - } - - public void setContent(String content) { - this.content = content; - } - - public String getMappingContent() { - return mappingContent; - } - - public void setMappingContent(String mappingContent) { - this.mappingContent = mappingContent; - } - -} diff --git a/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/data/ArtifactType.java b/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/data/ArtifactType.java deleted file mode 100644 index b651b54fd..000000000 --- a/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/data/ArtifactType.java +++ /dev/null @@ -1,102 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2018 IBM. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.ccsdk.config.model.data; - -import java.util.List; -import java.util.Map; -import com.fasterxml.jackson.annotation.JsonIgnore; -import com.fasterxml.jackson.annotation.JsonProperty; - -public class ArtifactType { - @JsonIgnore - private String id; - private String description; - private String version; - private Map metadata; - @JsonProperty("derived_from") - private String derivedFrom; - private Map properties; - @JsonProperty("mime_type") - private String mimeType; - @JsonProperty("file_ext") - private List fileExt; - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - public String getDescription() { - return description; - } - - public void setDescription(String description) { - this.description = description; - } - - public String getVersion() { - return version; - } - - public void setVersion(String version) { - this.version = version; - } - - public Map getMetadata() { - return metadata; - } - - public void setMetadata(Map metadata) { - this.metadata = metadata; - } - - public String getDerivedFrom() { - return derivedFrom; - } - - public void setDerivedFrom(String derivedFrom) { - this.derivedFrom = derivedFrom; - } - - public Map getProperties() { - return properties; - } - - public void setProperties(Map properties) { - this.properties = properties; - } - - public String getMimeType() { - return mimeType; - } - - public void setMimeType(String mimeType) { - this.mimeType = mimeType; - } - - public List getFileExt() { - return fileExt; - } - - public void setFileExt(List fileExt) { - this.fileExt = fileExt; - } -} diff --git a/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/data/CapabilityAssignment.java b/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/data/CapabilityAssignment.java deleted file mode 100644 index 45c79fb4d..000000000 --- a/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/data/CapabilityAssignment.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2018 IBM. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.ccsdk.config.model.data; - -import java.util.Map; -import com.fasterxml.jackson.annotation.JsonIgnore; - -/** - * CapabilityAssignment.java Purpose: Provide CapabilityAssignment TOSCO Model POJO bean. - * - * @version 1.0 - */ -public class CapabilityAssignment { - @JsonIgnore - private String id; - private Map properties; - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - public Map getProperties() { - return properties; - } - - public void setProperties(Map properties) { - this.properties = properties; - } - -} diff --git a/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/data/CapabilityDefinition.java b/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/data/CapabilityDefinition.java deleted file mode 100644 index b64fa5eaa..000000000 --- a/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/data/CapabilityDefinition.java +++ /dev/null @@ -1,88 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2018 IBM. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.ccsdk.config.model.data; - -import java.util.List; -import java.util.Map; -import com.fasterxml.jackson.annotation.JsonIgnore; -import com.fasterxml.jackson.annotation.JsonProperty; - -/** - * CapabilityDefinition.java Purpose: Provide CapabilityDefinition TOSCO Model POJO bean. - * - * @version 1.0 - */ -public class CapabilityDefinition { - @JsonIgnore - private String id; - private String type; - private String description; - private Map properties; - @JsonProperty("valid_source_types") - private List validSourceTypes; - private List occurrences; - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - public String getType() { - return type; - } - - public void setType(String type) { - this.type = type; - } - - public String getDescription() { - return description; - } - - public void setDescription(String description) { - this.description = description; - } - - public Map getProperties() { - return properties; - } - - public void setProperties(Map properties) { - this.properties = properties; - } - - public List getValidSourceTypes() { - return validSourceTypes; - } - - public void setValidSourceTypes(List validSourceTypes) { - this.validSourceTypes = validSourceTypes; - } - - public List getOccurrences() { - return occurrences; - } - - public void setOccurrences(List occurrences) { - this.occurrences = occurrences; - } - -} diff --git a/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/data/ConstraintClause.java b/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/data/ConstraintClause.java deleted file mode 100644 index 12842b537..000000000 --- a/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/data/ConstraintClause.java +++ /dev/null @@ -1,150 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2018 IBM. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.ccsdk.config.model.data; - -import java.util.List; -import com.fasterxml.jackson.annotation.JsonProperty; - -/** - * ConstraintClause.java Purpose: 3.5.2 Constraint clause. - * - * @version 1.0 - */ -public class ConstraintClause { - @JsonProperty("equal") - private Object equal; - - @JsonProperty("greater_than") - private Object greaterThan; - - @JsonProperty("greater_or_equal") - private Object greaterOrEqual; - - @JsonProperty("less_than") - private Object lessThan; - - @JsonProperty("less_or_equal") - private Object lessOrEqual; - - @JsonProperty("in_range") - private Object inRange; - - @JsonProperty("valid_values") - private List validValues; - - @JsonProperty("length") - private Object length; - - @JsonProperty("min_length") - private Object minLength; - - @JsonProperty("max_length") - private Object maxLength; - - @JsonProperty("pattern") - private String pattern; - - public Object getEqual() { - return equal; - } - - public void setEqual(Object equal) { - this.equal = equal; - } - - public Object getGreaterThan() { - return greaterThan; - } - - public void setGreaterThan(Object greaterThan) { - this.greaterThan = greaterThan; - } - - public Object getGreaterOrEqual() { - return greaterOrEqual; - } - - public void setGreaterOrEqual(Object greaterOrEqual) { - this.greaterOrEqual = greaterOrEqual; - } - - public Object getLessThan() { - return lessThan; - } - - public void setLessThan(Object lessThan) { - this.lessThan = lessThan; - } - - public Object getLessOrEqual() { - return lessOrEqual; - } - - public void setLessOrEqual(Object lessOrEqual) { - this.lessOrEqual = lessOrEqual; - } - - public Object getInRange() { - return inRange; - } - - public void setInRange(Object inRange) { - this.inRange = inRange; - } - - public List getValidValues() { - return validValues; - } - - public void setValidValues(List validValues) { - this.validValues = validValues; - } - - public Object getLength() { - return length; - } - - public void setLength(Object length) { - this.length = length; - } - - public Object getMinLength() { - return minLength; - } - - public void setMinLength(Object minLength) { - this.minLength = minLength; - } - - public Object getMaxLength() { - return maxLength; - } - - public void setMaxLength(Object maxLength) { - this.maxLength = maxLength; - } - - public String getPattern() { - return pattern; - } - - public void setPattern(String pattern) { - this.pattern = pattern; - } - -} diff --git a/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/data/DataType.java b/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/data/DataType.java deleted file mode 100644 index 2a3bfa84f..000000000 --- a/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/data/DataType.java +++ /dev/null @@ -1,88 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2018 IBM. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.ccsdk.config.model.data; - -import java.util.List; -import java.util.Map; -import com.fasterxml.jackson.annotation.JsonIgnore; -import com.fasterxml.jackson.annotation.JsonProperty; - -/** - * DataType.java Purpose: Provide DataType TOSCO Model POJO bean. - * - * @version 1.0 - */ -public class DataType { - @JsonIgnore - private String id; - private String version; - private String description; - @JsonProperty("derived_from") - private String derivedFrom; - private List> constraints; - private Map properties; - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - public String getVersion() { - return version; - } - - public void setVersion(String version) { - this.version = version; - } - - public String getDescription() { - return description; - } - - public void setDescription(String description) { - this.description = description; - } - - public String getDerivedFrom() { - return derivedFrom; - } - - public void setDerivedFrom(String derivedFrom) { - this.derivedFrom = derivedFrom; - } - - public List> getConstraints() { - return constraints; - } - - public void setConstraints(List> constraints) { - this.constraints = constraints; - } - - public Map getProperties() { - return properties; - } - - public void setProperties(Map properties) { - this.properties = properties; - } - -} diff --git a/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/data/EntrySchema.java b/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/data/EntrySchema.java deleted file mode 100644 index b98cfd338..000000000 --- a/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/data/EntrySchema.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2018 IBM. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.ccsdk.config.model.data; - -/** - * EntrySchema.java Purpose: Provide EntrySchema TOSCO Model POJO bean. - * - * @version 1.0 - */ -public class EntrySchema { - private String type; - - public String getType() { - return type; - } - - public void setType(String type) { - this.type = type; - } - -} diff --git a/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/data/Implementation.java b/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/data/Implementation.java deleted file mode 100644 index 016a8cfa0..000000000 --- a/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/data/Implementation.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2018 IBM. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.ccsdk.config.model.data; - -import java.util.List; -import com.fasterxml.jackson.annotation.JsonIgnore; - -/** - * Implementation.java Purpose: Provide Operation Implementation TOSCO Model POJO bean. - * - * @version 1.0 - */ -public class Implementation { - @JsonIgnore - private String primary; - private List dependencies; - - public String getPrimary() { - return primary; - } - - public void setPrimary(String primary) { - this.primary = primary; - } - - public List getDependencies() { - return dependencies; - } - - public void setDependencies(List dependencies) { - this.dependencies = dependencies; - } - -} diff --git a/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/data/InterfaceAssignment.java b/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/data/InterfaceAssignment.java deleted file mode 100644 index fc7f56f71..000000000 --- a/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/data/InterfaceAssignment.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2018 IBM. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.ccsdk.config.model.data; - -import java.util.Map; -import com.fasterxml.jackson.annotation.JsonIgnore; - -/** - * InterfaceAssignment.java Purpose: Provide InterfaceAssignment TOSCO Model POJO bean. - * - * @version 1.0 - */ -public class InterfaceAssignment { - @JsonIgnore - private String id; - private String type; - private Map operations; - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - public String getType() { - return type; - } - - public void setType(String type) { - this.type = type; - } - - public Map getOperations() { - return operations; - } - - public void setOperations(Map operations) { - this.operations = operations; - } - -} diff --git a/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/data/InterfaceDefinition.java b/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/data/InterfaceDefinition.java deleted file mode 100644 index d3cbbd539..000000000 --- a/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/data/InterfaceDefinition.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2018 IBM. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.ccsdk.config.model.data; - -import java.util.Map; -import com.fasterxml.jackson.annotation.JsonIgnore; - -/** - * InterfaceAssignment.java Purpose: Provide InterfaceAssignment TOSCO Model POJO bean. - * - * @version 1.0 - */ -public class InterfaceDefinition { - @JsonIgnore - private String id; - private String type; - private Map operations; - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - public String getType() { - return type; - } - - public void setType(String type) { - this.type = type; - } - - public Map getOperations() { - return operations; - } - - public void setOperations(Map operations) { - this.operations = operations; - } - -} diff --git a/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/data/NodeTemplate.java b/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/data/NodeTemplate.java deleted file mode 100644 index 489a89b65..000000000 --- a/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/data/NodeTemplate.java +++ /dev/null @@ -1,112 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2018 IBM. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.ccsdk.config.model.data; - -import java.util.Map; -import com.fasterxml.jackson.annotation.JsonIgnore; - -/** - * NodeTemplate.java Purpose: Provide NodeTemplate TOSCO Model POJO bean. - * - * @version 1.0 - */ -public class NodeTemplate { - @JsonIgnore - private String id; - private String description; - private String type; - private Map metadata; - private Map properties; - private Map interfaces; - private Map artifacts; - private Map capabilities; - private Map requirements; - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - public String getDescription() { - return description; - } - - public void setDescription(String description) { - this.description = description; - } - - public String getType() { - return type; - } - - public void setType(String type) { - this.type = type; - } - - public Map getMetadata() { - return metadata; - } - - public void setMetadata(Map metadata) { - this.metadata = metadata; - } - - public Map getProperties() { - return properties; - } - - public void setProperties(Map properties) { - this.properties = properties; - } - - public Map getInterfaces() { - return interfaces; - } - - public void setInterfaces(Map interfaces) { - this.interfaces = interfaces; - } - - public Map getArtifacts() { - return artifacts; - } - - public void setArtifacts(Map artifacts) { - this.artifacts = artifacts; - } - - public Map getCapabilities() { - return capabilities; - } - - public void setCapabilities(Map capabilities) { - this.capabilities = capabilities; - } - - public Map getRequirements() { - return requirements; - } - - public void setRequirements(Map requirements) { - this.requirements = requirements; - } - -} diff --git a/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/data/NodeType.java b/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/data/NodeType.java deleted file mode 100644 index 5d55846ad..000000000 --- a/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/data/NodeType.java +++ /dev/null @@ -1,114 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2018 IBM. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.ccsdk.config.model.data; - -import java.util.Map; -import com.fasterxml.jackson.annotation.JsonIgnore; -import com.fasterxml.jackson.annotation.JsonProperty; - -/** - * NodeType.java Purpose: Provide NodeType TOSCO Model POJO bean. - * - * @version 1.0 - */ -public class NodeType { - @JsonIgnore - private String id; - private String description; - private String version; - private Map metadata; - @JsonProperty("derived_from") - private String derivedFrom; - private Map properties; - private Map capabilities; - private Map requirements; - private Map interfaces; - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - public String getDescription() { - return description; - } - - public void setDescription(String description) { - this.description = description; - } - - public String getVersion() { - return version; - } - - public void setVersion(String version) { - this.version = version; - } - - public Map getMetadata() { - return metadata; - } - - public void setMetadata(Map metadata) { - this.metadata = metadata; - } - - public String getDerivedFrom() { - return derivedFrom; - } - - public void setDerivedFrom(String derivedFrom) { - this.derivedFrom = derivedFrom; - } - - public Map getProperties() { - return properties; - } - - public void setProperties(Map properties) { - this.properties = properties; - } - - public Map getCapabilities() { - return capabilities; - } - - public void setCapabilities(Map capabilities) { - this.capabilities = capabilities; - } - - public Map getRequirements() { - return requirements; - } - - public void setRequirements(Map requirements) { - this.requirements = requirements; - } - - public Map getInterfaces() { - return interfaces; - } - - public void setInterfaces(Map interfaces) { - this.interfaces = interfaces; - } - -} diff --git a/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/data/OperationAssignment.java b/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/data/OperationAssignment.java deleted file mode 100644 index 8df81f5f5..000000000 --- a/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/data/OperationAssignment.java +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2018 IBM. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.ccsdk.config.model.data; - -import java.util.Map; -import com.fasterxml.jackson.annotation.JsonIgnore; - -/** - * OperationAssignment.java Purpose: Provide OperationAssignment TOSCO Model POJO bean. - * - * @version 1.0 - */ -public class OperationAssignment { - @JsonIgnore - private String id; - private String description; - private String implementation; - private Map inputs; - private Map outputs; - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - public String getDescription() { - return description; - } - - public void setDescription(String description) { - this.description = description; - } - - public String getImplementation() { - return implementation; - } - - public void setImplementation(String implementation) { - this.implementation = implementation; - } - - public Map getInputs() { - return inputs; - } - - public void setInputs(Map inputs) { - this.inputs = inputs; - } - - public Map getOutputs() { - return outputs; - } - - public void setOutputs(Map outputs) { - this.outputs = outputs; - } - -} diff --git a/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/data/OperationDefinition.java b/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/data/OperationDefinition.java deleted file mode 100644 index 9a1d3ddc4..000000000 --- a/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/data/OperationDefinition.java +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2018 IBM. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.ccsdk.config.model.data; - -import java.util.Map; -import com.fasterxml.jackson.annotation.JsonIgnore; - -/** - * OperationDefinition.java Purpose: Provide OperationDefinition TOSCO Model POJO bean. - * - * @version 1.0 - */ -public class OperationDefinition { - @JsonIgnore - private String id; - private String description; - private Implementation implementation; - private Map inputs; - private Map outputs; - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - public String getDescription() { - return description; - } - - public void setDescription(String description) { - this.description = description; - } - - public Implementation getImplementation() { - return implementation; - } - - public void setImplementation(Implementation implementation) { - this.implementation = implementation; - } - - public Map getInputs() { - return inputs; - } - - public void setInputs(Map inputs) { - this.inputs = inputs; - } - - public Map getOutputs() { - return outputs; - } - - public void setOutputs(Map outputs) { - this.outputs = outputs; - } - -} diff --git a/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/data/PropertyDefinition.java b/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/data/PropertyDefinition.java deleted file mode 100644 index b4a3a8fac..000000000 --- a/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/data/PropertyDefinition.java +++ /dev/null @@ -1,125 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2018 IBM. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.ccsdk.config.model.data; - -import java.util.HashMap; -import java.util.List; -import com.fasterxml.jackson.annotation.JsonIgnore; -import com.fasterxml.jackson.annotation.JsonProperty; - -/** - * PropertyDefinition.java Purpose: Provide PropertyDefinition TOSCO Model POJO bean. - * - * @version 1.0 - */ -public class PropertyDefinition { - @JsonIgnore - private String id; - private String description; - private Boolean required; - private String type; - @JsonProperty("default") - private Object defaultValue; - private String status; - private List> constraints; - @JsonProperty("entry_schema") - private EntrySchema entrySchema; - private Object value; - - @Override - public String toString() { - StringBuilder builder = new StringBuilder("["); - builder.append(" type :" + getType()); - builder.append(", value :" + getValue()); - builder.append("]"); - return builder.toString(); - } - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - public String getDescription() { - return description; - } - - public void setDescription(String description) { - this.description = description; - } - - public Boolean getRequired() { - return required; - } - - public void setRequired(Boolean required) { - this.required = required; - } - - public String getType() { - return type; - } - - public void setType(String type) { - this.type = type; - } - - public Object getDefaultValue() { - return defaultValue; - } - - public void setDefaultValue(Object defaultValue) { - this.defaultValue = defaultValue; - } - - public String getStatus() { - return status; - } - - public void setStatus(String status) { - this.status = status; - } - - public List> getConstraints() { - return constraints; - } - - public void setConstraints(List> constraints) { - this.constraints = constraints; - } - - public EntrySchema getEntrySchema() { - return entrySchema; - } - - public void setEntrySchema(EntrySchema entrySchema) { - this.entrySchema = entrySchema; - } - - public Object getValue() { - return value; - } - - public void setValue(Object value) { - this.value = value; - } - -} diff --git a/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/data/RelationshipTemplate.java b/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/data/RelationshipTemplate.java deleted file mode 100644 index b0de5878f..000000000 --- a/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/data/RelationshipTemplate.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2018 IBM. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.ccsdk.config.model.data; - -import java.util.Map; - -/** - * RelationshipTemplate.java Purpose: Provide RelationshipTemplate TOSCO Model POJO bean. - * - * @version 1.0 - */ -public class RelationshipTemplate { - private String description; - private String type; - private Map properties; - - public String getDescription() { - return description; - } - - public void setDescription(String description) { - this.description = description; - } - - public String getType() { - return type; - } - - public void setType(String type) { - this.type = type; - } - - public Map getProperties() { - return properties; - } - - public void setProperties(Map properties) { - this.properties = properties; - } - -} diff --git a/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/data/RequirementAssignment.java b/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/data/RequirementAssignment.java deleted file mode 100644 index b6d35d6c1..000000000 --- a/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/data/RequirementAssignment.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2018 IBM. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.ccsdk.config.model.data; - -import com.fasterxml.jackson.annotation.JsonIgnore; - -/** - * RequirementAssignment.java Purpose: Provide RequirementAssignment TOSCO Model POJO bean. - * - * @version 1.0 - */ -public class RequirementAssignment { - @JsonIgnore - private String id; - private String capability; - private String node; - // Relationship Type or Relationship Template - private String relationship; - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - public String getCapability() { - return capability; - } - - public void setCapability(String capability) { - this.capability = capability; - } - - public String getNode() { - return node; - } - - public void setNode(String node) { - this.node = node; - } - - public String getRelationship() { - return relationship; - } - - public void setRelationship(String relationship) { - this.relationship = relationship; - } - -} diff --git a/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/data/RequirementDefinition.java b/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/data/RequirementDefinition.java deleted file mode 100644 index 68b2c41c0..000000000 --- a/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/data/RequirementDefinition.java +++ /dev/null @@ -1,85 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2018 IBM. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.ccsdk.config.model.data; - -import java.util.List; -import com.fasterxml.jackson.annotation.JsonIgnore; - -/** - * RequirementDefinition.java Purpose: Provide RequirementDefinition TOSCO Model POJO bean. - * - * @version 1.0 - */ -public class RequirementDefinition { - @JsonIgnore - private String id; - private String description; - private String capability; - private String node; - private String relationship; - private List occurrences; - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - public String getDescription() { - return description; - } - - public void setDescription(String description) { - this.description = description; - } - - public String getCapability() { - return capability; - } - - public void setCapability(String capability) { - this.capability = capability; - } - - public String getNode() { - return node; - } - - public void setNode(String node) { - this.node = node; - } - - public String getRelationship() { - return relationship; - } - - public void setRelationship(String relationship) { - this.relationship = relationship; - } - - public List getOccurrences() { - return occurrences; - } - - public void setOccurrences(List occurrences) { - this.occurrences = occurrences; - } - -} diff --git a/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/data/ResourceAssignment.java b/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/data/ResourceAssignment.java deleted file mode 100644 index b84f6e3a2..000000000 --- a/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/data/ResourceAssignment.java +++ /dev/null @@ -1,165 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2018 IBM. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.ccsdk.config.model.data; - -import java.util.Date; -import java.util.List; -import com.fasterxml.jackson.annotation.JsonFormat; -import com.fasterxml.jackson.annotation.JsonProperty; - -/** - * ResourceAssignment.java Purpose: Provide ResourceAssignment Custom TOSCO Model POJO bean. - * - * @version 1.0 - */ -public class ResourceAssignment { - - private String name; - - @JsonProperty("property") - private PropertyDefinition property; - - @JsonProperty("input-param") - private Boolean inputParameter; - - @JsonProperty("dictionary-name") - private String dictionaryName; - - @JsonProperty("dictionary-source") - private String dictionarySource; - - @JsonProperty("dependencies") - private List dependencies; - - @JsonProperty("version") - private int version; - - @JsonProperty("status") - private String status; - - @JsonProperty("message") - private String message; - - @JsonProperty("updated-date") - @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "dd-MM-yyyy hh:mm:ss") - private Date updatedDate; - - @JsonProperty("updated-by") - private String updatedBy; - - @Override - public String toString() { - StringBuilder builder = new StringBuilder("["); - builder.append("name = " + name); - builder.append(", source = " + dictionarySource); - if (dependencies != null) { - builder.append(", dependencies = " + dependencies); - } - builder.append("]"); - return builder.toString(); - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public PropertyDefinition getProperty() { - return property; - } - - public void setProperty(PropertyDefinition property) { - this.property = property; - } - - public Boolean getInputParameter() { - return inputParameter; - } - - public void setInputParameter(Boolean inputParameter) { - this.inputParameter = inputParameter; - } - - public String getDictionaryName() { - return dictionaryName; - } - - public void setDictionaryName(String dictionaryName) { - this.dictionaryName = dictionaryName; - } - - public String getDictionarySource() { - return dictionarySource; - } - - public void setDictionarySource(String dictionarySource) { - this.dictionarySource = dictionarySource; - } - - public List getDependencies() { - return dependencies; - } - - public void setDependencies(List dependencies) { - this.dependencies = dependencies; - } - - public int getVersion() { - return version; - } - - public void setVersion(int version) { - this.version = version; - } - - public String getStatus() { - return status; - } - - public void setStatus(String status) { - this.status = status; - } - - public String getMessage() { - return message; - } - - public void setMessage(String message) { - this.message = message; - } - - public Date getUpdatedDate() { - return updatedDate; - } - - public void setUpdatedDate(Date updatedDate) { - this.updatedDate = updatedDate; - } - - public String getUpdatedBy() { - return updatedBy; - } - - public void setUpdatedBy(String updatedBy) { - this.updatedBy = updatedBy; - } - -} diff --git a/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/data/ServiceTemplate.java b/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/data/ServiceTemplate.java deleted file mode 100644 index ea9efa1a9..000000000 --- a/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/data/ServiceTemplate.java +++ /dev/null @@ -1,118 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2018 IBM. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.ccsdk.config.model.data; - -import java.util.Map; -import com.fasterxml.jackson.annotation.JsonIgnore; -import com.fasterxml.jackson.annotation.JsonProperty; - -/** - * ServiceTemplate.java Purpose: Provide ServiceTemplate TOSCO Model POJO bean. - * - * @version 1.0 - */ -public class ServiceTemplate { - @JsonIgnore - private String id; - @JsonProperty("tosca_definitions_version") - private String toscaDefinitionsVersion; - private Map metadata; - private String description; - @JsonProperty("dsl_definitions") - private Map dslDefinitions; - @JsonProperty("topology_template") - private TopologyTemplate topologyTemplate; - @JsonProperty("artifact_types") - private Map artifactTypes; - @JsonProperty("node_types") - private Map nodeTypes; - @JsonProperty("data_types") - private Map dataTypes; - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - public String getToscaDefinitionsVersion() { - return toscaDefinitionsVersion; - } - - public void setToscaDefinitionsVersion(String toscaDefinitionsVersion) { - this.toscaDefinitionsVersion = toscaDefinitionsVersion; - } - - public Map getMetadata() { - return metadata; - } - - public void setMetadata(Map metadata) { - this.metadata = metadata; - } - - public String getDescription() { - return description; - } - - public void setDescription(String description) { - this.description = description; - } - - public Map getDslDefinitions() { - return dslDefinitions; - } - - public void setDslDefinitions(Map dslDefinitions) { - this.dslDefinitions = dslDefinitions; - } - - public TopologyTemplate getTopologyTemplate() { - return topologyTemplate; - } - - public void setTopologyTemplate(TopologyTemplate topologyTemplate) { - this.topologyTemplate = topologyTemplate; - } - - public Map getNodeTypes() { - return nodeTypes; - } - - public void setNodeTypes(Map nodeTypes) { - this.nodeTypes = nodeTypes; - } - - public Map getDataTypes() { - return dataTypes; - } - - public void setDataTypes(Map dataTypes) { - this.dataTypes = dataTypes; - } - - public Map getArtifactTypes() { - return artifactTypes; - } - - public void setArtifactTypes(Map artifactTypes) { - this.artifactTypes = artifactTypes; - } -} diff --git a/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/data/TopologyTemplate.java b/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/data/TopologyTemplate.java deleted file mode 100644 index 5e775f1a6..000000000 --- a/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/data/TopologyTemplate.java +++ /dev/null @@ -1,97 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2018 IBM. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.ccsdk.config.model.data; - -import java.util.Map; -import com.fasterxml.jackson.annotation.JsonIgnore; -import com.fasterxml.jackson.annotation.JsonProperty; - -/** - * TopologyTemplate.java Purpose: Provide TopologyTemplate TOSCO Model POJO bean. - * - * @version 1.0 - */ -public class TopologyTemplate { - @JsonIgnore - private String id; - private String description; - private Map inputs; - @JsonProperty("node_templates") - private Map nodeTemplates; - @JsonProperty("relationship_templates") - private Map relationshipTemplates; - private Map capabilities; - private Map workflows; - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - public String getDescription() { - return description; - } - - public void setDescription(String description) { - this.description = description; - } - - public Map getInputs() { - return inputs; - } - - public void setInputs(Map inputs) { - this.inputs = inputs; - } - - public Map getNodeTemplates() { - return nodeTemplates; - } - - public void setNodeTemplates(Map nodeTemplates) { - this.nodeTemplates = nodeTemplates; - } - - public Map getRelationshipTemplates() { - return relationshipTemplates; - } - - public void setRelationshipTemplates(Map relationshipTemplates) { - this.relationshipTemplates = relationshipTemplates; - } - - public Map getCapabilities() { - return capabilities; - } - - public void setCapabilities(Map capabilities) { - this.capabilities = capabilities; - } - - public Map getWorkflows() { - return workflows; - } - - public void setWorkflows(Map workflows) { - this.workflows = workflows; - } - -} diff --git a/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/data/Workflow.java b/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/data/Workflow.java deleted file mode 100644 index 733743cbd..000000000 --- a/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/data/Workflow.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2018 IBM. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.ccsdk.config.model.data; - -import com.fasterxml.jackson.annotation.JsonIgnore; - -/** - * Workflow.java Purpose: Provide Workflow TOSCO Model POJO bean. - * - * @version 1.0 - */ -public class Workflow { - @JsonIgnore - private String id; - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - -} diff --git a/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/data/api/ActionIdentifiers.java b/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/data/api/ActionIdentifiers.java deleted file mode 100644 index cadfe1b62..000000000 --- a/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/data/api/ActionIdentifiers.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2018 IBM. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.ccsdk.config.model.data.api; - -import com.fasterxml.jackson.annotation.JsonProperty; - -public class ActionIdentifiers { - @JsonProperty("service-template-name") - private String serviceTemplateName; - @JsonProperty("service-template-version") - private String serviceTemplateVersion; - @JsonProperty("action-name") - private String actionName; - private String mode; - - public String getServiceTemplateName() { - return serviceTemplateName; - } - - public void setServiceTemplateName(String serviceTemplateName) { - this.serviceTemplateName = serviceTemplateName; - } - - public String getServiceTemplateVersion() { - return serviceTemplateVersion; - } - - public void setServiceTemplateVersion(String serviceTemplateVersion) { - this.serviceTemplateVersion = serviceTemplateVersion; - } - - public String getActionName() { - return actionName; - } - - public void setActionName(String actionName) { - this.actionName = actionName; - } - - public String getMode() { - return mode; - } - - public void setMode(String mode) { - this.mode = mode; - } -} diff --git a/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/data/api/CommonHeader.java b/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/data/api/CommonHeader.java deleted file mode 100644 index d816307d1..000000000 --- a/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/data/api/CommonHeader.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2018 IBM. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.ccsdk.config.model.data.api; - -import com.fasterxml.jackson.annotation.JsonProperty; - -public class CommonHeader { - - private String timestamp; - @JsonProperty("api-ver") - private String apiVer; - @JsonProperty("originator-id") - private String originatorId; - @JsonProperty("request-id") - private String requestId; - @JsonProperty("sub-request-id") - private String subRequestId; - private Flags flags; - - public String getTimestamp() { - return timestamp; - } - - public void setTimestamp(String timestamp) { - this.timestamp = timestamp; - } - - public String getApiVer() { - return apiVer; - } - - public void setApiVer(String apiVer) { - this.apiVer = apiVer; - } - - public String getOriginatorId() { - return originatorId; - } - - public void setOriginatorId(String originatorId) { - this.originatorId = originatorId; - } - - public String getRequestId() { - return requestId; - } - - public void setRequestId(String requestId) { - this.requestId = requestId; - } - - public String getSubRequestId() { - return subRequestId; - } - - public void setSubRequestId(String subRequestId) { - this.subRequestId = subRequestId; - } - - public Flags getFlags() { - return flags; - } - - public void setFlags(Flags flags) { - this.flags = flags; - } -} diff --git a/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/data/api/Flags.java b/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/data/api/Flags.java deleted file mode 100644 index 81adc7416..000000000 --- a/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/data/api/Flags.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2018 IBM. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.ccsdk.config.model.data.api; - -public class Flags { - private boolean force; - private Integer ttl; - - public boolean isForce() { - return force; - } - - public void setForce(boolean force) { - this.force = force; - } - - public Integer getTtl() { - return ttl; - } - - public void setTtl(Integer ttl) { - this.ttl = ttl; - } - -} diff --git a/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/data/api/Status.java b/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/data/api/Status.java deleted file mode 100644 index 7c678e9ab..000000000 --- a/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/data/api/Status.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2018 IBM. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.ccsdk.config.model.data.api; - -import com.fasterxml.jackson.annotation.JsonProperty; - -public class Status { - - private Integer code; - @JsonProperty("error-message") - private String errorMessage; - private String message; - private String completed; - - public Integer getCode() { - return code; - } - - public void setCode(Integer code) { - this.code = code; - } - - public String getErrorMessage() { - return errorMessage; - } - - public void setErrorMessage(String errorMessage) { - this.errorMessage = errorMessage; - } - - public String getMessage() { - return message; - } - - public void setMessage(String message) { - this.message = message; - } - - public String getCompleted() { - return completed; - } - - public void setCompleted(String completed) { - this.completed = completed; - } -} diff --git a/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/data/api/TransactionRequest.java b/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/data/api/TransactionRequest.java deleted file mode 100644 index ebfa97f5d..000000000 --- a/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/data/api/TransactionRequest.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2018 IBM. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.ccsdk.config.model.data.api; - -import com.fasterxml.jackson.annotation.JsonProperty; - -public class TransactionRequest { - - @JsonProperty("transaction-request-id") - private String transactionRequestId; - @JsonProperty("message-type") - private String messageType; - - public String getTransactionRequestId() { - return transactionRequestId; - } - - public void setTransactionRequestId(String transactionRequestId) { - this.transactionRequestId = transactionRequestId; - } - - public String getMessageType() { - return messageType; - } - - public void setMessageType(String messageType) { - this.messageType = messageType; - } - -} diff --git a/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/data/api/TransactionResponse.java b/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/data/api/TransactionResponse.java deleted file mode 100644 index 6a7b2e335..000000000 --- a/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/data/api/TransactionResponse.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2018 IBM. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.ccsdk.config.model.data.api; - -import java.util.List; -import com.fasterxml.jackson.annotation.JsonProperty; - -public class TransactionResponse { - - @JsonProperty("transaction-request-id") - private String transactionRequestId; - @JsonProperty("event-message") - private List eventMessage; - - public String getTransactionRequestId() { - return transactionRequestId; - } - - public void setTransactionRequestId(String transactionRequestId) { - this.transactionRequestId = transactionRequestId; - } - - public List getEventMessage() { - return eventMessage; - } - - public void setEventMessage(List eventMessage) { - this.eventMessage = eventMessage; - } - -} diff --git a/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/data/dict/ResourceDefinition.java b/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/data/dict/ResourceDefinition.java deleted file mode 100644 index e374aeb95..000000000 --- a/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/data/dict/ResourceDefinition.java +++ /dev/null @@ -1,103 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2018 IBM. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.ccsdk.config.model.data.dict; - -import java.util.Map; -import org.onap.ccsdk.config.model.data.PropertyDefinition; -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import com.fasterxml.jackson.annotation.JsonProperty; - -@JsonIgnoreProperties(ignoreUnknown = true) -public class ResourceDefinition { - private String tags; - - @JsonProperty(value = "name", required = true) - private String name; - - @JsonProperty(value = "property") - private PropertyDefinition property; - - @JsonProperty(value = "updated-by") - private String updatedBy; - - @JsonProperty(value = "resource-type", required = true) - private String resourceType; - - @JsonProperty(value = "resource-path", required = true) - private String resourcePath; - - @JsonProperty(value = "sources", required = true) - private Map sourcesDefinition; - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public PropertyDefinition getProperty() { - return property; - } - - public void setProperty(PropertyDefinition property) { - this.property = property; - } - - public String getTags() { - return tags; - } - - public void setTags(String tags) { - this.tags = tags; - } - - public String getUpdatedBy() { - return updatedBy; - } - - public void setUpdatedBy(String updatedBy) { - this.updatedBy = updatedBy; - } - - public String getResourceType() { - return resourceType; - } - - public void setResourceType(String resourceType) { - this.resourceType = resourceType; - } - - public String getResourcePath() { - return resourcePath; - } - - public void setResourcePath(String resourcePath) { - this.resourcePath = resourcePath; - } - - public Map getSources() { - return sourcesDefinition; - } - - public void setSources(Map sourcesDefinition) { - this.sourcesDefinition = sourcesDefinition; - } - -} diff --git a/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/data/dict/SourcesDefinition.java b/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/data/dict/SourcesDefinition.java deleted file mode 100644 index 6b9fc0ab6..000000000 --- a/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/data/dict/SourcesDefinition.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2018 IBM. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.ccsdk.config.model.data.dict; - -import com.fasterxml.jackson.annotation.JsonProperty; - -public class SourcesDefinition { - - @JsonProperty(value = "type", required = true) - private String type; - - @JsonProperty(value = "properties", required = true) - private SourcesProperties properties; - - public String getType() { - return type; - } - - public void setType(String type) { - this.type = type; - } - - public SourcesProperties getProperties() { - return properties; - } - - public void setProperties(SourcesProperties properties) { - this.properties = properties; - } - -} diff --git a/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/data/dict/SourcesProperties.java b/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/data/dict/SourcesProperties.java deleted file mode 100644 index 5be164768..000000000 --- a/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/data/dict/SourcesProperties.java +++ /dev/null @@ -1,125 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2018 IBM. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.ccsdk.config.model.data.dict; - -import java.util.List; -import java.util.Map; -import com.fasterxml.jackson.annotation.JsonProperty; - -public class SourcesProperties { - - @JsonProperty(value = "name") - private String name; - - @JsonProperty(value = "base") - private String base; - - @JsonProperty(value = "type") - private String type; - - @JsonProperty(value = "query") - private String query; - - @JsonProperty(value = "url-path") - private String urlPath; - - @JsonProperty(value = "path") - private String path; - - @JsonProperty("input-key-mapping") - private Map inputKeyMapping; - - @JsonProperty("output-key-mapping") - private Map outputKeyMapping; - - @JsonProperty("key-dependencies") - private List dependencies; - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public String getBase() { - return base; - } - - public void setBase(String base) { - this.base = base; - } - - public String getType() { - return type; - } - - public void setType(String type) { - this.type = type; - } - - public String getQuery() { - return query; - } - - public void setQuery(String query) { - this.query = query; - } - - public String getUrlPath() { - return urlPath; - } - - public void setUrlPath(String urlPath) { - this.urlPath = urlPath; - } - - public String getPath() { - return path; - } - - public void setPath(String path) { - this.path = path; - } - - public Map getInputKeyMapping() { - return inputKeyMapping; - } - - public void setInputKeyMapping(Map inputKeyMapping) { - this.inputKeyMapping = inputKeyMapping; - } - - public Map getOutputKeyMapping() { - return outputKeyMapping; - } - - public void setOutputKeyMapping(Map outputKeyMapping) { - this.outputKeyMapping = outputKeyMapping; - } - - public List getDependencies() { - return dependencies; - } - - public void setDependencies(List dependencies) { - this.dependencies = dependencies; - } - -} diff --git a/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/domain/ConfigModel.java b/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/domain/ConfigModel.java deleted file mode 100644 index 9821fd0eb..000000000 --- a/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/domain/ConfigModel.java +++ /dev/null @@ -1,231 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2018 IBM. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.ccsdk.config.model.domain; - -import java.io.Serializable; -import java.util.Date; -import java.util.List; -import com.fasterxml.jackson.annotation.JsonFormat; - -public class ConfigModel implements Serializable { - - private Long id; - private String serviceUUID; - private String distributionId; - private String serviceName; - private String serviceDescription; - private String resourceUUID; - private String resourceInstanceName; - private String resourceName; - private String resourceVersion; - private String resourceType; - private String artifactUUId; - private String artifactType; - private String artifactVersion; - private String artifactDescription; - private Integer internalVersion; - @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "MM/dd/yyyy KK:mm:ss a Z") - private Date createdDate = new Date(); - private String artifactName; - private String published; - private String updatedBy; - private String tags; - @SuppressWarnings("squid:S1948") - private List configModelContents; - - @Override - public String toString() { - StringBuilder buffer = new StringBuilder("["); - buffer.append("id = " + id); - buffer.append(", artifactType = " + artifactType); - buffer.append(", artifactVersion = " + artifactVersion); - buffer.append(", artifactName = " + artifactName); - buffer.append(", active = " + published); - buffer.append("]"); - return buffer.toString(); - } - - public Long getId() { - return id; - } - - public void setId(Long id) { - this.id = id; - } - - public String getServiceUUID() { - return serviceUUID; - } - - public void setServiceUUID(String serviceUUID) { - this.serviceUUID = serviceUUID; - } - - public String getDistributionId() { - return distributionId; - } - - public void setDistributionId(String distributionId) { - this.distributionId = distributionId; - } - - public String getServiceName() { - return serviceName; - } - - public void setServiceName(String serviceName) { - this.serviceName = serviceName; - } - - public String getServiceDescription() { - return serviceDescription; - } - - public void setServiceDescription(String serviceDescription) { - this.serviceDescription = serviceDescription; - } - - public String getResourceUUID() { - return resourceUUID; - } - - public void setResourceUUID(String resourceUUID) { - this.resourceUUID = resourceUUID; - } - - public String getResourceInstanceName() { - return resourceInstanceName; - } - - public void setResourceInstanceName(String resourceInstanceName) { - this.resourceInstanceName = resourceInstanceName; - } - - public String getResourceName() { - return resourceName; - } - - public void setResourceName(String resourceName) { - this.resourceName = resourceName; - } - - public String getResourceVersion() { - return resourceVersion; - } - - public void setResourceVersion(String resourceVersion) { - this.resourceVersion = resourceVersion; - } - - public String getResourceType() { - return resourceType; - } - - public void setResourceType(String resourceType) { - this.resourceType = resourceType; - } - - public String getArtifactUUId() { - return artifactUUId; - } - - public void setArtifactUUId(String artifactUUId) { - this.artifactUUId = artifactUUId; - } - - public String getArtifactType() { - return artifactType; - } - - public void setArtifactType(String artifactType) { - this.artifactType = artifactType; - } - - public String getArtifactVersion() { - return artifactVersion; - } - - public void setArtifactVersion(String artifactVersion) { - this.artifactVersion = artifactVersion; - } - - public String getArtifactDescription() { - return artifactDescription; - } - - public void setArtifactDescription(String artifactDescription) { - this.artifactDescription = artifactDescription; - } - - public Integer getInternalVersion() { - return internalVersion; - } - - public void setInternalVersion(Integer internalVersion) { - this.internalVersion = internalVersion; - } - - public Date getCreatedDate() { - return createdDate; - } - - public void setCreatedDate(Date createdDate) { - this.createdDate = createdDate; - } - - public String getArtifactName() { - return artifactName; - } - - public void setArtifactName(String artifactName) { - this.artifactName = artifactName; - } - - public String getPublished() { - return published; - } - - public void setPublished(String published) { - this.published = published; - } - - public String getUpdatedBy() { - return updatedBy; - } - - public void setUpdatedBy(String updatedBy) { - this.updatedBy = updatedBy; - } - - public String getTags() { - return tags; - } - - public void setTags(String tags) { - this.tags = tags; - } - - public List getConfigModelContents() { - return configModelContents; - } - - public void setConfigModelContents(List configModelContents) { - this.configModelContents = configModelContents; - } - -} diff --git a/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/domain/ConfigModelContent.java b/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/domain/ConfigModelContent.java deleted file mode 100644 index d1ef5fef8..000000000 --- a/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/domain/ConfigModelContent.java +++ /dev/null @@ -1,91 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2018 IBM. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.ccsdk.config.model.domain; - -import java.util.Date; -import com.fasterxml.jackson.annotation.JsonFormat; - -public class ConfigModelContent { - - private Long id; - private String name; - private String contentType; - private String description; - private String content; - @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "MM/dd/yyyy KK:mm:ss a Z") - private Date createdDate = new Date(); - - @Override - public String toString() { - StringBuilder buffer = new StringBuilder("["); - buffer.append("id = " + id); - buffer.append(", name = " + name); - buffer.append(", type = " + contentType); - buffer.append("]"); - return buffer.toString(); - } - - public Long getId() { - return id; - } - - public void setId(Long id) { - this.id = id; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public String getContentType() { - return contentType; - } - - public void setContentType(String type) { - this.contentType = type; - } - - public String getDescription() { - return description; - } - - public void setDescription(String description) { - this.description = description; - } - - public String getContent() { - return content; - } - - public void setContent(String content) { - this.content = content; - } - - public Date getCreatedDate() { - return createdDate; - } - - public void setCreatedDate(Date createdDate) { - this.createdDate = createdDate; - } - -} diff --git a/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/domain/ResourceDictionary.java b/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/domain/ResourceDictionary.java deleted file mode 100644 index 163566c3c..000000000 --- a/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/domain/ResourceDictionary.java +++ /dev/null @@ -1,162 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2018 IBM. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.ccsdk.config.model.domain; - -import java.io.Serializable; -import java.util.Date; - -public class ResourceDictionary implements Serializable { - private static final long serialVersionUID = 1L; - - private Long id; - private String name; - private String resourcePath; - private String resourceType; - private String dataType; - private String entrySchema; - private String validValues; - private String sampleValue; - private String definition; - private String description; - private String tags; - private Date creationDate; - private String updatedBy; - - @Override - public String toString() { - StringBuilder buffer = new StringBuilder("["); - buffer.append("id = " + id); - buffer.append(", name = " + name); - buffer.append(", resourcePath = " + resourcePath); - buffer.append(", resourceType = " + resourceType); - buffer.append(", dataType = " + dataType); - buffer.append(", entrySchema = " + entrySchema); - buffer.append(", validValues = " + validValues); - buffer.append(", definition =" + definition); - buffer.append(", description = " + description); - buffer.append(", tags = " + tags); - buffer.append(", creationDate = " + creationDate); - buffer.append("]"); - return buffer.toString(); - } - - public Long getId() { - return id; - } - - public void setId(Long id) { - this.id = id; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public String getResourcePath() { - return resourcePath; - } - - public void setResourcePath(String resourcePath) { - this.resourcePath = resourcePath; - } - - public String getResourceType() { - return resourceType; - } - - public void setResourceType(String resourceType) { - this.resourceType = resourceType; - } - - public String getDataType() { - return dataType; - } - - public void setDataType(String dataType) { - this.dataType = dataType; - } - - public String getEntrySchema() { - return entrySchema; - } - - public void setEntrySchema(String entrySchema) { - this.entrySchema = entrySchema; - } - - public String getValidValues() { - return validValues; - } - - public void setValidValues(String validValues) { - this.validValues = validValues; - } - - public String getSampleValue() { - return sampleValue; - } - - public void setSampleValue(String sampleValue) { - this.sampleValue = sampleValue; - } - - public String getDefinition() { - return definition; - } - - public void setDefinition(String definition) { - this.definition = definition; - } - - public String getDescription() { - return description; - } - - public void setDescription(String description) { - this.description = description; - } - - public String getTags() { - return tags; - } - - public void setTags(String tags) { - this.tags = tags; - } - - public Date getCreationDate() { - return creationDate; - } - - public void setCreationDate(Date creationDate) { - this.creationDate = creationDate; - } - - public String getUpdatedBy() { - return updatedBy; - } - - public void setUpdatedBy(String updatedBy) { - this.updatedBy = updatedBy; - } - -} diff --git a/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/service/ComponentNode.java b/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/service/ComponentNode.java deleted file mode 100644 index fd8e79c49..000000000 --- a/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/service/ComponentNode.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2018 IBM. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.ccsdk.config.model.service; - -import java.util.Map; -import org.onap.ccsdk.sli.core.sli.SvcLogicContext; -import org.onap.ccsdk.sli.core.sli.SvcLogicException; -import org.onap.ccsdk.sli.core.sli.SvcLogicJavaPlugin; - -public interface ComponentNode extends SvcLogicJavaPlugin { - - public Boolean preCondition(Map inParams, SvcLogicContext ctx, Map componentContext) - throws SvcLogicException; - - public void preProcess(Map inParams, SvcLogicContext ctx, Map componentContext) - throws SvcLogicException; - - public void process(Map inParams, SvcLogicContext ctx) throws SvcLogicException; - - public void process(Map inParams, SvcLogicContext ctx, Map componentContext) - throws SvcLogicException; - - public void postProcess(Map inParams, SvcLogicContext ctx, Map componentContext) - throws SvcLogicException; - -} diff --git a/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/service/ComponentNodeDelegate.java b/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/service/ComponentNodeDelegate.java deleted file mode 100644 index e2d332cd9..000000000 --- a/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/service/ComponentNodeDelegate.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2018 IBM. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.ccsdk.config.model.service; - -import java.util.Map; -import org.onap.ccsdk.sli.core.sli.SvcLogicContext; -import org.onap.ccsdk.sli.core.sli.SvcLogicException; -import org.onap.ccsdk.sli.core.sli.SvcLogicJavaPlugin; -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; - -public class ComponentNodeDelegate implements SvcLogicJavaPlugin { - - private static EELFLogger logger = EELFManager.getInstance().getLogger(ComponentNodeDelegate.class); - private ComponentNodeService componentNodeService; - - public ComponentNodeDelegate(ComponentNodeService componentNodeService) { - logger.info("{} Constructor Initiated", "ComponentNodeDelegate"); - this.componentNodeService = componentNodeService; - - } - - public void process(Map inParams, SvcLogicContext ctx) throws SvcLogicException { - this.componentNodeService.process(inParams, ctx, null); - } - -} diff --git a/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/service/ComponentNodeService.java b/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/service/ComponentNodeService.java deleted file mode 100644 index 6c954518a..000000000 --- a/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/service/ComponentNodeService.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2018 IBM. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.ccsdk.config.model.service; - -import java.util.Map; -import org.onap.ccsdk.sli.core.sli.SvcLogicContext; -import org.onap.ccsdk.sli.core.sli.SvcLogicException; - -public interface ComponentNodeService { - - public void process(Map inParams, SvcLogicContext ctx, Map componentContext) - throws SvcLogicException; - - public ComponentNode getComponentNodeInterface(String pluginName, String componentType) throws SvcLogicException; - - public ComponentNode getComponentNode(SvcLogicContext ctx, String selectorName) throws SvcLogicException; -} diff --git a/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/service/ComponentNodeServiceImpl.java b/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/service/ComponentNodeServiceImpl.java deleted file mode 100644 index a2f1e7af3..000000000 --- a/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/service/ComponentNodeServiceImpl.java +++ /dev/null @@ -1,174 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2018 IBM. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.ccsdk.config.model.service; - -import java.util.HashMap; -import java.util.Map; -import org.apache.commons.lang3.StringUtils; -import org.onap.ccsdk.config.data.adaptor.DataAdaptorConstants; -import org.onap.ccsdk.config.data.adaptor.domain.TransactionLog; -import org.onap.ccsdk.config.data.adaptor.service.ConfigResourceService; -import org.onap.ccsdk.config.model.ConfigModelConstant; -import org.onap.ccsdk.config.model.data.InterfaceAssignment; -import org.onap.ccsdk.config.model.data.NodeTemplate; -import org.onap.ccsdk.config.model.utils.TransformationUtils; -import org.onap.ccsdk.config.rest.adaptor.service.ConfigRestAdaptorService; -import org.onap.ccsdk.sli.core.sli.SvcLogicContext; -import org.onap.ccsdk.sli.core.sli.SvcLogicException; -import org.osgi.framework.BundleContext; -import org.osgi.framework.ServiceReference; -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; - -public class ComponentNodeServiceImpl implements ComponentNodeService { - - private static EELFLogger logger = EELFManager.getInstance().getLogger(ComponentNodeServiceImpl.class); - - private BundleContext bcontext; - private ConfigResourceService configResourceService; - private ConfigModelService configModelService; - - public ComponentNodeServiceImpl(BundleContext blueprintBundleContext, ConfigResourceService configResourceService, - ConfigRestAdaptorService configRestAdaptorService) { - logger.info("{} Constructor Initiated", "ComponentNodeServiceImpl"); - this.bcontext = blueprintBundleContext; - this.configResourceService = configResourceService; - this.configModelService = new ConfigModelServiceImpl(configRestAdaptorService); - } - - @Override - public void process(Map inParams, SvcLogicContext ctx, Map componentContext) - throws SvcLogicException { - String requestId = null; - String selector = null; - try { - selector = inParams.get(ConfigModelConstant.PROPERTY_SELECTOR); - requestId = ctx.getAttribute(ConfigModelConstant.PROPERTY_REQUEST_ID); - - logger.info("Component execution started with input params ({})", inParams); - configModelService.assignInParamsFromModel(ctx, inParams); - - String currentInterface = inParams.get(ConfigModelConstant.PROPERTY_CURRENT_INTERFACE); - String currentNodeDerivedFrom = inParams.get(ConfigModelConstant.PROPERTY_CURRENT_NODETYPE_DERIVED_FROM); - - configResourceService.save(new TransactionLog(requestId, DataAdaptorConstants.LOG_MESSAGE_TYPE_COMPONENT, - String.format("Executing Component (%s) derived from (%s) with Params : (%s) ", currentInterface, - currentNodeDerivedFrom, inParams))); - - ComponentNode handler = getComponentNodeInterface(currentInterface, currentNodeDerivedFrom); - - if (handler == null) { - throw new SvcLogicException( - String.format("Could not find Component for Interface %s", currentInterface)); - } - if (componentContext == null) { - componentContext = new HashMap<>(); - } - - logger.debug("Executing component ({})", currentInterface); - - if (handler.preCondition(inParams, ctx, componentContext)) { - handler.preProcess(inParams, ctx, componentContext); - handler.process(inParams, ctx, componentContext); - handler.postProcess(inParams, ctx, componentContext); - logger.debug("Executed component ({}) successfully.", currentInterface); - configResourceService - .save(new TransactionLog(requestId, DataAdaptorConstants.LOG_MESSAGE_TYPE_COMPONENT, - String.format("Component (%s) executed successfully. ", currentInterface))); - - ctx.setAttribute(selector + ConfigModelConstant.PROPERTY_DOT_STATUS, - ConfigModelConstant.STATUS_SUCCESS); - } else { - logger.info("Skipped component execution ({})", handler.getClass()); - configResourceService - .save(new TransactionLog(requestId, DataAdaptorConstants.LOG_MESSAGE_TYPE_COMPONENT, - String.format("Skipping component (%s) execution.", handler.getClass()))); - ctx.setAttribute(selector + ConfigModelConstant.PROPERTY_DOT_STATUS, - ConfigModelConstant.STATUS_SKIPPED); - } - - configModelService.assignOutParamsFromModel(ctx, inParams); - ctx.setStatus(ConfigModelConstant.STATUS_SUCCESS); - } catch (Exception e) { - logger.error(String.format("Failed in component (%s) execution for request id (%s) with error %s", selector, - requestId, e.getMessage())); - configResourceService.save(new TransactionLog(requestId, DataAdaptorConstants.LOG_MESSAGE_TYPE_COMPONENT, - String.format("Failed in component (%s) execution for request id (%s) with error %s", selector, - requestId, e.getMessage()))); - - ctx.setAttribute(selector + ConfigModelConstant.PROPERTY_DOT_STATUS, ConfigModelConstant.STATUS_FAILURE); - ctx.setAttribute(selector + ConfigModelConstant.PROPERTY_DOT_ERROR_MESSAGE, e.getMessage()); - ctx.setAttribute(ConfigModelConstant.PROPERTY_ERROR_MESSAGE, e.getMessage()); - ctx.setStatus(ConfigModelConstant.STATUS_FAILURE); - throw new SvcLogicException(e.getMessage(), e); - } - } - - @Override - public ComponentNode getComponentNodeInterface(String pluginName, String componentType) throws SvcLogicException { - - logger.info("Searching for component node plugin ({}) component type ({})", pluginName, componentType); - - if (StringUtils.isBlank(pluginName)) { - throw new SvcLogicException( - String.format("Could not get Interface Name from Service Template : %s ", pluginName)); - } - - pluginName = pluginName.replace("-", "."); - ServiceReference sref = bcontext.getServiceReference(pluginName); - - if (sref == null) { - throw new SvcLogicException( - String.format("Could not find service reference object for plugin %s", pluginName)); - } - return (ComponentNode) bcontext.getService(sref); - } - - @Override - public ComponentNode getComponentNode(SvcLogicContext ctx, String componentKey) throws SvcLogicException { - - if (StringUtils.isBlank(componentKey)) { - logger.warn("Can't get node template content for a component key ({})", componentKey); - return null; - } - - String nodeTemplateContent = ctx.getAttribute(ConfigModelConstant.PROPERTY_NODE_TEMPLATES_DOT + componentKey); - logger.info("Processing component template : ({})", nodeTemplateContent); - - if (StringUtils.isBlank(nodeTemplateContent)) { - logger.warn("Couldn't get node template content for component key ({})", componentKey); - return null; - } - - NodeTemplate nodeTemplate = TransformationUtils.readValue(nodeTemplateContent, NodeTemplate.class); - if (nodeTemplate == null || StringUtils.isBlank(nodeTemplate.getType())) { - logger.warn("Failed to convert content ({}) to node template.", nodeTemplateContent); - return null; - } - - ComponentNode componentNode = null; - for (Map.Entry nodeTemplateInterface : nodeTemplate.getInterfaces().entrySet()) { - if (nodeTemplateInterface != null && nodeTemplateInterface.getValue() != null) { - String pluginName = nodeTemplateInterface.getKey(); - componentNode = getComponentNodeInterface(pluginName, ConfigModelConstant.MODEL_TYPE_NODE_COMPONENT); - } - } - return componentNode; - } - -} diff --git a/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/service/ConfigBlueprintService.java b/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/service/ConfigBlueprintService.java deleted file mode 100644 index 49c64abc9..000000000 --- a/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/service/ConfigBlueprintService.java +++ /dev/null @@ -1,100 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2018 IBM. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.ccsdk.config.model.service; - -import java.util.List; -import java.util.Map; -import org.apache.commons.lang3.StringUtils; -import org.onap.ccsdk.config.model.ConfigModelConstant; -import org.onap.ccsdk.config.model.domain.ConfigModel; -import org.onap.ccsdk.config.model.domain.ConfigModelContent; -import org.onap.ccsdk.config.model.utils.PrepareContextUtils; -import org.onap.ccsdk.config.rest.adaptor.ConfigRestAdaptorConstants; -import org.onap.ccsdk.config.rest.adaptor.ConfigRestAdaptorException; -import org.onap.ccsdk.config.rest.adaptor.service.ConfigRestAdaptorService; -import org.onap.ccsdk.sli.core.sli.SvcLogicException; -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; - -public class ConfigBlueprintService { - - private static EELFLogger logger = EELFManager.getInstance().getLogger(ConfigBlueprintService.class); - - private final ConfigRestAdaptorService configRestAdaptorService; - - public ConfigBlueprintService(ConfigRestAdaptorService configRestAdaptorService) { - this.configRestAdaptorService = configRestAdaptorService; - } - - public Map prepareContext(Map context, String input, String serviceTemplateName, - String serviceTemplateVersion) throws SvcLogicException { - try { - PrepareContextUtils prepareContextUtils = new PrepareContextUtils(); - String serviceTemplateContent = getServiceModel(context, serviceTemplateName, serviceTemplateVersion); - - if (StringUtils.isBlank(serviceTemplateContent)) { - throw new SvcLogicException(String.format("Failed to get the Service Template (%s), version (%s)", - serviceTemplateName, serviceTemplateVersion)); - } - - return prepareContextUtils.prepareContext(context, input, serviceTemplateContent); - } catch (Exception e) { - throw new SvcLogicException(e.getMessage(), e); - } - } - - @SuppressWarnings("squid:S3776") - private String getServiceModel(Map context, String serviceTemplateName, - String serviceTemplateVersion) throws SvcLogicException, ConfigRestAdaptorException { - String content = null; - - logger.info("Getting service template ({}) of version ({}) ", serviceTemplateName, serviceTemplateVersion); - - String path = "configmodelbyname/" + serviceTemplateName + "/version/" + serviceTemplateVersion; - - ConfigModel configModel = configRestAdaptorService - .getResource(ConfigRestAdaptorConstants.SELECTOR_MODEL_SERVICE, path, ConfigModel.class); - - if (configModel == null || configModel.getConfigModelContents() == null - || configModel.getConfigModelContents().isEmpty()) { - throw new SvcLogicException("Service template model is missing for service template name (" - + serviceTemplateName + "), service template version (" + serviceTemplateVersion + ") "); - } else { - if (configModel.getPublished() == null || !configModel.getPublished().equalsIgnoreCase("Y")) { - throw new SvcLogicException(String.format( - "Service template model is not published for service template (%s) ", serviceTemplateName)); - } - - List configModelContents = configModel.getConfigModelContents(); - for (ConfigModelContent configModelContent : configModelContents) { - if (configModelContent != null) { - if (ConfigModelConstant.MODEL_CONTENT_TYPE_TOSCA_JSON.equals(configModelContent.getContentType())) { - content = configModelContent.getContent(); - } else if (ConfigModelConstant.MODEL_CONTENT_TYPE_TEMPLATE - .equals(configModelContent.getContentType())) { - context.put(ConfigModelConstant.PROPERTY_NODE_TEMPLATES_DOT + configModelContent.getName() - + ".content", configModelContent.getContent()); - } - } - } - logger.trace("Service model data : {} ", content); - } - return content; - } - -} diff --git a/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/service/ConfigModelNode.java b/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/service/ConfigModelNode.java deleted file mode 100644 index 3347424fe..000000000 --- a/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/service/ConfigModelNode.java +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2018 IBM. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.ccsdk.config.model.service; - -import org.onap.ccsdk.sli.core.sli.SvcLogicJavaPlugin; - -public class ConfigModelNode implements SvcLogicJavaPlugin { - -} diff --git a/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/service/ConfigModelService.java b/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/service/ConfigModelService.java deleted file mode 100644 index 0c112baa8..000000000 --- a/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/service/ConfigModelService.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2018 IBM. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.ccsdk.config.model.service; - -import java.util.List; -import java.util.Map; -import org.onap.ccsdk.config.model.data.ServiceTemplate; -import org.onap.ccsdk.sli.core.sli.SvcLogicContext; -import org.onap.ccsdk.sli.core.sli.SvcLogicException; - -public interface ConfigModelService { - - public Boolean validateServiceTemplate(ServiceTemplate serviceTemplate) throws SvcLogicException; - - public Map prepareContext(Map context, String input, String serviceTemplateName, - String serviceTemplateVersion) throws SvcLogicException; - - public Map prepareContext(Map context, String input, String serviceTemplateContent) - throws SvcLogicException; - - public Map convertJson2properties(Map context, String jsonContent, - List blockKeys) throws SvcLogicException; - - public Map convertServiceTemplate2Properties(String serviceTemplateContent, - final Map context) throws SvcLogicException; - - public Map convertServiceTemplate2Properties(ServiceTemplate serviceTemplate, - final Map context) throws SvcLogicException; - - public SvcLogicContext assignInParamsFromModel(final SvcLogicContext context, final Map inParams) - throws SvcLogicException; - - public SvcLogicContext assignOutParamsFromModel(final SvcLogicContext context, final Map inParams) - throws SvcLogicException; - - public String getNodeTemplateContent(final SvcLogicContext context, String templateName) throws SvcLogicException; - - public String getNodeTemplateMapping(final SvcLogicContext context, String templateName) throws SvcLogicException; - -} diff --git a/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/service/ConfigModelServiceImpl.java b/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/service/ConfigModelServiceImpl.java deleted file mode 100644 index a3014b6b8..000000000 --- a/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/service/ConfigModelServiceImpl.java +++ /dev/null @@ -1,244 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2018 IBM. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.ccsdk.config.model.service; - -import java.util.List; -import java.util.Map; -import org.apache.commons.lang3.StringUtils; -import org.onap.ccsdk.config.model.ConfigModelConstant; -import org.onap.ccsdk.config.model.ConfigModelException; -import org.onap.ccsdk.config.model.data.CapabilityAssignment; -import org.onap.ccsdk.config.model.data.NodeTemplate; -import org.onap.ccsdk.config.model.data.NodeType; -import org.onap.ccsdk.config.model.data.ServiceTemplate; -import org.onap.ccsdk.config.model.utils.NodePropertyUtils; -import org.onap.ccsdk.config.model.utils.PrepareContextUtils; -import org.onap.ccsdk.config.model.utils.ServiceTemplateUtils; -import org.onap.ccsdk.config.model.utils.TransformationUtils; -import org.onap.ccsdk.config.model.validator.ServiceTemplateValidator; -import org.onap.ccsdk.config.rest.adaptor.service.ConfigRestAdaptorService; -import org.onap.ccsdk.sli.core.sli.SvcLogicContext; -import org.onap.ccsdk.sli.core.sli.SvcLogicException; -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; - -public class ConfigModelServiceImpl implements ConfigModelService { - - private static EELFLogger logger = EELFManager.getInstance().getLogger(ConfigModelServiceImpl.class); - private static final String CLASS_NAME = "ConfigModelServiceImpl"; - - private final ConfigRestAdaptorService configRestAdaptorService; - - public ConfigModelServiceImpl(ConfigRestAdaptorService configRestAdaptorService) { - logger.info("{} Constuctor Initated...", CLASS_NAME); - this.configRestAdaptorService = configRestAdaptorService; - } - - @Override - public Boolean validateServiceTemplate(ServiceTemplate serviceTemplate) throws SvcLogicException { - try { - ServiceTemplateValidator serviceTemplateValidator = new ServiceTemplateValidator(); - return serviceTemplateValidator.validateServiceTemplate(serviceTemplate); - } catch (ConfigModelException e) { - throw new SvcLogicException(e.getMessage()); - } - } - - @Override - public Map prepareContext(Map context, String input, String serviceTemplateName, - String serviceTemplateVersion) throws SvcLogicException { - - ConfigBlueprintService configBlueprintService = new ConfigBlueprintService(configRestAdaptorService); - return configBlueprintService.prepareContext(context, input, serviceTemplateName, serviceTemplateVersion); - } - - @Override - public Map prepareContext(Map context, String input, String serviceTemplateContent) - throws SvcLogicException { - try { - PrepareContextUtils prepareContextUtils = new PrepareContextUtils(); - return prepareContextUtils.prepareContext(context, input, serviceTemplateContent); - } catch (Exception e) { - throw new SvcLogicException(e.getMessage()); - } - } - - @Override - public Map convertJson2properties(Map context, String jsonContent, - List blockKeys) throws SvcLogicException { - try { - return TransformationUtils.convertJson2Properties(context, jsonContent, blockKeys); - } catch (Exception e) { - throw new SvcLogicException(e.getMessage()); - } - } - - @Override - public Map convertServiceTemplate2Properties(String serviceTemplateContent, - final Map context) throws SvcLogicException { - try { - ServiceTemplateUtils serviceTemplateUtils = new ServiceTemplateUtils(); - return serviceTemplateUtils.convertServiceTemplate2Properties(serviceTemplateContent, context); - } catch (Exception e) { - throw new SvcLogicException(e.getMessage()); - } - } - - @Override - public Map convertServiceTemplate2Properties(ServiceTemplate serviceTemplate, - final Map context) throws SvcLogicException { - try { - ServiceTemplateUtils serviceTemplateUtils = new ServiceTemplateUtils(); - return serviceTemplateUtils.convertServiceTemplate2Properties(serviceTemplate, context); - } catch (Exception e) { - throw new SvcLogicException(e.getMessage()); - } - } - - @SuppressWarnings("squid:S3776") - @Override - public SvcLogicContext assignInParamsFromModel(final SvcLogicContext context, final Map inParams) - throws SvcLogicException { - logger.debug("Processing component input param ({})", inParams); - try { - if (context != null && inParams != null && inParams.containsKey(ConfigModelConstant.PROPERTY_SELECTOR)) { - String componentKey = inParams.get(ConfigModelConstant.PROPERTY_SELECTOR); - if (StringUtils.isNotBlank(componentKey)) { - String nodeTemplateContent = - context.getAttribute(ConfigModelConstant.PROPERTY_NODE_TEMPLATES_DOT + componentKey); - logger.info("Processing node template content ({})", nodeTemplateContent); - if (StringUtils.isNotBlank(nodeTemplateContent)) { - NodeTemplate nodeTemplate = - TransformationUtils.readValue(nodeTemplateContent, NodeTemplate.class); - if (nodeTemplate != null && StringUtils.isNotBlank(nodeTemplate.getType())) { - String nodeTypeContent = context - .getAttribute(ConfigModelConstant.PROPERTY_NODE_TYPES_DOT + nodeTemplate.getType()); - NodeType nodetype = TransformationUtils.readValue(nodeTypeContent, NodeType.class); - if (nodetype != null) { - inParams.put(ConfigModelConstant.PROPERTY_CURRENT_NODETYPE_DERIVED_FROM, - nodetype.getDerivedFrom()); - NodePropertyUtils nodePropertyUtils = new NodePropertyUtils(context, inParams); - nodePropertyUtils.assignInParamsFromModel(nodetype, nodeTemplate); - } else { - throw new SvcLogicException( - String.format("Failed to get node type (%s) for node template (%s).", - nodeTemplate.getType(), componentKey)); - } - - } else { - throw new SvcLogicException(String - .format("Failed to convert content (%s) to node template.", nodeTemplateContent)); - } - } else { - throw new SvcLogicException(String - .format("Couldn't get node template content for component key (%s).", componentKey)); - } - } else { - throw new SvcLogicException( - String.format("Couldn't get component key (prefix) from inparam (%s)", inParams)); - } - } - } catch (Exception e) { - throw new SvcLogicException(e.getMessage()); - } - return context; - } - - @Override - public SvcLogicContext assignOutParamsFromModel(final SvcLogicContext context, final Map inParams) - throws SvcLogicException { - try { - if (context != null && inParams != null && inParams.containsKey(ConfigModelConstant.PROPERTY_SELECTOR)) { - String componentKey = inParams.get(ConfigModelConstant.PROPERTY_SELECTOR); - logger.info("Processing component output for prefix key ({})", componentKey); - if (StringUtils.isNotBlank(componentKey)) { - String nodeTemplateContent = - context.getAttribute(ConfigModelConstant.PROPERTY_NODE_TEMPLATES_DOT + componentKey); - if (StringUtils.isNotBlank(nodeTemplateContent)) { - NodeTemplate nodeTemplate = - TransformationUtils.readValue(nodeTemplateContent, NodeTemplate.class); - if (nodeTemplate != null && StringUtils.isNotBlank(nodeTemplate.getType())) { - String nodeTypeContent = context - .getAttribute(ConfigModelConstant.PROPERTY_NODE_TYPES_DOT + nodeTemplate.getType()); - NodeType nodetype = TransformationUtils.readValue(nodeTypeContent, NodeType.class); - NodePropertyUtils nodePropertyUtils = new NodePropertyUtils(context, inParams); - nodePropertyUtils.assignOutParamsFromModel(nodetype, nodeTemplate); - } - } - } - } - } catch (Exception e) { - throw new SvcLogicException(e.getMessage()); - } - return context; - } - - @Override - public String getNodeTemplateContent(final SvcLogicContext context, String templateName) throws SvcLogicException { - String content = null; - try { - if (context != null && StringUtils.isNotBlank(templateName)) { - logger.info("Processing Artifact Node Template for content : ({})", templateName); - content = context - .getAttribute(ConfigModelConstant.PROPERTY_NODE_TEMPLATES_DOT + templateName + ".content"); - } - } catch (Exception e) { - throw new SvcLogicException(e.getMessage()); - } - return content; - } - - @SuppressWarnings("squid:S3776") - @Override - public String getNodeTemplateMapping(final SvcLogicContext context, String templateName) throws SvcLogicException { - String mapping = null; - try { - if (context != null && StringUtils.isNotBlank(templateName)) { - logger.info("Processing artifact node template for mapping : ({})", templateName); - if (StringUtils.isNotBlank(templateName)) { - String nodeTemplateContent = - context.getAttribute(ConfigModelConstant.PROPERTY_NODE_TEMPLATES_DOT + templateName); - if (StringUtils.isNotBlank(nodeTemplateContent)) { - - NodeTemplate nodeTemplate = - TransformationUtils.readValue(nodeTemplateContent, NodeTemplate.class); - - if (nodeTemplate != null && nodeTemplate.getCapabilities() != null && nodeTemplate - .getCapabilities().containsKey(ConfigModelConstant.CAPABILITY_PROPERTY_MAPPING)) { - - CapabilityAssignment capability = - nodeTemplate.getCapabilities().get(ConfigModelConstant.CAPABILITY_PROPERTY_MAPPING); - if (capability.getProperties() != null) { - List mappingList = (List) capability.getProperties() - .get(ConfigModelConstant.CAPABILITY_PROPERTY_MAPPING); - if (mappingList != null) { - mapping = TransformationUtils.getJson(mappingList); - } - - } - } - } - } - } - } catch (Exception e) { - throw new SvcLogicException(e.getMessage()); - } - return mapping; - } - -} diff --git a/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/utils/ExpressionUtils.java b/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/utils/ExpressionUtils.java deleted file mode 100644 index 06b4c3005..000000000 --- a/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/utils/ExpressionUtils.java +++ /dev/null @@ -1,191 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2018 IBM. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.ccsdk.config.model.utils; - -import java.io.IOException; -import java.util.HashMap; -import java.util.Iterator; -import java.util.Map; -import org.apache.commons.lang3.StringUtils; -import org.onap.ccsdk.config.model.ConfigModelConstant; -import org.onap.ccsdk.config.model.data.PropertyDefinition; -import org.onap.ccsdk.sli.core.sli.SvcLogicContext; -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; -import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.databind.node.ObjectNode; - -public class ExpressionUtils { - private static EELFLogger logger = EELFManager.getInstance().getLogger(ExpressionUtils.class); - - private final SvcLogicContext context; - private final Map inParams; - - public ExpressionUtils(final SvcLogicContext context, final Map inParams) { - this.context = context; - this.inParams = inParams; - } - - public void populatePropertAssignmentsWithPrefix(String prefix, Map typeProperties, - Map templateProperties) throws IOException { - if (typeProperties != null && templateProperties != null) { - ObjectMapper mapper = new ObjectMapper(); - String templatejsonContent = mapper.writeValueAsString(templateProperties); - logger.debug("Expression inputs ({}).", templatejsonContent); - - JsonNode rootArray = mapper.readTree(templatejsonContent); - processJsonExpression(rootArray); - if (rootArray != null) { - Map prefixParams = new HashMap<>(); - TransformationUtils.convertJson2RootProperties(prefixParams, rootArray); - logger.info("Resolved inputs ({}).", rootArray); - prefixParams.forEach((key, value) -> { - this.inParams.put(prefix + "." + key, value); - }); - } - } - } - - public void populatePropertAssignments(Map typeProperties, - Map templateProperties) throws IOException { - if (typeProperties != null && templateProperties != null) { - ObjectMapper mapper = new ObjectMapper(); - String templatejsonContent = mapper.writeValueAsString(templateProperties); - logger.info("Expression inputs ({}).", templatejsonContent); - - JsonNode rootArray = mapper.readTree(templatejsonContent); - processJsonExpression(rootArray); - TransformationUtils.convertJson2RootProperties(this.inParams, rootArray); - logger.info("Resolved inputs ({}).", rootArray); - - } - } - - public void populateOutPropertAssignments(Map typeProperties, - Map templateProperties) throws IOException { - if (typeProperties != null && templateProperties != null) { - ObjectMapper mapper = new ObjectMapper(); - String templatejsonContent = mapper.writeValueAsString(templateProperties); - logger.info("Expression outputs ({}).", templatejsonContent); - - JsonNode rootArray = mapper.readTree(templatejsonContent); - processJsonExpression(rootArray); - logger.info("Resolved outputs ({}).", rootArray); - } - } - - public void processJsonExpression(JsonNode rootArray) throws IOException { - if (rootArray != null) { - Iterator> fields = rootArray.fields(); - while (fields.hasNext()) { - Map.Entry entry = fields.next(); - processJsonNode(rootArray, entry.getKey(), entry.getValue()); - } - } - } - - private void processJsonNode(JsonNode parentNode, String nodeName, JsonNode node) throws IOException { - if (node == null) { - // Do Nothing - } else if (node.isArray()) { - String[] a = new String[node.size()]; - - for (int i = 0; i < a.length; i++) { - processJsonNode(null, null, node.get(i)); - } - } else if (node.isObject()) { - - Iterator> fields = node.fields(); - while (fields.hasNext()) { - Map.Entry entry = fields.next(); - processJsonNode(node, entry.getKey(), entry.getValue()); - } - } else if (node.isTextual()) { - boolean expression = checkExpressionContent(node.asText()); - if (expression) { - processExpressionContent(parentNode, nodeName, node); - } - } - } - - private boolean checkExpressionContent(String content) { - return (StringUtils.isNotBlank(content) && (content.contains(ConfigModelConstant.EXPRESSION_GET_INPUT) - || content.contains(ConfigModelConstant.EXPRESSION_GET_ATTRIBUTE) - || content.contains(ConfigModelConstant.EXPRESSION_SET_VALUE))); - } - - @SuppressWarnings("squid:S3776") - private void processExpressionContent(JsonNode parentNode, String nodeName, JsonNode node) throws IOException { - - if (node != null && StringUtils.isNotBlank(node.asText())) { - String content = node.asText(); - ObjectMapper mapper = new ObjectMapper(); - Map expressionMap = mapper.readValue(content, Map.class); - boolean isExpressionNode = false; - - if (expressionMap != null) { - String expressionValue = null; - String expressionKey = null; - - if (expressionMap.containsKey(ConfigModelConstant.EXPRESSION_GET_INPUT)) { - isExpressionNode = true; - expressionKey = expressionMap.get(ConfigModelConstant.EXPRESSION_GET_INPUT); - expressionValue = resolveGetInputExpression(expressionKey, context); - if (expressionValue == null) { - expressionValue = resolveGetInputExpression("inputs." + expressionKey + ".default", context); - } - } else if (expressionMap.containsKey(ConfigModelConstant.EXPRESSION_GET_ATTRIBUTE)) { - isExpressionNode = true; - expressionValue = - context.getAttribute(expressionMap.get(ConfigModelConstant.EXPRESSION_GET_ATTRIBUTE)); - } else if (expressionMap.containsKey(ConfigModelConstant.EXPRESSION_SET_VALUE)) { - isExpressionNode = true; - expressionKey = expressionMap.get(ConfigModelConstant.EXPRESSION_SET_VALUE); - expressionValue = context.getAttribute(expressionKey); - - if (StringUtils.isNotBlank(expressionKey)) { - context.setAttribute(expressionKey, expressionValue); - } - } - - if (isExpressionNode && expressionValue == null) { - ((ObjectNode) parentNode).put(nodeName, ""); - } - if (StringUtils.isNotBlank(expressionValue)) { - if (expressionValue.trim().startsWith("[") || expressionValue.trim().startsWith("{")) { - JsonNode valueNode = mapper.readTree(expressionValue); - ((ObjectNode) parentNode).put(nodeName, valueNode); - } else { - ((ObjectNode) parentNode).put(nodeName, expressionValue); - } - } - logger.debug("expression ({}), expression key ({}), expression Value ({})", expressionMap, - expressionKey, expressionValue); - } - } - } - - private String resolveGetInputExpression(String key, final SvcLogicContext context) { - if (StringUtils.isNotBlank(key) && context != null) { - return context.getAttribute(key); - } - return null; - } - -} diff --git a/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/utils/JsonParserUtils.java b/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/utils/JsonParserUtils.java deleted file mode 100644 index 3555ee739..000000000 --- a/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/utils/JsonParserUtils.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2018 IBM. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.ccsdk.config.model.utils; - -import static com.jayway.jsonpath.JsonPath.using; -import java.util.List; -import com.fasterxml.jackson.databind.JsonNode; -import com.jayway.jsonpath.Configuration; -import com.jayway.jsonpath.Option; -import com.jayway.jsonpath.spi.json.JacksonJsonNodeJsonProvider; -import com.jayway.jsonpath.spi.mapper.JacksonMappingProvider; - -@SuppressWarnings("squid:S1118") -public class JsonParserUtils { - - public static final Configuration JACKSON_JSON_NODE_CONFIGURATION = Configuration.builder() - .mappingProvider(new JacksonMappingProvider()).jsonProvider(new JacksonJsonNodeJsonProvider()).build(); - - public static final Configuration PATH_CONFIGURATION = Configuration.builder().options(Option.AS_PATH_LIST).build(); - - public static List paths(String jsonContent, String expression) { - return using(PATH_CONFIGURATION).parse(jsonContent).read(expression); - } - - public static List paths(JsonNode jsonNode, String expression) { - return paths(jsonNode.toString(), expression); - } - - public static JsonNode parse(String jsonContent, String expression) { - return using(JACKSON_JSON_NODE_CONFIGURATION).parse(jsonContent).read(expression); - } - - public static JsonNode parse(JsonNode jsonNode, String expression) { - return parse(jsonNode.toString(), expression); - } - - public static JsonNode parseNSet(String jsonContent, String expression, JsonNode value) { - return using(JACKSON_JSON_NODE_CONFIGURATION).parse(jsonContent).set(expression, value).json(); - } - - public static JsonNode parseNSet(JsonNode jsonNode, String expression, JsonNode valueNode) { - return parseNSet(jsonNode.toString(), expression, valueNode); - } -} diff --git a/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/utils/JsonUtils.java b/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/utils/JsonUtils.java deleted file mode 100644 index 5bc663234..000000000 --- a/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/utils/JsonUtils.java +++ /dev/null @@ -1,109 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2018 IBM. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.ccsdk.config.model.utils; - -import org.onap.ccsdk.config.model.ValidTypes; -import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.node.ArrayNode; -import com.fasterxml.jackson.databind.node.NullNode; -import com.fasterxml.jackson.databind.node.ObjectNode; - -/** - * JsonUtils.java Purpose: Provide Configuration Generator JsonUtils Information - * - * @version 1.0 - */ -public class JsonUtils { - - private JsonUtils() { - - } - - public static void populatePrimitiveValues(String key, Object value, String primitiveType, ObjectNode objectNode) { - if (ValidTypes.DATA_TYPE_BOOLEAN.equals(primitiveType)) { - objectNode.put(key, (Boolean) value); - } else if (ValidTypes.DATA_TYPE_INTEGER.equals(primitiveType)) { - objectNode.put(key, (Integer) value); - } else if (ValidTypes.DATA_TYPE_FLOAT.equals(primitiveType)) { - objectNode.put(key, (Float) value); - } else if (ValidTypes.DATA_TYPE_TIMESTAMP.equals(primitiveType)) { - objectNode.put(key, (String) value); - } else { - objectNode.put(key, (String) value); - } - } - - public static void populatePrimitiveValues(Object value, String primitiveType, ArrayNode objectNode) { - if (ValidTypes.DATA_TYPE_BOOLEAN.equals(primitiveType)) { - objectNode.add((Boolean) value); - } else if (ValidTypes.DATA_TYPE_INTEGER.equals(primitiveType)) { - objectNode.add((Integer) value); - } else if (ValidTypes.DATA_TYPE_FLOAT.equals(primitiveType)) { - objectNode.add((Float) value); - } else if (ValidTypes.DATA_TYPE_TIMESTAMP.equals(primitiveType)) { - objectNode.add((String) value); - } else { - objectNode.add((String) value); - } - } - - public static void populatePrimitiveDefaultValues(String key, String primitiveType, ObjectNode objectNode) { - if (ValidTypes.DATA_TYPE_BOOLEAN.equals(primitiveType)) { - objectNode.put(key, false); - } else if (ValidTypes.DATA_TYPE_INTEGER.equals(primitiveType)) { - objectNode.put(key, 0); - } else if (ValidTypes.DATA_TYPE_FLOAT.equals(primitiveType)) { - objectNode.put(key, 0.0); - } else { - objectNode.put(key, ""); - } - } - - public static void populatePrimitiveDefaultValuesForArrayNode(String primitiveType, ArrayNode arrayNode) { - if (ValidTypes.DATA_TYPE_BOOLEAN.equals(primitiveType)) { - arrayNode.add(false); - } else if (ValidTypes.DATA_TYPE_INTEGER.equals(primitiveType)) { - arrayNode.add(0); - } else if (ValidTypes.DATA_TYPE_FLOAT.equals(primitiveType)) { - arrayNode.add(0.0); - } else { - arrayNode.add(""); - } - } - - public static void populateJsonNodeValues(String key, JsonNode nodeValue, String type, ObjectNode objectNode) { - if (nodeValue == null || nodeValue instanceof NullNode) { - objectNode.put(key, nodeValue); - } else if (ValidTypes.getPrimitivePropertType().contains(type)) { - if (ValidTypes.DATA_TYPE_BOOLEAN.equals(type)) { - objectNode.put(key, nodeValue.asBoolean()); - } else if (ValidTypes.DATA_TYPE_INTEGER.equals(type)) { - objectNode.put(key, nodeValue.asInt()); - } else if (ValidTypes.DATA_TYPE_FLOAT.equals(type)) { - objectNode.put(key, nodeValue.floatValue()); - } else if (ValidTypes.DATA_TYPE_TIMESTAMP.equals(type)) { - objectNode.put(key, nodeValue.asText()); - } else { - objectNode.put(key, nodeValue.asText()); - } - } else { - objectNode.set(key, nodeValue); - } - } - -} diff --git a/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/utils/NodePropertyUtils.java b/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/utils/NodePropertyUtils.java deleted file mode 100644 index 59da39bb5..000000000 --- a/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/utils/NodePropertyUtils.java +++ /dev/null @@ -1,187 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2018 IBM. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.ccsdk.config.model.utils; - -import java.io.IOException; -import java.util.HashMap; -import java.util.Map; -import org.apache.commons.lang3.StringUtils; -import org.onap.ccsdk.config.model.ConfigModelConstant; -import org.onap.ccsdk.config.model.data.CapabilityAssignment; -import org.onap.ccsdk.config.model.data.CapabilityDefinition; -import org.onap.ccsdk.config.model.data.InterfaceAssignment; -import org.onap.ccsdk.config.model.data.InterfaceDefinition; -import org.onap.ccsdk.config.model.data.NodeTemplate; -import org.onap.ccsdk.config.model.data.NodeType; -import org.onap.ccsdk.config.model.data.OperationAssignment; -import org.onap.ccsdk.config.model.data.OperationDefinition; -import org.onap.ccsdk.config.model.data.PropertyDefinition; -import org.onap.ccsdk.sli.core.sli.SvcLogicContext; -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; - -public class NodePropertyUtils { - - private static EELFLogger logger = EELFManager.getInstance().getLogger(NodePropertyUtils.class); - private final SvcLogicContext context; - private final Map inParams; - private ExpressionUtils jsonExpressionUtils; - - public NodePropertyUtils(final SvcLogicContext context, final Map inParams) { - this.context = context; - this.inParams = inParams; - jsonExpressionUtils = new ExpressionUtils(this.context, this.inParams); - } - - @SuppressWarnings("squid:S3776") - public SvcLogicContext assignInParamsFromModel(NodeType nodetype, NodeTemplate nodeTemplate) throws IOException { - if (nodeTemplate != null) { - Map inputs = null; - // Populate the Type inputs - Map nodeTypeinputs = new HashMap<>(); - for (Map.Entry nodeTypeInterface : nodetype.getInterfaces().entrySet()) { - if (nodeTypeInterface != null && nodeTypeInterface.getValue() != null) { - for (Map.Entry nodeTypeOperation : nodeTypeInterface.getValue() - .getOperations().entrySet()) { - nodeTypeinputs = nodeTypeOperation.getValue().getInputs(); - logger.trace("Populated node type input ({}).", nodeTypeinputs); - } - } - } - - if (!nodeTypeinputs.isEmpty()) { - // Populate the Template inputs - for (Map.Entry nodeTemplateInterface : nodeTemplate.getInterfaces() - .entrySet()) { - if (nodeTemplateInterface != null && nodeTemplateInterface.getValue() != null) { - this.inParams.put(ConfigModelConstant.PROPERTY_CURRENT_INTERFACE, - nodeTemplateInterface.getKey()); - for (Map.Entry nodeTemplateOperation : nodeTemplateInterface - .getValue().getOperations().entrySet()) { - if (nodeTemplateOperation != null) { - this.inParams.put(ConfigModelConstant.PROPERTY_CURRENT_OPERATION, - nodeTemplateOperation.getKey()); - if (StringUtils.isNotBlank(nodeTemplateOperation.getValue().getImplementation())) { - this.inParams.put(ConfigModelConstant.PROPERTY_CURRENT_IMPLEMENTATION, - nodeTemplateOperation.getValue().getImplementation()); - } - inputs = nodeTemplateOperation.getValue().getInputs(); - logger.trace("Populated node template input({}).", inputs); - // Assign Default Values & Types - jsonExpressionUtils.populatePropertAssignments(nodeTypeinputs, inputs); - } - } - } - } - } - - if (nodeTemplate.getRequirements() != null && !nodeTemplate.getRequirements().isEmpty()) { - assignInParamsFromRequirementModel(nodeTemplate, context, inParams); - } - } - return context; - } - - @SuppressWarnings("squid:S3776") - public SvcLogicContext assignOutParamsFromModel(NodeType nodetype, NodeTemplate nodeTemplate) throws IOException { - - if (nodeTemplate != null) { - Map outputs = null; - // Populate the Type Outputs - Map nodeTypeOutputs = new HashMap<>(); - - for (Map.Entry nodeTypeInterface : nodetype.getInterfaces().entrySet()) { - if (nodeTypeInterface != null && nodeTypeInterface.getValue() != null) { - for (Map.Entry nodeTypeOperation : nodeTypeInterface.getValue() - .getOperations().entrySet()) { - nodeTypeOutputs = nodeTypeOperation.getValue().getOutputs(); - logger.info("Populated node type output ({}).", nodeTypeOutputs); - } - } - } - - if (!nodeTypeOutputs.isEmpty()) { - // Populate the Template Outputs - for (Map.Entry nodeTemplateInterface : nodeTemplate.getInterfaces() - .entrySet()) { - if (nodeTemplateInterface != null && nodeTemplateInterface.getValue() != null) { - for (Map.Entry nodeTemplateOperation : nodeTemplateInterface - .getValue().getOperations().entrySet()) { - outputs = nodeTemplateOperation.getValue().getOutputs(); - logger.info("Populated node template output ({}).", outputs); - // Assign Default Values & Types - jsonExpressionUtils.populateOutPropertAssignments(nodeTypeOutputs, outputs); - // TO DO - } - } - } - } - } - return context; - } - - @SuppressWarnings({"squid:S3776", "squid:S00112"}) - public SvcLogicContext assignInParamsFromRequirementModel(NodeTemplate nodeTemplate, final SvcLogicContext context, - final Map inParams) { - if (nodeTemplate != null && nodeTemplate.getRequirements() != null && context != null && inParams != null) { - nodeTemplate.getRequirements().forEach((requrementKey, requirement) -> { - if (requirement != null && StringUtils.isNotBlank(requirement.getNode()) - && StringUtils.isNotBlank(requirement.getCapability())) { - String requirementNodeTemplateContent = context - .getAttribute(ConfigModelConstant.PROPERTY_NODE_TEMPLATES_DOT + requirement.getNode()); - logger.info("Processing requirement node ({}) template content ({}) ", requirement.getNode(), - requirementNodeTemplateContent); - NodeTemplate requirementNodeTemplate = - TransformationUtils.readValue(requirementNodeTemplateContent, NodeTemplate.class); - if (requirementNodeTemplate != null && requirementNodeTemplate.getCapabilities() != null) { - String nodeTypeContent = context.getAttribute( - ConfigModelConstant.PROPERTY_NODE_TYPES_DOT + requirementNodeTemplate.getType()); - NodeType nodeType = TransformationUtils.readValue(nodeTypeContent, NodeType.class); - if (nodeType != null && nodeType.getCapabilities() != null - && nodeType.getCapabilities().containsKey(requirement.getCapability())) { - CapabilityDefinition capabilityDefinition = - nodeType.getCapabilities().get(requirement.getCapability()); - if (capabilityDefinition != null) { - CapabilityAssignment capabilityAssignment = - requirementNodeTemplate.getCapabilities().get(requirement.getCapability()); - try { - assignInParamsFromCapabilityModel(requrementKey, capabilityDefinition, - capabilityAssignment, context); - } catch (Exception e) { - throw new RuntimeException(e); - } - } - } - } - } - }); - } - return context; - } - - public SvcLogicContext assignInParamsFromCapabilityModel(String requirementName, - CapabilityDefinition capabilityDefinition, CapabilityAssignment capabilityAssignment, - final SvcLogicContext context) throws IOException { - if (capabilityAssignment != null && capabilityAssignment.getProperties() != null) { - jsonExpressionUtils.populatePropertAssignmentsWithPrefix(requirementName, - capabilityDefinition.getProperties(), capabilityAssignment.getProperties()); - } - return context; - } - -} diff --git a/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/utils/PrepareContextUtils.java b/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/utils/PrepareContextUtils.java deleted file mode 100644 index ed215d2ad..000000000 --- a/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/utils/PrepareContextUtils.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2018 IBM. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.ccsdk.config.model.utils; - -import java.util.HashMap; -import java.util.Map; -import org.apache.commons.lang3.StringUtils; -import org.onap.ccsdk.config.model.ConfigModelConstant; -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; - -public class PrepareContextUtils { - - private static EELFLogger logger = EELFManager.getInstance().getLogger(PrepareContextUtils.class); - - public Map prepareContext(Map context, String input, String serviceTemplateContent) - throws Exception { - if (StringUtils.isNotBlank(serviceTemplateContent)) { - - if (context == null) { - context = new HashMap<>(); - } - if (StringUtils.isNotBlank(input)) { - TransformationUtils.convertJson2RootProperties(context, input); - } - - String recipeName = context.get(ConfigModelConstant.PROPERTY_ACTION_NAME); - if (StringUtils.isNotBlank(recipeName)) { - String recipeInputName = - recipeName.replace(ConfigModelConstant.PROPERTY_RECIPE, ConfigModelConstant.PROPERTY_REQUEST); - String recipeInput = context.get(recipeInputName); - if (StringUtils.isNotBlank(recipeInput)) { - // Un necessary to hold the Recipe Request, It is already in input - context.remove(recipeInputName); - context.remove(ConfigModelConstant.PROPERTY_PAYLOAD); - TransformationUtils.convertJson2RootProperties(context, recipeInput); - logger.info("Converted recipe ({}) request inputs to context.", recipeName); - } - } - - ServiceTemplateUtils serviceTemplateUtils = new ServiceTemplateUtils(); - serviceTemplateUtils.convertServiceTemplate2Properties(serviceTemplateContent, context); - } - return context; - - } - -} diff --git a/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/utils/ResourceAssignmentUtils.java b/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/utils/ResourceAssignmentUtils.java deleted file mode 100644 index 3cdf95c86..000000000 --- a/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/utils/ResourceAssignmentUtils.java +++ /dev/null @@ -1,302 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2018 IBM. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.ccsdk.config.model.utils; - -import java.util.Date; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; -import org.apache.commons.lang3.BooleanUtils; -import org.apache.commons.lang3.StringUtils; -import org.onap.ccsdk.config.model.ConfigModelConstant; -import org.onap.ccsdk.config.model.ConfigModelException; -import org.onap.ccsdk.config.model.ValidTypes; -import org.onap.ccsdk.config.model.data.ResourceAssignment; -import org.onap.ccsdk.config.model.data.dict.ResourceDefinition; -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; -import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.databind.node.ArrayNode; -import com.fasterxml.jackson.databind.node.NullNode; -import com.fasterxml.jackson.databind.node.ObjectNode; -import com.google.common.base.Preconditions; - -public class ResourceAssignmentUtils { - - private ResourceAssignmentUtils() { - - } - - private static EELFLogger logger = EELFManager.getInstance().getLogger(ResourceAssignmentUtils.class); - - public static String getArtifactNodeContent(String nodeTemplateName, Map context) { - Preconditions.checkArgument(StringUtils.isNotBlank(nodeTemplateName), - "getArtifactNodeContent missing template name"); - return (String) context.get(ConfigModelConstant.PROPERTY_NODE_TEMPLATES_DOT + nodeTemplateName + ".content"); - } - - public static List getArtifactNodeMapping(String nodeTemplateName, - Map context) { - Preconditions.checkArgument(StringUtils.isNotBlank(nodeTemplateName), - "getArtifactNodeMapping missing template name"); - List resourceAssignments = null; - String resourceMappingContent = - (String) context.get(ConfigModelConstant.PROPERTY_NODE_TEMPLATES_DOT + nodeTemplateName + ".mapping"); - if (StringUtils.isNotBlank(resourceMappingContent)) { - resourceAssignments = TransformationUtils.getListfromJson(resourceMappingContent, ResourceAssignment.class); - - } else { - logger.warn("missing mapping content for node template ({})", nodeTemplateName); - } - return resourceAssignments; - } - - // Not used Any whre - public static synchronized void cleanContextTemplateNDictionaryKeys(Map componentContext) { - String recipeName = (String) componentContext.get(ConfigModelConstant.PROPERTY_ACTION_NAME); - Set removeSet = new HashSet<>(); - componentContext.forEach((key, value) -> { - if (StringUtils.isNotBlank(key) - && (key.startsWith(ConfigModelConstant.PROPERTY_DICTIONARY_KEY_DOT + recipeName + ".") - || key.startsWith(ConfigModelConstant.PROPERTY_RECIPE_KEY_DOT + recipeName + "."))) { - removeSet.add(key); - } - }); - componentContext.keySet().removeAll(removeSet); - } - - public static synchronized Object getDictionaryKeyValue(Map componentContext, - ResourceAssignment resourceMapping) { - Object value = null; - if (resourceMapping != null && componentContext != null) { - String recipeName = (String) componentContext.get(ConfigModelConstant.PROPERTY_ACTION_NAME); - String dictionaryKeyName = resourceMapping.getDictionaryName(); - value = componentContext - .get(ConfigModelConstant.PROPERTY_DICTIONARY_KEY_DOT + recipeName + "." + dictionaryKeyName); - } - return value; - } - - public static synchronized Object getDictionaryKeyValue(Map componentContext, - ResourceDefinition resourceDictionary) { - Object value = null; - if (resourceDictionary != null && componentContext != null) { - String recipeName = (String) componentContext.get(ConfigModelConstant.PROPERTY_ACTION_NAME); - String dictionaryKeyName = resourceDictionary.getName(); - value = componentContext - .get(ConfigModelConstant.PROPERTY_DICTIONARY_KEY_DOT + recipeName + "." + dictionaryKeyName); - } - return value; - } - - public static synchronized Object getTemplateKeyValue(Map componentContext, - ResourceAssignment resourceMapping) { - Object value = null; - if (resourceMapping != null && componentContext != null) { - String recipeName = (String) componentContext.get(ConfigModelConstant.PROPERTY_ACTION_NAME); - String templateKeyName = resourceMapping.getName(); - value = componentContext - .get(ConfigModelConstant.PROPERTY_RECIPE_KEY_DOT + recipeName + "." + templateKeyName); - } - return value; - } - - public static synchronized void setResourceDataValue(Map componentContext, - ResourceAssignment resourceAssignment, Object value) throws ConfigModelException { - - if (resourceAssignment != null && StringUtils.isNotBlank(resourceAssignment.getName()) - && resourceAssignment.getProperty() != null) { - - String recipeName = (String) componentContext.get(ConfigModelConstant.PROPERTY_ACTION_NAME); - String templateKeyName = resourceAssignment.getName(); - String dictionaryKeyName = resourceAssignment.getDictionaryName(); - - if (StringUtils.isBlank(dictionaryKeyName)) { - resourceAssignment.setDictionaryName(templateKeyName); - dictionaryKeyName = templateKeyName; - logger.warn("Missing dictionary key, setting with template key ({}) as dictionary key ({})", - templateKeyName, dictionaryKeyName); - } - String type = resourceAssignment.getProperty().getType(); - try { - if (StringUtils.isNotBlank(type)) { - Object convertedValue = convertResourceValue(type, value); - - componentContext.put( - ConfigModelConstant.PROPERTY_DICTIONARY_KEY_DOT + recipeName + "." + dictionaryKeyName, - convertedValue); - componentContext.put( - ConfigModelConstant.PROPERTY_RECIPE_KEY_DOT + recipeName + "." + templateKeyName, - convertedValue); - - logger.trace("Setting Resource Value ({}) for Resource Name ({}) of type ({}) ", convertedValue, - dictionaryKeyName, type); - - resourceAssignment.getProperty().setValue(convertedValue); - resourceAssignment.setUpdatedDate(new Date()); - resourceAssignment.setUpdatedBy(ConfigModelConstant.USER_SYSTEM); - resourceAssignment.setStatus(ConfigModelConstant.STATUS_SUCCESS); - } - } catch (Exception e) { - throw new ConfigModelException(String.format( - "Failed in setting value for template key (%s) and dictionary key (%s) of type (%s) with error message (%s)", - templateKeyName, dictionaryKeyName, type, e.getMessage())); - } - } else { - throw new ConfigModelException( - String.format("Failed in setting resource value for resource mapping (%s)", resourceAssignment)); - } - } - - private static Object convertResourceValue(String type, Object value) { - Object convertedValue = null; - - if (value == null || value instanceof NullNode) { - logger.info("Returning {} value from convertResourceValue", value); - return null; - } - - if (ValidTypes.getPrimitivePropertType().contains(type)) { - convertedValue = convertPrimitiveResourceValue(type, value); - } else { - // Case where Resource is non-primitive type - if (value instanceof JsonNode || value instanceof ObjectNode || value instanceof ArrayNode) { - convertedValue = value; - } else if (value instanceof String) { - convertedValue = TransformationUtils.getJsonNodeForString((String) value); - } else { - convertedValue = TransformationUtils.getJsonNodeForObject(value); - } - } - return convertedValue; - } - - @SuppressWarnings("squid:S3776") - private static Object convertPrimitiveResourceValue(String type, Object value) { - Object convertedValue = value; - - if (value instanceof ArrayNode) { - if (ValidTypes.DATA_TYPE_BOOLEAN.equalsIgnoreCase(type)) { - convertedValue = ((ArrayNode) value).asBoolean(); - } else if (ValidTypes.DATA_TYPE_INTEGER.equalsIgnoreCase(type)) { - convertedValue = ((ArrayNode) value).asInt(); - } else if (ValidTypes.DATA_TYPE_FLOAT.equalsIgnoreCase(type)) { - convertedValue = Float.valueOf(((ArrayNode) value).toString()); - } else { - convertedValue = ((ArrayNode) value).toString(); - } - } else if (value instanceof JsonNode) { - if (ValidTypes.DATA_TYPE_BOOLEAN.equalsIgnoreCase(type)) { - convertedValue = ((JsonNode) value).asBoolean(); - } else if (ValidTypes.DATA_TYPE_INTEGER.equalsIgnoreCase(type)) { - convertedValue = ((JsonNode) value).asInt(); - } else if (ValidTypes.DATA_TYPE_FLOAT.equalsIgnoreCase(type)) { - convertedValue = Float.valueOf(((JsonNode) value).asText()); - } else { - convertedValue = ((JsonNode) value).asText(); - } - } else if (value instanceof String) { - if (ValidTypes.DATA_TYPE_BOOLEAN.equalsIgnoreCase(type)) { - convertedValue = Boolean.valueOf((String) value); - } else if (ValidTypes.DATA_TYPE_INTEGER.equalsIgnoreCase(type)) { - convertedValue = Integer.valueOf((String) value); - } else if (ValidTypes.DATA_TYPE_FLOAT.equalsIgnoreCase(type)) { - convertedValue = Float.valueOf((String) value); - } - } - logger.info("Returning value ({}) from convertPrimitiveResourceValue", convertedValue); - return convertedValue; - } - - @SuppressWarnings("squid:S1172") - public static synchronized void setFailedResourceDataValue(Map componentContext, - ResourceAssignment resourceAssignment, String message) { - setFailedResourceDataValue(resourceAssignment, message); - } - - public static synchronized void setFailedResourceDataValue(ResourceAssignment resourceAssignment, String message) { - if (resourceAssignment != null && StringUtils.isNotBlank(resourceAssignment.getName()) - && resourceAssignment.getProperty() != null) { - resourceAssignment.setUpdatedDate(new Date()); - resourceAssignment.setStatus(ConfigModelConstant.STATUS_FAILURE); - resourceAssignment.setUpdatedBy(ConfigModelConstant.USER_SYSTEM); - resourceAssignment.setMessage(message); - } - } - - public static synchronized void assertTemplateKeyValueNotNull(Map componentContext, - ResourceAssignment resourceAssignment) throws ConfigModelException { - if (resourceAssignment != null && resourceAssignment.getProperty() != null - && BooleanUtils.isTrue(resourceAssignment.getProperty().getRequired()) - && getTemplateKeyValue(componentContext, resourceAssignment) == null) { - logger.error("failed to populate mandatory resource mapping ({})", resourceAssignment); - throw new ConfigModelException( - String.format("failed to populate mandatory resource mapping (%s)", resourceAssignment)); - } - } - - @SuppressWarnings({"squid:S3776", "squid:S1141"}) - public static synchronized String generateResourceDataForAssignments(List assignments) - throws ConfigModelException { - String result = "{}"; - try { - ObjectMapper mapper = new ObjectMapper(); - JsonNode root = mapper.readTree(result); - for (ResourceAssignment resourceMapping : assignments) { - if (resourceMapping != null && resourceMapping.getName() != null - && resourceMapping.getProperty() != null) { - - String type = resourceMapping.getProperty().getType(); - Object value = resourceMapping.getProperty().getValue(); - logger.info("Generating Resource name ({}), type ({}), value ({})", resourceMapping.getName(), type, - value); - if (value == null) { - ((ObjectNode) root).set(resourceMapping.getName(), null); - } else if (value instanceof JsonNode) { - ((ObjectNode) root).put(resourceMapping.getName(), (JsonNode) value); - } else if (ValidTypes.DATA_TYPE_STRING.equalsIgnoreCase(type)) { - ((ObjectNode) root).put(resourceMapping.getName(), (String) value); - } else if (ValidTypes.DATA_TYPE_BOOLEAN.equalsIgnoreCase(type)) { - ((ObjectNode) root).put(resourceMapping.getName(), (Boolean) value); - } else if (ValidTypes.DATA_TYPE_INTEGER.equalsIgnoreCase(type)) { - ((ObjectNode) root).put(resourceMapping.getName(), (Integer) value); - } else if (ValidTypes.DATA_TYPE_FLOAT.equalsIgnoreCase(type)) { - ((ObjectNode) root).put(resourceMapping.getName(), (Float) value); - } else if (ValidTypes.DATA_TYPE_TIMESTAMP.equalsIgnoreCase(type)) { - ((ObjectNode) root).put(resourceMapping.getName(), (String) value); - } else { - JsonNode jsonNode = TransformationUtils.getJsonNodeForObject(value); - if (jsonNode != null) { - ((ObjectNode) root).put(resourceMapping.getName(), jsonNode); - } else { - ((ObjectNode) root).set(resourceMapping.getName(), null); - } - } - } - } - result = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(root); - logger.info("Generated Resource Param Data ({})", result); - } catch (Exception e) { - throw new ConfigModelException(e.getMessage(), e); - } - return result; - } - -} diff --git a/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/utils/ResourceDictionaryUtils.java b/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/utils/ResourceDictionaryUtils.java deleted file mode 100644 index fccf86534..000000000 --- a/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/utils/ResourceDictionaryUtils.java +++ /dev/null @@ -1,119 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2018 IBM. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.ccsdk.config.model.utils; - -import java.util.Map; -import java.util.Optional; -import java.util.function.Supplier; -import org.apache.commons.collections.CollectionUtils; -import org.apache.commons.collections.MapUtils; -import org.apache.commons.lang3.StringUtils; -import org.onap.ccsdk.config.model.ConfigModelConstant; -import org.onap.ccsdk.config.model.data.PropertyDefinition; -import org.onap.ccsdk.config.model.data.ResourceAssignment; -import org.onap.ccsdk.config.model.data.dict.ResourceDefinition; -import org.onap.ccsdk.config.model.data.dict.SourcesDefinition; -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; - -/** - * ResourceDictionaryUtils.java Purpose to provide ResourceDictionaryUtils - * - * @version 1.0 - */ -public class ResourceDictionaryUtils { - - private ResourceDictionaryUtils() { - // Do nothing - } - - private static EELFLogger logger = EELFManager.getInstance().getLogger(ResourceDictionaryUtils.class); - - /** - * This Method is to assign the source name to the Dictionary Definition Check to see if the source - * definition is not present then assign, if more than one source then assign only one source. - * - * @param resourceAssignment - * @param resourceDefinition - */ - @SuppressWarnings("squid:S3776") - public static void populateSourceMapping(ResourceAssignment resourceAssignment, - ResourceDefinition resourceDefinition) { - - if (resourceAssignment != null && resourceDefinition != null - && StringUtils.isBlank(resourceAssignment.getDictionarySource())) { - - setProperty(resourceAssignment, resourceDefinition); - Map sourcesDefinition = resourceDefinition.getSources(); - - if (sourcesDefinition != null && MapUtils.isNotEmpty(sourcesDefinition) && sourcesDefinition.size() == 1) { - if (sourcesDefinition.get("input") != null) { - resourceAssignment.setDictionarySource(ConfigModelConstant.SOURCE_INPUT); - } else if (sourcesDefinition.get("default") != null) { - resourceAssignment.setDictionarySource(ConfigModelConstant.SOURCE_DEFAULT); - } else if (sourcesDefinition.get("db") != null) { - resourceAssignment.setDictionarySource(ConfigModelConstant.SOURCE_DB); - if (resolve(() -> sourcesDefinition.get("db").getProperties().getDependencies()).isPresent() - && CollectionUtils - .isNotEmpty(sourcesDefinition.get("db").getProperties().getDependencies())) { - resourceAssignment - .setDependencies(sourcesDefinition.get("db").getProperties().getDependencies()); - } - } else if (sourcesDefinition.get("mdsal") != null) { - resourceAssignment.setDictionarySource(ConfigModelConstant.SOURCE_MDSAL); - if (resolve(() -> sourcesDefinition.get("mdsal").getProperties().getDependencies()).isPresent() - && CollectionUtils - .isNotEmpty(sourcesDefinition.get("mdsal").getProperties().getDependencies())) { - resourceAssignment - .setDependencies(sourcesDefinition.get("mdsal").getProperties().getDependencies()); - } - } - logger.info("automapped resourceAssignment : {}", resourceAssignment); - } - } - } - - public static Optional resolve(Supplier resolver) { - try { - T result = resolver.get(); - return Optional.ofNullable(result); - } catch (NullPointerException e) { - return Optional.empty(); - } - } - - /** - * Overriding ResourceAssignment Properties with properties defined in Dictionary - */ - private static void setProperty(ResourceAssignment resourceAssignment, ResourceDefinition resourceDefinition) { - if (StringUtils.isNotBlank(resourceDefinition.getProperty().getType())) { - PropertyDefinition property = resourceAssignment.getProperty(); - if (property == null) { - property = new PropertyDefinition(); - } - if (resourceDefinition.getProperty() != null) { - property.setType(resourceDefinition.getProperty().getType()); - if (resourceDefinition.getProperty().getEntrySchema() != null) { - property.setEntrySchema(resourceDefinition.getProperty().getEntrySchema()); - } - resourceAssignment.setProperty(property); - } - } - } - -} diff --git a/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/utils/ServiceTemplateUtils.java b/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/utils/ServiceTemplateUtils.java deleted file mode 100644 index c60d624c1..000000000 --- a/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/utils/ServiceTemplateUtils.java +++ /dev/null @@ -1,277 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2018 IBM. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.ccsdk.config.model.utils; - -import java.util.Map; -import org.apache.commons.collections.MapUtils; -import org.apache.commons.lang3.StringUtils; -import org.onap.ccsdk.config.model.ConfigModelConstant; -import org.onap.ccsdk.config.model.data.InterfaceAssignment; -import org.onap.ccsdk.config.model.data.InterfaceDefinition; -import org.onap.ccsdk.config.model.data.NodeTemplate; -import org.onap.ccsdk.config.model.data.NodeType; -import org.onap.ccsdk.config.model.data.OperationAssignment; -import org.onap.ccsdk.config.model.data.OperationDefinition; -import org.onap.ccsdk.config.model.data.ServiceTemplate; -import org.onap.ccsdk.config.model.data.TopologyTemplate; -import org.onap.ccsdk.sli.core.sli.SvcLogicContext; -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; - -public class ServiceTemplateUtils { - private static EELFLogger logger = EELFManager.getInstance().getLogger(ServiceTemplateUtils.class); - - public Map convertServiceTemplate2Properties(String serviceTemplateContent, - final Map context) { - if (StringUtils.isNotBlank(serviceTemplateContent)) { - ServiceTemplate serviceTemplate = - TransformationUtils.readValue(serviceTemplateContent, ServiceTemplate.class); - convertServiceTemplate2Properties(serviceTemplate, context); - } - return context; - } - - public Map convertServiceTemplate2Properties(ServiceTemplate serviceTemplate, - final Map context) { - if (serviceTemplate != null) { - convertServiceTemplateMetadata2Properties(serviceTemplate, context); - convertServiceTemplateInputs2Properties(serviceTemplate, context); - convertDataTypes2Properties(serviceTemplate, context); - convertNode2Properties(serviceTemplate, context); - } - return context; - } - - public Map convertServiceTemplateMetadata2Properties(ServiceTemplate serviceTemplate, - final Map context) { - - if (serviceTemplate != null && serviceTemplate.getMetadata() != null) { - serviceTemplate.getMetadata().forEach((metaDataKey, metadata) -> { - context.put(metaDataKey, metadata); - }); - } - return context; - } - - public Map convertServiceTemplateInputs2Properties(ServiceTemplate serviceTemplate, - final Map context) { - - if (serviceTemplate != null && serviceTemplate.getTopologyTemplate() != null - && serviceTemplate.getTopologyTemplate().getInputs() != null) { - - serviceTemplate.getTopologyTemplate().getInputs().forEach((paramKey, parameterDefinition) -> { - if (parameterDefinition != null) { - context.put(ConfigModelConstant.PROPERTY_INPUTS_DOT + paramKey + ".type", - parameterDefinition.getType()); - if (parameterDefinition.getRequired()) { - context.put(ConfigModelConstant.PROPERTY_INPUTS_DOT + paramKey + ".required", - String.valueOf(parameterDefinition.getRequired())); - } - if (parameterDefinition.getDefaultValue() != null) { - context.put(ConfigModelConstant.PROPERTY_INPUTS_DOT + paramKey + ".default", - String.valueOf(parameterDefinition.getDefaultValue())); - } - } - }); - } - return context; - } - - public Map convertDataTypes2Properties(ServiceTemplate serviceTemplate, - final Map context) { - if (serviceTemplate != null && serviceTemplate.getDataTypes() != null) { - serviceTemplate.getDataTypes().forEach((dataTypeKey, dataType) -> { - logger.trace("Populating Data Type Key : ({})", dataTypeKey); - String dataTypeContent = TransformationUtils.getJson(dataType); - context.put("data_types." + dataTypeKey, dataTypeContent); - }); - } - return context; - } - - public Map convertNode2Properties(ServiceTemplate serviceTemplate, - final Map context) { - - if (serviceTemplate != null && serviceTemplate.getNodeTypes() != null - && serviceTemplate.getTopologyTemplate() != null - && serviceTemplate.getTopologyTemplate().getNodeTemplates() != null) { - - serviceTemplate.getTopologyTemplate().getNodeTemplates().forEach((nodeTemplateKey, nodeTemplate) -> { - if (nodeTemplate != null && StringUtils.isNotBlank(nodeTemplate.getType())) { - String nodeTypeKey = nodeTemplate.getType(); - logger.trace("Populating Node Type Key : ({}) for Node Template : ({})", nodeTypeKey, - nodeTemplateKey); - String nodeTemplateContent = TransformationUtils.getJson(nodeTemplate); - context.put("node_templates." + nodeTemplateKey, nodeTemplateContent); - if (serviceTemplate.getNodeTypes().containsKey(nodeTypeKey)) { - NodeType nodeType = serviceTemplate.getNodeTypes().get(nodeTypeKey); - String nodeTypeContent = TransformationUtils.getJson(nodeType); - context.put("node_types." + nodeTypeKey, nodeTypeContent); - String nodeDerivedFrom = nodeType.getDerivedFrom(); - if (ConfigModelConstant.MODEL_TYPE_NODE_DG.equalsIgnoreCase(nodeDerivedFrom)) { - populateDGNodeProperties(nodeTemplateKey, nodeTemplate, context, nodeDerivedFrom); - } - } - // Populate the Artifact Definitions - populateNodeTemplateArtifacts(nodeTemplateKey, nodeTemplate, context); - } - }); - } - return context; - } - - @SuppressWarnings("squid:S1172") - public Map populateVnfNodeProperties(String nodeTemplateKey, NodeTemplate nodeTemplate, - final Map context, String nodeDerivedFrom) { - if (nodeTemplate != null && nodeTemplate.getCapabilities() != null) { - nodeTemplate.getCapabilities().forEach((capabilityKey, capability) -> { - capability.getProperties().forEach((propertyKey, property) -> { - context.put(nodeTemplateKey + "." + capabilityKey + "." + propertyKey, String.valueOf(property)); - }); - }); - } - - return context; - } - - public Map populateNodeTemplateArtifacts(String nodeTemplateKey, NodeTemplate nodeTemplate, - final Map context) { - if (MapUtils.isNotEmpty(nodeTemplate.getArtifacts())) { - nodeTemplate.getArtifacts().forEach((artifactName, artifact) -> { - if (StringUtils.isNotBlank(artifactName) && artifact != null) { - logger.trace("Populating Node Template Artifacts ({}) for Node Template ({})", artifactName, - nodeTemplateKey); - String fileKeyName = ConfigModelConstant.PROPERTY_NODE_TEMPLATES_DOT + nodeTemplateKey + "." - + ConfigModelConstant.PROPERTY_ARTIFACTS_DOT + artifactName + ".file"; - String deployKeyName = ConfigModelConstant.PROPERTY_NODE_TEMPLATES_DOT + nodeTemplateKey + "." - + ConfigModelConstant.PROPERTY_ARTIFACTS_DOT + artifactName + ".deploy_path"; - String contentKeyName = ConfigModelConstant.PROPERTY_NODE_TEMPLATES_DOT + nodeTemplateKey + "." - + ConfigModelConstant.PROPERTY_ARTIFACTS_DOT + artifactName + ".content"; - context.put(fileKeyName, artifact.getFile()); - context.put(deployKeyName, artifact.getDeployPath()); - context.put(contentKeyName, artifact.getContent()); - } - }); - } - return context; - } - - public Map populateDGNodeProperties(String nodeTemplateKey, NodeTemplate nodeTemplate, - final Map context, String nodeDerivedFrom) { - if (nodeTemplate != null && nodeTemplate.getInterfaces() != null) { - - if (nodeTemplate.getProperties() != null) { - nodeTemplate.getProperties().forEach((propKey, propValue) -> { - if (propKey != null && propValue != null) { - context.put("dg." + nodeTemplateKey + "." + propKey, String.valueOf(propValue)); - } - }); - } - - nodeTemplate.getInterfaces().forEach((interfaceKey, interfaceDefinition) -> { - - interfaceDefinition.getOperations().forEach((operationKey, operation) -> { - if (ConfigModelConstant.MODEL_TYPE_NODE_DG.equalsIgnoreCase(nodeDerivedFrom)) { - context.put("dg." + nodeTemplateKey + ".module", interfaceKey); - context.put("dg." + nodeTemplateKey + ".flow", operationKey); - } - }); - }); - } - return context; - } - - public SvcLogicContext getInterfaceOpertationDefinition(ServiceTemplate serviceTemplate, - final SvcLogicContext context) { - - if (serviceTemplate != null && serviceTemplate.getNodeTypes() != null - && serviceTemplate.getTopologyTemplate() != null - && serviceTemplate.getTopologyTemplate().getNodeTemplates() != null) { - - TopologyTemplate topologyTemplates = serviceTemplate.getTopologyTemplate(); - // Copy Definition to Template - copyNodeType2Template(serviceTemplate.getNodeTypes(), topologyTemplates.getNodeTemplates()); - - topologyTemplates.getNodeTemplates().forEach((templateKey, nodeTemplate) -> { - - if (StringUtils.isNotBlank(templateKey) && nodeTemplate != null - && nodeTemplate.getInterfaces() != null) { - - nodeTemplate.getInterfaces().forEach((interfaceKey, interfaceDefinition) -> { - if (StringUtils.isNotBlank(interfaceKey) && interfaceDefinition != null) { - interfaceDefinition.getOperations().forEach((operationKey, operation) -> { - String definitionKey = interfaceKey + "." + operationKey; - String definitionContent = TransformationUtils.getJson(operation); - context.setAttribute(definitionKey, definitionContent); - // Set the Operation & Method Params - }); - } - }); - } - }); - } - return context; - } - - public void copyNodeType2Template(Map nodeTypes, Map nodeTemplates) { - if (nodeTypes != null && nodeTemplates != null) { - - nodeTemplates.forEach((templateKey, nodeTemplate) -> { - if (StringUtils.isNotBlank(templateKey) && nodeTemplate != null) { - String type = nodeTemplate.getType(); - // Check the Node Template Type is Present - if (StringUtils.isNotBlank(type) && nodeTypes.containsKey(type)) { - NodeType nodeType = nodeTypes.get(type); - logger.trace("Checking Node Type Content : ({})", TransformationUtils.getJson(nodeType)); - copyNodeTypeInterface2Template(nodeType.getInterfaces(), nodeTemplate.getInterfaces()); - } - } - }); - } - } - - public void copyNodeTypeInterface2Template(Map nodeTypeInterfaces, - Map nodeTemplateInterfaces) { - if (nodeTypeInterfaces != null && nodeTemplateInterfaces != null) { - - nodeTemplateInterfaces.forEach((interfaceKey, nodeTemplateinterface) -> { - InterfaceDefinition nodeTypeInterface = nodeTypeInterfaces.get(interfaceKey); - logger.trace("Checking Interface Type Content : ({})", TransformationUtils.getJson(nodeTypeInterface)); - if (nodeTypeInterface != null && nodeTemplateinterface != null) { - copyNodeTypeOperation2Template(nodeTypeInterface.getOperations(), - nodeTemplateinterface.getOperations()); - } - }); - } - } - - public void copyNodeTypeOperation2Template(Map nodeTypeOperations, - Map nodeTemplateOperations) { - if (nodeTypeOperations != null && nodeTemplateOperations != null) { - - nodeTemplateOperations.forEach((operationKey, nodeTemplateOperation) -> { - OperationDefinition nodeTypeInterfaceOperation = nodeTypeOperations.get(operationKey); - if (nodeTypeInterfaceOperation != null && nodeTemplateOperation != null) { - logger.info("Checking Operation Type Content : " + operationKey + " : " - + TransformationUtils.getJson(nodeTypeInterfaceOperation)); - } - }); - } - } - -} diff --git a/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/utils/TopologicalSortingUtils.java b/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/utils/TopologicalSortingUtils.java deleted file mode 100644 index 8aa4a454a..000000000 --- a/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/utils/TopologicalSortingUtils.java +++ /dev/null @@ -1,188 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2018 IBM. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.ccsdk.config.model.utils; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; -import java.util.Queue; -import java.util.Stack; - -public class TopologicalSortingUtils { - - /** - * The implementation here is basically an adjacency list, but instead of an array of lists, a Map - * is used to map each vertex to its list of adjacent vertices. - */ - private Map> neighbors = new HashMap<>(); - - /** - * String representation of graph. - */ - @Override - public String toString() { - StringBuilder s = new StringBuilder(); - neighbors.forEach((v, vs) -> s.append("\n " + v + " -> " + vs)); - return s.toString(); - } - - public Map> getNeighbors() { - return neighbors; - } - - /** - * Add a vertex to the graph. Nothing happens if vertex is already in graph. - */ - public void add(V vertex) { - if (neighbors.containsKey(vertex)) - return; - neighbors.put(vertex, new ArrayList()); - } - - /** - * True iff graph contains vertex. - */ - public boolean contains(V vertex) { - return neighbors.containsKey(vertex); - } - - /** - * Add an edge to the graph; if either vertex does not exist, it's added. This implementation allows - * the creation of multi-edges and self-loops. - */ - public void add(V from, V to) { - this.add(from); - this.add(to); - neighbors.get(from).add(to); - } - - /** - * Remove an edge from the graph. Nothing happens if no such edge. - * - * @throws IllegalArgumentException if either vertex doesn't exist. - */ - public void remove(V from, V to) { - if (!(this.contains(from) && this.contains(to))) - throw new IllegalArgumentException("Nonexistent vertex"); - neighbors.get(from).remove(to); - } - - /** - * Report (as a Map) the out-degree of each vertex. - */ - public Map outDegree() { - Map result = new HashMap<>(); - neighbors.forEach((v, vs) -> result.put(v, vs.size())); - return result; - } - - /** - * Report (as a Map) the in-degree of each vertex. - */ - public Map inDegree() { - Map result = new HashMap<>(); - for (V v : neighbors.keySet()) - result.put(v, 0); // All in-degrees are 0 - - neighbors.forEach((from, vs) -> vs.forEach(to -> result.put(to, result.get(to) + 1) // Increment in-degree - )); - - return result; - } - - /** - * Report (as a List) the topological sort of the vertices; null for no such sort. - */ - @SuppressWarnings({"squid:S1149", "squid:S1168"}) - public List topSort() { - Map degree = inDegree(); - // Determine all vertices with zero in-degree - Stack zeroVerts = new Stack<>(); // Stack as good as any here - - degree.forEach((v, vs) -> { - if (vs == 0) - zeroVerts.push(v); - }); - - // Determine the topological order - List result = new ArrayList<>(); - while (!zeroVerts.isEmpty()) { - V v = zeroVerts.pop(); // Choose a vertex with zero in-degree - result.add(v); // Vertex v is next in topol order - // "Remove" vertex v by updating its neighbors - for (V neighbor : neighbors.get(v)) { - degree.put(neighbor, degree.get(neighbor) - 1); - // Remember any vertices that now have zero in-degree - if (degree.get(neighbor) == 0) - zeroVerts.push(neighbor); - } - } - // Check that we have used the entire graph (if not, there was a cycle) - if (result.size() != neighbors.size()) - return null; - return result; - } - - /** - * True iff graph is a dag (directed acyclic graph). - */ - public boolean isDag() { - return topSort() != null; - } - - /** - * Report (as a Map) the bfs distance to each vertex from the start vertex. The distance is an - * Integer; the value null is used to represent infinity (implying that the corresponding node - * cannot be reached). - */ - public Map bfsDistance(V start) { - Map distance = new HashMap<>(); - // Initially, all distance are infinity, except start node - for (V v : neighbors.keySet()) - distance.put(v, null); - distance.put(start, 0); - // Process nodes in queue order - Queue queue = new LinkedList<>(); - queue.offer(start); // Place start node in queue - while (!queue.isEmpty()) { - V v = queue.remove(); - int vDist = distance.get(v); - // Update neighbors - for (V neighbor : neighbors.get(v)) { - if (distance.get(neighbor) != null) - continue; // Ignore if already done - distance.put(neighbor, vDist + 1); - queue.offer(neighbor); - } - } - return distance; - } - - /** - * Main program (for testing). public static void main (String[] args) { // Create a Graph with - * Integer nodes TopologicalSortingUtils graph = new TopologicalSortingUtils(); - * graph.add("bundle-id", "bundle-mac"); graph.add("bundle-id", "bundle-ip"); - * graph.add("bundle-mac", "bundle-ip"); graph.add("bundle-ip", "bundle-mac"); - * System.out.println("The current graph: " + graph); System.out.println("In-degrees: " + - * graph.inDegree()); System.out.println("Out-degrees: " + graph.outDegree()); System.out.println("A - * topological sort of the vertices: " + graph.topSort()); System.out.println("The graph " + - * (graph.isDag()?"is":"is not") + " a dag"); } - */ -} diff --git a/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/utils/TransformationUtils.java b/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/utils/TransformationUtils.java deleted file mode 100644 index 311be9db7..000000000 --- a/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/utils/TransformationUtils.java +++ /dev/null @@ -1,429 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2018 IBM. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.ccsdk.config.model.utils; - -import java.io.IOException; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Properties; -import java.util.TreeMap; -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; -import com.fasterxml.jackson.annotation.JsonInclude.Include; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.core.type.TypeReference; -import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.databind.SerializationFeature; -import com.fasterxml.jackson.databind.node.ArrayNode; -import com.fasterxml.jackson.databind.type.CollectionType; -import com.fasterxml.jackson.module.jsonSchema.JsonSchema; -import com.fasterxml.jackson.module.jsonSchema.JsonSchemaGenerator; - -/** - * TransformationUtils.java Purpose: Provide Configuration Generator TransformationUtils Information - * - * @version 1.0 - */ -public class TransformationUtils { - - private static EELFLogger logger = EELFManager.getInstance().getLogger(TransformationUtils.class); - - private TransformationUtils() { - - } - - /** - * This is a getJson method - * - * @param configparameters - * @return String - */ - public static String getJson(Map configparameters) { - String jsonContent = null; - try { - ObjectMapper mapper = new ObjectMapper(); - jsonContent = mapper.writeValueAsString(configparameters); - } catch (JsonProcessingException e) { - logger.warn(e.getMessage()); - } - return jsonContent; - } - - /** - * This is a getJsonNode method - * - * @param configparameters - * @return String - */ - public static JsonNode getJsonNode(Map configparameters) { - JsonNode jsonContent = null; - try { - ObjectMapper mapper = new ObjectMapper(); - jsonContent = mapper.valueToTree(configparameters); - } catch (Exception e) { - logger.warn(e.getMessage()); - } - return jsonContent; - } - - /** - * This is a getJson method - * - * @param instance - * @param pretty - * @return Map - */ - public static String getJson(Object instance, boolean pretty) { - try { - ObjectMapper mapper = new ObjectMapper(); - mapper.setSerializationInclusion(Include.NON_NULL); - if (pretty) { - mapper.enable(SerializationFeature.INDENT_OUTPUT); - } - return mapper.writeValueAsString(instance); - } catch (JsonProcessingException e) { - logger.warn(e.getMessage()); - } - return null; - } - - /** - * This is a getJson method - * - * @param instance - * @return String - */ - public static String getJson(Object instance) { - return getJson(instance, false); - } - - /** - * This is a getJsonNodeForobject method - * - * @param instance - * @return JsonNode - */ - public static JsonNode getJsonNodeForObject(Object instance) { - try { - ObjectMapper mapper = new ObjectMapper(); - mapper.setSerializationInclusion(Include.NON_NULL); - return mapper.convertValue(instance, JsonNode.class); - } catch (Exception e) { - logger.warn(e.getMessage()); - } - return null; - } - - /** - * This is a getJsonNodeForString method - * - * @param content - * @return JsonNode - */ - public static JsonNode getJsonNodeForString(String content) { - try { - ObjectMapper mapper = new ObjectMapper(); - mapper.setSerializationInclusion(Include.NON_NULL); - return mapper.readTree(content); - } catch (Exception e) { - logger.warn(e.getMessage()); - } - return null; - } - - /** - * This is a getMapfromJson method - * - * @param content - * @return Map - */ - public static Map getMapfromJson(String content) { - try { - ObjectMapper mapper = new ObjectMapper(); - return mapper.readValue(content, new TypeReference>() {}); - } catch (Exception e) { - logger.warn("failed in getMapfromJson for the content ({}) with error message ({}).", content, - e.getMessage()); - } - return null; - } - - /** - * This is a getMapfromJson method - * - * @param content - * @return Map - */ - public static Map getMapfromJsonString(String content) { - try { - ObjectMapper mapper = new ObjectMapper(); - return mapper.readValue(content, new TypeReference>() {}); - } catch (Exception e) { - logger.warn("failed in getMapfromJson for the content ({}) with error message ({}).", content, - e.getMessage()); - } - return null; - } - - /** - * This is a getListfromJson method - * - * @param content - * @return Map - */ - @SuppressWarnings("squid:S1168") - public static List getListfromJson(String content, Class valueType) { - try { - ObjectMapper mapper = new ObjectMapper(); - CollectionType javaType = mapper.getTypeFactory().constructCollectionType(List.class, valueType); - return mapper.readValue(content, javaType); - } catch (Exception e) { - logger.warn("failed in getListfromJson for the content ({}) with error message ({}).", content, - e.getMessage()); - } - return null; - } - - /** - * This is a getJsonSchema method - * - * @param valueType - * @return String - */ - public static String getJsonSchema(Class clazz) { - try { - ObjectMapper mapper = new ObjectMapper(); - JsonSchemaGenerator schemaGen = new JsonSchemaGenerator(mapper); - JsonSchema schema = schemaGen.generateSchema(clazz); - return mapper.writerWithDefaultPrettyPrinter().writeValueAsString(schema); - - } catch (Exception e) { - logger.warn("failed in getJsonSchema with error message ({}).", e.getMessage()); - } - return null; - } - - /** - * This is a readValue method - * - * @param content - * @param valueType - * @return - */ - - public static T readValue(String content, Class valueType) { - try { - ObjectMapper mapper = new ObjectMapper(); - return mapper.readValue(content, valueType); - } catch (Exception e) { - logger.warn("failed in readValue for the content ({}) with error message ({}).", content, e.getMessage()); - } - return null; - } - - /** - * @param node - * @param valueType - * @param - * @return - */ - public static T treeToValue(JsonNode node, Class valueType) { - try { - ObjectMapper mapper = new ObjectMapper(); - return mapper.treeToValue(node, valueType); - } catch (Exception e) { - logger.warn("failed in readValue for the content ({}) with error message ({}).", node, e.getMessage()); - } - return null; - } - - /** - * @param node - * @param valueType - * @param - * @return List - */ - public static List treeToListValue(JsonNode node, Class valueType) { - List resultList = new ArrayList<>(); - if (node instanceof ArrayNode) { - for (JsonNode subnode : node) { - if (subnode != null) { - resultList.add(treeToValue(subnode, valueType)); - } - } - } - return resultList; - } - - /** - * This is a removeJsonNullNode method - * - * @param node - */ - public static void removeJsonNullNode(JsonNode node) { - Iterator it = node.iterator(); - while (it.hasNext()) { - JsonNode child = it.next(); - if (child.isNull()) { - it.remove(); - } else { - removeJsonNullNode(child); - } - } - } - - public static void printProperty(Properties property) { - if (property != null) { - Map sortedMap = new TreeMap(property); - StringBuilder buffer = new StringBuilder(); - sortedMap.entrySet().forEach(message -> { - buffer.append("\n" + message.toString()); - }); - logger.debug("Property : ({})", buffer); - } - } - - public static void printMap(Map map) { - if (map != null) { - Map sortedMap = new TreeMap(map); - StringBuilder buffer = new StringBuilder(); - sortedMap.entrySet().forEach(message -> { - buffer.append("\n" + message.toString()); - }); - logger.debug("Map: ({})", buffer); - } - } - - @SuppressWarnings("squid:S00112") - public static Map convertJson2RootProperties(Map context, String jsonContent) - throws Exception { - if (context == null) { - context = new HashMap<>(); - } - - ObjectMapper mapper = new ObjectMapper(); - JsonNode rootArray = mapper.readTree(jsonContent); - return convertJson2RootProperties(context, rootArray); - } - - public static Map convertJson2RootProperties(Map context, JsonNode rootArray) { - Map sortedMap = null; - - if (context == null) { - context = new HashMap<>(); - } - if (rootArray != null) { - Iterator> fields = rootArray.fields(); - while (fields.hasNext()) { - Map.Entry entry = fields.next(); - if (entry != null && entry.getValue() != null) { - if (entry.getValue().isTextual()) { - context.put(entry.getKey(), entry.getValue().textValue()); - } else { - context.put(entry.getKey(), entry.getValue().toString()); - } - } - } - } - sortedMap = new TreeMap<>(context); - return sortedMap; - } - - @SuppressWarnings("squid:S00112") - public static Map convertJson2Properties(Map context, String jsonContent, - List blockKeys) throws Exception { - Map sortedMap = null; - - if (context == null) { - context = new HashMap<>(); - } - - ObjectMapper mapper = new ObjectMapper(); - JsonNode rootArray = mapper.readTree(jsonContent); - - if (rootArray != null) { - Iterator> fields = rootArray.fields(); - while (fields.hasNext()) { - Map.Entry entry = fields.next(); - processJsonNode(context, blockKeys, entry.getKey(), entry.getValue()); - } - } - sortedMap = new TreeMap<>(context); - return sortedMap; - } - - public static Map convertJson2Properties(Map context, JsonNode rootArray, - List blockKeys) throws IOException { - Map sortedMap = null; - - if (context == null) { - context = new HashMap<>(); - } - - if (blockKeys == null) { - blockKeys = new ArrayList<>(); - } - - if (rootArray != null) { - Iterator> fields = rootArray.fields(); - while (fields.hasNext()) { - Map.Entry entry = fields.next(); - processJsonNode(context, blockKeys, entry.getKey(), entry.getValue()); - } - } - sortedMap = new TreeMap<>(context); - return sortedMap; - } - - private static void processJsonNode(Map propertyMap, List blockKeys, String nodeName, - JsonNode node) throws IOException { - - logger.trace("Block Key ({})", nodeName); - if (node == null) { - return; - } - - String keyName = null; - if (blockKeys != null && blockKeys.contains(nodeName)) { - if (node.isArray() || node.isObject()) { - propertyMap.put(nodeName, node.toString()); - } else { - propertyMap.put(nodeName, node.asText()); - } - } else if (node.isArray()) { - for (int i = 0; i < node.size(); i++) { - keyName = nodeName + "[" + i + "]"; - processJsonNode(propertyMap, blockKeys, keyName, node.get(i)); - } - } else if (node.isObject()) { - Iterator> fields = node.fields(); - while (fields.hasNext()) { - Map.Entry entry = fields.next(); - keyName = nodeName + "." + entry.getKey(); - processJsonNode(propertyMap, blockKeys, keyName, entry.getValue()); - } - } else { - propertyMap.put(nodeName, node.asText()); - } - } - -} diff --git a/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/validator/DataTypeValidator.java b/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/validator/DataTypeValidator.java deleted file mode 100644 index c603040a3..000000000 --- a/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/validator/DataTypeValidator.java +++ /dev/null @@ -1,109 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2018 IBM. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.ccsdk.config.model.validator; - -import java.util.HashMap; -import java.util.Map; -import org.apache.commons.lang3.StringUtils; -import org.onap.ccsdk.config.model.ConfigModelException; -import org.onap.ccsdk.config.model.ValidTypes; -import org.onap.ccsdk.config.model.data.DataType; -import org.onap.ccsdk.config.model.data.PropertyDefinition; -import org.onap.ccsdk.config.model.data.ServiceTemplate; - -/** - * DataTypeValidator.java Purpose: Provide Configuration Generator DataTypeValidator - * - * @version 1.0 - */ -public class DataTypeValidator { - - private StringBuilder message; - private Map stDataTypes; - private ServiceTemplate serviceTemplate; - private PropertyDefinitionValidator propertyDefinitionValidator; - - /** - * This is a DataTypeValidator - * - * @param serviceTemplate - * @throws ConfigModelException - */ - public DataTypeValidator(ServiceTemplate serviceTemplate, StringBuilder message) throws ConfigModelException { - this.serviceTemplate = serviceTemplate; - this.message = message; - propertyDefinitionValidator = new PropertyDefinitionValidator(this.message); - stDataTypes = new HashMap<>(); - loadInitial(); - - } - - private void loadInitial() { - if (serviceTemplate != null && serviceTemplate.getDataTypes() != null) { - message.append("\n DataTypes" + serviceTemplate.getDataTypes()); - serviceTemplate.getDataTypes().forEach((dataTypeKey, dataType) -> { - stDataTypes.put(dataTypeKey, dataType); - message.append("\n Data Type (" + dataTypeKey + ") loaded successfully."); - }); - } - } - - /** - * This is a validateDataTypes - * - * @return boolean - * @throws ConfigModelException - */ - @SuppressWarnings("squid:S00112") - public boolean validateDataTypes() { - if (serviceTemplate != null && serviceTemplate.getDataTypes() != null) { - - serviceTemplate.getDataTypes().forEach((dataTypeKey, dataType) -> { - if (dataType != null) { - try { - String derivedFrom = dataType.getDerivedFrom(); - checkValidDerivedType(dataTypeKey, derivedFrom); - checkValidProperties(dataTypeKey, dataType.getProperties()); - } catch (ConfigModelException e) { - throw new RuntimeException(e); - } - - } - - }); - } - return true; - } - - private boolean checkValidDerivedType(String dataTypeName, String derivedFrom) throws ConfigModelException { - - if (StringUtils.isBlank(derivedFrom) || !ValidTypes.getValidDataTypeDerivedFrom().contains(derivedFrom)) { - throw new ConfigModelException(derivedFrom + " is not a valid derived type for Data type " + dataTypeName); - } - return true; - } - - private boolean checkValidProperties(String dataTypeName, Map properties) { - if (properties != null) { - message.append("\n validation Data Type (" + dataTypeName + ") Property."); - propertyDefinitionValidator.validatePropertyDefinition(stDataTypes, properties); - } - return true; - } - -} diff --git a/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/validator/NodeTypeValidator.java b/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/validator/NodeTypeValidator.java deleted file mode 100644 index f46d6483c..000000000 --- a/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/validator/NodeTypeValidator.java +++ /dev/null @@ -1,237 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2018 IBM. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.ccsdk.config.model.validator; - -import java.util.HashMap; -import java.util.Map; -import org.apache.commons.lang3.StringUtils; -import org.onap.ccsdk.config.model.ConfigModelConstant; -import org.onap.ccsdk.config.model.ConfigModelException; -import org.onap.ccsdk.config.model.ValidTypes; -import org.onap.ccsdk.config.model.data.CapabilityDefinition; -import org.onap.ccsdk.config.model.data.DataType; -import org.onap.ccsdk.config.model.data.InterfaceDefinition; -import org.onap.ccsdk.config.model.data.NodeType; -import org.onap.ccsdk.config.model.data.OperationDefinition; -import org.onap.ccsdk.config.model.data.PropertyDefinition; -import org.onap.ccsdk.config.model.data.RequirementDefinition; -import org.onap.ccsdk.config.model.data.ServiceTemplate; -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; - -/** - * NodeTypeValidator.java Purpose: Provide Configuration Generator NodeTypeValidator - * - * @version 1.0 - */ -public class NodeTypeValidator { - private static EELFLogger logger = EELFManager.getInstance().getLogger(NodeTypeValidator.class); - private StringBuilder message; - private Map stDataTypes; - private Map stNodeTypes; - private ServiceTemplate serviceTemplate; - private PropertyDefinitionValidator propertyDefinitionValidator; - - /** - * This is a NodeTypeValidator - * - * @param serviceTemplate - * @throws ConfigModelException - */ - public NodeTypeValidator(ServiceTemplate serviceTemplate, StringBuilder message) throws ConfigModelException { - this.serviceTemplate = serviceTemplate; - this.message = message; - propertyDefinitionValidator = new PropertyDefinitionValidator(this.message); - stDataTypes = new HashMap<>(); - stNodeTypes = new HashMap<>(); - loadInitial(); - - } - - private void loadInitial() { - if (serviceTemplate != null) { - - if (serviceTemplate.getDataTypes() != null) { - serviceTemplate.getDataTypes().forEach((dataTypeKey, dataType) -> { - stDataTypes.put(dataTypeKey, dataType); - logger.trace("Data Type ({}) loaded successfully.", dataTypeKey); - }); - } - - if (serviceTemplate.getNodeTypes() != null) { - serviceTemplate.getNodeTypes().forEach((nodeTypeKey, nodeType) -> { - stNodeTypes.put(nodeTypeKey, nodeType); - logger.trace("NodeType Type ({}) loaded successfully.", nodeTypeKey); - }); - } - - } - - } - - /** - * This is a validateNodeTypes to validate the Node Type - * - * @return boolean - * @throws ConfigModelException - */ - @SuppressWarnings({"squid:S00112", "squid:S3776"}) - public boolean validateNodeTypes() { - if (serviceTemplate != null && serviceTemplate.getNodeTypes() != null) { - serviceTemplate.getNodeTypes().forEach((nodeTypeKey, nodeType) -> { - if (nodeType != null) { - message.append("\n ***** Validation Node Type (" + nodeTypeKey + "), derived from (" - + nodeType.getDerivedFrom() + ")"); - try { - validateNodeType(ConfigModelConstant.MODEL_DEFINITION_TYPE_NODE_TYPE, - nodeType.getDerivedFrom()); - - if (nodeType.getProperties() != null) { - checkValidProperties(nodeType.getProperties()); - } - - if (nodeType.getCapabilities() != null) { - validateNodeTypeCapabilities(nodeType.getCapabilities()); - } - - if (nodeType.getInterfaces() != null) { - validateNodeTypeInterface(nodeType.getInterfaces()); - } - - if (nodeType.getRequirements() != null) { - validateNodeTypeRequirement(nodeType.getRequirements()); - } - - } catch (ConfigModelException e) { - logger.error(e.getMessage()); - throw new RuntimeException(e.getMessage()); - } - - } - }); - } - return true; - } - - private boolean validateNodeType(String definitionType, String derivedFrom) throws ConfigModelException { - boolean valid = true; - if (!ConfigModelConstant.MODEL_DEFINITION_TYPE_DATA_TYPE.equalsIgnoreCase(definitionType) - && !ValidTypes.getValidNodeTypes().contains(derivedFrom)) { - throw new ConfigModelException("Not Valid Model Type (" + derivedFrom + ")"); - } - return valid; - } - - private boolean checkValidProperties(Map properties) { - if (properties != null) { - propertyDefinitionValidator.validatePropertyDefinition(stDataTypes, properties); - } - return true; - } - - @SuppressWarnings("squid:S00112") - private boolean validateNodeTypeCapabilities(Map capabilities) { - if (capabilities != null) { - capabilities.forEach((capabilityKey, capability) -> { - if (capability != null) { - Map properties = capability.getProperties(); - message.append("\n Validation Capability (" + capabilityKey + ") properties :"); - propertyDefinitionValidator.validatePropertyDefinition(stDataTypes, properties); - } - }); - } - return true; - } - - @SuppressWarnings("squid:S00112") - private boolean validateNodeTypeInterface(Map interfaces) { - if (interfaces != null) { - interfaces.forEach((interfaceKey, interfaceDefinition) -> { - if (interfaceDefinition != null && interfaceDefinition.getOperations() != null) { - validateNodeTypeInterfaceOperation(interfaceDefinition.getOperations()); - } - }); - } - return true; - } - - @SuppressWarnings("squid:S00112") - private boolean validateNodeTypeInterfaceOperation(Map operations) { - if (operations != null) { - operations.forEach((operationKey, operation) -> { - if (operation != null) { - Map inputs = operation.getInputs(); - message.append("\n Validation Operation (" + operationKey + ") Inputs :"); - propertyDefinitionValidator.validatePropertyDefinition(stDataTypes, inputs); - message.append("\n Validation Operation (" + operationKey + ") output :"); - Map outputs = operation.getOutputs(); - propertyDefinitionValidator.validatePropertyDefinition(stDataTypes, outputs); - } - }); - } - return true; - } - - @SuppressWarnings("squid:S00112") - private boolean validateNodeTypeRequirement(Map requirements) { - if (requirements != null) { - requirements.forEach((requirementKey, requirement) -> { - if (requirement != null) { - String nodeTypeName = requirement.getNode(); - String capabilityName = requirement.getCapability(); - try { - checkCapabilityPresentInNodeType(nodeTypeName, capabilityName); - } catch (ConfigModelException e) { - throw new RuntimeException(e); - } - } - }); - } - return true; - } - - private boolean checkCapabilityPresentInNodeType(String nodeTypeName, String capabilityName) - throws ConfigModelException { - if (StringUtils.isNotBlank(nodeTypeName) && StringUtils.isNotBlank(capabilityName)) { - - if (!stNodeTypes.containsKey(nodeTypeName)) { - throw new ConfigModelException(nodeTypeName + " Node Type not Defined."); - } else { - message.append("\n Node Type (" + nodeTypeName + ") Defined."); - } - - NodeType relationalNodeType = stNodeTypes.get(nodeTypeName); - - if (relationalNodeType.getCapabilities() == null) { - throw new ConfigModelException( - "Node Type (" + nodeTypeName + "), doesn't have Capability Definitions."); - } - - if (!relationalNodeType.getCapabilities().containsKey(capabilityName)) { - throw new ConfigModelException("Node Type (" + nodeTypeName + ") doesn't have (" + capabilityName - + ") Capability Definitions."); - } else { - message.append( - "\n Node Type (" + nodeTypeName + ") has (" + capabilityName + ") Capability Definitions."); - } - - } - return true; - } - -} diff --git a/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/validator/PropertyDefinitionValidator.java b/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/validator/PropertyDefinitionValidator.java deleted file mode 100644 index dc8638349..000000000 --- a/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/validator/PropertyDefinitionValidator.java +++ /dev/null @@ -1,89 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2018 IBM. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.ccsdk.config.model.validator; - -import java.util.Map; -import org.apache.commons.lang3.StringUtils; -import org.onap.ccsdk.config.model.ConfigModelException; -import org.onap.ccsdk.config.model.ValidTypes; -import org.onap.ccsdk.config.model.data.DataType; -import org.onap.ccsdk.config.model.data.PropertyDefinition; - -/** - * PropertyDefinitionValidator.java Purpose: Provide Configuration Generator - * PropertyDefinitionValidator - * - * @version 1.0 - */ -public class PropertyDefinitionValidator { - - StringBuilder message = new StringBuilder(); - - public PropertyDefinitionValidator(StringBuilder message) { - this.message = message; - - } - - /** - * This is a validatePropertyDefinition stored in database - * - * @param stDataTypes - * @param properties - * @return boolean - * @throws ConfigModelException - */ - @SuppressWarnings({"squid:S00112", "squid:S3776", "squid:S1192"}) - public boolean validatePropertyDefinition(Map stDataTypes, - Map properties) { - - if (stDataTypes != null && properties != null) { - properties.forEach((propertyKey, prop) -> { - if (propertyKey != null && prop != null) { - try { - String propertType = prop.getType(); - message.append("\n Validating (" + propertyKey + ") " + prop); - - if (!ValidTypes.getValidPropertType().contains(propertType) - && !stDataTypes.containsKey(propertType)) { - throw new ConfigModelException("Data Type (" + propertyKey + ") -> type(" + propertType - + ") is not a valid type."); - } else if (ValidTypes.getListPropertType().contains(propertType)) { - if (prop.getEntrySchema() == null || StringUtils.isBlank(prop.getEntrySchema().getType())) { - throw new ConfigModelException("Data Type (" + propertyKey + ") -> type (" + propertType - + ") Entity Schema is not defined."); - } - - String entitySchemaType = prop.getEntrySchema().getType(); - - if (!ValidTypes.getValidPropertType().contains(entitySchemaType) - && !stDataTypes.containsKey(entitySchemaType)) { - message.append("\n Present Data Type " + stDataTypes); - throw new ConfigModelException("Data Type (" + propertyKey + ") -> type(" + propertType - + ") -> entitySchema(" + entitySchemaType + ") is not defined."); - } - } - } catch (ConfigModelException e) { - throw new RuntimeException(e); - } - } - }); - } - return true; - } - -} diff --git a/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/validator/ResourceAssignmentValidator.java b/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/validator/ResourceAssignmentValidator.java deleted file mode 100644 index cd486cf7f..000000000 --- a/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/validator/ResourceAssignmentValidator.java +++ /dev/null @@ -1,163 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2018 IBM. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.ccsdk.config.model.validator; - -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; -import org.apache.commons.lang3.StringUtils; -import org.onap.ccsdk.config.model.ConfigModelConstant; -import org.onap.ccsdk.config.model.ConfigModelException; -import org.onap.ccsdk.config.model.data.CapabilityAssignment; -import org.onap.ccsdk.config.model.data.NodeTemplate; -import org.onap.ccsdk.config.model.data.ResourceAssignment; -import org.onap.ccsdk.config.model.utils.TopologicalSortingUtils; -import org.onap.ccsdk.config.model.utils.TransformationUtils; -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; - -public class ResourceAssignmentValidator { - private static EELFLogger logger = EELFManager.getInstance().getLogger(ResourceAssignmentValidator.class); - private List assignments; - private Map resourceAssignmentMap = new HashMap<>(); - private StringBuilder validationMessage = new StringBuilder(); - - public ResourceAssignmentValidator(NodeTemplate nodeTemplate) throws ConfigModelException { - - if (nodeTemplate != null && nodeTemplate.getCapabilities() != null) { - CapabilityAssignment capabilityAssignment = - nodeTemplate.getCapabilities().get(ConfigModelConstant.CAPABILITY_PROPERTY_MAPPING); - if (capabilityAssignment != null && capabilityAssignment.getProperties() != null) { - Object mappingObject = - capabilityAssignment.getProperties().get(ConfigModelConstant.CAPABILITY_PROPERTY_MAPPING); - if (mappingObject != null) { - String mappingContent = TransformationUtils.getJson(mappingObject); - if (StringUtils.isNotBlank(mappingContent)) { - this.assignments = - TransformationUtils.getListfromJson(mappingContent, ResourceAssignment.class); - } else { - validationMessage - .append(String.format("Failed to transform Mapping Content (%s) ", mappingContent)); - throw new ConfigModelException( - String.format("Failed to transform Mapping Content (%s) ", mappingContent)); - } - } - } - } - } - - public ResourceAssignmentValidator(List assignments) { - this.assignments = assignments; - } - - /** - * This is a validateResourceAssignment to validate the Topology Template - * - * @return boolean - * @throws ConfigModelException - */ - public boolean validateResourceAssignment() throws ConfigModelException { - if (assignments != null && !assignments.isEmpty()) { - validateDuplicateDictionaryKeys(); - validateCyclicDependencty(); - if (validationMessage.length() > 0) { - logger.error("Resourece Assignment Validation : {}", validationMessage); - throw new ConfigModelException("Resourece Assignment Validation :" + validationMessage.toString()); - } - } - return true; - } - - @SuppressWarnings("squid:S3776") - private void validateDuplicateDictionaryKeys() { - this.assignments.forEach(resourceMapping -> { - if (resourceMapping != null) { - if (!resourceAssignmentMap.containsKey(resourceMapping.getName())) { - resourceAssignmentMap.put(resourceMapping.getName(), resourceMapping); - } else { - validationMessage.append(String.format("Duplicate Assignment Template Key (%s) is Present", - resourceMapping.getName())); - } - } - }); - - if (!assignments.isEmpty()) { - Set uniqueSet = new HashSet<>(); - for (ResourceAssignment resourceAssignment : assignments) { - if (resourceAssignment != null) { - boolean added = uniqueSet.add(resourceAssignment.getDictionaryName()); - if (!added) { - validationMessage.append( - String.format("Duplicate Assignment Dictionary Key (%s) present with Template Key (%s)", - resourceAssignment.getDictionaryName(), resourceAssignment.getName())); - } - } - } - } - } - - private void validateCyclicDependencty() { - TopologicalSortingUtils topologySorting = new TopologicalSortingUtils<>(); - this.resourceAssignmentMap.forEach((mappingKey, mapping) -> { - if (mapping != null) { - if (mapping.getDependencies() != null && !mapping.getDependencies().isEmpty()) { - for (String dependency : mapping.getDependencies()) { - topologySorting.add(resourceAssignmentMap.get(dependency), mapping); - } - } else { - topologySorting.add(null, mapping); - } - } - }); - - if (!topologySorting.isDag()) { - String graph = getTopologicalGraph(topologySorting); - validationMessage.append("Cyclic Dependency :" + graph); - } - } - - public String getTopologicalGraph(TopologicalSortingUtils topologySorting) { - StringBuilder s = new StringBuilder(); - if (topologySorting != null) { - Map> neighbors = topologySorting.getNeighbors(); - - neighbors.forEach((v, vs) -> { - if (v == null) { - s.append("\n * -> ["); - List links = vs; - for (ResourceAssignment resourceAssignment : links) { - s.append("(" + resourceAssignment.getDictionaryName() + ":" + resourceAssignment.getName() - + "),"); - } - s.append("]"); - } else { - s.append("\n (" + v.getDictionaryName() + ":" + v.getName() + ") -> ["); - List links = vs; - for (ResourceAssignment resourceAssignment : links) { - s.append("(" + resourceAssignment.getDictionaryName() + ":" + resourceAssignment.getName() - + "),"); - } - s.append("]"); - } - }); - } - return s.toString(); - } -} diff --git a/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/validator/ServiceTemplateValidator.java b/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/validator/ServiceTemplateValidator.java deleted file mode 100644 index c329c7fc1..000000000 --- a/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/validator/ServiceTemplateValidator.java +++ /dev/null @@ -1,129 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2018 IBM. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.ccsdk.config.model.validator; - -import java.util.HashMap; -import java.util.Map; -import org.apache.commons.lang3.StringUtils; -import org.onap.ccsdk.config.model.ConfigModelConstant; -import org.onap.ccsdk.config.model.ConfigModelException; -import org.onap.ccsdk.config.model.data.ServiceTemplate; -import org.onap.ccsdk.config.model.utils.TransformationUtils; -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; - -/** - * ServiceTemplateValidator.java Purpose: Provide Configuration Generator ServiceTemplateValidator - * - * @version 1.0 - */ - -public class ServiceTemplateValidator { - - private static EELFLogger logger = EELFManager.getInstance().getLogger(ServiceTemplateValidator.class); - - private Map metaData = new HashMap<>(); - - StringBuilder message = new StringBuilder(); - - /** - * This is a validateServiceTemplate - * - * @param serviceTemplateContent - * @return boolean - * @throws ConfigModelException - */ - @SuppressWarnings("squid:S00112") - public boolean validateServiceTemplate(String serviceTemplateContent) throws ConfigModelException { - if (StringUtils.isNotBlank(serviceTemplateContent)) { - ServiceTemplate serviceTemplate = - TransformationUtils.readValue(serviceTemplateContent, ServiceTemplate.class); - return validateServiceTemplate(serviceTemplate); - } else { - throw new ConfigModelException( - "Service Template Content is (" + serviceTemplateContent + ") not Defined."); - } - } - - /** - * This is a validateServiceTemplate - * - * @param serviceTemplate - * @return boolean - * @throws ConfigModelException - */ - @SuppressWarnings("squid:S00112") - public boolean validateServiceTemplate(ServiceTemplate serviceTemplate) throws ConfigModelException { - if (serviceTemplate != null) { - try { - validateMetaData(serviceTemplate); - (new DataTypeValidator(serviceTemplate, message)).validateDataTypes(); - (new NodeTypeValidator(serviceTemplate, message)).validateNodeTypes(); - (new TopologyTemplateValidator(serviceTemplate, message)).validateTopologyTemplate(); - logger.debug("Validation Message : {}", message); - } catch (Exception e) { - throw new ConfigModelException( - "Validation Failed " + e.toString() + ",Message Trace : \n" + message.toString()); - } - - } else { - throw new ConfigModelException("Service Template is not defined."); - } - return true; - } - - /** - * This is a getMetaData to get the key information during the - * - * @return Map - */ - public Map getMetaData() { - return metaData; - } - - private void validateMetaData(ServiceTemplate serviceTemplate) throws ConfigModelException { - if (serviceTemplate.getMetadata() != null) { - this.metaData.putAll(serviceTemplate.getMetadata()); - - String author = serviceTemplate.getMetadata().get(ConfigModelConstant.SERVICE_TEMPLATE_KEY_ARTIFACT_AUTHOR); - String serviceTemplateName = - serviceTemplate.getMetadata().get(ConfigModelConstant.SERVICE_TEMPLATE_KEY_ARTIFACT_NAME); - String serviceTemplateVersion = - serviceTemplate.getMetadata().get(ConfigModelConstant.SERVICE_TEMPLATE_KEY_ARTIFACT_VERSION); - - if (StringUtils.isBlank(author)) { - throw new ConfigModelException("Service Template Metadata (author) Information is missing."); - } - - if (StringUtils.isBlank(serviceTemplateName)) { - throw new ConfigModelException( - "Service Template Metadata (service-template-name) Information is missing."); - } - - if (StringUtils.isBlank(serviceTemplateVersion)) { - throw new ConfigModelException( - "Service Template Metadata (service-template-version) Information is missing."); - } - - } else { - throw new ConfigModelException("Service Template Metadata Information is missing."); - } - - } - -} diff --git a/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/validator/TopologyTemplateValidator.java b/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/validator/TopologyTemplateValidator.java deleted file mode 100644 index dc1e314ea..000000000 --- a/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/validator/TopologyTemplateValidator.java +++ /dev/null @@ -1,203 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2018 IBM. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.ccsdk.config.model.validator; - -import java.util.HashMap; -import java.util.Map; -import org.apache.commons.lang3.StringUtils; -import org.onap.ccsdk.config.model.ConfigModelConstant; -import org.onap.ccsdk.config.model.ConfigModelException; -import org.onap.ccsdk.config.model.data.DataType; -import org.onap.ccsdk.config.model.data.NodeTemplate; -import org.onap.ccsdk.config.model.data.NodeType; -import org.onap.ccsdk.config.model.data.PropertyDefinition; -import org.onap.ccsdk.config.model.data.RequirementAssignment; -import org.onap.ccsdk.config.model.data.ServiceTemplate; -import org.onap.ccsdk.config.model.data.TopologyTemplate; -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; - -/** - * TopologyTemplateValidator.java Purpose: Provide Configuration Generator TopologyTemplateValidator - * - * @version 1.0 - */ -public class TopologyTemplateValidator { - private static EELFLogger logger = EELFManager.getInstance().getLogger(TopologyTemplateValidator.class); - private StringBuilder message; - private Map stDataTypes; - private Map stNodeTypes; - private Map stNodeTemplates; - private ServiceTemplate serviceTemplate; - private PropertyDefinitionValidator propertyDefinitionValidator; - - /** - * This is a TopologyTemplateValidator - * - * @param serviceTemplate - * @throws ConfigModelException - */ - public TopologyTemplateValidator(ServiceTemplate serviceTemplate, StringBuilder message) { - this.serviceTemplate = serviceTemplate; - this.message = message; - propertyDefinitionValidator = new PropertyDefinitionValidator(this.message); - stDataTypes = new HashMap<>(); - stNodeTypes = new HashMap<>(); - stNodeTemplates = new HashMap<>(); - loadInitial(); - } - - private void loadInitial() { - if (serviceTemplate != null) { - - if (serviceTemplate.getDataTypes() != null) { - serviceTemplate.getDataTypes().forEach((dataTypeKey, dataType) -> { - stDataTypes.put(dataTypeKey, dataType); - logger.trace("Data Type ({}) loaded successfully.", dataTypeKey); - }); - } - - if (serviceTemplate.getNodeTypes() != null) { - serviceTemplate.getNodeTypes().forEach((nodeTypeKey, nodeType) -> { - stNodeTypes.put(nodeTypeKey, nodeType); - logger.trace("Node Type ({}) loaded successfully.", nodeTypeKey); - }); - } - - if (serviceTemplate.getTopologyTemplate() != null) { - TopologyTemplate topologyTemplate = serviceTemplate.getTopologyTemplate(); - - if (topologyTemplate.getNodeTemplates() != null) { - topologyTemplate.getNodeTemplates().forEach((nodeTemplateKey, nodeTemplate) -> { - stNodeTemplates.put(nodeTemplateKey, nodeTemplate); - logger.trace("Node Template ({}) Type loaded successfully.", nodeTemplateKey); - }); - } - } - } - - } - - /** - * This is a validateTopologyTemplate to validate the Topology Template - * - * @return boolean - * @throws ConfigModelException - */ - public boolean validateTopologyTemplate() { - if (serviceTemplate != null && serviceTemplate.getTopologyTemplate() != null) { - - checkValidInputProperties(serviceTemplate.getTopologyTemplate().getInputs()); - - validateNodeTemplates(serviceTemplate.getTopologyTemplate().getNodeTemplates()); - } - return true; - } - - private boolean checkValidInputProperties(Map properties) { - if (properties != null) { - message.append("\n Validation topology template input properties :"); - propertyDefinitionValidator.validatePropertyDefinition(stDataTypes, properties); - } - return true; - } - - @SuppressWarnings({"squid:S00112", "squid:S3776"}) - private boolean validateNodeTemplates(Map nodeTemplates) { - if (nodeTemplates != null) { - nodeTemplates.forEach((nodeTemplateKey, nodeTemplate) -> { - if (nodeTemplate != null) { - message.append("\n ##### Validation Node Template (" + nodeTemplateKey + "), of type (" - + nodeTemplate.getType() + ")"); - - String nodeTypeName = nodeTemplate.getType(); - if (!stNodeTypes.containsKey(nodeTypeName)) { - throw new RuntimeException("Node Type (" + nodeTypeName + ")not Defined."); - } - - if (nodeTemplate.getRequirements() != null) { - validateNodeTemplateRequirement(nodeTemplate.getRequirements()); - } - - // Validate Resource Assignments - NodeType nodeType = stNodeTypes.get(nodeTypeName); - if (nodeType != null - && ConfigModelConstant.MODEL_TYPE_NODE_ARTIFACT.equals(nodeType.getDerivedFrom())) { - logger.info("Validating Resource Assignment NodeTemplate ({}).", nodeTemplateKey); - ResourceAssignmentValidator resourceAssignmentValidator; - try { - resourceAssignmentValidator = new ResourceAssignmentValidator(nodeTemplate); - resourceAssignmentValidator.validateResourceAssignment(); - } catch (ConfigModelException e) { - throw new RuntimeException(e); - } - - } - } - }); - } - return true; - } - - @SuppressWarnings("squid:S00112") - private boolean validateNodeTemplateRequirement(Map requirements) { - if (requirements != null) { - requirements.forEach((requirementKey, requirement) -> { - if (requirement != null) { - String requirementnodeTypeName = requirement.getNode(); - String capabilityName = requirement.getCapability(); - try { - checkCapabilityPresentInNodeTemplate(requirementnodeTypeName, capabilityName); - } catch (ConfigModelException e) { - throw new RuntimeException(e); - } - } - }); - } - return true; - } - - private boolean checkCapabilityPresentInNodeTemplate(String nodeTemplateName, String capabilityName) - throws ConfigModelException { - if (StringUtils.isNotBlank(nodeTemplateName) && StringUtils.isNotBlank(capabilityName)) { - - if (!stNodeTemplates.containsKey(nodeTemplateName)) { - throw new ConfigModelException(nodeTemplateName + " Node Template not Defined."); - } else { - message.append("\n Node Template (" + nodeTemplateName + ") Defined."); - } - - NodeTemplate relationalNodeType = stNodeTemplates.get(nodeTemplateName); - - if (relationalNodeType.getCapabilities() == null) { - throw new ConfigModelException( - "Node Template (" + nodeTemplateName + "), doesn't have Capability Definitions."); - } - - if (!relationalNodeType.getCapabilities().containsKey(capabilityName)) { - throw new ConfigModelException("Node Type (" + nodeTemplateName + ") doesn't have (" + capabilityName - + ") Capability Definitions."); - } else { - message.append("\n Node Template (" + nodeTemplateName + ") has (" + capabilityName - + ") Capability Definitions."); - } - - } - return true; - } -} diff --git a/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/ConfigModelConstant.java b/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/ConfigModelConstant.java new file mode 100644 index 000000000..28572f666 --- /dev/null +++ b/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/ConfigModelConstant.java @@ -0,0 +1,147 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2018 IBM. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.ccsdk.features.model; + +public class ConfigModelConstant { + + private ConfigModelConstant() { + + } + + public static final String STATUS_CODE_SUCCESS = "200"; + public static final String STATUS_CODE_FAILURE = "400"; + + public static final String STATUS_SUCCESS = "success"; + public static final String STATUS_FAILURE = "failure"; + public static final String STATUS_SKIPPED = "skipped"; + + public static final String CONFIG_STATUS_PENDING = "pending"; + public static final String CONFIG_STATUS_FAILED = "failed"; + public static final String CONFIG_STATUS_SUCCESS = "success"; + + public static final String USER_SYSTEM = "System"; + public static final String PROTOCOL_NETCONF = "netconf"; + + public static final String MODEL_CONTENT_TYPE_TOSCA_JSON = "TOSCA_JSON"; + public static final String MODEL_CONTENT_TYPE_TOSCA_YAML = "TOSCA_YAML"; + public static final String MODEL_CONTENT_TYPE_TEMPLATE = "TEMPLATE"; + public static final String MODEL_CONTENT_TYPE_YANG = "YANG"; + public static final String MODEL_CONTENT_TYPE_SCHEMA = "SCHEMA"; + + public static final String SERVICE_TEMPLATE_KEY_ARTIFACT_AUTHOR = "author"; + public static final String SERVICE_TEMPLATE_KEY_ARTIFACT_NAME = "service-template-name"; + public static final String SERVICE_TEMPLATE_KEY_ARTIFACT_VERSION = "service-template-version"; + + public static final String MODEL_DEFINITION_TYPE_NODE_TYPE = "node_type"; + public static final String MODEL_DEFINITION_TYPE_CAPABILITY_TYPE = "capability_type"; + public static final String MODEL_DEFINITION_TYPE_RELATIONSHIP_TYPE = "relationship_type"; + public static final String MODEL_DEFINITION_TYPE_DATA_TYPE = "data_type"; + public static final String MODEL_DEFINITION_TYPE_ARTIFACT_TYPE = "artifact_type"; + + public static final String MODEL_TYPE_DATA_TYPE = "tosca.datatypes.Root"; + public static final String MODEL_TYPE_DATA_TYPE_DYNAMIC = "tosca.datatypes.Dynamic"; + public static final String MODEL_TYPE_NODE_TYPE = "tosca.nodes.Root"; + + public static final String MODEL_TYPE_NODE_DG = "tosca.nodes.DG"; + public static final String MODEL_TYPE_NODE_COMPONENT = "tosca.nodes.Component"; + public static final String MODEL_TYPE_NODE_COMPONENT_PYTHON = "tosca.nodes.Component.Python"; + public static final String MODEL_TYPE_NODE_VNF = "tosca.nodes.Vnf"; + public static final String MODEL_TYPE_NODE_ARTIFACT = "tosca.nodes.Artifact"; + + public static final String MODEL_TYPE_ARTIFACT_TEMPLATE = "tosca.artifact.Template"; + public static final String MODEL_TYPE_ARTIFACT_LICENCE = "tosca.artifacts.Licence"; + + public static final String MODEL_TYPE_RELATIONSHIPS_DEPENDS_ON = "tosca.relationships.DependsOn"; + public static final String MODEL_TYPE_RELATIONSHIPS_HOSTED_ON = "tosca.relationships.HostedOn"; + public static final String MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO = "tosca.relationships.ConnectsTo"; + public static final String MODEL_TYPE_RELATIONSHIPS_ATTACH_TO = "tosca.relationships.AttachesTo"; + public static final String MODEL_TYPE_RELATIONSHIPS_ROUTES_TO = "tosca.relationships.RoutesTo"; + + public static final String NODE_TEMPLATE_TYPE_ARTIFACT_CONFIG_TEMPLATE = "artifact-config-template"; + + public static final String CAPABILITY_PROPERTY_MAPPING = "mapping"; + public static final String CAPABILITY_PROPERTY_CONTENT = "content"; + + public static final String SOURCE_INPUT = "input"; + public static final String SOURCE_DEFAULT = "default"; + public static final String SOURCE_MDSAL = "mdsal"; + public static final String SOURCE_DB = "db"; + public static final String SOURCE_COMPONENT = "component"; + + public static final String PROPERTY_STATUS = "status"; + public static final String PROPERTY_ERROR_CODE = "error-code"; + public static final String PROPERTY_ERROR_MESSAGE = "error-message"; + + public static final String PROPERTY_REQUEST_INPUT = "request-input"; + public static final String PROPERTY_REQUEST_HEADER = "request-header"; + public static final String PROPERTY_REQUEST_PAYLOAD = "request-payload"; + + public static final String PROPERTY_RESPONSE_PAYLOAD = "response-payload"; + public static final String PROPERTY_RESPONSE_JSON_NODE = "response-json-node"; + + public static final String PROPERTY_PAYLOAD = "payload"; + public static final String PROPERTY_INPUTS = "inputs"; + public static final String PROPERTY_ORGINATOR_ID = "originator-id"; + public static final String PROPERTY_API_VERSION = "api-ver"; + public static final String PROPERTY_REQUEST_ID = "request-id"; + public static final String PROPERTY_SUB_REQUEST_ID = "sub-request-id"; + public static final String PROPERTY_REQUEST = "request"; + public static final String PROPERTY_RECIPE = "action"; + + public static final String PROPERTY_SELECTOR = "prifix"; + public static final String PROPERTY_NODE_TEMPLATES = "node_templates"; + public static final String PROPERTY_NODE_TYPES = "node_types"; + public static final String PROPERTY_DATA_TYPES = "data_types"; + public static final String PROPERTY_ACTION_NAME = "action-name"; + public static final String PROPERTY_ACTION_PREFIX = "action-prefix"; + public static final String PROPERTY_TEMPLATE_NAME = "template-name"; + + public static final String PROPERTY_CURRENT_INTERFACE = "current-interface"; + public static final String PROPERTY_CURRENT_OPERATION = "current-operation"; + public static final String PROPERTY_CURRENT_IMPLEMENTATION = "current-implementation"; + public static final String PROPERTY_CURRENT_NODETYPE_DERIVED_FROM = "current-node-type-derived-from"; + public static final String PROPERTY_CURRENT_RESOURCE_ASSIGNMENT = "current-resource-assignment"; + public static final String PROPERTY_CURRENT_DICTIONARY_DEFINITION = "current-dictionary-definition"; + public static final String PROPERTY_RESOURCE_ASSIGNMENTS_DATA = "resource-assignments-data"; + + public static final String PROPERTY_RECIPE_NAMES = "action-names"; + public static final String PROPERTY_DICTIONARIES = "dictionaries"; + public static final String PROPERTY_RESOURCE_ASSIGNMENTS = "resource-assignments"; + public static final String PROPERTY_RESOURCE_KEY = "resource-key"; + public static final String PROPERTY_RESOURCE_NAME = "resource-name"; + public static final String PROPERTY_RESERVATION_ID = "reservation-id"; + + public static final String PROPERTY_NODE_TEMPLATES_DOT = "node_templates."; + public static final String PROPERTY_NODE_TYPES_DOT = "node_types."; + public static final String PROPERTY_DATA_TYPES_DOT = "data_types."; + public static final String PROPERTY_INPUTS_DOT = "inputs."; + public static final String PROPERTY_ARTIFACTS_DOT = "artifacts."; + public static final String PROPERTY_DICTIONARY_KEY_DOT = "dictionary-key."; + public static final String PROPERTY_TEMPLATE_KEY_DOT = "template-key."; + public static final String PROPERTY_RECIPE_KEY_DOT = "recipe-key."; + + public static final String PROPERTY_DOT_STATUS = ".status"; + public static final String PROPERTY_DOT_ERROR_MESSAGE = ".error-message"; + + public static final String EXPRESSION_GET_INPUT = "get_input"; + public static final String EXPRESSION_GET_ATTRIBUTE = "get_attribute"; + public static final String EXPRESSION_SET_VALUE = "set_value"; + + public static final String CONFIG_PROPERTY_MAP_KEY_PREFIX = "org.onap.ccsdk.sli.adaptors."; + +} diff --git a/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/ConfigModelException.java b/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/ConfigModelException.java new file mode 100644 index 000000000..aa71c265a --- /dev/null +++ b/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/ConfigModelException.java @@ -0,0 +1,50 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2018 IBM. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.ccsdk.features.model; + +/** + * ConfigGeneratorException.java Purpose: Provide Configuration Generator ConfigGeneratorException + * + * @version 1.0 + */ +public class ConfigModelException extends Exception { + + /** + * + */ + private static final long serialVersionUID = 1L; + + /** + * This is a ConfigGeneratorException constructor + * + * @param message + */ + public ConfigModelException(String message) { + super(message); + } + + /** + * This is a ConfigGeneratorException constructor + * + * @param message + */ + public ConfigModelException(String message, Throwable cause) { + super(message, cause); + } + +} diff --git a/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/ValidTypes.java b/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/ValidTypes.java new file mode 100644 index 000000000..1be6089d5 --- /dev/null +++ b/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/ValidTypes.java @@ -0,0 +1,105 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2018 IBM. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.ccsdk.features.model; + +import java.util.ArrayList; +import java.util.List; + +/** + * ValidTypes.java Purpose: Provide Configuration Generator ValidTypes + * + * @version 1.0 + */ +public class ValidTypes { + + public static final String DATA_TYPE_STRING = "string"; + public static final String DATA_TYPE_INTEGER = "integer"; + public static final String DATA_TYPE_FLOAT = "float"; + public static final String DATA_TYPE_BOOLEAN = "boolean"; + public static final String DATA_TYPE_TIMESTAMP = "timestamp"; + public static final String DATA_TYPE_NULL = "null"; + public static final String DATA_TYPE_LIST = "list"; + public static final String DATA_TYPE_LONGTEXT = "longtext"; + + private ValidTypes() { + + } + + public static List getValidModelTypes() { + List validTypes = new ArrayList<>(); + validTypes.add(ConfigModelConstant.MODEL_DEFINITION_TYPE_DATA_TYPE); + validTypes.add(ConfigModelConstant.MODEL_DEFINITION_TYPE_NODE_TYPE); + validTypes.add(ConfigModelConstant.MODEL_DEFINITION_TYPE_CAPABILITY_TYPE); + validTypes.add(ConfigModelConstant.MODEL_DEFINITION_TYPE_RELATIONSHIP_TYPE); + return validTypes; + } + + public static List getValidNodeTypes() { + List validTypes = new ArrayList<>(); + validTypes.add(ConfigModelConstant.MODEL_TYPE_NODE_DG); + validTypes.add(ConfigModelConstant.MODEL_TYPE_NODE_COMPONENT); + validTypes.add(ConfigModelConstant.MODEL_TYPE_NODE_VNF); + validTypes.add(ConfigModelConstant.MODEL_TYPE_NODE_ARTIFACT); + return validTypes; + } + + public static List getValidDerivedFrom() { + List validTypes = new ArrayList<>(); + validTypes.add(ConfigModelConstant.MODEL_TYPE_DATA_TYPE_DYNAMIC); + validTypes.add(ConfigModelConstant.MODEL_TYPE_DATA_TYPE); + validTypes.add(ConfigModelConstant.MODEL_TYPE_NODE_TYPE); + return validTypes; + } + + public static List getValidDataTypeDerivedFrom() { + List validTypes = new ArrayList<>(); + validTypes.add(ConfigModelConstant.MODEL_TYPE_DATA_TYPE_DYNAMIC); + validTypes.add(ConfigModelConstant.MODEL_TYPE_DATA_TYPE); + return validTypes; + } + + public static List getValidPropertType() { + List validTypes = new ArrayList<>(); + validTypes.add(DATA_TYPE_STRING); + validTypes.add(DATA_TYPE_INTEGER); + validTypes.add(DATA_TYPE_FLOAT); + validTypes.add(DATA_TYPE_BOOLEAN); + validTypes.add(DATA_TYPE_TIMESTAMP); + validTypes.add(DATA_TYPE_NULL); + validTypes.add(DATA_TYPE_LIST); + return validTypes; + } + + public static List getPrimitivePropertType() { + List validTypes = new ArrayList<>(); + validTypes.add(DATA_TYPE_STRING); + validTypes.add(DATA_TYPE_INTEGER); + validTypes.add(DATA_TYPE_FLOAT); + validTypes.add(DATA_TYPE_BOOLEAN); + validTypes.add(DATA_TYPE_TIMESTAMP); + validTypes.add(DATA_TYPE_NULL); + return validTypes; + } + + public static List getListPropertType() { + List validTypes = new ArrayList<>(); + validTypes.add(DATA_TYPE_LIST); + return validTypes; + } + +} diff --git a/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/data/ArtifactDefinition.java b/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/data/ArtifactDefinition.java new file mode 100644 index 000000000..a26209425 --- /dev/null +++ b/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/data/ArtifactDefinition.java @@ -0,0 +1,105 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2018 IBM. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.ccsdk.features.model.data; + +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * ArtifactDefinition.java Purpose: Provide ArtifactDefinition TOSCO Model POJO bean. + * + * @version 1.0 + */ +public class ArtifactDefinition { + @JsonIgnore + private String id; + private String type; + private String file; + private String repository; + private String description; + @JsonProperty("deploy_Path") + private String deployPath; + // Used for Template Type + private String content; + private String mappingContent; + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + public String getFile() { + return file; + } + + public void setFile(String file) { + this.file = file; + } + + public String getRepository() { + return repository; + } + + public void setRepository(String repository) { + this.repository = repository; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public String getDeployPath() { + return deployPath; + } + + public void setDeployPath(String deployPath) { + this.deployPath = deployPath; + } + + public String getContent() { + return content; + } + + public void setContent(String content) { + this.content = content; + } + + public String getMappingContent() { + return mappingContent; + } + + public void setMappingContent(String mappingContent) { + this.mappingContent = mappingContent; + } + +} diff --git a/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/data/ArtifactType.java b/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/data/ArtifactType.java new file mode 100644 index 000000000..3add0a3f5 --- /dev/null +++ b/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/data/ArtifactType.java @@ -0,0 +1,102 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2018 IBM. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.ccsdk.features.model.data; + +import java.util.List; +import java.util.Map; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonProperty; + +public class ArtifactType { + @JsonIgnore + private String id; + private String description; + private String version; + private Map metadata; + @JsonProperty("derived_from") + private String derivedFrom; + private Map properties; + @JsonProperty("mime_type") + private String mimeType; + @JsonProperty("file_ext") + private List fileExt; + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public String getVersion() { + return version; + } + + public void setVersion(String version) { + this.version = version; + } + + public Map getMetadata() { + return metadata; + } + + public void setMetadata(Map metadata) { + this.metadata = metadata; + } + + public String getDerivedFrom() { + return derivedFrom; + } + + public void setDerivedFrom(String derivedFrom) { + this.derivedFrom = derivedFrom; + } + + public Map getProperties() { + return properties; + } + + public void setProperties(Map properties) { + this.properties = properties; + } + + public String getMimeType() { + return mimeType; + } + + public void setMimeType(String mimeType) { + this.mimeType = mimeType; + } + + public List getFileExt() { + return fileExt; + } + + public void setFileExt(List fileExt) { + this.fileExt = fileExt; + } +} diff --git a/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/data/CapabilityAssignment.java b/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/data/CapabilityAssignment.java new file mode 100644 index 000000000..f40388ce0 --- /dev/null +++ b/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/data/CapabilityAssignment.java @@ -0,0 +1,49 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2018 IBM. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.ccsdk.features.model.data; + +import java.util.Map; +import com.fasterxml.jackson.annotation.JsonIgnore; + +/** + * CapabilityAssignment.java Purpose: Provide CapabilityAssignment TOSCO Model POJO bean. + * + * @version 1.0 + */ +public class CapabilityAssignment { + @JsonIgnore + private String id; + private Map properties; + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public Map getProperties() { + return properties; + } + + public void setProperties(Map properties) { + this.properties = properties; + } + +} diff --git a/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/data/CapabilityDefinition.java b/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/data/CapabilityDefinition.java new file mode 100644 index 000000000..467e9bbdc --- /dev/null +++ b/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/data/CapabilityDefinition.java @@ -0,0 +1,88 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2018 IBM. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.ccsdk.features.model.data; + +import java.util.List; +import java.util.Map; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * CapabilityDefinition.java Purpose: Provide CapabilityDefinition TOSCO Model POJO bean. + * + * @version 1.0 + */ +public class CapabilityDefinition { + @JsonIgnore + private String id; + private String type; + private String description; + private Map properties; + @JsonProperty("valid_source_types") + private List validSourceTypes; + private List occurrences; + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public Map getProperties() { + return properties; + } + + public void setProperties(Map properties) { + this.properties = properties; + } + + public List getValidSourceTypes() { + return validSourceTypes; + } + + public void setValidSourceTypes(List validSourceTypes) { + this.validSourceTypes = validSourceTypes; + } + + public List getOccurrences() { + return occurrences; + } + + public void setOccurrences(List occurrences) { + this.occurrences = occurrences; + } + +} diff --git a/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/data/ConstraintClause.java b/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/data/ConstraintClause.java new file mode 100644 index 000000000..2066e8f7a --- /dev/null +++ b/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/data/ConstraintClause.java @@ -0,0 +1,150 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2018 IBM. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.ccsdk.features.model.data; + +import java.util.List; +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * ConstraintClause.java Purpose: 3.5.2 Constraint clause. + * + * @version 1.0 + */ +public class ConstraintClause { + @JsonProperty("equal") + private Object equal; + + @JsonProperty("greater_than") + private Object greaterThan; + + @JsonProperty("greater_or_equal") + private Object greaterOrEqual; + + @JsonProperty("less_than") + private Object lessThan; + + @JsonProperty("less_or_equal") + private Object lessOrEqual; + + @JsonProperty("in_range") + private Object inRange; + + @JsonProperty("valid_values") + private List validValues; + + @JsonProperty("length") + private Object length; + + @JsonProperty("min_length") + private Object minLength; + + @JsonProperty("max_length") + private Object maxLength; + + @JsonProperty("pattern") + private String pattern; + + public Object getEqual() { + return equal; + } + + public void setEqual(Object equal) { + this.equal = equal; + } + + public Object getGreaterThan() { + return greaterThan; + } + + public void setGreaterThan(Object greaterThan) { + this.greaterThan = greaterThan; + } + + public Object getGreaterOrEqual() { + return greaterOrEqual; + } + + public void setGreaterOrEqual(Object greaterOrEqual) { + this.greaterOrEqual = greaterOrEqual; + } + + public Object getLessThan() { + return lessThan; + } + + public void setLessThan(Object lessThan) { + this.lessThan = lessThan; + } + + public Object getLessOrEqual() { + return lessOrEqual; + } + + public void setLessOrEqual(Object lessOrEqual) { + this.lessOrEqual = lessOrEqual; + } + + public Object getInRange() { + return inRange; + } + + public void setInRange(Object inRange) { + this.inRange = inRange; + } + + public List getValidValues() { + return validValues; + } + + public void setValidValues(List validValues) { + this.validValues = validValues; + } + + public Object getLength() { + return length; + } + + public void setLength(Object length) { + this.length = length; + } + + public Object getMinLength() { + return minLength; + } + + public void setMinLength(Object minLength) { + this.minLength = minLength; + } + + public Object getMaxLength() { + return maxLength; + } + + public void setMaxLength(Object maxLength) { + this.maxLength = maxLength; + } + + public String getPattern() { + return pattern; + } + + public void setPattern(String pattern) { + this.pattern = pattern; + } + +} diff --git a/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/data/DataType.java b/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/data/DataType.java new file mode 100644 index 000000000..6df6ba2a8 --- /dev/null +++ b/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/data/DataType.java @@ -0,0 +1,88 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2018 IBM. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.ccsdk.features.model.data; + +import java.util.List; +import java.util.Map; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * DataType.java Purpose: Provide DataType TOSCO Model POJO bean. + * + * @version 1.0 + */ +public class DataType { + @JsonIgnore + private String id; + private String version; + private String description; + @JsonProperty("derived_from") + private String derivedFrom; + private List> constraints; + private Map properties; + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getVersion() { + return version; + } + + public void setVersion(String version) { + this.version = version; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public String getDerivedFrom() { + return derivedFrom; + } + + public void setDerivedFrom(String derivedFrom) { + this.derivedFrom = derivedFrom; + } + + public List> getConstraints() { + return constraints; + } + + public void setConstraints(List> constraints) { + this.constraints = constraints; + } + + public Map getProperties() { + return properties; + } + + public void setProperties(Map properties) { + this.properties = properties; + } + +} diff --git a/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/data/EntrySchema.java b/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/data/EntrySchema.java new file mode 100644 index 000000000..663442161 --- /dev/null +++ b/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/data/EntrySchema.java @@ -0,0 +1,36 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2018 IBM. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.ccsdk.features.model.data; + +/** + * EntrySchema.java Purpose: Provide EntrySchema TOSCO Model POJO bean. + * + * @version 1.0 + */ +public class EntrySchema { + private String type; + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + +} diff --git a/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/data/Implementation.java b/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/data/Implementation.java new file mode 100644 index 000000000..46facdb69 --- /dev/null +++ b/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/data/Implementation.java @@ -0,0 +1,49 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2018 IBM. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.ccsdk.features.model.data; + +import java.util.List; +import com.fasterxml.jackson.annotation.JsonIgnore; + +/** + * Implementation.java Purpose: Provide Operation Implementation TOSCO Model POJO bean. + * + * @version 1.0 + */ +public class Implementation { + @JsonIgnore + private String primary; + private List dependencies; + + public String getPrimary() { + return primary; + } + + public void setPrimary(String primary) { + this.primary = primary; + } + + public List getDependencies() { + return dependencies; + } + + public void setDependencies(List dependencies) { + this.dependencies = dependencies; + } + +} diff --git a/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/data/InterfaceAssignment.java b/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/data/InterfaceAssignment.java new file mode 100644 index 000000000..9007dd027 --- /dev/null +++ b/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/data/InterfaceAssignment.java @@ -0,0 +1,58 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2018 IBM. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.ccsdk.features.model.data; + +import java.util.Map; +import com.fasterxml.jackson.annotation.JsonIgnore; + +/** + * InterfaceAssignment.java Purpose: Provide InterfaceAssignment TOSCO Model POJO bean. + * + * @version 1.0 + */ +public class InterfaceAssignment { + @JsonIgnore + private String id; + private String type; + private Map operations; + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + public Map getOperations() { + return operations; + } + + public void setOperations(Map operations) { + this.operations = operations; + } + +} diff --git a/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/data/InterfaceDefinition.java b/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/data/InterfaceDefinition.java new file mode 100644 index 000000000..bcd0ef375 --- /dev/null +++ b/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/data/InterfaceDefinition.java @@ -0,0 +1,58 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2018 IBM. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.ccsdk.features.model.data; + +import java.util.Map; +import com.fasterxml.jackson.annotation.JsonIgnore; + +/** + * InterfaceAssignment.java Purpose: Provide InterfaceAssignment TOSCO Model POJO bean. + * + * @version 1.0 + */ +public class InterfaceDefinition { + @JsonIgnore + private String id; + private String type; + private Map operations; + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + public Map getOperations() { + return operations; + } + + public void setOperations(Map operations) { + this.operations = operations; + } + +} diff --git a/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/data/NodeTemplate.java b/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/data/NodeTemplate.java new file mode 100644 index 000000000..c62b719e3 --- /dev/null +++ b/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/data/NodeTemplate.java @@ -0,0 +1,112 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2018 IBM. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.ccsdk.features.model.data; + +import java.util.Map; +import com.fasterxml.jackson.annotation.JsonIgnore; + +/** + * NodeTemplate.java Purpose: Provide NodeTemplate TOSCO Model POJO bean. + * + * @version 1.0 + */ +public class NodeTemplate { + @JsonIgnore + private String id; + private String description; + private String type; + private Map metadata; + private Map properties; + private Map interfaces; + private Map artifacts; + private Map capabilities; + private Map requirements; + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + public Map getMetadata() { + return metadata; + } + + public void setMetadata(Map metadata) { + this.metadata = metadata; + } + + public Map getProperties() { + return properties; + } + + public void setProperties(Map properties) { + this.properties = properties; + } + + public Map getInterfaces() { + return interfaces; + } + + public void setInterfaces(Map interfaces) { + this.interfaces = interfaces; + } + + public Map getArtifacts() { + return artifacts; + } + + public void setArtifacts(Map artifacts) { + this.artifacts = artifacts; + } + + public Map getCapabilities() { + return capabilities; + } + + public void setCapabilities(Map capabilities) { + this.capabilities = capabilities; + } + + public Map getRequirements() { + return requirements; + } + + public void setRequirements(Map requirements) { + this.requirements = requirements; + } + +} diff --git a/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/data/NodeType.java b/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/data/NodeType.java new file mode 100644 index 000000000..f97910995 --- /dev/null +++ b/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/data/NodeType.java @@ -0,0 +1,114 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2018 IBM. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.ccsdk.features.model.data; + +import java.util.Map; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * NodeType.java Purpose: Provide NodeType TOSCO Model POJO bean. + * + * @version 1.0 + */ +public class NodeType { + @JsonIgnore + private String id; + private String description; + private String version; + private Map metadata; + @JsonProperty("derived_from") + private String derivedFrom; + private Map properties; + private Map capabilities; + private Map requirements; + private Map interfaces; + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public String getVersion() { + return version; + } + + public void setVersion(String version) { + this.version = version; + } + + public Map getMetadata() { + return metadata; + } + + public void setMetadata(Map metadata) { + this.metadata = metadata; + } + + public String getDerivedFrom() { + return derivedFrom; + } + + public void setDerivedFrom(String derivedFrom) { + this.derivedFrom = derivedFrom; + } + + public Map getProperties() { + return properties; + } + + public void setProperties(Map properties) { + this.properties = properties; + } + + public Map getCapabilities() { + return capabilities; + } + + public void setCapabilities(Map capabilities) { + this.capabilities = capabilities; + } + + public Map getRequirements() { + return requirements; + } + + public void setRequirements(Map requirements) { + this.requirements = requirements; + } + + public Map getInterfaces() { + return interfaces; + } + + public void setInterfaces(Map interfaces) { + this.interfaces = interfaces; + } + +} diff --git a/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/data/OperationAssignment.java b/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/data/OperationAssignment.java new file mode 100644 index 000000000..cbb14067d --- /dev/null +++ b/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/data/OperationAssignment.java @@ -0,0 +1,76 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2018 IBM. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.ccsdk.features.model.data; + +import java.util.Map; +import com.fasterxml.jackson.annotation.JsonIgnore; + +/** + * OperationAssignment.java Purpose: Provide OperationAssignment TOSCO Model POJO bean. + * + * @version 1.0 + */ +public class OperationAssignment { + @JsonIgnore + private String id; + private String description; + private String implementation; + private Map inputs; + private Map outputs; + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public String getImplementation() { + return implementation; + } + + public void setImplementation(String implementation) { + this.implementation = implementation; + } + + public Map getInputs() { + return inputs; + } + + public void setInputs(Map inputs) { + this.inputs = inputs; + } + + public Map getOutputs() { + return outputs; + } + + public void setOutputs(Map outputs) { + this.outputs = outputs; + } + +} diff --git a/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/data/OperationDefinition.java b/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/data/OperationDefinition.java new file mode 100644 index 000000000..eeb333500 --- /dev/null +++ b/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/data/OperationDefinition.java @@ -0,0 +1,76 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2018 IBM. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.ccsdk.features.model.data; + +import java.util.Map; +import com.fasterxml.jackson.annotation.JsonIgnore; + +/** + * OperationDefinition.java Purpose: Provide OperationDefinition TOSCO Model POJO bean. + * + * @version 1.0 + */ +public class OperationDefinition { + @JsonIgnore + private String id; + private String description; + private Implementation implementation; + private Map inputs; + private Map outputs; + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public Implementation getImplementation() { + return implementation; + } + + public void setImplementation(Implementation implementation) { + this.implementation = implementation; + } + + public Map getInputs() { + return inputs; + } + + public void setInputs(Map inputs) { + this.inputs = inputs; + } + + public Map getOutputs() { + return outputs; + } + + public void setOutputs(Map outputs) { + this.outputs = outputs; + } + +} diff --git a/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/data/PropertyDefinition.java b/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/data/PropertyDefinition.java new file mode 100644 index 000000000..a300d2386 --- /dev/null +++ b/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/data/PropertyDefinition.java @@ -0,0 +1,125 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2018 IBM. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.ccsdk.features.model.data; + +import java.util.HashMap; +import java.util.List; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * PropertyDefinition.java Purpose: Provide PropertyDefinition TOSCO Model POJO bean. + * + * @version 1.0 + */ +public class PropertyDefinition { + @JsonIgnore + private String id; + private String description; + private Boolean required; + private String type; + @JsonProperty("default") + private Object defaultValue; + private String status; + private List> constraints; + @JsonProperty("entry_schema") + private EntrySchema entrySchema; + private Object value; + + @Override + public String toString() { + StringBuilder builder = new StringBuilder("["); + builder.append(" type :" + getType()); + builder.append(", value :" + getValue()); + builder.append("]"); + return builder.toString(); + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public Boolean getRequired() { + return required; + } + + public void setRequired(Boolean required) { + this.required = required; + } + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + public Object getDefaultValue() { + return defaultValue; + } + + public void setDefaultValue(Object defaultValue) { + this.defaultValue = defaultValue; + } + + public String getStatus() { + return status; + } + + public void setStatus(String status) { + this.status = status; + } + + public List> getConstraints() { + return constraints; + } + + public void setConstraints(List> constraints) { + this.constraints = constraints; + } + + public EntrySchema getEntrySchema() { + return entrySchema; + } + + public void setEntrySchema(EntrySchema entrySchema) { + this.entrySchema = entrySchema; + } + + public Object getValue() { + return value; + } + + public void setValue(Object value) { + this.value = value; + } + +} diff --git a/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/data/RelationshipTemplate.java b/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/data/RelationshipTemplate.java new file mode 100644 index 000000000..172d5a846 --- /dev/null +++ b/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/data/RelationshipTemplate.java @@ -0,0 +1,56 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2018 IBM. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.ccsdk.features.model.data; + +import java.util.Map; + +/** + * RelationshipTemplate.java Purpose: Provide RelationshipTemplate TOSCO Model POJO bean. + * + * @version 1.0 + */ +public class RelationshipTemplate { + private String description; + private String type; + private Map properties; + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + public Map getProperties() { + return properties; + } + + public void setProperties(Map properties) { + this.properties = properties; + } + +} diff --git a/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/data/RequirementAssignment.java b/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/data/RequirementAssignment.java new file mode 100644 index 000000000..c26de45e5 --- /dev/null +++ b/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/data/RequirementAssignment.java @@ -0,0 +1,67 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2018 IBM. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.ccsdk.features.model.data; + +import com.fasterxml.jackson.annotation.JsonIgnore; + +/** + * RequirementAssignment.java Purpose: Provide RequirementAssignment TOSCO Model POJO bean. + * + * @version 1.0 + */ +public class RequirementAssignment { + @JsonIgnore + private String id; + private String capability; + private String node; + // Relationship Type or Relationship Template + private String relationship; + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getCapability() { + return capability; + } + + public void setCapability(String capability) { + this.capability = capability; + } + + public String getNode() { + return node; + } + + public void setNode(String node) { + this.node = node; + } + + public String getRelationship() { + return relationship; + } + + public void setRelationship(String relationship) { + this.relationship = relationship; + } + +} diff --git a/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/data/RequirementDefinition.java b/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/data/RequirementDefinition.java new file mode 100644 index 000000000..623a76031 --- /dev/null +++ b/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/data/RequirementDefinition.java @@ -0,0 +1,85 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2018 IBM. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.ccsdk.features.model.data; + +import java.util.List; +import com.fasterxml.jackson.annotation.JsonIgnore; + +/** + * RequirementDefinition.java Purpose: Provide RequirementDefinition TOSCO Model POJO bean. + * + * @version 1.0 + */ +public class RequirementDefinition { + @JsonIgnore + private String id; + private String description; + private String capability; + private String node; + private String relationship; + private List occurrences; + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public String getCapability() { + return capability; + } + + public void setCapability(String capability) { + this.capability = capability; + } + + public String getNode() { + return node; + } + + public void setNode(String node) { + this.node = node; + } + + public String getRelationship() { + return relationship; + } + + public void setRelationship(String relationship) { + this.relationship = relationship; + } + + public List getOccurrences() { + return occurrences; + } + + public void setOccurrences(List occurrences) { + this.occurrences = occurrences; + } + +} diff --git a/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/data/ResourceAssignment.java b/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/data/ResourceAssignment.java new file mode 100644 index 000000000..b288041d8 --- /dev/null +++ b/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/data/ResourceAssignment.java @@ -0,0 +1,165 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2018 IBM. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.ccsdk.features.model.data; + +import java.util.Date; +import java.util.List; +import com.fasterxml.jackson.annotation.JsonFormat; +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * ResourceAssignment.java Purpose: Provide ResourceAssignment Custom TOSCO Model POJO bean. + * + * @version 1.0 + */ +public class ResourceAssignment { + + private String name; + + @JsonProperty("property") + private PropertyDefinition property; + + @JsonProperty("input-param") + private Boolean inputParameter; + + @JsonProperty("dictionary-name") + private String dictionaryName; + + @JsonProperty("dictionary-source") + private String dictionarySource; + + @JsonProperty("dependencies") + private List dependencies; + + @JsonProperty("version") + private int version; + + @JsonProperty("status") + private String status; + + @JsonProperty("message") + private String message; + + @JsonProperty("updated-date") + @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "dd-MM-yyyy hh:mm:ss") + private Date updatedDate; + + @JsonProperty("updated-by") + private String updatedBy; + + @Override + public String toString() { + StringBuilder builder = new StringBuilder("["); + builder.append("name = " + name); + builder.append(", source = " + dictionarySource); + if (dependencies != null) { + builder.append(", dependencies = " + dependencies); + } + builder.append("]"); + return builder.toString(); + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public PropertyDefinition getProperty() { + return property; + } + + public void setProperty(PropertyDefinition property) { + this.property = property; + } + + public Boolean getInputParameter() { + return inputParameter; + } + + public void setInputParameter(Boolean inputParameter) { + this.inputParameter = inputParameter; + } + + public String getDictionaryName() { + return dictionaryName; + } + + public void setDictionaryName(String dictionaryName) { + this.dictionaryName = dictionaryName; + } + + public String getDictionarySource() { + return dictionarySource; + } + + public void setDictionarySource(String dictionarySource) { + this.dictionarySource = dictionarySource; + } + + public List getDependencies() { + return dependencies; + } + + public void setDependencies(List dependencies) { + this.dependencies = dependencies; + } + + public int getVersion() { + return version; + } + + public void setVersion(int version) { + this.version = version; + } + + public String getStatus() { + return status; + } + + public void setStatus(String status) { + this.status = status; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + public Date getUpdatedDate() { + return updatedDate; + } + + public void setUpdatedDate(Date updatedDate) { + this.updatedDate = updatedDate; + } + + public String getUpdatedBy() { + return updatedBy; + } + + public void setUpdatedBy(String updatedBy) { + this.updatedBy = updatedBy; + } + +} diff --git a/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/data/ServiceTemplate.java b/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/data/ServiceTemplate.java new file mode 100644 index 000000000..f66d73727 --- /dev/null +++ b/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/data/ServiceTemplate.java @@ -0,0 +1,118 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2018 IBM. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.ccsdk.features.model.data; + +import java.util.Map; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * ServiceTemplate.java Purpose: Provide ServiceTemplate TOSCO Model POJO bean. + * + * @version 1.0 + */ +public class ServiceTemplate { + @JsonIgnore + private String id; + @JsonProperty("tosca_definitions_version") + private String toscaDefinitionsVersion; + private Map metadata; + private String description; + @JsonProperty("dsl_definitions") + private Map dslDefinitions; + @JsonProperty("topology_template") + private TopologyTemplate topologyTemplate; + @JsonProperty("artifact_types") + private Map artifactTypes; + @JsonProperty("node_types") + private Map nodeTypes; + @JsonProperty("data_types") + private Map dataTypes; + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getToscaDefinitionsVersion() { + return toscaDefinitionsVersion; + } + + public void setToscaDefinitionsVersion(String toscaDefinitionsVersion) { + this.toscaDefinitionsVersion = toscaDefinitionsVersion; + } + + public Map getMetadata() { + return metadata; + } + + public void setMetadata(Map metadata) { + this.metadata = metadata; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public Map getDslDefinitions() { + return dslDefinitions; + } + + public void setDslDefinitions(Map dslDefinitions) { + this.dslDefinitions = dslDefinitions; + } + + public TopologyTemplate getTopologyTemplate() { + return topologyTemplate; + } + + public void setTopologyTemplate(TopologyTemplate topologyTemplate) { + this.topologyTemplate = topologyTemplate; + } + + public Map getNodeTypes() { + return nodeTypes; + } + + public void setNodeTypes(Map nodeTypes) { + this.nodeTypes = nodeTypes; + } + + public Map getDataTypes() { + return dataTypes; + } + + public void setDataTypes(Map dataTypes) { + this.dataTypes = dataTypes; + } + + public Map getArtifactTypes() { + return artifactTypes; + } + + public void setArtifactTypes(Map artifactTypes) { + this.artifactTypes = artifactTypes; + } +} diff --git a/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/data/TopologyTemplate.java b/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/data/TopologyTemplate.java new file mode 100644 index 000000000..1f609386a --- /dev/null +++ b/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/data/TopologyTemplate.java @@ -0,0 +1,97 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2018 IBM. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.ccsdk.features.model.data; + +import java.util.Map; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * TopologyTemplate.java Purpose: Provide TopologyTemplate TOSCO Model POJO bean. + * + * @version 1.0 + */ +public class TopologyTemplate { + @JsonIgnore + private String id; + private String description; + private Map inputs; + @JsonProperty("node_templates") + private Map nodeTemplates; + @JsonProperty("relationship_templates") + private Map relationshipTemplates; + private Map capabilities; + private Map workflows; + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public Map getInputs() { + return inputs; + } + + public void setInputs(Map inputs) { + this.inputs = inputs; + } + + public Map getNodeTemplates() { + return nodeTemplates; + } + + public void setNodeTemplates(Map nodeTemplates) { + this.nodeTemplates = nodeTemplates; + } + + public Map getRelationshipTemplates() { + return relationshipTemplates; + } + + public void setRelationshipTemplates(Map relationshipTemplates) { + this.relationshipTemplates = relationshipTemplates; + } + + public Map getCapabilities() { + return capabilities; + } + + public void setCapabilities(Map capabilities) { + this.capabilities = capabilities; + } + + public Map getWorkflows() { + return workflows; + } + + public void setWorkflows(Map workflows) { + this.workflows = workflows; + } + +} diff --git a/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/data/Workflow.java b/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/data/Workflow.java new file mode 100644 index 000000000..09742a3d0 --- /dev/null +++ b/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/data/Workflow.java @@ -0,0 +1,39 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2018 IBM. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.ccsdk.features.model.data; + +import com.fasterxml.jackson.annotation.JsonIgnore; + +/** + * Workflow.java Purpose: Provide Workflow TOSCO Model POJO bean. + * + * @version 1.0 + */ +public class Workflow { + @JsonIgnore + private String id; + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + +} diff --git a/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/data/api/ActionIdentifiers.java b/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/data/api/ActionIdentifiers.java new file mode 100644 index 000000000..2b54a2c8b --- /dev/null +++ b/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/data/api/ActionIdentifiers.java @@ -0,0 +1,62 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2018 IBM. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.ccsdk.features.model.data.api; + +import com.fasterxml.jackson.annotation.JsonProperty; + +public class ActionIdentifiers { + @JsonProperty("service-template-name") + private String serviceTemplateName; + @JsonProperty("service-template-version") + private String serviceTemplateVersion; + @JsonProperty("action-name") + private String actionName; + private String mode; + + public String getServiceTemplateName() { + return serviceTemplateName; + } + + public void setServiceTemplateName(String serviceTemplateName) { + this.serviceTemplateName = serviceTemplateName; + } + + public String getServiceTemplateVersion() { + return serviceTemplateVersion; + } + + public void setServiceTemplateVersion(String serviceTemplateVersion) { + this.serviceTemplateVersion = serviceTemplateVersion; + } + + public String getActionName() { + return actionName; + } + + public void setActionName(String actionName) { + this.actionName = actionName; + } + + public String getMode() { + return mode; + } + + public void setMode(String mode) { + this.mode = mode; + } +} diff --git a/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/data/api/CommonHeader.java b/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/data/api/CommonHeader.java new file mode 100644 index 000000000..4a4011ef1 --- /dev/null +++ b/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/data/api/CommonHeader.java @@ -0,0 +1,82 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2018 IBM. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.ccsdk.features.model.data.api; + +import com.fasterxml.jackson.annotation.JsonProperty; + +public class CommonHeader { + + private String timestamp; + @JsonProperty("api-ver") + private String apiVer; + @JsonProperty("originator-id") + private String originatorId; + @JsonProperty("request-id") + private String requestId; + @JsonProperty("sub-request-id") + private String subRequestId; + private Flags flags; + + public String getTimestamp() { + return timestamp; + } + + public void setTimestamp(String timestamp) { + this.timestamp = timestamp; + } + + public String getApiVer() { + return apiVer; + } + + public void setApiVer(String apiVer) { + this.apiVer = apiVer; + } + + public String getOriginatorId() { + return originatorId; + } + + public void setOriginatorId(String originatorId) { + this.originatorId = originatorId; + } + + public String getRequestId() { + return requestId; + } + + public void setRequestId(String requestId) { + this.requestId = requestId; + } + + public String getSubRequestId() { + return subRequestId; + } + + public void setSubRequestId(String subRequestId) { + this.subRequestId = subRequestId; + } + + public Flags getFlags() { + return flags; + } + + public void setFlags(Flags flags) { + this.flags = flags; + } +} diff --git a/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/data/api/Flags.java b/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/data/api/Flags.java new file mode 100644 index 000000000..b1f2a9399 --- /dev/null +++ b/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/data/api/Flags.java @@ -0,0 +1,40 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2018 IBM. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.ccsdk.features.model.data.api; + +public class Flags { + private boolean force; + private Integer ttl; + + public boolean isForce() { + return force; + } + + public void setForce(boolean force) { + this.force = force; + } + + public Integer getTtl() { + return ttl; + } + + public void setTtl(Integer ttl) { + this.ttl = ttl; + } + +} diff --git a/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/data/api/Status.java b/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/data/api/Status.java new file mode 100644 index 000000000..2cdd839d6 --- /dev/null +++ b/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/data/api/Status.java @@ -0,0 +1,61 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2018 IBM. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.ccsdk.features.model.data.api; + +import com.fasterxml.jackson.annotation.JsonProperty; + +public class Status { + + private Integer code; + @JsonProperty("error-message") + private String errorMessage; + private String message; + private String completed; + + public Integer getCode() { + return code; + } + + public void setCode(Integer code) { + this.code = code; + } + + public String getErrorMessage() { + return errorMessage; + } + + public void setErrorMessage(String errorMessage) { + this.errorMessage = errorMessage; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + public String getCompleted() { + return completed; + } + + public void setCompleted(String completed) { + this.completed = completed; + } +} diff --git a/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/data/api/TransactionRequest.java b/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/data/api/TransactionRequest.java new file mode 100644 index 000000000..56148eeef --- /dev/null +++ b/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/data/api/TransactionRequest.java @@ -0,0 +1,45 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2018 IBM. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.ccsdk.features.model.data.api; + +import com.fasterxml.jackson.annotation.JsonProperty; + +public class TransactionRequest { + + @JsonProperty("transaction-request-id") + private String transactionRequestId; + @JsonProperty("message-type") + private String messageType; + + public String getTransactionRequestId() { + return transactionRequestId; + } + + public void setTransactionRequestId(String transactionRequestId) { + this.transactionRequestId = transactionRequestId; + } + + public String getMessageType() { + return messageType; + } + + public void setMessageType(String messageType) { + this.messageType = messageType; + } + +} diff --git a/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/data/api/TransactionResponse.java b/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/data/api/TransactionResponse.java new file mode 100644 index 000000000..cc935e813 --- /dev/null +++ b/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/data/api/TransactionResponse.java @@ -0,0 +1,46 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2018 IBM. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.ccsdk.features.model.data.api; + +import java.util.List; +import com.fasterxml.jackson.annotation.JsonProperty; + +public class TransactionResponse { + + @JsonProperty("transaction-request-id") + private String transactionRequestId; + @JsonProperty("event-message") + private List eventMessage; + + public String getTransactionRequestId() { + return transactionRequestId; + } + + public void setTransactionRequestId(String transactionRequestId) { + this.transactionRequestId = transactionRequestId; + } + + public List getEventMessage() { + return eventMessage; + } + + public void setEventMessage(List eventMessage) { + this.eventMessage = eventMessage; + } + +} diff --git a/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/data/dict/ResourceDefinition.java b/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/data/dict/ResourceDefinition.java new file mode 100644 index 000000000..3b115b729 --- /dev/null +++ b/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/data/dict/ResourceDefinition.java @@ -0,0 +1,105 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2018 IBM. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.ccsdk.features.model.data.dict; + +import java.util.Map; + +import org.onap.ccsdk.features.model.data.PropertyDefinition; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; + +@JsonIgnoreProperties(ignoreUnknown = true) +public class ResourceDefinition { + private String tags; + + @JsonProperty(value = "name", required = true) + private String name; + + @JsonProperty(value = "property") + private PropertyDefinition property; + + @JsonProperty(value = "updated-by") + private String updatedBy; + + @JsonProperty(value = "resource-type", required = true) + private String resourceType; + + @JsonProperty(value = "resource-path", required = true) + private String resourcePath; + + @JsonProperty(value = "sources", required = true) + private Map sourcesDefinition; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public PropertyDefinition getProperty() { + return property; + } + + public void setProperty(PropertyDefinition property) { + this.property = property; + } + + public String getTags() { + return tags; + } + + public void setTags(String tags) { + this.tags = tags; + } + + public String getUpdatedBy() { + return updatedBy; + } + + public void setUpdatedBy(String updatedBy) { + this.updatedBy = updatedBy; + } + + public String getResourceType() { + return resourceType; + } + + public void setResourceType(String resourceType) { + this.resourceType = resourceType; + } + + public String getResourcePath() { + return resourcePath; + } + + public void setResourcePath(String resourcePath) { + this.resourcePath = resourcePath; + } + + public Map getSources() { + return sourcesDefinition; + } + + public void setSources(Map sourcesDefinition) { + this.sourcesDefinition = sourcesDefinition; + } + +} diff --git a/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/data/dict/SourcesDefinition.java b/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/data/dict/SourcesDefinition.java new file mode 100644 index 000000000..8ba4471e3 --- /dev/null +++ b/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/data/dict/SourcesDefinition.java @@ -0,0 +1,46 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2018 IBM. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.ccsdk.features.model.data.dict; + +import com.fasterxml.jackson.annotation.JsonProperty; + +public class SourcesDefinition { + + @JsonProperty(value = "type", required = true) + private String type; + + @JsonProperty(value = "properties", required = true) + private SourcesProperties properties; + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + public SourcesProperties getProperties() { + return properties; + } + + public void setProperties(SourcesProperties properties) { + this.properties = properties; + } + +} diff --git a/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/data/dict/SourcesProperties.java b/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/data/dict/SourcesProperties.java new file mode 100644 index 000000000..2a57617ec --- /dev/null +++ b/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/data/dict/SourcesProperties.java @@ -0,0 +1,125 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2018 IBM. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.ccsdk.features.model.data.dict; + +import java.util.List; +import java.util.Map; +import com.fasterxml.jackson.annotation.JsonProperty; + +public class SourcesProperties { + + @JsonProperty(value = "name") + private String name; + + @JsonProperty(value = "base") + private String base; + + @JsonProperty(value = "type") + private String type; + + @JsonProperty(value = "query") + private String query; + + @JsonProperty(value = "url-path") + private String urlPath; + + @JsonProperty(value = "path") + private String path; + + @JsonProperty("input-key-mapping") + private Map inputKeyMapping; + + @JsonProperty("output-key-mapping") + private Map outputKeyMapping; + + @JsonProperty("key-dependencies") + private List dependencies; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getBase() { + return base; + } + + public void setBase(String base) { + this.base = base; + } + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + public String getQuery() { + return query; + } + + public void setQuery(String query) { + this.query = query; + } + + public String getUrlPath() { + return urlPath; + } + + public void setUrlPath(String urlPath) { + this.urlPath = urlPath; + } + + public String getPath() { + return path; + } + + public void setPath(String path) { + this.path = path; + } + + public Map getInputKeyMapping() { + return inputKeyMapping; + } + + public void setInputKeyMapping(Map inputKeyMapping) { + this.inputKeyMapping = inputKeyMapping; + } + + public Map getOutputKeyMapping() { + return outputKeyMapping; + } + + public void setOutputKeyMapping(Map outputKeyMapping) { + this.outputKeyMapping = outputKeyMapping; + } + + public List getDependencies() { + return dependencies; + } + + public void setDependencies(List dependencies) { + this.dependencies = dependencies; + } + +} diff --git a/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/domain/ConfigModel.java b/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/domain/ConfigModel.java new file mode 100644 index 000000000..97862b8ce --- /dev/null +++ b/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/domain/ConfigModel.java @@ -0,0 +1,231 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2018 IBM. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.ccsdk.features.model.domain; + +import java.io.Serializable; +import java.util.Date; +import java.util.List; +import com.fasterxml.jackson.annotation.JsonFormat; + +public class ConfigModel implements Serializable { + + private Long id; + private String serviceUUID; + private String distributionId; + private String serviceName; + private String serviceDescription; + private String resourceUUID; + private String resourceInstanceName; + private String resourceName; + private String resourceVersion; + private String resourceType; + private String artifactUUId; + private String artifactType; + private String artifactVersion; + private String artifactDescription; + private Integer internalVersion; + @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "MM/dd/yyyy KK:mm:ss a Z") + private Date createdDate = new Date(); + private String artifactName; + private String published; + private String updatedBy; + private String tags; + @SuppressWarnings("squid:S1948") + private List configModelContents; + + @Override + public String toString() { + StringBuilder buffer = new StringBuilder("["); + buffer.append("id = " + id); + buffer.append(", artifactType = " + artifactType); + buffer.append(", artifactVersion = " + artifactVersion); + buffer.append(", artifactName = " + artifactName); + buffer.append(", active = " + published); + buffer.append("]"); + return buffer.toString(); + } + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getServiceUUID() { + return serviceUUID; + } + + public void setServiceUUID(String serviceUUID) { + this.serviceUUID = serviceUUID; + } + + public String getDistributionId() { + return distributionId; + } + + public void setDistributionId(String distributionId) { + this.distributionId = distributionId; + } + + public String getServiceName() { + return serviceName; + } + + public void setServiceName(String serviceName) { + this.serviceName = serviceName; + } + + public String getServiceDescription() { + return serviceDescription; + } + + public void setServiceDescription(String serviceDescription) { + this.serviceDescription = serviceDescription; + } + + public String getResourceUUID() { + return resourceUUID; + } + + public void setResourceUUID(String resourceUUID) { + this.resourceUUID = resourceUUID; + } + + public String getResourceInstanceName() { + return resourceInstanceName; + } + + public void setResourceInstanceName(String resourceInstanceName) { + this.resourceInstanceName = resourceInstanceName; + } + + public String getResourceName() { + return resourceName; + } + + public void setResourceName(String resourceName) { + this.resourceName = resourceName; + } + + public String getResourceVersion() { + return resourceVersion; + } + + public void setResourceVersion(String resourceVersion) { + this.resourceVersion = resourceVersion; + } + + public String getResourceType() { + return resourceType; + } + + public void setResourceType(String resourceType) { + this.resourceType = resourceType; + } + + public String getArtifactUUId() { + return artifactUUId; + } + + public void setArtifactUUId(String artifactUUId) { + this.artifactUUId = artifactUUId; + } + + public String getArtifactType() { + return artifactType; + } + + public void setArtifactType(String artifactType) { + this.artifactType = artifactType; + } + + public String getArtifactVersion() { + return artifactVersion; + } + + public void setArtifactVersion(String artifactVersion) { + this.artifactVersion = artifactVersion; + } + + public String getArtifactDescription() { + return artifactDescription; + } + + public void setArtifactDescription(String artifactDescription) { + this.artifactDescription = artifactDescription; + } + + public Integer getInternalVersion() { + return internalVersion; + } + + public void setInternalVersion(Integer internalVersion) { + this.internalVersion = internalVersion; + } + + public Date getCreatedDate() { + return createdDate; + } + + public void setCreatedDate(Date createdDate) { + this.createdDate = createdDate; + } + + public String getArtifactName() { + return artifactName; + } + + public void setArtifactName(String artifactName) { + this.artifactName = artifactName; + } + + public String getPublished() { + return published; + } + + public void setPublished(String published) { + this.published = published; + } + + public String getUpdatedBy() { + return updatedBy; + } + + public void setUpdatedBy(String updatedBy) { + this.updatedBy = updatedBy; + } + + public String getTags() { + return tags; + } + + public void setTags(String tags) { + this.tags = tags; + } + + public List getConfigModelContents() { + return configModelContents; + } + + public void setConfigModelContents(List configModelContents) { + this.configModelContents = configModelContents; + } + +} diff --git a/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/domain/ConfigModelContent.java b/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/domain/ConfigModelContent.java new file mode 100644 index 000000000..b820b1214 --- /dev/null +++ b/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/domain/ConfigModelContent.java @@ -0,0 +1,91 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2018 IBM. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.ccsdk.features.model.domain; + +import java.util.Date; +import com.fasterxml.jackson.annotation.JsonFormat; + +public class ConfigModelContent { + + private Long id; + private String name; + private String contentType; + private String description; + private String content; + @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "MM/dd/yyyy KK:mm:ss a Z") + private Date createdDate = new Date(); + + @Override + public String toString() { + StringBuilder buffer = new StringBuilder("["); + buffer.append("id = " + id); + buffer.append(", name = " + name); + buffer.append(", type = " + contentType); + buffer.append("]"); + return buffer.toString(); + } + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getContentType() { + return contentType; + } + + public void setContentType(String type) { + this.contentType = type; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public String getContent() { + return content; + } + + public void setContent(String content) { + this.content = content; + } + + public Date getCreatedDate() { + return createdDate; + } + + public void setCreatedDate(Date createdDate) { + this.createdDate = createdDate; + } + +} diff --git a/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/domain/ResourceDictionary.java b/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/domain/ResourceDictionary.java new file mode 100644 index 000000000..c62bf69b2 --- /dev/null +++ b/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/domain/ResourceDictionary.java @@ -0,0 +1,162 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2018 IBM. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.ccsdk.features.model.domain; + +import java.io.Serializable; +import java.util.Date; + +public class ResourceDictionary implements Serializable { + private static final long serialVersionUID = 1L; + + private Long id; + private String name; + private String resourcePath; + private String resourceType; + private String dataType; + private String entrySchema; + private String validValues; + private String sampleValue; + private String definition; + private String description; + private String tags; + private Date creationDate; + private String updatedBy; + + @Override + public String toString() { + StringBuilder buffer = new StringBuilder("["); + buffer.append("id = " + id); + buffer.append(", name = " + name); + buffer.append(", resourcePath = " + resourcePath); + buffer.append(", resourceType = " + resourceType); + buffer.append(", dataType = " + dataType); + buffer.append(", entrySchema = " + entrySchema); + buffer.append(", validValues = " + validValues); + buffer.append(", definition =" + definition); + buffer.append(", description = " + description); + buffer.append(", tags = " + tags); + buffer.append(", creationDate = " + creationDate); + buffer.append("]"); + return buffer.toString(); + } + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getResourcePath() { + return resourcePath; + } + + public void setResourcePath(String resourcePath) { + this.resourcePath = resourcePath; + } + + public String getResourceType() { + return resourceType; + } + + public void setResourceType(String resourceType) { + this.resourceType = resourceType; + } + + public String getDataType() { + return dataType; + } + + public void setDataType(String dataType) { + this.dataType = dataType; + } + + public String getEntrySchema() { + return entrySchema; + } + + public void setEntrySchema(String entrySchema) { + this.entrySchema = entrySchema; + } + + public String getValidValues() { + return validValues; + } + + public void setValidValues(String validValues) { + this.validValues = validValues; + } + + public String getSampleValue() { + return sampleValue; + } + + public void setSampleValue(String sampleValue) { + this.sampleValue = sampleValue; + } + + public String getDefinition() { + return definition; + } + + public void setDefinition(String definition) { + this.definition = definition; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public String getTags() { + return tags; + } + + public void setTags(String tags) { + this.tags = tags; + } + + public Date getCreationDate() { + return creationDate; + } + + public void setCreationDate(Date creationDate) { + this.creationDate = creationDate; + } + + public String getUpdatedBy() { + return updatedBy; + } + + public void setUpdatedBy(String updatedBy) { + this.updatedBy = updatedBy; + } + +} diff --git a/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/service/ComponentNode.java b/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/service/ComponentNode.java new file mode 100644 index 000000000..92ccee223 --- /dev/null +++ b/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/service/ComponentNode.java @@ -0,0 +1,41 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2018 IBM. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.ccsdk.features.model.service; + +import java.util.Map; +import org.onap.ccsdk.sli.core.sli.SvcLogicContext; +import org.onap.ccsdk.sli.core.sli.SvcLogicException; +import org.onap.ccsdk.sli.core.sli.SvcLogicJavaPlugin; + +public interface ComponentNode extends SvcLogicJavaPlugin { + + public Boolean preCondition(Map inParams, SvcLogicContext ctx, Map componentContext) + throws SvcLogicException; + + public void preProcess(Map inParams, SvcLogicContext ctx, Map componentContext) + throws SvcLogicException; + + public void process(Map inParams, SvcLogicContext ctx) throws SvcLogicException; + + public void process(Map inParams, SvcLogicContext ctx, Map componentContext) + throws SvcLogicException; + + public void postProcess(Map inParams, SvcLogicContext ctx, Map componentContext) + throws SvcLogicException; + +} diff --git a/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/service/ComponentNodeDelegate.java b/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/service/ComponentNodeDelegate.java new file mode 100644 index 000000000..4b9743fb7 --- /dev/null +++ b/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/service/ComponentNodeDelegate.java @@ -0,0 +1,42 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2018 IBM. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.ccsdk.features.model.service; + +import java.util.Map; +import org.onap.ccsdk.sli.core.sli.SvcLogicContext; +import org.onap.ccsdk.sli.core.sli.SvcLogicException; +import org.onap.ccsdk.sli.core.sli.SvcLogicJavaPlugin; +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; + +public class ComponentNodeDelegate implements SvcLogicJavaPlugin { + + private static EELFLogger logger = EELFManager.getInstance().getLogger(ComponentNodeDelegate.class); + private ComponentNodeService componentNodeService; + + public ComponentNodeDelegate(ComponentNodeService componentNodeService) { + logger.info("{} Constructor Initiated", "ComponentNodeDelegate"); + this.componentNodeService = componentNodeService; + + } + + public void process(Map inParams, SvcLogicContext ctx) throws SvcLogicException { + this.componentNodeService.process(inParams, ctx, null); + } + +} diff --git a/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/service/ComponentNodeService.java b/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/service/ComponentNodeService.java new file mode 100644 index 000000000..12efc6569 --- /dev/null +++ b/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/service/ComponentNodeService.java @@ -0,0 +1,32 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2018 IBM. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.ccsdk.features.model.service; + +import java.util.Map; +import org.onap.ccsdk.sli.core.sli.SvcLogicContext; +import org.onap.ccsdk.sli.core.sli.SvcLogicException; + +public interface ComponentNodeService { + + public void process(Map inParams, SvcLogicContext ctx, Map componentContext) + throws SvcLogicException; + + public ComponentNode getComponentNodeInterface(String pluginName, String componentType) throws SvcLogicException; + + public ComponentNode getComponentNode(SvcLogicContext ctx, String selectorName) throws SvcLogicException; +} diff --git a/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/service/ComponentNodeServiceImpl.java b/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/service/ComponentNodeServiceImpl.java new file mode 100644 index 000000000..df0dae10f --- /dev/null +++ b/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/service/ComponentNodeServiceImpl.java @@ -0,0 +1,174 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2018 IBM. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.ccsdk.features.model.service; + +import java.util.HashMap; +import java.util.Map; +import org.apache.commons.lang3.StringUtils; +import org.onap.ccsdk.features.data.adaptor.DataAdaptorConstants; +import org.onap.ccsdk.features.data.adaptor.domain.TransactionLog; +import org.onap.ccsdk.features.data.adaptor.service.ConfigResourceService; +import org.onap.ccsdk.features.model.ConfigModelConstant; +import org.onap.ccsdk.features.model.data.InterfaceAssignment; +import org.onap.ccsdk.features.model.data.NodeTemplate; +import org.onap.ccsdk.features.model.utils.TransformationUtils; +import org.onap.ccsdk.features.rest.adaptor.service.ConfigRestAdaptorService; +import org.onap.ccsdk.sli.core.sli.SvcLogicContext; +import org.onap.ccsdk.sli.core.sli.SvcLogicException; +import org.osgi.framework.BundleContext; +import org.osgi.framework.ServiceReference; +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; + +public class ComponentNodeServiceImpl implements ComponentNodeService { + + private static EELFLogger logger = EELFManager.getInstance().getLogger(ComponentNodeServiceImpl.class); + + private BundleContext bcontext; + private ConfigResourceService configResourceService; + private ConfigModelService configModelService; + + public ComponentNodeServiceImpl(BundleContext blueprintBundleContext, ConfigResourceService configResourceService, + ConfigRestAdaptorService configRestAdaptorService) { + logger.info("{} Constructor Initiated", "ComponentNodeServiceImpl"); + this.bcontext = blueprintBundleContext; + this.configResourceService = configResourceService; + this.configModelService = new ConfigModelServiceImpl(configRestAdaptorService); + } + + @Override + public void process(Map inParams, SvcLogicContext ctx, Map componentContext) + throws SvcLogicException { + String requestId = null; + String selector = null; + try { + selector = inParams.get(ConfigModelConstant.PROPERTY_SELECTOR); + requestId = ctx.getAttribute(ConfigModelConstant.PROPERTY_REQUEST_ID); + + logger.info("Component execution started with input params ({})", inParams); + configModelService.assignInParamsFromModel(ctx, inParams); + + String currentInterface = inParams.get(ConfigModelConstant.PROPERTY_CURRENT_INTERFACE); + String currentNodeDerivedFrom = inParams.get(ConfigModelConstant.PROPERTY_CURRENT_NODETYPE_DERIVED_FROM); + + configResourceService.save(new TransactionLog(requestId, DataAdaptorConstants.LOG_MESSAGE_TYPE_COMPONENT, + String.format("Executing Component (%s) derived from (%s) with Params : (%s) ", currentInterface, + currentNodeDerivedFrom, inParams))); + + ComponentNode handler = getComponentNodeInterface(currentInterface, currentNodeDerivedFrom); + + if (handler == null) { + throw new SvcLogicException( + String.format("Could not find Component for Interface %s", currentInterface)); + } + if (componentContext == null) { + componentContext = new HashMap<>(); + } + + logger.debug("Executing component ({})", currentInterface); + + if (handler.preCondition(inParams, ctx, componentContext)) { + handler.preProcess(inParams, ctx, componentContext); + handler.process(inParams, ctx, componentContext); + handler.postProcess(inParams, ctx, componentContext); + logger.debug("Executed component ({}) successfully.", currentInterface); + configResourceService + .save(new TransactionLog(requestId, DataAdaptorConstants.LOG_MESSAGE_TYPE_COMPONENT, + String.format("Component (%s) executed successfully. ", currentInterface))); + + ctx.setAttribute(selector + ConfigModelConstant.PROPERTY_DOT_STATUS, + ConfigModelConstant.STATUS_SUCCESS); + } else { + logger.info("Skipped component execution ({})", handler.getClass()); + configResourceService + .save(new TransactionLog(requestId, DataAdaptorConstants.LOG_MESSAGE_TYPE_COMPONENT, + String.format("Skipping component (%s) execution.", handler.getClass()))); + ctx.setAttribute(selector + ConfigModelConstant.PROPERTY_DOT_STATUS, + ConfigModelConstant.STATUS_SKIPPED); + } + + configModelService.assignOutParamsFromModel(ctx, inParams); + ctx.setStatus(ConfigModelConstant.STATUS_SUCCESS); + } catch (Exception e) { + logger.error(String.format("Failed in component (%s) execution for request id (%s) with error %s", selector, + requestId, e.getMessage())); + configResourceService.save(new TransactionLog(requestId, DataAdaptorConstants.LOG_MESSAGE_TYPE_COMPONENT, + String.format("Failed in component (%s) execution for request id (%s) with error %s", selector, + requestId, e.getMessage()))); + + ctx.setAttribute(selector + ConfigModelConstant.PROPERTY_DOT_STATUS, ConfigModelConstant.STATUS_FAILURE); + ctx.setAttribute(selector + ConfigModelConstant.PROPERTY_DOT_ERROR_MESSAGE, e.getMessage()); + ctx.setAttribute(ConfigModelConstant.PROPERTY_ERROR_MESSAGE, e.getMessage()); + ctx.setStatus(ConfigModelConstant.STATUS_FAILURE); + throw new SvcLogicException(e.getMessage(), e); + } + } + + @Override + public ComponentNode getComponentNodeInterface(String pluginName, String componentType) throws SvcLogicException { + + logger.info("Searching for component node plugin ({}) component type ({})", pluginName, componentType); + + if (StringUtils.isBlank(pluginName)) { + throw new SvcLogicException( + String.format("Could not get Interface Name from Service Template : %s ", pluginName)); + } + + pluginName = pluginName.replace("-", "."); + ServiceReference sref = bcontext.getServiceReference(pluginName); + + if (sref == null) { + throw new SvcLogicException( + String.format("Could not find service reference object for plugin %s", pluginName)); + } + return (ComponentNode) bcontext.getService(sref); + } + + @Override + public ComponentNode getComponentNode(SvcLogicContext ctx, String componentKey) throws SvcLogicException { + + if (StringUtils.isBlank(componentKey)) { + logger.warn("Can't get node template content for a component key ({})", componentKey); + return null; + } + + String nodeTemplateContent = ctx.getAttribute(ConfigModelConstant.PROPERTY_NODE_TEMPLATES_DOT + componentKey); + logger.info("Processing component template : ({})", nodeTemplateContent); + + if (StringUtils.isBlank(nodeTemplateContent)) { + logger.warn("Couldn't get node template content for component key ({})", componentKey); + return null; + } + + NodeTemplate nodeTemplate = TransformationUtils.readValue(nodeTemplateContent, NodeTemplate.class); + if (nodeTemplate == null || StringUtils.isBlank(nodeTemplate.getType())) { + logger.warn("Failed to convert content ({}) to node template.", nodeTemplateContent); + return null; + } + + ComponentNode componentNode = null; + for (Map.Entry nodeTemplateInterface : nodeTemplate.getInterfaces().entrySet()) { + if (nodeTemplateInterface != null && nodeTemplateInterface.getValue() != null) { + String pluginName = nodeTemplateInterface.getKey(); + componentNode = getComponentNodeInterface(pluginName, ConfigModelConstant.MODEL_TYPE_NODE_COMPONENT); + } + } + return componentNode; + } + +} diff --git a/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/service/ConfigBlueprintService.java b/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/service/ConfigBlueprintService.java new file mode 100644 index 000000000..3b30d3bb4 --- /dev/null +++ b/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/service/ConfigBlueprintService.java @@ -0,0 +1,100 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2018 IBM. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.ccsdk.features.model.service; + +import java.util.List; +import java.util.Map; +import org.apache.commons.lang3.StringUtils; +import org.onap.ccsdk.features.model.ConfigModelConstant; +import org.onap.ccsdk.features.model.domain.ConfigModel; +import org.onap.ccsdk.features.model.domain.ConfigModelContent; +import org.onap.ccsdk.features.model.utils.PrepareContextUtils; +import org.onap.ccsdk.features.rest.adaptor.ConfigRestAdaptorConstants; +import org.onap.ccsdk.features.rest.adaptor.ConfigRestAdaptorException; +import org.onap.ccsdk.features.rest.adaptor.service.ConfigRestAdaptorService; +import org.onap.ccsdk.sli.core.sli.SvcLogicException; +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; + +public class ConfigBlueprintService { + + private static EELFLogger logger = EELFManager.getInstance().getLogger(ConfigBlueprintService.class); + + private final ConfigRestAdaptorService configRestAdaptorService; + + public ConfigBlueprintService(ConfigRestAdaptorService configRestAdaptorService) { + this.configRestAdaptorService = configRestAdaptorService; + } + + public Map prepareContext(Map context, String input, String serviceTemplateName, + String serviceTemplateVersion) throws SvcLogicException { + try { + PrepareContextUtils prepareContextUtils = new PrepareContextUtils(); + String serviceTemplateContent = getServiceModel(context, serviceTemplateName, serviceTemplateVersion); + + if (StringUtils.isBlank(serviceTemplateContent)) { + throw new SvcLogicException(String.format("Failed to get the Service Template (%s), version (%s)", + serviceTemplateName, serviceTemplateVersion)); + } + + return prepareContextUtils.prepareContext(context, input, serviceTemplateContent); + } catch (Exception e) { + throw new SvcLogicException(e.getMessage(), e); + } + } + + @SuppressWarnings("squid:S3776") + private String getServiceModel(Map context, String serviceTemplateName, + String serviceTemplateVersion) throws SvcLogicException, ConfigRestAdaptorException { + String content = null; + + logger.info("Getting service template ({}) of version ({}) ", serviceTemplateName, serviceTemplateVersion); + + String path = "configmodelbyname/" + serviceTemplateName + "/version/" + serviceTemplateVersion; + + ConfigModel configModel = configRestAdaptorService + .getResource(ConfigRestAdaptorConstants.SELECTOR_MODEL_SERVICE, path, ConfigModel.class); + + if (configModel == null || configModel.getConfigModelContents() == null + || configModel.getConfigModelContents().isEmpty()) { + throw new SvcLogicException("Service template model is missing for service template name (" + + serviceTemplateName + "), service template version (" + serviceTemplateVersion + ") "); + } else { + if (configModel.getPublished() == null || !configModel.getPublished().equalsIgnoreCase("Y")) { + throw new SvcLogicException(String.format( + "Service template model is not published for service template (%s) ", serviceTemplateName)); + } + + List configModelContents = configModel.getConfigModelContents(); + for (ConfigModelContent configModelContent : configModelContents) { + if (configModelContent != null) { + if (ConfigModelConstant.MODEL_CONTENT_TYPE_TOSCA_JSON.equals(configModelContent.getContentType())) { + content = configModelContent.getContent(); + } else if (ConfigModelConstant.MODEL_CONTENT_TYPE_TEMPLATE + .equals(configModelContent.getContentType())) { + context.put(ConfigModelConstant.PROPERTY_NODE_TEMPLATES_DOT + configModelContent.getName() + + ".content", configModelContent.getContent()); + } + } + } + logger.trace("Service model data : {} ", content); + } + return content; + } + +} diff --git a/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/service/ConfigModelNode.java b/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/service/ConfigModelNode.java new file mode 100644 index 000000000..cb652bd68 --- /dev/null +++ b/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/service/ConfigModelNode.java @@ -0,0 +1,24 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2018 IBM. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.ccsdk.features.model.service; + +import org.onap.ccsdk.sli.core.sli.SvcLogicJavaPlugin; + +public class ConfigModelNode implements SvcLogicJavaPlugin { + +} diff --git a/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/service/ConfigModelService.java b/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/service/ConfigModelService.java new file mode 100644 index 000000000..b0df3e607 --- /dev/null +++ b/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/service/ConfigModelService.java @@ -0,0 +1,56 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2018 IBM. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.ccsdk.features.model.service; + +import java.util.List; +import java.util.Map; + +import org.onap.ccsdk.features.model.data.ServiceTemplate; +import org.onap.ccsdk.sli.core.sli.SvcLogicContext; +import org.onap.ccsdk.sli.core.sli.SvcLogicException; + +public interface ConfigModelService { + + public Boolean validateServiceTemplate(ServiceTemplate serviceTemplate) throws SvcLogicException; + + public Map prepareContext(Map context, String input, String serviceTemplateName, + String serviceTemplateVersion) throws SvcLogicException; + + public Map prepareContext(Map context, String input, String serviceTemplateContent) + throws SvcLogicException; + + public Map convertJson2properties(Map context, String jsonContent, + List blockKeys) throws SvcLogicException; + + public Map convertServiceTemplate2Properties(String serviceTemplateContent, + final Map context) throws SvcLogicException; + + public Map convertServiceTemplate2Properties(ServiceTemplate serviceTemplate, + final Map context) throws SvcLogicException; + + public SvcLogicContext assignInParamsFromModel(final SvcLogicContext context, final Map inParams) + throws SvcLogicException; + + public SvcLogicContext assignOutParamsFromModel(final SvcLogicContext context, final Map inParams) + throws SvcLogicException; + + public String getNodeTemplateContent(final SvcLogicContext context, String templateName) throws SvcLogicException; + + public String getNodeTemplateMapping(final SvcLogicContext context, String templateName) throws SvcLogicException; + +} diff --git a/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/service/ConfigModelServiceImpl.java b/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/service/ConfigModelServiceImpl.java new file mode 100644 index 000000000..231f76af9 --- /dev/null +++ b/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/service/ConfigModelServiceImpl.java @@ -0,0 +1,244 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2018 IBM. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.ccsdk.features.model.service; + +import java.util.List; +import java.util.Map; +import org.apache.commons.lang3.StringUtils; +import org.onap.ccsdk.features.model.ConfigModelConstant; +import org.onap.ccsdk.features.model.ConfigModelException; +import org.onap.ccsdk.features.model.data.CapabilityAssignment; +import org.onap.ccsdk.features.model.data.NodeTemplate; +import org.onap.ccsdk.features.model.data.NodeType; +import org.onap.ccsdk.features.model.data.ServiceTemplate; +import org.onap.ccsdk.features.model.utils.NodePropertyUtils; +import org.onap.ccsdk.features.model.utils.PrepareContextUtils; +import org.onap.ccsdk.features.model.utils.ServiceTemplateUtils; +import org.onap.ccsdk.features.model.utils.TransformationUtils; +import org.onap.ccsdk.features.model.validator.ServiceTemplateValidator; +import org.onap.ccsdk.features.rest.adaptor.service.ConfigRestAdaptorService; +import org.onap.ccsdk.sli.core.sli.SvcLogicContext; +import org.onap.ccsdk.sli.core.sli.SvcLogicException; +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; + +public class ConfigModelServiceImpl implements ConfigModelService { + + private static EELFLogger logger = EELFManager.getInstance().getLogger(ConfigModelServiceImpl.class); + private static final String CLASS_NAME = "ConfigModelServiceImpl"; + + private final ConfigRestAdaptorService configRestAdaptorService; + + public ConfigModelServiceImpl(ConfigRestAdaptorService configRestAdaptorService) { + logger.info("{} Constuctor Initated...", CLASS_NAME); + this.configRestAdaptorService = configRestAdaptorService; + } + + @Override + public Boolean validateServiceTemplate(ServiceTemplate serviceTemplate) throws SvcLogicException { + try { + ServiceTemplateValidator serviceTemplateValidator = new ServiceTemplateValidator(); + return serviceTemplateValidator.validateServiceTemplate(serviceTemplate); + } catch (ConfigModelException e) { + throw new SvcLogicException(e.getMessage()); + } + } + + @Override + public Map prepareContext(Map context, String input, String serviceTemplateName, + String serviceTemplateVersion) throws SvcLogicException { + + ConfigBlueprintService configBlueprintService = new ConfigBlueprintService(configRestAdaptorService); + return configBlueprintService.prepareContext(context, input, serviceTemplateName, serviceTemplateVersion); + } + + @Override + public Map prepareContext(Map context, String input, String serviceTemplateContent) + throws SvcLogicException { + try { + PrepareContextUtils prepareContextUtils = new PrepareContextUtils(); + return prepareContextUtils.prepareContext(context, input, serviceTemplateContent); + } catch (Exception e) { + throw new SvcLogicException(e.getMessage()); + } + } + + @Override + public Map convertJson2properties(Map context, String jsonContent, + List blockKeys) throws SvcLogicException { + try { + return TransformationUtils.convertJson2Properties(context, jsonContent, blockKeys); + } catch (Exception e) { + throw new SvcLogicException(e.getMessage()); + } + } + + @Override + public Map convertServiceTemplate2Properties(String serviceTemplateContent, + final Map context) throws SvcLogicException { + try { + ServiceTemplateUtils serviceTemplateUtils = new ServiceTemplateUtils(); + return serviceTemplateUtils.convertServiceTemplate2Properties(serviceTemplateContent, context); + } catch (Exception e) { + throw new SvcLogicException(e.getMessage()); + } + } + + @Override + public Map convertServiceTemplate2Properties(ServiceTemplate serviceTemplate, + final Map context) throws SvcLogicException { + try { + ServiceTemplateUtils serviceTemplateUtils = new ServiceTemplateUtils(); + return serviceTemplateUtils.convertServiceTemplate2Properties(serviceTemplate, context); + } catch (Exception e) { + throw new SvcLogicException(e.getMessage()); + } + } + + @SuppressWarnings("squid:S3776") + @Override + public SvcLogicContext assignInParamsFromModel(final SvcLogicContext context, final Map inParams) + throws SvcLogicException { + logger.debug("Processing component input param ({})", inParams); + try { + if (context != null && inParams != null && inParams.containsKey(ConfigModelConstant.PROPERTY_SELECTOR)) { + String componentKey = inParams.get(ConfigModelConstant.PROPERTY_SELECTOR); + if (StringUtils.isNotBlank(componentKey)) { + String nodeTemplateContent = + context.getAttribute(ConfigModelConstant.PROPERTY_NODE_TEMPLATES_DOT + componentKey); + logger.info("Processing node template content ({})", nodeTemplateContent); + if (StringUtils.isNotBlank(nodeTemplateContent)) { + NodeTemplate nodeTemplate = + TransformationUtils.readValue(nodeTemplateContent, NodeTemplate.class); + if (nodeTemplate != null && StringUtils.isNotBlank(nodeTemplate.getType())) { + String nodeTypeContent = context + .getAttribute(ConfigModelConstant.PROPERTY_NODE_TYPES_DOT + nodeTemplate.getType()); + NodeType nodetype = TransformationUtils.readValue(nodeTypeContent, NodeType.class); + if (nodetype != null) { + inParams.put(ConfigModelConstant.PROPERTY_CURRENT_NODETYPE_DERIVED_FROM, + nodetype.getDerivedFrom()); + NodePropertyUtils nodePropertyUtils = new NodePropertyUtils(context, inParams); + nodePropertyUtils.assignInParamsFromModel(nodetype, nodeTemplate); + } else { + throw new SvcLogicException( + String.format("Failed to get node type (%s) for node template (%s).", + nodeTemplate.getType(), componentKey)); + } + + } else { + throw new SvcLogicException(String + .format("Failed to convert content (%s) to node template.", nodeTemplateContent)); + } + } else { + throw new SvcLogicException(String + .format("Couldn't get node template content for component key (%s).", componentKey)); + } + } else { + throw new SvcLogicException( + String.format("Couldn't get component key (prefix) from inparam (%s)", inParams)); + } + } + } catch (Exception e) { + throw new SvcLogicException(e.getMessage()); + } + return context; + } + + @Override + public SvcLogicContext assignOutParamsFromModel(final SvcLogicContext context, final Map inParams) + throws SvcLogicException { + try { + if (context != null && inParams != null && inParams.containsKey(ConfigModelConstant.PROPERTY_SELECTOR)) { + String componentKey = inParams.get(ConfigModelConstant.PROPERTY_SELECTOR); + logger.info("Processing component output for prefix key ({})", componentKey); + if (StringUtils.isNotBlank(componentKey)) { + String nodeTemplateContent = + context.getAttribute(ConfigModelConstant.PROPERTY_NODE_TEMPLATES_DOT + componentKey); + if (StringUtils.isNotBlank(nodeTemplateContent)) { + NodeTemplate nodeTemplate = + TransformationUtils.readValue(nodeTemplateContent, NodeTemplate.class); + if (nodeTemplate != null && StringUtils.isNotBlank(nodeTemplate.getType())) { + String nodeTypeContent = context + .getAttribute(ConfigModelConstant.PROPERTY_NODE_TYPES_DOT + nodeTemplate.getType()); + NodeType nodetype = TransformationUtils.readValue(nodeTypeContent, NodeType.class); + NodePropertyUtils nodePropertyUtils = new NodePropertyUtils(context, inParams); + nodePropertyUtils.assignOutParamsFromModel(nodetype, nodeTemplate); + } + } + } + } + } catch (Exception e) { + throw new SvcLogicException(e.getMessage()); + } + return context; + } + + @Override + public String getNodeTemplateContent(final SvcLogicContext context, String templateName) throws SvcLogicException { + String content = null; + try { + if (context != null && StringUtils.isNotBlank(templateName)) { + logger.info("Processing Artifact Node Template for content : ({})", templateName); + content = context + .getAttribute(ConfigModelConstant.PROPERTY_NODE_TEMPLATES_DOT + templateName + ".content"); + } + } catch (Exception e) { + throw new SvcLogicException(e.getMessage()); + } + return content; + } + + @SuppressWarnings("squid:S3776") + @Override + public String getNodeTemplateMapping(final SvcLogicContext context, String templateName) throws SvcLogicException { + String mapping = null; + try { + if (context != null && StringUtils.isNotBlank(templateName)) { + logger.info("Processing artifact node template for mapping : ({})", templateName); + if (StringUtils.isNotBlank(templateName)) { + String nodeTemplateContent = + context.getAttribute(ConfigModelConstant.PROPERTY_NODE_TEMPLATES_DOT + templateName); + if (StringUtils.isNotBlank(nodeTemplateContent)) { + + NodeTemplate nodeTemplate = + TransformationUtils.readValue(nodeTemplateContent, NodeTemplate.class); + + if (nodeTemplate != null && nodeTemplate.getCapabilities() != null && nodeTemplate + .getCapabilities().containsKey(ConfigModelConstant.CAPABILITY_PROPERTY_MAPPING)) { + + CapabilityAssignment capability = + nodeTemplate.getCapabilities().get(ConfigModelConstant.CAPABILITY_PROPERTY_MAPPING); + if (capability.getProperties() != null) { + List mappingList = (List) capability.getProperties() + .get(ConfigModelConstant.CAPABILITY_PROPERTY_MAPPING); + if (mappingList != null) { + mapping = TransformationUtils.getJson(mappingList); + } + + } + } + } + } + } + } catch (Exception e) { + throw new SvcLogicException(e.getMessage()); + } + return mapping; + } + +} diff --git a/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/utils/ExpressionUtils.java b/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/utils/ExpressionUtils.java new file mode 100644 index 000000000..cdc8fc330 --- /dev/null +++ b/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/utils/ExpressionUtils.java @@ -0,0 +1,191 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2018 IBM. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.ccsdk.features.model.utils; + +import java.io.IOException; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; +import org.apache.commons.lang3.StringUtils; +import org.onap.ccsdk.features.model.ConfigModelConstant; +import org.onap.ccsdk.features.model.data.PropertyDefinition; +import org.onap.ccsdk.sli.core.sli.SvcLogicContext; +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.node.ObjectNode; + +public class ExpressionUtils { + private static EELFLogger logger = EELFManager.getInstance().getLogger(ExpressionUtils.class); + + private final SvcLogicContext context; + private final Map inParams; + + public ExpressionUtils(final SvcLogicContext context, final Map inParams) { + this.context = context; + this.inParams = inParams; + } + + public void populatePropertAssignmentsWithPrefix(String prefix, Map typeProperties, + Map templateProperties) throws IOException { + if (typeProperties != null && templateProperties != null) { + ObjectMapper mapper = new ObjectMapper(); + String templatejsonContent = mapper.writeValueAsString(templateProperties); + logger.debug("Expression inputs ({}).", templatejsonContent); + + JsonNode rootArray = mapper.readTree(templatejsonContent); + processJsonExpression(rootArray); + if (rootArray != null) { + Map prefixParams = new HashMap<>(); + TransformationUtils.convertJson2RootProperties(prefixParams, rootArray); + logger.info("Resolved inputs ({}).", rootArray); + prefixParams.forEach((key, value) -> { + this.inParams.put(prefix + "." + key, value); + }); + } + } + } + + public void populatePropertAssignments(Map typeProperties, + Map templateProperties) throws IOException { + if (typeProperties != null && templateProperties != null) { + ObjectMapper mapper = new ObjectMapper(); + String templatejsonContent = mapper.writeValueAsString(templateProperties); + logger.info("Expression inputs ({}).", templatejsonContent); + + JsonNode rootArray = mapper.readTree(templatejsonContent); + processJsonExpression(rootArray); + TransformationUtils.convertJson2RootProperties(this.inParams, rootArray); + logger.info("Resolved inputs ({}).", rootArray); + + } + } + + public void populateOutPropertAssignments(Map typeProperties, + Map templateProperties) throws IOException { + if (typeProperties != null && templateProperties != null) { + ObjectMapper mapper = new ObjectMapper(); + String templatejsonContent = mapper.writeValueAsString(templateProperties); + logger.info("Expression outputs ({}).", templatejsonContent); + + JsonNode rootArray = mapper.readTree(templatejsonContent); + processJsonExpression(rootArray); + logger.info("Resolved outputs ({}).", rootArray); + } + } + + public void processJsonExpression(JsonNode rootArray) throws IOException { + if (rootArray != null) { + Iterator> fields = rootArray.fields(); + while (fields.hasNext()) { + Map.Entry entry = fields.next(); + processJsonNode(rootArray, entry.getKey(), entry.getValue()); + } + } + } + + private void processJsonNode(JsonNode parentNode, String nodeName, JsonNode node) throws IOException { + if (node == null) { + // Do Nothing + } else if (node.isArray()) { + String[] a = new String[node.size()]; + + for (int i = 0; i < a.length; i++) { + processJsonNode(null, null, node.get(i)); + } + } else if (node.isObject()) { + + Iterator> fields = node.fields(); + while (fields.hasNext()) { + Map.Entry entry = fields.next(); + processJsonNode(node, entry.getKey(), entry.getValue()); + } + } else if (node.isTextual()) { + boolean expression = checkExpressionContent(node.asText()); + if (expression) { + processExpressionContent(parentNode, nodeName, node); + } + } + } + + private boolean checkExpressionContent(String content) { + return (StringUtils.isNotBlank(content) && (content.contains(ConfigModelConstant.EXPRESSION_GET_INPUT) + || content.contains(ConfigModelConstant.EXPRESSION_GET_ATTRIBUTE) + || content.contains(ConfigModelConstant.EXPRESSION_SET_VALUE))); + } + + @SuppressWarnings("squid:S3776") + private void processExpressionContent(JsonNode parentNode, String nodeName, JsonNode node) throws IOException { + + if (node != null && StringUtils.isNotBlank(node.asText())) { + String content = node.asText(); + ObjectMapper mapper = new ObjectMapper(); + Map expressionMap = mapper.readValue(content, Map.class); + boolean isExpressionNode = false; + + if (expressionMap != null) { + String expressionValue = null; + String expressionKey = null; + + if (expressionMap.containsKey(ConfigModelConstant.EXPRESSION_GET_INPUT)) { + isExpressionNode = true; + expressionKey = expressionMap.get(ConfigModelConstant.EXPRESSION_GET_INPUT); + expressionValue = resolveGetInputExpression(expressionKey, context); + if (expressionValue == null) { + expressionValue = resolveGetInputExpression("inputs." + expressionKey + ".default", context); + } + } else if (expressionMap.containsKey(ConfigModelConstant.EXPRESSION_GET_ATTRIBUTE)) { + isExpressionNode = true; + expressionValue = + context.getAttribute(expressionMap.get(ConfigModelConstant.EXPRESSION_GET_ATTRIBUTE)); + } else if (expressionMap.containsKey(ConfigModelConstant.EXPRESSION_SET_VALUE)) { + isExpressionNode = true; + expressionKey = expressionMap.get(ConfigModelConstant.EXPRESSION_SET_VALUE); + expressionValue = context.getAttribute(expressionKey); + + if (StringUtils.isNotBlank(expressionKey)) { + context.setAttribute(expressionKey, expressionValue); + } + } + + if (isExpressionNode && expressionValue == null) { + ((ObjectNode) parentNode).put(nodeName, ""); + } + if (StringUtils.isNotBlank(expressionValue)) { + if (expressionValue.trim().startsWith("[") || expressionValue.trim().startsWith("{")) { + JsonNode valueNode = mapper.readTree(expressionValue); + ((ObjectNode) parentNode).put(nodeName, valueNode); + } else { + ((ObjectNode) parentNode).put(nodeName, expressionValue); + } + } + logger.debug("expression ({}), expression key ({}), expression Value ({})", expressionMap, + expressionKey, expressionValue); + } + } + } + + private String resolveGetInputExpression(String key, final SvcLogicContext context) { + if (StringUtils.isNotBlank(key) && context != null) { + return context.getAttribute(key); + } + return null; + } + +} diff --git a/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/utils/JsonParserUtils.java b/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/utils/JsonParserUtils.java new file mode 100644 index 000000000..d9cc3507f --- /dev/null +++ b/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/utils/JsonParserUtils.java @@ -0,0 +1,59 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2018 IBM. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.ccsdk.features.model.utils; + +import static com.jayway.jsonpath.JsonPath.using; +import java.util.List; +import com.fasterxml.jackson.databind.JsonNode; +import com.jayway.jsonpath.Configuration; +import com.jayway.jsonpath.Option; +import com.jayway.jsonpath.spi.json.JacksonJsonNodeJsonProvider; +import com.jayway.jsonpath.spi.mapper.JacksonMappingProvider; + +@SuppressWarnings("squid:S1118") +public class JsonParserUtils { + + public static final Configuration JACKSON_JSON_NODE_CONFIGURATION = Configuration.builder() + .mappingProvider(new JacksonMappingProvider()).jsonProvider(new JacksonJsonNodeJsonProvider()).build(); + + public static final Configuration PATH_CONFIGURATION = Configuration.builder().options(Option.AS_PATH_LIST).build(); + + public static List paths(String jsonContent, String expression) { + return using(PATH_CONFIGURATION).parse(jsonContent).read(expression); + } + + public static List paths(JsonNode jsonNode, String expression) { + return paths(jsonNode.toString(), expression); + } + + public static JsonNode parse(String jsonContent, String expression) { + return using(JACKSON_JSON_NODE_CONFIGURATION).parse(jsonContent).read(expression); + } + + public static JsonNode parse(JsonNode jsonNode, String expression) { + return parse(jsonNode.toString(), expression); + } + + public static JsonNode parseNSet(String jsonContent, String expression, JsonNode value) { + return using(JACKSON_JSON_NODE_CONFIGURATION).parse(jsonContent).set(expression, value).json(); + } + + public static JsonNode parseNSet(JsonNode jsonNode, String expression, JsonNode valueNode) { + return parseNSet(jsonNode.toString(), expression, valueNode); + } +} diff --git a/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/utils/JsonUtils.java b/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/utils/JsonUtils.java new file mode 100644 index 000000000..11f4de3e0 --- /dev/null +++ b/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/utils/JsonUtils.java @@ -0,0 +1,110 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2018 IBM. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.ccsdk.features.model.utils; + +import org.onap.ccsdk.features.model.ValidTypes; + +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.node.ArrayNode; +import com.fasterxml.jackson.databind.node.NullNode; +import com.fasterxml.jackson.databind.node.ObjectNode; + +/** + * JsonUtils.java Purpose: Provide Configuration Generator JsonUtils Information + * + * @version 1.0 + */ +public class JsonUtils { + + private JsonUtils() { + + } + + public static void populatePrimitiveValues(String key, Object value, String primitiveType, ObjectNode objectNode) { + if (ValidTypes.DATA_TYPE_BOOLEAN.equals(primitiveType)) { + objectNode.put(key, (Boolean) value); + } else if (ValidTypes.DATA_TYPE_INTEGER.equals(primitiveType)) { + objectNode.put(key, (Integer) value); + } else if (ValidTypes.DATA_TYPE_FLOAT.equals(primitiveType)) { + objectNode.put(key, (Float) value); + } else if (ValidTypes.DATA_TYPE_TIMESTAMP.equals(primitiveType)) { + objectNode.put(key, (String) value); + } else { + objectNode.put(key, (String) value); + } + } + + public static void populatePrimitiveValues(Object value, String primitiveType, ArrayNode objectNode) { + if (ValidTypes.DATA_TYPE_BOOLEAN.equals(primitiveType)) { + objectNode.add((Boolean) value); + } else if (ValidTypes.DATA_TYPE_INTEGER.equals(primitiveType)) { + objectNode.add((Integer) value); + } else if (ValidTypes.DATA_TYPE_FLOAT.equals(primitiveType)) { + objectNode.add((Float) value); + } else if (ValidTypes.DATA_TYPE_TIMESTAMP.equals(primitiveType)) { + objectNode.add((String) value); + } else { + objectNode.add((String) value); + } + } + + public static void populatePrimitiveDefaultValues(String key, String primitiveType, ObjectNode objectNode) { + if (ValidTypes.DATA_TYPE_BOOLEAN.equals(primitiveType)) { + objectNode.put(key, false); + } else if (ValidTypes.DATA_TYPE_INTEGER.equals(primitiveType)) { + objectNode.put(key, 0); + } else if (ValidTypes.DATA_TYPE_FLOAT.equals(primitiveType)) { + objectNode.put(key, 0.0); + } else { + objectNode.put(key, ""); + } + } + + public static void populatePrimitiveDefaultValuesForArrayNode(String primitiveType, ArrayNode arrayNode) { + if (ValidTypes.DATA_TYPE_BOOLEAN.equals(primitiveType)) { + arrayNode.add(false); + } else if (ValidTypes.DATA_TYPE_INTEGER.equals(primitiveType)) { + arrayNode.add(0); + } else if (ValidTypes.DATA_TYPE_FLOAT.equals(primitiveType)) { + arrayNode.add(0.0); + } else { + arrayNode.add(""); + } + } + + public static void populateJsonNodeValues(String key, JsonNode nodeValue, String type, ObjectNode objectNode) { + if (nodeValue == null || nodeValue instanceof NullNode) { + objectNode.put(key, nodeValue); + } else if (ValidTypes.getPrimitivePropertType().contains(type)) { + if (ValidTypes.DATA_TYPE_BOOLEAN.equals(type)) { + objectNode.put(key, nodeValue.asBoolean()); + } else if (ValidTypes.DATA_TYPE_INTEGER.equals(type)) { + objectNode.put(key, nodeValue.asInt()); + } else if (ValidTypes.DATA_TYPE_FLOAT.equals(type)) { + objectNode.put(key, nodeValue.floatValue()); + } else if (ValidTypes.DATA_TYPE_TIMESTAMP.equals(type)) { + objectNode.put(key, nodeValue.asText()); + } else { + objectNode.put(key, nodeValue.asText()); + } + } else { + objectNode.set(key, nodeValue); + } + } + +} diff --git a/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/utils/NodePropertyUtils.java b/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/utils/NodePropertyUtils.java new file mode 100644 index 000000000..0feb8b5a7 --- /dev/null +++ b/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/utils/NodePropertyUtils.java @@ -0,0 +1,187 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2018 IBM. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.ccsdk.features.model.utils; + +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; +import org.apache.commons.lang3.StringUtils; +import org.onap.ccsdk.features.model.ConfigModelConstant; +import org.onap.ccsdk.features.model.data.CapabilityAssignment; +import org.onap.ccsdk.features.model.data.CapabilityDefinition; +import org.onap.ccsdk.features.model.data.InterfaceAssignment; +import org.onap.ccsdk.features.model.data.InterfaceDefinition; +import org.onap.ccsdk.features.model.data.NodeTemplate; +import org.onap.ccsdk.features.model.data.NodeType; +import org.onap.ccsdk.features.model.data.OperationAssignment; +import org.onap.ccsdk.features.model.data.OperationDefinition; +import org.onap.ccsdk.features.model.data.PropertyDefinition; +import org.onap.ccsdk.sli.core.sli.SvcLogicContext; +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; + +public class NodePropertyUtils { + + private static EELFLogger logger = EELFManager.getInstance().getLogger(NodePropertyUtils.class); + private final SvcLogicContext context; + private final Map inParams; + private ExpressionUtils jsonExpressionUtils; + + public NodePropertyUtils(final SvcLogicContext context, final Map inParams) { + this.context = context; + this.inParams = inParams; + jsonExpressionUtils = new ExpressionUtils(this.context, this.inParams); + } + + @SuppressWarnings("squid:S3776") + public SvcLogicContext assignInParamsFromModel(NodeType nodetype, NodeTemplate nodeTemplate) throws IOException { + if (nodeTemplate != null) { + Map inputs = null; + // Populate the Type inputs + Map nodeTypeinputs = new HashMap<>(); + for (Map.Entry nodeTypeInterface : nodetype.getInterfaces().entrySet()) { + if (nodeTypeInterface != null && nodeTypeInterface.getValue() != null) { + for (Map.Entry nodeTypeOperation : nodeTypeInterface.getValue() + .getOperations().entrySet()) { + nodeTypeinputs = nodeTypeOperation.getValue().getInputs(); + logger.trace("Populated node type input ({}).", nodeTypeinputs); + } + } + } + + if (!nodeTypeinputs.isEmpty()) { + // Populate the Template inputs + for (Map.Entry nodeTemplateInterface : nodeTemplate.getInterfaces() + .entrySet()) { + if (nodeTemplateInterface != null && nodeTemplateInterface.getValue() != null) { + this.inParams.put(ConfigModelConstant.PROPERTY_CURRENT_INTERFACE, + nodeTemplateInterface.getKey()); + for (Map.Entry nodeTemplateOperation : nodeTemplateInterface + .getValue().getOperations().entrySet()) { + if (nodeTemplateOperation != null) { + this.inParams.put(ConfigModelConstant.PROPERTY_CURRENT_OPERATION, + nodeTemplateOperation.getKey()); + if (StringUtils.isNotBlank(nodeTemplateOperation.getValue().getImplementation())) { + this.inParams.put(ConfigModelConstant.PROPERTY_CURRENT_IMPLEMENTATION, + nodeTemplateOperation.getValue().getImplementation()); + } + inputs = nodeTemplateOperation.getValue().getInputs(); + logger.trace("Populated node template input({}).", inputs); + // Assign Default Values & Types + jsonExpressionUtils.populatePropertAssignments(nodeTypeinputs, inputs); + } + } + } + } + } + + if (nodeTemplate.getRequirements() != null && !nodeTemplate.getRequirements().isEmpty()) { + assignInParamsFromRequirementModel(nodeTemplate, context, inParams); + } + } + return context; + } + + @SuppressWarnings("squid:S3776") + public SvcLogicContext assignOutParamsFromModel(NodeType nodetype, NodeTemplate nodeTemplate) throws IOException { + + if (nodeTemplate != null) { + Map outputs = null; + // Populate the Type Outputs + Map nodeTypeOutputs = new HashMap<>(); + + for (Map.Entry nodeTypeInterface : nodetype.getInterfaces().entrySet()) { + if (nodeTypeInterface != null && nodeTypeInterface.getValue() != null) { + for (Map.Entry nodeTypeOperation : nodeTypeInterface.getValue() + .getOperations().entrySet()) { + nodeTypeOutputs = nodeTypeOperation.getValue().getOutputs(); + logger.info("Populated node type output ({}).", nodeTypeOutputs); + } + } + } + + if (!nodeTypeOutputs.isEmpty()) { + // Populate the Template Outputs + for (Map.Entry nodeTemplateInterface : nodeTemplate.getInterfaces() + .entrySet()) { + if (nodeTemplateInterface != null && nodeTemplateInterface.getValue() != null) { + for (Map.Entry nodeTemplateOperation : nodeTemplateInterface + .getValue().getOperations().entrySet()) { + outputs = nodeTemplateOperation.getValue().getOutputs(); + logger.info("Populated node template output ({}).", outputs); + // Assign Default Values & Types + jsonExpressionUtils.populateOutPropertAssignments(nodeTypeOutputs, outputs); + // TO DO + } + } + } + } + } + return context; + } + + @SuppressWarnings({"squid:S3776", "squid:S00112"}) + public SvcLogicContext assignInParamsFromRequirementModel(NodeTemplate nodeTemplate, final SvcLogicContext context, + final Map inParams) { + if (nodeTemplate != null && nodeTemplate.getRequirements() != null && context != null && inParams != null) { + nodeTemplate.getRequirements().forEach((requrementKey, requirement) -> { + if (requirement != null && StringUtils.isNotBlank(requirement.getNode()) + && StringUtils.isNotBlank(requirement.getCapability())) { + String requirementNodeTemplateContent = context + .getAttribute(ConfigModelConstant.PROPERTY_NODE_TEMPLATES_DOT + requirement.getNode()); + logger.info("Processing requirement node ({}) template content ({}) ", requirement.getNode(), + requirementNodeTemplateContent); + NodeTemplate requirementNodeTemplate = + TransformationUtils.readValue(requirementNodeTemplateContent, NodeTemplate.class); + if (requirementNodeTemplate != null && requirementNodeTemplate.getCapabilities() != null) { + String nodeTypeContent = context.getAttribute( + ConfigModelConstant.PROPERTY_NODE_TYPES_DOT + requirementNodeTemplate.getType()); + NodeType nodeType = TransformationUtils.readValue(nodeTypeContent, NodeType.class); + if (nodeType != null && nodeType.getCapabilities() != null + && nodeType.getCapabilities().containsKey(requirement.getCapability())) { + CapabilityDefinition capabilityDefinition = + nodeType.getCapabilities().get(requirement.getCapability()); + if (capabilityDefinition != null) { + CapabilityAssignment capabilityAssignment = + requirementNodeTemplate.getCapabilities().get(requirement.getCapability()); + try { + assignInParamsFromCapabilityModel(requrementKey, capabilityDefinition, + capabilityAssignment, context); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + } + } + } + }); + } + return context; + } + + public SvcLogicContext assignInParamsFromCapabilityModel(String requirementName, + CapabilityDefinition capabilityDefinition, CapabilityAssignment capabilityAssignment, + final SvcLogicContext context) throws IOException { + if (capabilityAssignment != null && capabilityAssignment.getProperties() != null) { + jsonExpressionUtils.populatePropertAssignmentsWithPrefix(requirementName, + capabilityDefinition.getProperties(), capabilityAssignment.getProperties()); + } + return context; + } + +} diff --git a/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/utils/PrepareContextUtils.java b/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/utils/PrepareContextUtils.java new file mode 100644 index 000000000..6678a1245 --- /dev/null +++ b/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/utils/PrepareContextUtils.java @@ -0,0 +1,64 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2018 IBM. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.ccsdk.features.model.utils; + +import java.util.HashMap; +import java.util.Map; +import org.apache.commons.lang3.StringUtils; +import org.onap.ccsdk.features.model.ConfigModelConstant; + +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; + +public class PrepareContextUtils { + + private static EELFLogger logger = EELFManager.getInstance().getLogger(PrepareContextUtils.class); + + public Map prepareContext(Map context, String input, String serviceTemplateContent) + throws Exception { + if (StringUtils.isNotBlank(serviceTemplateContent)) { + + if (context == null) { + context = new HashMap<>(); + } + if (StringUtils.isNotBlank(input)) { + TransformationUtils.convertJson2RootProperties(context, input); + } + + String recipeName = context.get(ConfigModelConstant.PROPERTY_ACTION_NAME); + if (StringUtils.isNotBlank(recipeName)) { + String recipeInputName = + recipeName.replace(ConfigModelConstant.PROPERTY_RECIPE, ConfigModelConstant.PROPERTY_REQUEST); + String recipeInput = context.get(recipeInputName); + if (StringUtils.isNotBlank(recipeInput)) { + // Un necessary to hold the Recipe Request, It is already in input + context.remove(recipeInputName); + context.remove(ConfigModelConstant.PROPERTY_PAYLOAD); + TransformationUtils.convertJson2RootProperties(context, recipeInput); + logger.info("Converted recipe ({}) request inputs to context.", recipeName); + } + } + + ServiceTemplateUtils serviceTemplateUtils = new ServiceTemplateUtils(); + serviceTemplateUtils.convertServiceTemplate2Properties(serviceTemplateContent, context); + } + return context; + + } + +} diff --git a/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/utils/ResourceAssignmentUtils.java b/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/utils/ResourceAssignmentUtils.java new file mode 100644 index 000000000..371acddf6 --- /dev/null +++ b/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/utils/ResourceAssignmentUtils.java @@ -0,0 +1,303 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2018 IBM. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.ccsdk.features.model.utils; + +import java.util.Date; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; +import org.apache.commons.lang3.BooleanUtils; +import org.apache.commons.lang3.StringUtils; +import org.onap.ccsdk.features.model.ConfigModelConstant; +import org.onap.ccsdk.features.model.ConfigModelException; +import org.onap.ccsdk.features.model.ValidTypes; +import org.onap.ccsdk.features.model.data.ResourceAssignment; +import org.onap.ccsdk.features.model.data.dict.ResourceDefinition; + +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.node.ArrayNode; +import com.fasterxml.jackson.databind.node.NullNode; +import com.fasterxml.jackson.databind.node.ObjectNode; +import com.google.common.base.Preconditions; + +public class ResourceAssignmentUtils { + + private ResourceAssignmentUtils() { + + } + + private static EELFLogger logger = EELFManager.getInstance().getLogger(ResourceAssignmentUtils.class); + + public static String getArtifactNodeContent(String nodeTemplateName, Map context) { + Preconditions.checkArgument(StringUtils.isNotBlank(nodeTemplateName), + "getArtifactNodeContent missing template name"); + return (String) context.get(ConfigModelConstant.PROPERTY_NODE_TEMPLATES_DOT + nodeTemplateName + ".content"); + } + + public static List getArtifactNodeMapping(String nodeTemplateName, + Map context) { + Preconditions.checkArgument(StringUtils.isNotBlank(nodeTemplateName), + "getArtifactNodeMapping missing template name"); + List resourceAssignments = null; + String resourceMappingContent = + (String) context.get(ConfigModelConstant.PROPERTY_NODE_TEMPLATES_DOT + nodeTemplateName + ".mapping"); + if (StringUtils.isNotBlank(resourceMappingContent)) { + resourceAssignments = TransformationUtils.getListfromJson(resourceMappingContent, ResourceAssignment.class); + + } else { + logger.warn("missing mapping content for node template ({})", nodeTemplateName); + } + return resourceAssignments; + } + + // Not used Any whre + public static synchronized void cleanContextTemplateNDictionaryKeys(Map componentContext) { + String recipeName = (String) componentContext.get(ConfigModelConstant.PROPERTY_ACTION_NAME); + Set removeSet = new HashSet<>(); + componentContext.forEach((key, value) -> { + if (StringUtils.isNotBlank(key) + && (key.startsWith(ConfigModelConstant.PROPERTY_DICTIONARY_KEY_DOT + recipeName + ".") + || key.startsWith(ConfigModelConstant.PROPERTY_RECIPE_KEY_DOT + recipeName + "."))) { + removeSet.add(key); + } + }); + componentContext.keySet().removeAll(removeSet); + } + + public static synchronized Object getDictionaryKeyValue(Map componentContext, + ResourceAssignment resourceMapping) { + Object value = null; + if (resourceMapping != null && componentContext != null) { + String recipeName = (String) componentContext.get(ConfigModelConstant.PROPERTY_ACTION_NAME); + String dictionaryKeyName = resourceMapping.getDictionaryName(); + value = componentContext + .get(ConfigModelConstant.PROPERTY_DICTIONARY_KEY_DOT + recipeName + "." + dictionaryKeyName); + } + return value; + } + + public static synchronized Object getDictionaryKeyValue(Map componentContext, + ResourceDefinition resourceDictionary) { + Object value = null; + if (resourceDictionary != null && componentContext != null) { + String recipeName = (String) componentContext.get(ConfigModelConstant.PROPERTY_ACTION_NAME); + String dictionaryKeyName = resourceDictionary.getName(); + value = componentContext + .get(ConfigModelConstant.PROPERTY_DICTIONARY_KEY_DOT + recipeName + "." + dictionaryKeyName); + } + return value; + } + + public static synchronized Object getTemplateKeyValue(Map componentContext, + ResourceAssignment resourceMapping) { + Object value = null; + if (resourceMapping != null && componentContext != null) { + String recipeName = (String) componentContext.get(ConfigModelConstant.PROPERTY_ACTION_NAME); + String templateKeyName = resourceMapping.getName(); + value = componentContext + .get(ConfigModelConstant.PROPERTY_RECIPE_KEY_DOT + recipeName + "." + templateKeyName); + } + return value; + } + + public static synchronized void setResourceDataValue(Map componentContext, + ResourceAssignment resourceAssignment, Object value) throws ConfigModelException { + + if (resourceAssignment != null && StringUtils.isNotBlank(resourceAssignment.getName()) + && resourceAssignment.getProperty() != null) { + + String recipeName = (String) componentContext.get(ConfigModelConstant.PROPERTY_ACTION_NAME); + String templateKeyName = resourceAssignment.getName(); + String dictionaryKeyName = resourceAssignment.getDictionaryName(); + + if (StringUtils.isBlank(dictionaryKeyName)) { + resourceAssignment.setDictionaryName(templateKeyName); + dictionaryKeyName = templateKeyName; + logger.warn("Missing dictionary key, setting with template key ({}) as dictionary key ({})", + templateKeyName, dictionaryKeyName); + } + String type = resourceAssignment.getProperty().getType(); + try { + if (StringUtils.isNotBlank(type)) { + Object convertedValue = convertResourceValue(type, value); + + componentContext.put( + ConfigModelConstant.PROPERTY_DICTIONARY_KEY_DOT + recipeName + "." + dictionaryKeyName, + convertedValue); + componentContext.put( + ConfigModelConstant.PROPERTY_RECIPE_KEY_DOT + recipeName + "." + templateKeyName, + convertedValue); + + logger.trace("Setting Resource Value ({}) for Resource Name ({}) of type ({}) ", convertedValue, + dictionaryKeyName, type); + + resourceAssignment.getProperty().setValue(convertedValue); + resourceAssignment.setUpdatedDate(new Date()); + resourceAssignment.setUpdatedBy(ConfigModelConstant.USER_SYSTEM); + resourceAssignment.setStatus(ConfigModelConstant.STATUS_SUCCESS); + } + } catch (Exception e) { + throw new ConfigModelException(String.format( + "Failed in setting value for template key (%s) and dictionary key (%s) of type (%s) with error message (%s)", + templateKeyName, dictionaryKeyName, type, e.getMessage())); + } + } else { + throw new ConfigModelException( + String.format("Failed in setting resource value for resource mapping (%s)", resourceAssignment)); + } + } + + private static Object convertResourceValue(String type, Object value) { + Object convertedValue = null; + + if (value == null || value instanceof NullNode) { + logger.info("Returning {} value from convertResourceValue", value); + return null; + } + + if (ValidTypes.getPrimitivePropertType().contains(type)) { + convertedValue = convertPrimitiveResourceValue(type, value); + } else { + // Case where Resource is non-primitive type + if (value instanceof JsonNode || value instanceof ObjectNode || value instanceof ArrayNode) { + convertedValue = value; + } else if (value instanceof String) { + convertedValue = TransformationUtils.getJsonNodeForString((String) value); + } else { + convertedValue = TransformationUtils.getJsonNodeForObject(value); + } + } + return convertedValue; + } + + @SuppressWarnings("squid:S3776") + private static Object convertPrimitiveResourceValue(String type, Object value) { + Object convertedValue = value; + + if (value instanceof ArrayNode) { + if (ValidTypes.DATA_TYPE_BOOLEAN.equalsIgnoreCase(type)) { + convertedValue = ((ArrayNode) value).asBoolean(); + } else if (ValidTypes.DATA_TYPE_INTEGER.equalsIgnoreCase(type)) { + convertedValue = ((ArrayNode) value).asInt(); + } else if (ValidTypes.DATA_TYPE_FLOAT.equalsIgnoreCase(type)) { + convertedValue = Float.valueOf(((ArrayNode) value).toString()); + } else { + convertedValue = ((ArrayNode) value).toString(); + } + } else if (value instanceof JsonNode) { + if (ValidTypes.DATA_TYPE_BOOLEAN.equalsIgnoreCase(type)) { + convertedValue = ((JsonNode) value).asBoolean(); + } else if (ValidTypes.DATA_TYPE_INTEGER.equalsIgnoreCase(type)) { + convertedValue = ((JsonNode) value).asInt(); + } else if (ValidTypes.DATA_TYPE_FLOAT.equalsIgnoreCase(type)) { + convertedValue = Float.valueOf(((JsonNode) value).asText()); + } else { + convertedValue = ((JsonNode) value).asText(); + } + } else if (value instanceof String) { + if (ValidTypes.DATA_TYPE_BOOLEAN.equalsIgnoreCase(type)) { + convertedValue = Boolean.valueOf((String) value); + } else if (ValidTypes.DATA_TYPE_INTEGER.equalsIgnoreCase(type)) { + convertedValue = Integer.valueOf((String) value); + } else if (ValidTypes.DATA_TYPE_FLOAT.equalsIgnoreCase(type)) { + convertedValue = Float.valueOf((String) value); + } + } + logger.info("Returning value ({}) from convertPrimitiveResourceValue", convertedValue); + return convertedValue; + } + + @SuppressWarnings("squid:S1172") + public static synchronized void setFailedResourceDataValue(Map componentContext, + ResourceAssignment resourceAssignment, String message) { + setFailedResourceDataValue(resourceAssignment, message); + } + + public static synchronized void setFailedResourceDataValue(ResourceAssignment resourceAssignment, String message) { + if (resourceAssignment != null && StringUtils.isNotBlank(resourceAssignment.getName()) + && resourceAssignment.getProperty() != null) { + resourceAssignment.setUpdatedDate(new Date()); + resourceAssignment.setStatus(ConfigModelConstant.STATUS_FAILURE); + resourceAssignment.setUpdatedBy(ConfigModelConstant.USER_SYSTEM); + resourceAssignment.setMessage(message); + } + } + + public static synchronized void assertTemplateKeyValueNotNull(Map componentContext, + ResourceAssignment resourceAssignment) throws ConfigModelException { + if (resourceAssignment != null && resourceAssignment.getProperty() != null + && BooleanUtils.isTrue(resourceAssignment.getProperty().getRequired()) + && getTemplateKeyValue(componentContext, resourceAssignment) == null) { + logger.error("failed to populate mandatory resource mapping ({})", resourceAssignment); + throw new ConfigModelException( + String.format("failed to populate mandatory resource mapping (%s)", resourceAssignment)); + } + } + + @SuppressWarnings({"squid:S3776", "squid:S1141"}) + public static synchronized String generateResourceDataForAssignments(List assignments) + throws ConfigModelException { + String result = "{}"; + try { + ObjectMapper mapper = new ObjectMapper(); + JsonNode root = mapper.readTree(result); + for (ResourceAssignment resourceMapping : assignments) { + if (resourceMapping != null && resourceMapping.getName() != null + && resourceMapping.getProperty() != null) { + + String type = resourceMapping.getProperty().getType(); + Object value = resourceMapping.getProperty().getValue(); + logger.info("Generating Resource name ({}), type ({}), value ({})", resourceMapping.getName(), type, + value); + if (value == null) { + ((ObjectNode) root).set(resourceMapping.getName(), null); + } else if (value instanceof JsonNode) { + ((ObjectNode) root).put(resourceMapping.getName(), (JsonNode) value); + } else if (ValidTypes.DATA_TYPE_STRING.equalsIgnoreCase(type)) { + ((ObjectNode) root).put(resourceMapping.getName(), (String) value); + } else if (ValidTypes.DATA_TYPE_BOOLEAN.equalsIgnoreCase(type)) { + ((ObjectNode) root).put(resourceMapping.getName(), (Boolean) value); + } else if (ValidTypes.DATA_TYPE_INTEGER.equalsIgnoreCase(type)) { + ((ObjectNode) root).put(resourceMapping.getName(), (Integer) value); + } else if (ValidTypes.DATA_TYPE_FLOAT.equalsIgnoreCase(type)) { + ((ObjectNode) root).put(resourceMapping.getName(), (Float) value); + } else if (ValidTypes.DATA_TYPE_TIMESTAMP.equalsIgnoreCase(type)) { + ((ObjectNode) root).put(resourceMapping.getName(), (String) value); + } else { + JsonNode jsonNode = TransformationUtils.getJsonNodeForObject(value); + if (jsonNode != null) { + ((ObjectNode) root).put(resourceMapping.getName(), jsonNode); + } else { + ((ObjectNode) root).set(resourceMapping.getName(), null); + } + } + } + } + result = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(root); + logger.info("Generated Resource Param Data ({})", result); + } catch (Exception e) { + throw new ConfigModelException(e.getMessage(), e); + } + return result; + } + +} diff --git a/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/utils/ResourceDictionaryUtils.java b/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/utils/ResourceDictionaryUtils.java new file mode 100644 index 000000000..c73f67c05 --- /dev/null +++ b/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/utils/ResourceDictionaryUtils.java @@ -0,0 +1,120 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2018 IBM. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.ccsdk.features.model.utils; + +import java.util.Map; +import java.util.Optional; +import java.util.function.Supplier; +import org.apache.commons.collections.CollectionUtils; +import org.apache.commons.collections.MapUtils; +import org.apache.commons.lang3.StringUtils; +import org.onap.ccsdk.features.model.ConfigModelConstant; +import org.onap.ccsdk.features.model.data.PropertyDefinition; +import org.onap.ccsdk.features.model.data.ResourceAssignment; +import org.onap.ccsdk.features.model.data.dict.ResourceDefinition; +import org.onap.ccsdk.features.model.data.dict.SourcesDefinition; + +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; + +/** + * ResourceDictionaryUtils.java Purpose to provide ResourceDictionaryUtils + * + * @version 1.0 + */ +public class ResourceDictionaryUtils { + + private ResourceDictionaryUtils() { + // Do nothing + } + + private static EELFLogger logger = EELFManager.getInstance().getLogger(ResourceDictionaryUtils.class); + + /** + * This Method is to assign the source name to the Dictionary Definition Check to see if the source + * definition is not present then assign, if more than one source then assign only one source. + * + * @param resourceAssignment + * @param resourceDefinition + */ + @SuppressWarnings("squid:S3776") + public static void populateSourceMapping(ResourceAssignment resourceAssignment, + ResourceDefinition resourceDefinition) { + + if (resourceAssignment != null && resourceDefinition != null + && StringUtils.isBlank(resourceAssignment.getDictionarySource())) { + + setProperty(resourceAssignment, resourceDefinition); + Map sourcesDefinition = resourceDefinition.getSources(); + + if (sourcesDefinition != null && MapUtils.isNotEmpty(sourcesDefinition) && sourcesDefinition.size() == 1) { + if (sourcesDefinition.get("input") != null) { + resourceAssignment.setDictionarySource(ConfigModelConstant.SOURCE_INPUT); + } else if (sourcesDefinition.get("default") != null) { + resourceAssignment.setDictionarySource(ConfigModelConstant.SOURCE_DEFAULT); + } else if (sourcesDefinition.get("db") != null) { + resourceAssignment.setDictionarySource(ConfigModelConstant.SOURCE_DB); + if (resolve(() -> sourcesDefinition.get("db").getProperties().getDependencies()).isPresent() + && CollectionUtils + .isNotEmpty(sourcesDefinition.get("db").getProperties().getDependencies())) { + resourceAssignment + .setDependencies(sourcesDefinition.get("db").getProperties().getDependencies()); + } + } else if (sourcesDefinition.get("mdsal") != null) { + resourceAssignment.setDictionarySource(ConfigModelConstant.SOURCE_MDSAL); + if (resolve(() -> sourcesDefinition.get("mdsal").getProperties().getDependencies()).isPresent() + && CollectionUtils + .isNotEmpty(sourcesDefinition.get("mdsal").getProperties().getDependencies())) { + resourceAssignment + .setDependencies(sourcesDefinition.get("mdsal").getProperties().getDependencies()); + } + } + logger.info("automapped resourceAssignment : {}", resourceAssignment); + } + } + } + + public static Optional resolve(Supplier resolver) { + try { + T result = resolver.get(); + return Optional.ofNullable(result); + } catch (NullPointerException e) { + return Optional.empty(); + } + } + + /** + * Overriding ResourceAssignment Properties with properties defined in Dictionary + */ + private static void setProperty(ResourceAssignment resourceAssignment, ResourceDefinition resourceDefinition) { + if (StringUtils.isNotBlank(resourceDefinition.getProperty().getType())) { + PropertyDefinition property = resourceAssignment.getProperty(); + if (property == null) { + property = new PropertyDefinition(); + } + if (resourceDefinition.getProperty() != null) { + property.setType(resourceDefinition.getProperty().getType()); + if (resourceDefinition.getProperty().getEntrySchema() != null) { + property.setEntrySchema(resourceDefinition.getProperty().getEntrySchema()); + } + resourceAssignment.setProperty(property); + } + } + } + +} diff --git a/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/utils/ServiceTemplateUtils.java b/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/utils/ServiceTemplateUtils.java new file mode 100644 index 000000000..c63719875 --- /dev/null +++ b/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/utils/ServiceTemplateUtils.java @@ -0,0 +1,277 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2018 IBM. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.ccsdk.features.model.utils; + +import java.util.Map; +import org.apache.commons.collections.MapUtils; +import org.apache.commons.lang3.StringUtils; +import org.onap.ccsdk.features.model.ConfigModelConstant; +import org.onap.ccsdk.features.model.data.InterfaceAssignment; +import org.onap.ccsdk.features.model.data.InterfaceDefinition; +import org.onap.ccsdk.features.model.data.NodeTemplate; +import org.onap.ccsdk.features.model.data.NodeType; +import org.onap.ccsdk.features.model.data.OperationAssignment; +import org.onap.ccsdk.features.model.data.OperationDefinition; +import org.onap.ccsdk.features.model.data.ServiceTemplate; +import org.onap.ccsdk.features.model.data.TopologyTemplate; +import org.onap.ccsdk.sli.core.sli.SvcLogicContext; +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; + +public class ServiceTemplateUtils { + private static EELFLogger logger = EELFManager.getInstance().getLogger(ServiceTemplateUtils.class); + + public Map convertServiceTemplate2Properties(String serviceTemplateContent, + final Map context) { + if (StringUtils.isNotBlank(serviceTemplateContent)) { + ServiceTemplate serviceTemplate = + TransformationUtils.readValue(serviceTemplateContent, ServiceTemplate.class); + convertServiceTemplate2Properties(serviceTemplate, context); + } + return context; + } + + public Map convertServiceTemplate2Properties(ServiceTemplate serviceTemplate, + final Map context) { + if (serviceTemplate != null) { + convertServiceTemplateMetadata2Properties(serviceTemplate, context); + convertServiceTemplateInputs2Properties(serviceTemplate, context); + convertDataTypes2Properties(serviceTemplate, context); + convertNode2Properties(serviceTemplate, context); + } + return context; + } + + public Map convertServiceTemplateMetadata2Properties(ServiceTemplate serviceTemplate, + final Map context) { + + if (serviceTemplate != null && serviceTemplate.getMetadata() != null) { + serviceTemplate.getMetadata().forEach((metaDataKey, metadata) -> { + context.put(metaDataKey, metadata); + }); + } + return context; + } + + public Map convertServiceTemplateInputs2Properties(ServiceTemplate serviceTemplate, + final Map context) { + + if (serviceTemplate != null && serviceTemplate.getTopologyTemplate() != null + && serviceTemplate.getTopologyTemplate().getInputs() != null) { + + serviceTemplate.getTopologyTemplate().getInputs().forEach((paramKey, parameterDefinition) -> { + if (parameterDefinition != null) { + context.put(ConfigModelConstant.PROPERTY_INPUTS_DOT + paramKey + ".type", + parameterDefinition.getType()); + if (parameterDefinition.getRequired()) { + context.put(ConfigModelConstant.PROPERTY_INPUTS_DOT + paramKey + ".required", + String.valueOf(parameterDefinition.getRequired())); + } + if (parameterDefinition.getDefaultValue() != null) { + context.put(ConfigModelConstant.PROPERTY_INPUTS_DOT + paramKey + ".default", + String.valueOf(parameterDefinition.getDefaultValue())); + } + } + }); + } + return context; + } + + public Map convertDataTypes2Properties(ServiceTemplate serviceTemplate, + final Map context) { + if (serviceTemplate != null && serviceTemplate.getDataTypes() != null) { + serviceTemplate.getDataTypes().forEach((dataTypeKey, dataType) -> { + logger.trace("Populating Data Type Key : ({})", dataTypeKey); + String dataTypeContent = TransformationUtils.getJson(dataType); + context.put("data_types." + dataTypeKey, dataTypeContent); + }); + } + return context; + } + + public Map convertNode2Properties(ServiceTemplate serviceTemplate, + final Map context) { + + if (serviceTemplate != null && serviceTemplate.getNodeTypes() != null + && serviceTemplate.getTopologyTemplate() != null + && serviceTemplate.getTopologyTemplate().getNodeTemplates() != null) { + + serviceTemplate.getTopologyTemplate().getNodeTemplates().forEach((nodeTemplateKey, nodeTemplate) -> { + if (nodeTemplate != null && StringUtils.isNotBlank(nodeTemplate.getType())) { + String nodeTypeKey = nodeTemplate.getType(); + logger.trace("Populating Node Type Key : ({}) for Node Template : ({})", nodeTypeKey, + nodeTemplateKey); + String nodeTemplateContent = TransformationUtils.getJson(nodeTemplate); + context.put("node_templates." + nodeTemplateKey, nodeTemplateContent); + if (serviceTemplate.getNodeTypes().containsKey(nodeTypeKey)) { + NodeType nodeType = serviceTemplate.getNodeTypes().get(nodeTypeKey); + String nodeTypeContent = TransformationUtils.getJson(nodeType); + context.put("node_types." + nodeTypeKey, nodeTypeContent); + String nodeDerivedFrom = nodeType.getDerivedFrom(); + if (ConfigModelConstant.MODEL_TYPE_NODE_DG.equalsIgnoreCase(nodeDerivedFrom)) { + populateDGNodeProperties(nodeTemplateKey, nodeTemplate, context, nodeDerivedFrom); + } + } + // Populate the Artifact Definitions + populateNodeTemplateArtifacts(nodeTemplateKey, nodeTemplate, context); + } + }); + } + return context; + } + + @SuppressWarnings("squid:S1172") + public Map populateVnfNodeProperties(String nodeTemplateKey, NodeTemplate nodeTemplate, + final Map context, String nodeDerivedFrom) { + if (nodeTemplate != null && nodeTemplate.getCapabilities() != null) { + nodeTemplate.getCapabilities().forEach((capabilityKey, capability) -> { + capability.getProperties().forEach((propertyKey, property) -> { + context.put(nodeTemplateKey + "." + capabilityKey + "." + propertyKey, String.valueOf(property)); + }); + }); + } + + return context; + } + + public Map populateNodeTemplateArtifacts(String nodeTemplateKey, NodeTemplate nodeTemplate, + final Map context) { + if (MapUtils.isNotEmpty(nodeTemplate.getArtifacts())) { + nodeTemplate.getArtifacts().forEach((artifactName, artifact) -> { + if (StringUtils.isNotBlank(artifactName) && artifact != null) { + logger.trace("Populating Node Template Artifacts ({}) for Node Template ({})", artifactName, + nodeTemplateKey); + String fileKeyName = ConfigModelConstant.PROPERTY_NODE_TEMPLATES_DOT + nodeTemplateKey + "." + + ConfigModelConstant.PROPERTY_ARTIFACTS_DOT + artifactName + ".file"; + String deployKeyName = ConfigModelConstant.PROPERTY_NODE_TEMPLATES_DOT + nodeTemplateKey + "." + + ConfigModelConstant.PROPERTY_ARTIFACTS_DOT + artifactName + ".deploy_path"; + String contentKeyName = ConfigModelConstant.PROPERTY_NODE_TEMPLATES_DOT + nodeTemplateKey + "." + + ConfigModelConstant.PROPERTY_ARTIFACTS_DOT + artifactName + ".content"; + context.put(fileKeyName, artifact.getFile()); + context.put(deployKeyName, artifact.getDeployPath()); + context.put(contentKeyName, artifact.getContent()); + } + }); + } + return context; + } + + public Map populateDGNodeProperties(String nodeTemplateKey, NodeTemplate nodeTemplate, + final Map context, String nodeDerivedFrom) { + if (nodeTemplate != null && nodeTemplate.getInterfaces() != null) { + + if (nodeTemplate.getProperties() != null) { + nodeTemplate.getProperties().forEach((propKey, propValue) -> { + if (propKey != null && propValue != null) { + context.put("dg." + nodeTemplateKey + "." + propKey, String.valueOf(propValue)); + } + }); + } + + nodeTemplate.getInterfaces().forEach((interfaceKey, interfaceDefinition) -> { + + interfaceDefinition.getOperations().forEach((operationKey, operation) -> { + if (ConfigModelConstant.MODEL_TYPE_NODE_DG.equalsIgnoreCase(nodeDerivedFrom)) { + context.put("dg." + nodeTemplateKey + ".module", interfaceKey); + context.put("dg." + nodeTemplateKey + ".flow", operationKey); + } + }); + }); + } + return context; + } + + public SvcLogicContext getInterfaceOpertationDefinition(ServiceTemplate serviceTemplate, + final SvcLogicContext context) { + + if (serviceTemplate != null && serviceTemplate.getNodeTypes() != null + && serviceTemplate.getTopologyTemplate() != null + && serviceTemplate.getTopologyTemplate().getNodeTemplates() != null) { + + TopologyTemplate topologyTemplates = serviceTemplate.getTopologyTemplate(); + // Copy Definition to Template + copyNodeType2Template(serviceTemplate.getNodeTypes(), topologyTemplates.getNodeTemplates()); + + topologyTemplates.getNodeTemplates().forEach((templateKey, nodeTemplate) -> { + + if (StringUtils.isNotBlank(templateKey) && nodeTemplate != null + && nodeTemplate.getInterfaces() != null) { + + nodeTemplate.getInterfaces().forEach((interfaceKey, interfaceDefinition) -> { + if (StringUtils.isNotBlank(interfaceKey) && interfaceDefinition != null) { + interfaceDefinition.getOperations().forEach((operationKey, operation) -> { + String definitionKey = interfaceKey + "." + operationKey; + String definitionContent = TransformationUtils.getJson(operation); + context.setAttribute(definitionKey, definitionContent); + // Set the Operation & Method Params + }); + } + }); + } + }); + } + return context; + } + + public void copyNodeType2Template(Map nodeTypes, Map nodeTemplates) { + if (nodeTypes != null && nodeTemplates != null) { + + nodeTemplates.forEach((templateKey, nodeTemplate) -> { + if (StringUtils.isNotBlank(templateKey) && nodeTemplate != null) { + String type = nodeTemplate.getType(); + // Check the Node Template Type is Present + if (StringUtils.isNotBlank(type) && nodeTypes.containsKey(type)) { + NodeType nodeType = nodeTypes.get(type); + logger.trace("Checking Node Type Content : ({})", TransformationUtils.getJson(nodeType)); + copyNodeTypeInterface2Template(nodeType.getInterfaces(), nodeTemplate.getInterfaces()); + } + } + }); + } + } + + public void copyNodeTypeInterface2Template(Map nodeTypeInterfaces, + Map nodeTemplateInterfaces) { + if (nodeTypeInterfaces != null && nodeTemplateInterfaces != null) { + + nodeTemplateInterfaces.forEach((interfaceKey, nodeTemplateinterface) -> { + InterfaceDefinition nodeTypeInterface = nodeTypeInterfaces.get(interfaceKey); + logger.trace("Checking Interface Type Content : ({})", TransformationUtils.getJson(nodeTypeInterface)); + if (nodeTypeInterface != null && nodeTemplateinterface != null) { + copyNodeTypeOperation2Template(nodeTypeInterface.getOperations(), + nodeTemplateinterface.getOperations()); + } + }); + } + } + + public void copyNodeTypeOperation2Template(Map nodeTypeOperations, + Map nodeTemplateOperations) { + if (nodeTypeOperations != null && nodeTemplateOperations != null) { + + nodeTemplateOperations.forEach((operationKey, nodeTemplateOperation) -> { + OperationDefinition nodeTypeInterfaceOperation = nodeTypeOperations.get(operationKey); + if (nodeTypeInterfaceOperation != null && nodeTemplateOperation != null) { + logger.info("Checking Operation Type Content : " + operationKey + " : " + + TransformationUtils.getJson(nodeTypeInterfaceOperation)); + } + }); + } + } + +} diff --git a/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/utils/TopologicalSortingUtils.java b/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/utils/TopologicalSortingUtils.java new file mode 100644 index 000000000..4f16a0c5f --- /dev/null +++ b/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/utils/TopologicalSortingUtils.java @@ -0,0 +1,188 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2018 IBM. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.ccsdk.features.model.utils; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.Queue; +import java.util.Stack; + +public class TopologicalSortingUtils { + + /** + * The implementation here is basically an adjacency list, but instead of an array of lists, a Map + * is used to map each vertex to its list of adjacent vertices. + */ + private Map> neighbors = new HashMap<>(); + + /** + * String representation of graph. + */ + @Override + public String toString() { + StringBuilder s = new StringBuilder(); + neighbors.forEach((v, vs) -> s.append("\n " + v + " -> " + vs)); + return s.toString(); + } + + public Map> getNeighbors() { + return neighbors; + } + + /** + * Add a vertex to the graph. Nothing happens if vertex is already in graph. + */ + public void add(V vertex) { + if (neighbors.containsKey(vertex)) + return; + neighbors.put(vertex, new ArrayList()); + } + + /** + * True iff graph contains vertex. + */ + public boolean contains(V vertex) { + return neighbors.containsKey(vertex); + } + + /** + * Add an edge to the graph; if either vertex does not exist, it's added. This implementation allows + * the creation of multi-edges and self-loops. + */ + public void add(V from, V to) { + this.add(from); + this.add(to); + neighbors.get(from).add(to); + } + + /** + * Remove an edge from the graph. Nothing happens if no such edge. + * + * @throws IllegalArgumentException if either vertex doesn't exist. + */ + public void remove(V from, V to) { + if (!(this.contains(from) && this.contains(to))) + throw new IllegalArgumentException("Nonexistent vertex"); + neighbors.get(from).remove(to); + } + + /** + * Report (as a Map) the out-degree of each vertex. + */ + public Map outDegree() { + Map result = new HashMap<>(); + neighbors.forEach((v, vs) -> result.put(v, vs.size())); + return result; + } + + /** + * Report (as a Map) the in-degree of each vertex. + */ + public Map inDegree() { + Map result = new HashMap<>(); + for (V v : neighbors.keySet()) + result.put(v, 0); // All in-degrees are 0 + + neighbors.forEach((from, vs) -> vs.forEach(to -> result.put(to, result.get(to) + 1) // Increment in-degree + )); + + return result; + } + + /** + * Report (as a List) the topological sort of the vertices; null for no such sort. + */ + @SuppressWarnings({"squid:S1149", "squid:S1168"}) + public List topSort() { + Map degree = inDegree(); + // Determine all vertices with zero in-degree + Stack zeroVerts = new Stack<>(); // Stack as good as any here + + degree.forEach((v, vs) -> { + if (vs == 0) + zeroVerts.push(v); + }); + + // Determine the topological order + List result = new ArrayList<>(); + while (!zeroVerts.isEmpty()) { + V v = zeroVerts.pop(); // Choose a vertex with zero in-degree + result.add(v); // Vertex v is next in topol order + // "Remove" vertex v by updating its neighbors + for (V neighbor : neighbors.get(v)) { + degree.put(neighbor, degree.get(neighbor) - 1); + // Remember any vertices that now have zero in-degree + if (degree.get(neighbor) == 0) + zeroVerts.push(neighbor); + } + } + // Check that we have used the entire graph (if not, there was a cycle) + if (result.size() != neighbors.size()) + return null; + return result; + } + + /** + * True iff graph is a dag (directed acyclic graph). + */ + public boolean isDag() { + return topSort() != null; + } + + /** + * Report (as a Map) the bfs distance to each vertex from the start vertex. The distance is an + * Integer; the value null is used to represent infinity (implying that the corresponding node + * cannot be reached). + */ + public Map bfsDistance(V start) { + Map distance = new HashMap<>(); + // Initially, all distance are infinity, except start node + for (V v : neighbors.keySet()) + distance.put(v, null); + distance.put(start, 0); + // Process nodes in queue order + Queue queue = new LinkedList<>(); + queue.offer(start); // Place start node in queue + while (!queue.isEmpty()) { + V v = queue.remove(); + int vDist = distance.get(v); + // Update neighbors + for (V neighbor : neighbors.get(v)) { + if (distance.get(neighbor) != null) + continue; // Ignore if already done + distance.put(neighbor, vDist + 1); + queue.offer(neighbor); + } + } + return distance; + } + + /** + * Main program (for testing). public static void main (String[] args) { // Create a Graph with + * Integer nodes TopologicalSortingUtils graph = new TopologicalSortingUtils(); + * graph.add("bundle-id", "bundle-mac"); graph.add("bundle-id", "bundle-ip"); + * graph.add("bundle-mac", "bundle-ip"); graph.add("bundle-ip", "bundle-mac"); + * System.out.println("The current graph: " + graph); System.out.println("In-degrees: " + + * graph.inDegree()); System.out.println("Out-degrees: " + graph.outDegree()); System.out.println("A + * topological sort of the vertices: " + graph.topSort()); System.out.println("The graph " + + * (graph.isDag()?"is":"is not") + " a dag"); } + */ +} diff --git a/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/utils/TransformationUtils.java b/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/utils/TransformationUtils.java new file mode 100644 index 000000000..138745ccf --- /dev/null +++ b/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/utils/TransformationUtils.java @@ -0,0 +1,429 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2018 IBM. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.ccsdk.features.model.utils; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Properties; +import java.util.TreeMap; +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; +import com.fasterxml.jackson.annotation.JsonInclude.Include; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.SerializationFeature; +import com.fasterxml.jackson.databind.node.ArrayNode; +import com.fasterxml.jackson.databind.type.CollectionType; +import com.fasterxml.jackson.module.jsonSchema.JsonSchema; +import com.fasterxml.jackson.module.jsonSchema.JsonSchemaGenerator; + +/** + * TransformationUtils.java Purpose: Provide Configuration Generator TransformationUtils Information + * + * @version 1.0 + */ +public class TransformationUtils { + + private static EELFLogger logger = EELFManager.getInstance().getLogger(TransformationUtils.class); + + private TransformationUtils() { + + } + + /** + * This is a getJson method + * + * @param configparameters + * @return String + */ + public static String getJson(Map configparameters) { + String jsonContent = null; + try { + ObjectMapper mapper = new ObjectMapper(); + jsonContent = mapper.writeValueAsString(configparameters); + } catch (JsonProcessingException e) { + logger.warn(e.getMessage()); + } + return jsonContent; + } + + /** + * This is a getJsonNode method + * + * @param configparameters + * @return String + */ + public static JsonNode getJsonNode(Map configparameters) { + JsonNode jsonContent = null; + try { + ObjectMapper mapper = new ObjectMapper(); + jsonContent = mapper.valueToTree(configparameters); + } catch (Exception e) { + logger.warn(e.getMessage()); + } + return jsonContent; + } + + /** + * This is a getJson method + * + * @param instance + * @param pretty + * @return Map + */ + public static String getJson(Object instance, boolean pretty) { + try { + ObjectMapper mapper = new ObjectMapper(); + mapper.setSerializationInclusion(Include.NON_NULL); + if (pretty) { + mapper.enable(SerializationFeature.INDENT_OUTPUT); + } + return mapper.writeValueAsString(instance); + } catch (JsonProcessingException e) { + logger.warn(e.getMessage()); + } + return null; + } + + /** + * This is a getJson method + * + * @param instance + * @return String + */ + public static String getJson(Object instance) { + return getJson(instance, false); + } + + /** + * This is a getJsonNodeForobject method + * + * @param instance + * @return JsonNode + */ + public static JsonNode getJsonNodeForObject(Object instance) { + try { + ObjectMapper mapper = new ObjectMapper(); + mapper.setSerializationInclusion(Include.NON_NULL); + return mapper.convertValue(instance, JsonNode.class); + } catch (Exception e) { + logger.warn(e.getMessage()); + } + return null; + } + + /** + * This is a getJsonNodeForString method + * + * @param content + * @return JsonNode + */ + public static JsonNode getJsonNodeForString(String content) { + try { + ObjectMapper mapper = new ObjectMapper(); + mapper.setSerializationInclusion(Include.NON_NULL); + return mapper.readTree(content); + } catch (Exception e) { + logger.warn(e.getMessage()); + } + return null; + } + + /** + * This is a getMapfromJson method + * + * @param content + * @return Map + */ + public static Map getMapfromJson(String content) { + try { + ObjectMapper mapper = new ObjectMapper(); + return mapper.readValue(content, new TypeReference>() {}); + } catch (Exception e) { + logger.warn("failed in getMapfromJson for the content ({}) with error message ({}).", content, + e.getMessage()); + } + return null; + } + + /** + * This is a getMapfromJson method + * + * @param content + * @return Map + */ + public static Map getMapfromJsonString(String content) { + try { + ObjectMapper mapper = new ObjectMapper(); + return mapper.readValue(content, new TypeReference>() {}); + } catch (Exception e) { + logger.warn("failed in getMapfromJson for the content ({}) with error message ({}).", content, + e.getMessage()); + } + return null; + } + + /** + * This is a getListfromJson method + * + * @param content + * @return Map + */ + @SuppressWarnings("squid:S1168") + public static List getListfromJson(String content, Class valueType) { + try { + ObjectMapper mapper = new ObjectMapper(); + CollectionType javaType = mapper.getTypeFactory().constructCollectionType(List.class, valueType); + return mapper.readValue(content, javaType); + } catch (Exception e) { + logger.warn("failed in getListfromJson for the content ({}) with error message ({}).", content, + e.getMessage()); + } + return null; + } + + /** + * This is a getJsonSchema method + * + * @param valueType + * @return String + */ + public static String getJsonSchema(Class clazz) { + try { + ObjectMapper mapper = new ObjectMapper(); + JsonSchemaGenerator schemaGen = new JsonSchemaGenerator(mapper); + JsonSchema schema = schemaGen.generateSchema(clazz); + return mapper.writerWithDefaultPrettyPrinter().writeValueAsString(schema); + + } catch (Exception e) { + logger.warn("failed in getJsonSchema with error message ({}).", e.getMessage()); + } + return null; + } + + /** + * This is a readValue method + * + * @param content + * @param valueType + * @return + */ + + public static T readValue(String content, Class valueType) { + try { + ObjectMapper mapper = new ObjectMapper(); + return mapper.readValue(content, valueType); + } catch (Exception e) { + logger.warn("failed in readValue for the content ({}) with error message ({}).", content, e.getMessage()); + } + return null; + } + + /** + * @param node + * @param valueType + * @param + * @return + */ + public static T treeToValue(JsonNode node, Class valueType) { + try { + ObjectMapper mapper = new ObjectMapper(); + return mapper.treeToValue(node, valueType); + } catch (Exception e) { + logger.warn("failed in readValue for the content ({}) with error message ({}).", node, e.getMessage()); + } + return null; + } + + /** + * @param node + * @param valueType + * @param + * @return List + */ + public static List treeToListValue(JsonNode node, Class valueType) { + List resultList = new ArrayList<>(); + if (node instanceof ArrayNode) { + for (JsonNode subnode : node) { + if (subnode != null) { + resultList.add(treeToValue(subnode, valueType)); + } + } + } + return resultList; + } + + /** + * This is a removeJsonNullNode method + * + * @param node + */ + public static void removeJsonNullNode(JsonNode node) { + Iterator it = node.iterator(); + while (it.hasNext()) { + JsonNode child = it.next(); + if (child.isNull()) { + it.remove(); + } else { + removeJsonNullNode(child); + } + } + } + + public static void printProperty(Properties property) { + if (property != null) { + Map sortedMap = new TreeMap(property); + StringBuilder buffer = new StringBuilder(); + sortedMap.entrySet().forEach(message -> { + buffer.append("\n" + message.toString()); + }); + logger.debug("Property : ({})", buffer); + } + } + + public static void printMap(Map map) { + if (map != null) { + Map sortedMap = new TreeMap(map); + StringBuilder buffer = new StringBuilder(); + sortedMap.entrySet().forEach(message -> { + buffer.append("\n" + message.toString()); + }); + logger.debug("Map: ({})", buffer); + } + } + + @SuppressWarnings("squid:S00112") + public static Map convertJson2RootProperties(Map context, String jsonContent) + throws Exception { + if (context == null) { + context = new HashMap<>(); + } + + ObjectMapper mapper = new ObjectMapper(); + JsonNode rootArray = mapper.readTree(jsonContent); + return convertJson2RootProperties(context, rootArray); + } + + public static Map convertJson2RootProperties(Map context, JsonNode rootArray) { + Map sortedMap = null; + + if (context == null) { + context = new HashMap<>(); + } + if (rootArray != null) { + Iterator> fields = rootArray.fields(); + while (fields.hasNext()) { + Map.Entry entry = fields.next(); + if (entry != null && entry.getValue() != null) { + if (entry.getValue().isTextual()) { + context.put(entry.getKey(), entry.getValue().textValue()); + } else { + context.put(entry.getKey(), entry.getValue().toString()); + } + } + } + } + sortedMap = new TreeMap<>(context); + return sortedMap; + } + + @SuppressWarnings("squid:S00112") + public static Map convertJson2Properties(Map context, String jsonContent, + List blockKeys) throws Exception { + Map sortedMap = null; + + if (context == null) { + context = new HashMap<>(); + } + + ObjectMapper mapper = new ObjectMapper(); + JsonNode rootArray = mapper.readTree(jsonContent); + + if (rootArray != null) { + Iterator> fields = rootArray.fields(); + while (fields.hasNext()) { + Map.Entry entry = fields.next(); + processJsonNode(context, blockKeys, entry.getKey(), entry.getValue()); + } + } + sortedMap = new TreeMap<>(context); + return sortedMap; + } + + public static Map convertJson2Properties(Map context, JsonNode rootArray, + List blockKeys) throws IOException { + Map sortedMap = null; + + if (context == null) { + context = new HashMap<>(); + } + + if (blockKeys == null) { + blockKeys = new ArrayList<>(); + } + + if (rootArray != null) { + Iterator> fields = rootArray.fields(); + while (fields.hasNext()) { + Map.Entry entry = fields.next(); + processJsonNode(context, blockKeys, entry.getKey(), entry.getValue()); + } + } + sortedMap = new TreeMap<>(context); + return sortedMap; + } + + private static void processJsonNode(Map propertyMap, List blockKeys, String nodeName, + JsonNode node) throws IOException { + + logger.trace("Block Key ({})", nodeName); + if (node == null) { + return; + } + + String keyName = null; + if (blockKeys != null && blockKeys.contains(nodeName)) { + if (node.isArray() || node.isObject()) { + propertyMap.put(nodeName, node.toString()); + } else { + propertyMap.put(nodeName, node.asText()); + } + } else if (node.isArray()) { + for (int i = 0; i < node.size(); i++) { + keyName = nodeName + "[" + i + "]"; + processJsonNode(propertyMap, blockKeys, keyName, node.get(i)); + } + } else if (node.isObject()) { + Iterator> fields = node.fields(); + while (fields.hasNext()) { + Map.Entry entry = fields.next(); + keyName = nodeName + "." + entry.getKey(); + processJsonNode(propertyMap, blockKeys, keyName, entry.getValue()); + } + } else { + propertyMap.put(nodeName, node.asText()); + } + } + +} diff --git a/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/validator/DataTypeValidator.java b/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/validator/DataTypeValidator.java new file mode 100644 index 000000000..32d546eed --- /dev/null +++ b/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/validator/DataTypeValidator.java @@ -0,0 +1,109 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2018 IBM. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.ccsdk.features.model.validator; + +import java.util.HashMap; +import java.util.Map; +import org.apache.commons.lang3.StringUtils; +import org.onap.ccsdk.features.model.ConfigModelException; +import org.onap.ccsdk.features.model.ValidTypes; +import org.onap.ccsdk.features.model.data.DataType; +import org.onap.ccsdk.features.model.data.PropertyDefinition; +import org.onap.ccsdk.features.model.data.ServiceTemplate; + +/** + * DataTypeValidator.java Purpose: Provide Configuration Generator DataTypeValidator + * + * @version 1.0 + */ +public class DataTypeValidator { + + private StringBuilder message; + private Map stDataTypes; + private ServiceTemplate serviceTemplate; + private PropertyDefinitionValidator propertyDefinitionValidator; + + /** + * This is a DataTypeValidator + * + * @param serviceTemplate + * @throws ConfigModelException + */ + public DataTypeValidator(ServiceTemplate serviceTemplate, StringBuilder message) throws ConfigModelException { + this.serviceTemplate = serviceTemplate; + this.message = message; + propertyDefinitionValidator = new PropertyDefinitionValidator(this.message); + stDataTypes = new HashMap<>(); + loadInitial(); + + } + + private void loadInitial() { + if (serviceTemplate != null && serviceTemplate.getDataTypes() != null) { + message.append("\n DataTypes" + serviceTemplate.getDataTypes()); + serviceTemplate.getDataTypes().forEach((dataTypeKey, dataType) -> { + stDataTypes.put(dataTypeKey, dataType); + message.append("\n Data Type (" + dataTypeKey + ") loaded successfully."); + }); + } + } + + /** + * This is a validateDataTypes + * + * @return boolean + * @throws ConfigModelException + */ + @SuppressWarnings("squid:S00112") + public boolean validateDataTypes() { + if (serviceTemplate != null && serviceTemplate.getDataTypes() != null) { + + serviceTemplate.getDataTypes().forEach((dataTypeKey, dataType) -> { + if (dataType != null) { + try { + String derivedFrom = dataType.getDerivedFrom(); + checkValidDerivedType(dataTypeKey, derivedFrom); + checkValidProperties(dataTypeKey, dataType.getProperties()); + } catch (ConfigModelException e) { + throw new RuntimeException(e); + } + + } + + }); + } + return true; + } + + private boolean checkValidDerivedType(String dataTypeName, String derivedFrom) throws ConfigModelException { + + if (StringUtils.isBlank(derivedFrom) || !ValidTypes.getValidDataTypeDerivedFrom().contains(derivedFrom)) { + throw new ConfigModelException(derivedFrom + " is not a valid derived type for Data type " + dataTypeName); + } + return true; + } + + private boolean checkValidProperties(String dataTypeName, Map properties) { + if (properties != null) { + message.append("\n validation Data Type (" + dataTypeName + ") Property."); + propertyDefinitionValidator.validatePropertyDefinition(stDataTypes, properties); + } + return true; + } + +} diff --git a/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/validator/NodeTypeValidator.java b/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/validator/NodeTypeValidator.java new file mode 100644 index 000000000..4c719768d --- /dev/null +++ b/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/validator/NodeTypeValidator.java @@ -0,0 +1,238 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2018 IBM. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.ccsdk.features.model.validator; + +import java.util.HashMap; +import java.util.Map; +import org.apache.commons.lang3.StringUtils; +import org.onap.ccsdk.features.model.ConfigModelConstant; +import org.onap.ccsdk.features.model.ConfigModelException; +import org.onap.ccsdk.features.model.ValidTypes; +import org.onap.ccsdk.features.model.data.CapabilityDefinition; +import org.onap.ccsdk.features.model.data.DataType; +import org.onap.ccsdk.features.model.data.InterfaceDefinition; +import org.onap.ccsdk.features.model.data.NodeType; +import org.onap.ccsdk.features.model.data.OperationDefinition; +import org.onap.ccsdk.features.model.data.PropertyDefinition; +import org.onap.ccsdk.features.model.data.RequirementDefinition; +import org.onap.ccsdk.features.model.data.ServiceTemplate; + +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; + +/** + * NodeTypeValidator.java Purpose: Provide Configuration Generator NodeTypeValidator + * + * @version 1.0 + */ +public class NodeTypeValidator { + private static EELFLogger logger = EELFManager.getInstance().getLogger(NodeTypeValidator.class); + private StringBuilder message; + private Map stDataTypes; + private Map stNodeTypes; + private ServiceTemplate serviceTemplate; + private PropertyDefinitionValidator propertyDefinitionValidator; + + /** + * This is a NodeTypeValidator + * + * @param serviceTemplate + * @throws ConfigModelException + */ + public NodeTypeValidator(ServiceTemplate serviceTemplate, StringBuilder message) throws ConfigModelException { + this.serviceTemplate = serviceTemplate; + this.message = message; + propertyDefinitionValidator = new PropertyDefinitionValidator(this.message); + stDataTypes = new HashMap<>(); + stNodeTypes = new HashMap<>(); + loadInitial(); + + } + + private void loadInitial() { + if (serviceTemplate != null) { + + if (serviceTemplate.getDataTypes() != null) { + serviceTemplate.getDataTypes().forEach((dataTypeKey, dataType) -> { + stDataTypes.put(dataTypeKey, dataType); + logger.trace("Data Type ({}) loaded successfully.", dataTypeKey); + }); + } + + if (serviceTemplate.getNodeTypes() != null) { + serviceTemplate.getNodeTypes().forEach((nodeTypeKey, nodeType) -> { + stNodeTypes.put(nodeTypeKey, nodeType); + logger.trace("NodeType Type ({}) loaded successfully.", nodeTypeKey); + }); + } + + } + + } + + /** + * This is a validateNodeTypes to validate the Node Type + * + * @return boolean + * @throws ConfigModelException + */ + @SuppressWarnings({"squid:S00112", "squid:S3776"}) + public boolean validateNodeTypes() { + if (serviceTemplate != null && serviceTemplate.getNodeTypes() != null) { + serviceTemplate.getNodeTypes().forEach((nodeTypeKey, nodeType) -> { + if (nodeType != null) { + message.append("\n ***** Validation Node Type (" + nodeTypeKey + "), derived from (" + + nodeType.getDerivedFrom() + ")"); + try { + validateNodeType(ConfigModelConstant.MODEL_DEFINITION_TYPE_NODE_TYPE, + nodeType.getDerivedFrom()); + + if (nodeType.getProperties() != null) { + checkValidProperties(nodeType.getProperties()); + } + + if (nodeType.getCapabilities() != null) { + validateNodeTypeCapabilities(nodeType.getCapabilities()); + } + + if (nodeType.getInterfaces() != null) { + validateNodeTypeInterface(nodeType.getInterfaces()); + } + + if (nodeType.getRequirements() != null) { + validateNodeTypeRequirement(nodeType.getRequirements()); + } + + } catch (ConfigModelException e) { + logger.error(e.getMessage()); + throw new RuntimeException(e.getMessage()); + } + + } + }); + } + return true; + } + + private boolean validateNodeType(String definitionType, String derivedFrom) throws ConfigModelException { + boolean valid = true; + if (!ConfigModelConstant.MODEL_DEFINITION_TYPE_DATA_TYPE.equalsIgnoreCase(definitionType) + && !ValidTypes.getValidNodeTypes().contains(derivedFrom)) { + throw new ConfigModelException("Not Valid Model Type (" + derivedFrom + ")"); + } + return valid; + } + + private boolean checkValidProperties(Map properties) { + if (properties != null) { + propertyDefinitionValidator.validatePropertyDefinition(stDataTypes, properties); + } + return true; + } + + @SuppressWarnings("squid:S00112") + private boolean validateNodeTypeCapabilities(Map capabilities) { + if (capabilities != null) { + capabilities.forEach((capabilityKey, capability) -> { + if (capability != null) { + Map properties = capability.getProperties(); + message.append("\n Validation Capability (" + capabilityKey + ") properties :"); + propertyDefinitionValidator.validatePropertyDefinition(stDataTypes, properties); + } + }); + } + return true; + } + + @SuppressWarnings("squid:S00112") + private boolean validateNodeTypeInterface(Map interfaces) { + if (interfaces != null) { + interfaces.forEach((interfaceKey, interfaceDefinition) -> { + if (interfaceDefinition != null && interfaceDefinition.getOperations() != null) { + validateNodeTypeInterfaceOperation(interfaceDefinition.getOperations()); + } + }); + } + return true; + } + + @SuppressWarnings("squid:S00112") + private boolean validateNodeTypeInterfaceOperation(Map operations) { + if (operations != null) { + operations.forEach((operationKey, operation) -> { + if (operation != null) { + Map inputs = operation.getInputs(); + message.append("\n Validation Operation (" + operationKey + ") Inputs :"); + propertyDefinitionValidator.validatePropertyDefinition(stDataTypes, inputs); + message.append("\n Validation Operation (" + operationKey + ") output :"); + Map outputs = operation.getOutputs(); + propertyDefinitionValidator.validatePropertyDefinition(stDataTypes, outputs); + } + }); + } + return true; + } + + @SuppressWarnings("squid:S00112") + private boolean validateNodeTypeRequirement(Map requirements) { + if (requirements != null) { + requirements.forEach((requirementKey, requirement) -> { + if (requirement != null) { + String nodeTypeName = requirement.getNode(); + String capabilityName = requirement.getCapability(); + try { + checkCapabilityPresentInNodeType(nodeTypeName, capabilityName); + } catch (ConfigModelException e) { + throw new RuntimeException(e); + } + } + }); + } + return true; + } + + private boolean checkCapabilityPresentInNodeType(String nodeTypeName, String capabilityName) + throws ConfigModelException { + if (StringUtils.isNotBlank(nodeTypeName) && StringUtils.isNotBlank(capabilityName)) { + + if (!stNodeTypes.containsKey(nodeTypeName)) { + throw new ConfigModelException(nodeTypeName + " Node Type not Defined."); + } else { + message.append("\n Node Type (" + nodeTypeName + ") Defined."); + } + + NodeType relationalNodeType = stNodeTypes.get(nodeTypeName); + + if (relationalNodeType.getCapabilities() == null) { + throw new ConfigModelException( + "Node Type (" + nodeTypeName + "), doesn't have Capability Definitions."); + } + + if (!relationalNodeType.getCapabilities().containsKey(capabilityName)) { + throw new ConfigModelException("Node Type (" + nodeTypeName + ") doesn't have (" + capabilityName + + ") Capability Definitions."); + } else { + message.append( + "\n Node Type (" + nodeTypeName + ") has (" + capabilityName + ") Capability Definitions."); + } + + } + return true; + } + +} diff --git a/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/validator/PropertyDefinitionValidator.java b/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/validator/PropertyDefinitionValidator.java new file mode 100644 index 000000000..080fee2b6 --- /dev/null +++ b/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/validator/PropertyDefinitionValidator.java @@ -0,0 +1,89 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2018 IBM. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.ccsdk.features.model.validator; + +import java.util.Map; +import org.apache.commons.lang3.StringUtils; +import org.onap.ccsdk.features.model.ConfigModelException; +import org.onap.ccsdk.features.model.ValidTypes; +import org.onap.ccsdk.features.model.data.DataType; +import org.onap.ccsdk.features.model.data.PropertyDefinition; + +/** + * PropertyDefinitionValidator.java Purpose: Provide Configuration Generator + * PropertyDefinitionValidator + * + * @version 1.0 + */ +public class PropertyDefinitionValidator { + + StringBuilder message = new StringBuilder(); + + public PropertyDefinitionValidator(StringBuilder message) { + this.message = message; + + } + + /** + * This is a validatePropertyDefinition stored in database + * + * @param stDataTypes + * @param properties + * @return boolean + * @throws ConfigModelException + */ + @SuppressWarnings({"squid:S00112", "squid:S3776", "squid:S1192"}) + public boolean validatePropertyDefinition(Map stDataTypes, + Map properties) { + + if (stDataTypes != null && properties != null) { + properties.forEach((propertyKey, prop) -> { + if (propertyKey != null && prop != null) { + try { + String propertType = prop.getType(); + message.append("\n Validating (" + propertyKey + ") " + prop); + + if (!ValidTypes.getValidPropertType().contains(propertType) + && !stDataTypes.containsKey(propertType)) { + throw new ConfigModelException("Data Type (" + propertyKey + ") -> type(" + propertType + + ") is not a valid type."); + } else if (ValidTypes.getListPropertType().contains(propertType)) { + if (prop.getEntrySchema() == null || StringUtils.isBlank(prop.getEntrySchema().getType())) { + throw new ConfigModelException("Data Type (" + propertyKey + ") -> type (" + propertType + + ") Entity Schema is not defined."); + } + + String entitySchemaType = prop.getEntrySchema().getType(); + + if (!ValidTypes.getValidPropertType().contains(entitySchemaType) + && !stDataTypes.containsKey(entitySchemaType)) { + message.append("\n Present Data Type " + stDataTypes); + throw new ConfigModelException("Data Type (" + propertyKey + ") -> type(" + propertType + + ") -> entitySchema(" + entitySchemaType + ") is not defined."); + } + } + } catch (ConfigModelException e) { + throw new RuntimeException(e); + } + } + }); + } + return true; + } + +} diff --git a/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/validator/ResourceAssignmentValidator.java b/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/validator/ResourceAssignmentValidator.java new file mode 100644 index 000000000..83e9f6e9d --- /dev/null +++ b/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/validator/ResourceAssignmentValidator.java @@ -0,0 +1,164 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2018 IBM. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.ccsdk.features.model.validator; + +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; +import org.apache.commons.lang3.StringUtils; +import org.onap.ccsdk.features.model.ConfigModelConstant; +import org.onap.ccsdk.features.model.ConfigModelException; +import org.onap.ccsdk.features.model.data.CapabilityAssignment; +import org.onap.ccsdk.features.model.data.NodeTemplate; +import org.onap.ccsdk.features.model.data.ResourceAssignment; +import org.onap.ccsdk.features.model.utils.TopologicalSortingUtils; +import org.onap.ccsdk.features.model.utils.TransformationUtils; + +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; + +public class ResourceAssignmentValidator { + private static EELFLogger logger = EELFManager.getInstance().getLogger(ResourceAssignmentValidator.class); + private List assignments; + private Map resourceAssignmentMap = new HashMap<>(); + private StringBuilder validationMessage = new StringBuilder(); + + public ResourceAssignmentValidator(NodeTemplate nodeTemplate) throws ConfigModelException { + + if (nodeTemplate != null && nodeTemplate.getCapabilities() != null) { + CapabilityAssignment capabilityAssignment = + nodeTemplate.getCapabilities().get(ConfigModelConstant.CAPABILITY_PROPERTY_MAPPING); + if (capabilityAssignment != null && capabilityAssignment.getProperties() != null) { + Object mappingObject = + capabilityAssignment.getProperties().get(ConfigModelConstant.CAPABILITY_PROPERTY_MAPPING); + if (mappingObject != null) { + String mappingContent = TransformationUtils.getJson(mappingObject); + if (StringUtils.isNotBlank(mappingContent)) { + this.assignments = + TransformationUtils.getListfromJson(mappingContent, ResourceAssignment.class); + } else { + validationMessage + .append(String.format("Failed to transform Mapping Content (%s) ", mappingContent)); + throw new ConfigModelException( + String.format("Failed to transform Mapping Content (%s) ", mappingContent)); + } + } + } + } + } + + public ResourceAssignmentValidator(List assignments) { + this.assignments = assignments; + } + + /** + * This is a validateResourceAssignment to validate the Topology Template + * + * @return boolean + * @throws ConfigModelException + */ + public boolean validateResourceAssignment() throws ConfigModelException { + if (assignments != null && !assignments.isEmpty()) { + validateDuplicateDictionaryKeys(); + validateCyclicDependencty(); + if (validationMessage.length() > 0) { + logger.error("Resourece Assignment Validation : {}", validationMessage); + throw new ConfigModelException("Resourece Assignment Validation :" + validationMessage.toString()); + } + } + return true; + } + + @SuppressWarnings("squid:S3776") + private void validateDuplicateDictionaryKeys() { + this.assignments.forEach(resourceMapping -> { + if (resourceMapping != null) { + if (!resourceAssignmentMap.containsKey(resourceMapping.getName())) { + resourceAssignmentMap.put(resourceMapping.getName(), resourceMapping); + } else { + validationMessage.append(String.format("Duplicate Assignment Template Key (%s) is Present", + resourceMapping.getName())); + } + } + }); + + if (!assignments.isEmpty()) { + Set uniqueSet = new HashSet<>(); + for (ResourceAssignment resourceAssignment : assignments) { + if (resourceAssignment != null) { + boolean added = uniqueSet.add(resourceAssignment.getDictionaryName()); + if (!added) { + validationMessage.append( + String.format("Duplicate Assignment Dictionary Key (%s) present with Template Key (%s)", + resourceAssignment.getDictionaryName(), resourceAssignment.getName())); + } + } + } + } + } + + private void validateCyclicDependencty() { + TopologicalSortingUtils topologySorting = new TopologicalSortingUtils<>(); + this.resourceAssignmentMap.forEach((mappingKey, mapping) -> { + if (mapping != null) { + if (mapping.getDependencies() != null && !mapping.getDependencies().isEmpty()) { + for (String dependency : mapping.getDependencies()) { + topologySorting.add(resourceAssignmentMap.get(dependency), mapping); + } + } else { + topologySorting.add(null, mapping); + } + } + }); + + if (!topologySorting.isDag()) { + String graph = getTopologicalGraph(topologySorting); + validationMessage.append("Cyclic Dependency :" + graph); + } + } + + public String getTopologicalGraph(TopologicalSortingUtils topologySorting) { + StringBuilder s = new StringBuilder(); + if (topologySorting != null) { + Map> neighbors = topologySorting.getNeighbors(); + + neighbors.forEach((v, vs) -> { + if (v == null) { + s.append("\n * -> ["); + List links = vs; + for (ResourceAssignment resourceAssignment : links) { + s.append("(" + resourceAssignment.getDictionaryName() + ":" + resourceAssignment.getName() + + "),"); + } + s.append("]"); + } else { + s.append("\n (" + v.getDictionaryName() + ":" + v.getName() + ") -> ["); + List links = vs; + for (ResourceAssignment resourceAssignment : links) { + s.append("(" + resourceAssignment.getDictionaryName() + ":" + resourceAssignment.getName() + + "),"); + } + s.append("]"); + } + }); + } + return s.toString(); + } +} diff --git a/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/validator/ServiceTemplateValidator.java b/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/validator/ServiceTemplateValidator.java new file mode 100644 index 000000000..83927913a --- /dev/null +++ b/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/validator/ServiceTemplateValidator.java @@ -0,0 +1,130 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2018 IBM. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.ccsdk.features.model.validator; + +import java.util.HashMap; +import java.util.Map; +import org.apache.commons.lang3.StringUtils; +import org.onap.ccsdk.features.model.ConfigModelConstant; +import org.onap.ccsdk.features.model.ConfigModelException; +import org.onap.ccsdk.features.model.data.ServiceTemplate; +import org.onap.ccsdk.features.model.utils.TransformationUtils; + +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; + +/** + * ServiceTemplateValidator.java Purpose: Provide Configuration Generator ServiceTemplateValidator + * + * @version 1.0 + */ + +public class ServiceTemplateValidator { + + private static EELFLogger logger = EELFManager.getInstance().getLogger(ServiceTemplateValidator.class); + + private Map metaData = new HashMap<>(); + + StringBuilder message = new StringBuilder(); + + /** + * This is a validateServiceTemplate + * + * @param serviceTemplateContent + * @return boolean + * @throws ConfigModelException + */ + @SuppressWarnings("squid:S00112") + public boolean validateServiceTemplate(String serviceTemplateContent) throws ConfigModelException { + if (StringUtils.isNotBlank(serviceTemplateContent)) { + ServiceTemplate serviceTemplate = + TransformationUtils.readValue(serviceTemplateContent, ServiceTemplate.class); + return validateServiceTemplate(serviceTemplate); + } else { + throw new ConfigModelException( + "Service Template Content is (" + serviceTemplateContent + ") not Defined."); + } + } + + /** + * This is a validateServiceTemplate + * + * @param serviceTemplate + * @return boolean + * @throws ConfigModelException + */ + @SuppressWarnings("squid:S00112") + public boolean validateServiceTemplate(ServiceTemplate serviceTemplate) throws ConfigModelException { + if (serviceTemplate != null) { + try { + validateMetaData(serviceTemplate); + (new DataTypeValidator(serviceTemplate, message)).validateDataTypes(); + (new NodeTypeValidator(serviceTemplate, message)).validateNodeTypes(); + (new TopologyTemplateValidator(serviceTemplate, message)).validateTopologyTemplate(); + logger.debug("Validation Message : {}", message); + } catch (Exception e) { + throw new ConfigModelException( + "Validation Failed " + e.toString() + ",Message Trace : \n" + message.toString()); + } + + } else { + throw new ConfigModelException("Service Template is not defined."); + } + return true; + } + + /** + * This is a getMetaData to get the key information during the + * + * @return Map + */ + public Map getMetaData() { + return metaData; + } + + private void validateMetaData(ServiceTemplate serviceTemplate) throws ConfigModelException { + if (serviceTemplate.getMetadata() != null) { + this.metaData.putAll(serviceTemplate.getMetadata()); + + String author = serviceTemplate.getMetadata().get(ConfigModelConstant.SERVICE_TEMPLATE_KEY_ARTIFACT_AUTHOR); + String serviceTemplateName = + serviceTemplate.getMetadata().get(ConfigModelConstant.SERVICE_TEMPLATE_KEY_ARTIFACT_NAME); + String serviceTemplateVersion = + serviceTemplate.getMetadata().get(ConfigModelConstant.SERVICE_TEMPLATE_KEY_ARTIFACT_VERSION); + + if (StringUtils.isBlank(author)) { + throw new ConfigModelException("Service Template Metadata (author) Information is missing."); + } + + if (StringUtils.isBlank(serviceTemplateName)) { + throw new ConfigModelException( + "Service Template Metadata (service-template-name) Information is missing."); + } + + if (StringUtils.isBlank(serviceTemplateVersion)) { + throw new ConfigModelException( + "Service Template Metadata (service-template-version) Information is missing."); + } + + } else { + throw new ConfigModelException("Service Template Metadata Information is missing."); + } + + } + +} diff --git a/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/validator/TopologyTemplateValidator.java b/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/validator/TopologyTemplateValidator.java new file mode 100644 index 000000000..0f1258a9c --- /dev/null +++ b/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/features/model/validator/TopologyTemplateValidator.java @@ -0,0 +1,204 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2018 IBM. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.ccsdk.features.model.validator; + +import java.util.HashMap; +import java.util.Map; +import org.apache.commons.lang3.StringUtils; +import org.onap.ccsdk.features.model.ConfigModelConstant; +import org.onap.ccsdk.features.model.ConfigModelException; +import org.onap.ccsdk.features.model.data.DataType; +import org.onap.ccsdk.features.model.data.NodeTemplate; +import org.onap.ccsdk.features.model.data.NodeType; +import org.onap.ccsdk.features.model.data.PropertyDefinition; +import org.onap.ccsdk.features.model.data.RequirementAssignment; +import org.onap.ccsdk.features.model.data.ServiceTemplate; +import org.onap.ccsdk.features.model.data.TopologyTemplate; + +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; + +/** + * TopologyTemplateValidator.java Purpose: Provide Configuration Generator TopologyTemplateValidator + * + * @version 1.0 + */ +public class TopologyTemplateValidator { + private static EELFLogger logger = EELFManager.getInstance().getLogger(TopologyTemplateValidator.class); + private StringBuilder message; + private Map stDataTypes; + private Map stNodeTypes; + private Map stNodeTemplates; + private ServiceTemplate serviceTemplate; + private PropertyDefinitionValidator propertyDefinitionValidator; + + /** + * This is a TopologyTemplateValidator + * + * @param serviceTemplate + * @throws ConfigModelException + */ + public TopologyTemplateValidator(ServiceTemplate serviceTemplate, StringBuilder message) { + this.serviceTemplate = serviceTemplate; + this.message = message; + propertyDefinitionValidator = new PropertyDefinitionValidator(this.message); + stDataTypes = new HashMap<>(); + stNodeTypes = new HashMap<>(); + stNodeTemplates = new HashMap<>(); + loadInitial(); + } + + private void loadInitial() { + if (serviceTemplate != null) { + + if (serviceTemplate.getDataTypes() != null) { + serviceTemplate.getDataTypes().forEach((dataTypeKey, dataType) -> { + stDataTypes.put(dataTypeKey, dataType); + logger.trace("Data Type ({}) loaded successfully.", dataTypeKey); + }); + } + + if (serviceTemplate.getNodeTypes() != null) { + serviceTemplate.getNodeTypes().forEach((nodeTypeKey, nodeType) -> { + stNodeTypes.put(nodeTypeKey, nodeType); + logger.trace("Node Type ({}) loaded successfully.", nodeTypeKey); + }); + } + + if (serviceTemplate.getTopologyTemplate() != null) { + TopologyTemplate topologyTemplate = serviceTemplate.getTopologyTemplate(); + + if (topologyTemplate.getNodeTemplates() != null) { + topologyTemplate.getNodeTemplates().forEach((nodeTemplateKey, nodeTemplate) -> { + stNodeTemplates.put(nodeTemplateKey, nodeTemplate); + logger.trace("Node Template ({}) Type loaded successfully.", nodeTemplateKey); + }); + } + } + } + + } + + /** + * This is a validateTopologyTemplate to validate the Topology Template + * + * @return boolean + * @throws ConfigModelException + */ + public boolean validateTopologyTemplate() { + if (serviceTemplate != null && serviceTemplate.getTopologyTemplate() != null) { + + checkValidInputProperties(serviceTemplate.getTopologyTemplate().getInputs()); + + validateNodeTemplates(serviceTemplate.getTopologyTemplate().getNodeTemplates()); + } + return true; + } + + private boolean checkValidInputProperties(Map properties) { + if (properties != null) { + message.append("\n Validation topology template input properties :"); + propertyDefinitionValidator.validatePropertyDefinition(stDataTypes, properties); + } + return true; + } + + @SuppressWarnings({"squid:S00112", "squid:S3776"}) + private boolean validateNodeTemplates(Map nodeTemplates) { + if (nodeTemplates != null) { + nodeTemplates.forEach((nodeTemplateKey, nodeTemplate) -> { + if (nodeTemplate != null) { + message.append("\n ##### Validation Node Template (" + nodeTemplateKey + "), of type (" + + nodeTemplate.getType() + ")"); + + String nodeTypeName = nodeTemplate.getType(); + if (!stNodeTypes.containsKey(nodeTypeName)) { + throw new RuntimeException("Node Type (" + nodeTypeName + ")not Defined."); + } + + if (nodeTemplate.getRequirements() != null) { + validateNodeTemplateRequirement(nodeTemplate.getRequirements()); + } + + // Validate Resource Assignments + NodeType nodeType = stNodeTypes.get(nodeTypeName); + if (nodeType != null + && ConfigModelConstant.MODEL_TYPE_NODE_ARTIFACT.equals(nodeType.getDerivedFrom())) { + logger.info("Validating Resource Assignment NodeTemplate ({}).", nodeTemplateKey); + ResourceAssignmentValidator resourceAssignmentValidator; + try { + resourceAssignmentValidator = new ResourceAssignmentValidator(nodeTemplate); + resourceAssignmentValidator.validateResourceAssignment(); + } catch (ConfigModelException e) { + throw new RuntimeException(e); + } + + } + } + }); + } + return true; + } + + @SuppressWarnings("squid:S00112") + private boolean validateNodeTemplateRequirement(Map requirements) { + if (requirements != null) { + requirements.forEach((requirementKey, requirement) -> { + if (requirement != null) { + String requirementnodeTypeName = requirement.getNode(); + String capabilityName = requirement.getCapability(); + try { + checkCapabilityPresentInNodeTemplate(requirementnodeTypeName, capabilityName); + } catch (ConfigModelException e) { + throw new RuntimeException(e); + } + } + }); + } + return true; + } + + private boolean checkCapabilityPresentInNodeTemplate(String nodeTemplateName, String capabilityName) + throws ConfigModelException { + if (StringUtils.isNotBlank(nodeTemplateName) && StringUtils.isNotBlank(capabilityName)) { + + if (!stNodeTemplates.containsKey(nodeTemplateName)) { + throw new ConfigModelException(nodeTemplateName + " Node Template not Defined."); + } else { + message.append("\n Node Template (" + nodeTemplateName + ") Defined."); + } + + NodeTemplate relationalNodeType = stNodeTemplates.get(nodeTemplateName); + + if (relationalNodeType.getCapabilities() == null) { + throw new ConfigModelException( + "Node Template (" + nodeTemplateName + "), doesn't have Capability Definitions."); + } + + if (!relationalNodeType.getCapabilities().containsKey(capabilityName)) { + throw new ConfigModelException("Node Type (" + nodeTemplateName + ") doesn't have (" + capabilityName + + ") Capability Definitions."); + } else { + message.append("\n Node Template (" + nodeTemplateName + ") has (" + capabilityName + + ") Capability Definitions."); + } + + } + return true; + } +} diff --git a/blueprints-processor/plugin/model-provider/src/main/resources/org/opendaylight/blueprint/impl-blueprint.xml b/blueprints-processor/plugin/model-provider/src/main/resources/org/opendaylight/blueprint/impl-blueprint.xml index 2bfab86f8..5a07f94c6 100644 --- a/blueprints-processor/plugin/model-provider/src/main/resources/org/opendaylight/blueprint/impl-blueprint.xml +++ b/blueprints-processor/plugin/model-provider/src/main/resources/org/opendaylight/blueprint/impl-blueprint.xml @@ -23,46 +23,46 @@ + interface="org.onap.ccsdk.features.data.adaptor.service.ConfigResourceService" /> + interface="org.onap.ccsdk.features.rest.adaptor.service.ConfigRestAdaptorService" /> + class="org.onap.ccsdk.features.model.service.ConfigModelNode"> + interface="org.onap.ccsdk.features.model.service.ConfigModelNode" /> + class="org.onap.ccsdk.features.model.service.ConfigModelServiceImpl"> + interface="org.onap.ccsdk.features.model.service.ConfigModelService" /> + class="org.onap.ccsdk.features.model.service.ComponentNodeServiceImpl"> + interface="org.onap.ccsdk.features.model.service.ComponentNodeService" /> + class="org.onap.ccsdk.features.model.service.ComponentNodeDelegate"> + interface="org.onap.ccsdk.features.model.service.ComponentNodeDelegate" /> diff --git a/blueprints-processor/plugin/model-provider/src/test/java/org/onap/ccsdk/config/model/ResourceDictionaryUtilsTest.java b/blueprints-processor/plugin/model-provider/src/test/java/org/onap/ccsdk/config/model/ResourceDictionaryUtilsTest.java deleted file mode 100644 index 1b3dc9c1f..000000000 --- a/blueprints-processor/plugin/model-provider/src/test/java/org/onap/ccsdk/config/model/ResourceDictionaryUtilsTest.java +++ /dev/null @@ -1,216 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2018 IBM. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.ccsdk.config.model; - -import java.util.Arrays; -import java.util.HashMap; -import org.junit.Assert; -import org.junit.Test; -import org.onap.ccsdk.config.model.data.PropertyDefinition; -import org.onap.ccsdk.config.model.data.ResourceAssignment; -import org.onap.ccsdk.config.model.data.dict.ResourceDefinition; -import org.onap.ccsdk.config.model.data.dict.SourcesDefinition; -import org.onap.ccsdk.config.model.data.dict.SourcesProperties; -import org.onap.ccsdk.config.model.utils.ResourceDictionaryUtils; -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; - -public class ResourceDictionaryUtilsTest { - private static EELFLogger logger = EELFManager.getInstance().getLogger(ResourceDictionaryUtilsTest.class); - - @Test - public void validateSingleInputSource() { - try { - logger.info(" **************** Validating validateSingleInputSource *****************"); - ResourceAssignment resourceAssignment = new ResourceAssignment(); - resourceAssignment.setName("test-input-key"); - - PropertyDefinition propertyDefinition = new PropertyDefinition(); - propertyDefinition.setType(ValidTypes.DATA_TYPE_STRING); - - SourcesProperties sourcesProp = new SourcesProperties(); - sourcesProp.setDependencies(Arrays.asList(new String[] {"vnf-id", "vnf-name"})); - - SourcesDefinition sourceDef = new SourcesDefinition(); - sourceDef.setProperties(sourcesProp); - - HashMap sources = new HashMap<>(); - sources.put("input", sourceDef); - - ResourceDefinition resourceDefinition = new ResourceDefinition(); - resourceDefinition.setProperty(propertyDefinition); - resourceDefinition.setSources(sources); - - ResourceDictionaryUtils.populateSourceMapping(resourceAssignment, resourceDefinition); - - Assert.assertNotNull("Resource assignment input sourceName is missing ", - resourceAssignment.getDictionarySource()); - Assert.assertNotNull("Resource assignment input sourceName property is missing ", - resourceAssignment.getProperty()); - Assert.assertNotNull("Resource assignment input sourceName property type is missing ", - resourceAssignment.getProperty().getType()); - - } catch (Exception e) { - e.printStackTrace(); - } - } - - @Test - public void validateSingleDbSource() { - try { - logger.info(" **************** Validating validateSingleDbSource *****************"); - ResourceAssignment resourceAssignment = new ResourceAssignment(); - resourceAssignment.setName("test-db-key"); - - PropertyDefinition propertyDefinition = new PropertyDefinition(); - propertyDefinition.setType(ValidTypes.DATA_TYPE_STRING); - - SourcesProperties sourcesProp = new SourcesProperties(); - sourcesProp.setDependencies(Arrays.asList(new String[] {"vnf-id", "vnf-name"})); - - SourcesDefinition sourceDef = new SourcesDefinition(); - sourceDef.setProperties(sourcesProp); - - HashMap sources = new HashMap<>(); - sources.put("db", sourceDef); - - ResourceDefinition resourceDefinition = new ResourceDefinition(); - resourceDefinition.setProperty(propertyDefinition); - resourceDefinition.setSources(sources); - - ResourceDictionaryUtils.populateSourceMapping(resourceAssignment, resourceDefinition); - Assert.assertNotNull("Resource assignment db sourceName sourceName is missing ", - resourceAssignment.getDictionarySource()); - Assert.assertNotNull("Resource assignment db sourceName sourceName property is missing ", - resourceAssignment.getProperty()); - Assert.assertNotNull("Resource assignment db sourceName sourceName property type is missing ", - resourceAssignment.getProperty().getType()); - - Assert.assertNotNull("Resource assignment db dependecy is missing ", resourceAssignment.getDependencies()); - Assert.assertEquals("Resource assignment db dependecy count mismatch ", 2, - resourceAssignment.getDependencies().size()); - - } catch (Exception e) { - e.printStackTrace(); - } - } - - @Test - public void validateMultiSource() { - try { - logger.info(" **************** Validating validateMultiSource *****************"); - ResourceAssignment resourceAssignment = new ResourceAssignment(); - resourceAssignment.setName("test-multi-key"); - - PropertyDefinition propertyDefinition = new PropertyDefinition(); - propertyDefinition.setType(ValidTypes.DATA_TYPE_STRING); - - SourcesProperties sourcesProp = new SourcesProperties(); - sourcesProp.setDependencies(Arrays.asList(new String[] {"vnf-id", "vnf-name"})); - - SourcesDefinition sourceDef = new SourcesDefinition(); - sourceDef.setProperties(sourcesProp); - - HashMap sources = new HashMap<>(); - sources.put("input", sourceDef); - sources.put("mdsal", sourceDef); - - ResourceDefinition resourceDefinition = new ResourceDefinition(); - resourceDefinition.setProperty(propertyDefinition); - resourceDefinition.setSources(sources); - - ResourceDictionaryUtils.populateSourceMapping(resourceAssignment, resourceDefinition); - Assert.assertNotNull("Resource assignment db sourceName sourceName property is missing ", - resourceAssignment.getProperty()); - Assert.assertNotNull("Resource assignment db sourceName sourceName property type is missing ", - resourceAssignment.getProperty().getType()); - Assert.assertNull("Resource assignment multi sourceName sourceName definition is present ", - resourceAssignment.getDictionarySource()); - Assert.assertNull("Resource assignment multi sourceName dependecy is present ", - resourceAssignment.getDependencies()); - - } catch (Exception e) { - e.printStackTrace(); - } - } - - @Test - public void testSourceDefault() { - logger.info(" **************** Validating testSourceDefault *****************"); - ResourceAssignment resourceAssignment = new ResourceAssignment(); - resourceAssignment.setName("test-input-key"); - - PropertyDefinition propertyDefinition = new PropertyDefinition(); - propertyDefinition.setType(ValidTypes.DATA_TYPE_STRING); - - SourcesProperties sourcesProp = new SourcesProperties(); - sourcesProp.setDependencies(Arrays.asList(new String[] {"vnf-id", "vnf-name"})); - - SourcesDefinition sourceDef = new SourcesDefinition(); - sourceDef.setProperties(sourcesProp); - - HashMap sources = new HashMap<>(); - sources.put("default", sourceDef); - - ResourceDefinition resourceDefinition = new ResourceDefinition(); - resourceDefinition.setProperty(propertyDefinition); - resourceDefinition.setSources(sources); - - ResourceDictionaryUtils.populateSourceMapping(resourceAssignment, resourceDefinition); - - Assert.assertNotNull("Resource assignment default sourceName is missing ", - resourceAssignment.getDictionarySource()); - Assert.assertNotNull("Resource assignment default sourceName property is missing ", - resourceAssignment.getProperty()); - Assert.assertNotNull("Resource assignment default sourceName property type is missing ", - resourceAssignment.getProperty().getType()); - } - - @Test - public void testSourceMdsal() { - logger.info(" **************** Validating testSourceMdsal *****************"); - ResourceAssignment resourceAssignment = new ResourceAssignment(); - resourceAssignment.setName("test-input-key"); - - PropertyDefinition propertyDefinition = new PropertyDefinition(); - propertyDefinition.setType(ValidTypes.DATA_TYPE_STRING); - - SourcesProperties sourcesProp = new SourcesProperties(); - sourcesProp.setDependencies(Arrays.asList(new String[] {"vnf-id", "vnf-name"})); - - SourcesDefinition sourceDef = new SourcesDefinition(); - sourceDef.setProperties(sourcesProp); - - HashMap sources = new HashMap<>(); - sources.put("mdsal", sourceDef); - - ResourceDefinition resourceDefinition = new ResourceDefinition(); - resourceDefinition.setProperty(propertyDefinition); - resourceDefinition.setSources(sources); - - ResourceDictionaryUtils.populateSourceMapping(resourceAssignment, resourceDefinition); - - Assert.assertNotNull("Resource assignment mdsal sourceName is missing ", - resourceAssignment.getDictionarySource()); - Assert.assertNotNull("Resource assignment mdsal sourceName property is missing ", - resourceAssignment.getProperty()); - Assert.assertNotNull("Resource assignment mdsal sourceName property type is missing ", - resourceAssignment.getProperty().getType()); - } - -} diff --git a/blueprints-processor/plugin/model-provider/src/test/java/org/onap/ccsdk/config/model/utils/JsonParserUtilsTest.java b/blueprints-processor/plugin/model-provider/src/test/java/org/onap/ccsdk/config/model/utils/JsonParserUtilsTest.java deleted file mode 100644 index 693c505e3..000000000 --- a/blueprints-processor/plugin/model-provider/src/test/java/org/onap/ccsdk/config/model/utils/JsonParserUtilsTest.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2018 IBM. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.ccsdk.config.model.utils; - -import org.junit.Assert; -import org.junit.Test; -import com.fasterxml.jackson.databind.JsonNode; - -public class JsonParserUtilsTest { - - @Test - public void testParse() { - final String jsonExample = "{\"key\":\"value\"}"; - - JsonNode rootJsonNode = JsonParserUtils.parse(jsonExample, "$"); - Assert.assertEquals(jsonExample, rootJsonNode.toString()); - - JsonNode keyJsonNode = JsonParserUtils.parse(rootJsonNode, "$['key']"); - Assert.assertEquals("value", keyJsonNode.asText()); - - Assert.assertEquals(jsonExample, - JsonParserUtils.parseNSet("{\"key\":\"NOT_VALUE\"}", "$['key']", keyJsonNode).toString()); - - rootJsonNode = JsonParserUtils.parse("{\"key\":\"NOT_VALUE\"}", "$"); - Assert.assertEquals(jsonExample, JsonParserUtils.parseNSet(rootJsonNode, "$['key']", keyJsonNode).toString()); - } - -} diff --git a/blueprints-processor/plugin/model-provider/src/test/java/org/onap/ccsdk/config/model/utils/JsonUtilsTest.java b/blueprints-processor/plugin/model-provider/src/test/java/org/onap/ccsdk/config/model/utils/JsonUtilsTest.java deleted file mode 100644 index 5dd0fae27..000000000 --- a/blueprints-processor/plugin/model-provider/src/test/java/org/onap/ccsdk/config/model/utils/JsonUtilsTest.java +++ /dev/null @@ -1,103 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2018 IBM. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.ccsdk.config.model.utils; - -import static org.junit.Assert.assertTrue; -import org.junit.Test; -import org.onap.ccsdk.config.model.ValidTypes; -import com.fasterxml.jackson.databind.node.ArrayNode; -import com.fasterxml.jackson.databind.node.JsonNodeFactory; -import com.fasterxml.jackson.databind.node.ObjectNode; - -public class JsonUtilsTest { - - @Test - public void testPopulatePrimitiveValues() { - ObjectNode objectNode = JsonNodeFactory.instance.objectNode(); - JsonUtils.populatePrimitiveValues("key1", "value", "", objectNode); - JsonUtils.populatePrimitiveValues("key2", true, ValidTypes.DATA_TYPE_BOOLEAN, objectNode); - JsonUtils.populatePrimitiveValues("key3", 1, ValidTypes.DATA_TYPE_INTEGER, objectNode); - JsonUtils.populatePrimitiveValues("key4", 1.1f, ValidTypes.DATA_TYPE_FLOAT, objectNode); - JsonUtils.populatePrimitiveValues("key5", "13213123131", ValidTypes.DATA_TYPE_TIMESTAMP, objectNode); - - assertTrue("value".equals(objectNode.get("key1").asText())); - assertTrue(objectNode.get("key2").asBoolean()); - assertTrue(objectNode.get("key3").asInt() == 1); - assertTrue(objectNode.get("key4").floatValue() == 1.1f); - assertTrue("13213123131".equals(objectNode.get("key5").asText())); - } - - @Test - public void testPopulatePrimitiveValuesArrayNode() { - ArrayNode objectNode = JsonNodeFactory.instance.arrayNode(); - JsonUtils.populatePrimitiveValues("value", "", objectNode); - JsonUtils.populatePrimitiveValues(true, ValidTypes.DATA_TYPE_BOOLEAN, objectNode); - JsonUtils.populatePrimitiveValues(1, ValidTypes.DATA_TYPE_INTEGER, objectNode); - JsonUtils.populatePrimitiveValues(1.1f, ValidTypes.DATA_TYPE_FLOAT, objectNode); - JsonUtils.populatePrimitiveValues("13213123131", ValidTypes.DATA_TYPE_TIMESTAMP, objectNode); - - assertTrue(objectNode.size() == 5); - } - - @Test - public void testPopulatePrimitiveDefaultValues() { - ObjectNode objectNode = JsonNodeFactory.instance.objectNode(); - JsonUtils.populatePrimitiveDefaultValues("key1", "", objectNode); - JsonUtils.populatePrimitiveDefaultValues("key2", ValidTypes.DATA_TYPE_BOOLEAN, objectNode); - JsonUtils.populatePrimitiveDefaultValues("key3", ValidTypes.DATA_TYPE_INTEGER, objectNode); - JsonUtils.populatePrimitiveDefaultValues("key4", ValidTypes.DATA_TYPE_FLOAT, objectNode); - - assertTrue("".equals(objectNode.get("key1").asText())); - assertTrue(objectNode.get("key2").asBoolean() == false); - assertTrue(objectNode.get("key3").asInt() == 0); - assertTrue(objectNode.get("key4").floatValue() == 0.0f); - } - - @Test - public void testPopulatePrimitiveDefaultValuesForArrayNode() { - ArrayNode objectNode = JsonNodeFactory.instance.arrayNode(); - JsonUtils.populatePrimitiveDefaultValuesForArrayNode("", objectNode); - JsonUtils.populatePrimitiveDefaultValuesForArrayNode(ValidTypes.DATA_TYPE_BOOLEAN, objectNode); - JsonUtils.populatePrimitiveDefaultValuesForArrayNode(ValidTypes.DATA_TYPE_INTEGER, objectNode); - JsonUtils.populatePrimitiveDefaultValuesForArrayNode(ValidTypes.DATA_TYPE_FLOAT, objectNode); - - assertTrue(objectNode.size() == 4); - } - - @Test - public void testPopulateJsonNodeValues() { - ObjectNode objectNode = JsonNodeFactory.instance.objectNode(); - JsonUtils.populateJsonNodeValues("key1", JsonNodeFactory.instance.textNode("value"), - ValidTypes.DATA_TYPE_STRING, objectNode); - JsonUtils.populateJsonNodeValues("key2", JsonNodeFactory.instance.booleanNode(true), - ValidTypes.DATA_TYPE_BOOLEAN, objectNode); - JsonUtils.populateJsonNodeValues("key3", JsonNodeFactory.instance.numberNode(1), ValidTypes.DATA_TYPE_INTEGER, - objectNode); - JsonUtils.populateJsonNodeValues("key4", JsonNodeFactory.instance.numberNode(1.1f), ValidTypes.DATA_TYPE_FLOAT, - objectNode); - JsonUtils.populateJsonNodeValues("key5", JsonNodeFactory.instance.textNode("13213123131"), - ValidTypes.DATA_TYPE_TIMESTAMP, objectNode); - assertTrue(objectNode.get("key2").asBoolean()); - - assertTrue("value".equals(objectNode.get("key1").asText())); - assertTrue(objectNode.get("key2").asBoolean()); - assertTrue(objectNode.get("key3").asInt() == 1); - assertTrue(objectNode.get("key4").floatValue() == 1.1f); - assertTrue("13213123131".equals(objectNode.get("key5").asText())); - } -} diff --git a/blueprints-processor/plugin/model-provider/src/test/java/org/onap/ccsdk/config/model/utils/ResourceAssignmentUtilsTest.java b/blueprints-processor/plugin/model-provider/src/test/java/org/onap/ccsdk/config/model/utils/ResourceAssignmentUtilsTest.java deleted file mode 100644 index 034d70d7d..000000000 --- a/blueprints-processor/plugin/model-provider/src/test/java/org/onap/ccsdk/config/model/utils/ResourceAssignmentUtilsTest.java +++ /dev/null @@ -1,198 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2018 IBM. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.ccsdk.config.model.utils; - -import static org.junit.Assert.assertTrue; -import java.io.File; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import org.junit.Test; -import org.onap.ccsdk.config.model.ConfigModelConstant; -import org.onap.ccsdk.config.model.ConfigModelException; -import org.onap.ccsdk.config.model.ValidTypes; -import org.onap.ccsdk.config.model.data.PropertyDefinition; -import org.onap.ccsdk.config.model.data.ResourceAssignment; -import org.onap.ccsdk.config.model.data.dict.ResourceDefinition; -import com.fasterxml.jackson.core.type.TypeReference; -import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.ObjectMapper; - -public class ResourceAssignmentUtilsTest { - - @Test - public void testGetArtifactNodeContent() { - String nodeTemplateName = "nodeTemplateNmae"; - String templateContent = "content"; - Map context = new HashMap(); - context.put(ConfigModelConstant.PROPERTY_NODE_TEMPLATES_DOT + nodeTemplateName + ".content", templateContent); - - String retrievedContent = ResourceAssignmentUtils.getArtifactNodeContent(nodeTemplateName, context); - - assertTrue(templateContent.equals(retrievedContent)); - } - - @Test - public void testGetArtifactNodeMapping() { - String nodeTemplateName = "nodeTemplateNmae"; - String templateContent = "[]"; - Map context = new HashMap(); - context.put(ConfigModelConstant.PROPERTY_NODE_TEMPLATES_DOT + nodeTemplateName + ".mapping", templateContent); - - List map = ResourceAssignmentUtils.getArtifactNodeMapping(nodeTemplateName, context); - assertTrue(map.size() == 0); - } - - @Test - public void testCleanContextTemplateNDictionaryKeys() { - String recipeName = "recipe"; - Map componentContext = new HashMap(); - componentContext.put(ConfigModelConstant.PROPERTY_ACTION_NAME, recipeName); - componentContext.put(ConfigModelConstant.PROPERTY_DICTIONARY_KEY_DOT + recipeName + ".", "value1"); - componentContext.put(ConfigModelConstant.PROPERTY_RECIPE_KEY_DOT + recipeName + ".", "value2"); - ResourceAssignmentUtils.cleanContextTemplateNDictionaryKeys(componentContext); - - assertTrue(componentContext.size() == 1); - } - - @Test - public void testGetDictionaryKeyValue() { - String recipeName = "recipe"; - String dictionaryName = "dictionaryKey"; - Map componentContext = new HashMap(); - componentContext.put(ConfigModelConstant.PROPERTY_ACTION_NAME, recipeName); - componentContext.put(ConfigModelConstant.PROPERTY_DICTIONARY_KEY_DOT + recipeName + "." + dictionaryName, - "value1"); - ResourceAssignment resourceAssignment = new ResourceAssignment(); - resourceAssignment.setDictionaryName(dictionaryName); - - String value = (String) ResourceAssignmentUtils.getDictionaryKeyValue(componentContext, resourceAssignment); - assertTrue("value1".equals(value)); - } - - @Test - public void testGetDictionaryKeyValueWithDictionaryDefinition() { - String recipeName = "recipe"; - String dictionaryName = "dictionaryKey"; - Map componentContext = new HashMap(); - componentContext.put(ConfigModelConstant.PROPERTY_ACTION_NAME, recipeName); - componentContext.put(ConfigModelConstant.PROPERTY_DICTIONARY_KEY_DOT + recipeName + "." + dictionaryName, - "value1"); - ResourceDefinition resourceDefinition = new ResourceDefinition(); - resourceDefinition.setName(dictionaryName); - - String value = (String) ResourceAssignmentUtils.getDictionaryKeyValue(componentContext, resourceDefinition); - assertTrue("value1".equals(value)); - } - - @Test - public void testGetTemplateKeyValue() { - String recipeName = "recipe"; - String templateKeyName = "templateKey"; - Map componentContext = new HashMap(); - componentContext.put(ConfigModelConstant.PROPERTY_ACTION_NAME, recipeName); - componentContext.put(ConfigModelConstant.PROPERTY_RECIPE_KEY_DOT + recipeName + "." + templateKeyName, - "value1"); - ResourceAssignment resourceAssignment = new ResourceAssignment(); - resourceAssignment.setName(templateKeyName); - - String value = (String) ResourceAssignmentUtils.getTemplateKeyValue(componentContext, resourceAssignment); - assertTrue("value1".equals(value)); - } - - @Test - public void testSetResourceDataValue() throws Exception { - String recipeName = "recipe"; - Map componentContext = new HashMap(); - componentContext.put(ConfigModelConstant.PROPERTY_ACTION_NAME, recipeName); - - ResourceAssignment resourceAssignment = createResourceAssignment("name1", ValidTypes.DATA_TYPE_STRING, null); - Object value = "value"; - ResourceAssignmentUtils.setResourceDataValue(componentContext, resourceAssignment, value); - assertTrue(value.equals(resourceAssignment.getProperty().getValue())); - - resourceAssignment = createResourceAssignment("name1", ValidTypes.DATA_TYPE_INTEGER, null); - value = "1"; - ResourceAssignmentUtils.setResourceDataValue(componentContext, resourceAssignment, value); - assertTrue((int) resourceAssignment.getProperty().getValue() == 1); - - resourceAssignment = createResourceAssignment("name1", ValidTypes.DATA_TYPE_BOOLEAN, null); - value = "true"; - ResourceAssignmentUtils.setResourceDataValue(componentContext, resourceAssignment, value); - assertTrue((boolean) resourceAssignment.getProperty().getValue()); - - resourceAssignment = createResourceAssignment("name1", ValidTypes.DATA_TYPE_FLOAT, null); - value = "1.1"; - ResourceAssignmentUtils.setResourceDataValue(componentContext, resourceAssignment, value); - assertTrue((float) resourceAssignment.getProperty().getValue() == 1.1f); - } - - @Test - public void testSetFailedResourceDataValue() throws Exception { - ResourceAssignment resourceAssignment = createResourceAssignment("name1", ValidTypes.DATA_TYPE_STRING, "value"); - String message = "message"; - ResourceAssignmentUtils.setFailedResourceDataValue(null, resourceAssignment, message); - - assertTrue(message.equals(resourceAssignment.getMessage())); - assertTrue(ConfigModelConstant.STATUS_FAILURE.equals(resourceAssignment.getStatus())); - } - - @Test(expected = ConfigModelException.class) - public void testAssertTemplateKeyValueNotNull() throws Exception { - Map componentContext = null; - ResourceAssignment resourceAssignment = createResourceAssignment("name1", ValidTypes.DATA_TYPE_STRING, "value"); - ResourceAssignmentUtils.assertTemplateKeyValueNotNull(componentContext, resourceAssignment); - } - - @Test - public void testGenerateResourceDataForAssignments() throws Exception { - List assignments = new ArrayList(); - assignments.add(createResourceAssignment("name1", ValidTypes.DATA_TYPE_STRING, "string")); - assignments.add(createResourceAssignment("name2", ValidTypes.DATA_TYPE_BOOLEAN, true)); - assignments.add(createResourceAssignment("name3", ValidTypes.DATA_TYPE_INTEGER, 1)); - assignments.add(createResourceAssignment("name4", ValidTypes.DATA_TYPE_FLOAT, 1.1f)); - assignments.add(createResourceAssignment("name5", ValidTypes.DATA_TYPE_TIMESTAMP, "1523908097735")); - assignments.add(createResourceAssignment("name6", "", new HashMap())); - ResourceAssignmentUtils.generateResourceDataForAssignments(assignments); - } - - public void testResourceAssignmentForNullEmptyValues() throws Exception { - - ObjectMapper mapper = new ObjectMapper(); - JsonNode raContent = - mapper.readTree(new File("src/test/resources/service_templates/ra-content-with-mising-value.json")); - - List assignments = - mapper.readValue(raContent.toString(), new TypeReference>() {}); - - ResourceAssignmentUtils.generateResourceDataForAssignments(assignments); - } - - private ResourceAssignment createResourceAssignment(String name, String dataType, Object value) { - PropertyDefinition property = new PropertyDefinition(); - property.setType(dataType); - property.setValue(value); - property.setRequired(true); - ResourceAssignment ra = new ResourceAssignment(); - ra.setName(name); - ra.setProperty(property); - return ra; - } - -} diff --git a/blueprints-processor/plugin/model-provider/src/test/java/org/onap/ccsdk/config/model/utils/ServiceTemplateUtilsTest.java b/blueprints-processor/plugin/model-provider/src/test/java/org/onap/ccsdk/config/model/utils/ServiceTemplateUtilsTest.java deleted file mode 100644 index 5364ae924..000000000 --- a/blueprints-processor/plugin/model-provider/src/test/java/org/onap/ccsdk/config/model/utils/ServiceTemplateUtilsTest.java +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2018 IBM. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.ccsdk.config.model.utils; - -import java.util.HashMap; -import java.util.Map; -import org.junit.Assert; -import org.junit.Test; -import org.onap.ccsdk.config.model.data.ArtifactDefinition; -import org.onap.ccsdk.config.model.data.CapabilityAssignment; -import org.onap.ccsdk.config.model.data.NodeTemplate; - -public class ServiceTemplateUtilsTest { - - ServiceTemplateUtils serviceTemplateUtils = new ServiceTemplateUtils(); - - @Test - public void testPopulateVnfNodeProperties() { - NodeTemplate nodeTemplate = createNodeTemplate(); - - String nodeTemplateKey = "nodeTemplateKey"; - Map context = new HashMap(); - - Map result = - serviceTemplateUtils.populateVnfNodeProperties(nodeTemplateKey, nodeTemplate, context, null); - - Assert.assertTrue(result.size() > 0); - } - - @Test - public void testPopulateNodeTemplateArtifacts() { - String nodeTemplateKey = "nodeTemplateKey"; - NodeTemplate nodeTemplate = createNodeTemplate(); - Map context = new HashMap(); - - Map result = - serviceTemplateUtils.populateNodeTemplateArtifacts(nodeTemplateKey, nodeTemplate, context); - - Assert.assertTrue(result.size() > 0); - } - - private NodeTemplate createNodeTemplate() { - NodeTemplate nodeTemplate = new NodeTemplate(); - Map properties = new HashMap(); - properties.put("prop1", "value"); - CapabilityAssignment capabilityAssignment = new CapabilityAssignment(); - capabilityAssignment.setProperties(properties); - Map capabilities = new HashMap(); - capabilities.put("key", capabilityAssignment); - nodeTemplate.setCapabilities(capabilities); - - ArtifactDefinition artifactDefinition = new ArtifactDefinition(); - artifactDefinition.setFile("file"); - artifactDefinition.setDeployPath("deployPath"); - artifactDefinition.setContent("content"); - Map artifacts = new HashMap(); - artifacts.put("artifactName1", artifactDefinition); - nodeTemplate.setArtifacts(artifacts); - - return nodeTemplate; - } -} diff --git a/blueprints-processor/plugin/model-provider/src/test/java/org/onap/ccsdk/config/model/utils/TransformationUtilsTest.java b/blueprints-processor/plugin/model-provider/src/test/java/org/onap/ccsdk/config/model/utils/TransformationUtilsTest.java deleted file mode 100644 index ca57e5fab..000000000 --- a/blueprints-processor/plugin/model-provider/src/test/java/org/onap/ccsdk/config/model/utils/TransformationUtilsTest.java +++ /dev/null @@ -1,90 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2018 IBM. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.ccsdk.config.model.utils; - -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; -import java.util.HashMap; -import java.util.Map; -import org.junit.Test; -import com.fasterxml.jackson.databind.JsonNode; - -public class TransformationUtilsTest { - - @Test - public void testGetJson() { - Map configparameters = new HashMap(); - configparameters.put("key", "value"); - String json = TransformationUtils.getJson(configparameters); - assertTrue("{\"key\":\"value\"}".equals(json)); - } - - @Test - public void testGetJsonNodeForString() { - String content = "{\"key\":\"value\"}"; - JsonNode jsonNodeForString = TransformationUtils.getJsonNodeForString(content); - assertNotNull(jsonNodeForString); - } - - @Test - public void testGetMapfromJson() { - String content = "{\"key\":\"value\"}"; - Map mapfromJson = TransformationUtils.getMapfromJson(content); - assertTrue(mapfromJson.size() == 1); - assertTrue("value".equals(mapfromJson.get("key"))); - } - - @Test - public void testGetMapfromJsonString() { - String content = "{\"key\":\"value\"}"; - Map mapfromJson = TransformationUtils.getMapfromJsonString(content); - assertTrue(mapfromJson.size() == 1); - assertTrue("value".equals(mapfromJson.get("key"))); - } - - @Test - public void testConvertJson2RootProperties() throws Exception { - Map context = new HashMap(); - String jsonContent = "{\"key\":\"value\"}"; - Map convertJson2RootProperties = - TransformationUtils.convertJson2RootProperties(context, jsonContent); - assertTrue(convertJson2RootProperties.size() == 1); - assertTrue("value".equals(convertJson2RootProperties.get("key"))); - } - - @SuppressWarnings("unchecked") - @Test - public void testGetJsonNodeAndTreeToValueAndConvertJson2Properties() throws Exception { - Map configparameters = new HashMap(); - configparameters.put("key", "value"); - JsonNode jsonNode = TransformationUtils.getJsonNode(configparameters); - assertNotNull(jsonNode); - - Map result = TransformationUtils.treeToValue(jsonNode, HashMap.class); - assertTrue("value".equals(result.get("key"))); - - result = TransformationUtils.convertJson2Properties(null, jsonNode, null); - assertTrue("value".equals(result.get("key"))); - } - - @Test - public void testGetJsonSchema() { - String jsonSchema = TransformationUtils.getJsonSchema(String.class); - assertNotNull(jsonSchema); - } -} diff --git a/blueprints-processor/plugin/model-provider/src/test/java/org/onap/ccsdk/config/model/validator/ServiceTemplateValidationTest.java b/blueprints-processor/plugin/model-provider/src/test/java/org/onap/ccsdk/config/model/validator/ServiceTemplateValidationTest.java deleted file mode 100644 index 4c5e6a99c..000000000 --- a/blueprints-processor/plugin/model-provider/src/test/java/org/onap/ccsdk/config/model/validator/ServiceTemplateValidationTest.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2018 IBM. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.ccsdk.config.model.validator; - -import java.nio.charset.Charset; -import org.apache.commons.io.IOUtils; -import org.junit.Test; -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; - -public class ServiceTemplateValidationTest { - private static EELFLogger logger = EELFManager.getInstance().getLogger(ServiceTemplateValidationTest.class); - - @Test - public void validateServiceTemplate() { - try { - logger.info(" **************** Validating Default *****************"); - String serviceTemplateContent = IOUtils.toString(ServiceTemplateValidationTest.class.getClassLoader() - .getResourceAsStream("service_templates/default.json"), Charset.defaultCharset()); - ServiceTemplateValidator serviceTemplateValidator = new ServiceTemplateValidator(); - serviceTemplateValidator.validateServiceTemplate(serviceTemplateContent); - logger.info(" **************** Reqource Assignment *****************"); - serviceTemplateContent = IOUtils.toString(ServiceTemplateValidationTest.class.getClassLoader() - .getResourceAsStream("service_templates/resource_assignment.json"), Charset.defaultCharset()); - serviceTemplateValidator.validateServiceTemplate(serviceTemplateContent); - } catch (Exception e) { - e.printStackTrace(); - } - - } - -} diff --git a/blueprints-processor/plugin/model-provider/src/test/java/org/onap/ccsdk/config/params/service/ComponentNodeTest.java b/blueprints-processor/plugin/model-provider/src/test/java/org/onap/ccsdk/config/params/service/ComponentNodeTest.java deleted file mode 100644 index d73a622c6..000000000 --- a/blueprints-processor/plugin/model-provider/src/test/java/org/onap/ccsdk/config/params/service/ComponentNodeTest.java +++ /dev/null @@ -1,140 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2018 IBM. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.ccsdk.config.params.service; - -import static org.mockito.Matchers.any; -import java.io.File; -import java.nio.charset.Charset; -import java.util.Arrays; -import java.util.HashMap; -import java.util.Map; -import org.apache.commons.io.FileUtils; -import org.apache.commons.lang3.StringUtils; -import org.apache.sling.testing.mock.osgi.MockOsgi; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mock; -import org.mockito.Mockito; -import org.mockito.MockitoAnnotations; -import org.mockito.invocation.InvocationOnMock; -import org.mockito.runners.MockitoJUnitRunner; -import org.mockito.stubbing.Answer; -import org.onap.ccsdk.config.data.adaptor.domain.TransactionLog; -import org.onap.ccsdk.config.data.adaptor.service.ConfigResourceService; -import org.onap.ccsdk.config.model.ConfigModelConstant; -import org.onap.ccsdk.config.model.service.ComponentNodeDelegate; -import org.onap.ccsdk.config.model.service.ComponentNodeServiceImpl; -import org.onap.ccsdk.config.model.service.ConfigModelService; -import org.onap.ccsdk.config.model.service.ConfigModelServiceImpl; -import org.onap.ccsdk.config.model.utils.TransformationUtils; -import org.onap.ccsdk.config.rest.adaptor.service.ConfigRestAdaptorService; -import org.onap.ccsdk.sli.core.sli.SvcLogicContext; -import org.onap.ccsdk.sli.core.sli.SvcLogicException; -import org.osgi.framework.BundleContext; -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; - -@RunWith(MockitoJUnitRunner.class) -public class ComponentNodeTest { - private static EELFLogger logger = EELFManager.getInstance().getLogger(ComponentNodeTest.class); - @Mock - private ConfigResourceService configResourceService; - - @Mock - private ConfigRestAdaptorService configRestAdaptorService; - - BundleContext bundleContext = MockOsgi.newBundleContext(); - - @Before - public void before() { - MockitoAnnotations.initMocks(this); - - MockComponentNode mockSvcLogicPlugin = new MockComponentNode(); - bundleContext.registerService(MockComponentNode.class, mockSvcLogicPlugin, null); - - try { - Mockito.doAnswer(new Answer() { - @Override - public Void answer(InvocationOnMock invocationOnMock) throws Throwable { - Object[] args = invocationOnMock.getArguments(); - if (args != null) { - logger.trace("Transaction info " + Arrays.asList(args)); - } - return null; - } - }).when(configResourceService).save(any(TransactionLog.class)); - } catch (SvcLogicException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - - @After - public void after() { - - } - - @Test - public void testProcess() { - - try { - String serviceTemplateContent = FileUtils.readFileToString( - new File("src/test/resources/componentnode/default.json"), Charset.defaultCharset()); - ConfigModelService configModelService = new ConfigModelServiceImpl(configRestAdaptorService); - - Map map = new HashMap<>(); - configModelService.convertServiceTemplate2Properties(serviceTemplateContent, map); - - SvcLogicContext ctx = new SvcLogicContext(); - map.forEach((name, value) -> { - if (StringUtils.isNotBlank(name) && StringUtils.isNotBlank(value)) { - ctx.setAttribute(name, value); - } - }); - ctx.setAttribute("vnf-id", "1234"); - - ComponentNodeServiceImpl componentNodeService = - new ComponentNodeServiceImpl(bundleContext, configResourceService, configRestAdaptorService); - - ComponentNodeDelegate componentNodeDelegate = new ComponentNodeDelegate(componentNodeService); - Map inParams = new HashMap<>(); - inParams.put(ConfigModelConstant.PROPERTY_SELECTOR, "generate-configuration"); - - componentNodeDelegate.process(inParams, ctx); - TransformationUtils.printMap(inParams); - - } catch (Exception e) { - e.printStackTrace(); - } - - } - - @Test(expected = SvcLogicException.class) - public void testFailure() throws Exception { - ComponentNodeServiceImpl componentNodeService = - new ComponentNodeServiceImpl(bundleContext, configResourceService, configRestAdaptorService); - ComponentNodeDelegate componentNodeDelegate = new ComponentNodeDelegate(componentNodeService); - - Map inParams = new HashMap(); - inParams.put(ConfigModelConstant.PROPERTY_SELECTOR, "generate-configuration"); - SvcLogicContext ctx = new SvcLogicContext(); - componentNodeDelegate.process(inParams, ctx); - } -} diff --git a/blueprints-processor/plugin/model-provider/src/test/java/org/onap/ccsdk/config/params/service/ConfigModelServiceTest.java b/blueprints-processor/plugin/model-provider/src/test/java/org/onap/ccsdk/config/params/service/ConfigModelServiceTest.java deleted file mode 100644 index 77972a63e..000000000 --- a/blueprints-processor/plugin/model-provider/src/test/java/org/onap/ccsdk/config/params/service/ConfigModelServiceTest.java +++ /dev/null @@ -1,219 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2018 IBM. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.ccsdk.config.params.service; - -import static org.junit.Assert.fail; -import java.io.File; -import java.nio.charset.Charset; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import org.apache.commons.io.FileUtils; -import org.junit.Assert; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Matchers; -import org.mockito.Mock; -import org.mockito.Mockito; -import org.mockito.runners.MockitoJUnitRunner; -import org.onap.ccsdk.config.model.ConfigModelConstant; -import org.onap.ccsdk.config.model.data.ServiceTemplate; -import org.onap.ccsdk.config.model.domain.ConfigModel; -import org.onap.ccsdk.config.model.domain.ConfigModelContent; -import org.onap.ccsdk.config.model.service.ConfigModelService; -import org.onap.ccsdk.config.model.service.ConfigModelServiceImpl; -import org.onap.ccsdk.config.rest.adaptor.service.ConfigRestAdaptorService; -import org.onap.ccsdk.sli.core.sli.SvcLogicContext; -import org.onap.ccsdk.sli.core.sli.SvcLogicException; -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; - -@RunWith(MockitoJUnitRunner.class) -public class ConfigModelServiceTest { - - private static EELFLogger logger = EELFManager.getInstance().getLogger(ConfigModelServiceTest.class); - - @Mock - private ConfigRestAdaptorService configRestAdaptorService; - - @Test - public void testConfigAssignmentInputOutputParams() throws Exception { - - String fileContent = FileUtils.readFileToString( - new File("src/test/resources/service_templates/resource_assignment.json"), Charset.defaultCharset()); - - Map context = new HashMap<>(); - ConfigModelServiceImpl configModelServiceImpl = new ConfigModelServiceImpl(configRestAdaptorService); - context = configModelServiceImpl.convertServiceTemplate2Properties(fileContent, context); - - Assert.assertNotNull("Failed to Prepare Context : ", context); - - context.put("request-id", "12345"); - context.put("vnf-id", "vnf12345"); - - Map inparams = new HashMap(); - inparams.put(ConfigModelConstant.PROPERTY_SELECTOR, "resource-assignment"); - - SvcLogicContext inputContext = new SvcLogicContext(); - context.forEach((name, value) -> { - inputContext.setAttribute(name, value); - }); - - // TransformationUtils.printProperty(inputContext.toProperties()); - - configModelServiceImpl.assignInParamsFromModel(inputContext, inparams); - Assert.assertNotNull("In Param is Null : ", inparams); - Assert.assertNotNull("Failed to get entity-id in Inparms : ", inparams.get("resource-id")); - Assert.assertEquals("Failed to get entity-id vlaue in Inparms ", String.valueOf("vnf12345"), - inparams.get("resource-id")); - Assert.assertNotNull("Failed to get request-id in Inparms : ", inparams.get("request-id")); - Assert.assertEquals("Failed to get request-id vlaue in Inparms ", String.valueOf("12345"), - inparams.get("request-id")); - - configModelServiceImpl.assignOutParamsFromModel(inputContext, inparams); - logger.info("*************** Output Params *************"); - // TransformationUtils.printProperty(inputContext.toProperties()); - - } - - @Test - public void testConvertServiceTemplate2PropertiesComplex() throws Exception { - String fileContent = FileUtils.readFileToString( - new File("src/test/resources/service_templates/resource_assignment.json"), Charset.defaultCharset()); - - Map context = new HashMap<>(); - context.put("host-password", "1234"); - context.put("host-ip-address", "[123.23.34.45, 123.23.34.45]"); - - ConfigModelServiceImpl configModelServiceImpl = new ConfigModelServiceImpl(configRestAdaptorService); - configModelServiceImpl.convertServiceTemplate2Properties(fileContent, context); - - // TransformationUtils.printMap(context); - - Map inparams = new HashMap(); - inparams.put(ConfigModelConstant.PROPERTY_SELECTOR, "resource-assignment"); - logger.info("Before Input Result: " + inparams); - - SvcLogicContext inputContext = new SvcLogicContext(); - context.forEach((name, value) -> { - inputContext.setAttribute(name, value); - }); - - configModelServiceImpl.assignInParamsFromModel(inputContext, inparams); - logger.info("----------Input Result: " + inparams); - - inputContext.setAttribute("assignment-params", "default-assigned"); - configModelServiceImpl.assignOutParamsFromModel(inputContext, inparams); - - // TransformationUtils.printProperty(inputContext.toProperties()); - - } - - @Test - public void testGetNodeTemplateContent() throws Exception { - String templateContent = "{\"id\":\"id\"}"; - SvcLogicContext context = new SvcLogicContext(); - context.setAttribute(ConfigModelConstant.PROPERTY_NODE_TEMPLATES_DOT + templateContent + ".content", - templateContent); - - ConfigModelServiceImpl configModelServiceImpl = new ConfigModelServiceImpl(configRestAdaptorService); - String content = configModelServiceImpl.getNodeTemplateContent(context, templateContent); - - Assert.assertEquals(content, templateContent); - } - - @Test - public void testGetNodeTemplateMapping() throws Exception { - String templateContent = "{\"capabilities\":{\"mapping\":{\"properties\":{\"mapping\":[\"test\"]}}}}"; - SvcLogicContext context = new SvcLogicContext(); - context.setAttribute(ConfigModelConstant.PROPERTY_NODE_TEMPLATES_DOT + templateContent, templateContent); - - ConfigModelServiceImpl configModelServiceImpl = new ConfigModelServiceImpl(configRestAdaptorService); - configModelServiceImpl.getNodeTemplateMapping(context, templateContent); - // Assert.assertEquals(content, templateContent); - } - - @Test - public void testValidateServiceTemplate() throws Exception { - ConfigModelServiceImpl configModelServiceImpl = new ConfigModelServiceImpl(configRestAdaptorService); - ServiceTemplate serviceTemplate = new ServiceTemplate(); - - try { - configModelServiceImpl.validateServiceTemplate(null); - fail("Should have thrown exception"); - } catch (SvcLogicException e) { - } - - try { - configModelServiceImpl.validateServiceTemplate(serviceTemplate); - fail("Should have thrown exception"); - } catch (SvcLogicException e) { - } - - Map metadata = new HashMap(); - metadata.put(ConfigModelConstant.SERVICE_TEMPLATE_KEY_ARTIFACT_AUTHOR, "author"); - metadata.put(ConfigModelConstant.SERVICE_TEMPLATE_KEY_ARTIFACT_NAME, "name"); - metadata.put(ConfigModelConstant.SERVICE_TEMPLATE_KEY_ARTIFACT_VERSION, "version"); - serviceTemplate.setMetadata(metadata); - - Assert.assertTrue(configModelServiceImpl.validateServiceTemplate(serviceTemplate)); - } - - @Test - public void testPrepareContext() throws Exception { - Mockito.when(configRestAdaptorService.getResource(Matchers.anyString(), Matchers.anyString(), Matchers.any())) - .thenReturn(createConfigModel()); - - String input = "{\"action-name\": \"resource-assignment-action\"}"; - ConfigModelService configModelService = new ConfigModelServiceImpl(configRestAdaptorService); - - Map ctx = - configModelService.prepareContext(null, input, "serviceTemplateName", "serviceTemplateVersion"); - Assert.assertEquals("resource-assignment-action", ctx.get(ConfigModelConstant.PROPERTY_ACTION_NAME)); - - ctx = configModelService.prepareContext(null, input, "{}"); - Assert.assertEquals("resource-assignment-action", ctx.get(ConfigModelConstant.PROPERTY_ACTION_NAME)); - } - - @Test - public void testConvertServiceTemplate2Properties() throws Exception { - Map metadata = new HashMap(); - metadata.put("key", "value"); - ServiceTemplate serviceTemplate = new ServiceTemplate(); - serviceTemplate.setMetadata(metadata); - Map context = new HashMap(); - - ConfigModelService configModelService = new ConfigModelServiceImpl(configRestAdaptorService); - Map ctx = configModelService.convertServiceTemplate2Properties(serviceTemplate, context); - - Assert.assertEquals("value", ctx.get("key")); - } - - private ConfigModel createConfigModel() { - ConfigModel configModel = new ConfigModel(); - List configModelContents = new ArrayList(); - ConfigModelContent configModelContent = new ConfigModelContent(); - configModelContent.setContentType(ConfigModelConstant.MODEL_CONTENT_TYPE_TOSCA_JSON); - configModelContent.setContent("{\"description\": \"description\"}"); - configModelContents.add(configModelContent); - configModel.setConfigModelContents(configModelContents); - configModel.setPublished("Y"); - return configModel; - } -} diff --git a/blueprints-processor/plugin/model-provider/src/test/java/org/onap/ccsdk/config/params/service/ExpressionUtilsTest.java b/blueprints-processor/plugin/model-provider/src/test/java/org/onap/ccsdk/config/params/service/ExpressionUtilsTest.java deleted file mode 100644 index e72b0531f..000000000 --- a/blueprints-processor/plugin/model-provider/src/test/java/org/onap/ccsdk/config/params/service/ExpressionUtilsTest.java +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2018 IBM. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.ccsdk.config.params.service; - -import java.io.File; -import java.nio.charset.Charset; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import org.apache.commons.io.FileUtils; -import org.junit.Test; -import org.onap.ccsdk.config.model.utils.ExpressionUtils; -import org.onap.ccsdk.config.model.utils.TransformationUtils; -import org.onap.ccsdk.sli.core.sli.SvcLogicContext; -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; -import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.ObjectMapper; - -public class ExpressionUtilsTest { - private static EELFLogger logger = EELFManager.getInstance().getLogger(ExpressionUtilsTest.class); - - @Test - public void testProcessJsonExpression() throws Exception { - String fileContent = FileUtils.readFileToString(new File("src/test/resources/properties/default.json"), - Charset.defaultCharset()); - - SvcLogicContext context = new SvcLogicContext(); - context.setAttribute("host-password", "1234"); - context.setAttribute("host-ip-address", "[\"123.23.34.45\", \"123.23.34.45\"]"); - context.setAttribute("loopback-default", "[\"Sample\", \"Brinda\"]"); - - Map inparams = new HashMap(); - ExpressionUtils jsonExpressionUtils = new ExpressionUtils(context, inparams); - ObjectMapper mapper = new ObjectMapper(); - JsonNode rootArray = mapper.readTree(fileContent); - jsonExpressionUtils.processJsonExpression(rootArray); - - } - - @Test - public void testJson2Property() throws Exception { - String fileContent = FileUtils.readFileToString(new File("src/test/resources/properties/convert.json"), - Charset.defaultCharset()); - - List blockKeys = new ArrayList(); - blockKeys.add( - "interfaces.ResourceAssignmentService.operations.getResourceAssignment.inputs.assignment-mappings"); - blockKeys.add("interfaces.ResourceAssignmentService.operations.getResourceAssignment.outputs"); - blockKeys.add("type"); - - Map workflowMap = new HashMap<>(); - Map propertyMap = - TransformationUtils.convertJson2Properties(workflowMap, fileContent, blockKeys); - - TransformationUtils.printMap(propertyMap); - - } - -} diff --git a/blueprints-processor/plugin/model-provider/src/test/java/org/onap/ccsdk/config/params/service/MockComponentNode.java b/blueprints-processor/plugin/model-provider/src/test/java/org/onap/ccsdk/config/params/service/MockComponentNode.java deleted file mode 100644 index 00260c9e3..000000000 --- a/blueprints-processor/plugin/model-provider/src/test/java/org/onap/ccsdk/config/params/service/MockComponentNode.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2018 IBM. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.ccsdk.config.params.service; - -import java.util.Map; -import org.onap.ccsdk.config.model.service.ComponentNode; -import org.onap.ccsdk.sli.core.sli.SvcLogicContext; -import org.onap.ccsdk.sli.core.sli.SvcLogicException; -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; - -public class MockComponentNode implements ComponentNode { - private static EELFLogger logger = EELFManager.getInstance().getLogger(MockComponentNode.class); - - @Override - public Boolean preCondition(Map inParams, SvcLogicContext ctx, Map componentContext) - throws SvcLogicException { - logger.info("Received preCondition "); - componentContext.put("test-key", "test"); - return true; - } - - @Override - public void process(Map inParams, SvcLogicContext ctx) throws SvcLogicException { - - } - - @Override - public void process(Map inParams, SvcLogicContext ctx, Map componentContext) - throws SvcLogicException { - logger.info("Received Request " + componentContext); - } - - @Override - public void preProcess(Map inParams, SvcLogicContext ctx, Map componentContext) - throws SvcLogicException { - logger.info("Received preProcess "); - - } - - @Override - public void postProcess(Map inParams, SvcLogicContext ctx, Map componentContext) - throws SvcLogicException { - logger.info("Received postProcess "); - } - -} diff --git a/blueprints-processor/plugin/model-provider/src/test/java/org/onap/ccsdk/config/params/service/ServiceTemplateCreateUtils.java b/blueprints-processor/plugin/model-provider/src/test/java/org/onap/ccsdk/config/params/service/ServiceTemplateCreateUtils.java deleted file mode 100644 index 52f540565..000000000 --- a/blueprints-processor/plugin/model-provider/src/test/java/org/onap/ccsdk/config/params/service/ServiceTemplateCreateUtils.java +++ /dev/null @@ -1,193 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2018 IBM. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.ccsdk.config.params.service; - -import java.io.File; -import java.io.IOException; -import java.nio.charset.Charset; -import java.util.HashMap; -import java.util.Map; -import org.apache.commons.io.FileUtils; -import org.apache.commons.lang3.StringUtils; -import org.onap.ccsdk.config.model.ConfigModelConstant; -import org.onap.ccsdk.config.model.data.DataType; -import org.onap.ccsdk.config.model.data.NodeTemplate; -import org.onap.ccsdk.config.model.data.NodeType; -import org.onap.ccsdk.config.model.data.ServiceTemplate; -import org.onap.ccsdk.config.model.data.TopologyTemplate; -import org.onap.ccsdk.config.model.data.dict.ResourceDefinition; -import org.onap.ccsdk.config.model.utils.TransformationUtils; - -public class ServiceTemplateCreateUtils { - - public void createNodeTypes(String serviceTemplateFileName) throws IOException { - if (StringUtils.isNotBlank(serviceTemplateFileName)) { - String fileContent = - FileUtils.readFileToString(new File(serviceTemplateFileName), Charset.defaultCharset()); - if (StringUtils.isNotBlank(fileContent)) { - // System.out.println("NodeTypeCreateUtils.createNodeTypes()" +fileContent ); - ServiceTemplate serviceTemplate = TransformationUtils.readValue(fileContent, ServiceTemplate.class); - - String formattedServiceTemplateContent = TransformationUtils.getJson(serviceTemplate, true); - - FileUtils.writeStringToFile(new File("src/test/resources/service_templates/default.json"), - formattedServiceTemplateContent, Charset.defaultCharset()); - - createVrrNodeTemplate(serviceTemplate); - createDictionarySchema(); - - } - } - } - - public void createNodeTypes(ServiceTemplate serviceTemplate) throws IOException { - - if (serviceTemplate != null && serviceTemplate.getNodeTypes() != null) { - serviceTemplate.getNodeTypes().forEach((nodeTypeKey, node_types) -> { - - if (node_types != null && StringUtils.isNotBlank(node_types.getDerivedFrom())) { - - try { - String fileName = "src/test/resources/node_types/"; - if (ConfigModelConstant.MODEL_TYPE_NODE_VNF.equalsIgnoreCase(node_types.getDerivedFrom())) { - fileName = fileName + "vnf/" + nodeTypeKey + ".json"; - } - if (ConfigModelConstant.MODEL_TYPE_NODE_DG.equalsIgnoreCase(node_types.getDerivedFrom())) { - fileName = fileName + "dg/" + nodeTypeKey + ".json"; - } - if (ConfigModelConstant.MODEL_TYPE_NODE_COMPONENT - .equalsIgnoreCase(node_types.getDerivedFrom())) { - fileName = fileName + "component/" + nodeTypeKey + ".json"; - } - String content = TransformationUtils.getJson(node_types, true); - FileUtils.write(new File(fileName), content, Charset.defaultCharset()); - } catch (IOException e) { - e.printStackTrace(); - } - - } - System.out.println("NodeTypeCreateUtils.createNodeTypes()" + nodeTypeKey); - }); - } - - } - - public void createResourceAssignmentNodeTemplate(ServiceTemplate serviceTemplate) throws IOException { - if (serviceTemplate != null) { - ServiceTemplate workingServiceTemplate = new ServiceTemplate(); - workingServiceTemplate.setMetadata(serviceTemplate.getMetadata()); - - Map data_types = new HashMap(); - data_types.put("datatype-property", serviceTemplate.getDataTypes().get("datatype-property")); - data_types.put("datatype-resource-assignment", - serviceTemplate.getDataTypes().get("datatype-resource-assignment")); - - workingServiceTemplate.setDataTypes(data_types); - - TopologyTemplate topology_template = new TopologyTemplate(); - Map node_templates = new HashMap(); - - Map node_Templates = serviceTemplate.getTopologyTemplate().getNodeTemplates(); - - node_templates.put("base-config-template", node_Templates.get("base-config-template")); - node_templates.put("licence-template", node_Templates.get("licence-template")); - - node_templates.put("resource-assignment-action", node_Templates.get("resource-assignment-action")); - node_templates.put("resource-assignment", node_Templates.get("resource-assignment")); - - topology_template.setNodeTemplates(node_templates); - topology_template.setInputs(serviceTemplate.getTopologyTemplate().getInputs()); - - Map node_types = new HashMap(); - node_types.put("artifact-config-template", serviceTemplate.getNodeTypes().get("artifact-config-template")); - node_types.put("dg-resource-assignment", serviceTemplate.getNodeTypes().get("dg-resource-assignment")); - node_types.put("component-resource-assignment", - serviceTemplate.getNodeTypes().get("component-resource-assignment")); - - workingServiceTemplate.setNodeTypes(node_types); - workingServiceTemplate.setTopologyTemplate(topology_template); - - String workingServiceTemplateConmtent = TransformationUtils.getJson(workingServiceTemplate, true); - - FileUtils.writeStringToFile(new File("src/test/resources/service_templates/resource_assignment.json"), - workingServiceTemplateConmtent, Charset.defaultCharset()); - - File lcmFile = new File( - "../../../northbound/selfservice-api/provider/src/test/resources/service_templates/resource_assignment.json"); - FileUtils.writeStringToFile(lcmFile, workingServiceTemplateConmtent, Charset.defaultCharset()); - - File resourceAssignmetFile = new File( - "../../../plugin/assignment/provider/src/test/resources/service_templates/resource_assignment.json"); - FileUtils.writeStringToFile(resourceAssignmetFile, workingServiceTemplateConmtent, - Charset.defaultCharset()); - - System.out.println("NodeTypeCreateUtils.createNodeTemplate() :" + workingServiceTemplateConmtent); - } - - } - - public void createVrrNodeTemplate(ServiceTemplate serviceTemplate) throws IOException { - if (serviceTemplate != null) { - ServiceTemplate workingServiceTemplate = new ServiceTemplate(); - workingServiceTemplate.setMetadata(serviceTemplate.getMetadata()); - - TopologyTemplate topology_template = new TopologyTemplate(); - Map node_templates = new HashMap(); - - Map node_Templates = serviceTemplate.getTopologyTemplate().getNodeTemplates(); - - node_templates.put("resource-assignment-action", node_Templates.get("resource-assignment-action")); - node_templates.put("resource-assignment", node_Templates.get("resource-assignment")); - - node_templates.put("activate-action", node_Templates.get("activate-action")); - node_templates.put("base-config-template", node_Templates.get("base-config-template")); - node_templates.put("licence-template", node_Templates.get("licence-template")); - node_templates.put("vrr-netconf-device", node_Templates.get("vrr-netconf-device")); - node_templates.put("get-netconf-config", node_Templates.get("get-netconf-config")); - node_templates.put("edit-netconf-config", node_Templates.get("edit-netconf-config")); - node_templates.put("transaction-netconf-baseconfig", node_Templates.get("transaction-netconf-baseconfig")); - - topology_template.setNodeTemplates(node_templates); - topology_template.setInputs(serviceTemplate.getTopologyTemplate().getInputs()); - - workingServiceTemplate.setTopologyTemplate(topology_template); - - String workingServiceTemplateContent = TransformationUtils.getJson(workingServiceTemplate, true); - - FileUtils.writeStringToFile(new File("src/test/resources/service_templates/vrr_config.json"), - workingServiceTemplateContent, Charset.defaultCharset()); - - } - } - - public void createDictionarySchema() throws IOException { - String schema = TransformationUtils.getJsonSchema(ResourceDefinition.class); - FileUtils.writeStringToFile(new File("src/test/resources/dictionary/dictionary_schema.json"), schema, - Charset.defaultCharset()); - } - - public static void main(String[] args) { - try { - ServiceTemplateCreateUtils utils = new ServiceTemplateCreateUtils(); - utils.createNodeTypes("src/test/resources/service_templates/default.json"); - } catch (Exception e) { - // TODO: handle exception - } - } - -} diff --git a/blueprints-processor/plugin/model-provider/src/test/java/org/onap/ccsdk/features/model/ResourceDictionaryUtilsTest.java b/blueprints-processor/plugin/model-provider/src/test/java/org/onap/ccsdk/features/model/ResourceDictionaryUtilsTest.java new file mode 100644 index 000000000..a84f52f50 --- /dev/null +++ b/blueprints-processor/plugin/model-provider/src/test/java/org/onap/ccsdk/features/model/ResourceDictionaryUtilsTest.java @@ -0,0 +1,218 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2018 IBM. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.ccsdk.features.model; + +import java.util.Arrays; +import java.util.HashMap; +import org.junit.Assert; +import org.junit.Test; +import org.onap.ccsdk.features.model.ValidTypes; +import org.onap.ccsdk.features.model.data.PropertyDefinition; +import org.onap.ccsdk.features.model.data.ResourceAssignment; +import org.onap.ccsdk.features.model.data.dict.ResourceDefinition; +import org.onap.ccsdk.features.model.data.dict.SourcesDefinition; +import org.onap.ccsdk.features.model.data.dict.SourcesProperties; +import org.onap.ccsdk.features.model.utils.ResourceDictionaryUtils; + +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; + +public class ResourceDictionaryUtilsTest { + private static EELFLogger logger = EELFManager.getInstance().getLogger(ResourceDictionaryUtilsTest.class); + + @Test + public void validateSingleInputSource() { + try { + logger.info(" **************** Validating validateSingleInputSource *****************"); + ResourceAssignment resourceAssignment = new ResourceAssignment(); + resourceAssignment.setName("test-input-key"); + + PropertyDefinition propertyDefinition = new PropertyDefinition(); + propertyDefinition.setType(ValidTypes.DATA_TYPE_STRING); + + SourcesProperties sourcesProp = new SourcesProperties(); + sourcesProp.setDependencies(Arrays.asList(new String[] {"vnf-id", "vnf-name"})); + + SourcesDefinition sourceDef = new SourcesDefinition(); + sourceDef.setProperties(sourcesProp); + + HashMap sources = new HashMap<>(); + sources.put("input", sourceDef); + + ResourceDefinition resourceDefinition = new ResourceDefinition(); + resourceDefinition.setProperty(propertyDefinition); + resourceDefinition.setSources(sources); + + ResourceDictionaryUtils.populateSourceMapping(resourceAssignment, resourceDefinition); + + Assert.assertNotNull("Resource assignment input sourceName is missing ", + resourceAssignment.getDictionarySource()); + Assert.assertNotNull("Resource assignment input sourceName property is missing ", + resourceAssignment.getProperty()); + Assert.assertNotNull("Resource assignment input sourceName property type is missing ", + resourceAssignment.getProperty().getType()); + + } catch (Exception e) { + e.printStackTrace(); + } + } + + @Test + public void validateSingleDbSource() { + try { + logger.info(" **************** Validating validateSingleDbSource *****************"); + ResourceAssignment resourceAssignment = new ResourceAssignment(); + resourceAssignment.setName("test-db-key"); + + PropertyDefinition propertyDefinition = new PropertyDefinition(); + propertyDefinition.setType(ValidTypes.DATA_TYPE_STRING); + + SourcesProperties sourcesProp = new SourcesProperties(); + sourcesProp.setDependencies(Arrays.asList(new String[] {"vnf-id", "vnf-name"})); + + SourcesDefinition sourceDef = new SourcesDefinition(); + sourceDef.setProperties(sourcesProp); + + HashMap sources = new HashMap<>(); + sources.put("db", sourceDef); + + ResourceDefinition resourceDefinition = new ResourceDefinition(); + resourceDefinition.setProperty(propertyDefinition); + resourceDefinition.setSources(sources); + + ResourceDictionaryUtils.populateSourceMapping(resourceAssignment, resourceDefinition); + Assert.assertNotNull("Resource assignment db sourceName sourceName is missing ", + resourceAssignment.getDictionarySource()); + Assert.assertNotNull("Resource assignment db sourceName sourceName property is missing ", + resourceAssignment.getProperty()); + Assert.assertNotNull("Resource assignment db sourceName sourceName property type is missing ", + resourceAssignment.getProperty().getType()); + + Assert.assertNotNull("Resource assignment db dependecy is missing ", resourceAssignment.getDependencies()); + Assert.assertEquals("Resource assignment db dependecy count mismatch ", 2, + resourceAssignment.getDependencies().size()); + + } catch (Exception e) { + e.printStackTrace(); + } + } + + @Test + public void validateMultiSource() { + try { + logger.info(" **************** Validating validateMultiSource *****************"); + ResourceAssignment resourceAssignment = new ResourceAssignment(); + resourceAssignment.setName("test-multi-key"); + + PropertyDefinition propertyDefinition = new PropertyDefinition(); + propertyDefinition.setType(ValidTypes.DATA_TYPE_STRING); + + SourcesProperties sourcesProp = new SourcesProperties(); + sourcesProp.setDependencies(Arrays.asList(new String[] {"vnf-id", "vnf-name"})); + + SourcesDefinition sourceDef = new SourcesDefinition(); + sourceDef.setProperties(sourcesProp); + + HashMap sources = new HashMap<>(); + sources.put("input", sourceDef); + sources.put("mdsal", sourceDef); + + ResourceDefinition resourceDefinition = new ResourceDefinition(); + resourceDefinition.setProperty(propertyDefinition); + resourceDefinition.setSources(sources); + + ResourceDictionaryUtils.populateSourceMapping(resourceAssignment, resourceDefinition); + Assert.assertNotNull("Resource assignment db sourceName sourceName property is missing ", + resourceAssignment.getProperty()); + Assert.assertNotNull("Resource assignment db sourceName sourceName property type is missing ", + resourceAssignment.getProperty().getType()); + Assert.assertNull("Resource assignment multi sourceName sourceName definition is present ", + resourceAssignment.getDictionarySource()); + Assert.assertNull("Resource assignment multi sourceName dependecy is present ", + resourceAssignment.getDependencies()); + + } catch (Exception e) { + e.printStackTrace(); + } + } + + @Test + public void testSourceDefault() { + logger.info(" **************** Validating testSourceDefault *****************"); + ResourceAssignment resourceAssignment = new ResourceAssignment(); + resourceAssignment.setName("test-input-key"); + + PropertyDefinition propertyDefinition = new PropertyDefinition(); + propertyDefinition.setType(ValidTypes.DATA_TYPE_STRING); + + SourcesProperties sourcesProp = new SourcesProperties(); + sourcesProp.setDependencies(Arrays.asList(new String[] {"vnf-id", "vnf-name"})); + + SourcesDefinition sourceDef = new SourcesDefinition(); + sourceDef.setProperties(sourcesProp); + + HashMap sources = new HashMap<>(); + sources.put("default", sourceDef); + + ResourceDefinition resourceDefinition = new ResourceDefinition(); + resourceDefinition.setProperty(propertyDefinition); + resourceDefinition.setSources(sources); + + ResourceDictionaryUtils.populateSourceMapping(resourceAssignment, resourceDefinition); + + Assert.assertNotNull("Resource assignment default sourceName is missing ", + resourceAssignment.getDictionarySource()); + Assert.assertNotNull("Resource assignment default sourceName property is missing ", + resourceAssignment.getProperty()); + Assert.assertNotNull("Resource assignment default sourceName property type is missing ", + resourceAssignment.getProperty().getType()); + } + + @Test + public void testSourceMdsal() { + logger.info(" **************** Validating testSourceMdsal *****************"); + ResourceAssignment resourceAssignment = new ResourceAssignment(); + resourceAssignment.setName("test-input-key"); + + PropertyDefinition propertyDefinition = new PropertyDefinition(); + propertyDefinition.setType(ValidTypes.DATA_TYPE_STRING); + + SourcesProperties sourcesProp = new SourcesProperties(); + sourcesProp.setDependencies(Arrays.asList(new String[] {"vnf-id", "vnf-name"})); + + SourcesDefinition sourceDef = new SourcesDefinition(); + sourceDef.setProperties(sourcesProp); + + HashMap sources = new HashMap<>(); + sources.put("mdsal", sourceDef); + + ResourceDefinition resourceDefinition = new ResourceDefinition(); + resourceDefinition.setProperty(propertyDefinition); + resourceDefinition.setSources(sources); + + ResourceDictionaryUtils.populateSourceMapping(resourceAssignment, resourceDefinition); + + Assert.assertNotNull("Resource assignment mdsal sourceName is missing ", + resourceAssignment.getDictionarySource()); + Assert.assertNotNull("Resource assignment mdsal sourceName property is missing ", + resourceAssignment.getProperty()); + Assert.assertNotNull("Resource assignment mdsal sourceName property type is missing ", + resourceAssignment.getProperty().getType()); + } + +} diff --git a/blueprints-processor/plugin/model-provider/src/test/java/org/onap/ccsdk/features/model/utils/JsonParserUtilsTest.java b/blueprints-processor/plugin/model-provider/src/test/java/org/onap/ccsdk/features/model/utils/JsonParserUtilsTest.java new file mode 100644 index 000000000..98943db7e --- /dev/null +++ b/blueprints-processor/plugin/model-provider/src/test/java/org/onap/ccsdk/features/model/utils/JsonParserUtilsTest.java @@ -0,0 +1,45 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2018 IBM. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.ccsdk.features.model.utils; + +import org.junit.Assert; +import org.junit.Test; +import org.onap.ccsdk.features.model.utils.JsonParserUtils; + +import com.fasterxml.jackson.databind.JsonNode; + +public class JsonParserUtilsTest { + + @Test + public void testParse() { + final String jsonExample = "{\"key\":\"value\"}"; + + JsonNode rootJsonNode = JsonParserUtils.parse(jsonExample, "$"); + Assert.assertEquals(jsonExample, rootJsonNode.toString()); + + JsonNode keyJsonNode = JsonParserUtils.parse(rootJsonNode, "$['key']"); + Assert.assertEquals("value", keyJsonNode.asText()); + + Assert.assertEquals(jsonExample, + JsonParserUtils.parseNSet("{\"key\":\"NOT_VALUE\"}", "$['key']", keyJsonNode).toString()); + + rootJsonNode = JsonParserUtils.parse("{\"key\":\"NOT_VALUE\"}", "$"); + Assert.assertEquals(jsonExample, JsonParserUtils.parseNSet(rootJsonNode, "$['key']", keyJsonNode).toString()); + } + +} diff --git a/blueprints-processor/plugin/model-provider/src/test/java/org/onap/ccsdk/features/model/utils/JsonUtilsTest.java b/blueprints-processor/plugin/model-provider/src/test/java/org/onap/ccsdk/features/model/utils/JsonUtilsTest.java new file mode 100644 index 000000000..d5db17008 --- /dev/null +++ b/blueprints-processor/plugin/model-provider/src/test/java/org/onap/ccsdk/features/model/utils/JsonUtilsTest.java @@ -0,0 +1,105 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2018 IBM. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.ccsdk.features.model.utils; + +import static org.junit.Assert.assertTrue; +import org.junit.Test; +import org.onap.ccsdk.features.model.ValidTypes; +import org.onap.ccsdk.features.model.utils.JsonUtils; + +import com.fasterxml.jackson.databind.node.ArrayNode; +import com.fasterxml.jackson.databind.node.JsonNodeFactory; +import com.fasterxml.jackson.databind.node.ObjectNode; + +public class JsonUtilsTest { + + @Test + public void testPopulatePrimitiveValues() { + ObjectNode objectNode = JsonNodeFactory.instance.objectNode(); + JsonUtils.populatePrimitiveValues("key1", "value", "", objectNode); + JsonUtils.populatePrimitiveValues("key2", true, ValidTypes.DATA_TYPE_BOOLEAN, objectNode); + JsonUtils.populatePrimitiveValues("key3", 1, ValidTypes.DATA_TYPE_INTEGER, objectNode); + JsonUtils.populatePrimitiveValues("key4", 1.1f, ValidTypes.DATA_TYPE_FLOAT, objectNode); + JsonUtils.populatePrimitiveValues("key5", "13213123131", ValidTypes.DATA_TYPE_TIMESTAMP, objectNode); + + assertTrue("value".equals(objectNode.get("key1").asText())); + assertTrue(objectNode.get("key2").asBoolean()); + assertTrue(objectNode.get("key3").asInt() == 1); + assertTrue(objectNode.get("key4").floatValue() == 1.1f); + assertTrue("13213123131".equals(objectNode.get("key5").asText())); + } + + @Test + public void testPopulatePrimitiveValuesArrayNode() { + ArrayNode objectNode = JsonNodeFactory.instance.arrayNode(); + JsonUtils.populatePrimitiveValues("value", "", objectNode); + JsonUtils.populatePrimitiveValues(true, ValidTypes.DATA_TYPE_BOOLEAN, objectNode); + JsonUtils.populatePrimitiveValues(1, ValidTypes.DATA_TYPE_INTEGER, objectNode); + JsonUtils.populatePrimitiveValues(1.1f, ValidTypes.DATA_TYPE_FLOAT, objectNode); + JsonUtils.populatePrimitiveValues("13213123131", ValidTypes.DATA_TYPE_TIMESTAMP, objectNode); + + assertTrue(objectNode.size() == 5); + } + + @Test + public void testPopulatePrimitiveDefaultValues() { + ObjectNode objectNode = JsonNodeFactory.instance.objectNode(); + JsonUtils.populatePrimitiveDefaultValues("key1", "", objectNode); + JsonUtils.populatePrimitiveDefaultValues("key2", ValidTypes.DATA_TYPE_BOOLEAN, objectNode); + JsonUtils.populatePrimitiveDefaultValues("key3", ValidTypes.DATA_TYPE_INTEGER, objectNode); + JsonUtils.populatePrimitiveDefaultValues("key4", ValidTypes.DATA_TYPE_FLOAT, objectNode); + + assertTrue("".equals(objectNode.get("key1").asText())); + assertTrue(objectNode.get("key2").asBoolean() == false); + assertTrue(objectNode.get("key3").asInt() == 0); + assertTrue(objectNode.get("key4").floatValue() == 0.0f); + } + + @Test + public void testPopulatePrimitiveDefaultValuesForArrayNode() { + ArrayNode objectNode = JsonNodeFactory.instance.arrayNode(); + JsonUtils.populatePrimitiveDefaultValuesForArrayNode("", objectNode); + JsonUtils.populatePrimitiveDefaultValuesForArrayNode(ValidTypes.DATA_TYPE_BOOLEAN, objectNode); + JsonUtils.populatePrimitiveDefaultValuesForArrayNode(ValidTypes.DATA_TYPE_INTEGER, objectNode); + JsonUtils.populatePrimitiveDefaultValuesForArrayNode(ValidTypes.DATA_TYPE_FLOAT, objectNode); + + assertTrue(objectNode.size() == 4); + } + + @Test + public void testPopulateJsonNodeValues() { + ObjectNode objectNode = JsonNodeFactory.instance.objectNode(); + JsonUtils.populateJsonNodeValues("key1", JsonNodeFactory.instance.textNode("value"), + ValidTypes.DATA_TYPE_STRING, objectNode); + JsonUtils.populateJsonNodeValues("key2", JsonNodeFactory.instance.booleanNode(true), + ValidTypes.DATA_TYPE_BOOLEAN, objectNode); + JsonUtils.populateJsonNodeValues("key3", JsonNodeFactory.instance.numberNode(1), ValidTypes.DATA_TYPE_INTEGER, + objectNode); + JsonUtils.populateJsonNodeValues("key4", JsonNodeFactory.instance.numberNode(1.1f), ValidTypes.DATA_TYPE_FLOAT, + objectNode); + JsonUtils.populateJsonNodeValues("key5", JsonNodeFactory.instance.textNode("13213123131"), + ValidTypes.DATA_TYPE_TIMESTAMP, objectNode); + assertTrue(objectNode.get("key2").asBoolean()); + + assertTrue("value".equals(objectNode.get("key1").asText())); + assertTrue(objectNode.get("key2").asBoolean()); + assertTrue(objectNode.get("key3").asInt() == 1); + assertTrue(objectNode.get("key4").floatValue() == 1.1f); + assertTrue("13213123131".equals(objectNode.get("key5").asText())); + } +} diff --git a/blueprints-processor/plugin/model-provider/src/test/java/org/onap/ccsdk/features/model/utils/ResourceAssignmentUtilsTest.java b/blueprints-processor/plugin/model-provider/src/test/java/org/onap/ccsdk/features/model/utils/ResourceAssignmentUtilsTest.java new file mode 100644 index 000000000..53eb624b5 --- /dev/null +++ b/blueprints-processor/plugin/model-provider/src/test/java/org/onap/ccsdk/features/model/utils/ResourceAssignmentUtilsTest.java @@ -0,0 +1,200 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2018 IBM. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.ccsdk.features.model.utils; + +import static org.junit.Assert.assertTrue; +import java.io.File; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import org.junit.Test; +import org.onap.ccsdk.features.model.ConfigModelConstant; +import org.onap.ccsdk.features.model.ConfigModelException; +import org.onap.ccsdk.features.model.ValidTypes; +import org.onap.ccsdk.features.model.data.PropertyDefinition; +import org.onap.ccsdk.features.model.data.ResourceAssignment; +import org.onap.ccsdk.features.model.data.dict.ResourceDefinition; +import org.onap.ccsdk.features.model.utils.ResourceAssignmentUtils; + +import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; + +public class ResourceAssignmentUtilsTest { + + @Test + public void testGetArtifactNodeContent() { + String nodeTemplateName = "nodeTemplateNmae"; + String templateContent = "content"; + Map context = new HashMap(); + context.put(ConfigModelConstant.PROPERTY_NODE_TEMPLATES_DOT + nodeTemplateName + ".content", templateContent); + + String retrievedContent = ResourceAssignmentUtils.getArtifactNodeContent(nodeTemplateName, context); + + assertTrue(templateContent.equals(retrievedContent)); + } + + @Test + public void testGetArtifactNodeMapping() { + String nodeTemplateName = "nodeTemplateNmae"; + String templateContent = "[]"; + Map context = new HashMap(); + context.put(ConfigModelConstant.PROPERTY_NODE_TEMPLATES_DOT + nodeTemplateName + ".mapping", templateContent); + + List map = ResourceAssignmentUtils.getArtifactNodeMapping(nodeTemplateName, context); + assertTrue(map.size() == 0); + } + + @Test + public void testCleanContextTemplateNDictionaryKeys() { + String recipeName = "recipe"; + Map componentContext = new HashMap(); + componentContext.put(ConfigModelConstant.PROPERTY_ACTION_NAME, recipeName); + componentContext.put(ConfigModelConstant.PROPERTY_DICTIONARY_KEY_DOT + recipeName + ".", "value1"); + componentContext.put(ConfigModelConstant.PROPERTY_RECIPE_KEY_DOT + recipeName + ".", "value2"); + ResourceAssignmentUtils.cleanContextTemplateNDictionaryKeys(componentContext); + + assertTrue(componentContext.size() == 1); + } + + @Test + public void testGetDictionaryKeyValue() { + String recipeName = "recipe"; + String dictionaryName = "dictionaryKey"; + Map componentContext = new HashMap(); + componentContext.put(ConfigModelConstant.PROPERTY_ACTION_NAME, recipeName); + componentContext.put(ConfigModelConstant.PROPERTY_DICTIONARY_KEY_DOT + recipeName + "." + dictionaryName, + "value1"); + ResourceAssignment resourceAssignment = new ResourceAssignment(); + resourceAssignment.setDictionaryName(dictionaryName); + + String value = (String) ResourceAssignmentUtils.getDictionaryKeyValue(componentContext, resourceAssignment); + assertTrue("value1".equals(value)); + } + + @Test + public void testGetDictionaryKeyValueWithDictionaryDefinition() { + String recipeName = "recipe"; + String dictionaryName = "dictionaryKey"; + Map componentContext = new HashMap(); + componentContext.put(ConfigModelConstant.PROPERTY_ACTION_NAME, recipeName); + componentContext.put(ConfigModelConstant.PROPERTY_DICTIONARY_KEY_DOT + recipeName + "." + dictionaryName, + "value1"); + ResourceDefinition resourceDefinition = new ResourceDefinition(); + resourceDefinition.setName(dictionaryName); + + String value = (String) ResourceAssignmentUtils.getDictionaryKeyValue(componentContext, resourceDefinition); + assertTrue("value1".equals(value)); + } + + @Test + public void testGetTemplateKeyValue() { + String recipeName = "recipe"; + String templateKeyName = "templateKey"; + Map componentContext = new HashMap(); + componentContext.put(ConfigModelConstant.PROPERTY_ACTION_NAME, recipeName); + componentContext.put(ConfigModelConstant.PROPERTY_RECIPE_KEY_DOT + recipeName + "." + templateKeyName, + "value1"); + ResourceAssignment resourceAssignment = new ResourceAssignment(); + resourceAssignment.setName(templateKeyName); + + String value = (String) ResourceAssignmentUtils.getTemplateKeyValue(componentContext, resourceAssignment); + assertTrue("value1".equals(value)); + } + + @Test + public void testSetResourceDataValue() throws Exception { + String recipeName = "recipe"; + Map componentContext = new HashMap(); + componentContext.put(ConfigModelConstant.PROPERTY_ACTION_NAME, recipeName); + + ResourceAssignment resourceAssignment = createResourceAssignment("name1", ValidTypes.DATA_TYPE_STRING, null); + Object value = "value"; + ResourceAssignmentUtils.setResourceDataValue(componentContext, resourceAssignment, value); + assertTrue(value.equals(resourceAssignment.getProperty().getValue())); + + resourceAssignment = createResourceAssignment("name1", ValidTypes.DATA_TYPE_INTEGER, null); + value = "1"; + ResourceAssignmentUtils.setResourceDataValue(componentContext, resourceAssignment, value); + assertTrue((int) resourceAssignment.getProperty().getValue() == 1); + + resourceAssignment = createResourceAssignment("name1", ValidTypes.DATA_TYPE_BOOLEAN, null); + value = "true"; + ResourceAssignmentUtils.setResourceDataValue(componentContext, resourceAssignment, value); + assertTrue((boolean) resourceAssignment.getProperty().getValue()); + + resourceAssignment = createResourceAssignment("name1", ValidTypes.DATA_TYPE_FLOAT, null); + value = "1.1"; + ResourceAssignmentUtils.setResourceDataValue(componentContext, resourceAssignment, value); + assertTrue((float) resourceAssignment.getProperty().getValue() == 1.1f); + } + + @Test + public void testSetFailedResourceDataValue() throws Exception { + ResourceAssignment resourceAssignment = createResourceAssignment("name1", ValidTypes.DATA_TYPE_STRING, "value"); + String message = "message"; + ResourceAssignmentUtils.setFailedResourceDataValue(null, resourceAssignment, message); + + assertTrue(message.equals(resourceAssignment.getMessage())); + assertTrue(ConfigModelConstant.STATUS_FAILURE.equals(resourceAssignment.getStatus())); + } + + @Test(expected = ConfigModelException.class) + public void testAssertTemplateKeyValueNotNull() throws Exception { + Map componentContext = null; + ResourceAssignment resourceAssignment = createResourceAssignment("name1", ValidTypes.DATA_TYPE_STRING, "value"); + ResourceAssignmentUtils.assertTemplateKeyValueNotNull(componentContext, resourceAssignment); + } + + @Test + public void testGenerateResourceDataForAssignments() throws Exception { + List assignments = new ArrayList(); + assignments.add(createResourceAssignment("name1", ValidTypes.DATA_TYPE_STRING, "string")); + assignments.add(createResourceAssignment("name2", ValidTypes.DATA_TYPE_BOOLEAN, true)); + assignments.add(createResourceAssignment("name3", ValidTypes.DATA_TYPE_INTEGER, 1)); + assignments.add(createResourceAssignment("name4", ValidTypes.DATA_TYPE_FLOAT, 1.1f)); + assignments.add(createResourceAssignment("name5", ValidTypes.DATA_TYPE_TIMESTAMP, "1523908097735")); + assignments.add(createResourceAssignment("name6", "", new HashMap())); + ResourceAssignmentUtils.generateResourceDataForAssignments(assignments); + } + + public void testResourceAssignmentForNullEmptyValues() throws Exception { + + ObjectMapper mapper = new ObjectMapper(); + JsonNode raContent = + mapper.readTree(new File("src/test/resources/service_templates/ra-content-with-mising-value.json")); + + List assignments = + mapper.readValue(raContent.toString(), new TypeReference>() {}); + + ResourceAssignmentUtils.generateResourceDataForAssignments(assignments); + } + + private ResourceAssignment createResourceAssignment(String name, String dataType, Object value) { + PropertyDefinition property = new PropertyDefinition(); + property.setType(dataType); + property.setValue(value); + property.setRequired(true); + ResourceAssignment ra = new ResourceAssignment(); + ra.setName(name); + ra.setProperty(property); + return ra; + } + +} diff --git a/blueprints-processor/plugin/model-provider/src/test/java/org/onap/ccsdk/features/model/utils/ServiceTemplateUtilsTest.java b/blueprints-processor/plugin/model-provider/src/test/java/org/onap/ccsdk/features/model/utils/ServiceTemplateUtilsTest.java new file mode 100644 index 000000000..df330b69e --- /dev/null +++ b/blueprints-processor/plugin/model-provider/src/test/java/org/onap/ccsdk/features/model/utils/ServiceTemplateUtilsTest.java @@ -0,0 +1,78 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2018 IBM. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.ccsdk.features.model.utils; + +import java.util.HashMap; +import java.util.Map; +import org.junit.Assert; +import org.junit.Test; +import org.onap.ccsdk.features.model.data.ArtifactDefinition; +import org.onap.ccsdk.features.model.data.CapabilityAssignment; +import org.onap.ccsdk.features.model.data.NodeTemplate; +import org.onap.ccsdk.features.model.utils.ServiceTemplateUtils; + +public class ServiceTemplateUtilsTest { + + ServiceTemplateUtils serviceTemplateUtils = new ServiceTemplateUtils(); + + @Test + public void testPopulateVnfNodeProperties() { + NodeTemplate nodeTemplate = createNodeTemplate(); + + String nodeTemplateKey = "nodeTemplateKey"; + Map context = new HashMap(); + + Map result = + serviceTemplateUtils.populateVnfNodeProperties(nodeTemplateKey, nodeTemplate, context, null); + + Assert.assertTrue(result.size() > 0); + } + + @Test + public void testPopulateNodeTemplateArtifacts() { + String nodeTemplateKey = "nodeTemplateKey"; + NodeTemplate nodeTemplate = createNodeTemplate(); + Map context = new HashMap(); + + Map result = + serviceTemplateUtils.populateNodeTemplateArtifacts(nodeTemplateKey, nodeTemplate, context); + + Assert.assertTrue(result.size() > 0); + } + + private NodeTemplate createNodeTemplate() { + NodeTemplate nodeTemplate = new NodeTemplate(); + Map properties = new HashMap(); + properties.put("prop1", "value"); + CapabilityAssignment capabilityAssignment = new CapabilityAssignment(); + capabilityAssignment.setProperties(properties); + Map capabilities = new HashMap(); + capabilities.put("key", capabilityAssignment); + nodeTemplate.setCapabilities(capabilities); + + ArtifactDefinition artifactDefinition = new ArtifactDefinition(); + artifactDefinition.setFile("file"); + artifactDefinition.setDeployPath("deployPath"); + artifactDefinition.setContent("content"); + Map artifacts = new HashMap(); + artifacts.put("artifactName1", artifactDefinition); + nodeTemplate.setArtifacts(artifacts); + + return nodeTemplate; + } +} diff --git a/blueprints-processor/plugin/model-provider/src/test/java/org/onap/ccsdk/features/model/utils/TransformationUtilsTest.java b/blueprints-processor/plugin/model-provider/src/test/java/org/onap/ccsdk/features/model/utils/TransformationUtilsTest.java new file mode 100644 index 000000000..cfcf246cd --- /dev/null +++ b/blueprints-processor/plugin/model-provider/src/test/java/org/onap/ccsdk/features/model/utils/TransformationUtilsTest.java @@ -0,0 +1,92 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2018 IBM. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.ccsdk.features.model.utils; + +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import java.util.HashMap; +import java.util.Map; +import org.junit.Test; +import org.onap.ccsdk.features.model.utils.TransformationUtils; + +import com.fasterxml.jackson.databind.JsonNode; + +public class TransformationUtilsTest { + + @Test + public void testGetJson() { + Map configparameters = new HashMap(); + configparameters.put("key", "value"); + String json = TransformationUtils.getJson(configparameters); + assertTrue("{\"key\":\"value\"}".equals(json)); + } + + @Test + public void testGetJsonNodeForString() { + String content = "{\"key\":\"value\"}"; + JsonNode jsonNodeForString = TransformationUtils.getJsonNodeForString(content); + assertNotNull(jsonNodeForString); + } + + @Test + public void testGetMapfromJson() { + String content = "{\"key\":\"value\"}"; + Map mapfromJson = TransformationUtils.getMapfromJson(content); + assertTrue(mapfromJson.size() == 1); + assertTrue("value".equals(mapfromJson.get("key"))); + } + + @Test + public void testGetMapfromJsonString() { + String content = "{\"key\":\"value\"}"; + Map mapfromJson = TransformationUtils.getMapfromJsonString(content); + assertTrue(mapfromJson.size() == 1); + assertTrue("value".equals(mapfromJson.get("key"))); + } + + @Test + public void testConvertJson2RootProperties() throws Exception { + Map context = new HashMap(); + String jsonContent = "{\"key\":\"value\"}"; + Map convertJson2RootProperties = + TransformationUtils.convertJson2RootProperties(context, jsonContent); + assertTrue(convertJson2RootProperties.size() == 1); + assertTrue("value".equals(convertJson2RootProperties.get("key"))); + } + + @SuppressWarnings("unchecked") + @Test + public void testGetJsonNodeAndTreeToValueAndConvertJson2Properties() throws Exception { + Map configparameters = new HashMap(); + configparameters.put("key", "value"); + JsonNode jsonNode = TransformationUtils.getJsonNode(configparameters); + assertNotNull(jsonNode); + + Map result = TransformationUtils.treeToValue(jsonNode, HashMap.class); + assertTrue("value".equals(result.get("key"))); + + result = TransformationUtils.convertJson2Properties(null, jsonNode, null); + assertTrue("value".equals(result.get("key"))); + } + + @Test + public void testGetJsonSchema() { + String jsonSchema = TransformationUtils.getJsonSchema(String.class); + assertNotNull(jsonSchema); + } +} diff --git a/blueprints-processor/plugin/model-provider/src/test/java/org/onap/ccsdk/features/model/validator/ServiceTemplateValidationTest.java b/blueprints-processor/plugin/model-provider/src/test/java/org/onap/ccsdk/features/model/validator/ServiceTemplateValidationTest.java new file mode 100644 index 000000000..83ac18022 --- /dev/null +++ b/blueprints-processor/plugin/model-provider/src/test/java/org/onap/ccsdk/features/model/validator/ServiceTemplateValidationTest.java @@ -0,0 +1,49 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2018 IBM. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.ccsdk.features.model.validator; + +import java.nio.charset.Charset; +import org.apache.commons.io.IOUtils; +import org.junit.Test; +import org.onap.ccsdk.features.model.validator.ServiceTemplateValidator; + +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; + +public class ServiceTemplateValidationTest { + private static EELFLogger logger = EELFManager.getInstance().getLogger(ServiceTemplateValidationTest.class); + + @Test + public void validateServiceTemplate() { + try { + logger.info(" **************** Validating Default *****************"); + String serviceTemplateContent = IOUtils.toString(ServiceTemplateValidationTest.class.getClassLoader() + .getResourceAsStream("service_templates/default.json"), Charset.defaultCharset()); + ServiceTemplateValidator serviceTemplateValidator = new ServiceTemplateValidator(); + serviceTemplateValidator.validateServiceTemplate(serviceTemplateContent); + logger.info(" **************** Reqource Assignment *****************"); + serviceTemplateContent = IOUtils.toString(ServiceTemplateValidationTest.class.getClassLoader() + .getResourceAsStream("service_templates/resource_assignment.json"), Charset.defaultCharset()); + serviceTemplateValidator.validateServiceTemplate(serviceTemplateContent); + } catch (Exception e) { + e.printStackTrace(); + } + + } + +} diff --git a/blueprints-processor/plugin/model-provider/src/test/java/org/onap/ccsdk/features/params/service/ComponentNodeTest.java b/blueprints-processor/plugin/model-provider/src/test/java/org/onap/ccsdk/features/params/service/ComponentNodeTest.java new file mode 100644 index 000000000..9c048f48e --- /dev/null +++ b/blueprints-processor/plugin/model-provider/src/test/java/org/onap/ccsdk/features/params/service/ComponentNodeTest.java @@ -0,0 +1,140 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2018 IBM. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.ccsdk.features.params.service; + +import static org.mockito.Matchers.any; +import java.io.File; +import java.nio.charset.Charset; +import java.util.Arrays; +import java.util.HashMap; +import java.util.Map; +import org.apache.commons.io.FileUtils; +import org.apache.commons.lang3.StringUtils; +import org.apache.sling.testing.mock.osgi.MockOsgi; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.MockitoAnnotations; +import org.mockito.invocation.InvocationOnMock; +import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.stubbing.Answer; +import org.onap.ccsdk.features.data.adaptor.domain.TransactionLog; +import org.onap.ccsdk.features.data.adaptor.service.ConfigResourceService; +import org.onap.ccsdk.features.model.ConfigModelConstant; +import org.onap.ccsdk.features.model.service.ComponentNodeDelegate; +import org.onap.ccsdk.features.model.service.ComponentNodeServiceImpl; +import org.onap.ccsdk.features.model.service.ConfigModelService; +import org.onap.ccsdk.features.model.service.ConfigModelServiceImpl; +import org.onap.ccsdk.features.model.utils.TransformationUtils; +import org.onap.ccsdk.features.rest.adaptor.service.ConfigRestAdaptorService; +import org.onap.ccsdk.sli.core.sli.SvcLogicContext; +import org.onap.ccsdk.sli.core.sli.SvcLogicException; +import org.osgi.framework.BundleContext; +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; + +@RunWith(MockitoJUnitRunner.class) +public class ComponentNodeTest { + private static EELFLogger logger = EELFManager.getInstance().getLogger(ComponentNodeTest.class); + @Mock + private ConfigResourceService configResourceService; + + @Mock + private ConfigRestAdaptorService configRestAdaptorService; + + BundleContext bundleContext = MockOsgi.newBundleContext(); + + @Before + public void before() { + MockitoAnnotations.initMocks(this); + + MockComponentNode mockSvcLogicPlugin = new MockComponentNode(); + bundleContext.registerService(MockComponentNode.class, mockSvcLogicPlugin, null); + + try { + Mockito.doAnswer(new Answer() { + @Override + public Void answer(InvocationOnMock invocationOnMock) throws Throwable { + Object[] args = invocationOnMock.getArguments(); + if (args != null) { + logger.trace("Transaction info " + Arrays.asList(args)); + } + return null; + } + }).when(configResourceService).save(any(TransactionLog.class)); + } catch (SvcLogicException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + @After + public void after() { + + } + + @Test + public void testProcess() { + + try { + String serviceTemplateContent = FileUtils.readFileToString( + new File("src/test/resources/componentnode/default.json"), Charset.defaultCharset()); + ConfigModelService configModelService = new ConfigModelServiceImpl(configRestAdaptorService); + + Map map = new HashMap<>(); + configModelService.convertServiceTemplate2Properties(serviceTemplateContent, map); + + SvcLogicContext ctx = new SvcLogicContext(); + map.forEach((name, value) -> { + if (StringUtils.isNotBlank(name) && StringUtils.isNotBlank(value)) { + ctx.setAttribute(name, value); + } + }); + ctx.setAttribute("vnf-id", "1234"); + + ComponentNodeServiceImpl componentNodeService = + new ComponentNodeServiceImpl(bundleContext, configResourceService, configRestAdaptorService); + + ComponentNodeDelegate componentNodeDelegate = new ComponentNodeDelegate(componentNodeService); + Map inParams = new HashMap<>(); + inParams.put(ConfigModelConstant.PROPERTY_SELECTOR, "generate-configuration"); + + componentNodeDelegate.process(inParams, ctx); + TransformationUtils.printMap(inParams); + + } catch (Exception e) { + e.printStackTrace(); + } + + } + + @Test(expected = SvcLogicException.class) + public void testFailure() throws Exception { + ComponentNodeServiceImpl componentNodeService = + new ComponentNodeServiceImpl(bundleContext, configResourceService, configRestAdaptorService); + ComponentNodeDelegate componentNodeDelegate = new ComponentNodeDelegate(componentNodeService); + + Map inParams = new HashMap(); + inParams.put(ConfigModelConstant.PROPERTY_SELECTOR, "generate-configuration"); + SvcLogicContext ctx = new SvcLogicContext(); + componentNodeDelegate.process(inParams, ctx); + } +} diff --git a/blueprints-processor/plugin/model-provider/src/test/java/org/onap/ccsdk/features/params/service/ConfigModelServiceTest.java b/blueprints-processor/plugin/model-provider/src/test/java/org/onap/ccsdk/features/params/service/ConfigModelServiceTest.java new file mode 100644 index 000000000..3e62fafd0 --- /dev/null +++ b/blueprints-processor/plugin/model-provider/src/test/java/org/onap/ccsdk/features/params/service/ConfigModelServiceTest.java @@ -0,0 +1,219 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2018 IBM. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.ccsdk.features.params.service; + +import static org.junit.Assert.fail; +import java.io.File; +import java.nio.charset.Charset; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import org.apache.commons.io.FileUtils; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Matchers; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.runners.MockitoJUnitRunner; +import org.onap.ccsdk.features.model.ConfigModelConstant; +import org.onap.ccsdk.features.model.data.ServiceTemplate; +import org.onap.ccsdk.features.model.domain.ConfigModel; +import org.onap.ccsdk.features.model.domain.ConfigModelContent; +import org.onap.ccsdk.features.model.service.ConfigModelService; +import org.onap.ccsdk.features.model.service.ConfigModelServiceImpl; +import org.onap.ccsdk.features.rest.adaptor.service.ConfigRestAdaptorService; +import org.onap.ccsdk.sli.core.sli.SvcLogicContext; +import org.onap.ccsdk.sli.core.sli.SvcLogicException; +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; + +@RunWith(MockitoJUnitRunner.class) +public class ConfigModelServiceTest { + + private static EELFLogger logger = EELFManager.getInstance().getLogger(ConfigModelServiceTest.class); + + @Mock + private ConfigRestAdaptorService configRestAdaptorService; + + @Test + public void testConfigAssignmentInputOutputParams() throws Exception { + + String fileContent = FileUtils.readFileToString( + new File("src/test/resources/service_templates/resource_assignment.json"), Charset.defaultCharset()); + + Map context = new HashMap<>(); + ConfigModelServiceImpl configModelServiceImpl = new ConfigModelServiceImpl(configRestAdaptorService); + context = configModelServiceImpl.convertServiceTemplate2Properties(fileContent, context); + + Assert.assertNotNull("Failed to Prepare Context : ", context); + + context.put("request-id", "12345"); + context.put("vnf-id", "vnf12345"); + + Map inparams = new HashMap(); + inparams.put(ConfigModelConstant.PROPERTY_SELECTOR, "resource-assignment"); + + SvcLogicContext inputContext = new SvcLogicContext(); + context.forEach((name, value) -> { + inputContext.setAttribute(name, value); + }); + + // TransformationUtils.printProperty(inputContext.toProperties()); + + configModelServiceImpl.assignInParamsFromModel(inputContext, inparams); + Assert.assertNotNull("In Param is Null : ", inparams); + Assert.assertNotNull("Failed to get entity-id in Inparms : ", inparams.get("resource-id")); + Assert.assertEquals("Failed to get entity-id vlaue in Inparms ", String.valueOf("vnf12345"), + inparams.get("resource-id")); + Assert.assertNotNull("Failed to get request-id in Inparms : ", inparams.get("request-id")); + Assert.assertEquals("Failed to get request-id vlaue in Inparms ", String.valueOf("12345"), + inparams.get("request-id")); + + configModelServiceImpl.assignOutParamsFromModel(inputContext, inparams); + logger.info("*************** Output Params *************"); + // TransformationUtils.printProperty(inputContext.toProperties()); + + } + + @Test + public void testConvertServiceTemplate2PropertiesComplex() throws Exception { + String fileContent = FileUtils.readFileToString( + new File("src/test/resources/service_templates/resource_assignment.json"), Charset.defaultCharset()); + + Map context = new HashMap<>(); + context.put("host-password", "1234"); + context.put("host-ip-address", "[123.23.34.45, 123.23.34.45]"); + + ConfigModelServiceImpl configModelServiceImpl = new ConfigModelServiceImpl(configRestAdaptorService); + configModelServiceImpl.convertServiceTemplate2Properties(fileContent, context); + + // TransformationUtils.printMap(context); + + Map inparams = new HashMap(); + inparams.put(ConfigModelConstant.PROPERTY_SELECTOR, "resource-assignment"); + logger.info("Before Input Result: " + inparams); + + SvcLogicContext inputContext = new SvcLogicContext(); + context.forEach((name, value) -> { + inputContext.setAttribute(name, value); + }); + + configModelServiceImpl.assignInParamsFromModel(inputContext, inparams); + logger.info("----------Input Result: " + inparams); + + inputContext.setAttribute("assignment-params", "default-assigned"); + configModelServiceImpl.assignOutParamsFromModel(inputContext, inparams); + + // TransformationUtils.printProperty(inputContext.toProperties()); + + } + + @Test + public void testGetNodeTemplateContent() throws Exception { + String templateContent = "{\"id\":\"id\"}"; + SvcLogicContext context = new SvcLogicContext(); + context.setAttribute(ConfigModelConstant.PROPERTY_NODE_TEMPLATES_DOT + templateContent + ".content", + templateContent); + + ConfigModelServiceImpl configModelServiceImpl = new ConfigModelServiceImpl(configRestAdaptorService); + String content = configModelServiceImpl.getNodeTemplateContent(context, templateContent); + + Assert.assertEquals(content, templateContent); + } + + @Test + public void testGetNodeTemplateMapping() throws Exception { + String templateContent = "{\"capabilities\":{\"mapping\":{\"properties\":{\"mapping\":[\"test\"]}}}}"; + SvcLogicContext context = new SvcLogicContext(); + context.setAttribute(ConfigModelConstant.PROPERTY_NODE_TEMPLATES_DOT + templateContent, templateContent); + + ConfigModelServiceImpl configModelServiceImpl = new ConfigModelServiceImpl(configRestAdaptorService); + configModelServiceImpl.getNodeTemplateMapping(context, templateContent); + // Assert.assertEquals(content, templateContent); + } + + @Test + public void testValidateServiceTemplate() throws Exception { + ConfigModelServiceImpl configModelServiceImpl = new ConfigModelServiceImpl(configRestAdaptorService); + ServiceTemplate serviceTemplate = new ServiceTemplate(); + + try { + configModelServiceImpl.validateServiceTemplate(null); + fail("Should have thrown exception"); + } catch (SvcLogicException e) { + } + + try { + configModelServiceImpl.validateServiceTemplate(serviceTemplate); + fail("Should have thrown exception"); + } catch (SvcLogicException e) { + } + + Map metadata = new HashMap(); + metadata.put(ConfigModelConstant.SERVICE_TEMPLATE_KEY_ARTIFACT_AUTHOR, "author"); + metadata.put(ConfigModelConstant.SERVICE_TEMPLATE_KEY_ARTIFACT_NAME, "name"); + metadata.put(ConfigModelConstant.SERVICE_TEMPLATE_KEY_ARTIFACT_VERSION, "version"); + serviceTemplate.setMetadata(metadata); + + Assert.assertTrue(configModelServiceImpl.validateServiceTemplate(serviceTemplate)); + } + + @Test + public void testPrepareContext() throws Exception { + Mockito.when(configRestAdaptorService.getResource(Matchers.anyString(), Matchers.anyString(), Matchers.any())) + .thenReturn(createConfigModel()); + + String input = "{\"action-name\": \"resource-assignment-action\"}"; + ConfigModelService configModelService = new ConfigModelServiceImpl(configRestAdaptorService); + + Map ctx = + configModelService.prepareContext(null, input, "serviceTemplateName", "serviceTemplateVersion"); + Assert.assertEquals("resource-assignment-action", ctx.get(ConfigModelConstant.PROPERTY_ACTION_NAME)); + + ctx = configModelService.prepareContext(null, input, "{}"); + Assert.assertEquals("resource-assignment-action", ctx.get(ConfigModelConstant.PROPERTY_ACTION_NAME)); + } + + @Test + public void testConvertServiceTemplate2Properties() throws Exception { + Map metadata = new HashMap(); + metadata.put("key", "value"); + ServiceTemplate serviceTemplate = new ServiceTemplate(); + serviceTemplate.setMetadata(metadata); + Map context = new HashMap(); + + ConfigModelService configModelService = new ConfigModelServiceImpl(configRestAdaptorService); + Map ctx = configModelService.convertServiceTemplate2Properties(serviceTemplate, context); + + Assert.assertEquals("value", ctx.get("key")); + } + + private ConfigModel createConfigModel() { + ConfigModel configModel = new ConfigModel(); + List configModelContents = new ArrayList(); + ConfigModelContent configModelContent = new ConfigModelContent(); + configModelContent.setContentType(ConfigModelConstant.MODEL_CONTENT_TYPE_TOSCA_JSON); + configModelContent.setContent("{\"description\": \"description\"}"); + configModelContents.add(configModelContent); + configModel.setConfigModelContents(configModelContents); + configModel.setPublished("Y"); + return configModel; + } +} diff --git a/blueprints-processor/plugin/model-provider/src/test/java/org/onap/ccsdk/features/params/service/ExpressionUtilsTest.java b/blueprints-processor/plugin/model-provider/src/test/java/org/onap/ccsdk/features/params/service/ExpressionUtilsTest.java new file mode 100644 index 000000000..a1e273a84 --- /dev/null +++ b/blueprints-processor/plugin/model-provider/src/test/java/org/onap/ccsdk/features/params/service/ExpressionUtilsTest.java @@ -0,0 +1,76 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2018 IBM. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.ccsdk.features.params.service; + +import java.io.File; +import java.nio.charset.Charset; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import org.apache.commons.io.FileUtils; +import org.junit.Test; +import org.onap.ccsdk.features.model.utils.ExpressionUtils; +import org.onap.ccsdk.features.model.utils.TransformationUtils; +import org.onap.ccsdk.sli.core.sli.SvcLogicContext; +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; + +public class ExpressionUtilsTest { + private static EELFLogger logger = EELFManager.getInstance().getLogger(ExpressionUtilsTest.class); + + @Test + public void testProcessJsonExpression() throws Exception { + String fileContent = FileUtils.readFileToString(new File("src/test/resources/properties/default.json"), + Charset.defaultCharset()); + + SvcLogicContext context = new SvcLogicContext(); + context.setAttribute("host-password", "1234"); + context.setAttribute("host-ip-address", "[\"123.23.34.45\", \"123.23.34.45\"]"); + context.setAttribute("loopback-default", "[\"Sample\", \"Brinda\"]"); + + Map inparams = new HashMap(); + ExpressionUtils jsonExpressionUtils = new ExpressionUtils(context, inparams); + ObjectMapper mapper = new ObjectMapper(); + JsonNode rootArray = mapper.readTree(fileContent); + jsonExpressionUtils.processJsonExpression(rootArray); + + } + + @Test + public void testJson2Property() throws Exception { + String fileContent = FileUtils.readFileToString(new File("src/test/resources/properties/convert.json"), + Charset.defaultCharset()); + + List blockKeys = new ArrayList(); + blockKeys.add( + "interfaces.ResourceAssignmentService.operations.getResourceAssignment.inputs.assignment-mappings"); + blockKeys.add("interfaces.ResourceAssignmentService.operations.getResourceAssignment.outputs"); + blockKeys.add("type"); + + Map workflowMap = new HashMap<>(); + Map propertyMap = + TransformationUtils.convertJson2Properties(workflowMap, fileContent, blockKeys); + + TransformationUtils.printMap(propertyMap); + + } + +} diff --git a/blueprints-processor/plugin/model-provider/src/test/java/org/onap/ccsdk/features/params/service/MockComponentNode.java b/blueprints-processor/plugin/model-provider/src/test/java/org/onap/ccsdk/features/params/service/MockComponentNode.java new file mode 100644 index 000000000..35f23bcb1 --- /dev/null +++ b/blueprints-processor/plugin/model-provider/src/test/java/org/onap/ccsdk/features/params/service/MockComponentNode.java @@ -0,0 +1,63 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2018 IBM. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.ccsdk.features.params.service; + +import java.util.Map; + +import org.onap.ccsdk.features.model.service.ComponentNode; +import org.onap.ccsdk.sli.core.sli.SvcLogicContext; +import org.onap.ccsdk.sli.core.sli.SvcLogicException; +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; + +public class MockComponentNode implements ComponentNode { + private static EELFLogger logger = EELFManager.getInstance().getLogger(MockComponentNode.class); + + @Override + public Boolean preCondition(Map inParams, SvcLogicContext ctx, Map componentContext) + throws SvcLogicException { + logger.info("Received preCondition "); + componentContext.put("test-key", "test"); + return true; + } + + @Override + public void process(Map inParams, SvcLogicContext ctx) throws SvcLogicException { + + } + + @Override + public void process(Map inParams, SvcLogicContext ctx, Map componentContext) + throws SvcLogicException { + logger.info("Received Request " + componentContext); + } + + @Override + public void preProcess(Map inParams, SvcLogicContext ctx, Map componentContext) + throws SvcLogicException { + logger.info("Received preProcess "); + + } + + @Override + public void postProcess(Map inParams, SvcLogicContext ctx, Map componentContext) + throws SvcLogicException { + logger.info("Received postProcess "); + } + +} diff --git a/blueprints-processor/plugin/model-provider/src/test/java/org/onap/ccsdk/features/params/service/ServiceTemplateCreateUtils.java b/blueprints-processor/plugin/model-provider/src/test/java/org/onap/ccsdk/features/params/service/ServiceTemplateCreateUtils.java new file mode 100644 index 000000000..5c89d45ae --- /dev/null +++ b/blueprints-processor/plugin/model-provider/src/test/java/org/onap/ccsdk/features/params/service/ServiceTemplateCreateUtils.java @@ -0,0 +1,193 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2018 IBM. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.ccsdk.features.params.service; + +import java.io.File; +import java.io.IOException; +import java.nio.charset.Charset; +import java.util.HashMap; +import java.util.Map; +import org.apache.commons.io.FileUtils; +import org.apache.commons.lang3.StringUtils; +import org.onap.ccsdk.features.model.ConfigModelConstant; +import org.onap.ccsdk.features.model.data.DataType; +import org.onap.ccsdk.features.model.data.NodeTemplate; +import org.onap.ccsdk.features.model.data.NodeType; +import org.onap.ccsdk.features.model.data.ServiceTemplate; +import org.onap.ccsdk.features.model.data.TopologyTemplate; +import org.onap.ccsdk.features.model.data.dict.ResourceDefinition; +import org.onap.ccsdk.features.model.utils.TransformationUtils; + +public class ServiceTemplateCreateUtils { + + public void createNodeTypes(String serviceTemplateFileName) throws IOException { + if (StringUtils.isNotBlank(serviceTemplateFileName)) { + String fileContent = + FileUtils.readFileToString(new File(serviceTemplateFileName), Charset.defaultCharset()); + if (StringUtils.isNotBlank(fileContent)) { + // System.out.println("NodeTypeCreateUtils.createNodeTypes()" +fileContent ); + ServiceTemplate serviceTemplate = TransformationUtils.readValue(fileContent, ServiceTemplate.class); + + String formattedServiceTemplateContent = TransformationUtils.getJson(serviceTemplate, true); + + FileUtils.writeStringToFile(new File("src/test/resources/service_templates/default.json"), + formattedServiceTemplateContent, Charset.defaultCharset()); + + createVrrNodeTemplate(serviceTemplate); + createDictionarySchema(); + + } + } + } + + public void createNodeTypes(ServiceTemplate serviceTemplate) throws IOException { + + if (serviceTemplate != null && serviceTemplate.getNodeTypes() != null) { + serviceTemplate.getNodeTypes().forEach((nodeTypeKey, node_types) -> { + + if (node_types != null && StringUtils.isNotBlank(node_types.getDerivedFrom())) { + + try { + String fileName = "src/test/resources/node_types/"; + if (ConfigModelConstant.MODEL_TYPE_NODE_VNF.equalsIgnoreCase(node_types.getDerivedFrom())) { + fileName = fileName + "vnf/" + nodeTypeKey + ".json"; + } + if (ConfigModelConstant.MODEL_TYPE_NODE_DG.equalsIgnoreCase(node_types.getDerivedFrom())) { + fileName = fileName + "dg/" + nodeTypeKey + ".json"; + } + if (ConfigModelConstant.MODEL_TYPE_NODE_COMPONENT + .equalsIgnoreCase(node_types.getDerivedFrom())) { + fileName = fileName + "component/" + nodeTypeKey + ".json"; + } + String content = TransformationUtils.getJson(node_types, true); + FileUtils.write(new File(fileName), content, Charset.defaultCharset()); + } catch (IOException e) { + e.printStackTrace(); + } + + } + System.out.println("NodeTypeCreateUtils.createNodeTypes()" + nodeTypeKey); + }); + } + + } + + public void createResourceAssignmentNodeTemplate(ServiceTemplate serviceTemplate) throws IOException { + if (serviceTemplate != null) { + ServiceTemplate workingServiceTemplate = new ServiceTemplate(); + workingServiceTemplate.setMetadata(serviceTemplate.getMetadata()); + + Map data_types = new HashMap(); + data_types.put("datatype-property", serviceTemplate.getDataTypes().get("datatype-property")); + data_types.put("datatype-resource-assignment", + serviceTemplate.getDataTypes().get("datatype-resource-assignment")); + + workingServiceTemplate.setDataTypes(data_types); + + TopologyTemplate topology_template = new TopologyTemplate(); + Map node_templates = new HashMap(); + + Map node_Templates = serviceTemplate.getTopologyTemplate().getNodeTemplates(); + + node_templates.put("base-config-template", node_Templates.get("base-config-template")); + node_templates.put("licence-template", node_Templates.get("licence-template")); + + node_templates.put("resource-assignment-action", node_Templates.get("resource-assignment-action")); + node_templates.put("resource-assignment", node_Templates.get("resource-assignment")); + + topology_template.setNodeTemplates(node_templates); + topology_template.setInputs(serviceTemplate.getTopologyTemplate().getInputs()); + + Map node_types = new HashMap(); + node_types.put("artifact-config-template", serviceTemplate.getNodeTypes().get("artifact-config-template")); + node_types.put("dg-resource-assignment", serviceTemplate.getNodeTypes().get("dg-resource-assignment")); + node_types.put("component-resource-assignment", + serviceTemplate.getNodeTypes().get("component-resource-assignment")); + + workingServiceTemplate.setNodeTypes(node_types); + workingServiceTemplate.setTopologyTemplate(topology_template); + + String workingServiceTemplateConmtent = TransformationUtils.getJson(workingServiceTemplate, true); + + FileUtils.writeStringToFile(new File("src/test/resources/service_templates/resource_assignment.json"), + workingServiceTemplateConmtent, Charset.defaultCharset()); + + File lcmFile = new File( + "../../../northbound/selfservice-api/provider/src/test/resources/service_templates/resource_assignment.json"); + FileUtils.writeStringToFile(lcmFile, workingServiceTemplateConmtent, Charset.defaultCharset()); + + File resourceAssignmetFile = new File( + "../../../plugin/assignment/provider/src/test/resources/service_templates/resource_assignment.json"); + FileUtils.writeStringToFile(resourceAssignmetFile, workingServiceTemplateConmtent, + Charset.defaultCharset()); + + System.out.println("NodeTypeCreateUtils.createNodeTemplate() :" + workingServiceTemplateConmtent); + } + + } + + public void createVrrNodeTemplate(ServiceTemplate serviceTemplate) throws IOException { + if (serviceTemplate != null) { + ServiceTemplate workingServiceTemplate = new ServiceTemplate(); + workingServiceTemplate.setMetadata(serviceTemplate.getMetadata()); + + TopologyTemplate topology_template = new TopologyTemplate(); + Map node_templates = new HashMap(); + + Map node_Templates = serviceTemplate.getTopologyTemplate().getNodeTemplates(); + + node_templates.put("resource-assignment-action", node_Templates.get("resource-assignment-action")); + node_templates.put("resource-assignment", node_Templates.get("resource-assignment")); + + node_templates.put("activate-action", node_Templates.get("activate-action")); + node_templates.put("base-config-template", node_Templates.get("base-config-template")); + node_templates.put("licence-template", node_Templates.get("licence-template")); + node_templates.put("vrr-netconf-device", node_Templates.get("vrr-netconf-device")); + node_templates.put("get-netconf-config", node_Templates.get("get-netconf-config")); + node_templates.put("edit-netconf-config", node_Templates.get("edit-netconf-config")); + node_templates.put("transaction-netconf-baseconfig", node_Templates.get("transaction-netconf-baseconfig")); + + topology_template.setNodeTemplates(node_templates); + topology_template.setInputs(serviceTemplate.getTopologyTemplate().getInputs()); + + workingServiceTemplate.setTopologyTemplate(topology_template); + + String workingServiceTemplateContent = TransformationUtils.getJson(workingServiceTemplate, true); + + FileUtils.writeStringToFile(new File("src/test/resources/service_templates/vrr_config.json"), + workingServiceTemplateContent, Charset.defaultCharset()); + + } + } + + public void createDictionarySchema() throws IOException { + String schema = TransformationUtils.getJsonSchema(ResourceDefinition.class); + FileUtils.writeStringToFile(new File("src/test/resources/dictionary/dictionary_schema.json"), schema, + Charset.defaultCharset()); + } + + public static void main(String[] args) { + try { + ServiceTemplateCreateUtils utils = new ServiceTemplateCreateUtils(); + utils.createNodeTypes("src/test/resources/service_templates/default.json"); + } catch (Exception e) { + // TODO: handle exception + } + } + +} diff --git a/blueprints-processor/plugin/model-provider/src/test/resources/componentnode/default.json b/blueprints-processor/plugin/model-provider/src/test/resources/componentnode/default.json index 0129195c2..e538b0c48 100644 --- a/blueprints-processor/plugin/model-provider/src/test/resources/componentnode/default.json +++ b/blueprints-processor/plugin/model-provider/src/test/resources/componentnode/default.json @@ -41,7 +41,7 @@ "generate-configuration": { "type": "mock-component-generateConfig", "interfaces": { - "org-onap-ccsdk-config-params-service-MockComponentNode": { + "org-onap-ccsdk-features-params-service-MockComponentNode": { "operations": { "process": { "inputs": { @@ -63,7 +63,7 @@ "node_types": { "mock-component-generateConfig": { "interfaces": { - "org-onap-ccsdk-config-params-service-MockComponentNode": { + "org-onap-ccsdk-features-params-service-MockComponentNode": { "operations": { "process": { "inputs": { diff --git a/blueprints-processor/plugin/model-provider/src/test/resources/service_templates/default.json b/blueprints-processor/plugin/model-provider/src/test/resources/service_templates/default.json index d3dd9934a..e53f0f6cd 100644 --- a/blueprints-processor/plugin/model-provider/src/test/resources/service_templates/default.json +++ b/blueprints-processor/plugin/model-provider/src/test/resources/service_templates/default.json @@ -146,7 +146,7 @@ "resource-assignment" : { "type" : "component-resource-assignment", "interfaces" : { - "org-onap-ccsdk-config-assignment-service-ConfigAssignmentNode" : { + "org-onap-ccsdk-features-assignment-service-ConfigAssignmentNode" : { "operations" : { "process" : { "inputs" : { @@ -171,7 +171,7 @@ "generate-configuration" : { "type" : "component-config-generator", "interfaces" : { - "org-onap-ccsdk-config-generator-service-ConfigGeneratorNode" : { + "org-onap-ccsdk-features-generator-service-ConfigGeneratorNode" : { "operations" : { "process" : { "inputs" : { @@ -403,7 +403,7 @@ } }, "interfaces" : { - "org-onap-ccsdk-config-assignment-service-ConfigAssignmentNode" : { + "org-onap-ccsdk-features-assignment-service-ConfigAssignmentNode" : { "operations" : { "process" : { "inputs" : { @@ -465,7 +465,7 @@ } }, "interfaces" : { - "org-onap-ccsdk-config-generator-service-ConfigGeneratorNode" : { + "org-onap-ccsdk-features-generator-service-ConfigGeneratorNode" : { "operations" : { "process" : { "inputs" : { @@ -512,7 +512,7 @@ "type" : "string" }, "mask-info" : { - "description" : "If template contains mask encription keys, then this mask-info field will be generated, This JSON Content alligns to the bean org.onap.ccsdk.config.model.data.custom.MaskInfo ", + "description" : "If template contains mask encription keys, then this mask-info field will be generated, This JSON Content alligns to the bean org.onap.ccsdk.features.model.data.custom.MaskInfo ", "required" : false, "type" : "string" }, diff --git a/blueprints-processor/plugin/model-provider/src/test/resources/service_templates/resource_assignment.json b/blueprints-processor/plugin/model-provider/src/test/resources/service_templates/resource_assignment.json index 0e29fe160..cbea6a82c 100644 --- a/blueprints-processor/plugin/model-provider/src/test/resources/service_templates/resource_assignment.json +++ b/blueprints-processor/plugin/model-provider/src/test/resources/service_templates/resource_assignment.json @@ -139,7 +139,7 @@ "resource-assignment": { "type": "component-resource-assignment", "interfaces": { - "org-onap-ccsdk-config-assignment-service-ConfigAssignmentNode": { + "org-onap-ccsdk-features-assignment-service-ConfigAssignmentNode": { "operations": { "process": { "inputs": { @@ -243,7 +243,7 @@ } }, "interfaces": { - "org-onap-ccsdk-config-assignment-service-ConfigAssignmentNode": { + "org-onap-ccsdk-features-assignment-service-ConfigAssignmentNode": { "operations": { "process": { "inputs": { diff --git a/blueprints-processor/plugin/model-provider/src/test/resources/service_templates/vrr_config.json b/blueprints-processor/plugin/model-provider/src/test/resources/service_templates/vrr_config.json index fdfb12799..8c87f2d34 100644 --- a/blueprints-processor/plugin/model-provider/src/test/resources/service_templates/vrr_config.json +++ b/blueprints-processor/plugin/model-provider/src/test/resources/service_templates/vrr_config.json @@ -139,7 +139,7 @@ "resource-assignment": { "type": "component-resource-assignment", "interfaces": { - "org-onap-ccsdk-config-assignment-service-ConfigAssignmentNode": { + "org-onap-ccsdk-features-assignment-service-ConfigAssignmentNode": { "operations": { "process": { "inputs": { -- cgit 1.2.3-korg