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.slf4j.Logger;
35 import org.slf4j.LoggerFactory;
37 public class UpdateNodeExecutor extends SvcLogicNodeExecutor {
39 private static final Logger LOG = LoggerFactory
40 .getLogger(UpdateNodeExecutor.class);
43 public SvcLogicNode execute(SvcLogicServiceImpl svc, SvcLogicNode node,
44 SvcLogicContext ctx) throws SvcLogicException {
46 String plugin = SvcLogicExpressionResolver.evaluate(
47 node.getAttribute("plugin"), node, ctx);
48 String resourceType = SvcLogicExpressionResolver.evaluate(
49 node.getAttribute("resource"), node, ctx);
50 String key = SvcLogicExpressionResolver.evaluateAsKey(
51 node.getAttribute("key"), node, ctx);
52 String pfx = SvcLogicExpressionResolver.evaluate(
53 node.getAttribute("pfx"), node, ctx);
56 Map<String, String> parmMap = new HashMap<String, String>();
58 Set<Map.Entry<String, SvcLogicExpression>> parmSet = node
60 boolean hasParms = false;
62 for (Iterator<Map.Entry<String, SvcLogicExpression>> iter = parmSet
63 .iterator(); iter.hasNext();) {
65 Map.Entry<String, SvcLogicExpression> curEnt = iter.next();
66 String curName = curEnt.getKey();
67 SvcLogicExpression curExpr = curEnt.getValue();
68 if (curExpr != null) {
69 String curExprValue = SvcLogicExpressionResolver.evaluate(
72 LOG.debug("Parameter " + curName + " = "
73 + curExpr.asParsedExpr() + " resolves to "
76 parmMap.put(curName, curExprValue);
80 String outValue = "failure";
82 if (LOG.isDebugEnabled()) {
83 LOG.debug("save node encountered - looking for resource class "
88 SvcLogicResource resourcePlugin = getSvcLogicResource(plugin);
91 if (resourcePlugin != null) {
94 switch (resourcePlugin.update(resourceType, key,
100 outValue = "not-found";
104 outValue = "failure";
106 } catch (SvcLogicException e) {
107 LOG.error("Caught exception from resource plugin", e);
108 outValue = "failure";
111 LOG.warn("Could not find SvcLogicResource object for plugin "
115 SvcLogicNode nextNode = node.getOutcomeValue(outValue);
116 if (nextNode != null) {
117 if (LOG.isDebugEnabled()) {
118 LOG.debug("about to execute " + outValue + " branch");
123 nextNode = node.getOutcomeValue("Other");
124 if (nextNode != null) {
125 if (LOG.isDebugEnabled()) {
126 LOG.debug("about to execute Other branch");
129 if (LOG.isDebugEnabled()) {
130 LOG.debug("no "+outValue+" or Other branch found");