From cadd88348aa9934a63849e149ddb4b60f7fbef5a Mon Sep 17 00:00:00 2001 From: "Singal, Kapil (ks220y)" Date: Tue, 4 Sep 2018 21:57:47 -0400 Subject: Blueprints Processor MDSAL Resource Assignment Creating SDN Blueprints Processor MDSAL Resource Assignment Processor Change-Id: I111c9682a5601f32536e93180d4357fc7ac8a961 Issue-ID: CCSDK-498 Signed-off-by: Singal, Kapil (ks220y) --- .../processor/MdsalResourceProcessor.java | 239 ++++++++++++++++++ .../processor/MdsalResourceProcessorTest.java | 268 +++++++++++++++++++++ .../mapping/Mdsal/array-complex-response.json | 12 + .../Mdsal/array-complex-v4-assigned-response.json | 13 + .../resources/mapping/Mdsal/complex-response.json | 6 + .../resources/mapping/Mdsal/default-pointer.json | 166 +++++++++++++ .../test/resources/mapping/Mdsal/dt-location.json | 15 ++ .../mapping/Mdsal/dt-v4-assigned-ip-list.json | 27 +++ .../mapping/Mdsal/mdsal-array-v4iplist.json | 76 ++++++ .../test/resources/mapping/Mdsal/mdsal-array.json | 42 ++++ .../resources/mapping/Mdsal/mdsal-complex.json | 38 +++ .../test/resources/mapping/Mdsal/mdsal-simple.json | 37 +++ .../mapping/Mdsal/resource-assignments-array.json | 15 ++ .../Mdsal/resource-assignments-complex-simple.json | 12 + .../Mdsal/resource-assignments-complex.json | 12 + .../mapping/Mdsal/resource-assignments-simple.json | 12 + .../resources/mapping/Mdsal/simple-response.json | 3 + 17 files changed, 993 insertions(+) create mode 100644 blueprints-processor/plugin/assignment-provider/src/main/java/org/onap/ccsdk/config/assignment/processor/MdsalResourceProcessor.java create mode 100644 blueprints-processor/plugin/assignment-provider/src/test/java/org/onap/ccsdk/config/assignment/processor/MdsalResourceProcessorTest.java create mode 100644 blueprints-processor/plugin/assignment-provider/src/test/resources/mapping/Mdsal/array-complex-response.json create mode 100644 blueprints-processor/plugin/assignment-provider/src/test/resources/mapping/Mdsal/array-complex-v4-assigned-response.json create mode 100644 blueprints-processor/plugin/assignment-provider/src/test/resources/mapping/Mdsal/complex-response.json create mode 100644 blueprints-processor/plugin/assignment-provider/src/test/resources/mapping/Mdsal/default-pointer.json create mode 100644 blueprints-processor/plugin/assignment-provider/src/test/resources/mapping/Mdsal/dt-location.json create mode 100644 blueprints-processor/plugin/assignment-provider/src/test/resources/mapping/Mdsal/dt-v4-assigned-ip-list.json create mode 100644 blueprints-processor/plugin/assignment-provider/src/test/resources/mapping/Mdsal/mdsal-array-v4iplist.json create mode 100644 blueprints-processor/plugin/assignment-provider/src/test/resources/mapping/Mdsal/mdsal-array.json create mode 100644 blueprints-processor/plugin/assignment-provider/src/test/resources/mapping/Mdsal/mdsal-complex.json create mode 100644 blueprints-processor/plugin/assignment-provider/src/test/resources/mapping/Mdsal/mdsal-simple.json create mode 100644 blueprints-processor/plugin/assignment-provider/src/test/resources/mapping/Mdsal/resource-assignments-array.json create mode 100644 blueprints-processor/plugin/assignment-provider/src/test/resources/mapping/Mdsal/resource-assignments-complex-simple.json create mode 100644 blueprints-processor/plugin/assignment-provider/src/test/resources/mapping/Mdsal/resource-assignments-complex.json create mode 100644 blueprints-processor/plugin/assignment-provider/src/test/resources/mapping/Mdsal/resource-assignments-simple.json create mode 100644 blueprints-processor/plugin/assignment-provider/src/test/resources/mapping/Mdsal/simple-response.json (limited to 'blueprints-processor/plugin') 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 new file mode 100644 index 000000000..15528e13e --- /dev/null +++ b/blueprints-processor/plugin/assignment-provider/src/main/java/org/onap/ccsdk/config/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.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/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 new file mode 100644 index 000000000..2d651c836 --- /dev/null +++ b/blueprints-processor/plugin/assignment-provider/src/test/java/org/onap/ccsdk/config/assignment/processor/MdsalResourceProcessorTest.java @@ -0,0 +1,268 @@ +/* + * 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/resources/mapping/Mdsal/array-complex-response.json b/blueprints-processor/plugin/assignment-provider/src/test/resources/mapping/Mdsal/array-complex-response.json new file mode 100644 index 000000000..2dfe89e29 --- /dev/null +++ b/blueprints-processor/plugin/assignment-provider/src/test/resources/mapping/Mdsal/array-complex-response.json @@ -0,0 +1,12 @@ +{ + "locations": [ + { + "mdsal-country": "US", + "mdsal-state": "NJ" + }, + { + "mdsal-country": "INDIA", + "mdsal-state": "TN" + } + ] +} diff --git a/blueprints-processor/plugin/assignment-provider/src/test/resources/mapping/Mdsal/array-complex-v4-assigned-response.json b/blueprints-processor/plugin/assignment-provider/src/test/resources/mapping/Mdsal/array-complex-v4-assigned-response.json new file mode 100644 index 000000000..d7c5546c1 --- /dev/null +++ b/blueprints-processor/plugin/assignment-provider/src/test/resources/mapping/Mdsal/array-complex-v4-assigned-response.json @@ -0,0 +1,13 @@ +{ + "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" + } + ] +} diff --git a/blueprints-processor/plugin/assignment-provider/src/test/resources/mapping/Mdsal/complex-response.json b/blueprints-processor/plugin/assignment-provider/src/test/resources/mapping/Mdsal/complex-response.json new file mode 100644 index 000000000..1a36100fd --- /dev/null +++ b/blueprints-processor/plugin/assignment-provider/src/test/resources/mapping/Mdsal/complex-response.json @@ -0,0 +1,6 @@ +{ + "locations": { + "mdsal-country": "US", + "mdsal-state": "NJ" + } +} diff --git a/blueprints-processor/plugin/assignment-provider/src/test/resources/mapping/Mdsal/default-pointer.json b/blueprints-processor/plugin/assignment-provider/src/test/resources/mapping/Mdsal/default-pointer.json new file mode 100644 index 000000000..47edb1881 --- /dev/null +++ b/blueprints-processor/plugin/assignment-provider/src/test/resources/mapping/Mdsal/default-pointer.json @@ -0,0 +1,166 @@ +{ + "vnf-topology-information": { + "vnf-assignments": { + "availability-zones": [ + { + "availability-zone": "frkde-esx-az01" + } + ], + "vnf-vms": [ + { + "vm-type": "vre", + "vm-count": 1, + "vm-networks": [ + { + "network-role": "ADIGOam.OAM", + "network-name": "ADIGOAM.OAM", + "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" + } + ], + "network-id": "VPEADIG1d77c-1086-41ec-b7f3-94bb30936807" + }, + { + "network-role": "Internal-Network", + "network-name": "VMX-INTTERNAL056", + "v4-assigned-ip-list": [ + { + "v4-ip-type": "INTERNAL", + "v4-ip-prefix": "128.0.0.1", + "ipv4-prefix-block": "128.0.0.0", + "v4-ip-prefix-length": 24, + "v4-ip-source": "OTHER" + } + ], + "network-forwarding": "l2", + "network-id": "VMX-INT1" + } + ], + "vm-names": [ + { + "vm-name": "ADIG_19_vnf_name061rej", + "vm-uuid": "50d2032d-fe15-4e82-94f3-8b73c566a345" + } + ] + }, + { + "vm-type": "vpfe", + "vm-count": 1, + "vm-networks": [ + { + "network-role": "ADIG_SRIOV_3", + "network-name": "ADIG_SRIOV_3", + "multicast-allow": true, + "broadcast-allow": true, + "network-id": "VPEADIG1d77c-1086-41ec-b7f3-94bb30936810", + "vlan-filter": "[4013,4014]", + "network-macs": [ + { + "mac-address": "dc:38:e1:69:bf:5f" + } + ], + "vlan-strip": false, + "unicast-allow": true + }, + { + "network-role": "ADIG_SRIOV_4", + "network-name": "ADIG_SRIOV_4", + "multicast-allow": true, + "broadcast-allow": true, + "network-id": "VPEADIG1d77c-1086-41ec-b7f3-94bb30936811", + "vlan-filter": "[4013,4014]", + "network-macs": [ + { + "mac-address": "dc:38:e1:69:bf:5f" + } + ], + "vlan-strip": false, + "unicast-allow": true + }, + { + "network-role": "ADIG_SRIOV_1", + "network-name": "ADIG_SRIOV_1", + "multicast-allow": true, + "broadcast-allow": true, + "network-id": "VPEADIG1d77c-1086-41ec-b7f3-94bb30936808", + "vlan-filter": "[4013,4014]", + "network-macs": [ + { + "mac-address": "dc:38:e1:69:bf:5f" + } + ], + "vlan-strip": false, + "unicast-allow": true + }, + { + "network-role": "ADIG_SRIOV_2", + "network-name": "ADIG_SRIOV_2", + "multicast-allow": true, + "broadcast-allow": true, + "network-id": "VPEADIG1d77c-1086-41ec-b7f3-94bb30936809", + "vlan-filter": "[4013,4014]", + "network-macs": [ + { + "mac-address": "dc:38:e1:69:bf:5f" + } + ], + "vlan-strip": false, + "unicast-allow": true + }, + { + "network-role": "Internal-Network", + "network-name": "VMX-INTTERNAL056", + "v4-assigned-ip-list": [ + { + "v4-ip-type": "INTERNAL", + "v4-ip-prefix": "128.0.0.16", + "ipv4-prefix-block": "128.0.0.0", + "v4-ip-prefix-length": 24, + "v4-ip-source": "OTHER" + } + ], + "network-forwarding": "l2", + "network-id": "VMX-INT1" + } + ], + "vm-names": [ + { + "vm-name": "ADIG_19_vnf_name056fej", + "vm-uuid": "d2ce6023-a3ab-412e-bc63-360307aac165" + } + ] + } + ], + "vnf-status": "Deactivated", + "vnf-networks": [ + { + "network-role": "ADIGOam.OAM", + "network-id": "VPEADIG1d77c-1086-41ec-b7f3-94bb30936807" + }, + { + "network-role": "ADIG_SRIOV_3", + "network-id": "VPEADIG1d77c-1086-41ec-b7f3-94bb30936810" + }, + { + "network-role": "ADIG_SRIOV_2", + "network-id": "VPEADIG1d77c-1086-41ec-b7f3-94bb30936809" + }, + { + "network-role": "ADIG_SRIOV_4", + "network-id": "VPEADIG1d77c-1086-41ec-b7f3-94bb30936811" + }, + { + "network-role": "ADIG_SRIOV_1", + "network-id": "VPEADIG1d77c-1086-41ec-b7f3-94bb30936808" + } + ] + } + } +} diff --git a/blueprints-processor/plugin/assignment-provider/src/test/resources/mapping/Mdsal/dt-location.json b/blueprints-processor/plugin/assignment-provider/src/test/resources/mapping/Mdsal/dt-location.json new file mode 100644 index 000000000..52e0a7967 --- /dev/null +++ b/blueprints-processor/plugin/assignment-provider/src/test/resources/mapping/Mdsal/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/Mdsal/dt-v4-assigned-ip-list.json b/blueprints-processor/plugin/assignment-provider/src/test/resources/mapping/Mdsal/dt-v4-assigned-ip-list.json new file mode 100644 index 000000000..bc8f1d2c2 --- /dev/null +++ b/blueprints-processor/plugin/assignment-provider/src/test/resources/mapping/Mdsal/dt-v4-assigned-ip-list.json @@ -0,0 +1,27 @@ +{ + "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" +} diff --git a/blueprints-processor/plugin/assignment-provider/src/test/resources/mapping/Mdsal/mdsal-array-v4iplist.json b/blueprints-processor/plugin/assignment-provider/src/test/resources/mapping/Mdsal/mdsal-array-v4iplist.json new file mode 100644 index 000000000..387a5ad2d --- /dev/null +++ b/blueprints-processor/plugin/assignment-provider/src/test/resources/mapping/Mdsal/mdsal-array-v4iplist.json @@ -0,0 +1,76 @@ +{ + "v4-ip-prefix": { + "name": "v4-ip-prefix", + "property": { + "type": "string" + }, + "sources": { + "mdsal": { + "type": "source-mdsal", + "properties": { + "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", + "path": "/v4-assigned-ip-list/0/v4-ip-prefix", + "input-key-mapping": { + "service-instance-id": "service-instance-id", + "oam-network-role": "oam-network-role", + "oam-ipv4-ip-type": "oam-ipv4-ip-type", + "oam-vm-type": "oam-vm-type" + }, + "output-key-mapping": { + "v4-ip-prefix": "v4-ip-prefix" + }, + "key-dependencies": [ + "service-instance-id", + "oam-network-role", + "oam-ipv4-ip-type", + "oam-vm-type" + ] + } + } + } + }, + "service-instance-id": { + "name": "service-instance-id", + "property": { + "type": "string" + }, + "sources": { + "default": { + "type": "source-input" + } + } + }, + "oam-network-role": { + "name": "oam-network-role", + "property": { + "type": "string" + }, + "sources": { + "default": { + "type": "source-input" + } + } + }, + "oam-ipv4-ip-type": { + "name": "oam-ipv4-ip-type", + "property": { + "type": "string" + }, + "sources": { + "default": { + "type": "source-input" + } + } + }, + "oam-vm-type": { + "name": "oam-vm-type", + "property": { + "type": "string" + }, + "sources": { + "default": { + "type": "source-input" + } + } + } +} diff --git a/blueprints-processor/plugin/assignment-provider/src/test/resources/mapping/Mdsal/mdsal-array.json b/blueprints-processor/plugin/assignment-provider/src/test/resources/mapping/Mdsal/mdsal-array.json new file mode 100644 index 000000000..290a15752 --- /dev/null +++ b/blueprints-processor/plugin/assignment-provider/src/test/resources/mapping/Mdsal/mdsal-array.json @@ -0,0 +1,42 @@ +{ + "locations": { + "name": "locations", + "property": { + "type": "list", + "entry_schema": { + "type": "dt-location" + } + }, + "sources": { + "mdsal": { + "type": "source-mdsal", + "properties": { + "url-path": "/restconf/config/L3VNF-API/services/service-list/$profile_name/12345", + "path": "/locations", + "input-key-mapping": { + "profile_name": "profile_name" + }, + "output-key-mapping": { + "mdsal-country": "country", + "mdsal-state": "state" + }, + "key-dependencies": [ + "profile_name" + ] + } + } + } + }, + "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/Mdsal/mdsal-complex.json b/blueprints-processor/plugin/assignment-provider/src/test/resources/mapping/Mdsal/mdsal-complex.json new file mode 100644 index 000000000..f5a7d7ef6 --- /dev/null +++ b/blueprints-processor/plugin/assignment-provider/src/test/resources/mapping/Mdsal/mdsal-complex.json @@ -0,0 +1,38 @@ +{ + "location": { + "name": "location", + "property": { + "type": "dt-location" + }, + "sources": { + "mdsal": { + "type": "source-mdsal", + "properties": { + "url-path": "/restconf/config/L3VNF-API/services/service-list/$profile_name/12345", + "path": "/locations", + "input-key-mapping": { + "profile_name": "profile_name" + }, + "output-key-mapping": { + "mdsal-country": "country", + "mdsal-state": "state" + }, + "key-dependencies": [ + "profile_name" + ] + } + } + } + }, + "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/Mdsal/mdsal-simple.json b/blueprints-processor/plugin/assignment-provider/src/test/resources/mapping/Mdsal/mdsal-simple.json new file mode 100644 index 000000000..db7ee7eed --- /dev/null +++ b/blueprints-processor/plugin/assignment-provider/src/test/resources/mapping/Mdsal/mdsal-simple.json @@ -0,0 +1,37 @@ +{ + "country": { + "name": "country", + "property": { + "type": "string" + }, + "sources": { + "mdsal": { + "type": "source-mdsal", + "properties": { + "url-path": "/restconf/config/L3VNF-API/services/service-list/$profile_name/12345", + "path": "/locations", + "input-key-mapping": { + "profile_name": "profile_name" + }, + "output-key-mapping": { + "country": "country" + }, + "key-dependencies": [ + "profile_name" + ] + } + } + } + }, + "profile_name": { + "name": "profile_name", + "property": { + "type": "string" + }, + "sources": { + "input": { + "type": "source-input" + } + } + } +} diff --git a/blueprints-processor/plugin/assignment-provider/src/test/resources/mapping/Mdsal/resource-assignments-array.json b/blueprints-processor/plugin/assignment-provider/src/test/resources/mapping/Mdsal/resource-assignments-array.json new file mode 100644 index 000000000..2b5865326 --- /dev/null +++ b/blueprints-processor/plugin/assignment-provider/src/test/resources/mapping/Mdsal/resource-assignments-array.json @@ -0,0 +1,15 @@ +[ + { + "name": "locations", + "input-param": true, + "property": { + "type": "list", + "entry_schema": { + "type": "dt-location" + } + }, + "dictionary-name": "locations", + "dictionary-source": "mdsal", + "dependencies": [] + } +] diff --git a/blueprints-processor/plugin/assignment-provider/src/test/resources/mapping/Mdsal/resource-assignments-complex-simple.json b/blueprints-processor/plugin/assignment-provider/src/test/resources/mapping/Mdsal/resource-assignments-complex-simple.json new file mode 100644 index 000000000..15881cfd0 --- /dev/null +++ b/blueprints-processor/plugin/assignment-provider/src/test/resources/mapping/Mdsal/resource-assignments-complex-simple.json @@ -0,0 +1,12 @@ +[ + { + "name": "v4-ip-prefix", + "input-param": true, + "property": { + "type": "string" + }, + "dictionary-name": "v4-ip-prefix", + "dictionary-source": "mdsal", + "dependencies": [] + } +] diff --git a/blueprints-processor/plugin/assignment-provider/src/test/resources/mapping/Mdsal/resource-assignments-complex.json b/blueprints-processor/plugin/assignment-provider/src/test/resources/mapping/Mdsal/resource-assignments-complex.json new file mode 100644 index 000000000..e42bd9431 --- /dev/null +++ b/blueprints-processor/plugin/assignment-provider/src/test/resources/mapping/Mdsal/resource-assignments-complex.json @@ -0,0 +1,12 @@ +[ + { + "name": "location", + "input-param": true, + "property": { + "type": "dt-location" + }, + "dictionary-name": "location", + "dictionary-source": "mdsal", + "dependencies": [] + } +] diff --git a/blueprints-processor/plugin/assignment-provider/src/test/resources/mapping/Mdsal/resource-assignments-simple.json b/blueprints-processor/plugin/assignment-provider/src/test/resources/mapping/Mdsal/resource-assignments-simple.json new file mode 100644 index 000000000..6385e6a8b --- /dev/null +++ b/blueprints-processor/plugin/assignment-provider/src/test/resources/mapping/Mdsal/resource-assignments-simple.json @@ -0,0 +1,12 @@ +[ + { + "name": "country", + "input-param": true, + "property": { + "type": "string" + }, + "dictionary-name": "country", + "dictionary-source": "mdsal", + "dependencies": [] + } +] diff --git a/blueprints-processor/plugin/assignment-provider/src/test/resources/mapping/Mdsal/simple-response.json b/blueprints-processor/plugin/assignment-provider/src/test/resources/mapping/Mdsal/simple-response.json new file mode 100644 index 000000000..8c2bb898f --- /dev/null +++ b/blueprints-processor/plugin/assignment-provider/src/test/resources/mapping/Mdsal/simple-response.json @@ -0,0 +1,3 @@ +{ + "locations": "US" +} -- cgit 1.2.3-korg