--- /dev/null
+/*\r
+ * Copyright © 2017-2018 AT&T Intellectual Property.\r
+ * Modifications Copyright © 2018 IBM.\r
+ * \r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ * \r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ * \r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+\r
+package org.onap.ccsdk.config.model.service;\r
+\r
+import java.util.Map;\r
+import org.onap.ccsdk.sli.core.sli.SvcLogicContext;\r
+import org.onap.ccsdk.sli.core.sli.SvcLogicException;\r
+import org.onap.ccsdk.sli.core.sli.SvcLogicJavaPlugin;\r
+\r
+public interface ComponentNode extends SvcLogicJavaPlugin {\r
+\r
+ public Boolean preCondition(Map<String, String> inParams, SvcLogicContext ctx, Map<String, Object> componentContext)\r
+ throws SvcLogicException;\r
+\r
+ public void preProcess(Map<String, String> inParams, SvcLogicContext ctx, Map<String, Object> componentContext)\r
+ throws SvcLogicException;\r
+\r
+ public void process(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException;\r
+\r
+ public void process(Map<String, String> inParams, SvcLogicContext ctx, Map<String, Object> componentContext)\r
+ throws SvcLogicException;\r
+\r
+ public void postProcess(Map<String, String> inParams, SvcLogicContext ctx, Map<String, Object> componentContext)\r
+ throws SvcLogicException;\r
+\r
+}\r
--- /dev/null
+/*\r
+ * Copyright © 2017-2018 AT&T Intellectual Property.\r
+ * Modifications Copyright © 2018 IBM.\r
+ * \r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ * \r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ * \r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+\r
+package org.onap.ccsdk.config.model.service;\r
+\r
+import java.util.Map;\r
+import org.onap.ccsdk.sli.core.sli.SvcLogicContext;\r
+import org.onap.ccsdk.sli.core.sli.SvcLogicException;\r
+import org.onap.ccsdk.sli.core.sli.SvcLogicJavaPlugin;\r
+import com.att.eelf.configuration.EELFLogger;\r
+import com.att.eelf.configuration.EELFManager;\r
+\r
+public class ComponentNodeDelegate implements SvcLogicJavaPlugin {\r
+\r
+ private static EELFLogger logger = EELFManager.getInstance().getLogger(ComponentNodeDelegate.class);\r
+ private ComponentNodeService componentNodeService;\r
+\r
+ public ComponentNodeDelegate(ComponentNodeService componentNodeService) {\r
+ logger.info("{} Constructor Initiated", "ComponentNodeDelegate");\r
+ this.componentNodeService = componentNodeService;\r
+\r
+ }\r
+\r
+ public void process(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {\r
+ this.componentNodeService.process(inParams, ctx, null);\r
+ }\r
+\r
+}\r
--- /dev/null
+/*\r
+ * Copyright © 2017-2018 AT&T Intellectual Property.\r
+ * Modifications Copyright © 2018 IBM.\r
+ * \r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ * \r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ * \r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+\r
+package org.onap.ccsdk.config.model.service;\r
+\r
+import java.util.Map;\r
+import org.onap.ccsdk.sli.core.sli.SvcLogicContext;\r
+import org.onap.ccsdk.sli.core.sli.SvcLogicException;\r
+\r
+public interface ComponentNodeService {\r
+\r
+ public void process(Map<String, String> inParams, SvcLogicContext ctx, Map<String, Object> componentContext)\r
+ throws SvcLogicException;\r
+\r
+ public ComponentNode getComponentNodeInterface(String pluginName, String componentType) throws SvcLogicException;\r
+\r
+ public ComponentNode getComponentNode(SvcLogicContext ctx, String selectorName) throws SvcLogicException;\r
+}\r
--- /dev/null
+/*\r
+ * Copyright © 2017-2018 AT&T Intellectual Property.\r
+ * Modifications Copyright © 2018 IBM.\r
+ * \r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ * \r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ * \r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+\r
+package org.onap.ccsdk.config.model.service;\r
+\r
+import java.util.HashMap;\r
+import java.util.Map;\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.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.InterfaceAssignment;\r
+import org.onap.ccsdk.config.model.data.NodeTemplate;\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 org.osgi.framework.BundleContext;\r
+import org.osgi.framework.ServiceReference;\r
+import com.att.eelf.configuration.EELFLogger;\r
+import com.att.eelf.configuration.EELFManager;\r
+\r
+public class ComponentNodeServiceImpl implements ComponentNodeService {\r
+\r
+ private static EELFLogger logger = EELFManager.getInstance().getLogger(ComponentNodeServiceImpl.class);\r
+\r
+ private BundleContext bcontext;\r
+ private ConfigResourceService configResourceService;\r
+ private ConfigModelService configModelService;\r
+\r
+ public ComponentNodeServiceImpl(BundleContext blueprintBundleContext, ConfigResourceService configResourceService,\r
+ ConfigRestAdaptorService configRestAdaptorService) {\r
+ logger.info("{} Constructor Initiated", "ComponentNodeServiceImpl");\r
+ this.bcontext = blueprintBundleContext;\r
+ this.configResourceService = configResourceService;\r
+ this.configModelService = new ConfigModelServiceImpl(configRestAdaptorService);\r
+ }\r
+\r
+ @Override\r
+ public void process(Map<String, String> inParams, SvcLogicContext ctx, Map<String, Object> componentContext)\r
+ throws SvcLogicException {\r
+ String requestId = null;\r
+ String selector = null;\r
+ try {\r
+ selector = inParams.get(ConfigModelConstant.PROPERTY_SELECTOR);\r
+ requestId = ctx.getAttribute(ConfigModelConstant.PROPERTY_REQUEST_ID);\r
+\r
+ logger.info("Component execution started with input params ({})", inParams);\r
+ configModelService.assignInParamsFromModel(ctx, inParams);\r
+\r
+ String currentInterface = inParams.get(ConfigModelConstant.PROPERTY_CURRENT_INTERFACE);\r
+ String currentNodeDerivedFrom = inParams.get(ConfigModelConstant.PROPERTY_CURRENT_NODETYPE_DERIVED_FROM);\r
+\r
+ configResourceService.save(new TransactionLog(requestId, DataAdaptorConstants.LOG_MESSAGE_TYPE_COMPONENT,\r
+ String.format("Executing Component (%s) derived from (%s) with Params : (%s) ", currentInterface,\r
+ currentNodeDerivedFrom, inParams)));\r
+\r
+ ComponentNode handler = getComponentNodeInterface(currentInterface, currentNodeDerivedFrom);\r
+\r
+ if (handler == null) {\r
+ throw new SvcLogicException(\r
+ String.format("Could not find Component for Interface %s", currentInterface));\r
+ }\r
+ if (componentContext == null) {\r
+ componentContext = new HashMap<>();\r
+ }\r
+\r
+ logger.debug("Executing component ({})", currentInterface);\r
+\r
+ if (handler.preCondition(inParams, ctx, componentContext)) {\r
+ handler.preProcess(inParams, ctx, componentContext);\r
+ handler.process(inParams, ctx, componentContext);\r
+ handler.postProcess(inParams, ctx, componentContext);\r
+ logger.debug("Executed component ({}) successfully.", currentInterface);\r
+ configResourceService\r
+ .save(new TransactionLog(requestId, DataAdaptorConstants.LOG_MESSAGE_TYPE_COMPONENT,\r
+ String.format("Component (%s) executed successfully. ", currentInterface)));\r
+\r
+ ctx.setAttribute(selector + ConfigModelConstant.PROPERTY_DOT_STATUS,\r
+ ConfigModelConstant.STATUS_SUCCESS);\r
+ } else {\r
+ logger.info("Skipped component execution ({})", handler.getClass());\r
+ configResourceService\r
+ .save(new TransactionLog(requestId, DataAdaptorConstants.LOG_MESSAGE_TYPE_COMPONENT,\r
+ String.format("Skipping component (%s) execution.", handler.getClass())));\r
+ ctx.setAttribute(selector + ConfigModelConstant.PROPERTY_DOT_STATUS,\r
+ ConfigModelConstant.STATUS_SKIPPED);\r
+ }\r
+\r
+ configModelService.assignOutParamsFromModel(ctx, inParams);\r
+ ctx.setStatus(ConfigModelConstant.STATUS_SUCCESS);\r
+ } catch (Exception e) {\r
+ logger.error(String.format("Failed in component (%s) execution for request id (%s) with error %s", selector,\r
+ requestId, e.getMessage()));\r
+ configResourceService.save(new TransactionLog(requestId, DataAdaptorConstants.LOG_MESSAGE_TYPE_COMPONENT,\r
+ String.format("Failed in component (%s) execution for request id (%s) with error %s", selector,\r
+ requestId, e.getMessage())));\r
+\r
+ ctx.setAttribute(selector + ConfigModelConstant.PROPERTY_DOT_STATUS, ConfigModelConstant.STATUS_FAILURE);\r
+ ctx.setAttribute(selector + ConfigModelConstant.PROPERTY_DOT_ERROR_MESSAGE, e.getMessage());\r
+ ctx.setAttribute(ConfigModelConstant.PROPERTY_ERROR_MESSAGE, e.getMessage());\r
+ ctx.setStatus(ConfigModelConstant.STATUS_FAILURE);\r
+ throw new SvcLogicException(e.getMessage(), e);\r
+ }\r
+ }\r
+\r
+ @Override\r
+ public ComponentNode getComponentNodeInterface(String pluginName, String componentType) throws SvcLogicException {\r
+\r
+ logger.info("Searching for component node plugin ({}) component type ({})", pluginName, componentType);\r
+\r
+ if (StringUtils.isBlank(pluginName)) {\r
+ throw new SvcLogicException(\r
+ String.format("Could not get Interface Name from Service Template : %s ", pluginName));\r
+ }\r
+\r
+ pluginName = pluginName.replace("-", ".");\r
+ ServiceReference sref = bcontext.getServiceReference(pluginName);\r
+\r
+ if (sref == null) {\r
+ throw new SvcLogicException(\r
+ String.format("Could not find service reference object for plugin %s", pluginName));\r
+ }\r
+ return (ComponentNode) bcontext.getService(sref);\r
+ }\r
+\r
+ @Override\r
+ public ComponentNode getComponentNode(SvcLogicContext ctx, String componentKey) throws SvcLogicException {\r
+\r
+ if (StringUtils.isBlank(componentKey)) {\r
+ logger.warn("Can't get node template content for a component key ({})", componentKey);\r
+ return null;\r
+ }\r
+\r
+ String nodeTemplateContent = ctx.getAttribute(ConfigModelConstant.PROPERTY_NODE_TEMPLATES_DOT + componentKey);\r
+ logger.info("Processing component template : ({})", nodeTemplateContent);\r
+\r
+ if (StringUtils.isBlank(nodeTemplateContent)) {\r
+ logger.warn("Couldn't get node template content for component key ({})", componentKey);\r
+ return null;\r
+ }\r
+\r
+ NodeTemplate nodeTemplate = TransformationUtils.readValue(nodeTemplateContent, NodeTemplate.class);\r
+ if (nodeTemplate == null || StringUtils.isBlank(nodeTemplate.getType())) {\r
+ logger.warn("Failed to convert content ({}) to node template.", nodeTemplateContent);\r
+ return null;\r
+ }\r
+\r
+ ComponentNode componentNode = null;\r
+ for (Map.Entry<String, InterfaceAssignment> nodeTemplateInterface : nodeTemplate.getInterfaces().entrySet()) {\r
+ if (nodeTemplateInterface != null && nodeTemplateInterface.getValue() != null) {\r
+ String pluginName = nodeTemplateInterface.getKey();\r
+ componentNode = getComponentNodeInterface(pluginName, ConfigModelConstant.MODEL_TYPE_NODE_COMPONENT);\r
+ }\r
+ }\r
+ return componentNode;\r
+ }\r
+\r
+}\r
--- /dev/null
+/*\r
+ * Copyright © 2017-2018 AT&T Intellectual Property.\r
+ * Modifications Copyright © 2018 IBM.\r
+ * \r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ * \r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ * \r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+\r
+package org.onap.ccsdk.config.model.service;\r
+\r
+import java.util.List;\r
+import java.util.Map;\r
+import org.apache.commons.lang3.StringUtils;\r
+import org.onap.ccsdk.config.model.ConfigModelConstant;\r
+import org.onap.ccsdk.config.model.domain.ConfigModel;\r
+import org.onap.ccsdk.config.model.domain.ConfigModelContent;\r
+import org.onap.ccsdk.config.model.utils.PrepareContextUtils;\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 ConfigBlueprintService {\r
+\r
+ private static EELFLogger logger = EELFManager.getInstance().getLogger(ConfigBlueprintService.class);\r
+\r
+ private final ConfigRestAdaptorService configRestAdaptorService;\r
+\r
+ public ConfigBlueprintService(ConfigRestAdaptorService configRestAdaptorService) {\r
+ this.configRestAdaptorService = configRestAdaptorService;\r
+ }\r
+\r
+ public Map<String, String> prepareContext(Map<String, String> context, String input, String serviceTemplateName,\r
+ String serviceTemplateVersion) throws SvcLogicException {\r
+ try {\r
+ PrepareContextUtils prepareContextUtils = new PrepareContextUtils();\r
+ String serviceTemplateContent = getServiceModel(context, serviceTemplateName, serviceTemplateVersion);\r
+\r
+ if (StringUtils.isBlank(serviceTemplateContent)) {\r
+ throw new SvcLogicException(String.format("Failed to get the Service Template (%s), version (%s)",\r
+ serviceTemplateName, serviceTemplateVersion));\r
+ }\r
+\r
+ return prepareContextUtils.prepareContext(context, input, serviceTemplateContent);\r
+ } catch (Exception e) {\r
+ throw new SvcLogicException(e.getMessage(), e);\r
+ }\r
+ }\r
+\r
+ @SuppressWarnings("squid:S3776")\r
+ private String getServiceModel(Map<String, String> context, String serviceTemplateName,\r
+ String serviceTemplateVersion) throws SvcLogicException, ConfigRestAdaptorException {\r
+ String content = null;\r
+\r
+ logger.info("Getting service template ({}) of version ({}) ", serviceTemplateName, serviceTemplateVersion);\r
+\r
+ String path = "configmodelbyname/" + serviceTemplateName + "/version/" + serviceTemplateVersion;\r
+\r
+ ConfigModel configModel = configRestAdaptorService\r
+ .getResource(ConfigRestAdaptorConstants.SELECTOR_MODEL_SERVICE, path, ConfigModel.class);\r
+\r
+ if (configModel == null || configModel.getConfigModelContents() == null\r
+ || configModel.getConfigModelContents().isEmpty()) {\r
+ throw new SvcLogicException("Service template model is missing for service template name ("\r
+ + serviceTemplateName + "), service template version (" + serviceTemplateVersion + ") ");\r
+ } else {\r
+ if (configModel.getPublished() == null || !configModel.getPublished().equalsIgnoreCase("Y")) {\r
+ throw new SvcLogicException(String.format(\r
+ "Service template model is not published for service template (%s) ", serviceTemplateName));\r
+ }\r
+\r
+ List<ConfigModelContent> configModelContents = configModel.getConfigModelContents();\r
+ for (ConfigModelContent configModelContent : configModelContents) {\r
+ if (configModelContent != null) {\r
+ if (ConfigModelConstant.MODEL_CONTENT_TYPE_TOSCA_JSON.equals(configModelContent.getContentType())) {\r
+ content = configModelContent.getContent();\r
+ } else if (ConfigModelConstant.MODEL_CONTENT_TYPE_TEMPLATE\r
+ .equals(configModelContent.getContentType())) {\r
+ context.put(ConfigModelConstant.PROPERTY_NODE_TEMPLATES_DOT + configModelContent.getName()\r
+ + ".content", configModelContent.getContent());\r
+ }\r
+ }\r
+ }\r
+ logger.trace("Service model data : {} ", content);\r
+ }\r
+ return content;\r
+ }\r
+\r
+}\r
--- /dev/null
+/*\r
+ * Copyright © 2017-2018 AT&T Intellectual Property.\r
+ * Modifications Copyright © 2018 IBM.\r
+ * \r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ * \r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ * \r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+\r
+package org.onap.ccsdk.config.model.service;\r
+\r
+import org.onap.ccsdk.sli.core.sli.SvcLogicJavaPlugin;\r
+\r
+public class ConfigModelNode implements SvcLogicJavaPlugin {\r
+\r
+}\r
--- /dev/null
+/*\r
+ * Copyright © 2017-2018 AT&T Intellectual Property.\r
+ * Modifications Copyright © 2018 IBM.\r
+ * \r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ * \r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ * \r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+\r
+package org.onap.ccsdk.config.model.service;\r
+\r
+import java.util.List;\r
+import java.util.Map;\r
+import org.onap.ccsdk.config.model.data.ServiceTemplate;\r
+import org.onap.ccsdk.sli.core.sli.SvcLogicContext;\r
+import org.onap.ccsdk.sli.core.sli.SvcLogicException;\r
+\r
+public interface ConfigModelService {\r
+\r
+ public Boolean validateServiceTemplate(ServiceTemplate serviceTemplate) throws SvcLogicException;\r
+\r
+ public Map<String, String> prepareContext(Map<String, String> context, String input, String serviceTemplateName,\r
+ String serviceTemplateVersion) throws SvcLogicException;\r
+\r
+ public Map<String, String> prepareContext(Map<String, String> context, String input, String serviceTemplateContent)\r
+ throws SvcLogicException;\r
+\r
+ public Map<String, String> convertJson2properties(Map<String, String> context, String jsonContent,\r
+ List<String> blockKeys) throws SvcLogicException;\r
+\r
+ public Map<String, String> convertServiceTemplate2Properties(String serviceTemplateContent,\r
+ final Map<String, String> context) throws SvcLogicException;\r
+\r
+ public Map<String, String> convertServiceTemplate2Properties(ServiceTemplate serviceTemplate,\r
+ final Map<String, String> context) throws SvcLogicException;\r
+\r
+ public SvcLogicContext assignInParamsFromModel(final SvcLogicContext context, final Map<String, String> inParams)\r
+ throws SvcLogicException;\r
+\r
+ public SvcLogicContext assignOutParamsFromModel(final SvcLogicContext context, final Map<String, String> inParams)\r
+ throws SvcLogicException;\r
+\r
+ public String getNodeTemplateContent(final SvcLogicContext context, String templateName) throws SvcLogicException;\r
+\r
+ public String getNodeTemplateMapping(final SvcLogicContext context, String templateName) throws SvcLogicException;\r
+\r
+}\r
--- /dev/null
+/*\r
+ * Copyright © 2017-2018 AT&T Intellectual Property.\r
+ * Modifications Copyright © 2018 IBM.\r
+ * \r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ * \r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ * \r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+\r
+package org.onap.ccsdk.config.model.service;\r
+\r
+import java.util.List;\r
+import java.util.Map;\r
+import org.apache.commons.lang3.StringUtils;\r
+import org.onap.ccsdk.config.model.ConfigModelConstant;\r
+import org.onap.ccsdk.config.model.ConfigModelException;\r
+import org.onap.ccsdk.config.model.data.CapabilityAssignment;\r
+import org.onap.ccsdk.config.model.data.NodeTemplate;\r
+import org.onap.ccsdk.config.model.data.NodeType;\r
+import org.onap.ccsdk.config.model.data.ServiceTemplate;\r
+import org.onap.ccsdk.config.model.utils.NodePropertyUtils;\r
+import org.onap.ccsdk.config.model.utils.PrepareContextUtils;\r
+import org.onap.ccsdk.config.model.utils.ServiceTemplateUtils;\r
+import org.onap.ccsdk.config.model.utils.TransformationUtils;\r
+import org.onap.ccsdk.config.model.validator.ServiceTemplateValidator;\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 ConfigModelServiceImpl implements ConfigModelService {\r
+\r
+ private static EELFLogger logger = EELFManager.getInstance().getLogger(ConfigModelServiceImpl.class);\r
+ private static final String CLASS_NAME = "ConfigModelServiceImpl";\r
+\r
+ private final ConfigRestAdaptorService configRestAdaptorService;\r
+\r
+ public ConfigModelServiceImpl(ConfigRestAdaptorService configRestAdaptorService) {\r
+ logger.info("{} Constuctor Initated...", CLASS_NAME);\r
+ this.configRestAdaptorService = configRestAdaptorService;\r
+ }\r
+\r
+ @Override\r
+ public Boolean validateServiceTemplate(ServiceTemplate serviceTemplate) throws SvcLogicException {\r
+ try {\r
+ ServiceTemplateValidator serviceTemplateValidator = new ServiceTemplateValidator();\r
+ return serviceTemplateValidator.validateServiceTemplate(serviceTemplate);\r
+ } catch (ConfigModelException e) {\r
+ throw new SvcLogicException(e.getMessage());\r
+ }\r
+ }\r
+\r
+ @Override\r
+ public Map<String, String> prepareContext(Map<String, String> context, String input, String serviceTemplateName,\r
+ String serviceTemplateVersion) throws SvcLogicException {\r
+\r
+ ConfigBlueprintService configBlueprintService = new ConfigBlueprintService(configRestAdaptorService);\r
+ return configBlueprintService.prepareContext(context, input, serviceTemplateName, serviceTemplateVersion);\r
+ }\r
+\r
+ @Override\r
+ public Map<String, String> prepareContext(Map<String, String> context, String input, String serviceTemplateContent)\r
+ throws SvcLogicException {\r
+ try {\r
+ PrepareContextUtils prepareContextUtils = new PrepareContextUtils();\r
+ return prepareContextUtils.prepareContext(context, input, serviceTemplateContent);\r
+ } catch (Exception e) {\r
+ throw new SvcLogicException(e.getMessage());\r
+ }\r
+ }\r
+\r
+ @Override\r
+ public Map<String, String> convertJson2properties(Map<String, String> context, String jsonContent,\r
+ List<String> blockKeys) throws SvcLogicException {\r
+ try {\r
+ return TransformationUtils.convertJson2Properties(context, jsonContent, blockKeys);\r
+ } catch (Exception e) {\r
+ throw new SvcLogicException(e.getMessage());\r
+ }\r
+ }\r
+\r
+ @Override\r
+ public Map<String, String> convertServiceTemplate2Properties(String serviceTemplateContent,\r
+ final Map<String, String> context) throws SvcLogicException {\r
+ try {\r
+ ServiceTemplateUtils serviceTemplateUtils = new ServiceTemplateUtils();\r
+ return serviceTemplateUtils.convertServiceTemplate2Properties(serviceTemplateContent, context);\r
+ } catch (Exception e) {\r
+ throw new SvcLogicException(e.getMessage());\r
+ }\r
+ }\r
+\r
+ @Override\r
+ public Map<String, String> convertServiceTemplate2Properties(ServiceTemplate serviceTemplate,\r
+ final Map<String, String> context) throws SvcLogicException {\r
+ try {\r
+ ServiceTemplateUtils serviceTemplateUtils = new ServiceTemplateUtils();\r
+ return serviceTemplateUtils.convertServiceTemplate2Properties(serviceTemplate, context);\r
+ } catch (Exception e) {\r
+ throw new SvcLogicException(e.getMessage());\r
+ }\r
+ }\r
+\r
+ @SuppressWarnings("squid:S3776")\r
+ @Override\r
+ public SvcLogicContext assignInParamsFromModel(final SvcLogicContext context, final Map<String, String> inParams)\r
+ throws SvcLogicException {\r
+ logger.debug("Processing component input param ({})", inParams);\r
+ try {\r
+ if (context != null && inParams != null && inParams.containsKey(ConfigModelConstant.PROPERTY_SELECTOR)) {\r
+ String componentKey = inParams.get(ConfigModelConstant.PROPERTY_SELECTOR);\r
+ if (StringUtils.isNotBlank(componentKey)) {\r
+ String nodeTemplateContent =\r
+ context.getAttribute(ConfigModelConstant.PROPERTY_NODE_TEMPLATES_DOT + componentKey);\r
+ logger.info("Processing node template content ({})", nodeTemplateContent);\r
+ if (StringUtils.isNotBlank(nodeTemplateContent)) {\r
+ NodeTemplate nodeTemplate =\r
+ TransformationUtils.readValue(nodeTemplateContent, NodeTemplate.class);\r
+ if (nodeTemplate != null && StringUtils.isNotBlank(nodeTemplate.getType())) {\r
+ String nodeTypeContent = context\r
+ .getAttribute(ConfigModelConstant.PROPERTY_NODE_TYPES_DOT + nodeTemplate.getType());\r
+ NodeType nodetype = TransformationUtils.readValue(nodeTypeContent, NodeType.class);\r
+ if (nodetype != null) {\r
+ inParams.put(ConfigModelConstant.PROPERTY_CURRENT_NODETYPE_DERIVED_FROM,\r
+ nodetype.getDerivedFrom());\r
+ NodePropertyUtils nodePropertyUtils = new NodePropertyUtils(context, inParams);\r
+ nodePropertyUtils.assignInParamsFromModel(nodetype, nodeTemplate);\r
+ } else {\r
+ throw new SvcLogicException(\r
+ String.format("Failed to get node type (%s) for node template (%s).",\r
+ nodeTemplate.getType(), componentKey));\r
+ }\r
+\r
+ } else {\r
+ throw new SvcLogicException(String\r
+ .format("Failed to convert content (%s) to node template.", nodeTemplateContent));\r
+ }\r
+ } else {\r
+ throw new SvcLogicException(String\r
+ .format("Couldn't get node template content for component key (%s).", componentKey));\r
+ }\r
+ } else {\r
+ throw new SvcLogicException(\r
+ String.format("Couldn't get component key (prefix) from inparam (%s)", inParams));\r
+ }\r
+ }\r
+ } catch (Exception e) {\r
+ throw new SvcLogicException(e.getMessage());\r
+ }\r
+ return context;\r
+ }\r
+\r
+ @Override\r
+ public SvcLogicContext assignOutParamsFromModel(final SvcLogicContext context, final Map<String, String> inParams)\r
+ throws SvcLogicException {\r
+ try {\r
+ if (context != null && inParams != null && inParams.containsKey(ConfigModelConstant.PROPERTY_SELECTOR)) {\r
+ String componentKey = inParams.get(ConfigModelConstant.PROPERTY_SELECTOR);\r
+ logger.info("Processing component output for prefix key ({})", componentKey);\r
+ if (StringUtils.isNotBlank(componentKey)) {\r
+ String nodeTemplateContent =\r
+ context.getAttribute(ConfigModelConstant.PROPERTY_NODE_TEMPLATES_DOT + componentKey);\r
+ if (StringUtils.isNotBlank(nodeTemplateContent)) {\r
+ NodeTemplate nodeTemplate =\r
+ TransformationUtils.readValue(nodeTemplateContent, NodeTemplate.class);\r
+ if (nodeTemplate != null && StringUtils.isNotBlank(nodeTemplate.getType())) {\r
+ String nodeTypeContent = context\r
+ .getAttribute(ConfigModelConstant.PROPERTY_NODE_TYPES_DOT + nodeTemplate.getType());\r
+ NodeType nodetype = TransformationUtils.readValue(nodeTypeContent, NodeType.class);\r
+ NodePropertyUtils nodePropertyUtils = new NodePropertyUtils(context, inParams);\r
+ nodePropertyUtils.assignOutParamsFromModel(nodetype, nodeTemplate);\r
+ }\r
+ }\r
+ }\r
+ }\r
+ } catch (Exception e) {\r
+ throw new SvcLogicException(e.getMessage());\r
+ }\r
+ return context;\r
+ }\r
+\r
+ @Override\r
+ public String getNodeTemplateContent(final SvcLogicContext context, String templateName) throws SvcLogicException {\r
+ String content = null;\r
+ try {\r
+ if (context != null && StringUtils.isNotBlank(templateName)) {\r
+ logger.info("Processing Artifact Node Template for content : ({})", templateName);\r
+ content = context\r
+ .getAttribute(ConfigModelConstant.PROPERTY_NODE_TEMPLATES_DOT + templateName + ".content");\r
+ }\r
+ } catch (Exception e) {\r
+ throw new SvcLogicException(e.getMessage());\r
+ }\r
+ return content;\r
+ }\r
+\r
+ @SuppressWarnings("squid:S3776")\r
+ @Override\r
+ public String getNodeTemplateMapping(final SvcLogicContext context, String templateName) throws SvcLogicException {\r
+ String mapping = null;\r
+ try {\r
+ if (context != null && StringUtils.isNotBlank(templateName)) {\r
+ logger.info("Processing artifact node template for mapping : ({})", templateName);\r
+ if (StringUtils.isNotBlank(templateName)) {\r
+ String nodeTemplateContent =\r
+ context.getAttribute(ConfigModelConstant.PROPERTY_NODE_TEMPLATES_DOT + templateName);\r
+ if (StringUtils.isNotBlank(nodeTemplateContent)) {\r
+\r
+ NodeTemplate nodeTemplate =\r
+ TransformationUtils.readValue(nodeTemplateContent, NodeTemplate.class);\r
+\r
+ if (nodeTemplate != null && nodeTemplate.getCapabilities() != null && nodeTemplate\r
+ .getCapabilities().containsKey(ConfigModelConstant.CAPABILITY_PROPERTY_MAPPING)) {\r
+\r
+ CapabilityAssignment capability =\r
+ nodeTemplate.getCapabilities().get(ConfigModelConstant.CAPABILITY_PROPERTY_MAPPING);\r
+ if (capability.getProperties() != null) {\r
+ List mappingList = (List) capability.getProperties()\r
+ .get(ConfigModelConstant.CAPABILITY_PROPERTY_MAPPING);\r
+ if (mappingList != null) {\r
+ mapping = TransformationUtils.getJson(mappingList);\r
+ }\r
+\r
+ }\r
+ }\r
+ }\r
+ }\r
+ }\r
+ } catch (Exception e) {\r
+ throw new SvcLogicException(e.getMessage());\r
+ }\r
+ return mapping;\r
+ }\r
+\r
+}\r