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 com.att.eelf.configuration.EELFLogger;
25 import com.att.eelf.configuration.EELFManager;
26 import java.util.Enumeration;
28 import java.util.Properties;
29 import org.onap.appc.flow.controller.data.Transaction;
30 import org.onap.appc.flow.controller.interfaces.FlowExecutorInterface;
31 import org.onap.appc.flow.controller.utils.FlowControllerConstants;
32 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
33 import org.onap.ccsdk.sli.core.sli.SvcLogicException;
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;
40 public class GraphExecutor implements FlowExecutorInterface {
42 private static final EELFLogger log = EELFManager.getInstance().getLogger(GraphExecutor.class);
43 private static final String SVC_LOGIC_STATUS_PARAM = "SvcLogic.status";
45 private SvcLogicService svcLogic = null;
47 public GraphExecutor() {
48 BundleContext bctx = FrameworkUtil.getBundle(SvcLogicService.class).getBundleContext();
50 ServiceReference sref = bctx.getServiceReference(SvcLogicService.NAME);
52 svcLogic = (SvcLogicService) bctx.getService(sref);
54 log.warn("Cannot find service reference for " + SvcLogicService.NAME);
56 log.debug("Graph Executor Initialized successfully");
59 public boolean hasGraph(String module, String rpc, String version, String mode) throws SvcLogicException {
60 return svcLogic.hasGraph(module, rpc, version, mode);
63 public Properties executeGraph(String module, String rpc, String version, String mode, Properties parms)
64 throws SvcLogicException {
65 log.debug("Parameters passed to SLI");
67 Properties respProps = svcLogic.execute(module, rpc, version, mode, parms);
68 if (log.isDebugEnabled()) {
69 log.debug("Parameters returned by SLI");
70 for (Object key : respProps.keySet()) {
71 String parmName = (String) key;
72 String parmValue = respProps.getProperty(parmName);
74 log.debug(parmName + " = " + parmValue);
81 public Map<String, String> execute(Transaction transaction, SvcLogicContext ctx) throws Exception {
83 String fn = "GraphExecutor.execute ";
84 log.debug(fn + "About to execute graph : " + transaction.getExecutionRPC());
86 Properties parms = new Properties();
87 for (Object key : ctx.getAttributeKeySet()) {
88 String parmName = (String) key;
89 String parmValue = ctx.getAttribute(parmName);
90 parms.put(parmName, parmValue);
91 log.info(fn + "Setting Key= " + parmName + "and Value = " + parmValue);
94 Properties returnParams =
95 executeGraph(transaction.getExecutionModule(), transaction.getExecutionRPC(), null, "sync", parms);
97 log.debug("Returned Params from DG Module: " + transaction.getExecutionModule() + "and DG NAME: "
98 + transaction.getExecutionRPC() + returnParams.toString());
100 Enumeration e = returnParams.propertyNames();
102 while (e.hasMoreElements()) {
103 String key = (String) e.nextElement();
104 log.info("NEW KEY = " + key + " -- " + returnParams.getProperty(key));
106 ctx.setAttribute(key, returnParams.getProperty(key));
109 if (FlowControllerConstants.FAILURE.equalsIgnoreCase(returnParams.getProperty(SVC_LOGIC_STATUS_PARAM))) {
110 transaction.setStatus(FlowControllerConstants.FAILURE);
112 ctx.getAttribute(FlowControllerConstants.RESPONSE_PREFIX)
113 + FlowControllerConstants.OUTPUT_PARAM_STATUS,
114 FlowControllerConstants.OUTPUT_STATUS_FAILURE);
115 ctx.setAttribute(ctx.getAttribute(FlowControllerConstants.RESPONSE_PREFIX)
116 + FlowControllerConstants.OUTPUT_STATUS_MESSAGE, returnParams.getProperty("error-message"));
117 transaction.setStatusCode("401");
118 transaction.setState(ctx.getAttribute(transaction.getExecutionModule() + "." + transaction.getExecutionRPC()
119 + "." + FlowControllerConstants.OUTPUT_STATUS_MESSAGE));
120 // Get error code from above instead setting here ...its for testing purpose
122 } else if (FlowControllerConstants.SUCCESS.equalsIgnoreCase(returnParams.getProperty(SVC_LOGIC_STATUS_PARAM))) {
123 transaction.setStatus(FlowControllerConstants.SUCCESS);
124 transaction.setStatusCode("400");
126 ctx.getAttribute(FlowControllerConstants.RESPONSE_PREFIX)
127 + FlowControllerConstants.OUTPUT_PARAM_STATUS,
128 FlowControllerConstants.OUTPUT_STATUS_SUCCESS);
129 transaction.setState(ctx.getAttribute(transaction.getExecutionModule() + "." + transaction.getExecutionRPC()
130 + "." + FlowControllerConstants.OUTPUT_STATUS_MESSAGE));
131 // Get error code from above instead setting here ...its for testing purpose
133 transaction.setStatus(FlowControllerConstants.OTHERS);
135 ctx.getAttribute(FlowControllerConstants.RESPONSE_PREFIX)
136 + FlowControllerConstants.OUTPUT_PARAM_STATUS,
137 FlowControllerConstants.OUTPUT_STATUS_FAILURE);
138 transaction.setStatusCode("401");
139 ctx.setAttribute(ctx.getAttribute(FlowControllerConstants.RESPONSE_PREFIX)
140 + FlowControllerConstants.OUTPUT_STATUS_MESSAGE, returnParams.getProperty("error-message"));
144 // Change null to required value if required in upper level