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.onap.ccsdk.sli.core.sli.provider.base;
24 import java.util.HashMap;
25 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 SaveNodeExecutor extends AbstractSvcLogicNodeExecutor {
38 private static final Logger LOG = LoggerFactory.getLogger(SaveNodeExecutor.class);
41 public SvcLogicNode execute(SvcLogicServiceBase svc, SvcLogicNode node, SvcLogicContext ctx)
42 throws SvcLogicException {
44 String plugin = SvcLogicExpressionResolver.evaluate(node.getAttribute("plugin"), node, ctx);
45 String resourceType = SvcLogicExpressionResolver.evaluate(node.getAttribute("resource"), node, ctx);
46 String key = SvcLogicExpressionResolver.evaluateAsKey(node.getAttribute("key"), node, ctx);
47 String forceStr = SvcLogicExpressionResolver.evaluate(node.getAttribute("force"), node, ctx);
48 String localOnlyStr = SvcLogicExpressionResolver.evaluate(node.getAttribute("local-only"), node, ctx);
49 String pfx = SvcLogicExpressionResolver.evaluate(node.getAttribute("pfx"), node, ctx);
51 boolean force = "true".equalsIgnoreCase(forceStr);
52 boolean localOnly = "true".equalsIgnoreCase(localOnlyStr);
54 Map<String, String> parmMap = new HashMap<String, String>();
56 Set<Map.Entry<String, SvcLogicExpression>> parmSet = node.getParameterSet();
57 boolean hasParms = false;
59 for (Iterator<Map.Entry<String, SvcLogicExpression>> iter = parmSet.iterator(); iter.hasNext();) {
61 Map.Entry<String, SvcLogicExpression> curEnt = iter.next();
62 String curName = curEnt.getKey();
63 SvcLogicExpression curExpr = curEnt.getValue();
64 if (curExpr != null) {
65 String curExprValue = SvcLogicExpressionResolver.evaluate(curExpr, node, ctx);
67 LOG.debug("Parameter " + curName + " = " + curExpr.asParsedExpr() + " resolves to " + curExprValue);
69 parmMap.put(curName, curExprValue);
73 String outValue = "failure";
75 if (LOG.isDebugEnabled()) {
76 LOG.debug("save node encountered - looking for resource class " + plugin);
81 SvcLogicResource resourcePlugin = getSvcLogicResource(plugin);
83 if (resourcePlugin != null) {
86 switch (resourcePlugin.save(resourceType, force, localOnly, key, parmMap, pfx, ctx)) {
91 outValue = "not-found";
97 } catch (SvcLogicException e) {
98 LOG.error("Caught exception from resource plugin", e);
102 LOG.warn("Could not find SvcLogicResource object for plugin " + plugin);
104 return (getNextNode(node, outValue));