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 org.openecomp.sdnc.sli.BreakNodeException;
25 import org.openecomp.sdnc.sli.SvcLogicContext;
26 import org.openecomp.sdnc.sli.SvcLogicException;
27 import org.openecomp.sdnc.sli.SvcLogicExpression;
28 import org.openecomp.sdnc.sli.SvcLogicNode;
29 import org.slf4j.Logger;
30 import org.slf4j.LoggerFactory;
32 public class ForNodeExecutor extends SvcLogicNodeExecutor {
34 private static final Logger LOG = LoggerFactory
35 .getLogger(ForNodeExecutor.class);
38 public SvcLogicNode execute(SvcLogicServiceImpl svc, SvcLogicNode node,
39 SvcLogicContext ctx) throws SvcLogicException {
41 SvcLogicExpression atomicExpr = node.getAttribute("atomic");
42 String atomicStr = SvcLogicExpressionResolver.evaluate(atomicExpr, node, ctx);
43 boolean isAtomic = !("false".equalsIgnoreCase(atomicStr));
45 int numOutcomes = node.getNumOutcomes();
46 String idxVar = SvcLogicExpressionResolver.evaluate(
47 node.getAttribute("index"), node, ctx);
48 String startVal = SvcLogicExpressionResolver.evaluate(
49 node.getAttribute("start"), node, ctx);
50 String endVal = SvcLogicExpressionResolver.evaluate(
51 node.getAttribute("end"), node, ctx);
53 LOG.debug("Executing "+ (isAtomic ? "atomic" : "non-atomic") + " for loop - for (int " + idxVar + " = " + startVal
54 + "; " + idxVar + " < " + endVal + "; " + idxVar + "++)");
60 startIdx = Integer.parseInt(startVal);
61 endIdx = Integer.parseInt(endVal);
62 } catch (NumberFormatException e) {
63 SvcLogicExpression silentFailureExpr = node.getAttribute("silentFailure");
64 String silentFailure = SvcLogicExpressionResolver.evaluate(silentFailureExpr, node, ctx);
65 boolean isSilentFailure = Boolean.parseBoolean(silentFailure);
66 String message = "Invalid index values [" + startVal + "," + endVal + "]";
68 throw new SvcLogicException(message);
70 LOG.debug(message + ". Not exiting because silentFailure was set to true.");
76 for (int ctr = startIdx; ctr < endIdx; ctr++) {
78 ctx.setAttribute(idxVar, "" + ctr);
80 for (int i = 0; i < numOutcomes; i++) {
82 if ("failure".equals(ctx.getStatus()) && isAtomic) {
83 LOG.info("For - stopped executing nodes due to failure status");
87 SvcLogicNode nextNode = node.getOutcomeValue("" + (i + 1));
88 if (nextNode != null) {
89 if (LOG.isDebugEnabled()) {
90 LOG.debug("For - executing outcome " + (i + 1));
92 SvcLogicNode innerNextNode = nextNode;
93 while (innerNextNode != null) {
94 innerNextNode = svc.executeNode(innerNextNode, ctx);
97 if (LOG.isDebugEnabled()) {
98 LOG.debug("For - done: no outcome " + (i + 1));
103 } catch (BreakNodeException br) {
104 LOG.debug("ForNodeExecutor caught break");