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.
18 * ============LICENSE_END=========================================================
21 package org.onap.appc.flow.controller.executorImpl;
23 import java.util.Enumeration;
24 import java.util.HashMap;
25 import java.util.Properties;
27 import org.onap.appc.flow.controller.data.Parameters;
28 import org.onap.appc.flow.controller.data.Transaction;
29 import org.onap.appc.flow.controller.interfaces.FlowExecutorInterface;
30 import org.onap.appc.flow.controller.utils.FlowControllerConstants;
31 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
32 import org.onap.ccsdk.sli.core.sli.SvcLogicException;
33 import org.onap.ccsdk.sli.core.sli.SvcLogicGraph;
34 import org.onap.ccsdk.sli.core.sli.provider.SvcLogicService;
35 import org.osgi.framework.BundleContext;
36 import org.osgi.framework.FrameworkUtil;
37 import org.osgi.framework.ServiceReference;
39 import com.att.eelf.configuration.EELFLogger;
40 import com.att.eelf.configuration.EELFManager;
43 public class GraphExecutor implements FlowExecutorInterface {
45 private static final EELFLogger log = EELFManager.getInstance().getLogger(GraphExecutor.class);
47 private SvcLogicService svcLogic = null;
49 public GraphExecutor() {
50 BundleContext bctx = FrameworkUtil.getBundle(SvcLogicService.class)
53 ServiceReference sref = bctx.getServiceReference(SvcLogicService.NAME);
55 svcLogic = (SvcLogicService) bctx.getService(sref);
59 log.warn("Cannot find service reference for "
60 + SvcLogicService.NAME);
62 log.debug("Graph Executor Initialized successfully");
65 public boolean hasGraph(String module, String rpc, String version,
66 String mode) throws SvcLogicException {
67 return (svcLogic.hasGraph(module, rpc, version, mode));
70 public Properties executeGraph(String module, String rpc, String version,
71 String mode, Properties parms) throws SvcLogicException {
72 log.debug("Parameters passed to SLI");
74 // for (Object key : parms.keySet()) {
75 // String parmName = (String) key;
76 // String parmValue = parms.getProperty(parmName);
78 // log.debug(parmName + " = " + parmValue);
81 Properties respProps = svcLogic.execute(module, rpc, version, mode,parms);
82 if (log.isDebugEnabled()) {
83 log.debug("Parameters returned by SLI");
84 for (Object key : respProps.keySet()) {
85 String parmName = (String) key;
86 String parmValue = respProps.getProperty(parmName);
88 log.debug(parmName + " = " + parmValue);
92 .equalsIgnoreCase(respProps.getProperty("SvcLogic.status"))) {
99 public HashMap<String, String> execute(Transaction transaction, SvcLogicContext ctx) throws Exception {
101 String fn = "GraphExecutor.execute ";
102 log.debug(fn + "About to execute graph : " + transaction.getExecutionRPC()) ;
104 Properties parms = new Properties();
105 for (Object key : ctx.getAttributeKeySet()) {
106 String parmName = (String) key;
107 String parmValue = ctx.getAttribute(parmName);
108 parms.put(parmName, parmValue);
109 log.info(fn + "Setting Key= " + parmName + "and Value = " + parmValue);
112 Properties returnParams = executeGraph(transaction.getExecutionModule(),transaction.getExecutionRPC(), null, "sync", parms);
114 //log.debug("Return Params executing DG :" + returnParams.toString());
116 log.debug("Returned Params from DG Module: " + transaction.getExecutionModule() + "and DG NAME: " + transaction.getExecutionRPC()
117 + returnParams.toString());
119 Enumeration e = returnParams.propertyNames();
121 while (e.hasMoreElements()) {
122 String key = (String) e.nextElement();
123 log.info("NEW KEY = " + key + " -- " + returnParams.getProperty(key));
125 ctx.setAttribute(key, returnParams.getProperty(key));
129 //Get the correct code from the SVC Logic and set it in transaction
130 // transaction.setStatusCode(returnParams.getProperty("SvcLogic.code"));
132 if (FlowControllerConstants.FAILURE
133 .equalsIgnoreCase(returnParams.getProperty("SvcLogic.status"))) {
134 transaction.setStatus(FlowControllerConstants.FAILURE);
135 ctx.setAttribute(ctx.getAttribute(FlowControllerConstants.RESPONSE_PREFIX) + FlowControllerConstants.OUTPUT_PARAM_STATUS, FlowControllerConstants.OUTPUT_STATUS_FAILURE);
136 ctx.setAttribute(ctx.getAttribute(FlowControllerConstants.RESPONSE_PREFIX) + FlowControllerConstants.OUTPUT_STATUS_MESSAGE, returnParams.getProperty("error-message"));
137 transaction.setStatusCode("401");
138 transaction.setState((ctx.getAttribute(transaction.getExecutionModule() + "." + transaction.getExecutionRPC() + "." + FlowControllerConstants.OUTPUT_STATUS_MESSAGE)) !=null ?
139 ctx.getAttribute(transaction.getExecutionModule() + "." + transaction.getExecutionRPC() + "." + FlowControllerConstants.OUTPUT_STATUS_MESSAGE): null);
140 //Get error code from above instead setting here ...its for testing purpose
144 else if(FlowControllerConstants.SUCCESS
145 .equalsIgnoreCase(returnParams.getProperty("SvcLogic.status"))) {
146 transaction.setStatus(FlowControllerConstants.SUCCESS);
147 transaction.setStatusCode("400");
148 ctx.setAttribute(ctx.getAttribute(FlowControllerConstants.RESPONSE_PREFIX) + FlowControllerConstants.OUTPUT_PARAM_STATUS, FlowControllerConstants.OUTPUT_STATUS_SUCCESS);
149 transaction.setState((ctx.getAttribute(transaction.getExecutionModule() + "." + transaction.getExecutionRPC() + "." + FlowControllerConstants.OUTPUT_STATUS_MESSAGE)) !=null ?
150 ctx.getAttribute(transaction.getExecutionModule() + "." + transaction.getExecutionRPC() + "." + FlowControllerConstants.OUTPUT_STATUS_MESSAGE): null);
151 //Get error code from above instead setting here ...its for testing purpose
154 transaction.setStatus(FlowControllerConstants.OTHERS);
155 ctx.setAttribute(ctx.getAttribute(FlowControllerConstants.RESPONSE_PREFIX) + FlowControllerConstants.OUTPUT_PARAM_STATUS, FlowControllerConstants.OUTPUT_STATUS_FAILURE);
156 transaction.setStatusCode("401");
157 ctx.setAttribute(ctx.getAttribute(FlowControllerConstants.RESPONSE_PREFIX) + FlowControllerConstants.OUTPUT_STATUS_MESSAGE, returnParams.getProperty("error-message"));
161 //Change null to required value if required in upper level