--- /dev/null
+/*\r
+ * Copyright © 2017-2018 AT&T Intellectual Property.\r
+ * Modifications Copyright © 2018 IBM.\r
+ * \r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ * \r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ * \r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+\r
+package org.onap.ccsdk.config.assignment.processor;\r
+\r
+import java.util.HashMap;\r
+import java.util.List;\r
+import java.util.Map;\r
+import org.apache.commons.collections.CollectionUtils;\r
+import org.apache.commons.collections.MapUtils;\r
+import org.apache.commons.lang3.StringUtils;\r
+import org.onap.ccsdk.config.assignment.service.ConfigAssignmentUtils;\r
+import org.onap.ccsdk.config.model.ConfigModelConstant;\r
+import org.onap.ccsdk.config.model.ConfigModelException;\r
+import org.onap.ccsdk.config.model.data.ResourceAssignment;\r
+import org.onap.ccsdk.config.model.data.dict.ResourceDefinition;\r
+import org.onap.ccsdk.config.model.data.dict.SourcesDefinition;\r
+import org.onap.ccsdk.config.model.service.ComponentNode;\r
+import org.onap.ccsdk.config.model.utils.ResourceAssignmentUtils;\r
+import org.onap.ccsdk.config.model.utils.TransformationUtils;\r
+import org.onap.ccsdk.config.rest.adaptor.ConfigRestAdaptorConstants;\r
+import org.onap.ccsdk.config.rest.adaptor.service.ConfigRestAdaptorService;\r
+import org.onap.ccsdk.sli.core.sli.SvcLogicContext;\r
+import org.onap.ccsdk.sli.core.sli.SvcLogicException;\r
+import com.att.eelf.configuration.EELFLogger;\r
+import com.att.eelf.configuration.EELFManager;\r
+import com.fasterxml.jackson.databind.JsonNode;\r
+\r
+public class MdsalResourceProcessor implements ComponentNode {\r
+\r
+ private static EELFLogger logger = EELFManager.getInstance().getLogger(MdsalResourceProcessor.class);\r
+ private ConfigRestAdaptorService configRestAdaptorService;\r
+ private Map<String, ResourceDefinition> dictionaries;\r
+\r
+ public MdsalResourceProcessor(ConfigRestAdaptorService configRestAdaptorService) {\r
+ this.configRestAdaptorService = configRestAdaptorService;\r
+ }\r
+\r
+ @Override\r
+ public Boolean preCondition(Map<String, String> inParams, SvcLogicContext ctx, Map<String, Object> componentContext)\r
+ throws SvcLogicException {\r
+ return Boolean.TRUE;\r
+ }\r
+\r
+ @Override\r
+ public void preProcess(Map<String, String> inParams, SvcLogicContext ctx, Map<String, Object> componentContext)\r
+ throws SvcLogicException {\r
+ // Auto-generated method stub\r
+ }\r
+\r
+ @Override\r
+ public void process(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {\r
+ // Auto-generated method stub\r
+ }\r
+\r
+ @SuppressWarnings("unchecked")\r
+ @Override\r
+ public void process(Map<String, String> inParams, SvcLogicContext ctx, Map<String, Object> componentContext)\r
+ throws SvcLogicException {\r
+ try {\r
+ List<ResourceAssignment> batchResourceAssignment =\r
+ (List<ResourceAssignment>) componentContext.get(ConfigModelConstant.PROPERTY_RESOURCE_ASSIGNMENTS);\r
+ dictionaries =\r
+ (Map<String, ResourceDefinition>) componentContext.get(ConfigModelConstant.PROPERTY_DICTIONARIES);\r
+\r
+ if (CollectionUtils.isNotEmpty(batchResourceAssignment)) {\r
+ for (ResourceAssignment resourceAssignment : batchResourceAssignment) {\r
+ processResourceAssignmnet(ctx, componentContext, resourceAssignment);\r
+ }\r
+ }\r
+ } catch (Exception e) {\r
+ throw new SvcLogicException(String.format("MdsalResourceProcessor Exception : (%s) ", e), e);\r
+ }\r
+ }\r
+\r
+ private void processResourceAssignmnet(SvcLogicContext ctx, Map<String, Object> componentContext,\r
+ ResourceAssignment resourceAssignment) throws ConfigModelException, SvcLogicException {\r
+\r
+ try {\r
+ // Validating Resource Assignment and Dictionary Definition data\r
+ validate(resourceAssignment);\r
+\r
+ // Check if It has Input\r
+ Object value = ConfigAssignmentUtils.getContextKeyValue(ctx, resourceAssignment.getName());\r
+ if (value != null) {\r
+ logger.info("mdsal source template key ({}) found from input and value is ({})",\r
+ resourceAssignment.getName(), value);\r
+ ResourceAssignmentUtils.setResourceDataValue(componentContext, resourceAssignment, value);\r
+ return;\r
+ }\r
+\r
+ ResourceDefinition resourceDefinition = dictionaries.get(resourceAssignment.getDictionaryName());\r
+ SourcesDefinition sourceMdsal = resourceDefinition.getSources().get("mdsal");\r
+ String urlPath = sourceMdsal.getProperties().getUrlPath();\r
+ String path = sourceMdsal.getProperties().getPath();\r
+ Map<String, String> inputKeyMapping = sourceMdsal.getProperties().getInputKeyMapping();\r
+ Map<String, String> outputKeyMapping = sourceMdsal.getProperties().getOutputKeyMapping();\r
+\r
+ logger.info(\r
+ "mdsal dictionary information : urlpath ({}), path({}), inputKeyMapping ({}), outputKeyMapping ({})",\r
+ urlPath, path, inputKeyMapping, outputKeyMapping);\r
+\r
+ // Resolving url Variables\r
+ Map<String, Object> urlVariables = populateUrlVariables(inputKeyMapping, componentContext);\r
+ for (Map.Entry<String, Object> entry : urlVariables.entrySet()) {\r
+ urlPath = urlPath.replaceAll("\\$" + entry.getKey(), entry.getValue().toString());\r
+ }\r
+\r
+ String restResponse = fetchResourceFromMDSAL(urlPath);\r
+ // if restResponse is null don't call processMdsalResults to populate the value\r
+ if (StringUtils.isNotBlank(restResponse)) {\r
+ // Processing MDSAL Response\r
+ processMdsalResults(ctx, componentContext, resourceAssignment, sourceMdsal, restResponse);\r
+ } else {\r
+ logger.warn("Coudn't get proper mdsal Response content ({}) for Resource Name ({}) for URI ({})",\r
+ restResponse, resourceAssignment.getDictionaryName(), urlPath);\r
+ }\r
+\r
+ // Check the value has populated for mandatory case\r
+ ResourceAssignmentUtils.assertTemplateKeyValueNotNull(componentContext, resourceAssignment);\r
+ } catch (Exception e) {\r
+ ResourceAssignmentUtils.setFailedResourceDataValue(componentContext, resourceAssignment, e.getMessage());\r
+ throw new SvcLogicException(\r
+ String.format("Failed in assignments for (%s) with (%s)", resourceAssignment, e), e);\r
+ }\r
+ }\r
+\r
+ private String fetchResourceFromMDSAL(String urlPath) {\r
+ String response = null;\r
+ try {\r
+ response = configRestAdaptorService.getResource(ConfigRestAdaptorConstants.SELECTOR_RESTCONF, urlPath,\r
+ String.class);\r
+ } catch (Exception e) {\r
+ logger.warn("Fetching MDSAL data for URL ({}) failed with Error ({})", urlPath, e);\r
+ }\r
+ return response;\r
+ }\r
+\r
+ private void validate(ResourceAssignment resourceAssignment) throws SvcLogicException {\r
+ if (resourceAssignment == null) {\r
+ throw new SvcLogicException("resource assignment is not defined");\r
+ }\r
+\r
+ if (StringUtils.isBlank(resourceAssignment.getName())) {\r
+ throw new SvcLogicException("resource assignment template key is not defined");\r
+ }\r
+\r
+ if (StringUtils.isBlank(resourceAssignment.getDictionaryName())) {\r
+ throw new SvcLogicException(\r
+ String.format("resource assignment dictionary name is not defined for template key (%s)",\r
+ resourceAssignment.getName()));\r
+ }\r
+\r
+ if (!ConfigModelConstant.SOURCE_MDSAL.equalsIgnoreCase(resourceAssignment.getDictionarySource())) {\r
+ throw new SvcLogicException(String.format("resource assignment source is not mdsal, it is (%s)",\r
+ resourceAssignment.getDictionarySource()));\r
+ }\r
+\r
+ ResourceDefinition resourceDefinition = dictionaries.get(resourceAssignment.getDictionaryName());\r
+ if (resourceDefinition == null) {\r
+ throw new SvcLogicException(String.format("missing resource dictionary definition for name (%s) ",\r
+ resourceAssignment.getDictionaryName()));\r
+ }\r
+\r
+ if (StringUtils.isBlank(resourceDefinition.getProperty().getType())) {\r
+ throw new SvcLogicException(String.format(String.format("Failed to get dictionary (%s) data type info.",\r
+ resourceAssignment.getDictionaryName())));\r
+ }\r
+\r
+ if (resourceDefinition.getSources() == null || resourceDefinition.getSources().get("mdsal") == null) {\r
+ throw new SvcLogicException(\r
+ String.format("missing resource dictionary mdsal source definition for name (%s) ",\r
+ resourceAssignment.getDictionaryName()));\r
+ }\r
+\r
+ SourcesDefinition sourceMdsal = resourceDefinition.getSources().get("mdsal");\r
+ if (StringUtils.isBlank(sourceMdsal.getProperties().getUrlPath())) {\r
+ throw new SvcLogicException(String.format("Failed to get request URL Path for dictionary (%s)",\r
+ resourceAssignment.getDictionaryName()));\r
+ }\r
+\r
+ if (StringUtils.isBlank(sourceMdsal.getProperties().getPath())) {\r
+ throw new SvcLogicException(String.format("Failed to get request Path for dictionary (%s)",\r
+ resourceAssignment.getDictionaryName()));\r
+ }\r
+ }\r
+\r
+ private Map<String, Object> populateUrlVariables(Map<String, String> inputKeyMapping,\r
+ Map<String, Object> componentContext) {\r
+ Map<String, Object> urlVariables = new HashMap<>();\r
+ if (MapUtils.isNotEmpty(inputKeyMapping)) {\r
+\r
+ for (Map.Entry<String, String> mapping : inputKeyMapping.entrySet()) {\r
+ ResourceDefinition referenceDictionaryDefinition = dictionaries.get(mapping.getValue());\r
+ Object expressionValue =\r
+ ResourceAssignmentUtils.getDictionaryKeyValue(componentContext, referenceDictionaryDefinition);\r
+ logger.trace("Reference dictionary key ({}), value ({})", mapping.getKey(), expressionValue);\r
+ urlVariables.put(mapping.getKey(), expressionValue);\r
+ }\r
+ }\r
+ return urlVariables;\r
+ }\r
+\r
+ private void processMdsalResults(SvcLogicContext ctx, Map<String, Object> componentContext,\r
+ ResourceAssignment resourceAssignment, SourcesDefinition sourceMdsal, String restResponse)\r
+ throws SvcLogicException, ConfigModelException {\r
+\r
+ Map<String, String> outputKeyMapping = sourceMdsal.getProperties().getOutputKeyMapping();\r
+ JsonNode responseNode = TransformationUtils.getJsonNodeForString(restResponse);\r
+ if (StringUtils.isNotBlank(sourceMdsal.getProperties().getPath())) {\r
+ responseNode = responseNode.at(sourceMdsal.getProperties().getPath());\r
+ }\r
+ if (responseNode != null) {\r
+ ConfigAssignmentUtils.populateValueForOutputMapping(ctx, componentContext, resourceAssignment,\r
+ outputKeyMapping, responseNode);\r
+ }\r
+ }\r
+\r
+ @Override\r
+ public void postProcess(Map<String, String> inParams, SvcLogicContext ctx, Map<String, Object> componentContext)\r
+ throws SvcLogicException {\r
+ // Do Nothing\r
+ }\r
+\r
+}\r
--- /dev/null
+/*\r
+ * Copyright © 2017-2018 AT&T Intellectual Property.\r
+ * Modifications Copyright © 2018 IBM.\r
+ * \r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ * \r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ * \r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+\r
+package org.onap.ccsdk.config.assignment.processor;\r
+\r
+import java.io.File;\r
+import java.nio.charset.Charset;\r
+import java.util.HashMap;\r
+import java.util.List;\r
+import java.util.Map;\r
+import org.apache.commons.io.FileUtils;\r
+import org.junit.Assert;\r
+import org.junit.Before;\r
+import org.junit.Test;\r
+import org.junit.runner.RunWith;\r
+import org.mockito.Matchers;\r
+import org.mockito.Mock;\r
+import org.mockito.Mockito;\r
+import org.mockito.invocation.InvocationOnMock;\r
+import org.mockito.runners.MockitoJUnitRunner;\r
+import org.mockito.stubbing.Answer;\r
+import org.onap.ccsdk.config.assignment.service.ConfigResourceAssignmentTestUtils;\r
+import org.onap.ccsdk.config.model.ConfigModelConstant;\r
+import org.onap.ccsdk.config.model.data.ResourceAssignment;\r
+import org.onap.ccsdk.config.model.data.dict.ResourceDefinition;\r
+import org.onap.ccsdk.config.model.utils.TransformationUtils;\r
+import org.onap.ccsdk.config.rest.adaptor.service.ConfigRestAdaptorService;\r
+import org.onap.ccsdk.sli.core.sli.SvcLogicContext;\r
+import com.att.eelf.configuration.EELFLogger;\r
+import com.att.eelf.configuration.EELFManager;\r
+\r
+@RunWith(MockitoJUnitRunner.class)\r
+public class MdsalResourceProcessorTest {\r
+\r
+ private static EELFLogger logger = EELFManager.getInstance().getLogger(MdsalResourceProcessorTest.class);\r
+\r
+ @Mock\r
+ private ConfigRestAdaptorService configRestAdaptorService;\r
+\r
+ @SuppressWarnings("unchecked")\r
+ @Before\r
+ public void before() {\r
+\r
+ }\r
+\r
+ @Test\r
+ @SuppressWarnings("unchecked")\r
+ public void testMdsalSimpleProcess() throws Exception {\r
+ logger.info(" ******************************* testMdsalSimpleProcess ***************************");\r
+\r
+ Mockito.doAnswer(new Answer<String>() {\r
+ @Override\r
+ public String answer(InvocationOnMock invocationOnMock) throws Throwable {\r
+ Object[] args = invocationOnMock.getArguments();\r
+ String response = null;\r
+ if (args != null) {\r
+ response = FileUtils.readFileToString(\r
+ new File("src/test/resources/mapping/Mdsal/simple-response.json"),\r
+ Charset.defaultCharset());\r
+ logger.info(" Returning response :" + response);\r
+ }\r
+ return response;\r
+ }\r
+ }).when(configRestAdaptorService).getResource(Matchers.anyString(), Matchers.anyString(),\r
+ Matchers.any(Class.class));\r
+\r
+ String recipeName = "sample-recipe";\r
+\r
+ String resourceassignmentContent = FileUtils.readFileToString(\r
+ new File("src/test/resources/mapping/Mdsal/resource-assignments-simple.json"),\r
+ Charset.defaultCharset());\r
+ List<ResourceAssignment> batchResourceAssignment =\r
+ TransformationUtils.getListfromJson(resourceassignmentContent, ResourceAssignment.class);\r
+\r
+ String dictionaryContent = FileUtils.readFileToString(\r
+ new File("src/test/resources/mapping/Mdsal/mdsal-simple.json"), Charset.defaultCharset());\r
+ Map<String, ResourceDefinition> dictionaries =\r
+ ConfigResourceAssignmentTestUtils.getMapfromJson(dictionaryContent);\r
+ MdsalResourceProcessor mdsalResourceProcessor = new MdsalResourceProcessor(configRestAdaptorService);\r
+ Map<String, Object> componentContext = new HashMap<>();\r
+ componentContext.put(ConfigModelConstant.PROPERTY_RESOURCE_ASSIGNMENTS, batchResourceAssignment);\r
+ componentContext.put(ConfigModelConstant.PROPERTY_ACTION_NAME, recipeName);\r
+ componentContext.put(ConfigModelConstant.PROPERTY_TEMPLATE_NAME, "sample-template");\r
+ componentContext.put(ConfigModelConstant.PROPERTY_DICTIONARIES, dictionaries);\r
+\r
+ componentContext.put(ConfigModelConstant.PROPERTY_DICTIONARY_KEY_DOT + recipeName + ".profile_name", "sample");\r
+\r
+ Map<String, String> inParams = new HashMap<>();\r
+ SvcLogicContext ctx = new SvcLogicContext();\r
+ mdsalResourceProcessor.process(inParams, ctx, componentContext);\r
+\r
+ }\r
+\r
+ @SuppressWarnings("unchecked")\r
+ @Test\r
+ public void testMDSALComplexProcess() throws Exception {\r
+ logger.info(" ******************************* testMDSALComplexProcess ***************************");\r
+\r
+ Mockito.doAnswer(new Answer<String>() {\r
+ @Override\r
+ public String answer(InvocationOnMock invocationOnMock) throws Throwable {\r
+ Object[] args = invocationOnMock.getArguments();\r
+ String response = null;\r
+ if (args != null) {\r
+ response = FileUtils.readFileToString(\r
+ new File("src/test/resources/mapping/Mdsal/complex-response.json"),\r
+ Charset.defaultCharset());\r
+ }\r
+ return response;\r
+ }\r
+ }).when(configRestAdaptorService).getResource(Matchers.anyString(), Matchers.anyString(),\r
+ Matchers.any(Class.class));\r
+\r
+ String recipeName = "sample-recipe";\r
+\r
+ String resourceassignmentContent = FileUtils.readFileToString(\r
+ new File("src/test/resources/mapping/Mdsal/resource-assignments-complex.json"),\r
+ Charset.defaultCharset());\r
+ List<ResourceAssignment> batchResourceAssignment =\r
+ TransformationUtils.getListfromJson(resourceassignmentContent, ResourceAssignment.class);\r
+\r
+ String dictionaryContent = FileUtils.readFileToString(\r
+ new File("src/test/resources/mapping/Mdsal/mdsal-complex.json"), Charset.defaultCharset());\r
+ Map<String, ResourceDefinition> dictionaries =\r
+ ConfigResourceAssignmentTestUtils.getMapfromJson(dictionaryContent);\r
+ MdsalResourceProcessor dbResourceProcessor = new MdsalResourceProcessor(configRestAdaptorService);\r
+ Map<String, Object> componentContext = new HashMap<>();\r
+ componentContext.put(ConfigModelConstant.PROPERTY_RESOURCE_ASSIGNMENTS, batchResourceAssignment);\r
+ componentContext.put(ConfigModelConstant.PROPERTY_ACTION_NAME, recipeName);\r
+ componentContext.put(ConfigModelConstant.PROPERTY_TEMPLATE_NAME, "sample-template");\r
+ componentContext.put(ConfigModelConstant.PROPERTY_DICTIONARIES, dictionaries);\r
+ componentContext.put(ConfigModelConstant.PROPERTY_DICTIONARY_KEY_DOT + recipeName + ".profile_name", "sample");\r
+\r
+ Map<String, String> inParams = new HashMap<>();\r
+ SvcLogicContext ctx = new SvcLogicContext();\r
+ String datatypeContent = FileUtils.readFileToString(\r
+ new File("src/test/resources/mapping/Mdsal/dt-location.json"), Charset.defaultCharset());\r
+ ctx.setAttribute("data_types.dt-location", datatypeContent);\r
+ dbResourceProcessor.process(inParams, ctx, componentContext);\r
+\r
+ }\r
+\r
+ @Test\r
+ @SuppressWarnings("unchecked")\r
+ public void testMDSALArrayComplexProcess() throws Exception {\r
+ logger.info(" ******************************* testMDSALArrayComplexProcess ***************************");\r
+\r
+ Mockito.doAnswer(new Answer<String>() {\r
+ @Override\r
+ public String answer(InvocationOnMock invocationOnMock) throws Throwable {\r
+ Object[] args = invocationOnMock.getArguments();\r
+ String response = null;\r
+ if (args != null) {\r
+ response = FileUtils.readFileToString(\r
+ new File("src/test/resources/mapping/Mdsal/array-complex-response.json"),\r
+ Charset.defaultCharset());\r
+ }\r
+ return response;\r
+ }\r
+ }).when(configRestAdaptorService).getResource(Matchers.anyString(), Matchers.anyString(),\r
+ Matchers.any(Class.class));\r
+\r
+ String recipeName = "sample-recipe";\r
+\r
+ String resourceassignmentContent = FileUtils.readFileToString(\r
+ new File("src/test/resources/mapping/Mdsal/resource-assignments-array.json"), Charset.defaultCharset());\r
+ List<ResourceAssignment> batchResourceAssignment =\r
+ TransformationUtils.getListfromJson(resourceassignmentContent, ResourceAssignment.class);\r
+\r
+ String dictionaryContent = FileUtils.readFileToString(\r
+ new File("src/test/resources/mapping/Mdsal/mdsal-array.json"), Charset.defaultCharset());\r
+\r
+ Map<String, ResourceDefinition> dictionaries =\r
+ ConfigResourceAssignmentTestUtils.getMapfromJson(dictionaryContent);\r
+ MdsalResourceProcessor dbResourceProcessor = new MdsalResourceProcessor(configRestAdaptorService);\r
+ Map<String, Object> componentContext = new HashMap<>();\r
+ componentContext.put(ConfigModelConstant.PROPERTY_RESOURCE_ASSIGNMENTS, batchResourceAssignment);\r
+ componentContext.put(ConfigModelConstant.PROPERTY_ACTION_NAME, recipeName);\r
+ componentContext.put(ConfigModelConstant.PROPERTY_TEMPLATE_NAME, "sample-template");\r
+ componentContext.put(ConfigModelConstant.PROPERTY_DICTIONARIES, dictionaries);\r
+ componentContext.put(ConfigModelConstant.PROPERTY_DICTIONARY_KEY_DOT + recipeName + ".profile_name", "sample");\r
+\r
+ Map<String, String> inParams = new HashMap<>();\r
+ SvcLogicContext ctx = new SvcLogicContext();\r
+ String datatypeContent = FileUtils.readFileToString(\r
+ new File("src/test/resources/mapping/Mdsal/dt-location.json"), Charset.defaultCharset());\r
+ ctx.setAttribute("data_types.dt-location", datatypeContent);\r
+ dbResourceProcessor.process(inParams, ctx, componentContext);\r
+ logger.info("Component Context = ({})", componentContext);\r
+ Assert.assertNotNull("failed to populate Array Complex response ", componentContext);\r
+\r
+ }\r
+\r
+ @Test\r
+ @SuppressWarnings("unchecked")\r
+ public void testMDSALArraySimpleProcess() throws Exception {\r
+ logger.info(" ******************************* testMDSALArrayComplexProcess ***************************");\r
+\r
+ Mockito.doAnswer(new Answer<String>() {\r
+ @Override\r
+ public String answer(InvocationOnMock invocationOnMock) throws Throwable {\r
+ Object[] args = invocationOnMock.getArguments();\r
+ String response = null;\r
+ if (args != null) {\r
+ response = FileUtils.readFileToString(\r
+ new File("src/test/resources/mapping/Mdsal/array-complex-v4-assigned-response.json"),\r
+ Charset.defaultCharset());\r
+ }\r
+ return response;\r
+ }\r
+ }).when(configRestAdaptorService).getResource(Matchers.anyString(), Matchers.anyString(),\r
+ Matchers.any(Class.class));\r
+\r
+ String recipeName = "sample-recipe";\r
+\r
+ String resourceassignmentContent = FileUtils.readFileToString(\r
+ new File("src/test/resources/mapping/Mdsal/resource-assignments-complex-simple.json"),\r
+ Charset.defaultCharset());\r
+ List<ResourceAssignment> batchResourceAssignment =\r
+ TransformationUtils.getListfromJson(resourceassignmentContent, ResourceAssignment.class);\r
+\r
+ String dictionaryContent = FileUtils.readFileToString(\r
+ new File("src/test/resources/mapping/Mdsal/mdsal-array-v4iplist.json"), Charset.defaultCharset());\r
+ Map<String, ResourceDefinition> dictionaries =\r
+ ConfigResourceAssignmentTestUtils.getMapfromJson(dictionaryContent);\r
+ MdsalResourceProcessor mdsalResourceProcessor = new MdsalResourceProcessor(configRestAdaptorService);\r
+ Map<String, Object> componentContext = new HashMap<>();\r
+ componentContext.put(ConfigModelConstant.PROPERTY_RESOURCE_ASSIGNMENTS, batchResourceAssignment);\r
+ componentContext.put(ConfigModelConstant.PROPERTY_ACTION_NAME, recipeName);\r
+ componentContext.put(ConfigModelConstant.PROPERTY_TEMPLATE_NAME, "sample-template");\r
+ componentContext.put(ConfigModelConstant.PROPERTY_DICTIONARIES, dictionaries);\r
+ componentContext.put(ConfigModelConstant.PROPERTY_DICTIONARY_KEY_DOT + recipeName + ".service-instance-id",\r
+ "3c8d5a63-a793-4206-a67c-4b2e8e648196");\r
+ componentContext.put(ConfigModelConstant.PROPERTY_DICTIONARY_KEY_DOT + recipeName + ".oam-network-role",\r
+ "sample");\r
+ componentContext.put(ConfigModelConstant.PROPERTY_DICTIONARY_KEY_DOT + recipeName + ".oam-ipv4-ip-type",\r
+ "sample");\r
+ componentContext.put(ConfigModelConstant.PROPERTY_DICTIONARY_KEY_DOT + recipeName + ".profile_name", "sample");\r
+ componentContext.put(ConfigModelConstant.PROPERTY_DICTIONARY_KEY_DOT + recipeName + ".oam-vm-type", "sample");\r
+\r
+ Map<String, String> inParams = new HashMap<>();\r
+ SvcLogicContext ctx = new SvcLogicContext();\r
+ // String datatypeContent = FileUtils.readFileToString(new\r
+ // File("src/test/resources/mapping/Mdsal/dt-v4-assigned-ip-list.json"), Charset.defaultCharset() );\r
+ // ctx.setAttribute("data_types.dt-v4-assigned-ip-list", datatypeContent);\r
+ mdsalResourceProcessor.process(inParams, ctx, componentContext);\r
+ logger.info("Component Context = ({})", componentContext);\r
+ Assert.assertNotNull("failed to populate Array Complex response ", componentContext);\r
+ Assert.assertEquals("Compare String ", "10.66.1.152",\r
+ componentContext.get(ConfigModelConstant.PROPERTY_RECIPE_KEY_DOT + recipeName + ".v4-ip-prefix"));\r
+\r
+ }\r
+\r
+}\r
--- /dev/null
+{\r
+ "locations": [\r
+ {\r
+ "mdsal-country": "US",\r
+ "mdsal-state": "NJ"\r
+ },\r
+ {\r
+ "mdsal-country": "INDIA",\r
+ "mdsal-state": "TN"\r
+ }\r
+ ]\r
+}\r
--- /dev/null
+{
+ "v4-assigned-ip-list": [
+ {
+ "v4-ip-type": "NMLAN",
+ "ipv4-gateway-prefix": "10.66.1.129",
+ "v4-ip-prefix": "10.66.1.152",
+ "v4-ip-prefix-length": 32,
+ "ip-count": 1,
+ "v4-ip-source": "EIPAM",
+ "client-key": "ADIG_19_vnf_name061rej01"
+ }
+ ]
+}
--- /dev/null
+{\r
+ "locations": {\r
+ "mdsal-country": "US",\r
+ "mdsal-state": "NJ"\r
+ }\r
+}\r
--- /dev/null
+{\r
+ "vnf-topology-information": {\r
+ "vnf-assignments": {\r
+ "availability-zones": [\r
+ {\r
+ "availability-zone": "frkde-esx-az01"\r
+ }\r
+ ],\r
+ "vnf-vms": [\r
+ {\r
+ "vm-type": "vre",\r
+ "vm-count": 1,\r
+ "vm-networks": [\r
+ {\r
+ "network-role": "ADIGOam.OAM",\r
+ "network-name": "ADIGOAM.OAM",\r
+ "v4-assigned-ip-list": [\r
+ {\r
+ "v4-ip-type": "NMLAN",\r
+ "ipv4-gateway-prefix": "10.66.1.129",\r
+ "v4-ip-prefix": "10.66.1.152",\r
+ "v4-ip-prefix-length": 32,\r
+ "ip-count": 1,\r
+ "v4-ip-source": "EIPAM",\r
+ "client-key": "ADIG_19_vnf_name061rej01"\r
+ }\r
+ ],\r
+ "network-id": "VPEADIG1d77c-1086-41ec-b7f3-94bb30936807"\r
+ },\r
+ {\r
+ "network-role": "Internal-Network",\r
+ "network-name": "VMX-INTTERNAL056",\r
+ "v4-assigned-ip-list": [\r
+ {\r
+ "v4-ip-type": "INTERNAL",\r
+ "v4-ip-prefix": "128.0.0.1",\r
+ "ipv4-prefix-block": "128.0.0.0",\r
+ "v4-ip-prefix-length": 24,\r
+ "v4-ip-source": "OTHER"\r
+ }\r
+ ],\r
+ "network-forwarding": "l2",\r
+ "network-id": "VMX-INT1"\r
+ }\r
+ ],\r
+ "vm-names": [\r
+ {\r
+ "vm-name": "ADIG_19_vnf_name061rej",\r
+ "vm-uuid": "50d2032d-fe15-4e82-94f3-8b73c566a345"\r
+ }\r
+ ]\r
+ },\r
+ {\r
+ "vm-type": "vpfe",\r
+ "vm-count": 1,\r
+ "vm-networks": [\r
+ {\r
+ "network-role": "ADIG_SRIOV_3",\r
+ "network-name": "ADIG_SRIOV_3",\r
+ "multicast-allow": true,\r
+ "broadcast-allow": true,\r
+ "network-id": "VPEADIG1d77c-1086-41ec-b7f3-94bb30936810",\r
+ "vlan-filter": "[4013,4014]",\r
+ "network-macs": [\r
+ {\r
+ "mac-address": "dc:38:e1:69:bf:5f"\r
+ }\r
+ ],\r
+ "vlan-strip": false,\r
+ "unicast-allow": true\r
+ },\r
+ {\r
+ "network-role": "ADIG_SRIOV_4",\r
+ "network-name": "ADIG_SRIOV_4",\r
+ "multicast-allow": true,\r
+ "broadcast-allow": true,\r
+ "network-id": "VPEADIG1d77c-1086-41ec-b7f3-94bb30936811",\r
+ "vlan-filter": "[4013,4014]",\r
+ "network-macs": [\r
+ {\r
+ "mac-address": "dc:38:e1:69:bf:5f"\r
+ }\r
+ ],\r
+ "vlan-strip": false,\r
+ "unicast-allow": true\r
+ },\r
+ {\r
+ "network-role": "ADIG_SRIOV_1",\r
+ "network-name": "ADIG_SRIOV_1",\r
+ "multicast-allow": true,\r
+ "broadcast-allow": true,\r
+ "network-id": "VPEADIG1d77c-1086-41ec-b7f3-94bb30936808",\r
+ "vlan-filter": "[4013,4014]",\r
+ "network-macs": [\r
+ {\r
+ "mac-address": "dc:38:e1:69:bf:5f"\r
+ }\r
+ ],\r
+ "vlan-strip": false,\r
+ "unicast-allow": true\r
+ },\r
+ {\r
+ "network-role": "ADIG_SRIOV_2",\r
+ "network-name": "ADIG_SRIOV_2",\r
+ "multicast-allow": true,\r
+ "broadcast-allow": true,\r
+ "network-id": "VPEADIG1d77c-1086-41ec-b7f3-94bb30936809",\r
+ "vlan-filter": "[4013,4014]",\r
+ "network-macs": [\r
+ {\r
+ "mac-address": "dc:38:e1:69:bf:5f"\r
+ }\r
+ ],\r
+ "vlan-strip": false,\r
+ "unicast-allow": true\r
+ },\r
+ {\r
+ "network-role": "Internal-Network",\r
+ "network-name": "VMX-INTTERNAL056",\r
+ "v4-assigned-ip-list": [\r
+ {\r
+ "v4-ip-type": "INTERNAL",\r
+ "v4-ip-prefix": "128.0.0.16",\r
+ "ipv4-prefix-block": "128.0.0.0",\r
+ "v4-ip-prefix-length": 24,\r
+ "v4-ip-source": "OTHER"\r
+ }\r
+ ],\r
+ "network-forwarding": "l2",\r
+ "network-id": "VMX-INT1"\r
+ }\r
+ ],\r
+ "vm-names": [\r
+ {\r
+ "vm-name": "ADIG_19_vnf_name056fej",\r
+ "vm-uuid": "d2ce6023-a3ab-412e-bc63-360307aac165"\r
+ }\r
+ ]\r
+ }\r
+ ],\r
+ "vnf-status": "Deactivated",\r
+ "vnf-networks": [\r
+ {\r
+ "network-role": "ADIGOam.OAM",\r
+ "network-id": "VPEADIG1d77c-1086-41ec-b7f3-94bb30936807"\r
+ },\r
+ {\r
+ "network-role": "ADIG_SRIOV_3",\r
+ "network-id": "VPEADIG1d77c-1086-41ec-b7f3-94bb30936810"\r
+ },\r
+ {\r
+ "network-role": "ADIG_SRIOV_2",\r
+ "network-id": "VPEADIG1d77c-1086-41ec-b7f3-94bb30936809"\r
+ },\r
+ {\r
+ "network-role": "ADIG_SRIOV_4",\r
+ "network-id": "VPEADIG1d77c-1086-41ec-b7f3-94bb30936811"\r
+ },\r
+ {\r
+ "network-role": "ADIG_SRIOV_1",\r
+ "network-id": "VPEADIG1d77c-1086-41ec-b7f3-94bb30936808"\r
+ }\r
+ ]\r
+ }\r
+ }\r
+}\r
--- /dev/null
+{\r
+ "version": "1.0.0",\r
+ "description": "test Data Type",\r
+ "properties": {\r
+ "country": {\r
+ "required": true,\r
+ "type": "string"\r
+ },\r
+ "state": {\r
+ "required": false,\r
+ "type": "string"\r
+ }\r
+ },\r
+ "derived_from": "tosca.datatypes.Root"\r
+}\r
--- /dev/null
+{
+ "version": "1.0.0",
+ "description": "This is dt-v4-assigned-ip-list Data Type",
+ "properties": {
+ "v4-ip-type": {
+ "required": true,
+ "type": "string"
+ },
+ "ipv4-gateway-prefix": {
+ "required": true,
+ "type": "string"
+ },
+ "v4-ip-prefix": {
+ "required": true,
+ "type": "string"
+ },
+ "v4-ip-prefix-length": {
+ "required": true,
+ "type": "string"
+ },
+ "v4-ip-source": {
+ "required": true,
+ "type": "string"
+ }
+ },
+ "derived_from": "tosca.datatypes.Root"
+}
--- /dev/null
+{\r
+ "v4-ip-prefix": {\r
+ "name": "v4-ip-prefix",\r
+ "property": {\r
+ "type": "string"\r
+ },\r
+ "sources": {\r
+ "mdsal": {\r
+ "type": "source-mdsal",\r
+ "properties": {\r
+ "url-path": "/restconf/config/L3VNF-API:services/service-list/$service-instance-id/service-data/vnf-topology-information/vnf-assignments/vnf-vms/$oam-ipv4-ip-type/vm-networks/$oam-network-role/v4-assigned-ip-list/$oam-vm-type",\r
+ "path": "/v4-assigned-ip-list/0/v4-ip-prefix",\r
+ "input-key-mapping": {\r
+ "service-instance-id": "service-instance-id",\r
+ "oam-network-role": "oam-network-role",\r
+ "oam-ipv4-ip-type": "oam-ipv4-ip-type",\r
+ "oam-vm-type": "oam-vm-type"\r
+ },\r
+ "output-key-mapping": {\r
+ "v4-ip-prefix": "v4-ip-prefix"\r
+ },\r
+ "key-dependencies": [\r
+ "service-instance-id",\r
+ "oam-network-role",\r
+ "oam-ipv4-ip-type",\r
+ "oam-vm-type"\r
+ ]\r
+ }\r
+ }\r
+ }\r
+ },\r
+ "service-instance-id": {\r
+ "name": "service-instance-id",\r
+ "property": {\r
+ "type": "string"\r
+ },\r
+ "sources": {\r
+ "default": {\r
+ "type": "source-input"\r
+ }\r
+ }\r
+ },\r
+ "oam-network-role": {\r
+ "name": "oam-network-role",\r
+ "property": {\r
+ "type": "string"\r
+ },\r
+ "sources": {\r
+ "default": {\r
+ "type": "source-input"\r
+ }\r
+ }\r
+ },\r
+ "oam-ipv4-ip-type": {\r
+ "name": "oam-ipv4-ip-type",\r
+ "property": {\r
+ "type": "string"\r
+ },\r
+ "sources": {\r
+ "default": {\r
+ "type": "source-input"\r
+ }\r
+ }\r
+ },\r
+ "oam-vm-type": {\r
+ "name": "oam-vm-type",\r
+ "property": {\r
+ "type": "string"\r
+ },\r
+ "sources": {\r
+ "default": {\r
+ "type": "source-input"\r
+ }\r
+ }\r
+ }\r
+}\r
--- /dev/null
+{\r
+ "locations": {\r
+ "name": "locations",\r
+ "property": {\r
+ "type": "list",\r
+ "entry_schema": {\r
+ "type": "dt-location"\r
+ }\r
+ },\r
+ "sources": {\r
+ "mdsal": {\r
+ "type": "source-mdsal",\r
+ "properties": {\r
+ "url-path": "/restconf/config/L3VNF-API/services/service-list/$profile_name/12345",\r
+ "path": "/locations",\r
+ "input-key-mapping": {\r
+ "profile_name": "profile_name"\r
+ },\r
+ "output-key-mapping": {\r
+ "mdsal-country": "country",\r
+ "mdsal-state": "state"\r
+ },\r
+ "key-dependencies": [\r
+ "profile_name"\r
+ ]\r
+ }\r
+ }\r
+ }\r
+ },\r
+ "profile_name": {\r
+ "name": "profile_name",\r
+ "property": {\r
+ "type": "string"\r
+ },\r
+ "sources": {\r
+ "default": {\r
+ "type": "source-input"\r
+ }\r
+ }\r
+ }\r
+}\r
+\r
--- /dev/null
+{\r
+ "location": {\r
+ "name": "location",\r
+ "property": {\r
+ "type": "dt-location"\r
+ },\r
+ "sources": {\r
+ "mdsal": {\r
+ "type": "source-mdsal",\r
+ "properties": {\r
+ "url-path": "/restconf/config/L3VNF-API/services/service-list/$profile_name/12345",\r
+ "path": "/locations",\r
+ "input-key-mapping": {\r
+ "profile_name": "profile_name"\r
+ },\r
+ "output-key-mapping": {\r
+ "mdsal-country": "country",\r
+ "mdsal-state": "state"\r
+ },\r
+ "key-dependencies": [\r
+ "profile_name"\r
+ ]\r
+ }\r
+ }\r
+ }\r
+ },\r
+ "profile_name": {\r
+ "name": "profile_name",\r
+ "property": {\r
+ "type": "string"\r
+ },\r
+ "sources": {\r
+ "default": {\r
+ "type": "source-input"\r
+ }\r
+ }\r
+ }\r
+}\r
--- /dev/null
+{\r
+ "country": {\r
+ "name": "country",\r
+ "property": {\r
+ "type": "string"\r
+ },\r
+ "sources": {\r
+ "mdsal": {\r
+ "type": "source-mdsal",\r
+ "properties": {\r
+ "url-path": "/restconf/config/L3VNF-API/services/service-list/$profile_name/12345",\r
+ "path": "/locations",\r
+ "input-key-mapping": {\r
+ "profile_name": "profile_name"\r
+ },\r
+ "output-key-mapping": {\r
+ "country": "country"\r
+ },\r
+ "key-dependencies": [\r
+ "profile_name"\r
+ ]\r
+ }\r
+ }\r
+ }\r
+ },\r
+ "profile_name": {\r
+ "name": "profile_name",\r
+ "property": {\r
+ "type": "string"\r
+ },\r
+ "sources": {\r
+ "input": {\r
+ "type": "source-input"\r
+ }\r
+ }\r
+ }\r
+}\r
--- /dev/null
+[\r
+ {\r
+ "name": "locations",\r
+ "input-param": true,\r
+ "property": {\r
+ "type": "list",\r
+ "entry_schema": {\r
+ "type": "dt-location"\r
+ }\r
+ },\r
+ "dictionary-name": "locations",\r
+ "dictionary-source": "mdsal",\r
+ "dependencies": []\r
+ }\r
+]\r
--- /dev/null
+[\r
+ {\r
+ "name": "v4-ip-prefix",\r
+ "input-param": true,\r
+ "property": {\r
+ "type": "string"\r
+ },\r
+ "dictionary-name": "v4-ip-prefix",\r
+ "dictionary-source": "mdsal",\r
+ "dependencies": []\r
+ }\r
+]\r
--- /dev/null
+[\r
+ {\r
+ "name": "location",\r
+ "input-param": true,\r
+ "property": {\r
+ "type": "dt-location"\r
+ },\r
+ "dictionary-name": "location",\r
+ "dictionary-source": "mdsal",\r
+ "dependencies": []\r
+ }\r
+]\r
--- /dev/null
+[\r
+ {\r
+ "name": "country",\r
+ "input-param": true,\r
+ "property": {\r
+ "type": "string"\r
+ },\r
+ "dictionary-name": "country",\r
+ "dictionary-source": "mdsal",\r
+ "dependencies": []\r
+ }\r
+]\r
--- /dev/null
+{\r
+ "locations": "US"\r
+}\r