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.SvcLogicContext;
25 import org.openecomp.sdnc.sli.SvcLogicException;
26 import org.openecomp.sdnc.sli.SvcLogicExpression;
27 import org.openecomp.sdnc.sli.SvcLogicNode;
28 import org.openecomp.sdnc.sli.SvcLogicResource;
29 import org.osgi.framework.BundleContext;
30 import org.osgi.framework.FrameworkUtil;
31 import org.osgi.framework.ServiceReference;
32 import org.slf4j.Logger;
33 import org.slf4j.LoggerFactory;
35 public class ReserveNodeExecutor extends SvcLogicNodeExecutor {
37 private static final Logger LOG = LoggerFactory
38 .getLogger(ReserveNodeExecutor.class);
41 public SvcLogicNode execute(SvcLogicServiceImpl svc, SvcLogicNode node,
42 SvcLogicContext ctx) throws SvcLogicException {
44 String plugin = SvcLogicExpressionResolver.evaluate(
45 node.getAttribute("plugin"), node, ctx);
46 String resourceType = SvcLogicExpressionResolver.evaluate(
47 node.getAttribute("resource"), node, ctx);
48 String key = SvcLogicExpressionResolver.evaluateAsKey(
49 node.getAttribute("key"), node, ctx);
50 String pfx = SvcLogicExpressionResolver.evaluate(node.getAttribute("pfx"),node,ctx);
53 SvcLogicExpression selectExpr = node.getAttribute("select");
56 if (selectExpr != null)
58 select = SvcLogicExpressionResolver.evaluateAsKey(selectExpr, node, ctx);
61 String outValue = "failure";
63 if (LOG.isDebugEnabled()) {
64 LOG.debug("reserve node encountered - looking for resource class "
70 SvcLogicResource resourcePlugin = getSvcLogicResource(plugin);
72 if (resourcePlugin != null) {
75 switch (resourcePlugin.reserve(resourceType, select, key, pfx, ctx)) {
80 outValue = "not-found";
86 } catch (SvcLogicException e) {
87 LOG.error("Caught exception from resource plugin", e);
91 LOG.warn("Could not find SvcLogicResource object for plugin "
95 SvcLogicNode nextNode = node.getOutcomeValue(outValue);
96 if (nextNode != null) {
97 if (LOG.isDebugEnabled()) {
98 LOG.debug("about to execute " + outValue + " branch");
103 nextNode = node.getOutcomeValue("Other");
104 if (nextNode != null) {
105 if (LOG.isDebugEnabled()) {
106 LOG.debug("about to execute Other branch");
109 if (LOG.isDebugEnabled()) {
111 LOG.debug("no "+outValue+" or Other branch found");
117 protected SvcLogicResource getSvcLogicResource(String plugin) {
118 BundleContext bctx = FrameworkUtil.getBundle(this.getClass())
121 ServiceReference sref = bctx.getServiceReference(plugin);
123 SvcLogicResource resourcePlugin = (SvcLogicResource) bctx
125 return resourcePlugin;
128 LOG.warn("Could not find service reference object for plugin " + plugin);