2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
22 package org.openecomp.sdnc.sli.provider;
24 import java.util.HashMap;
25 import java.util.Iterator;
29 import org.openecomp.sdnc.sli.SvcLogicContext;
30 import org.openecomp.sdnc.sli.SvcLogicException;
31 import org.openecomp.sdnc.sli.SvcLogicExpression;
32 import org.openecomp.sdnc.sli.SvcLogicNode;
33 import org.openecomp.sdnc.sli.SvcLogicResource;
34 import org.osgi.framework.BundleContext;
35 import org.osgi.framework.FrameworkUtil;
36 import org.osgi.framework.ServiceReference;
37 import org.slf4j.Logger;
38 import org.slf4j.LoggerFactory;
40 public class UpdateNodeExecutor extends SvcLogicNodeExecutor {
42 private static final Logger LOG = LoggerFactory
43 .getLogger(UpdateNodeExecutor.class);
46 public SvcLogicNode execute(SvcLogicServiceImpl svc, SvcLogicNode node,
47 SvcLogicContext ctx) throws SvcLogicException {
49 String plugin = SvcLogicExpressionResolver.evaluate(
50 node.getAttribute("plugin"), node, ctx);
51 String resourceType = SvcLogicExpressionResolver.evaluate(
52 node.getAttribute("resource"), node, ctx);
53 String key = SvcLogicExpressionResolver.evaluateAsKey(
54 node.getAttribute("key"), node, ctx);
55 String pfx = SvcLogicExpressionResolver.evaluate(
56 node.getAttribute("pfx"), node, ctx);
59 Map<String, String> parmMap = new HashMap<String, String>();
61 Set<Map.Entry<String, SvcLogicExpression>> parmSet = node
63 boolean hasParms = false;
65 for (Iterator<Map.Entry<String, SvcLogicExpression>> iter = parmSet
66 .iterator(); iter.hasNext();) {
68 Map.Entry<String, SvcLogicExpression> curEnt = iter.next();
69 String curName = curEnt.getKey();
70 SvcLogicExpression curExpr = curEnt.getValue();
71 if (curExpr != null) {
72 String curExprValue = SvcLogicExpressionResolver.evaluate(
75 LOG.debug("Parameter " + curName + " = "
76 + curExpr.asParsedExpr() + " resolves to "
79 parmMap.put(curName, curExprValue);
83 String outValue = "failure";
85 if (LOG.isDebugEnabled()) {
86 LOG.debug("save node encountered - looking for resource class "
91 SvcLogicResource resourcePlugin = getSvcLogicResource(plugin);
94 if (resourcePlugin != null) {
97 switch (resourcePlugin.update(resourceType, key,
100 outValue = "success";
103 outValue = "not-found";
107 outValue = "failure";
109 } catch (SvcLogicException e) {
110 LOG.error("Caught exception from resource plugin", e);
111 outValue = "failure";
114 LOG.warn("Could not find SvcLogicResource object for plugin "
118 SvcLogicNode nextNode = node.getOutcomeValue(outValue);
119 if (nextNode != null) {
120 if (LOG.isDebugEnabled()) {
121 LOG.debug("about to execute " + outValue + " branch");
126 nextNode = node.getOutcomeValue("Other");
127 if (nextNode != null) {
128 if (LOG.isDebugEnabled()) {
129 LOG.debug("about to execute Other branch");
132 if (LOG.isDebugEnabled()) {
133 LOG.debug("no "+outValue+" or Other branch found");
139 protected SvcLogicResource getSvcLogicResource(String plugin) {
140 BundleContext bctx = FrameworkUtil.getBundle(this.getClass())
143 ServiceReference sref = bctx.getServiceReference(plugin);
145 SvcLogicResource resourcePlugin = (SvcLogicResource) bctx
147 return resourcePlugin;
150 LOG.warn("Could not find service reference object for plugin " + plugin);