Update groupId to org.onap.ccsdk.sli
[ccsdk/sli/core.git] / sli / provider / src / main / java / org / onap / ccsdk / sli / core / sli / provider / BlockNodeExecutor.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP : CCSDK
4  * ================================================================================
5  * Copyright (C) 2017 ONAP
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.ccsdk.sli.core.sli.provider;
22
23 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
24 import org.onap.ccsdk.sli.core.sli.SvcLogicException;
25 import org.onap.ccsdk.sli.core.sli.SvcLogicExpression;
26 import org.onap.ccsdk.sli.core.sli.SvcLogicNode;
27 import org.slf4j.Logger;
28 import org.slf4j.LoggerFactory;
29
30 public class BlockNodeExecutor extends SvcLogicNodeExecutor {
31
32         private static final Logger LOG = LoggerFactory
33                         .getLogger(BlockNodeExecutor.class);
34         
35         @Override
36         public SvcLogicNode execute(SvcLogicServiceImpl svc, SvcLogicNode node, SvcLogicContext ctx)
37                         throws SvcLogicException {
38
39                 SvcLogicExpression atomicExpr = node.getAttribute("atomic");
40                 String atomicStr = SvcLogicExpressionResolver.evaluate(atomicExpr, node, ctx);
41                 boolean isAtomic = "true".equalsIgnoreCase(atomicStr);
42                 
43                 // Initialize status to success so that at least one outcome will execute
44                 ctx.setStatus("success");
45                 
46                 int numOutcomes = node.getNumOutcomes();
47
48                 for (int i = 0; i < numOutcomes; i++) {
49                         if ("failure".equals(ctx.getStatus()) && isAtomic) {
50                                 LOG.info("Block - stopped executing nodes due to failure status");
51                                 return(null);
52                         }
53                         
54                         SvcLogicNode nextNode = node.getOutcomeValue("" + (i + 1));
55                         if (nextNode != null) {
56                                 if (LOG.isDebugEnabled()) {
57                                         LOG.debug("Block - executing outcome " + (i + 1));
58                                 }
59                                 while (nextNode != null)
60                                 {
61                                        nextNode = svc.executeNode(nextNode, ctx);
62                                 }
63                         } else {
64                                 if (LOG.isDebugEnabled()) {
65                                         LOG.debug("Block - done: no outcome " + (i + 1));
66                                 }
67                         }
68                 }
69
70                 return (null);
71         }
72
73
74 }