summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMuthuramalingam, Brinda Santh(bs2796) <bs2796@att.com>2018-09-12 16:26:31 +0000
committerMuthuramalingam, Brinda Santh(bs2796) <bs2796@att.com>2018-09-12 16:26:31 +0000
commitcb0fe8c1d1ef6962a2e96cea9838454e28adccbe (patch)
tree9c5da532c0cfc89ff612eb51ef2cb847ca9ef4df
parentb21540f1211a039aa6907f60d7621c8d331ec94f (diff)
Controller Blueprints Microservice
Add dynamic resource source mapping rest service. Change-Id: I59274a4c0162bc6718c4248788c0e7f36830a129 Issue-ID: CCSDK-556 Signed-off-by: Muthuramalingam, Brinda Santh(bs2796) <bs2796@att.com>
-rw-r--r--components/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/ResourceDefinition.kt6
-rw-r--r--components/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/factory/ResourceSourceMappingFactory.kt47
-rw-r--r--components/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceAssignmentEnhancerService.kt86
-rw-r--r--components/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/factory/ResourceSourceMappingFactoryTest.java42
-rw-r--r--components/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceAssignmentEnhancerServiceTest.java48
-rw-r--r--components/resource-dict/src/test/resources/enrich/simple-enrich.json37
6 files changed, 95 insertions, 171 deletions
diff --git a/components/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/ResourceDefinition.kt b/components/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/ResourceDefinition.kt
index ff2608711..d141ed0cb 100644
--- a/components/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/ResourceDefinition.kt
+++ b/components/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/ResourceDefinition.kt
@@ -1,5 +1,6 @@
/*
* Copyright © 2018 IBM.
+ * Modifications Copyright © 2017-2018 AT&T Intellectual Property.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -92,3 +93,8 @@ open class ResourceAssignment {
* Default Source, Database Source, Rest Sources, etc)
*/
interface ResourceSource : Serializable
+
+
+open class ResourceSourceMapping {
+ lateinit var resourceSourceMappings: MutableMap<String, String>
+}
diff --git a/components/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/factory/ResourceSourceMappingFactory.kt b/components/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/factory/ResourceSourceMappingFactory.kt
new file mode 100644
index 000000000..2911ab26a
--- /dev/null
+++ b/components/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/factory/ResourceSourceMappingFactory.kt
@@ -0,0 +1,47 @@
+/*
+ * Copyright © 2017-2018 AT&T Intellectual Property.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onap.ccsdk.apps.controllerblueprints.resource.dict.factory
+
+import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException
+import org.onap.ccsdk.apps.controllerblueprints.core.format
+import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceSourceMapping
+
+/**
+ * ResourceSourceMappingFactory.
+ *
+ * @author Brinda Santh
+ */
+object ResourceSourceMappingFactory {
+
+ private val resourceSourceMappings: MutableMap<String, String> = hashMapOf()
+
+ fun registerSourceMapping(sourceInstance: String, nodeTypeName: String) {
+ resourceSourceMappings[sourceInstance] = nodeTypeName
+ }
+
+ fun getRegisterSourceMapping(sourceInstance: String): String {
+ return resourceSourceMappings[sourceInstance]
+ ?: throw BluePrintException(format("failed to get source({}) mapping", sourceInstance))
+ }
+
+ fun getRegisterSourceMapping(): ResourceSourceMapping {
+ val resourceSourceMapping = ResourceSourceMapping()
+ resourceSourceMapping.resourceSourceMappings = resourceSourceMappings
+ return resourceSourceMapping
+ }
+}
+
diff --git a/components/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceAssignmentEnhancerService.kt b/components/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceAssignmentEnhancerService.kt
deleted file mode 100644
index c5a78a9c9..000000000
--- a/components/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceAssignmentEnhancerService.kt
+++ /dev/null
@@ -1,86 +0,0 @@
-/*
- * Copyright © 2017-2018 AT&T Intellectual Property.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.onap.ccsdk.apps.controllerblueprints.resource.dict.service
-
-import com.att.eelf.configuration.EELFLogger
-import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException
-import org.onap.ccsdk.apps.controllerblueprints.core.data.ServiceTemplate
-import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintEnhancerDefaultService
-import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintEnhancerService
-import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignment
-import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceDefinition
-import com.att.eelf.configuration.EELFManager
-
-/**
- * ResourceAssignmentEnhancerService.
- *
- * @author Brinda Santh
- */
-interface ResourceAssignmentEnhancerService {
-
- @Throws(BluePrintException::class)
- fun enhanceBluePrint(bluePrintEnhancerService: BluePrintEnhancerService,
- resourceAssignments: List<ResourceAssignment>)
-
- @Throws(BluePrintException::class)
- fun enhanceBluePrint(resourceAssignments: List<ResourceAssignment>): ServiceTemplate
-}
-
-/**
- * ResourceAssignmentEnhancerDefaultService.
- *
- * @author Brinda Santh
- */
-open class ResourceAssignmentEnhancerDefaultService(private val resourceDefinitionRepoService: ResourceDefinitionRepoService)
- : ResourceAssignmentEnhancerService {
- private val log: EELFLogger = EELFManager.getInstance().getLogger(ResourceAssignmentValidationDefaultService::class.java)
-
- /**
- * Get the defined source instance from the ResourceAssignment,
- * then get the NodeType of the Sources assigned
- */
- override fun enhanceBluePrint(bluePrintEnhancerService: BluePrintEnhancerService,
- resourceAssignments: List<ResourceAssignment>) {
-
- // Iterate the Resource Assignment and
- resourceAssignments.map { resourceAssignment ->
- val dictionaryName = resourceAssignment.dictionaryName!!
- val dictionarySource = resourceAssignment.dictionarySource!!
- log.info("Enriching Assignment name({}), dictionary name({}), source({})", resourceAssignment.name,
- dictionaryName, dictionarySource)
- // Get the Resource Definition from Repo
- val resourceDefinition: ResourceDefinition = getResourceDefinition(dictionaryName)
-
- val sourceNodeTemplate = resourceDefinition.sources.get(dictionarySource)
-
- // Enrich as NodeTemplate
- bluePrintEnhancerService.enrichNodeTemplate(dictionarySource, sourceNodeTemplate!!)
- }
- }
-
- override fun enhanceBluePrint(resourceAssignments: List<ResourceAssignment>): ServiceTemplate {
- val bluePrintEnhancerService = BluePrintEnhancerDefaultService(resourceDefinitionRepoService)
- bluePrintEnhancerService.serviceTemplate = ServiceTemplate()
- bluePrintEnhancerService.initialCleanUp()
- enhanceBluePrint(bluePrintEnhancerService, resourceAssignments)
- return bluePrintEnhancerService.serviceTemplate
- }
-
- private fun getResourceDefinition(name: String): ResourceDefinition {
- return resourceDefinitionRepoService.getResourceDefinition(name)!!.block()!!
- }
-} \ No newline at end of file
diff --git a/components/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/factory/ResourceSourceMappingFactoryTest.java b/components/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/factory/ResourceSourceMappingFactoryTest.java
new file mode 100644
index 000000000..b67aa7998
--- /dev/null
+++ b/components/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/factory/ResourceSourceMappingFactoryTest.java
@@ -0,0 +1,42 @@
+/*
+ * Copyright © 2017-2018 AT&T Intellectual Property.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onap.ccsdk.apps.controllerblueprints.resource.dict.factory;
+
+import org.junit.Test;
+import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceSourceMapping;
+import org.springframework.util.Assert;
+
+public class ResourceSourceMappingFactoryTest {
+
+ @Test
+ public void testRegisterResourceMapping() {
+
+ ResourceSourceMappingFactory.INSTANCE.registerSourceMapping("db", "source-db");
+ ResourceSourceMappingFactory.INSTANCE.registerSourceMapping("input", "source-input");
+ ResourceSourceMappingFactory.INSTANCE.registerSourceMapping("default", "source-default");
+ ResourceSourceMappingFactory.INSTANCE.registerSourceMapping("mdsal", "source-rest");
+
+ String nodeTypeName = ResourceSourceMappingFactory.INSTANCE.getRegisterSourceMapping("db");
+ Assert.notNull(nodeTypeName, "Failed to get db mapping");
+
+ ResourceSourceMapping resourceSourceMapping = ResourceSourceMappingFactory.INSTANCE.getRegisterSourceMapping();
+ Assert.notNull(resourceSourceMapping, "Failed to get resource source mapping");
+ Assert.notNull(resourceSourceMapping.getResourceSourceMappings(), "Failed to get resource source mappings");
+
+ }
+
+}
diff --git a/components/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceAssignmentEnhancerServiceTest.java b/components/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceAssignmentEnhancerServiceTest.java
deleted file mode 100644
index 57c8509d1..000000000
--- a/components/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceAssignmentEnhancerServiceTest.java
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- * Copyright © 2017-2018 AT&T Intellectual Property.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.onap.ccsdk.apps.controllerblueprints.resource.dict.service;
-
-import org.junit.Assert;
-import org.junit.Test;
-import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException;
-import org.onap.ccsdk.apps.controllerblueprints.core.data.ServiceTemplate;
-import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonReactorUtils;
-import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignment;
-
-import java.util.List;
-
-/**
- * ResourceAssignmentEnhancerService.
- *
- * @author Brinda Santh
- */
-public class ResourceAssignmentEnhancerServiceTest {
-
- @Test
- public void testEnhanceBluePrint() throws BluePrintException {
-
- List<ResourceAssignment> resourceAssignments = JacksonReactorUtils
- .getListFromClassPathFile("enrich/simple-enrich.json", ResourceAssignment.class).block();
- Assert.assertNotNull("Failed to get Resource Assignment", resourceAssignments);
- ResourceDefinitionRepoService resourceDefinitionRepoService = new ResourceDefinitionFileRepoService("load");
- ResourceAssignmentEnhancerService resourceAssignmentEnhancerService =
- new ResourceAssignmentEnhancerDefaultService(resourceDefinitionRepoService);
- ServiceTemplate serviceTemplate = resourceAssignmentEnhancerService.enhanceBluePrint(resourceAssignments);
- Assert.assertNotNull("Failed to get Enriched service Template", serviceTemplate);
- }
-}
-
diff --git a/components/resource-dict/src/test/resources/enrich/simple-enrich.json b/components/resource-dict/src/test/resources/enrich/simple-enrich.json
deleted file mode 100644
index 641da80a2..000000000
--- a/components/resource-dict/src/test/resources/enrich/simple-enrich.json
+++ /dev/null
@@ -1,37 +0,0 @@
-[
- {
- "name": "rs-db-source",
- "input-param": true,
- "property": {
- "type": "string",
- "required": true
- },
- "dictionary-name": "db-source",
- "dictionary-source": "db",
- "dependencies": [
- "input-source"
- ]
- },
- {
- "name": "ra-default-source",
- "input-param": true,
- "property": {
- "type": "string",
- "required": true
- },
- "dictionary-name": "default-source",
- "dictionary-source": "default",
- "dependencies": []
- },
- {
- "name": "ra-input-source",
- "input-param": true,
- "property": {
- "type": "string",
- "required": true
- },
- "dictionary-name": "input-source",
- "dictionary-source": "input",
- "dependencies": []
- }
-]