summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSingal, Kapil (ks220y) <ks220y@att.com>2018-09-04 21:31:10 -0400
committerSingal, Kapil (ks220y) <ks220y@att.com>2018-09-04 21:35:06 -0400
commit79db143e7f121f28c6b8d44d66d86601ffc95ba4 (patch)
tree73a27c4ad152a25bab82aabf5e6f3ebf58afee0e
parent5256b3654a73d4c7e566c18e728cde153483a9f5 (diff)
SDN Blueprints Processor Input Resource Assignment
Creating SDN Controller Blueprints Input Resource Assignment Processor Change-Id: I64aec06cf09797177598c2348778e1c73dae3b5b Issue-ID: CCSDK-500 Signed-off-by: Singal, Kapil (ks220y) <ks220y@att.com>
-rw-r--r--blueprints-processor/plugin/assignment-provider/src/main/java/org/onap/ccsdk/config/assignment/processor/InputResourceProcessor.java96
-rw-r--r--blueprints-processor/plugin/assignment-provider/src/test/java/org/onap/ccsdk/config/assignment/processor/InputResourceProcessorTest.java178
-rw-r--r--blueprints-processor/plugin/assignment-provider/src/test/resources/mapping/input/dt-location.json15
-rw-r--r--blueprints-processor/plugin/assignment-provider/src/test/resources/mapping/input/input-complex.json24
-rw-r--r--blueprints-processor/plugin/assignment-provider/src/test/resources/mapping/input/input-simple.json35
-rw-r--r--blueprints-processor/plugin/assignment-provider/src/test/resources/mapping/input/resource-assignments-complex.json13
-rw-r--r--blueprints-processor/plugin/assignment-provider/src/test/resources/mapping/input/resource-assignments-simple.json32
-rw-r--r--blueprints-processor/plugin/assignment-provider/src/test/resources/mapping/input/sample-location.json4
8 files changed, 397 insertions, 0 deletions
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
new file mode 100644
index 000000000..e32e7af51
--- /dev/null
+++ b/blueprints-processor/plugin/assignment-provider/src/main/java/org/onap/ccsdk/config/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.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<String, String> inParams, SvcLogicContext ctx, Map<String, Object> componentContext)
+ throws SvcLogicException {
+ return Boolean.TRUE;
+ }
+
+ @Override
+ public void preProcess(Map<String, String> inParams, SvcLogicContext ctx, Map<String, Object> componentContext)
+ throws SvcLogicException {
+ // Auto-generated method stub
+ }
+
+ @Override
+ public void process(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
+ // Auto-generated method stub
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public void process(Map<String, String> inParams, SvcLogicContext ctx, Map<String, Object> componentContext)
+ throws SvcLogicException {
+ try {
+ List<ResourceAssignment> batchResourceAssignment =
+ (List<ResourceAssignment>) 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<String, Object> 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<String, String> inParams, SvcLogicContext ctx, Map<String, Object> componentContext)
+ throws SvcLogicException {
+ // Auto-generated method stub
+ }
+
+}
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
new file mode 100644
index 000000000..2aabdb3d9
--- /dev/null
+++ b/blueprints-processor/plugin/assignment-provider/src/test/java/org/onap/ccsdk/config/assignment/processor/InputResourceProcessorTest.java
@@ -0,0 +1,178 @@
+/*
+ * 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<Void>() {
+ @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<ResourceAssignment> batchResourceAssignment =
+ TransformationUtils.getListfromJson(resourceassignmentContent, ResourceAssignment.class);
+
+ String dictionaryContent = FileUtils.readFileToString(
+ new File("src/test/resources/mapping/default/default-simple.json"), Charset.defaultCharset());
+ Map<String, ResourceDefinition> dictionaries =
+ ConfigResourceAssignmentTestUtils.getMapfromJson(dictionaryContent);
+
+ InputResourceProcessor inputResourceProcessor = new InputResourceProcessor(configResourceService);
+ Map<String, Object> 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<String, String> 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<ResourceAssignment> batchResourceAssignment =
+ TransformationUtils.getListfromJson(resourceassignmentContent, ResourceAssignment.class);
+
+ String dictionaryContent = FileUtils.readFileToString(
+ new File("src/test/resources/mapping/input/input-complex.json"), Charset.defaultCharset());
+ Map<String, ResourceDefinition> dictionaries =
+ ConfigResourceAssignmentTestUtils.getMapfromJson(dictionaryContent);
+
+ InputResourceProcessor inputResourceProcessor = new InputResourceProcessor(configResourceService);
+ Map<String, Object> 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<String, String> 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/resources/mapping/input/dt-location.json b/blueprints-processor/plugin/assignment-provider/src/test/resources/mapping/input/dt-location.json
new file mode 100644
index 000000000..52e0a7967
--- /dev/null
+++ b/blueprints-processor/plugin/assignment-provider/src/test/resources/mapping/input/dt-location.json
@@ -0,0 +1,15 @@
+{
+ "version": "1.0.0",
+ "description": "test Data Type",
+ "properties": {
+ "country": {
+ "required": true,
+ "type": "string"
+ },
+ "state": {
+ "required": false,
+ "type": "string"
+ }
+ },
+ "derived_from": "tosca.datatypes.Root"
+}
diff --git a/blueprints-processor/plugin/assignment-provider/src/test/resources/mapping/input/input-complex.json b/blueprints-processor/plugin/assignment-provider/src/test/resources/mapping/input/input-complex.json
new file mode 100644
index 000000000..7eabe440a
--- /dev/null
+++ b/blueprints-processor/plugin/assignment-provider/src/test/resources/mapping/input/input-complex.json
@@ -0,0 +1,24 @@
+{
+ "location": {
+ "name": "location",
+ "property": {
+ "type": "dt-location"
+ },
+ "sources": {
+ "default": {
+ "type": "source-input"
+ }
+ }
+ },
+ "profile_name": {
+ "name": "profile_name",
+ "property": {
+ "type": "string"
+ },
+ "sources": {
+ "default": {
+ "type": "source-input"
+ }
+ }
+ }
+}
diff --git a/blueprints-processor/plugin/assignment-provider/src/test/resources/mapping/input/input-simple.json b/blueprints-processor/plugin/assignment-provider/src/test/resources/mapping/input/input-simple.json
new file mode 100644
index 000000000..7b663f36a
--- /dev/null
+++ b/blueprints-processor/plugin/assignment-provider/src/test/resources/mapping/input/input-simple.json
@@ -0,0 +1,35 @@
+{
+ "country": {
+ "name": "country",
+ "property": {
+ "type": "string"
+ },
+ "sources": {
+ "default": {
+ "type": "source-input"
+ }
+ }
+ },
+ "port": {
+ "name": "port",
+ "property": {
+ "type": "integer"
+ },
+ "sources": {
+ "default": {
+ "type": "source-input"
+ }
+ }
+ },
+ "voip-enabled": {
+ "name": "voip-enabled",
+ "property": {
+ "type": "boolean"
+ },
+ "sources": {
+ "default": {
+ "type": "source-input"
+ }
+ }
+ }
+}
diff --git a/blueprints-processor/plugin/assignment-provider/src/test/resources/mapping/input/resource-assignments-complex.json b/blueprints-processor/plugin/assignment-provider/src/test/resources/mapping/input/resource-assignments-complex.json
new file mode 100644
index 000000000..9e17841b4
--- /dev/null
+++ b/blueprints-processor/plugin/assignment-provider/src/test/resources/mapping/input/resource-assignments-complex.json
@@ -0,0 +1,13 @@
+[
+ {
+ "name": "location",
+ "input-param": true,
+ "property": {
+ "type": "dt-location",
+ "required": true
+ },
+ "dictionary-name": "location",
+ "dictionary-source": "input",
+ "dependencies": []
+ }
+]
diff --git a/blueprints-processor/plugin/assignment-provider/src/test/resources/mapping/input/resource-assignments-simple.json b/blueprints-processor/plugin/assignment-provider/src/test/resources/mapping/input/resource-assignments-simple.json
new file mode 100644
index 000000000..e3b2bcc06
--- /dev/null
+++ b/blueprints-processor/plugin/assignment-provider/src/test/resources/mapping/input/resource-assignments-simple.json
@@ -0,0 +1,32 @@
+[
+ {
+ "name": "country",
+ "input-param": true,
+ "property": {
+ "type": "string",
+ "default": "US"
+ },
+ "dictionary-source": "input",
+ "dependencies": []
+ },
+ {
+ "name": "port",
+ "input-param": true,
+ "property": {
+ "type": "integer",
+ "default": 830
+ },
+ "dictionary-source": "input",
+ "dependencies": []
+ },
+ {
+ "name": "voip-enabled",
+ "input-param": true,
+ "property": {
+ "type": "boolean",
+ "default": true
+ },
+ "dictionary-source": "input",
+ "dependencies": []
+ }
+]
diff --git a/blueprints-processor/plugin/assignment-provider/src/test/resources/mapping/input/sample-location.json b/blueprints-processor/plugin/assignment-provider/src/test/resources/mapping/input/sample-location.json
new file mode 100644
index 000000000..2f3f1c102
--- /dev/null
+++ b/blueprints-processor/plugin/assignment-provider/src/test/resources/mapping/input/sample-location.json
@@ -0,0 +1,4 @@
+{
+ "country": "US",
+ "state": "NJ"
+}