2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights
7 * ================================================================================
8 * Modifications Copyright (C) 2018 IBM.
9 * ================================================================================
10 * Licensed under the Apache License, Version 2.0 (the "License");
11 * you may not use this file except in compliance with the License.
12 * You may obtain a copy of the License at
14 * http://www.apache.org/licenses/LICENSE-2.0
16 * Unless required by applicable law or agreed to in writing, software
17 * distributed under the License is distributed on an "AS IS" BASIS,
18 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19 * See the License for the specific language governing permissions and
20 * limitations under the License.
21 * ============LICENSE_END=========================================================
24 package org.onap.ccsdk.sli.core.sli.provider.base;
26 import java.util.HashMap;
27 import java.util.Iterator;
31 import org.onap.ccsdk.sli.core.sli.SvcLogicAdaptor;
32 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
33 import org.onap.ccsdk.sli.core.sli.SvcLogicException;
34 import org.onap.ccsdk.sli.core.sli.SvcLogicExpression;
35 import org.onap.ccsdk.sli.core.sli.SvcLogicNode;
36 import org.slf4j.Logger;
37 import org.slf4j.LoggerFactory;
39 public class ConfigureNodeExecutor extends AbstractSvcLogicNodeExecutor {
40 private static final Logger LOG = LoggerFactory
41 .getLogger(ConfigureNodeExecutor.class);
42 private static final String CAUGHT_EXCEPTION_MSG="Caught exception from ";
43 private static final String ALREADY_ACTIVE= "already-active";
44 private static final String NOT_FOUND= "not-found";
46 public SvcLogicNode execute(SvcLogicServiceBase svc, SvcLogicNode node,
47 SvcLogicContext ctx) throws SvcLogicException {
49 String adaptorName = SvcLogicExpressionResolver.evaluate(
50 node.getAttribute("adaptor"), node, ctx);
51 String outValue = "failure";
53 if (LOG.isDebugEnabled()) {
54 LOG.debug("configure node encountered - looking for adaptor "
58 SvcLogicAdaptor adaptor = getAdaptor(adaptorName);
60 if (adaptor != null) {
61 String activate = SvcLogicExpressionResolver.evaluate(
62 node.getAttribute("activate"), node, ctx);
63 String key = SvcLogicExpressionResolver.evaluate(
64 node.getAttribute("key"), node, ctx);
66 boolean hasParms = false;
68 Map<String, String> parmMap = getResolvedParameters(node,ctx);
69 if(!parmMap.isEmpty()) {
74 SvcLogicAdaptor.ConfigStatus confStatus = SvcLogicAdaptor.ConfigStatus.FAILURE;
77 confStatus = adaptor.configure(key, parmMap, ctx);
78 } catch (Exception e) {
79 LOG.warn(CAUGHT_EXCEPTION_MSG+adaptorName+".configure", e);
80 confStatus = SvcLogicAdaptor.ConfigStatus.FAILURE;
86 if ((activate != null) && (activate.length() > 0)) {
87 if ("true".equalsIgnoreCase(activate)) {
88 SvcLogicAdaptor.ConfigStatus activateStatus = SvcLogicAdaptor.ConfigStatus.FAILURE;
91 activateStatus = adaptor.activate(key, ctx);
92 } catch (Exception e) {
94 LOG.warn(CAUGHT_EXCEPTION_MSG+adaptorName+".activate", e);
95 activateStatus = SvcLogicAdaptor.ConfigStatus.FAILURE;
97 switch (activateStatus) {
101 outValue = ALREADY_ACTIVE;
104 outValue = NOT_FOUND;
107 outValue = "not-ready";
111 outValue = "failure";
113 } else if ("false".equalsIgnoreCase(activate)) {
114 SvcLogicAdaptor.ConfigStatus deactivateStatus = SvcLogicAdaptor.ConfigStatus.FAILURE;
117 deactivateStatus = adaptor.deactivate(key, ctx);
118 } catch (Exception e) {
120 LOG.warn(CAUGHT_EXCEPTION_MSG+adaptorName+".deactivate", e);
121 deactivateStatus = SvcLogicAdaptor.ConfigStatus.FAILURE;
123 switch (deactivateStatus) {
127 outValue = ALREADY_ACTIVE;
130 outValue = NOT_FOUND;
133 outValue = "not-ready";
137 outValue = "failure";
143 outValue = ALREADY_ACTIVE;
146 outValue = NOT_FOUND;
149 outValue = "not-ready";
153 outValue = "failure";
156 if ((activate != null) && (activate.length() > 0)) {
157 if ("true".equalsIgnoreCase(activate)) {
158 SvcLogicAdaptor.ConfigStatus activateStatus = SvcLogicAdaptor.ConfigStatus.FAILURE;
160 activateStatus = adaptor.activate(key, ctx);
161 } catch (Exception e) {
162 LOG.warn(CAUGHT_EXCEPTION_MSG+adaptorName+".activate", e);
163 activateStatus = SvcLogicAdaptor.ConfigStatus.FAILURE;
165 switch (activateStatus) {
167 outValue = "success";
170 outValue = ALREADY_ACTIVE;
173 outValue = NOT_FOUND;
176 outValue = "not-ready";
180 outValue = "failure";
182 } else if ("false".equalsIgnoreCase(activate)) {
183 SvcLogicAdaptor.ConfigStatus deactivateStatus = SvcLogicAdaptor.ConfigStatus.FAILURE;
186 deactivateStatus = adaptor.deactivate(key, ctx);
187 } catch (Exception e) {
188 LOG.warn(CAUGHT_EXCEPTION_MSG+adaptorName+".deactivate", e);
189 deactivateStatus = SvcLogicAdaptor.ConfigStatus.FAILURE;
191 switch (deactivateStatus) {
193 outValue = "success";
196 outValue = ALREADY_ACTIVE;
199 outValue = NOT_FOUND;
202 outValue = "not-ready";
206 outValue = "failure";
210 LOG.warn("Nothing to configure - no parameters passed, and activate attribute is not set");
211 outValue = "success";
215 if (LOG.isWarnEnabled()) {
216 LOG.warn("Adaptor for " + adaptorName + " not found");
220 SvcLogicNode nextNode = node.getOutcomeValue(outValue);
221 if (nextNode != null) {
222 if (LOG.isDebugEnabled()) {
223 LOG.debug("about to execute " + outValue + " branch");
228 nextNode = node.getOutcomeValue("Other");
229 if (nextNode != null) {
230 if (LOG.isDebugEnabled()) {
231 LOG.debug("about to execute Other branch");
234 if (LOG.isDebugEnabled()) {
235 LOG.debug("no " + outValue + " or Other branch found");