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 GetResourceNodeExecutor extends SvcLogicNodeExecutor {
37 private static final Logger LOG = LoggerFactory
38 .getLogger(GetResourceNodeExecutor.class);
40 public SvcLogicNode execute(SvcLogicServiceImpl svc, SvcLogicNode node,
41 SvcLogicContext ctx) throws SvcLogicException {
43 String plugin = SvcLogicExpressionResolver.evaluate(
44 node.getAttribute("plugin"), node, ctx);
45 String resourceType = SvcLogicExpressionResolver.evaluate(
46 node.getAttribute("resource"), node, ctx);
47 String key = SvcLogicExpressionResolver.evaluateAsKey(
48 node.getAttribute("key"), node, ctx);
49 String pfx = SvcLogicExpressionResolver.evaluate(
50 node.getAttribute("pfx"), node, ctx);
52 String localOnlyStr = SvcLogicExpressionResolver.evaluate(
53 node.getAttribute("local-only"), node, ctx);
55 // Note: for get-resource, only refresh from A&AI if the DG explicitly set
56 // local-only to false. Otherwise, just read from local database.
57 boolean localOnly = true;
59 if ("false".equalsIgnoreCase(localOnlyStr)) {
63 SvcLogicExpression selectExpr = node.getAttribute("select");
66 if (selectExpr != null) {
67 select = SvcLogicExpressionResolver.evaluateAsKey(selectExpr, node,
71 SvcLogicExpression orderByExpr = node.getAttribute("order-by");
72 String orderBy = null;
74 if (orderByExpr != null) {
75 orderBy = SvcLogicExpressionResolver.evaluateAsKey(orderByExpr, node,
79 String outValue = "failure";
81 if (LOG.isDebugEnabled()) {
82 LOG.debug(node.getNodeType()
83 + " node encountered - looking for resource class "
88 SvcLogicResource resourcePlugin = getSvcLogicResource(plugin);
90 if (resourcePlugin != null) {
93 switch (resourcePlugin.query(resourceType, localOnly, select, key,
99 outValue = "not-found";
103 outValue = "failure";
105 } catch (SvcLogicException e) {
106 LOG.error("Caught exception from resource plugin", e);
107 outValue = "failure";
110 LOG.warn("Could not find SvcLogicResource object for plugin "
115 SvcLogicNode nextNode = node.getOutcomeValue(outValue);
116 if (nextNode != null) {
117 if (LOG.isDebugEnabled()) {
118 LOG.debug("about to execute " + outValue + " branch");
123 nextNode = node.getOutcomeValue("Other");
124 if (nextNode != null) {
125 if (LOG.isDebugEnabled()) {
126 LOG.debug("about to execute Other branch");
129 if (LOG.isDebugEnabled()) {
131 LOG.debug("no "+outValue+" or Other branch found");
137 protected SvcLogicResource getSvcLogicResource(String plugin) {
138 BundleContext bctx = FrameworkUtil.getBundle(this.getClass())
141 ServiceReference sref = bctx.getServiceReference(plugin);
143 SvcLogicResource resourcePlugin = (SvcLogicResource) bctx
145 return resourcePlugin;
148 LOG.warn("Could not find service reference object for plugin " + plugin);