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.SvcLogicConstants;
33 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
34 import org.onap.ccsdk.sli.core.sli.SvcLogicException;
35 import org.onap.ccsdk.sli.core.sli.SvcLogicExpression;
36 import org.onap.ccsdk.sli.core.sli.SvcLogicNode;
37 import org.slf4j.Logger;
38 import org.slf4j.LoggerFactory;
40 public class ConfigureNodeExecutor extends AbstractSvcLogicNodeExecutor {
41 private static final Logger LOG = LoggerFactory
42 .getLogger(ConfigureNodeExecutor.class);
43 private static final String CAUGHT_EXCEPTION_MSG="Caught exception from ";
44 private static final String ALREADY_ACTIVE= "already-active";
45 private static final String NOT_FOUND= "not-found";
47 public SvcLogicNode execute(SvcLogicServiceBase svc, SvcLogicNode node,
48 SvcLogicContext ctx) throws SvcLogicException {
50 String adaptorName = SvcLogicExpressionResolver.evaluate(
51 node.getAttribute("adaptor"), node, ctx);
52 String outValue = SvcLogicConstants.FAILURE;
54 if (LOG.isDebugEnabled()) {
55 LOG.debug("configure node encountered - looking for adaptor "
59 SvcLogicAdaptor adaptor = getAdaptor(adaptorName);
61 if (adaptor != null) {
62 String activate = SvcLogicExpressionResolver.evaluate(
63 node.getAttribute("activate"), node, ctx);
64 String key = SvcLogicExpressionResolver.evaluate(
65 node.getAttribute("key"), node, ctx);
67 boolean hasParms = false;
69 Map<String, String> parmMap = getResolvedParameters(node,ctx);
70 if(!parmMap.isEmpty()) {
75 SvcLogicAdaptor.ConfigStatus confStatus = SvcLogicAdaptor.ConfigStatus.FAILURE;
78 confStatus = adaptor.configure(key, parmMap, ctx);
79 } catch (Exception e) {
80 LOG.warn(CAUGHT_EXCEPTION_MSG+adaptorName+".configure", e);
81 confStatus = SvcLogicAdaptor.ConfigStatus.FAILURE;
86 outValue = SvcLogicConstants.SUCCESS;
87 if ((activate != null) && (activate.length() > 0)) {
88 if ("true".equalsIgnoreCase(activate)) {
89 SvcLogicAdaptor.ConfigStatus activateStatus = SvcLogicAdaptor.ConfigStatus.FAILURE;
92 activateStatus = adaptor.activate(key, ctx);
93 } catch (Exception e) {
95 LOG.warn(CAUGHT_EXCEPTION_MSG+adaptorName+".activate", e);
96 activateStatus = SvcLogicAdaptor.ConfigStatus.FAILURE;
98 switch (activateStatus) {
102 outValue = ALREADY_ACTIVE;
105 outValue = NOT_FOUND;
108 outValue = "not-ready";
112 outValue = SvcLogicConstants.FAILURE;
114 } else if ("false".equalsIgnoreCase(activate)) {
115 SvcLogicAdaptor.ConfigStatus deactivateStatus = SvcLogicAdaptor.ConfigStatus.FAILURE;
118 deactivateStatus = adaptor.deactivate(key, ctx);
119 } catch (Exception e) {
121 LOG.warn(CAUGHT_EXCEPTION_MSG+adaptorName+".deactivate", e);
122 deactivateStatus = SvcLogicAdaptor.ConfigStatus.FAILURE;
124 switch (deactivateStatus) {
128 outValue = ALREADY_ACTIVE;
131 outValue = NOT_FOUND;
134 outValue = "not-ready";
138 outValue = SvcLogicConstants.FAILURE;
144 outValue = ALREADY_ACTIVE;
147 outValue = NOT_FOUND;
150 outValue = "not-ready";
154 outValue = SvcLogicConstants.FAILURE;
157 if ((activate != null) && (activate.length() > 0)) {
158 if ("true".equalsIgnoreCase(activate)) {
159 SvcLogicAdaptor.ConfigStatus activateStatus = SvcLogicAdaptor.ConfigStatus.FAILURE;
161 activateStatus = adaptor.activate(key, ctx);
162 } catch (Exception e) {
163 LOG.warn(CAUGHT_EXCEPTION_MSG+adaptorName+".activate", e);
164 activateStatus = SvcLogicAdaptor.ConfigStatus.FAILURE;
166 switch (activateStatus) {
168 outValue = SvcLogicConstants.SUCCESS;
171 outValue = ALREADY_ACTIVE;
174 outValue = NOT_FOUND;
177 outValue = "not-ready";
181 outValue = SvcLogicConstants.FAILURE;
183 } else if ("false".equalsIgnoreCase(activate)) {
184 SvcLogicAdaptor.ConfigStatus deactivateStatus = SvcLogicAdaptor.ConfigStatus.FAILURE;
187 deactivateStatus = adaptor.deactivate(key, ctx);
188 } catch (Exception e) {
189 LOG.warn(CAUGHT_EXCEPTION_MSG+adaptorName+".deactivate", e);
190 deactivateStatus = SvcLogicAdaptor.ConfigStatus.FAILURE;
192 switch (deactivateStatus) {
194 outValue = SvcLogicConstants.SUCCESS;
197 outValue = ALREADY_ACTIVE;
200 outValue = NOT_FOUND;
203 outValue = "not-ready";
207 outValue = SvcLogicConstants.FAILURE;
211 LOG.warn("Nothing to configure - no parameters passed, and activate attribute is not set");
212 outValue = SvcLogicConstants.SUCCESS;
216 if (LOG.isWarnEnabled()) {
217 LOG.warn("Adaptor for " + adaptorName + " not found");
221 SvcLogicNode nextNode = node.getOutcomeValue(outValue);
222 if (nextNode != null) {
223 if (LOG.isDebugEnabled()) {
224 LOG.debug("about to execute " + outValue + " branch");
229 nextNode = node.getOutcomeValue("Other");
230 if (nextNode != null) {
231 if (LOG.isDebugEnabled()) {
232 LOG.debug("about to execute Other branch");
235 if (LOG.isDebugEnabled()) {
236 LOG.debug("no " + outValue + " or Other branch found");