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.slf4j.Logger;
30 import org.slf4j.LoggerFactory;
32 public class GetResourceNodeExecutor extends SvcLogicNodeExecutor {
34 private static final Logger LOG = LoggerFactory
35 .getLogger(GetResourceNodeExecutor.class);
37 public SvcLogicNode execute(SvcLogicServiceImpl svc, SvcLogicNode node,
38 SvcLogicContext ctx) throws SvcLogicException {
40 String plugin = SvcLogicExpressionResolver.evaluate(
41 node.getAttribute("plugin"), node, ctx);
42 String resourceType = SvcLogicExpressionResolver.evaluate(
43 node.getAttribute("resource"), node, ctx);
44 String key = SvcLogicExpressionResolver.evaluateAsKey(
45 node.getAttribute("key"), node, ctx);
46 String pfx = SvcLogicExpressionResolver.evaluate(
47 node.getAttribute("pfx"), node, ctx);
49 String localOnlyStr = SvcLogicExpressionResolver.evaluate(
50 node.getAttribute("local-only"), node, ctx);
52 // Note: for get-resource, only refresh from A&AI if the DG explicitly set
53 // local-only to false. Otherwise, just read from local database.
54 boolean localOnly = true;
56 if ("false".equalsIgnoreCase(localOnlyStr)) {
60 SvcLogicExpression selectExpr = node.getAttribute("select");
63 if (selectExpr != null) {
64 select = SvcLogicExpressionResolver.evaluateAsKey(selectExpr, node,
68 SvcLogicExpression orderByExpr = node.getAttribute("order-by");
69 String orderBy = null;
71 if (orderByExpr != null) {
72 orderBy = SvcLogicExpressionResolver.evaluateAsKey(orderByExpr, node,
76 String outValue = "failure";
78 if (LOG.isDebugEnabled()) {
79 LOG.debug(node.getNodeType()
80 + " node encountered - looking for resource class "
85 SvcLogicResource resourcePlugin = getSvcLogicResource(plugin);
87 if (resourcePlugin != null) {
90 switch (resourcePlugin.query(resourceType, localOnly, select, key,
96 outValue = "not-found";
100 outValue = "failure";
102 } catch (SvcLogicException e) {
103 LOG.error("Caught exception from resource plugin", e);
104 outValue = "failure";
107 LOG.warn("Could not find SvcLogicResource object for plugin "
112 SvcLogicNode nextNode = node.getOutcomeValue(outValue);
113 if (nextNode != null) {
114 if (LOG.isDebugEnabled()) {
115 LOG.debug("about to execute " + outValue + " branch");
120 nextNode = node.getOutcomeValue("Other");
121 if (nextNode != null) {
122 if (LOG.isDebugEnabled()) {
123 LOG.debug("about to execute Other branch");
126 if (LOG.isDebugEnabled()) {
128 LOG.debug("no "+outValue+" or Other branch found");