SDN Controller Blueprints Assignment 85/64485/2
authorSingal, Kapil (ks220y) <ks220y@att.com>
Tue, 4 Sep 2018 17:28:39 +0000 (13:28 -0400)
committerSingal, Kapil (ks220y) <ks220y@att.com>
Tue, 4 Sep 2018 17:36:15 +0000 (13:36 -0400)
Creating SDN Controller Blueprints Resource Assignment Service

Change-Id: I1d997226a515c36b2ca07d23991c0e98df2ab78c
Issue-ID: CCSDK-507
Signed-off-by: Singal, Kapil (ks220y) <ks220y@att.com>
13 files changed:
blueprints-processor/plugin/assignment-provider/src/main/java/org/onap/ccsdk/config/assignment/ConfigAssignmentConstants.java [new file with mode: 0644]
blueprints-processor/plugin/assignment-provider/src/main/java/org/onap/ccsdk/config/assignment/data/ResourceAssignmentData.java [new file with mode: 0644]
blueprints-processor/plugin/assignment-provider/src/main/java/org/onap/ccsdk/config/assignment/processor/ProcessorFactory.java [new file with mode: 0644]
blueprints-processor/plugin/assignment-provider/src/main/java/org/onap/ccsdk/config/assignment/processor/ResourceAssignmentProcessor.java [new file with mode: 0644]
blueprints-processor/plugin/assignment-provider/src/main/java/org/onap/ccsdk/config/assignment/service/ConfigAssignmentPersistService.java [new file with mode: 0644]
blueprints-processor/plugin/assignment-provider/src/main/java/org/onap/ccsdk/config/assignment/service/ConfigAssignmentProcessService.java [new file with mode: 0644]
blueprints-processor/plugin/assignment-provider/src/main/java/org/onap/ccsdk/config/assignment/service/ConfigAssignmentService.java [new file with mode: 0644]
blueprints-processor/plugin/assignment-provider/src/main/java/org/onap/ccsdk/config/assignment/service/ConfigAssignmentServiceImpl.java [new file with mode: 0644]
blueprints-processor/plugin/assignment-provider/src/main/java/org/onap/ccsdk/config/assignment/service/ConfigAssignmentUtils.java [new file with mode: 0644]
blueprints-processor/plugin/assignment-provider/src/main/java/org/onap/ccsdk/config/assignment/service/ConfigPreviewService.java [new file with mode: 0644]
blueprints-processor/plugin/assignment-provider/src/main/java/org/onap/ccsdk/config/assignment/service/ResourceDictionaryService.java [new file with mode: 0644]
blueprints-processor/plugin/assignment-provider/src/main/java/org/onap/ccsdk/config/assignment/service/ResourceModelService.java [new file with mode: 0644]
blueprints-processor/plugin/assignment-provider/src/main/resources/org/opendaylight/blueprint/impl-blueprint.xml [new file with mode: 0644]

diff --git a/blueprints-processor/plugin/assignment-provider/src/main/java/org/onap/ccsdk/config/assignment/ConfigAssignmentConstants.java b/blueprints-processor/plugin/assignment-provider/src/main/java/org/onap/ccsdk/config/assignment/ConfigAssignmentConstants.java
new file mode 100644 (file)
index 0000000..9ab5ae6
--- /dev/null
@@ -0,0 +1,34 @@
+/*\r
+ * Copyright © 2017-2018 AT&T Intellectual Property.\r
+ * \r
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except\r
+ * in compliance with the License. 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 distributed under the License\r
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express\r
+ * or implied. See the License for the specific language governing permissions and limitations under\r
+ * the License.\r
+ */\r
+\r
+package org.onap.ccsdk.config.assignment;\r
+\r
+@SuppressWarnings("squid:S1118")\r
+public class ConfigAssignmentConstants {\r
+    \r
+    public static final String OUTPUT_PARAM_STATUS = "status";\r
+    public static final String OUTPUT_PARAM_RESOURCE_ASSIGNMENT_PARAMS = "resource-assignment-params";\r
+    public static final String OUTPUT_PARAM_MASHED_DATA = "mashed-data";\r
+    public static final String OUTPUT_PARAM_ERROR_MESSAGE = "error-message";\r
+    public static final String OUTPUT_STATUS_SUCCESS = "success";\r
+    public static final String OUTPUT_STATUS_FAILURE = "failure";\r
+    \r
+    public static final String INPUT_PARAM_REQUEST_ID = "request-id";\r
+    public static final String INPUT_PARAM_RESOURCE_ID = "resource-id";\r
+    public static final String INPUT_PARAM_RESOURCE_TYPE = "resource-type";\r
+    public static final String INPUT_PARAM_ACTION_NAME = "action-name";\r
+    public static final String INPUT_PARAM_TEMPLATE_NAMES = "template-names";\r
+    public static final String INPUT_PARAM_INPUT_DATA = "input-data";\r
+    \r
+}\r
diff --git a/blueprints-processor/plugin/assignment-provider/src/main/java/org/onap/ccsdk/config/assignment/data/ResourceAssignmentData.java b/blueprints-processor/plugin/assignment-provider/src/main/java/org/onap/ccsdk/config/assignment/data/ResourceAssignmentData.java
new file mode 100644 (file)
index 0000000..d8a2745
--- /dev/null
@@ -0,0 +1,160 @@
+/*\r
+ * Copyright © 2017-2018 AT&T Intellectual Property.\r
+ * \r
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except\r
+ * in compliance with the License. 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 distributed under the License\r
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express\r
+ * or implied. See the License for the specific language governing permissions and limitations under\r
+ * the License.\r
+ */\r
+\r
+package org.onap.ccsdk.config.assignment.data;\r
+\r
+import java.util.HashMap;\r
+import java.util.List;\r
+import java.util.Map;\r
+import org.onap.ccsdk.config.model.data.ResourceAssignment;\r
+import org.onap.ccsdk.sli.core.sli.SvcLogicContext;\r
+\r
+public class ResourceAssignmentData {\r
+    \r
+    private String requestId;\r
+    private boolean reloadModel;\r
+    private String resourceType;\r
+    private String resourceId;\r
+    private String serviceTemplateName;\r
+    private String serviceTemplateVersion;\r
+    private String actionName;\r
+    private String inputData;\r
+    private SvcLogicContext svcLogicContext;\r
+    private List<String> templateNames;\r
+    private Map<String, List<ResourceAssignment>> templatesResourceAssignments = new HashMap<>();\r
+    private Map<String, String> templatesContents = new HashMap<>();\r
+    private Map<String, String> templatesMashedContents = new HashMap<>();\r
+    private Map<String, String> templatesData = new HashMap<>();\r
+    private Map<String, Object> context = new HashMap<>();\r
+    \r
+    public String getRequestId() {\r
+        return requestId;\r
+    }\r
+    \r
+    public void setRequestId(String requestId) {\r
+        this.requestId = requestId;\r
+    }\r
+    \r
+    public String getResourceType() {\r
+        return resourceType;\r
+    }\r
+    \r
+    public void setResourceType(String resourceType) {\r
+        this.resourceType = resourceType;\r
+    }\r
+    \r
+    public String getResourceId() {\r
+        return resourceId;\r
+    }\r
+    \r
+    public void setResourceId(String resourceId) {\r
+        this.resourceId = resourceId;\r
+    }\r
+    \r
+    public String getServiceTemplateName() {\r
+        return serviceTemplateName;\r
+    }\r
+    \r
+    public void setServiceTemplateName(String serviceTemplateName) {\r
+        this.serviceTemplateName = serviceTemplateName;\r
+    }\r
+    \r
+    public String getServiceTemplateVersion() {\r
+        return serviceTemplateVersion;\r
+    }\r
+    \r
+    public void setServiceTemplateVersion(String serviceTemplateVersion) {\r
+        this.serviceTemplateVersion = serviceTemplateVersion;\r
+    }\r
+    \r
+    public String getActionName() {\r
+        return actionName;\r
+    }\r
+    \r
+    public void setActionName(String actionName) {\r
+        this.actionName = actionName;\r
+    }\r
+    \r
+    public String getInputData() {\r
+        return inputData;\r
+    }\r
+    \r
+    public void setInputData(String inputData) {\r
+        this.inputData = inputData;\r
+    }\r
+    \r
+    public List<String> getTemplateNames() {\r
+        return templateNames;\r
+    }\r
+    \r
+    public void setTemplateNames(List<String> templateNames) {\r
+        this.templateNames = templateNames;\r
+    }\r
+    \r
+    public Map<String, List<ResourceAssignment>> getTemplatesResourceAssignments() {\r
+        return templatesResourceAssignments;\r
+    }\r
+    \r
+    public void setTemplatesResourceAssignments(Map<String, List<ResourceAssignment>> templatesResourceAssignments) {\r
+        this.templatesResourceAssignments = templatesResourceAssignments;\r
+    }\r
+    \r
+    public Map<String, String> getTemplatesContents() {\r
+        return templatesContents;\r
+    }\r
+    \r
+    public void setTemplatesContents(Map<String, String> templatesContents) {\r
+        this.templatesContents = templatesContents;\r
+    }\r
+    \r
+    public Map<String, String> getTemplatesMashedContents() {\r
+        return templatesMashedContents;\r
+    }\r
+    \r
+    public void setTemplatesMashedContents(Map<String, String> templatesMashedContents) {\r
+        this.templatesMashedContents = templatesMashedContents;\r
+    }\r
+    \r
+    public Map<String, String> getTemplatesData() {\r
+        return templatesData;\r
+    }\r
+    \r
+    public void setTemplatesData(Map<String, String> templatesData) {\r
+        this.templatesData = templatesData;\r
+    }\r
+    \r
+    public Map<String, Object> getContext() {\r
+        return context;\r
+    }\r
+    \r
+    public void setContext(Map<String, Object> context) {\r
+        this.context = context;\r
+    }\r
+    \r
+    public SvcLogicContext getSvcLogicContext() {\r
+        return svcLogicContext;\r
+    }\r
+    \r
+    public void setSvcLogicContext(SvcLogicContext svcLogicContext) {\r
+        this.svcLogicContext = svcLogicContext;\r
+    }\r
+    \r
+    public boolean isReloadModel() {\r
+        return reloadModel;\r
+    }\r
+    \r
+    public void setReloadModel(boolean reloadModel) {\r
+        this.reloadModel = reloadModel;\r
+    }\r
+}\r
diff --git a/blueprints-processor/plugin/assignment-provider/src/main/java/org/onap/ccsdk/config/assignment/processor/ProcessorFactory.java b/blueprints-processor/plugin/assignment-provider/src/main/java/org/onap/ccsdk/config/assignment/processor/ProcessorFactory.java
new file mode 100644 (file)
index 0000000..d80fec8
--- /dev/null
@@ -0,0 +1,49 @@
+/*\r
+ * Copyright © 2017-2018 AT&T Intellectual Property.\r
+ * \r
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except\r
+ * in compliance with the License. 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 distributed under the License\r
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express\r
+ * or implied. See the License for the specific language governing permissions and limitations under\r
+ * the License.\r
+ */\r
+\r
+package org.onap.ccsdk.config.assignment.processor;\r
+\r
+import org.onap.ccsdk.config.data.adaptor.service.ConfigResourceService;\r
+import org.onap.ccsdk.config.model.ConfigModelConstant;\r
+import org.onap.ccsdk.config.model.service.ComponentNode;\r
+import org.onap.ccsdk.config.model.service.ComponentNodeService;\r
+import org.onap.ccsdk.config.rest.adaptor.service.ConfigRestAdaptorService;\r
+\r
+public class ProcessorFactory {\r
+    \r
+    private ConfigResourceService configResourceService;\r
+    private ConfigRestAdaptorService configRestAdaptorService;\r
+    private ComponentNodeService componentNodeService;\r
+    \r
+    public ProcessorFactory(ConfigResourceService configResourceService,\r
+            ConfigRestAdaptorService configRestAdaptorService, ComponentNodeService componentNodeService) {\r
+        this.componentNodeService = componentNodeService;\r
+        this.configResourceService = configResourceService;\r
+        this.configRestAdaptorService = configRestAdaptorService;\r
+    }\r
+    \r
+    public ComponentNode getInstance(String source) {\r
+        \r
+        if (ConfigModelConstant.SOURCE_DEFAULT.equalsIgnoreCase(source)) {\r
+            return new DefaultResourceProcessor(configResourceService);\r
+        } else if (ConfigModelConstant.SOURCE_DB.equalsIgnoreCase(source)) {\r
+            return new DBResourceProcessor(configResourceService);\r
+        } else if (ConfigModelConstant.SOURCE_MDSAL.equalsIgnoreCase(source)) {\r
+            return new MdsalResourceProcessor(configRestAdaptorService);\r
+        }\r
+        // Default\r
+        return new InputResourceProcessor(configResourceService);\r
+    }\r
+    \r
+}\r
diff --git a/blueprints-processor/plugin/assignment-provider/src/main/java/org/onap/ccsdk/config/assignment/processor/ResourceAssignmentProcessor.java b/blueprints-processor/plugin/assignment-provider/src/main/java/org/onap/ccsdk/config/assignment/processor/ResourceAssignmentProcessor.java
new file mode 100644 (file)
index 0000000..c1c9b93
--- /dev/null
@@ -0,0 +1,117 @@
+/*\r
+ * Copyright © 2017-2018 AT&T Intellectual Property.\r
+ * \r
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except\r
+ * in compliance with the License. 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 distributed under the License\r
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express\r
+ * or implied. See the License for the specific language governing permissions and limitations under\r
+ * the License.\r
+ */\r
+\r
+package org.onap.ccsdk.config.assignment.processor;\r
+\r
+import java.util.ArrayList;\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.onap.ccsdk.config.model.data.ResourceAssignment;\r
+import org.onap.ccsdk.config.model.utils.TopologicalSortingUtils;\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
+public class ResourceAssignmentProcessor {\r
+    private static EELFLogger logger = EELFManager.getInstance().getLogger(ResourceAssignmentProcessor.class);\r
+    \r
+    private List<ResourceAssignment> assignments;\r
+    private Map<String, ResourceAssignment> resourceAssignmentMap;\r
+    \r
+    @SuppressWarnings("squid:S1172")\r
+    public ResourceAssignmentProcessor(List<ResourceAssignment> assignments, SvcLogicContext ctx) {\r
+        this.assignments = assignments;\r
+        this.resourceAssignmentMap = new HashMap<>();\r
+    }\r
+    \r
+    @SuppressWarnings("squid:S3776")\r
+    public List<List<ResourceAssignment>> process() {\r
+        List<List<ResourceAssignment>> sequenceBatchResourceAssignment = new ArrayList<>();\r
+        if (this.assignments != null) {\r
+            logger.info("Assignments ({})", this.assignments);\r
+            this.assignments.forEach(resourceMapping -> {\r
+                if (resourceMapping != null) {\r
+                    logger.trace("Processing Key ({})", resourceMapping.getName());\r
+                    resourceAssignmentMap.put(resourceMapping.getName(), resourceMapping);\r
+                }\r
+            });\r
+            \r
+            TopologicalSortingUtils<ResourceAssignment> topologySorting = new TopologicalSortingUtils<>();\r
+            this.resourceAssignmentMap.forEach((mappingKey, mapping) -> {\r
+                if (mapping != null) {\r
+                    if (mapping.getDependencies() != null && !mapping.getDependencies().isEmpty()) {\r
+                        for (String dependency : mapping.getDependencies()) {\r
+                            topologySorting.add(resourceAssignmentMap.get(dependency), mapping);\r
+                        }\r
+                    } else {\r
+                        topologySorting.add(null, mapping);\r
+                    }\r
+                }\r
+            });\r
+            \r
+            List<ResourceAssignment> sequencedResourceAssignments = topologySorting.topSort();\r
+            logger.info("Sorted Sequenced Assignments ({})", sequencedResourceAssignments);\r
+            \r
+            List<ResourceAssignment> batchResourceAssignment = null;\r
+            List<String> batchAssignmentName = null;\r
+            for (int i = 0; i < sequencedResourceAssignments.size(); i++) {\r
+                ResourceAssignment resourceAssignment = sequencedResourceAssignments.get(i);\r
+                ResourceAssignment previousResourceAssignment = null;\r
+                \r
+                if (i > 0) {\r
+                    previousResourceAssignment = sequencedResourceAssignments.get(i - 1);\r
+                }\r
+                if (resourceAssignment != null) {\r
+                    \r
+                    boolean dependencyPresence = false;\r
+                    if (batchAssignmentName != null && resourceAssignment.getDependencies() != null) {\r
+                        dependencyPresence =\r
+                                CollectionUtils.containsAny(batchAssignmentName, resourceAssignment.getDependencies());\r
+                    }\r
+                    \r
+                    logger.trace("({}) -> Checking ({}), with ({}), result ({})", resourceAssignment.getName(),\r
+                            batchAssignmentName, resourceAssignment.getDependencies(), dependencyPresence);\r
+                    \r
+                    if (previousResourceAssignment != null && resourceAssignment.getDictionarySource() != null\r
+                            && resourceAssignment.getDictionarySource()\r
+                                    .equalsIgnoreCase(previousResourceAssignment.getDictionarySource())\r
+                            && !dependencyPresence) {\r
+                        batchResourceAssignment.add(resourceAssignment);\r
+                        batchAssignmentName.add(resourceAssignment.getName());\r
+                    } else {\r
+                        if (batchResourceAssignment != null) {\r
+                            sequenceBatchResourceAssignment.add(batchResourceAssignment);\r
+                            logger.trace("Created old Set ({})", batchAssignmentName);\r
+                        }\r
+                        batchResourceAssignment = new ArrayList<>();\r
+                        batchResourceAssignment.add(resourceAssignment);\r
+                        \r
+                        batchAssignmentName = new ArrayList<>();\r
+                        batchAssignmentName.add(resourceAssignment.getName());\r
+                    }\r
+                }\r
+                \r
+                if (i == (sequencedResourceAssignments.size() - 1)) {\r
+                    logger.trace("Created old Set ({})", batchAssignmentName);\r
+                    sequenceBatchResourceAssignment.add(batchResourceAssignment);\r
+                }\r
+            }\r
+            logger.info("Batched Sequence : ({})", sequenceBatchResourceAssignment);\r
+        }\r
+        return sequenceBatchResourceAssignment;\r
+    }\r
+    \r
+}\r
diff --git a/blueprints-processor/plugin/assignment-provider/src/main/java/org/onap/ccsdk/config/assignment/service/ConfigAssignmentPersistService.java b/blueprints-processor/plugin/assignment-provider/src/main/java/org/onap/ccsdk/config/assignment/service/ConfigAssignmentPersistService.java
new file mode 100644 (file)
index 0000000..e27d57a
--- /dev/null
@@ -0,0 +1,120 @@
+/*\r
+ * Copyright © 2017-2018 AT&T Intellectual Property.\r
+ * \r
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except\r
+ * in compliance with the License. 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 distributed under the License\r
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express\r
+ * or implied. See the License for the specific language governing permissions and limitations under\r
+ * the License.\r
+ */\r
+\r
+package org.onap.ccsdk.config.assignment.service;\r
+\r
+import java.util.List;\r
+import org.apache.commons.collections.CollectionUtils;\r
+import org.apache.commons.lang3.StringUtils;\r
+import org.onap.ccsdk.config.data.adaptor.DataAdaptorConstants;\r
+import org.onap.ccsdk.config.data.adaptor.domain.ConfigResource;\r
+import org.onap.ccsdk.config.data.adaptor.domain.ResourceAssignmentData;\r
+import org.onap.ccsdk.config.data.adaptor.domain.TransactionLog;\r
+import org.onap.ccsdk.config.data.adaptor.service.ConfigResourceService;\r
+import org.onap.ccsdk.config.model.ConfigModelConstant;\r
+import org.onap.ccsdk.config.model.data.ResourceAssignment;\r
+import org.onap.ccsdk.config.model.utils.ResourceAssignmentUtils;\r
+import org.onap.ccsdk.config.model.utils.TransformationUtils;\r
+import org.onap.ccsdk.sli.core.sli.SvcLogicException;\r
+import com.att.eelf.configuration.EELFLogger;\r
+import com.att.eelf.configuration.EELFManager;\r
+\r
+public class ConfigAssignmentPersistService {\r
+    \r
+    private static EELFLogger logger = EELFManager.getInstance().getLogger(ConfigAssignmentPersistService.class);\r
+    \r
+    private ConfigResourceService configResourceService;\r
+    \r
+    public ConfigAssignmentPersistService(ConfigResourceService configResourceService) {\r
+        this.configResourceService = configResourceService;\r
+    }\r
+    \r
+    public void saveResourceMapping(org.onap.ccsdk.config.assignment.data.ResourceAssignmentData resourceAssignmentData,\r
+            String templateName, List<ResourceAssignment> resourceAssignments) throws SvcLogicException {\r
+        try {\r
+            \r
+            if (resourceAssignmentData == null) {\r
+                throw new SvcLogicException("Resource assignment data is missing");\r
+            }\r
+            \r
+            if (StringUtils.isBlank(resourceAssignmentData.getRequestId())) {\r
+                logger.warn("Request Id ({}) is missing, may be getting request for resource update.",\r
+                        resourceAssignmentData.getRequestId());\r
+            }\r
+            \r
+            if (StringUtils.isBlank(resourceAssignmentData.getResourceId())) {\r
+                throw new SvcLogicException("Resource Id is missing");\r
+            }\r
+            \r
+            if (StringUtils.isBlank(resourceAssignmentData.getResourceType())) {\r
+                throw new SvcLogicException("Resource type is missing");\r
+            }\r
+            \r
+            if (StringUtils.isBlank(resourceAssignmentData.getActionName())) {\r
+                throw new SvcLogicException("Action name is missing");\r
+            }\r
+            \r
+            if (StringUtils.isBlank(templateName)) {\r
+                throw new SvcLogicException("template name is missing");\r
+            }\r
+            \r
+            StringBuilder builder = new StringBuilder();\r
+            builder.append("Resource Assignment for Template Name :");\r
+            builder.append(templateName);\r
+            builder.append("\n");\r
+            builder.append(TransformationUtils.getJson(resourceAssignments, true));\r
+            \r
+            configResourceService.save(new TransactionLog(resourceAssignmentData.getRequestId(),\r
+                    DataAdaptorConstants.LOG_MESSAGE_TYPE_LOG, builder.toString()));\r
+            \r
+            // Resource Data should be Regenerated based on the new Updates\r
+            String resourceData = ResourceAssignmentUtils.generateResourceDataForAssignments(resourceAssignments);\r
+            \r
+            List<ResourceAssignmentData> resourceAssignmentDataList =\r
+                    ConfigAssignmentUtils.convertResoureAssignmentList(resourceAssignments);\r
+            \r
+            ConfigResource configResource = new ConfigResource();\r
+            configResource.setRequestId(resourceAssignmentData.getRequestId());\r
+            configResource.setServiceTemplateName(resourceAssignmentData.getServiceTemplateName());\r
+            configResource.setServiceTemplateVersion(resourceAssignmentData.getServiceTemplateVersion());\r
+            configResource.setRecipeName(resourceAssignmentData.getActionName());\r
+            configResource.setResourceId(resourceAssignmentData.getResourceId());\r
+            configResource.setResourceType(resourceAssignmentData.getResourceType());\r
+            configResource.setResourceData(resourceData);\r
+            configResource.setTemplateName(templateName);\r
+            configResource.setStatus(ConfigModelConstant.STATUS_SUCCESS);\r
+            configResource.setUpdatedBy(ConfigModelConstant.USER_SYSTEM);\r
+            \r
+            if (CollectionUtils.isNotEmpty(resourceAssignmentDataList)) {\r
+                configResource.setResourceAssignments(resourceAssignmentDataList);\r
+            }\r
+            configResource = configResourceService.saveConfigResource(configResource);\r
+            logger.info("Resource data saved successfully for the template ({}) with resource id ({})", templateName,\r
+                    configResource.getResourceId());\r
+            \r
+            builder = new StringBuilder();\r
+            builder.append("Resource Data Template Name :");\r
+            builder.append(templateName);\r
+            builder.append("\n");\r
+            builder.append(resourceData);\r
+            configResourceService.save(new TransactionLog(resourceAssignmentData.getRequestId(),\r
+                    DataAdaptorConstants.LOG_MESSAGE_TYPE_LOG, builder.toString()));\r
+            \r
+        } catch (Exception e) {\r
+            throw new SvcLogicException("ConfigAssignmentPersistService : " + e.getMessage(), e);\r
+        }\r
+        \r
+    }\r
+    \r
+}\r
diff --git a/blueprints-processor/plugin/assignment-provider/src/main/java/org/onap/ccsdk/config/assignment/service/ConfigAssignmentProcessService.java b/blueprints-processor/plugin/assignment-provider/src/main/java/org/onap/ccsdk/config/assignment/service/ConfigAssignmentProcessService.java
new file mode 100644 (file)
index 0000000..81e7689
--- /dev/null
@@ -0,0 +1,235 @@
+/*\r
+ * Copyright © 2017-2018 AT&T Intellectual Property.\r
+ * \r
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except\r
+ * in compliance with the License. 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 distributed under the License\r
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express\r
+ * or implied. See the License for the specific language governing permissions and limitations under\r
+ * the License.\r
+ */\r
+\r
+package org.onap.ccsdk.config.assignment.service;\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.lang3.StringUtils;\r
+import org.onap.ccsdk.config.assignment.ConfigAssignmentConstants;\r
+import org.onap.ccsdk.config.assignment.data.ResourceAssignmentData;\r
+import org.onap.ccsdk.config.assignment.processor.ProcessorFactory;\r
+import org.onap.ccsdk.config.assignment.processor.ResourceAssignmentProcessor;\r
+import org.onap.ccsdk.config.data.adaptor.service.ConfigResourceService;\r
+import org.onap.ccsdk.config.generator.service.ConfigGeneratorService;\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.service.ComponentNode;\r
+import org.onap.ccsdk.config.model.service.ComponentNodeService;\r
+import org.onap.ccsdk.config.model.service.ConfigModelService;\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.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
+\r
+public class ConfigAssignmentProcessService {\r
+    \r
+    private static EELFLogger logger = EELFManager.getInstance().getLogger(ConfigAssignmentProcessService.class);\r
+    \r
+    private ComponentNodeService componentNodeService;\r
+    private ConfigResourceService configResourceService;\r
+    private ConfigModelService configModelService;\r
+    private ConfigRestAdaptorService configRestAdaptorService;\r
+    private ConfigGeneratorService configGeneratorService;\r
+    \r
+    public ConfigAssignmentProcessService(ConfigResourceService configResourceService,\r
+            ConfigRestAdaptorService configRestAdaptorService, ConfigModelService configModelService,\r
+            ComponentNodeService componentNodeService, ConfigGeneratorService configGeneratorService) {\r
+        this.componentNodeService = componentNodeService;\r
+        this.configResourceService = configResourceService;\r
+        this.configModelService = configModelService;\r
+        this.configRestAdaptorService = configRestAdaptorService;\r
+        this.configGeneratorService = configGeneratorService;\r
+    }\r
+    \r
+    @SuppressWarnings("squid:S1141")\r
+    public void resolveResources(ResourceAssignmentData resourceAssignmentData) throws SvcLogicException {\r
+        try {\r
+            validateInputParams(resourceAssignmentData);\r
+            \r
+            String serviceTemplateName = resourceAssignmentData.getServiceTemplateName();\r
+            String serviceTemplateVersion = resourceAssignmentData.getServiceTemplateVersion();\r
+            String actionName = resourceAssignmentData.getActionName();\r
+            String inputData = resourceAssignmentData.getInputData();\r
+            SvcLogicContext svcLogicContext = resourceAssignmentData.getSvcLogicContext();\r
+            List<String> templateNames = resourceAssignmentData.getTemplateNames();\r
+            \r
+            if (resourceAssignmentData.isReloadModel()) {\r
+                Map<String, String> context = new HashMap<>();\r
+                context.put(ConfigModelConstant.PROPERTY_ACTION_NAME, actionName);\r
+                context = configModelService.prepareContext(context, inputData, serviceTemplateName,\r
+                        serviceTemplateVersion);\r
+                context.forEach((key, value) -> svcLogicContext.setAttribute(key, value));\r
+                logger.info("List of Resources provided in input: {}", svcLogicContext.toProperties());\r
+            }\r
+            \r
+            Map<String, Object> componentContext = resourceAssignmentData.getContext();\r
+            \r
+            if (CollectionUtils.isNotEmpty(templateNames)) {\r
+                // Get the Resource Assignments for templates and Validate the mappings\r
+                ResourceModelService resourceModelService = new ResourceModelService(configModelService);\r
+                \r
+                // Get the Resource Assignment\r
+                Map<String, List<ResourceAssignment>> templatesResourceAssignments =\r
+                        resourceModelService.getTemplatesResourceAssignments(svcLogicContext, templateNames);\r
+                \r
+                // Get the Template Contents\r
+                Map<String, String> templatesContents =\r
+                        resourceModelService.getTemplatesContents(svcLogicContext, templateNames);\r
+                \r
+                // Process each template\r
+                for (String templateName : templateNames) {\r
+                    List<ResourceAssignment> resourceAssignments = templatesResourceAssignments.get(templateName);\r
+                    String templateContent = templatesContents.get(templateName);\r
+                    if (resourceAssignments != null) {\r
+                        String templateData = null;\r
+                        try {\r
+                            // Populate the Dictionary\r
+                            ResourceDictionaryService resourceDictionaryService =\r
+                                    new ResourceDictionaryService(configRestAdaptorService);\r
+                            Map<String, ResourceDefinition> dictionaries =\r
+                                    resourceDictionaryService.getDataDictionaryDefinitions(resourceAssignments);\r
+                            \r
+                            processResourceAssignments(resourceAssignmentData, svcLogicContext, componentContext,\r
+                                    templateName, resourceAssignments, dictionaries);\r
+                            \r
+                            logger.info("decrypting config data for templateName {}", templateName);\r
+                            templateData =\r
+                                    ResourceAssignmentUtils.generateResourceDataForAssignments(resourceAssignments);\r
+                        } finally {\r
+                            saveResourceMapping(resourceAssignmentData, templateName, resourceAssignments);\r
+                        }\r
+                        \r
+                        logger.info("generating config preview for templateName {}", templateName);\r
+                        ConfigPreviewService configPreviewService = new ConfigPreviewService(configResourceService,\r
+                                configModelService, configGeneratorService);\r
+                        String mashedData = configPreviewService.generatePreview(templateContent, templateData);\r
+                        resourceAssignmentData.getTemplatesMashedContents().put(templateName, mashedData);\r
+                        resourceAssignmentData.getTemplatesData().put(templateName, templateData);\r
+                        \r
+                    } else {\r
+                        // Do nothing for Mapping not found\r
+                        logger.warn("No resource Assignment mappings to resolve for templateName {}", templateName);\r
+                    }\r
+                }\r
+            }\r
+            \r
+        } catch (Exception e) {\r
+            throw new SvcLogicException(e.getMessage(), e);\r
+        }\r
+    }\r
+    \r
+    private void processResourceAssignments(ResourceAssignmentData resourceAssignmentData, SvcLogicContext ctx,\r
+            Map<String, Object> componentContext, String templateName, List<ResourceAssignment> resourceAssignments,\r
+            Map<String, ResourceDefinition> dictionaries) throws SvcLogicException {\r
+        \r
+        String recipeName = resourceAssignmentData.getActionName();\r
+        \r
+        ResourceAssignmentProcessor resourceAssignmentProcessor =\r
+                new ResourceAssignmentProcessor(resourceAssignments, ctx);\r
+        List<List<ResourceAssignment>> sequenceBatchResourceAssignment = resourceAssignmentProcessor.process();\r
+        \r
+        logger.debug("Resource dictionary Info  ({})", dictionaries);\r
+        \r
+        if (sequenceBatchResourceAssignment != null) {\r
+            componentContext.put(ConfigModelConstant.PROPERTY_ACTION_NAME, recipeName);\r
+            componentContext.put(ConfigModelConstant.PROPERTY_TEMPLATE_NAME, templateName);\r
+            componentContext.put(ConfigModelConstant.PROPERTY_DICTIONARIES, dictionaries);\r
+            for (List<ResourceAssignment> batchResourceAssignment : sequenceBatchResourceAssignment) {\r
+                \r
+                processBatchResourceAssignments(resourceAssignmentData, ctx, componentContext, batchResourceAssignment);\r
+                \r
+                logger.debug("Batch Resource data status ({})", TransformationUtils.getJson(batchResourceAssignment));\r
+            }\r
+        }\r
+    }\r
+    \r
+    private void processBatchResourceAssignments(ResourceAssignmentData resourceAssignmentData, SvcLogicContext ctx,\r
+            Map<String, Object> componentContext, List<ResourceAssignment> batchResourceAssignment)\r
+            throws SvcLogicException {\r
+        \r
+        if (CollectionUtils.isNotEmpty(batchResourceAssignment)) {\r
+            \r
+            ResourceAssignment batchFirstResourceAssignment = batchResourceAssignment.get(0);\r
+            if (batchFirstResourceAssignment != null\r
+                    && StringUtils.isNotBlank(batchFirstResourceAssignment.getDictionarySource())) {\r
+                String source = batchFirstResourceAssignment.getDictionarySource();\r
+                // Processing their Source\r
+                logger.info("Processing source ({})  with batch ({}) ", source, batchResourceAssignment);\r
+                componentContext.put(ConfigModelConstant.PROPERTY_RESOURCE_ASSIGNMENTS, batchResourceAssignment);\r
+                \r
+                ProcessorFactory factory =\r
+                        new ProcessorFactory(configResourceService, configRestAdaptorService, componentNodeService);\r
+                \r
+                ComponentNode processor = factory.getInstance(source);\r
+                \r
+                Map<String, String> inParams = new HashMap<>();\r
+                inParams.put(ConfigAssignmentConstants.INPUT_PARAM_REQUEST_ID, resourceAssignmentData.getRequestId());\r
+                inParams.put(ConfigAssignmentConstants.INPUT_PARAM_RESOURCE_ID, resourceAssignmentData.getResourceId());\r
+                inParams.put(ConfigAssignmentConstants.INPUT_PARAM_RESOURCE_TYPE,\r
+                        resourceAssignmentData.getResourceType());\r
+                inParams.put(ConfigAssignmentConstants.INPUT_PARAM_ACTION_NAME, resourceAssignmentData.getActionName());\r
+                inParams.put(ConfigAssignmentConstants.INPUT_PARAM_TEMPLATE_NAMES,\r
+                        resourceAssignmentData.getTemplateNames().toString());\r
+                processor.process(inParams, ctx, componentContext);\r
+            }\r
+        }\r
+    }\r
+    \r
+    private void saveResourceMapping(ResourceAssignmentData resourceAssignmentData, String templateName,\r
+            List<ResourceAssignment> resourceAssignments) throws SvcLogicException {\r
+        if (resourceAssignmentData != null && StringUtils.isNotBlank(templateName)) {\r
+            \r
+            ConfigAssignmentPersistService configAssignmentPersistService =\r
+                    new ConfigAssignmentPersistService(configResourceService);\r
+            configAssignmentPersistService.saveResourceMapping(resourceAssignmentData, templateName,\r
+                    resourceAssignments);\r
+        }\r
+    }\r
+    \r
+    private void validateInputParams(ResourceAssignmentData resourceAssignmentData) throws SvcLogicException {\r
+        if (resourceAssignmentData == null) {\r
+            throw new SvcLogicException("Input parameters missing");\r
+        }\r
+        \r
+        String requestId = resourceAssignmentData.getRequestId();\r
+        if (StringUtils.isBlank(requestId)) {\r
+            throw new SvcLogicException("Request id parameters missing");\r
+        }\r
+        String resourceId = resourceAssignmentData.getResourceId();\r
+        if (StringUtils.isBlank(resourceId)) {\r
+            throw new SvcLogicException("Resource id parameter is missing");\r
+        }\r
+        String resourceType = resourceAssignmentData.getResourceType();\r
+        if (StringUtils.isBlank(resourceType)) {\r
+            throw new SvcLogicException("Resource type parameter is missing");\r
+        }\r
+        String actionName = resourceAssignmentData.getActionName();\r
+        if (StringUtils.isBlank(actionName)) {\r
+            throw new SvcLogicException("Action name is parameter is missing");\r
+        }\r
+        \r
+        List<String> templatesNames = resourceAssignmentData.getTemplateNames();\r
+        if (CollectionUtils.isEmpty(templatesNames)) {\r
+            throw new SvcLogicException("Template names parameter missing");\r
+        }\r
+    }\r
+    \r
+}\r
diff --git a/blueprints-processor/plugin/assignment-provider/src/main/java/org/onap/ccsdk/config/assignment/service/ConfigAssignmentService.java b/blueprints-processor/plugin/assignment-provider/src/main/java/org/onap/ccsdk/config/assignment/service/ConfigAssignmentService.java
new file mode 100644 (file)
index 0000000..e0fcc91
--- /dev/null
@@ -0,0 +1,32 @@
+/*\r
+ * Copyright © 2017-2018 AT&T Intellectual Property.\r
+ * \r
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except\r
+ * in compliance with the License. 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 distributed under the License\r
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express\r
+ * or implied. See the License for the specific language governing permissions and limitations under\r
+ * the License.\r
+ */\r
+\r
+package org.onap.ccsdk.config.assignment.service;\r
+\r
+import java.util.List;\r
+import org.onap.ccsdk.config.assignment.data.ResourceAssignmentData;\r
+import org.onap.ccsdk.config.model.data.ResourceAssignment;\r
+import org.onap.ccsdk.sli.core.sli.SvcLogicException;\r
+\r
+public interface ConfigAssignmentService {\r
+    \r
+    public void resolveResources(ResourceAssignmentData resourceAssignmentData) throws SvcLogicException;\r
+    \r
+    public void saveResourceMapping(ResourceAssignmentData resourceAssignmentData, String templateName,\r
+            List<ResourceAssignment> resourceAssignments) throws SvcLogicException;\r
+    \r
+    public ResourceAssignmentData generateTemplateResourceMash(ResourceAssignmentData resourceAssignmentData)\r
+            throws SvcLogicException;\r
+    \r
+}\r
diff --git a/blueprints-processor/plugin/assignment-provider/src/main/java/org/onap/ccsdk/config/assignment/service/ConfigAssignmentServiceImpl.java b/blueprints-processor/plugin/assignment-provider/src/main/java/org/onap/ccsdk/config/assignment/service/ConfigAssignmentServiceImpl.java
new file mode 100644 (file)
index 0000000..48e15b1
--- /dev/null
@@ -0,0 +1,76 @@
+/*\r
+ * Copyright © 2017-2018 AT&T Intellectual Property.\r
+ * \r
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except\r
+ * in compliance with the License. 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 distributed under the License\r
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express\r
+ * or implied. See the License for the specific language governing permissions and limitations under\r
+ * the License.\r
+ */\r
+\r
+package org.onap.ccsdk.config.assignment.service;\r
+\r
+import java.util.List;\r
+import org.onap.ccsdk.config.assignment.data.ResourceAssignmentData;\r
+import org.onap.ccsdk.config.data.adaptor.service.ConfigResourceService;\r
+import org.onap.ccsdk.config.generator.service.ConfigGeneratorService;\r
+import org.onap.ccsdk.config.model.data.ResourceAssignment;\r
+import org.onap.ccsdk.config.model.service.ComponentNodeService;\r
+import org.onap.ccsdk.config.model.service.ConfigModelService;\r
+import org.onap.ccsdk.config.rest.adaptor.service.ConfigRestAdaptorService;\r
+import org.onap.ccsdk.sli.core.sli.SvcLogicException;\r
+import com.att.eelf.configuration.EELFLogger;\r
+import com.att.eelf.configuration.EELFManager;\r
+\r
+public class ConfigAssignmentServiceImpl implements ConfigAssignmentService {\r
+    \r
+    private static EELFLogger logger = EELFManager.getInstance().getLogger(ConfigAssignmentServiceImpl.class);\r
+    \r
+    private ComponentNodeService componentNodeService;\r
+    private ConfigResourceService configResourceService;\r
+    private ConfigModelService configModelService;\r
+    private ConfigRestAdaptorService configRestAdaptorService;\r
+    private ConfigGeneratorService configGeneratorService;\r
+    \r
+    private static final String CLASS_NAME = "ConfigAssignmentServiceImpl";\r
+    \r
+    public ConfigAssignmentServiceImpl(ConfigResourceService configResourceService,\r
+            ConfigRestAdaptorService configRestAdaptorService, ConfigModelService configModelService,\r
+            ComponentNodeService componentNodeService, ConfigGeneratorService configGeneratorService) {\r
+        logger.info("{} Constuctor Initated...", CLASS_NAME);\r
+        this.componentNodeService = componentNodeService;\r
+        this.configResourceService = configResourceService;\r
+        this.configModelService = configModelService;\r
+        this.configRestAdaptorService = configRestAdaptorService;\r
+        this.configGeneratorService = configGeneratorService;\r
+    }\r
+    \r
+    @Override\r
+    public void resolveResources(ResourceAssignmentData resourceAssignmentData) throws SvcLogicException {\r
+        ConfigAssignmentProcessService configAssignmentProcessService =\r
+                new ConfigAssignmentProcessService(configResourceService, configRestAdaptorService, configModelService,\r
+                        componentNodeService, configGeneratorService);\r
+        configAssignmentProcessService.resolveResources(resourceAssignmentData);\r
+    }\r
+    \r
+    @Override\r
+    public void saveResourceMapping(ResourceAssignmentData resourceAssignmentData, String templateName,\r
+            List<ResourceAssignment> resourceAssignments) throws SvcLogicException {\r
+        ConfigAssignmentPersistService configAssignmentPersistService =\r
+                new ConfigAssignmentPersistService(configResourceService);\r
+        configAssignmentPersistService.saveResourceMapping(resourceAssignmentData, templateName, resourceAssignments);\r
+    }\r
+    \r
+    @Override\r
+    public ResourceAssignmentData generateTemplateResourceMash(ResourceAssignmentData resourceAssignmentData)\r
+            throws SvcLogicException {\r
+        ConfigPreviewService configPreviewService =\r
+                new ConfigPreviewService(configResourceService, configModelService, configGeneratorService);\r
+        return configPreviewService.generateTemplateResourceMash(resourceAssignmentData);\r
+    }\r
+    \r
+}\r
diff --git a/blueprints-processor/plugin/assignment-provider/src/main/java/org/onap/ccsdk/config/assignment/service/ConfigAssignmentUtils.java b/blueprints-processor/plugin/assignment-provider/src/main/java/org/onap/ccsdk/config/assignment/service/ConfigAssignmentUtils.java
new file mode 100644 (file)
index 0000000..1f74b71
--- /dev/null
@@ -0,0 +1,302 @@
+/*\r
+ * Copyright © 2017-2018 AT&T Intellectual Property.\r
+ * \r
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except\r
+ * in compliance with the License. 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 distributed under the License\r
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express\r
+ * or implied. See the License for the specific language governing permissions and limitations under\r
+ * the License.\r
+ */\r
+\r
+package org.onap.ccsdk.config.assignment.service;\r
+\r
+import java.util.ArrayList;\r
+import java.util.List;\r
+import java.util.Map;\r
+import org.apache.commons.collections.CollectionUtils;\r
+import org.apache.commons.collections.IteratorUtils;\r
+import org.apache.commons.collections.MapUtils;\r
+import org.apache.commons.lang3.StringUtils;\r
+import org.onap.ccsdk.config.data.adaptor.domain.ResourceAssignmentData;\r
+import org.onap.ccsdk.config.model.ConfigModelConstant;\r
+import org.onap.ccsdk.config.model.ConfigModelException;\r
+import org.onap.ccsdk.config.model.ValidTypes;\r
+import org.onap.ccsdk.config.model.data.DataType;\r
+import org.onap.ccsdk.config.model.data.EntrySchema;\r
+import org.onap.ccsdk.config.model.data.PropertyDefinition;\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.domain.ResourceDictionary;\r
+import org.onap.ccsdk.config.model.utils.JsonUtils;\r
+import org.onap.ccsdk.config.model.utils.ResourceAssignmentUtils;\r
+import org.onap.ccsdk.config.model.utils.TransformationUtils;\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
+import com.fasterxml.jackson.databind.node.ArrayNode;\r
+import com.fasterxml.jackson.databind.node.JsonNodeFactory;\r
+import com.fasterxml.jackson.databind.node.ObjectNode;\r
+\r
+public class ConfigAssignmentUtils {\r
+    \r
+    private ConfigAssignmentUtils() {\r
+        \r
+    }\r
+    \r
+    private static EELFLogger logger = EELFManager.getInstance().getLogger(ConfigAssignmentUtils.class);\r
+    \r
+    public static synchronized Object getContextKeyValue(SvcLogicContext context, String key) {\r
+        Object value = null;\r
+        if (context != null && key != null) {\r
+            if (context.getAttributeKeySet().contains(key)) {\r
+                String strValue = context.getAttribute(key);\r
+                if (StringUtils.isNotBlank(strValue)) {\r
+                    value = strValue;\r
+                }\r
+            } else {\r
+                // Do Nothing\r
+            }\r
+        }\r
+        return value;\r
+    }\r
+    \r
+    /*\r
+     * Populate the Field property type for the Data type\r
+     */\r
+    public static synchronized String getPropertyType(SvcLogicContext ctx, String dataTypeName, String propertyName)\r
+            throws SvcLogicException {\r
+        String type = ValidTypes.DATA_TYPE_STRING;\r
+        try {\r
+            if (ctx != null && StringUtils.isNotBlank(dataTypeName) && StringUtils.isNotBlank(propertyName)) {\r
+                String dataTypeContent = ctx.getAttribute(ConfigModelConstant.PROPERTY_DATA_TYPES_DOT + dataTypeName);\r
+                if (StringUtils.isNotBlank(dataTypeContent)) {\r
+                    DataType dataType = TransformationUtils.readValue(dataTypeContent, DataType.class);\r
+                    if (dataType != null && dataType.getProperties() != null\r
+                            && dataType.getProperties().containsKey(propertyName)) {\r
+                        PropertyDefinition propertyDefinition = dataType.getProperties().get(propertyName);\r
+                        if (StringUtils.isNotBlank(propertyDefinition.getType())) {\r
+                            type = propertyDefinition.getType();\r
+                            logger.trace("Data type({})'s property ({}) is ({})", dataTypeName, propertyName, type);\r
+                        } else {\r
+                            throw new SvcLogicException(String.format("Couldn't get data type (%s) ", dataTypeName));\r
+                        }\r
+                    }\r
+                } else {\r
+                    throw new SvcLogicException(String.format("Couldn't get data type (%s) content", dataTypeName));\r
+                }\r
+            }\r
+        } catch (Exception e) {\r
+            logger.error("couldn't get data type({})'s property ({}), type ({}), error message ({}).", dataTypeName,\r
+                    propertyName, type, e.getMessage());\r
+            throw new SvcLogicException(e.getMessage());\r
+        }\r
+        return type;\r
+    }\r
+    \r
+    /*\r
+     * Populate the Field property type for the Data type\r
+     */\r
+    public static synchronized PropertyDefinition getPropertyDefinition(SvcLogicContext ctx, String dataTypeName,\r
+            String propertyName) throws SvcLogicException {\r
+        PropertyDefinition propertyDefinition = null;\r
+        try {\r
+            if (ctx != null && StringUtils.isNotBlank(dataTypeName) && StringUtils.isNotBlank(propertyName)) {\r
+                String dataTypeContent = ctx.getAttribute(ConfigModelConstant.PROPERTY_DATA_TYPES_DOT + dataTypeName);\r
+                if (StringUtils.isNotBlank(dataTypeContent)) {\r
+                    DataType dataType = TransformationUtils.readValue(dataTypeContent, DataType.class);\r
+                    if (dataType != null && dataType.getProperties() != null\r
+                            && dataType.getProperties().containsKey(propertyName)) {\r
+                        propertyDefinition = dataType.getProperties().get(propertyName);\r
+                        if (propertyDefinition == null) {\r
+                            throw new SvcLogicException(String.format("couldn't get data type (%s) ", dataTypeName));\r
+                        }\r
+                    }\r
+                } else {\r
+                    throw new SvcLogicException(String.format("couldn't get data type (%s) content.", dataTypeName));\r
+                }\r
+            }\r
+        } catch (Exception e) {\r
+            throw new SvcLogicException(e.getMessage());\r
+        }\r
+        return propertyDefinition;\r
+    }\r
+    \r
+    public static synchronized ResourceDefinition getDictionaryDefinition(Map<String, ResourceDictionary> dictionaries,\r
+            String dictionaryName) {\r
+        ResourceDefinition resourceDefinition = null;\r
+        if (dictionaries != null && StringUtils.isNotBlank(dictionaryName)) {\r
+            ResourceDictionary resourceDictionary = dictionaries.get(dictionaryName);\r
+            if (resourceDictionary != null && StringUtils.isNotBlank(resourceDictionary.getDefinition())) {\r
+                resourceDefinition =\r
+                        TransformationUtils.readValue(resourceDictionary.getDefinition(), ResourceDefinition.class);\r
+            }\r
+        }\r
+        return resourceDefinition;\r
+    }\r
+    \r
+    @SuppressWarnings("squid:S3776")\r
+    public static synchronized void populateValueForOutputMapping(SvcLogicContext ctx,\r
+            Map<String, Object> componentContext, ResourceAssignment resourceAssignment,\r
+            Map<String, String> outputKeyMapping, JsonNode responseNode)\r
+            throws ConfigModelException, SvcLogicException {\r
+        if (resourceAssignment == null) {\r
+            throw new SvcLogicException("resourceAssignment is null.");\r
+        }\r
+        \r
+        if (ctx == null) {\r
+            throw new SvcLogicException("service logic context is null.");\r
+        }\r
+        \r
+        if (componentContext == null) {\r
+            throw new SvcLogicException("component context is null.");\r
+        }\r
+        \r
+        logger.info("populating value for output mapping ({}), from json ({})", outputKeyMapping, responseNode);\r
+        String dictionaryName = resourceAssignment.getDictionaryName();\r
+        String type = resourceAssignment.getProperty().getType();\r
+        \r
+        String entrySchema = null;\r
+        if (ValidTypes.getPrimitivePropertType().contains(type)) {\r
+            ResourceAssignmentUtils.setResourceDataValue(componentContext, resourceAssignment, responseNode);\r
+        } else if (ValidTypes.getListPropertType().contains(type)) {\r
+            // Array Types\r
+            if (resourceAssignment.getProperty().getEntrySchema() != null) {\r
+                entrySchema = resourceAssignment.getProperty().getEntrySchema().getType();\r
+            }\r
+            \r
+            if (StringUtils.isNotBlank(entrySchema)) {\r
+                ArrayNode arrayNode = JsonNodeFactory.instance.arrayNode();\r
+                if (ValidTypes.getPrimitivePropertType().contains(entrySchema)) {\r
+                    arrayNode = (ArrayNode) responseNode;\r
+                } else if (MapUtils.isNotEmpty(outputKeyMapping)) {\r
+                    List<JsonNode> responseArrayNode = IteratorUtils.toList(responseNode.elements());\r
+                    for (JsonNode responseSingleJsonNode : responseArrayNode) {\r
+                        if (responseSingleJsonNode != null) {\r
+                            ObjectNode arrayChildNode = JsonNodeFactory.instance.objectNode();\r
+                            for (Map.Entry<String, String> mapping : outputKeyMapping.entrySet()) {\r
+                                JsonNode responseKeyValue = responseSingleJsonNode.get(mapping.getKey());\r
+                                \r
+                                String propertyTypeForDataType =\r
+                                        ConfigAssignmentUtils.getPropertyType(ctx, entrySchema, mapping.getKey());\r
+                                logger.info("For List Type Resource: key ({}), value ({}), type  ({})",\r
+                                        mapping.getKey(), responseKeyValue, propertyTypeForDataType);\r
+                                JsonUtils.populateJsonNodeValues(mapping.getValue(), responseKeyValue,\r
+                                        propertyTypeForDataType, arrayChildNode);\r
+                            }\r
+                            arrayNode.add(arrayChildNode);\r
+                        }\r
+                    }\r
+                } else {\r
+                    arrayNode = (ArrayNode) responseNode;\r
+                }\r
+                // Set the List of Complex Values\r
+                ResourceAssignmentUtils.setResourceDataValue(componentContext, resourceAssignment, arrayNode);\r
+            } else {\r
+                throw new SvcLogicException(\r
+                        String.format("Entry schema is not defined for dictionary (%s) info", dictionaryName));\r
+            }\r
+        } else {\r
+            // Complex Types\r
+            ObjectNode objectNode = null;\r
+            if (MapUtils.isNotEmpty(outputKeyMapping)) {\r
+                objectNode = JsonNodeFactory.instance.objectNode();\r
+                for (Map.Entry<String, String> mapping : outputKeyMapping.entrySet()) {\r
+                    JsonNode responseKeyValue = responseNode.get(mapping.getKey());\r
+                    String propertyTypeForDataType =\r
+                            ConfigAssignmentUtils.getPropertyType(ctx, entrySchema, mapping.getKey());\r
+                    logger.info("For Complex Type Resource: key ({}), value ({}), type  ({})", mapping.getKey(),\r
+                            responseKeyValue, propertyTypeForDataType);\r
+                    JsonUtils.populateJsonNodeValues(mapping.getValue(), responseKeyValue, propertyTypeForDataType,\r
+                            objectNode);\r
+                }\r
+            } else {\r
+                objectNode = (ObjectNode) responseNode;\r
+            }\r
+            ResourceAssignmentUtils.setResourceDataValue(componentContext, resourceAssignment, objectNode);\r
+        }\r
+    }\r
+    \r
+    @SuppressWarnings("squid:S3776")\r
+    public static synchronized List<ResourceAssignment> convertResoureAssignmentDataList(\r
+            List<ResourceAssignmentData> resourceAssignmentDataList) {\r
+        List<ResourceAssignment> assignments = new ArrayList<>();\r
+        if (CollectionUtils.isNotEmpty(resourceAssignmentDataList)) {\r
+            for (ResourceAssignmentData resourceAssignmentData : resourceAssignmentDataList) {\r
+                if (resourceAssignmentData != null) {\r
+                    ResourceAssignment resourceAssignment = new ResourceAssignment();\r
+                    resourceAssignment.setName(resourceAssignmentData.getTemplateKeyName());\r
+                    resourceAssignment.setVersion(resourceAssignmentData.getVersion());\r
+                    resourceAssignment.setUpdatedBy(resourceAssignmentData.getUpdatedBy());\r
+                    resourceAssignment.setUpdatedDate(resourceAssignmentData.getUpdatedDate());\r
+                    resourceAssignment.setDictionaryName(resourceAssignmentData.getResourceName());\r
+                    resourceAssignment.setDictionarySource(resourceAssignmentData.getSource());\r
+                    resourceAssignment.setStatus(resourceAssignmentData.getStatus());\r
+                    resourceAssignment.setMessage(resourceAssignmentData.getMessage());\r
+                    PropertyDefinition property = new PropertyDefinition();\r
+                    property.setType(resourceAssignmentData.getDataType());\r
+                    \r
+                    if (StringUtils.isNotBlank(resourceAssignmentData.getResourceValue())) {\r
+                        if (ValidTypes.getPrimitivePropertType().contains(resourceAssignmentData.getDataType())) {\r
+                            property.setValue(resourceAssignmentData.getResourceValue());\r
+                        } else {\r
+                            JsonNode valueNode =\r
+                                    TransformationUtils.getJsonNodeForString(resourceAssignmentData.getResourceValue());\r
+                            property.setValue(valueNode);\r
+                        }\r
+                    }\r
+                    if (StringUtils.isNotBlank(resourceAssignmentData.getEntrySchema())) {\r
+                        EntrySchema entrySchema = new EntrySchema();\r
+                        entrySchema.setType(resourceAssignmentData.getEntrySchema());\r
+                        property.setEntrySchema(entrySchema);\r
+                    } else {\r
+                        property.setEntrySchema(null);\r
+                    }\r
+                    resourceAssignment.setProperty(property);\r
+                    assignments.add(resourceAssignment);\r
+                }\r
+            }\r
+            \r
+        }\r
+        return assignments;\r
+    }\r
+    \r
+    @SuppressWarnings("squid:S3776")\r
+    public static synchronized List<ResourceAssignmentData> convertResoureAssignmentList(\r
+            List<ResourceAssignment> assignments) {\r
+        List<ResourceAssignmentData> resourceAssignmentDataList = new ArrayList<>();\r
+        if (CollectionUtils.isNotEmpty(assignments)) {\r
+            for (ResourceAssignment assignment : assignments) {\r
+                if (assignment != null) {\r
+                    ResourceAssignmentData resourceAssignmentData = new ResourceAssignmentData();\r
+                    resourceAssignmentData.setTemplateKeyName(assignment.getName());\r
+                    resourceAssignmentData.setVersion(assignment.getVersion());\r
+                    resourceAssignmentData.setUpdatedBy(assignment.getUpdatedBy());\r
+                    resourceAssignmentData.setUpdatedDate(assignment.getUpdatedDate());\r
+                    if (assignment.getProperty() != null) {\r
+                        resourceAssignmentData.setDataType(assignment.getProperty().getType());\r
+                        if (assignment.getProperty().getEntrySchema() != null) {\r
+                            resourceAssignmentData.setEntrySchema(assignment.getProperty().getEntrySchema().getType());\r
+                        }\r
+                        if (assignment.getProperty().getValue() != null) {\r
+                            String valueContent = TransformationUtils.getJson(assignment.getProperty().getValue());\r
+                            resourceAssignmentData.setResourceValue(valueContent);\r
+                        }\r
+                    }\r
+                    resourceAssignmentData.setResourceName(assignment.getDictionaryName());\r
+                    resourceAssignmentData.setSource(assignment.getDictionarySource());\r
+                    resourceAssignmentData.setStatus(assignment.getStatus());\r
+                    resourceAssignmentData.setMessage(assignment.getMessage());\r
+                    resourceAssignmentDataList.add(resourceAssignmentData);\r
+                }\r
+            }\r
+        }\r
+        return resourceAssignmentDataList;\r
+    }\r
+    \r
+}\r
diff --git a/blueprints-processor/plugin/assignment-provider/src/main/java/org/onap/ccsdk/config/assignment/service/ConfigPreviewService.java b/blueprints-processor/plugin/assignment-provider/src/main/java/org/onap/ccsdk/config/assignment/service/ConfigPreviewService.java
new file mode 100644 (file)
index 0000000..7aa2d43
--- /dev/null
@@ -0,0 +1,116 @@
+/*\r
+ * Copyright © 2017-2018 AT&T Intellectual Property.\r
+ * \r
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except\r
+ * in compliance with the License. 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 distributed under the License\r
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express\r
+ * or implied. See the License for the specific language governing permissions and limitations under\r
+ * the License.\r
+ */\r
+\r
+package org.onap.ccsdk.config.assignment.service;\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.lang3.StringUtils;\r
+import org.onap.ccsdk.config.assignment.data.ResourceAssignmentData;\r
+import org.onap.ccsdk.config.data.adaptor.domain.ConfigResource;\r
+import org.onap.ccsdk.config.data.adaptor.service.ConfigResourceService;\r
+import org.onap.ccsdk.config.generator.data.ConfigGeneratorInfo;\r
+import org.onap.ccsdk.config.generator.service.ConfigGeneratorService;\r
+import org.onap.ccsdk.config.model.ConfigModelConstant;\r
+import org.onap.ccsdk.config.model.service.ConfigModelService;\r
+import org.onap.ccsdk.sli.core.sli.SvcLogicException;\r
+import com.att.eelf.configuration.EELFLogger;\r
+import com.att.eelf.configuration.EELFManager;\r
+\r
+public class ConfigPreviewService {\r
+    private static EELFLogger logger = EELFManager.getInstance().getLogger(ConfigAssignmentPersistService.class);\r
+    private ConfigResourceService configResourceService;\r
+    private ConfigModelService configModelService;\r
+    private ConfigGeneratorService configGeneratorService;\r
+    \r
+    public ConfigPreviewService(ConfigResourceService configResourceService, ConfigModelService configModelService,\r
+            ConfigGeneratorService configGeneratorService) {\r
+        this.configResourceService = configResourceService;\r
+        this.configModelService = configModelService;\r
+        this.configGeneratorService = configGeneratorService;\r
+    }\r
+    \r
+    public String generatePreview(String templateContent, String templateData) throws SvcLogicException {\r
+        String mashedData = "";\r
+        ConfigGeneratorInfo configGeneratorInfo =\r
+                configGeneratorService.generateConfiguration(templateContent, templateData);\r
+        if (configGeneratorInfo != null) {\r
+            mashedData = configGeneratorInfo.getMashedData();\r
+        }\r
+        return mashedData;\r
+    }\r
+    \r
+    public ResourceAssignmentData generateTemplateResourceMash(ResourceAssignmentData resourceAssignmentData)\r
+            throws SvcLogicException {\r
+        if (resourceAssignmentData == null) {\r
+            throw new SvcLogicException("Resource assignment data is missing");\r
+        }\r
+        if (StringUtils.isBlank(resourceAssignmentData.getServiceTemplateName())) {\r
+            throw new SvcLogicException("Service template name is missing");\r
+        }\r
+        if (StringUtils.isBlank(resourceAssignmentData.getServiceTemplateVersion())) {\r
+            throw new SvcLogicException("Service template version is missing");\r
+        }\r
+        if (StringUtils.isBlank(resourceAssignmentData.getResourceType())) {\r
+            throw new SvcLogicException("Resource type is missing");\r
+        }\r
+        if (StringUtils.isBlank(resourceAssignmentData.getResourceId())) {\r
+            throw new SvcLogicException("Resource Id is missing");\r
+        }\r
+        if (StringUtils.isBlank(resourceAssignmentData.getActionName())) {\r
+            throw new SvcLogicException("Action name is missing");\r
+        }\r
+        \r
+        String serviceTemplateName = resourceAssignmentData.getServiceTemplateName();\r
+        String serviceTemplateVersion = resourceAssignmentData.getServiceTemplateVersion();\r
+        String actionName = resourceAssignmentData.getActionName();\r
+        String resourceId = resourceAssignmentData.getResourceId();\r
+        String resourceType = resourceAssignmentData.getResourceType();\r
+        String inputData = "{}";\r
+        \r
+        Map<String, String> context = new HashMap<>();\r
+        context.put(ConfigModelConstant.PROPERTY_ACTION_NAME, actionName);\r
+        context = configModelService.prepareContext(context, inputData, serviceTemplateName, serviceTemplateVersion);\r
+        \r
+        ConfigResource configResourceQuery = new ConfigResource();\r
+        configResourceQuery.setServiceTemplateVersion(serviceTemplateName);\r
+        configResourceQuery.setServiceTemplateVersion(serviceTemplateVersion);\r
+        configResourceQuery.setRecipeName(actionName);\r
+        configResourceQuery.setResourceId(resourceId);\r
+        configResourceQuery.setResourceType(resourceType);\r
+        \r
+        List<ConfigResource> configResources = configResourceService.getConfigResource(configResourceQuery);\r
+        if (CollectionUtils.isNotEmpty(configResources)) {\r
+            for (ConfigResource cr : configResources) {\r
+                String templateContent = context\r
+                        .get(ConfigModelConstant.PROPERTY_NODE_TEMPLATES_DOT + cr.getTemplateName() + ".content");\r
+                String templateData = cr.getResourceData();\r
+                String previewContent = generatePreview(templateContent, templateData);\r
+                resourceAssignmentData.getTemplatesMashedContents().put(cr.getTemplateName(), previewContent);\r
+                logger.info("Preview generated for template name ({}) ", cr.getTemplateName());\r
+                logger.trace("Preview generated for preview ({}) ", previewContent);\r
+            }\r
+        } else {\r
+            logger.info(\r
+                    "Couldn't get config resource for service template name ({}) service template version ({})"\r
+                            + " action ({}) resource id ({}) resource type ({})",\r
+                    serviceTemplateName, serviceTemplateVersion, actionName, resourceId, resourceType);\r
+        }\r
+        return resourceAssignmentData;\r
+        \r
+    }\r
+    \r
+}\r
diff --git a/blueprints-processor/plugin/assignment-provider/src/main/java/org/onap/ccsdk/config/assignment/service/ResourceDictionaryService.java b/blueprints-processor/plugin/assignment-provider/src/main/java/org/onap/ccsdk/config/assignment/service/ResourceDictionaryService.java
new file mode 100644 (file)
index 0000000..97a4dd4
--- /dev/null
@@ -0,0 +1,109 @@
+/*\r
+ * Copyright © 2017-2018 AT&T Intellectual Property.\r
+ * \r
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except\r
+ * in compliance with the License. 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 distributed under the License\r
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express\r
+ * or implied. See the License for the specific language governing permissions and limitations under\r
+ * the License.\r
+ */\r
+\r
+package org.onap.ccsdk.config.assignment.service;\r
+\r
+import java.util.ArrayList;\r
+import java.util.HashMap;\r
+import java.util.List;\r
+import java.util.Map;\r
+import org.apache.commons.lang3.StringUtils;\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.domain.ResourceDictionary;\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.ConfigRestAdaptorException;\r
+import org.onap.ccsdk.config.rest.adaptor.service.ConfigRestAdaptorService;\r
+import org.onap.ccsdk.sli.core.sli.SvcLogicException;\r
+import com.att.eelf.configuration.EELFLogger;\r
+import com.att.eelf.configuration.EELFManager;\r
+\r
+public class ResourceDictionaryService {\r
+    \r
+    private static EELFLogger logger = EELFManager.getInstance().getLogger(ResourceDictionaryService.class);\r
+    private ConfigRestAdaptorService configRestAdaptorService;\r
+    \r
+    public ResourceDictionaryService(ConfigRestAdaptorService configRestAdaptorService) {\r
+        this.configRestAdaptorService = configRestAdaptorService;\r
+    }\r
+    \r
+    @SuppressWarnings("squid:S3776")\r
+    public Map<String, ResourceDefinition> getDataDictionaryDefinitions(List<ResourceAssignment> resourceAssignments)\r
+            throws SvcLogicException {\r
+        try {\r
+            Map<String, ResourceDefinition> dictionaries = new HashMap<>();\r
+            if (resourceAssignments != null) {\r
+                List<String> names = new ArrayList<>();\r
+                for (ResourceAssignment resourceAssignment : resourceAssignments) {\r
+                    if (resourceAssignment != null && StringUtils.isNotBlank(resourceAssignment.getDictionaryName())) {\r
+                        \r
+                        if (!names.contains(resourceAssignment.getDictionaryName())) {\r
+                            names.add(resourceAssignment.getDictionaryName());\r
+                        }\r
+                        \r
+                        if (resourceAssignment.getDependencies() != null\r
+                                && !resourceAssignment.getDependencies().isEmpty()) {\r
+                            List<String> dependencieNames = resourceAssignment.getDependencies();\r
+                            for (String dependencieName : dependencieNames) {\r
+                                if (StringUtils.isNotBlank(dependencieName) && !names.contains(dependencieName)) {\r
+                                    names.add(dependencieName);\r
+                                }\r
+                            }\r
+                        }\r
+                    }\r
+                }\r
+                queryResourceDictionaryDefinitions(dictionaries, names);\r
+            }\r
+            return dictionaries;\r
+        } catch (Exception e) {\r
+            throw new SvcLogicException("Failed in getting resource data dictionary : " + e.getMessage());\r
+        }\r
+        \r
+    }\r
+    \r
+    @SuppressWarnings("squid:S3776")\r
+    private void queryResourceDictionaryDefinitions(Map<String, ResourceDefinition> dictionaries, List<String> names)\r
+            throws SvcLogicException, ConfigRestAdaptorException {\r
+        logger.info("Getting resource dictionary definition for the names ({})", names);\r
+        if (!names.isEmpty()) {\r
+            \r
+            String dictionaryContents = configRestAdaptorService.postResource(\r
+                    ConfigRestAdaptorConstants.SELECTOR_MODEL_SERVICE, "dictionarybynames", names, String.class);\r
+            \r
+            if (StringUtils.isNotBlank(dictionaryContents)) {\r
+                List<ResourceDictionary> dataDictionaries =\r
+                        TransformationUtils.getListfromJson(dictionaryContents, ResourceDictionary.class);\r
+                if (dataDictionaries != null) {\r
+                    for (ResourceDictionary dataDictionary : dataDictionaries) {\r
+                        if (dataDictionary != null && StringUtils.isNotBlank(dataDictionary.getName())\r
+                                && StringUtils.isNotBlank(dataDictionary.getDefinition())) {\r
+                            ResourceDefinition resourceDefinition = TransformationUtils\r
+                                    .readValue(dataDictionary.getDefinition(), ResourceDefinition.class);\r
+                            if (resourceDefinition != null && StringUtils.isNotBlank(resourceDefinition.getName())) {\r
+                                dictionaries.put(resourceDefinition.getName(), resourceDefinition);\r
+                            } else {\r
+                                throw new SvcLogicException(\r
+                                        "Failed in getting resource data dictionary definition for : "\r
+                                                + dataDictionary.getName());\r
+                            }\r
+                        }\r
+                    }\r
+                }\r
+            } else {\r
+                logger.warn("No resource dictionary definition found for the names ({})", names);\r
+            }\r
+        }\r
+    }\r
+}\r
diff --git a/blueprints-processor/plugin/assignment-provider/src/main/java/org/onap/ccsdk/config/assignment/service/ResourceModelService.java b/blueprints-processor/plugin/assignment-provider/src/main/java/org/onap/ccsdk/config/assignment/service/ResourceModelService.java
new file mode 100644 (file)
index 0000000..7eb2196
--- /dev/null
@@ -0,0 +1,94 @@
+/*\r
+ * Copyright © 2017-2018 AT&T Intellectual Property.\r
+ * \r
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except\r
+ * in compliance with the License. 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 distributed under the License\r
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express\r
+ * or implied. See the License for the specific language governing permissions and limitations under\r
+ * the License.\r
+ */\r
+\r
+package org.onap.ccsdk.config.assignment.service;\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.lang3.StringUtils;\r
+import org.onap.ccsdk.config.model.data.ResourceAssignment;\r
+import org.onap.ccsdk.config.model.service.ConfigModelService;\r
+import org.onap.ccsdk.config.model.utils.TransformationUtils;\r
+import org.onap.ccsdk.config.model.validator.ResourceAssignmentValidator;\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
+\r
+public class ResourceModelService {\r
+    private static EELFLogger logger = EELFManager.getInstance().getLogger(ResourceModelService.class);\r
+    \r
+    private ConfigModelService configModelService;\r
+    \r
+    public ResourceModelService(ConfigModelService configModelService) {\r
+        this.configModelService = configModelService;\r
+    }\r
+    \r
+    public Map<String, String> getTemplatesContents(SvcLogicContext ctx, List<String> templateNames)\r
+            throws SvcLogicException {\r
+        Map<String, String> templatesContents = new HashMap<>();\r
+        try {\r
+            if (CollectionUtils.isNotEmpty(templateNames)) {\r
+                for (String templateName : templateNames) {\r
+                    String templateContent = this.configModelService.getNodeTemplateContent(ctx, templateName);\r
+                    logger.trace("Processing template ({}) with  content : {}", templateName, templateContent);\r
+                    templatesContents.put(templateName, templateContent);\r
+                }\r
+            }\r
+        } catch (Exception e) {\r
+            throw new SvcLogicException(e.getMessage());\r
+        }\r
+        return templatesContents;\r
+    }\r
+    \r
+    public Map<String, List<ResourceAssignment>> getTemplatesResourceAssignments(SvcLogicContext ctx,\r
+            List<String> templateNames) throws SvcLogicException {\r
+        Map<String, List<ResourceAssignment>> templatesResourceAssignments = new HashMap<>();\r
+        try {\r
+            if (CollectionUtils.isNotEmpty(templateNames)) {\r
+                for (String templateName : templateNames) {\r
+                    String resourceMappingContent = this.configModelService.getNodeTemplateMapping(ctx, templateName);\r
+                    logger.info("Processing template ({}) with resource assignment content : {}", templateName,\r
+                            resourceMappingContent);\r
+                    \r
+                    if (StringUtils.isNotBlank(resourceMappingContent)) {\r
+                        \r
+                        List<ResourceAssignment> resourceAssignments =\r
+                                TransformationUtils.getListfromJson(resourceMappingContent, ResourceAssignment.class);\r
+                        \r
+                        if (resourceAssignments != null) {\r
+                            ResourceAssignmentValidator resourceAssignmentValidator =\r
+                                    new ResourceAssignmentValidator(resourceAssignments);\r
+                            resourceAssignmentValidator.validateResourceAssignment();\r
+                            logger.info("Resource assignment validated successfully for the template ({})",\r
+                                    templateName);\r
+                            templatesResourceAssignments.put(templateName, resourceAssignments);\r
+                        } else {\r
+                            throw new SvcLogicException(String.format(\r
+                                    "Failed to convert assignment content (%s) to object", resourceMappingContent));\r
+                        }\r
+                    } else {\r
+                        // Do nothing, because som e templates may not have mappings\r
+                    }\r
+                }\r
+            }\r
+        } catch (Exception e) {\r
+            throw new SvcLogicException(e.getMessage());\r
+        }\r
+        \r
+        return templatesResourceAssignments;\r
+    }\r
+}\r
diff --git a/blueprints-processor/plugin/assignment-provider/src/main/resources/org/opendaylight/blueprint/impl-blueprint.xml b/blueprints-processor/plugin/assignment-provider/src/main/resources/org/opendaylight/blueprint/impl-blueprint.xml
new file mode 100644 (file)
index 0000000..ebefd64
--- /dev/null
@@ -0,0 +1,67 @@
+<?xml version="1.0" encoding="UTF-8"?>\r
+<!--\r
+  Copyright © 2017-2018 AT&T Intellectual Property.\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
+<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"\r
+       xmlns:odl="http://opendaylight.org/xmlns/blueprint/v1.0.0"\r
+       odl:use-default-for-reference-types="true">\r
+\r
+       <reference id="componentNodeService"\r
+               interface="org.onap.ccsdk.config.model.service.ComponentNodeService" />\r
+\r
+       <reference id="configResourceService"\r
+               interface="org.onap.ccsdk.config.data.adaptor.service.ConfigResourceService" />\r
+\r
+       <reference id="configModelService"\r
+               interface="org.onap.ccsdk.config.model.service.ConfigModelService" />\r
+\r
+       <reference id="configRestAdaptorService"\r
+               interface="org.onap.ccsdk.config.rest.adaptor.service.ConfigRestAdaptorService" />\r
+\r
+       <reference id="configGeneratorService"\r
+               interface="org.onap.ccsdk.config.generator.service.ConfigGeneratorService" />\r
+\r
+       <reference id="configProvDataStore"\r
+               interface="org.onap.ccsdk.config.provdata.service.ConfigProvDataStore" />\r
+\r
+       <!-- Expose the Common Component Bean -->\r
+       <bean id="configAssignmentNode"\r
+               class="org.onap.ccsdk.config.assignment.service.ConfigAssignmentNode">\r
+               <argument ref="configResourceService" />\r
+               <argument ref="configRestAdaptorService" />\r
+               <argument ref="configModelService" />\r
+               <argument ref="componentNodeService" />\r
+               <argument ref="configGeneratorService" />\r
+               <argument ref="configProvDataStore" />\r
+       </bean>\r
+\r
+       <service ref="configAssignmentNode"\r
+               interface="org.onap.ccsdk.config.assignment.service.ConfigAssignmentNode" />\r
+\r
+       <bean id="configAssignmentService"\r
+               class="org.onap.ccsdk.config.assignment.service.ConfigAssignmentServiceImpl">\r
+               <argument ref="configResourceService" />\r
+               <argument ref="configRestAdaptorService" />\r
+               <argument ref="configModelService" />\r
+               <argument ref="componentNodeService" />\r
+               <argument ref="configGeneratorService" />\r
+               <argument ref="configProvDataStore" />\r
+       </bean>\r
+\r
+       <service ref="configAssignmentService"\r
+               interface="org.onap.ccsdk.config.assignment.service.ConfigAssignmentService" />\r
+\r
+</blueprint>\r