2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * =============================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
19 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
20 * ============LICENSE_END=========================================================
22 package org.onap.appc.flow.controller.executorImpl;
24 import java.util.Enumeration;
25 import java.util.HashMap;
26 import java.util.Properties;
27 import org.onap.appc.flow.controller.data.Transaction;
28 import org.onap.appc.flow.controller.interfaces.FlowExecutorInterface;
29 import org.onap.appc.flow.controller.utils.FlowControllerConstants;
30 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
31 import org.onap.ccsdk.sli.core.sli.SvcLogicException;
32 import org.onap.ccsdk.sli.core.sli.provider.SvcLogicService;
33 import org.osgi.framework.BundleContext;
34 import org.osgi.framework.FrameworkUtil;
35 import org.osgi.framework.ServiceReference;
36 import com.att.eelf.configuration.EELFLogger;
37 import com.att.eelf.configuration.EELFManager;
40 public class GraphExecutor implements FlowExecutorInterface {
42 private static final EELFLogger log = EELFManager.getInstance().getLogger(GraphExecutor.class);
44 private SvcLogicService svcLogic = null;
46 public GraphExecutor() {
47 BundleContext bctx = FrameworkUtil.getBundle(SvcLogicService.class).getBundleContext();
49 ServiceReference sref = bctx.getServiceReference(SvcLogicService.NAME);
51 svcLogic = (SvcLogicService) bctx.getService(sref);
55 log.warn("Cannot find service reference for " + SvcLogicService.NAME);
57 log.debug("Graph Executor Initialized successfully");
60 public boolean hasGraph(String module, String rpc, String version, String mode) throws SvcLogicException {
61 return (svcLogic.hasGraph(module, rpc, version, mode));
64 public Properties executeGraph(String module, String rpc, String version, String mode, Properties parms)
65 throws SvcLogicException {
66 log.debug("Parameters passed to SLI");
68 // for (Object key : parms.keySet()) {
69 // String parmName = (String) key;
70 // String parmValue = parms.getProperty(parmName);
72 // log.debug(parmName + " = " + parmValue);
75 Properties respProps = svcLogic.execute(module, rpc, version, mode, parms);
76 if (log.isDebugEnabled()) {
77 log.debug("Parameters returned by SLI");
78 for (Object key : respProps.keySet()) {
79 String parmName = (String) key;
80 String parmValue = respProps.getProperty(parmName);
82 log.debug(parmName + " = " + parmValue);
85 if ("failure".equalsIgnoreCase(respProps.getProperty("SvcLogic.status"))) {
92 public HashMap<String, String> execute(Transaction transaction, SvcLogicContext ctx) throws Exception {
94 String fn = "GraphExecutor.execute ";
95 log.debug(fn + "About to execute graph : " + transaction.getExecutionRPC());
97 Properties parms = new Properties();
98 for (Object key : ctx.getAttributeKeySet()) {
99 String parmName = (String) key;
100 String parmValue = ctx.getAttribute(parmName);
101 parms.put(parmName, parmValue);
102 log.info(fn + "Setting Key= " + parmName + "and Value = " + parmValue);
105 Properties returnParams =
106 executeGraph(transaction.getExecutionModule(), transaction.getExecutionRPC(), null, "sync", parms);
108 // log.debug("Return Params executing DG :" + returnParams.toString());
110 log.debug("Returned Params from DG Module: " + transaction.getExecutionModule() + "and DG NAME: "
111 + transaction.getExecutionRPC() + returnParams.toString());
113 Enumeration e = returnParams.propertyNames();
115 while (e.hasMoreElements()) {
116 String key = (String) e.nextElement();
117 log.info("NEW KEY = " + key + " -- " + returnParams.getProperty(key));
119 ctx.setAttribute(key, returnParams.getProperty(key));
123 // Get the correct code from the SVC Logic and set it in transaction
124 // transaction.setStatusCode(returnParams.getProperty("SvcLogic.code"));
126 if (FlowControllerConstants.FAILURE.equalsIgnoreCase(returnParams.getProperty("SvcLogic.status"))) {
127 transaction.setStatus(FlowControllerConstants.FAILURE);
129 ctx.getAttribute(FlowControllerConstants.RESPONSE_PREFIX)
130 + FlowControllerConstants.OUTPUT_PARAM_STATUS,
131 FlowControllerConstants.OUTPUT_STATUS_FAILURE);
132 ctx.setAttribute(ctx.getAttribute(FlowControllerConstants.RESPONSE_PREFIX)
133 + FlowControllerConstants.OUTPUT_STATUS_MESSAGE, returnParams.getProperty("error-message"));
134 transaction.setStatusCode("401");
135 transaction.setState((ctx.getAttribute(transaction.getExecutionModule() + "."
136 + transaction.getExecutionRPC() + "." + FlowControllerConstants.OUTPUT_STATUS_MESSAGE)) != null
137 ? ctx.getAttribute(transaction.getExecutionModule() + "." + transaction.getExecutionRPC()
138 + "." + FlowControllerConstants.OUTPUT_STATUS_MESSAGE)
140 // Get error code from above instead setting here ...its for testing purpose
143 } else if (FlowControllerConstants.SUCCESS.equalsIgnoreCase(returnParams.getProperty("SvcLogic.status"))) {
144 transaction.setStatus(FlowControllerConstants.SUCCESS);
145 transaction.setStatusCode("400");
147 ctx.getAttribute(FlowControllerConstants.RESPONSE_PREFIX)
148 + FlowControllerConstants.OUTPUT_PARAM_STATUS,
149 FlowControllerConstants.OUTPUT_STATUS_SUCCESS);
150 transaction.setState((ctx.getAttribute(transaction.getExecutionModule() + "."
151 + transaction.getExecutionRPC() + "." + FlowControllerConstants.OUTPUT_STATUS_MESSAGE)) != null
152 ? ctx.getAttribute(transaction.getExecutionModule() + "." + transaction.getExecutionRPC()
153 + "." + FlowControllerConstants.OUTPUT_STATUS_MESSAGE)
155 // Get error code from above instead setting here ...its for testing purpose
157 transaction.setStatus(FlowControllerConstants.OTHERS);
159 ctx.getAttribute(FlowControllerConstants.RESPONSE_PREFIX)
160 + FlowControllerConstants.OUTPUT_PARAM_STATUS,
161 FlowControllerConstants.OUTPUT_STATUS_FAILURE);
162 transaction.setStatusCode("401");
163 ctx.setAttribute(ctx.getAttribute(FlowControllerConstants.RESPONSE_PREFIX)
164 + FlowControllerConstants.OUTPUT_STATUS_MESSAGE, returnParams.getProperty("error-message"));
168 // Change null to required value if required in upper level