Update groupId to org.onap.ccsdk.sli
[ccsdk/sli/core.git] / sli / provider / src / main / java / org / openecomp / sdnc / sli / provider / NotifyNodeExecutor.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * openECOMP : SDN-C
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights
6  *                                              reserved.
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
11  * 
12  *      http://www.apache.org/licenses/LICENSE-2.0
13  * 
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=========================================================
20  */
21
22 package org.openecomp.sdnc.sli.provider;
23
24 import org.openecomp.sdnc.sli.SvcLogicContext;
25 import org.openecomp.sdnc.sli.SvcLogicException;
26 import org.openecomp.sdnc.sli.SvcLogicNode;
27 import org.openecomp.sdnc.sli.SvcLogicResource;
28 import org.slf4j.Logger;
29 import org.slf4j.LoggerFactory;
30
31 public class NotifyNodeExecutor extends SvcLogicNodeExecutor {
32
33         private static final Logger LOG = LoggerFactory
34                         .getLogger(NotifyNodeExecutor.class);
35         
36         @Override
37         public SvcLogicNode execute(SvcLogicServiceImpl svc, SvcLogicNode node,
38                         SvcLogicContext ctx) throws SvcLogicException {
39
40                 String plugin = SvcLogicExpressionResolver.evaluate(
41                                 node.getAttribute("plugin"), node, ctx);
42                 String resourceType = SvcLogicExpressionResolver.evaluate(
43                                 node.getAttribute("resource"), node, ctx);
44                 String action = SvcLogicExpressionResolver.evaluateAsKey(
45                                 node.getAttribute("action"), node, ctx);
46                 String key = SvcLogicExpressionResolver.evaluateAsKey(
47                                 node.getAttribute("key"), node, ctx);
48
49                 String outValue = "failure";
50
51                 if (LOG.isDebugEnabled()) {
52                         LOG.debug("release node encountered - looking for resource class "
53                                         + plugin);
54                 }
55
56         SvcLogicResource resourcePlugin = getSvcLogicResource(plugin);
57                         if (resourcePlugin != null) {
58
59                                 try {
60
61                                         switch (resourcePlugin.notify(resourceType, action, key, ctx)) {
62                                         case SUCCESS:
63                                                 outValue = "success";
64                                                 break;
65                                         case NOT_FOUND:
66                                                 outValue = "not-found";
67                                                 break;
68                                         case FAILURE:
69                                         default:
70                                                 outValue = "failure";
71                                         }
72                                 } catch (SvcLogicException e) {
73                                         LOG.error("Caught exception from resource plugin", e);
74                                         outValue = "failure";
75                                 }
76                         } else {
77                                 LOG.warn("Could not find SvcLogicResource object for plugin "
78                                                 + plugin);
79                         }
80
81                 SvcLogicNode nextNode = node.getOutcomeValue(outValue);
82                 if (nextNode != null) {
83                         if (LOG.isDebugEnabled()) {
84                                 LOG.debug("about to execute " + outValue + " branch");
85                         }
86                         return (nextNode);
87                 }
88
89                 nextNode = node.getOutcomeValue("Other");
90                 if (nextNode != null) {
91                         if (LOG.isDebugEnabled()) {
92                                 LOG.debug("about to execute Other branch");
93                         }
94                 } else {
95                         if (LOG.isDebugEnabled()) {
96                                 LOG.debug("no "+outValue+" or Other branch found");
97                         }
98                 }
99                 return (nextNode);
100         }
101
102 }