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.SvcLogicAdaptor;
30 import org.openecomp.sdnc.sli.SvcLogicContext;
31 import org.openecomp.sdnc.sli.SvcLogicException;
32 import org.openecomp.sdnc.sli.SvcLogicExpression;
33 import org.openecomp.sdnc.sli.SvcLogicNode;
34 import org.slf4j.Logger;
35 import org.slf4j.LoggerFactory;
37 public class ConfigureNodeExecutor extends SvcLogicNodeExecutor {
38 private static final Logger LOG = LoggerFactory
39 .getLogger(ConfigureNodeExecutor.class);
41 public SvcLogicNode execute(SvcLogicServiceImpl svc, SvcLogicNode node,
42 SvcLogicContext ctx) throws SvcLogicException {
44 String adaptorName = SvcLogicExpressionResolver.evaluate(
45 node.getAttribute("adaptor"), node, ctx);
46 String outValue = "failure";
48 if (LOG.isDebugEnabled()) {
49 LOG.debug("configure node encountered - looking for adaptor "
53 SvcLogicAdaptor adaptor = getAdaptor(adaptorName);
55 if (adaptor != null) {
56 String activate = SvcLogicExpressionResolver.evaluate(
57 node.getAttribute("activate"), node, ctx);
58 String key = SvcLogicExpressionResolver.evaluate(
59 node.getAttribute("key"), node, ctx);
61 Map<String, String> parmMap = new HashMap<String, String>();
63 Set<Map.Entry<String, SvcLogicExpression>> parmSet = node
65 boolean hasParms = false;
67 for (Iterator<Map.Entry<String, SvcLogicExpression>> iter = parmSet
68 .iterator(); iter.hasNext();) {
70 Map.Entry<String, SvcLogicExpression> curEnt = iter.next();
71 String curName = curEnt.getKey();
72 SvcLogicExpression curExpr = curEnt.getValue();
73 String curExprValue = SvcLogicExpressionResolver.evaluate(curExpr, node, ctx);
75 LOG.debug("Parameter "+curName+" = "+curExpr.asParsedExpr()+" resolves to "+curExprValue);
77 parmMap.put(curName,curExprValue);
81 SvcLogicAdaptor.ConfigStatus confStatus = SvcLogicAdaptor.ConfigStatus.FAILURE;
84 confStatus = adaptor.configure(key, parmMap, ctx);
85 } catch (Exception e) {
86 LOG.warn("Caught exception from "+adaptorName+".configure", e);
87 confStatus = SvcLogicAdaptor.ConfigStatus.FAILURE;
93 if ((activate != null) && (activate.length() > 0)) {
94 if ("true".equalsIgnoreCase(activate)) {
95 SvcLogicAdaptor.ConfigStatus activateStatus = SvcLogicAdaptor.ConfigStatus.FAILURE;
98 activateStatus = adaptor.activate(key, ctx);
99 } catch (Exception e) {
101 LOG.warn("Caught exception from "+adaptorName+".activate", e);
102 activateStatus = SvcLogicAdaptor.ConfigStatus.FAILURE;
104 switch (activateStatus) {
108 outValue = "already-active";
111 outValue = "not-found";
114 outValue = "not-ready";
118 outValue = "failure";
120 } else if ("false".equalsIgnoreCase(activate)) {
121 SvcLogicAdaptor.ConfigStatus deactivateStatus = SvcLogicAdaptor.ConfigStatus.FAILURE;
124 deactivateStatus = adaptor.deactivate(key, ctx);
125 } catch (Exception e) {
127 LOG.warn("Caught exception from "+adaptorName+".deactivate", e);
128 deactivateStatus = SvcLogicAdaptor.ConfigStatus.FAILURE;
130 switch (deactivateStatus) {
134 outValue = "already-active";
137 outValue = "not-found";
140 outValue = "not-ready";
144 outValue = "failure";
150 outValue = "already-active";
153 outValue = "not-found";
156 outValue = "not-ready";
160 outValue = "failure";
163 if ((activate != null) && (activate.length() > 0)) {
164 if ("true".equalsIgnoreCase(activate)) {
165 SvcLogicAdaptor.ConfigStatus activateStatus = SvcLogicAdaptor.ConfigStatus.FAILURE;
167 activateStatus = adaptor.activate(key, ctx);
168 } catch (Exception e) {
169 LOG.warn("Caught exception from "+adaptorName+".activate", e);
170 activateStatus = SvcLogicAdaptor.ConfigStatus.FAILURE;
172 switch (activateStatus) {
174 outValue = "success";
177 outValue = "already-active";
180 outValue = "not-found";
183 outValue = "not-ready";
187 outValue = "failure";
189 } else if ("false".equalsIgnoreCase(activate)) {
190 SvcLogicAdaptor.ConfigStatus deactivateStatus = SvcLogicAdaptor.ConfigStatus.FAILURE;
193 deactivateStatus = adaptor.deactivate(key, ctx);
194 } catch (Exception e) {
195 LOG.warn("Caught exception from "+adaptorName+".deactivate", e);
196 deactivateStatus = SvcLogicAdaptor.ConfigStatus.FAILURE;
198 switch (deactivateStatus) {
200 outValue = "success";
203 outValue = "already-active";
206 outValue = "not-found";
209 outValue = "not-ready";
213 outValue = "failure";
217 LOG.warn("Nothing to configure - no parameters passed, and activate attribute is not set");
218 outValue = "success";
222 if (LOG.isWarnEnabled()) {
223 LOG.warn("Adaptor for " + adaptorName + " not found");
227 SvcLogicNode nextNode = node.getOutcomeValue(outValue);
228 if (nextNode != null) {
229 if (LOG.isDebugEnabled()) {
230 LOG.debug("about to execute " + outValue + " branch");
235 nextNode = node.getOutcomeValue("Other");
236 if (nextNode != null) {
237 if (LOG.isDebugEnabled()) {
238 LOG.debug("about to execute Other branch");
241 if (LOG.isDebugEnabled()) {
242 LOG.debug("no " + outValue + " or Other branch found");