+
+ private void restartDbLibProvider() {
+
+ Bundle bundle = FrameworkUtil.getBundle(org.onap.ccsdk.sli.core.dblib.DbLibService.class);
+ try {
+ bundle.stop();
+ bundle.start();
+ //Thread.sleep(5000);
+ } catch (org.osgi.framework.BundleException be) {
+ logger.error("Error restarting db lib" + be.toString());
+ } /*catch (InterruptedException e) {
+ }*/
+ }
+
+ private SvcLogicGraph fetchGraph(String module, String rpc, String version, String mode, StringBuilder sbError)
+ {
+ DbLibService dbLibSvc = null;
+
+ ServiceReference sref = null;
+ BundleContext bctx = null;
+
+ Bundle bundle = FrameworkUtil.getBundle(WorkFlowManagerImpl.class);
+
+ if (bundle != null) {
+ bctx = bundle.getBundleContext();
+
+ if (bctx != null) {
+ sref = bctx.getServiceReference("org.onap.ccsdk.sli.core.dblib.DbLibService");
+ }
+
+ if (sref == null) {
+ logger.warn("Could not find service reference for DBLIB service");
+ } else {
+ dbLibSvc = (DbLibService) bctx.getService(sref);
+ if (dbLibSvc == null) {
+ logger.warn("Could not find service reference for DBLIB service");
+ }
+ }
+ }
+ if (dbLibSvc == null)
+ return null;
+ else
+ logger.info("Retrieving graph(new)");
+
+ SvcLogicGraph retval = null;
+ CachedRowSet results = null;
+
+ String fetchVersionGraphSql = "SELECT graph FROM SVC_LOGIC"
+ + " WHERE module = ? AND rpc = ? AND mode = ? AND version = ?";
+
+ String fetchActiveGraphSql = "SELECT graph FROM SVC_LOGIC"
+ + " WHERE module = ? AND rpc = ? AND mode = ? AND active = 'Y'";
+
+
+ String fetchGraphStmt;
+
+ ArrayList<String> params = new ArrayList<>();
+ params.add(module);
+ params.add(rpc);
+ params.add(mode);
+
+ if (version == null) {
+ fetchGraphStmt = fetchActiveGraphSql;
+ } else {
+ params.add(version);
+ fetchGraphStmt = fetchVersionGraphSql;
+ }
+
+ StringBuilder sqlBuilder = new StringBuilder(fetchGraphStmt);
+ try {
+ results = dbLibSvc.getData(sqlBuilder.toString(), new ArrayList(params), "sdnctl");
+
+ if (results.next()) {
+
+ ObjectInputStream gStream = new ObjectInputStream(results.getBinaryStream("graph"));
+
+ Object graphObj = gStream.readObject();
+ gStream.close();
+
+ if (graphObj instanceof SvcLogicGraph) {
+ retval = (SvcLogicGraph) graphObj;
+ } else {
+ logger.error("invalid type for graph " + graphObj.getClass().getName());
+ return null;
+ }
+
+ } else {
+ return null;
+ }
+ } catch (SQLException e) {
+ logger.error("query " + sqlBuilder + " :: " + e.getMessage() + " Will retry");
+ //sbError.append(DRIVER_ERROR);
+ return null;
+ } catch (IOException e) {
+ logger.error("IOException " + " :: " + e.getMessage() + " Will retry");
+ //sbError.append(DRIVER_ERROR);
+ return null;
+ } catch (Exception e) {
+ logger.error("Exception " + " :: " + e.getMessage() + " Will retry");
+ sbError.append(DRIVER_ERROR);
+ return null;
+ }
+
+
+ return retval;
+ }
+
+ protected Properties workflowExecute(String module, String rpc, String version, String mode, Properties props)
+ throws SvcLogicException {
+ logger.info("Fetching service logic from data store");
+ //logger.info("Trial Restart ");
+ //restartDbLibProvider();
+ //logger.info("Trial Restart End");
+
+ StringBuilder sbError = new StringBuilder();
+ SvcLogicGraph graph = fetchGraph(module, rpc, version, mode, sbError);
+ if (sbError.toString().equals(DRIVER_ERROR))
+ {
+ restartDbLibProvider();
+ sbError = new StringBuilder();
+ graph = fetchGraph(module, rpc, version, mode, sbError);
+ }
+ if (graph == null) {
+ Properties retProps = new Properties();
+ retProps.setProperty("error-code", "401");
+ retProps.setProperty("error-message",
+ "No service logic found for [" + module + "," + rpc + "," + version + "," + mode + "]");
+ return (retProps);
+ }
+
+ SvcLogicContext ctx = new SvcLogicContext(props);
+ ctx.setAttribute("currentGraph", graph.toString());
+ ctx.setAttribute("X-ONAP-RequestID", MDC.get("X-ONAP-RequestID"));
+ svcLogic.execute(graph, ctx);
+ return (ctx.toProperties());
+ }
+
+ private void SVCLogicServiceExecute(WorkflowKey workflowKey, RequestContext requestContext,
+ Properties workflowParams, WorkflowResponse workflowResponse) {