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 = SvcLogicAdaptorFactory
54 .getInstance(adaptorName);
56 if (adaptor != null) {
57 String activate = SvcLogicExpressionResolver.evaluate(
58 node.getAttribute("activate"), node, ctx);
59 String key = SvcLogicExpressionResolver.evaluate(
60 node.getAttribute("key"), node, ctx);
62 Map<String, String> parmMap = new HashMap<String, String>();
64 Set<Map.Entry<String, SvcLogicExpression>> parmSet = node
66 boolean hasParms = false;
68 for (Iterator<Map.Entry<String, SvcLogicExpression>> iter = parmSet
69 .iterator(); iter.hasNext();) {
71 Map.Entry<String, SvcLogicExpression> curEnt = iter.next();
72 String curName = curEnt.getKey();
73 SvcLogicExpression curExpr = curEnt.getValue();
74 String curExprValue = SvcLogicExpressionResolver.evaluate(curExpr, node, ctx);
76 LOG.debug("Parameter "+curName+" = "+curExpr.asParsedExpr()+" resolves to "+curExprValue);
78 parmMap.put(curName,curExprValue);
82 SvcLogicAdaptor.ConfigStatus confStatus = SvcLogicAdaptor.ConfigStatus.FAILURE;
85 confStatus = adaptor.configure(key, parmMap, ctx);
86 } catch (Exception e) {
87 LOG.warn("Caught exception from "+adaptorName+".configure", e);
88 confStatus = SvcLogicAdaptor.ConfigStatus.FAILURE;
94 if ((activate != null) && (activate.length() > 0)) {
95 if ("true".equalsIgnoreCase(activate)) {
96 SvcLogicAdaptor.ConfigStatus activateStatus = SvcLogicAdaptor.ConfigStatus.FAILURE;
99 activateStatus = adaptor.activate(key, ctx);
100 } catch (Exception e) {
102 LOG.warn("Caught exception from "+adaptorName+".activate", e);
103 activateStatus = SvcLogicAdaptor.ConfigStatus.FAILURE;
105 switch (activateStatus) {
109 outValue = "already-active";
112 outValue = "not-found";
115 outValue = "not-ready";
119 outValue = "failure";
121 } else if ("false".equalsIgnoreCase(activate)) {
122 SvcLogicAdaptor.ConfigStatus deactivateStatus = SvcLogicAdaptor.ConfigStatus.FAILURE;
125 deactivateStatus = adaptor.deactivate(key, ctx);
126 } catch (Exception e) {
128 LOG.warn("Caught exception from "+adaptorName+".deactivate", e);
129 deactivateStatus = SvcLogicAdaptor.ConfigStatus.FAILURE;
131 switch (deactivateStatus) {
135 outValue = "already-active";
138 outValue = "not-found";
141 outValue = "not-ready";
145 outValue = "failure";
151 outValue = "already-active";
154 outValue = "not-found";
157 outValue = "not-ready";
161 outValue = "failure";
164 if ((activate != null) && (activate.length() > 0)) {
165 if ("true".equalsIgnoreCase(activate)) {
166 SvcLogicAdaptor.ConfigStatus activateStatus = SvcLogicAdaptor.ConfigStatus.FAILURE;
168 activateStatus = adaptor.activate(key, ctx);
169 } catch (Exception e) {
170 LOG.warn("Caught exception from "+adaptorName+".activate", e);
171 activateStatus = SvcLogicAdaptor.ConfigStatus.FAILURE;
173 switch (activateStatus) {
175 outValue = "success";
178 outValue = "already-active";
181 outValue = "not-found";
184 outValue = "not-ready";
188 outValue = "failure";
190 } else if ("false".equalsIgnoreCase(activate)) {
191 SvcLogicAdaptor.ConfigStatus deactivateStatus = SvcLogicAdaptor.ConfigStatus.FAILURE;
194 deactivateStatus = adaptor.deactivate(key, ctx);
195 } catch (Exception e) {
196 LOG.warn("Caught exception from "+adaptorName+".deactivate", e);
197 deactivateStatus = SvcLogicAdaptor.ConfigStatus.FAILURE;
199 switch (deactivateStatus) {
201 outValue = "success";
204 outValue = "already-active";
207 outValue = "not-found";
210 outValue = "not-ready";
214 outValue = "failure";
218 LOG.warn("Nothing to configure - no parameters passed, and activate attribute is not set");
219 outValue = "success";
223 if (LOG.isWarnEnabled()) {
224 LOG.warn("Adaptor for " + adaptorName + " not found");
228 SvcLogicNode nextNode = node.getOutcomeValue(outValue);
229 if (nextNode != null) {
230 if (LOG.isDebugEnabled()) {
231 LOG.debug("about to execute " + outValue + " branch");
236 nextNode = node.getOutcomeValue("Other");
237 if (nextNode != null) {
238 if (LOG.isDebugEnabled()) {
239 LOG.debug("about to execute Other branch");
242 if (LOG.isDebugEnabled()) {
243 LOG.debug("no " + outValue + " or Other branch found");