2  * ============LICENSE_START=======================================================
 
   4  * ================================================================================
 
   5  * Copyright (C) 2017-2018 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  * ============LICENSE_END=========================================================
 
  21 package org.onap.appc.flow.controller.executorImpl;
 
  23 import com.att.eelf.configuration.EELFLogger;
 
  24 import com.att.eelf.configuration.EELFManager;
 
  25 import java.util.Enumeration;
 
  27 import java.util.Properties;
 
  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.provider.SvcLogicService;
 
  34 import org.osgi.framework.BundleContext;
 
  35 import org.osgi.framework.FrameworkUtil;
 
  36 import org.osgi.framework.ServiceReference;
 
  39 public class GraphExecutor implements FlowExecutorInterface {
 
  41     private static final EELFLogger log = EELFManager.getInstance().getLogger(GraphExecutor.class);
 
  42     private static final String SVC_LOGIC_STATUS_PARAM = "SvcLogic.status";
 
  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);
 
  53             log.warn("Cannot find service reference for " + SvcLogicService.NAME);
 
  55         log.debug("Graph Executor Initialized successfully");
 
  58     public boolean hasGraph(String module, String rpc, String version, String mode) throws SvcLogicException {
 
  59         return svcLogic.hasGraph(module, rpc, version, mode);
 
  62     public Properties executeGraph(String module, String rpc, String version, String mode, Properties parms)
 
  63         throws SvcLogicException {
 
  64         log.debug("Parameters passed to SLI");
 
  66         Properties respProps = svcLogic.execute(module, rpc, version, mode, parms);
 
  67         if (log.isDebugEnabled()) {
 
  68             log.debug("Parameters returned by SLI");
 
  69             for (Object key : respProps.keySet()) {
 
  70                 String parmName = (String) key;
 
  71                 String parmValue = respProps.getProperty(parmName);
 
  73                 log.debug(parmName + " = " + parmValue);
 
  80     public Map<String, String> execute(Transaction transaction, SvcLogicContext ctx) throws Exception {
 
  82         String fn = "GraphExecutor.execute ";
 
  83         log.debug(fn + "About to execute graph : " + transaction.getExecutionRPC());
 
  85         Properties parms = new Properties();
 
  86         for (Object key : ctx.getAttributeKeySet()) {
 
  87             String parmName = (String) key;
 
  88             String parmValue = ctx.getAttribute(parmName);
 
  89             parms.put(parmName, parmValue);
 
  90             log.info(fn + "Setting Key= " + parmName + "and Value = " + parmValue);
 
  93         Properties returnParams =
 
  94             executeGraph(transaction.getExecutionModule(), transaction.getExecutionRPC(), null, "sync", parms);
 
  96         log.debug("Returned Params from DG Module: " + transaction.getExecutionModule() + "and DG NAME: "
 
  97             + transaction.getExecutionRPC() + returnParams.toString());
 
  99         Enumeration e = returnParams.propertyNames();
 
 101         while (e.hasMoreElements()) {
 
 102             String key = (String) e.nextElement();
 
 103             log.info("NEW KEY =  " + key + " -- " + returnParams.getProperty(key));
 
 105             ctx.setAttribute(key, returnParams.getProperty(key));
 
 108         if (FlowControllerConstants.FAILURE.equalsIgnoreCase(returnParams.getProperty(SVC_LOGIC_STATUS_PARAM))) {
 
 109             transaction.setStatus(FlowControllerConstants.FAILURE);
 
 111                 ctx.getAttribute(FlowControllerConstants.RESPONSE_PREFIX)
 
 112                     + FlowControllerConstants.OUTPUT_PARAM_STATUS,
 
 113                 FlowControllerConstants.OUTPUT_STATUS_FAILURE);
 
 114             ctx.setAttribute(ctx.getAttribute(FlowControllerConstants.RESPONSE_PREFIX)
 
 115                 + FlowControllerConstants.OUTPUT_STATUS_MESSAGE, returnParams.getProperty("error-message"));
 
 116             transaction.setStatusCode("401");
 
 117             transaction.setState(ctx.getAttribute(transaction.getExecutionModule() + "." + transaction.getExecutionRPC()
 
 118                 + "." + FlowControllerConstants.OUTPUT_STATUS_MESSAGE));
 
 119             // Get error code from above instead setting here ...its for testing purpose
 
 121         } else if (FlowControllerConstants.SUCCESS.equalsIgnoreCase(returnParams.getProperty(SVC_LOGIC_STATUS_PARAM))) {
 
 122             transaction.setStatus(FlowControllerConstants.SUCCESS);
 
 123             transaction.setStatusCode("400");
 
 125                 ctx.getAttribute(FlowControllerConstants.RESPONSE_PREFIX)
 
 126                     + FlowControllerConstants.OUTPUT_PARAM_STATUS,
 
 127                 FlowControllerConstants.OUTPUT_STATUS_SUCCESS);
 
 128             transaction.setState(ctx.getAttribute(transaction.getExecutionModule() + "." + transaction.getExecutionRPC()
 
 129                 + "." + FlowControllerConstants.OUTPUT_STATUS_MESSAGE));
 
 130             // Get error code from above instead setting here ...its for testing purpose
 
 132             transaction.setStatus(FlowControllerConstants.OTHERS);
 
 134                 ctx.getAttribute(FlowControllerConstants.RESPONSE_PREFIX)
 
 135                     + FlowControllerConstants.OUTPUT_PARAM_STATUS,
 
 136                 FlowControllerConstants.OUTPUT_STATUS_FAILURE);
 
 137             transaction.setStatusCode("401");
 
 138             ctx.setAttribute(ctx.getAttribute(FlowControllerConstants.RESPONSE_PREFIX)
 
 139                 + FlowControllerConstants.OUTPUT_STATUS_MESSAGE, returnParams.getProperty("error-message"));
 
 143         // Change null to required value if required in upper level