0d8416cdd97f95e165154ef69fbba21af4ec2784
[ccsdk/sli/core.git] / sli / provider / src / main / java / org / openecomp / sdnc / sli / provider / ReleaseNodeExecutor.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 ReleaseNodeExecutor extends SvcLogicNodeExecutor {
32
33         private static final Logger LOG = LoggerFactory
34                         .getLogger(ReleaseNodeExecutor.class);
35         @Override
36         public SvcLogicNode execute(SvcLogicServiceImpl svc, SvcLogicNode node,
37                         SvcLogicContext ctx) throws SvcLogicException {
38
39                 String plugin = SvcLogicExpressionResolver.evaluate(
40                                 node.getAttribute("plugin"), node, ctx);
41                 String resourceType = SvcLogicExpressionResolver.evaluate(
42                                 node.getAttribute("resource"), node, ctx);
43                 String key = SvcLogicExpressionResolver.evaluateAsKey(
44                                 node.getAttribute("key"), node, ctx);
45
46                 String outValue = "failure";
47
48                 if (LOG.isDebugEnabled()) {
49                         LOG.debug("release node encountered - looking for resource class "
50                                         + plugin);
51                 }
52
53         SvcLogicResource resourcePlugin = getSvcLogicResource(plugin);
54                         if (resourcePlugin != null) {
55
56                                 try {
57
58                                         switch (resourcePlugin.release(resourceType, key, ctx)) {
59                                         case SUCCESS:
60                                                 outValue = "success";
61                                                 break;
62                                         case NOT_FOUND:
63                                                 outValue = "not-found";
64                                                 break;
65                                         case FAILURE:
66                                         default:
67                                                 outValue = "failure";
68                                         }
69                                 } catch (SvcLogicException e) {
70                                         LOG.error("Caught exception from resource plugin", e);
71                                         outValue = "failure";
72                                 }
73                         } else {
74                                 LOG.warn("Could not find SvcLogicResource object for plugin "
75                                                 + plugin);
76                         }
77
78                 SvcLogicNode nextNode = node.getOutcomeValue(outValue);
79                 if (nextNode != null) {
80                         if (LOG.isDebugEnabled()) {
81                                 LOG.debug("about to execute " + outValue + " branch");
82                         }
83                         return (nextNode);
84                 }
85
86                 nextNode = node.getOutcomeValue("Other");
87                 if (nextNode != null) {
88                         if (LOG.isDebugEnabled()) {
89                                 LOG.debug("about to execute Other branch");
90                         }
91                 } else {
92                         if (LOG.isDebugEnabled()) {
93
94                                 LOG.debug("no "+outValue+" or Other branch found");
95                         }
96                 }
97                 return (nextNode);
98         }
99
100 }