summaryrefslogtreecommitdiffstats
path: root/blueprints-processor/plugin/model-provider/src
diff options
context:
space:
mode:
authorSingal, Kapil (ks220y) <ks220y@att.com>2018-09-04 22:32:06 -0400
committerSingal, Kapil (ks220y) <ks220y@att.com>2018-09-04 22:32:06 -0400
commitdea3a771f30f2a187e3bd0e91d4a39797eed3d2e (patch)
tree8054465752f0ba944b7fe54ee2afa5a050619817 /blueprints-processor/plugin/model-provider/src
parentbc19e1f0dd1d9ccf17ad390690de3b8ae2f76ddc (diff)
SDNC Blueprints Processor Model Service
Creating SDN Controller Blueprints Processor Model Service Change-Id: Icadc7eb9feef87024df84d047cef77d08232d921 Issue-ID: CCSDK-509 Signed-off-by: Singal, Kapil (ks220y) <ks220y@att.com>
Diffstat (limited to 'blueprints-processor/plugin/model-provider/src')
-rw-r--r--blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/service/ComponentNode.java41
-rw-r--r--blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/service/ComponentNodeDelegate.java42
-rw-r--r--blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/service/ComponentNodeService.java32
-rw-r--r--blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/service/ComponentNodeServiceImpl.java174
-rw-r--r--blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/service/ConfigBlueprintService.java100
-rw-r--r--blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/service/ConfigModelNode.java24
-rw-r--r--blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/service/ConfigModelService.java55
-rw-r--r--blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/service/ConfigModelServiceImpl.java244
8 files changed, 712 insertions, 0 deletions
diff --git a/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/service/ComponentNode.java b/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/service/ComponentNode.java
new file mode 100644
index 000000000..fd8e79c49
--- /dev/null
+++ b/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/service/ComponentNode.java
@@ -0,0 +1,41 @@
+/*
+ * 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.model.service;
+
+import java.util.Map;
+import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
+import org.onap.ccsdk.sli.core.sli.SvcLogicException;
+import org.onap.ccsdk.sli.core.sli.SvcLogicJavaPlugin;
+
+public interface ComponentNode extends SvcLogicJavaPlugin {
+
+ public Boolean preCondition(Map<String, String> inParams, SvcLogicContext ctx, Map<String, Object> componentContext)
+ throws SvcLogicException;
+
+ public void preProcess(Map<String, String> inParams, SvcLogicContext ctx, Map<String, Object> componentContext)
+ throws SvcLogicException;
+
+ public void process(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException;
+
+ public void process(Map<String, String> inParams, SvcLogicContext ctx, Map<String, Object> componentContext)
+ throws SvcLogicException;
+
+ public void postProcess(Map<String, String> inParams, SvcLogicContext ctx, Map<String, Object> componentContext)
+ throws SvcLogicException;
+
+}
diff --git a/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/service/ComponentNodeDelegate.java b/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/service/ComponentNodeDelegate.java
new file mode 100644
index 000000000..e2d332cd9
--- /dev/null
+++ b/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/service/ComponentNodeDelegate.java
@@ -0,0 +1,42 @@
+/*
+ * 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.model.service;
+
+import java.util.Map;
+import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
+import org.onap.ccsdk.sli.core.sli.SvcLogicException;
+import org.onap.ccsdk.sli.core.sli.SvcLogicJavaPlugin;
+import com.att.eelf.configuration.EELFLogger;
+import com.att.eelf.configuration.EELFManager;
+
+public class ComponentNodeDelegate implements SvcLogicJavaPlugin {
+
+ private static EELFLogger logger = EELFManager.getInstance().getLogger(ComponentNodeDelegate.class);
+ private ComponentNodeService componentNodeService;
+
+ public ComponentNodeDelegate(ComponentNodeService componentNodeService) {
+ logger.info("{} Constructor Initiated", "ComponentNodeDelegate");
+ this.componentNodeService = componentNodeService;
+
+ }
+
+ public void process(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
+ this.componentNodeService.process(inParams, ctx, null);
+ }
+
+}
diff --git a/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/service/ComponentNodeService.java b/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/service/ComponentNodeService.java
new file mode 100644
index 000000000..6c954518a
--- /dev/null
+++ b/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/service/ComponentNodeService.java
@@ -0,0 +1,32 @@
+/*
+ * 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.model.service;
+
+import java.util.Map;
+import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
+import org.onap.ccsdk.sli.core.sli.SvcLogicException;
+
+public interface ComponentNodeService {
+
+ public void process(Map<String, String> inParams, SvcLogicContext ctx, Map<String, Object> componentContext)
+ throws SvcLogicException;
+
+ public ComponentNode getComponentNodeInterface(String pluginName, String componentType) throws SvcLogicException;
+
+ public ComponentNode getComponentNode(SvcLogicContext ctx, String selectorName) throws SvcLogicException;
+}
diff --git a/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/service/ComponentNodeServiceImpl.java b/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/service/ComponentNodeServiceImpl.java
new file mode 100644
index 000000000..a2f1e7af3
--- /dev/null
+++ b/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/service/ComponentNodeServiceImpl.java
@@ -0,0 +1,174 @@
+/*
+ * 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.model.service;
+
+import java.util.HashMap;
+import java.util.Map;
+import org.apache.commons.lang3.StringUtils;
+import org.onap.ccsdk.config.data.adaptor.DataAdaptorConstants;
+import org.onap.ccsdk.config.data.adaptor.domain.TransactionLog;
+import org.onap.ccsdk.config.data.adaptor.service.ConfigResourceService;
+import org.onap.ccsdk.config.model.ConfigModelConstant;
+import org.onap.ccsdk.config.model.data.InterfaceAssignment;
+import org.onap.ccsdk.config.model.data.NodeTemplate;
+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 org.onap.ccsdk.sli.core.sli.SvcLogicException;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
+import com.att.eelf.configuration.EELFLogger;
+import com.att.eelf.configuration.EELFManager;
+
+public class ComponentNodeServiceImpl implements ComponentNodeService {
+
+ private static EELFLogger logger = EELFManager.getInstance().getLogger(ComponentNodeServiceImpl.class);
+
+ private BundleContext bcontext;
+ private ConfigResourceService configResourceService;
+ private ConfigModelService configModelService;
+
+ public ComponentNodeServiceImpl(BundleContext blueprintBundleContext, ConfigResourceService configResourceService,
+ ConfigRestAdaptorService configRestAdaptorService) {
+ logger.info("{} Constructor Initiated", "ComponentNodeServiceImpl");
+ this.bcontext = blueprintBundleContext;
+ this.configResourceService = configResourceService;
+ this.configModelService = new ConfigModelServiceImpl(configRestAdaptorService);
+ }
+
+ @Override
+ public void process(Map<String, String> inParams, SvcLogicContext ctx, Map<String, Object> componentContext)
+ throws SvcLogicException {
+ String requestId = null;
+ String selector = null;
+ try {
+ selector = inParams.get(ConfigModelConstant.PROPERTY_SELECTOR);
+ requestId = ctx.getAttribute(ConfigModelConstant.PROPERTY_REQUEST_ID);
+
+ logger.info("Component execution started with input params ({})", inParams);
+ configModelService.assignInParamsFromModel(ctx, inParams);
+
+ String currentInterface = inParams.get(ConfigModelConstant.PROPERTY_CURRENT_INTERFACE);
+ String currentNodeDerivedFrom = inParams.get(ConfigModelConstant.PROPERTY_CURRENT_NODETYPE_DERIVED_FROM);
+
+ configResourceService.save(new TransactionLog(requestId, DataAdaptorConstants.LOG_MESSAGE_TYPE_COMPONENT,
+ String.format("Executing Component (%s) derived from (%s) with Params : (%s) ", currentInterface,
+ currentNodeDerivedFrom, inParams)));
+
+ ComponentNode handler = getComponentNodeInterface(currentInterface, currentNodeDerivedFrom);
+
+ if (handler == null) {
+ throw new SvcLogicException(
+ String.format("Could not find Component for Interface %s", currentInterface));
+ }
+ if (componentContext == null) {
+ componentContext = new HashMap<>();
+ }
+
+ logger.debug("Executing component ({})", currentInterface);
+
+ if (handler.preCondition(inParams, ctx, componentContext)) {
+ handler.preProcess(inParams, ctx, componentContext);
+ handler.process(inParams, ctx, componentContext);
+ handler.postProcess(inParams, ctx, componentContext);
+ logger.debug("Executed component ({}) successfully.", currentInterface);
+ configResourceService
+ .save(new TransactionLog(requestId, DataAdaptorConstants.LOG_MESSAGE_TYPE_COMPONENT,
+ String.format("Component (%s) executed successfully. ", currentInterface)));
+
+ ctx.setAttribute(selector + ConfigModelConstant.PROPERTY_DOT_STATUS,
+ ConfigModelConstant.STATUS_SUCCESS);
+ } else {
+ logger.info("Skipped component execution ({})", handler.getClass());
+ configResourceService
+ .save(new TransactionLog(requestId, DataAdaptorConstants.LOG_MESSAGE_TYPE_COMPONENT,
+ String.format("Skipping component (%s) execution.", handler.getClass())));
+ ctx.setAttribute(selector + ConfigModelConstant.PROPERTY_DOT_STATUS,
+ ConfigModelConstant.STATUS_SKIPPED);
+ }
+
+ configModelService.assignOutParamsFromModel(ctx, inParams);
+ ctx.setStatus(ConfigModelConstant.STATUS_SUCCESS);
+ } catch (Exception e) {
+ logger.error(String.format("Failed in component (%s) execution for request id (%s) with error %s", selector,
+ requestId, e.getMessage()));
+ configResourceService.save(new TransactionLog(requestId, DataAdaptorConstants.LOG_MESSAGE_TYPE_COMPONENT,
+ String.format("Failed in component (%s) execution for request id (%s) with error %s", selector,
+ requestId, e.getMessage())));
+
+ ctx.setAttribute(selector + ConfigModelConstant.PROPERTY_DOT_STATUS, ConfigModelConstant.STATUS_FAILURE);
+ ctx.setAttribute(selector + ConfigModelConstant.PROPERTY_DOT_ERROR_MESSAGE, e.getMessage());
+ ctx.setAttribute(ConfigModelConstant.PROPERTY_ERROR_MESSAGE, e.getMessage());
+ ctx.setStatus(ConfigModelConstant.STATUS_FAILURE);
+ throw new SvcLogicException(e.getMessage(), e);
+ }
+ }
+
+ @Override
+ public ComponentNode getComponentNodeInterface(String pluginName, String componentType) throws SvcLogicException {
+
+ logger.info("Searching for component node plugin ({}) component type ({})", pluginName, componentType);
+
+ if (StringUtils.isBlank(pluginName)) {
+ throw new SvcLogicException(
+ String.format("Could not get Interface Name from Service Template : %s ", pluginName));
+ }
+
+ pluginName = pluginName.replace("-", ".");
+ ServiceReference sref = bcontext.getServiceReference(pluginName);
+
+ if (sref == null) {
+ throw new SvcLogicException(
+ String.format("Could not find service reference object for plugin %s", pluginName));
+ }
+ return (ComponentNode) bcontext.getService(sref);
+ }
+
+ @Override
+ public ComponentNode getComponentNode(SvcLogicContext ctx, String componentKey) throws SvcLogicException {
+
+ if (StringUtils.isBlank(componentKey)) {
+ logger.warn("Can't get node template content for a component key ({})", componentKey);
+ return null;
+ }
+
+ String nodeTemplateContent = ctx.getAttribute(ConfigModelConstant.PROPERTY_NODE_TEMPLATES_DOT + componentKey);
+ logger.info("Processing component template : ({})", nodeTemplateContent);
+
+ if (StringUtils.isBlank(nodeTemplateContent)) {
+ logger.warn("Couldn't get node template content for component key ({})", componentKey);
+ return null;
+ }
+
+ NodeTemplate nodeTemplate = TransformationUtils.readValue(nodeTemplateContent, NodeTemplate.class);
+ if (nodeTemplate == null || StringUtils.isBlank(nodeTemplate.getType())) {
+ logger.warn("Failed to convert content ({}) to node template.", nodeTemplateContent);
+ return null;
+ }
+
+ ComponentNode componentNode = null;
+ for (Map.Entry<String, InterfaceAssignment> nodeTemplateInterface : nodeTemplate.getInterfaces().entrySet()) {
+ if (nodeTemplateInterface != null && nodeTemplateInterface.getValue() != null) {
+ String pluginName = nodeTemplateInterface.getKey();
+ componentNode = getComponentNodeInterface(pluginName, ConfigModelConstant.MODEL_TYPE_NODE_COMPONENT);
+ }
+ }
+ return componentNode;
+ }
+
+}
diff --git a/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/service/ConfigBlueprintService.java b/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/service/ConfigBlueprintService.java
new file mode 100644
index 000000000..49c64abc9
--- /dev/null
+++ b/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/service/ConfigBlueprintService.java
@@ -0,0 +1,100 @@
+/*
+ * 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.model.service;
+
+import java.util.List;
+import java.util.Map;
+import org.apache.commons.lang3.StringUtils;
+import org.onap.ccsdk.config.model.ConfigModelConstant;
+import org.onap.ccsdk.config.model.domain.ConfigModel;
+import org.onap.ccsdk.config.model.domain.ConfigModelContent;
+import org.onap.ccsdk.config.model.utils.PrepareContextUtils;
+import org.onap.ccsdk.config.rest.adaptor.ConfigRestAdaptorConstants;
+import org.onap.ccsdk.config.rest.adaptor.ConfigRestAdaptorException;
+import org.onap.ccsdk.config.rest.adaptor.service.ConfigRestAdaptorService;
+import org.onap.ccsdk.sli.core.sli.SvcLogicException;
+import com.att.eelf.configuration.EELFLogger;
+import com.att.eelf.configuration.EELFManager;
+
+public class ConfigBlueprintService {
+
+ private static EELFLogger logger = EELFManager.getInstance().getLogger(ConfigBlueprintService.class);
+
+ private final ConfigRestAdaptorService configRestAdaptorService;
+
+ public ConfigBlueprintService(ConfigRestAdaptorService configRestAdaptorService) {
+ this.configRestAdaptorService = configRestAdaptorService;
+ }
+
+ public Map<String, String> prepareContext(Map<String, String> context, String input, String serviceTemplateName,
+ String serviceTemplateVersion) throws SvcLogicException {
+ try {
+ PrepareContextUtils prepareContextUtils = new PrepareContextUtils();
+ String serviceTemplateContent = getServiceModel(context, serviceTemplateName, serviceTemplateVersion);
+
+ if (StringUtils.isBlank(serviceTemplateContent)) {
+ throw new SvcLogicException(String.format("Failed to get the Service Template (%s), version (%s)",
+ serviceTemplateName, serviceTemplateVersion));
+ }
+
+ return prepareContextUtils.prepareContext(context, input, serviceTemplateContent);
+ } catch (Exception e) {
+ throw new SvcLogicException(e.getMessage(), e);
+ }
+ }
+
+ @SuppressWarnings("squid:S3776")
+ private String getServiceModel(Map<String, String> context, String serviceTemplateName,
+ String serviceTemplateVersion) throws SvcLogicException, ConfigRestAdaptorException {
+ String content = null;
+
+ logger.info("Getting service template ({}) of version ({}) ", serviceTemplateName, serviceTemplateVersion);
+
+ String path = "configmodelbyname/" + serviceTemplateName + "/version/" + serviceTemplateVersion;
+
+ ConfigModel configModel = configRestAdaptorService
+ .getResource(ConfigRestAdaptorConstants.SELECTOR_MODEL_SERVICE, path, ConfigModel.class);
+
+ if (configModel == null || configModel.getConfigModelContents() == null
+ || configModel.getConfigModelContents().isEmpty()) {
+ throw new SvcLogicException("Service template model is missing for service template name ("
+ + serviceTemplateName + "), service template version (" + serviceTemplateVersion + ") ");
+ } else {
+ if (configModel.getPublished() == null || !configModel.getPublished().equalsIgnoreCase("Y")) {
+ throw new SvcLogicException(String.format(
+ "Service template model is not published for service template (%s) ", serviceTemplateName));
+ }
+
+ List<ConfigModelContent> configModelContents = configModel.getConfigModelContents();
+ for (ConfigModelContent configModelContent : configModelContents) {
+ if (configModelContent != null) {
+ if (ConfigModelConstant.MODEL_CONTENT_TYPE_TOSCA_JSON.equals(configModelContent.getContentType())) {
+ content = configModelContent.getContent();
+ } else if (ConfigModelConstant.MODEL_CONTENT_TYPE_TEMPLATE
+ .equals(configModelContent.getContentType())) {
+ context.put(ConfigModelConstant.PROPERTY_NODE_TEMPLATES_DOT + configModelContent.getName()
+ + ".content", configModelContent.getContent());
+ }
+ }
+ }
+ logger.trace("Service model data : {} ", content);
+ }
+ return content;
+ }
+
+}
diff --git a/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/service/ConfigModelNode.java b/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/service/ConfigModelNode.java
new file mode 100644
index 000000000..3347424fe
--- /dev/null
+++ b/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/service/ConfigModelNode.java
@@ -0,0 +1,24 @@
+/*
+ * 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.model.service;
+
+import org.onap.ccsdk.sli.core.sli.SvcLogicJavaPlugin;
+
+public class ConfigModelNode implements SvcLogicJavaPlugin {
+
+}
diff --git a/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/service/ConfigModelService.java b/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/service/ConfigModelService.java
new file mode 100644
index 000000000..0c112baa8
--- /dev/null
+++ b/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/service/ConfigModelService.java
@@ -0,0 +1,55 @@
+/*
+ * 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.model.service;
+
+import java.util.List;
+import java.util.Map;
+import org.onap.ccsdk.config.model.data.ServiceTemplate;
+import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
+import org.onap.ccsdk.sli.core.sli.SvcLogicException;
+
+public interface ConfigModelService {
+
+ public Boolean validateServiceTemplate(ServiceTemplate serviceTemplate) throws SvcLogicException;
+
+ public Map<String, String> prepareContext(Map<String, String> context, String input, String serviceTemplateName,
+ String serviceTemplateVersion) throws SvcLogicException;
+
+ public Map<String, String> prepareContext(Map<String, String> context, String input, String serviceTemplateContent)
+ throws SvcLogicException;
+
+ public Map<String, String> convertJson2properties(Map<String, String> context, String jsonContent,
+ List<String> blockKeys) throws SvcLogicException;
+
+ public Map<String, String> convertServiceTemplate2Properties(String serviceTemplateContent,
+ final Map<String, String> context) throws SvcLogicException;
+
+ public Map<String, String> convertServiceTemplate2Properties(ServiceTemplate serviceTemplate,
+ final Map<String, String> context) throws SvcLogicException;
+
+ public SvcLogicContext assignInParamsFromModel(final SvcLogicContext context, final Map<String, String> inParams)
+ throws SvcLogicException;
+
+ public SvcLogicContext assignOutParamsFromModel(final SvcLogicContext context, final Map<String, String> inParams)
+ throws SvcLogicException;
+
+ public String getNodeTemplateContent(final SvcLogicContext context, String templateName) throws SvcLogicException;
+
+ public String getNodeTemplateMapping(final SvcLogicContext context, String templateName) throws SvcLogicException;
+
+}
diff --git a/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/service/ConfigModelServiceImpl.java b/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/service/ConfigModelServiceImpl.java
new file mode 100644
index 000000000..a3014b6b8
--- /dev/null
+++ b/blueprints-processor/plugin/model-provider/src/main/java/org/onap/ccsdk/config/model/service/ConfigModelServiceImpl.java
@@ -0,0 +1,244 @@
+/*
+ * 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.model.service;
+
+import java.util.List;
+import java.util.Map;
+import org.apache.commons.lang3.StringUtils;
+import org.onap.ccsdk.config.model.ConfigModelConstant;
+import org.onap.ccsdk.config.model.ConfigModelException;
+import org.onap.ccsdk.config.model.data.CapabilityAssignment;
+import org.onap.ccsdk.config.model.data.NodeTemplate;
+import org.onap.ccsdk.config.model.data.NodeType;
+import org.onap.ccsdk.config.model.data.ServiceTemplate;
+import org.onap.ccsdk.config.model.utils.NodePropertyUtils;
+import org.onap.ccsdk.config.model.utils.PrepareContextUtils;
+import org.onap.ccsdk.config.model.utils.ServiceTemplateUtils;
+import org.onap.ccsdk.config.model.utils.TransformationUtils;
+import org.onap.ccsdk.config.model.validator.ServiceTemplateValidator;
+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;
+
+public class ConfigModelServiceImpl implements ConfigModelService {
+
+ private static EELFLogger logger = EELFManager.getInstance().getLogger(ConfigModelServiceImpl.class);
+ private static final String CLASS_NAME = "ConfigModelServiceImpl";
+
+ private final ConfigRestAdaptorService configRestAdaptorService;
+
+ public ConfigModelServiceImpl(ConfigRestAdaptorService configRestAdaptorService) {
+ logger.info("{} Constuctor Initated...", CLASS_NAME);
+ this.configRestAdaptorService = configRestAdaptorService;
+ }
+
+ @Override
+ public Boolean validateServiceTemplate(ServiceTemplate serviceTemplate) throws SvcLogicException {
+ try {
+ ServiceTemplateValidator serviceTemplateValidator = new ServiceTemplateValidator();
+ return serviceTemplateValidator.validateServiceTemplate(serviceTemplate);
+ } catch (ConfigModelException e) {
+ throw new SvcLogicException(e.getMessage());
+ }
+ }
+
+ @Override
+ public Map<String, String> prepareContext(Map<String, String> context, String input, String serviceTemplateName,
+ String serviceTemplateVersion) throws SvcLogicException {
+
+ ConfigBlueprintService configBlueprintService = new ConfigBlueprintService(configRestAdaptorService);
+ return configBlueprintService.prepareContext(context, input, serviceTemplateName, serviceTemplateVersion);
+ }
+
+ @Override
+ public Map<String, String> prepareContext(Map<String, String> context, String input, String serviceTemplateContent)
+ throws SvcLogicException {
+ try {
+ PrepareContextUtils prepareContextUtils = new PrepareContextUtils();
+ return prepareContextUtils.prepareContext(context, input, serviceTemplateContent);
+ } catch (Exception e) {
+ throw new SvcLogicException(e.getMessage());
+ }
+ }
+
+ @Override
+ public Map<String, String> convertJson2properties(Map<String, String> context, String jsonContent,
+ List<String> blockKeys) throws SvcLogicException {
+ try {
+ return TransformationUtils.convertJson2Properties(context, jsonContent, blockKeys);
+ } catch (Exception e) {
+ throw new SvcLogicException(e.getMessage());
+ }
+ }
+
+ @Override
+ public Map<String, String> convertServiceTemplate2Properties(String serviceTemplateContent,
+ final Map<String, String> context) throws SvcLogicException {
+ try {
+ ServiceTemplateUtils serviceTemplateUtils = new ServiceTemplateUtils();
+ return serviceTemplateUtils.convertServiceTemplate2Properties(serviceTemplateContent, context);
+ } catch (Exception e) {
+ throw new SvcLogicException(e.getMessage());
+ }
+ }
+
+ @Override
+ public Map<String, String> convertServiceTemplate2Properties(ServiceTemplate serviceTemplate,
+ final Map<String, String> context) throws SvcLogicException {
+ try {
+ ServiceTemplateUtils serviceTemplateUtils = new ServiceTemplateUtils();
+ return serviceTemplateUtils.convertServiceTemplate2Properties(serviceTemplate, context);
+ } catch (Exception e) {
+ throw new SvcLogicException(e.getMessage());
+ }
+ }
+
+ @SuppressWarnings("squid:S3776")
+ @Override
+ public SvcLogicContext assignInParamsFromModel(final SvcLogicContext context, final Map<String, String> inParams)
+ throws SvcLogicException {
+ logger.debug("Processing component input param ({})", inParams);
+ try {
+ if (context != null && inParams != null && inParams.containsKey(ConfigModelConstant.PROPERTY_SELECTOR)) {
+ String componentKey = inParams.get(ConfigModelConstant.PROPERTY_SELECTOR);
+ if (StringUtils.isNotBlank(componentKey)) {
+ String nodeTemplateContent =
+ context.getAttribute(ConfigModelConstant.PROPERTY_NODE_TEMPLATES_DOT + componentKey);
+ logger.info("Processing node template content ({})", nodeTemplateContent);
+ if (StringUtils.isNotBlank(nodeTemplateContent)) {
+ NodeTemplate nodeTemplate =
+ TransformationUtils.readValue(nodeTemplateContent, NodeTemplate.class);
+ if (nodeTemplate != null && StringUtils.isNotBlank(nodeTemplate.getType())) {
+ String nodeTypeContent = context
+ .getAttribute(ConfigModelConstant.PROPERTY_NODE_TYPES_DOT + nodeTemplate.getType());
+ NodeType nodetype = TransformationUtils.readValue(nodeTypeContent, NodeType.class);
+ if (nodetype != null) {
+ inParams.put(ConfigModelConstant.PROPERTY_CURRENT_NODETYPE_DERIVED_FROM,
+ nodetype.getDerivedFrom());
+ NodePropertyUtils nodePropertyUtils = new NodePropertyUtils(context, inParams);
+ nodePropertyUtils.assignInParamsFromModel(nodetype, nodeTemplate);
+ } else {
+ throw new SvcLogicException(
+ String.format("Failed to get node type (%s) for node template (%s).",
+ nodeTemplate.getType(), componentKey));
+ }
+
+ } else {
+ throw new SvcLogicException(String
+ .format("Failed to convert content (%s) to node template.", nodeTemplateContent));
+ }
+ } else {
+ throw new SvcLogicException(String
+ .format("Couldn't get node template content for component key (%s).", componentKey));
+ }
+ } else {
+ throw new SvcLogicException(
+ String.format("Couldn't get component key (prefix) from inparam (%s)", inParams));
+ }
+ }
+ } catch (Exception e) {
+ throw new SvcLogicException(e.getMessage());
+ }
+ return context;
+ }
+
+ @Override
+ public SvcLogicContext assignOutParamsFromModel(final SvcLogicContext context, final Map<String, String> inParams)
+ throws SvcLogicException {
+ try {
+ if (context != null && inParams != null && inParams.containsKey(ConfigModelConstant.PROPERTY_SELECTOR)) {
+ String componentKey = inParams.get(ConfigModelConstant.PROPERTY_SELECTOR);
+ logger.info("Processing component output for prefix key ({})", componentKey);
+ if (StringUtils.isNotBlank(componentKey)) {
+ String nodeTemplateContent =
+ context.getAttribute(ConfigModelConstant.PROPERTY_NODE_TEMPLATES_DOT + componentKey);
+ if (StringUtils.isNotBlank(nodeTemplateContent)) {
+ NodeTemplate nodeTemplate =
+ TransformationUtils.readValue(nodeTemplateContent, NodeTemplate.class);
+ if (nodeTemplate != null && StringUtils.isNotBlank(nodeTemplate.getType())) {
+ String nodeTypeContent = context
+ .getAttribute(ConfigModelConstant.PROPERTY_NODE_TYPES_DOT + nodeTemplate.getType());
+ NodeType nodetype = TransformationUtils.readValue(nodeTypeContent, NodeType.class);
+ NodePropertyUtils nodePropertyUtils = new NodePropertyUtils(context, inParams);
+ nodePropertyUtils.assignOutParamsFromModel(nodetype, nodeTemplate);
+ }
+ }
+ }
+ }
+ } catch (Exception e) {
+ throw new SvcLogicException(e.getMessage());
+ }
+ return context;
+ }
+
+ @Override
+ public String getNodeTemplateContent(final SvcLogicContext context, String templateName) throws SvcLogicException {
+ String content = null;
+ try {
+ if (context != null && StringUtils.isNotBlank(templateName)) {
+ logger.info("Processing Artifact Node Template for content : ({})", templateName);
+ content = context
+ .getAttribute(ConfigModelConstant.PROPERTY_NODE_TEMPLATES_DOT + templateName + ".content");
+ }
+ } catch (Exception e) {
+ throw new SvcLogicException(e.getMessage());
+ }
+ return content;
+ }
+
+ @SuppressWarnings("squid:S3776")
+ @Override
+ public String getNodeTemplateMapping(final SvcLogicContext context, String templateName) throws SvcLogicException {
+ String mapping = null;
+ try {
+ if (context != null && StringUtils.isNotBlank(templateName)) {
+ logger.info("Processing artifact node template for mapping : ({})", templateName);
+ if (StringUtils.isNotBlank(templateName)) {
+ String nodeTemplateContent =
+ context.getAttribute(ConfigModelConstant.PROPERTY_NODE_TEMPLATES_DOT + templateName);
+ if (StringUtils.isNotBlank(nodeTemplateContent)) {
+
+ NodeTemplate nodeTemplate =
+ TransformationUtils.readValue(nodeTemplateContent, NodeTemplate.class);
+
+ if (nodeTemplate != null && nodeTemplate.getCapabilities() != null && nodeTemplate
+ .getCapabilities().containsKey(ConfigModelConstant.CAPABILITY_PROPERTY_MAPPING)) {
+
+ CapabilityAssignment capability =
+ nodeTemplate.getCapabilities().get(ConfigModelConstant.CAPABILITY_PROPERTY_MAPPING);
+ if (capability.getProperties() != null) {
+ List mappingList = (List) capability.getProperties()
+ .get(ConfigModelConstant.CAPABILITY_PROPERTY_MAPPING);
+ if (mappingList != null) {
+ mapping = TransformationUtils.getJson(mappingList);
+ }
+
+ }
+ }
+ }
+ }
+ }
+ } catch (Exception e) {
+ throw new SvcLogicException(e.getMessage());
+ }
+ return mapping;
+ }
+
+}