aboutsummaryrefslogtreecommitdiffstats
path: root/ms/controllerblueprints/modules/service/src
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
commit30bdb24f421db1d3703cfea707a8a6865adedb88 (patch)
treebeefaeee3b2c9ef6781e67650e79bd654b609315 /ms/controllerblueprints/modules/service/src
parentea77168400c599644309dc1734c7293037f7c465 (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>
Diffstat (limited to 'ms/controllerblueprints/modules/service/src')
-rw-r--r--ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ApplicationRegistrationService.java26
-rw-r--r--ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ResourceDictionaryService.java13
-rw-r--r--ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ResourceDictionaryRest.java7
-rw-r--r--ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/ResourceAssignmentEnhancerService.kt88
-rw-r--r--ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/ResourceAssignmentEnhancerServiceTest.java50
-rw-r--r--ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ResourceDictionaryRestTest.java8
-rw-r--r--ms/controllerblueprints/modules/service/src/test/resources/application.properties5
-rw-r--r--ms/controllerblueprints/modules/service/src/test/resources/enhance/simple-enrich.json37
8 files changed, 228 insertions, 6 deletions
diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ApplicationRegistrationService.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ApplicationRegistrationService.java
index 5a4a2877e..fc7410f96 100644
--- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ApplicationRegistrationService.java
+++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ApplicationRegistrationService.java
@@ -17,20 +17,40 @@
package org.onap.ccsdk.apps.controllerblueprints.service;
+import com.att.eelf.configuration.EELFLogger;
+import com.att.eelf.configuration.EELFManager;
+import org.apache.commons.collections.CollectionUtils;
+import org.onap.ccsdk.apps.controllerblueprints.resource.dict.factory.ResourceSourceMappingFactory;
+import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import javax.annotation.PostConstruct;
+import java.util.List;
@Component
@SuppressWarnings("unused")
public class ApplicationRegistrationService {
+ private static EELFLogger log = EELFManager.getInstance().getLogger(ApplicationRegistrationService.class);
+
+ @Value("#{'${resourceSourceMappings}'.split(',')}")
+ private List<String> resourceSourceMappings;
@PostConstruct
- public void register(){
+ public void register() {
registerDictionarySources();
}
- public void registerDictionarySources(){
-
+ public void registerDictionarySources() {
+ log.info("Registering Dictionary Sources : {}", resourceSourceMappings);
+ if (CollectionUtils.isNotEmpty(resourceSourceMappings)) {
+ resourceSourceMappings.forEach(resourceSourceMapping -> {
+ String[] mappingKeyValue = resourceSourceMapping.split("=");
+ if (mappingKeyValue != null && mappingKeyValue.length == 2) {
+ ResourceSourceMappingFactory.INSTANCE.registerSourceMapping(mappingKeyValue[0].trim(), mappingKeyValue[1].trim());
+ } else {
+ log.warn("failed to get resource source mapping {}", resourceSourceMapping);
+ }
+ });
+ }
}
}
diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ResourceDictionaryService.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ResourceDictionaryService.java
index 62aa0e29c..fd73db3b6 100644
--- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ResourceDictionaryService.java
+++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ResourceDictionaryService.java
@@ -22,8 +22,9 @@ import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException;
import org.onap.ccsdk.apps.controllerblueprints.core.data.PropertyDefinition;
-import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils;
import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceDefinition;
+import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceSourceMapping;
+import org.onap.ccsdk.apps.controllerblueprints.resource.dict.factory.ResourceSourceMappingFactory;
import org.onap.ccsdk.apps.controllerblueprints.service.domain.ResourceDictionary;
import org.onap.ccsdk.apps.controllerblueprints.service.repository.ResourceDictionaryRepository;
import org.onap.ccsdk.apps.controllerblueprints.service.validator.ResourceDictionaryValidator;
@@ -105,7 +106,7 @@ public class ResourceDictionaryService {
*/
public ResourceDictionary saveResourceDictionary(ResourceDictionary resourceDictionary) {
Preconditions.checkNotNull(resourceDictionary, "Resource Dictionary information is missing");
- Preconditions.checkNotNull(resourceDictionary.getDefinition(),"Resource Dictionary definition information is missing");
+ Preconditions.checkNotNull(resourceDictionary.getDefinition(), "Resource Dictionary definition information is missing");
ResourceDefinition resourceDefinition = resourceDictionary.getDefinition();
Preconditions.checkNotNull(resourceDefinition, "failed to get resource definition from content");
@@ -153,4 +154,12 @@ public class ResourceDictionaryService {
Preconditions.checkArgument(StringUtils.isNotBlank(name), "Resource dictionary Name Information is missing.");
resourceDictionaryRepository.deleteByName(name);
}
+
+ /**
+ * This is a getResourceSourceMapping service
+ *
+ */
+ public ResourceSourceMapping getResourceSourceMapping() {
+ return ResourceSourceMappingFactory.INSTANCE.getRegisterSourceMapping();
+ }
}
diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ResourceDictionaryRest.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ResourceDictionaryRest.java
index e0cf6c69b..287d413cc 100644
--- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ResourceDictionaryRest.java
+++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ResourceDictionaryRest.java
@@ -18,6 +18,7 @@
package org.onap.ccsdk.apps.controllerblueprints.service.rs;
import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException;
+import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceSourceMapping;
import org.onap.ccsdk.apps.controllerblueprints.service.ResourceDictionaryService;
import org.onap.ccsdk.apps.controllerblueprints.service.domain.ResourceDictionary;
import org.springframework.http.MediaType;
@@ -76,4 +77,10 @@ public class ResourceDictionaryRest {
}
+ @GetMapping(path = "/source-mapping", produces = MediaType.APPLICATION_JSON_VALUE)
+ public @ResponseBody
+ ResourceSourceMapping getResourceSourceMapping() {
+ return resourceDictionaryService.getResourceSourceMapping();
+ }
+
}
diff --git a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/ResourceAssignmentEnhancerService.kt b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/ResourceAssignmentEnhancerService.kt
new file mode 100644
index 000000000..0d08985a1
--- /dev/null
+++ b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/ResourceAssignmentEnhancerService.kt
@@ -0,0 +1,88 @@
+/*
+ * 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.service.enhancer
+
+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
+import org.onap.ccsdk.apps.controllerblueprints.resource.dict.service.ResourceAssignmentValidationDefaultService
+import org.onap.ccsdk.apps.controllerblueprints.resource.dict.service.ResourceDefinitionRepoService
+
+/**
+ * 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/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/ResourceAssignmentEnhancerServiceTest.java b/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/ResourceAssignmentEnhancerServiceTest.java
new file mode 100644
index 000000000..7d16f50fa
--- /dev/null
+++ b/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/ResourceAssignmentEnhancerServiceTest.java
@@ -0,0 +1,50 @@
+/*
+ * 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.service.enhancer;
+
+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 org.onap.ccsdk.apps.controllerblueprints.resource.dict.service.ResourceDefinitionFileRepoService;
+import org.onap.ccsdk.apps.controllerblueprints.resource.dict.service.ResourceDefinitionRepoService;
+
+import java.util.List;
+
+/**
+ * ResourceAssignmentEnhancerService.
+ *
+ * @author Brinda Santh
+ */
+public class ResourceAssignmentEnhancerServiceTest {
+
+ @Test
+ public void testEnhanceBluePrint() throws BluePrintException {
+
+ List<ResourceAssignment> resourceAssignments = JacksonReactorUtils
+ .getListFromClassPathFile("enhance/simple-enrich.json", ResourceAssignment.class).block();
+ Assert.assertNotNull("Failed to get Resource Assignment", resourceAssignments);
+ ResourceDefinitionRepoService resourceDefinitionRepoService = new ResourceDefinitionFileRepoService("./../../application/load");
+ ResourceAssignmentEnhancerService resourceAssignmentEnhancerService =
+ new ResourceAssignmentEnhancerDefaultService(resourceDefinitionRepoService);
+ ServiceTemplate serviceTemplate = resourceAssignmentEnhancerService.enhanceBluePrint(resourceAssignments);
+ Assert.assertNotNull("Failed to get Enriched service Template", serviceTemplate);
+ }
+}
+
diff --git a/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ResourceDictionaryRestTest.java b/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ResourceDictionaryRestTest.java
index 5955ae191..ac786d0e9 100644
--- a/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ResourceDictionaryRestTest.java
+++ b/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ResourceDictionaryRestTest.java
@@ -26,6 +26,7 @@ import org.junit.runners.MethodSorters;
import org.onap.ccsdk.apps.controllerblueprints.TestApplication;
import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils;
import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceDefinition;
+import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceSourceMapping;
import org.onap.ccsdk.apps.controllerblueprints.service.domain.ResourceDictionary;
import com.att.eelf.configuration.EELFLogger;
import com.att.eelf.configuration.EELFManager;
@@ -103,4 +104,11 @@ public class ResourceDictionaryRestTest {
}
+ @Test
+ public void test03GetResourceSourceMapping() {
+ ResourceSourceMapping resourceSourceMapping = resourceDictionaryRest.getResourceSourceMapping();
+ org.springframework.util.Assert.notNull(resourceSourceMapping, "Failed to get resource source mapping");
+ org.springframework.util.Assert.notNull(resourceSourceMapping.getResourceSourceMappings(), "Failed to get resource source mappings");
+ }
+
}
diff --git a/ms/controllerblueprints/modules/service/src/test/resources/application.properties b/ms/controllerblueprints/modules/service/src/test/resources/application.properties
index 429588b31..3a913b701 100644
--- a/ms/controllerblueprints/modules/service/src/test/resources/application.properties
+++ b/ms/controllerblueprints/modules/service/src/test/resources/application.properties
@@ -28,4 +28,7 @@ load.dataTypePath=./../../application/load/model_type/data_type
load.nodeTypePath=./../../application/load/model_type/node_type
load.artifactTypePath=./../../application/load/model_type/artifact_type
load.resourceDictionaryPath=./../../application/load/resource_dictionary
-load.blueprintsPath=./../../application/load/blueprints \ No newline at end of file
+load.blueprintsPath=./../../application/load/blueprints
+
+# Load Resource Source Mappings
+resourceSourceMappings=db=source-db,input=source-input,default=source-default,mdsal=source-rest \ No newline at end of file
diff --git a/ms/controllerblueprints/modules/service/src/test/resources/enhance/simple-enrich.json b/ms/controllerblueprints/modules/service/src/test/resources/enhance/simple-enrich.json
new file mode 100644
index 000000000..641da80a2
--- /dev/null
+++ b/ms/controllerblueprints/modules/service/src/test/resources/enhance/simple-enrich.json
@@ -0,0 +1,37 @@
+[
+ {
+ "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": []
+ }
+]