2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 ONAP
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.onap.ccsdk.sli.core.sli.provider;
23 import java.util.HashMap;
24 import java.util.Iterator;
28 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
29 import org.onap.ccsdk.sli.core.sli.SvcLogicException;
30 import org.onap.ccsdk.sli.core.sli.SvcLogicExpression;
31 import org.onap.ccsdk.sli.core.sli.SvcLogicNode;
32 import org.onap.ccsdk.sli.core.sli.SvcLogicResource;
33 import org.slf4j.Logger;
34 import org.slf4j.LoggerFactory;
36 public class UpdateNodeExecutor extends SvcLogicNodeExecutor {
38 private static final Logger LOG = LoggerFactory
39 .getLogger(UpdateNodeExecutor.class);
42 public SvcLogicNode execute(SvcLogicServiceImpl svc, SvcLogicNode node,
43 SvcLogicContext ctx) throws SvcLogicException {
45 String plugin = SvcLogicExpressionResolver.evaluate(
46 node.getAttribute("plugin"), node, ctx);
47 String resourceType = SvcLogicExpressionResolver.evaluate(
48 node.getAttribute("resource"), node, ctx);
49 String key = SvcLogicExpressionResolver.evaluateAsKey(
50 node.getAttribute("key"), node, ctx);
51 String pfx = SvcLogicExpressionResolver.evaluate(
52 node.getAttribute("pfx"), node, ctx);
55 Map<String, String> parmMap = new HashMap<String, String>();
57 Set<Map.Entry<String, SvcLogicExpression>> parmSet = node
59 boolean hasParms = false;
61 for (Iterator<Map.Entry<String, SvcLogicExpression>> iter = parmSet
62 .iterator(); iter.hasNext();) {
64 Map.Entry<String, SvcLogicExpression> curEnt = iter.next();
65 String curName = curEnt.getKey();
66 SvcLogicExpression curExpr = curEnt.getValue();
67 if (curExpr != null) {
68 String curExprValue = SvcLogicExpressionResolver.evaluate(
71 LOG.debug("Parameter " + curName + " = "
72 + curExpr.asParsedExpr() + " resolves to "
75 parmMap.put(curName, curExprValue);
79 String outValue = "failure";
81 if (LOG.isDebugEnabled()) {
82 LOG.debug("save node encountered - looking for resource class "
87 SvcLogicResource resourcePlugin = getSvcLogicResource(plugin);
90 if (resourcePlugin != null) {
93 switch (resourcePlugin.update(resourceType, key,
99 outValue = "not-found";
103 outValue = "failure";
105 } catch (SvcLogicException e) {
106 LOG.error("Caught exception from resource plugin", e);
107 outValue = "failure";
110 LOG.warn("Could not find SvcLogicResource object for plugin "
114 SvcLogicNode nextNode = node.getOutcomeValue(outValue);
115 if (nextNode != null) {
116 if (LOG.isDebugEnabled()) {
117 LOG.debug("about to execute " + outValue + " branch");
122 nextNode = node.getOutcomeValue("Other");
123 if (nextNode != null) {
124 if (LOG.isDebugEnabled()) {
125 LOG.debug("about to execute Other branch");
128 if (LOG.isDebugEnabled()) {
129 LOG.debug("no "+outValue+" or Other branch found");