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.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;
37 import com.att.eelf.configuration.EELFLogger;
38 import com.att.eelf.configuration.EELFManager;
41 public class GraphExecutor implements FlowExecutorInterface {
43 private static final EELFLogger log = EELFManager.getInstance().getLogger(GraphExecutor.class);
45 private SvcLogicService svcLogic = null;
47 public GraphExecutor() {
48 BundleContext bctx = FrameworkUtil.getBundle(SvcLogicService.class)
51 ServiceReference sref = bctx.getServiceReference(SvcLogicService.NAME);
53 svcLogic = (SvcLogicService) bctx.getService(sref);
57 log.warn("Cannot find service reference for "
58 + SvcLogicService.NAME);
60 log.debug("Graph Executor Initialized successfully");
63 public boolean hasGraph(String module, String rpc, String version,
64 String mode) throws SvcLogicException {
65 return (svcLogic.hasGraph(module, rpc, version, mode));
68 public Properties executeGraph(String module, String rpc, String version,
69 String mode, Properties parms) throws SvcLogicException {
70 log.debug("Parameters passed to SLI");
72 // for (Object key : parms.keySet()) {
73 // String parmName = (String) key;
74 // String parmValue = parms.getProperty(parmName);
76 // log.debug(parmName + " = " + parmValue);
79 Properties respProps = svcLogic.execute(module, rpc, version, mode,parms);
80 if (log.isDebugEnabled()) {
81 log.debug("Parameters returned by SLI");
82 for (Object key : respProps.keySet()) {
83 String parmName = (String) key;
84 String parmValue = respProps.getProperty(parmName);
86 log.debug(parmName + " = " + parmValue);
90 .equalsIgnoreCase(respProps.getProperty("SvcLogic.status"))) {
97 public HashMap<String, String> execute(Transaction transaction, SvcLogicContext ctx) throws Exception {
99 String fn = "GraphExecutor.execute ";
100 log.debug(fn + "About to execute graph : " + transaction.getExecutionRPC()) ;
102 Properties parms = new Properties();
103 for (Object key : ctx.getAttributeKeySet()) {
104 String parmName = (String) key;
105 String parmValue = ctx.getAttribute(parmName);
106 parms.put(parmName, parmValue);
107 log.info(fn + "Setting Key= " + parmName + "and Value = " + parmValue);
110 Properties returnParams = executeGraph(transaction.getExecutionModule(),transaction.getExecutionRPC(), null, "sync", parms);
112 //log.debug("Return Params executing DG :" + returnParams.toString());
114 log.debug("Returned Params from DG Module: " + transaction.getExecutionModule() + "and DG NAME: " + transaction.getExecutionRPC()
115 + returnParams.toString());
117 Enumeration e = returnParams.propertyNames();
119 while (e.hasMoreElements()) {
120 String key = (String) e.nextElement();
121 log.info("NEW KEY = " + key + " -- " + returnParams.getProperty(key));
123 ctx.setAttribute(key, returnParams.getProperty(key));
127 //Get the correct code from the SVC Logic and set it in transaction
128 // transaction.setStatusCode(returnParams.getProperty("SvcLogic.code"));
130 if (FlowControllerConstants.FAILURE
131 .equalsIgnoreCase(returnParams.getProperty("SvcLogic.status"))) {
132 transaction.setStatus(FlowControllerConstants.FAILURE);
133 ctx.setAttribute(ctx.getAttribute(FlowControllerConstants.RESPONSE_PREFIX) + FlowControllerConstants.OUTPUT_PARAM_STATUS, FlowControllerConstants.OUTPUT_STATUS_FAILURE);
134 ctx.setAttribute(ctx.getAttribute(FlowControllerConstants.RESPONSE_PREFIX) + FlowControllerConstants.OUTPUT_STATUS_MESSAGE, returnParams.getProperty("error-message"));
135 transaction.setStatusCode("401");
136 transaction.setState((ctx.getAttribute(transaction.getExecutionModule() + "." + transaction.getExecutionRPC() + "." + FlowControllerConstants.OUTPUT_STATUS_MESSAGE)) !=null ?
137 ctx.getAttribute(transaction.getExecutionModule() + "." + transaction.getExecutionRPC() + "." + FlowControllerConstants.OUTPUT_STATUS_MESSAGE): null);
138 //Get error code from above instead setting here ...its for testing purpose
142 else if(FlowControllerConstants.SUCCESS
143 .equalsIgnoreCase(returnParams.getProperty("SvcLogic.status"))) {
144 transaction.setStatus(FlowControllerConstants.SUCCESS);
145 transaction.setStatusCode("400");
146 ctx.setAttribute(ctx.getAttribute(FlowControllerConstants.RESPONSE_PREFIX) + FlowControllerConstants.OUTPUT_PARAM_STATUS, FlowControllerConstants.OUTPUT_STATUS_SUCCESS);
147 transaction.setState((ctx.getAttribute(transaction.getExecutionModule() + "." + transaction.getExecutionRPC() + "." + FlowControllerConstants.OUTPUT_STATUS_MESSAGE)) !=null ?
148 ctx.getAttribute(transaction.getExecutionModule() + "." + transaction.getExecutionRPC() + "." + FlowControllerConstants.OUTPUT_STATUS_MESSAGE): null);
149 //Get error code from above instead setting here ...its for testing purpose
152 transaction.setStatus(FlowControllerConstants.OTHERS);
153 ctx.setAttribute(ctx.getAttribute(FlowControllerConstants.RESPONSE_PREFIX) + FlowControllerConstants.OUTPUT_PARAM_STATUS, FlowControllerConstants.OUTPUT_STATUS_FAILURE);
154 transaction.setStatusCode("401");
155 ctx.setAttribute(ctx.getAttribute(FlowControllerConstants.RESPONSE_PREFIX) + FlowControllerConstants.OUTPUT_STATUS_MESSAGE, returnParams.getProperty("error-message"));
159 //Change null to required value if required in upper level