diff options
author | Gaurav Agrawal <gaurav.agrawal@huawei.com> | 2017-09-27 16:13:04 +0530 |
---|---|---|
committer | Gaurav Agrawal <gaurav.agrawal@huawei.com> | 2017-09-27 16:13:04 +0530 |
commit | bebf6ea5839c87799602da01b166000f8b746b86 (patch) | |
tree | 23b1535e24058ff74ae4134b7a8d8b0f2442a120 /sli/provider/src/main/java/org/onap/ccsdk | |
parent | 3458e16a7f0c9b48337a295359cda65423dbd587 (diff) |
Refinements to core
Changes includes:
1. Simplifying the test cases.
2. Critical Sonar issue fix for MdsalHelper
3. Critical sonar issue fix for SvcLogicServiceImpl
4. Use logger in-built formatting.
https://sonar.onap.org/component_issues/index?id=org.onap.ccsdk.sli.core%3Accsdk-sli-core#resolved=false|severities=CRITICAL
Change-Id: Ib85637fcd2351970f8d96bf6b855db05cf7d9834
Issue-Id: CCSDK-67
Signed-off-by: Gaurav Agrawal <gaurav.agrawal@huawei.com>
Diffstat (limited to 'sli/provider/src/main/java/org/onap/ccsdk')
-rw-r--r-- | sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/MdsalHelper.java | 2 | ||||
-rw-r--r-- | sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/SvcLogicServiceImpl.java | 64 |
2 files changed, 20 insertions, 46 deletions
diff --git a/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/MdsalHelper.java b/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/MdsalHelper.java index 3eeb398f..52c25b6b 100644 --- a/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/MdsalHelper.java +++ b/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/MdsalHelper.java @@ -765,7 +765,7 @@ public class MdsalHelper { } catch (Exception gme) { LOG.info("Unable to find static method getDefaultInstance for " - + "class {}", paramClass.getSimpleName(), e); + + "class {}", paramClass.getSimpleName(), gme); } } diff --git a/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/SvcLogicServiceImpl.java b/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/SvcLogicServiceImpl.java index 4bb460d7..5f4d3653 100644 --- a/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/SvcLogicServiceImpl.java +++ b/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/SvcLogicServiceImpl.java @@ -59,12 +59,11 @@ public class SvcLogicServiceImpl implements SvcLogicService { } if (nodeExecutors == null) { - nodeExecutors = new HashMap<String, SvcLogicNodeExecutor>(); + nodeExecutors = new HashMap<>(); } LOG.info("Opening service tracker"); - ServiceTracker tracker = new ServiceTracker(bctx, - SvcLogicNodeExecutor.class.getName(), null); + ServiceTracker tracker = new ServiceTracker(bctx, SvcLogicNodeExecutor.class.getName(), null); tracker.open(); @@ -90,14 +89,12 @@ public class SvcLogicServiceImpl implements SvcLogicService { + ")"; try { bctx.addServiceListener(listener, filter); - ServiceReference[] srl = bctx.getServiceReferences( - SvcLogicNodeExecutor.class.getName(), null); + ServiceReference[] srl = bctx.getServiceReferences(SvcLogicNodeExecutor.class.getName(), null); for (int i = 0; srl != null && i < srl.length; i++) { - listener.serviceChanged(new ServiceEvent( - ServiceEvent.REGISTERED, srl[i])); + listener.serviceChanged(new ServiceEvent(ServiceEvent.REGISTERED, srl[i])); } } catch (InvalidSyntaxException e) { - e.printStackTrace(); + LOG.info("Invalid syntax", e); } LOG.info("Done registerExecutors"); } @@ -107,26 +104,24 @@ public class SvcLogicServiceImpl implements SvcLogicService { String nodeName = (String) sr.getProperty("nodeType"); if (nodeName != null) { - SvcLogicNodeExecutor executor = null; + SvcLogicNodeExecutor executor; try { executor = (SvcLogicNodeExecutor) bctx.getService(sr); } catch (Exception e) { - LOG.error("Cannot get service executor for " + nodeName); + LOG.error("Cannot get service executor for {}", nodeName, e); return; } - registerExecutor(nodeName, executor); - } } public void registerExecutor(String nodeName, SvcLogicNodeExecutor executor) { if (nodeExecutors == null) { - nodeExecutors = new HashMap<String, SvcLogicNodeExecutor>(); + nodeExecutors = new HashMap<>(); } - LOG.info("SLI - registering executor for node type "+nodeName); + LOG.info("SLI - registering executor for node type {}", nodeName); nodeExecutors.put(nodeName, executor); } @@ -134,25 +129,16 @@ public class SvcLogicServiceImpl implements SvcLogicService { String nodeName = (String) sr.getProperty("nodeType"); if (nodeName != null) { - unregisterExecutor(nodeName); - } - } - public void unregisterExecutor(String nodeName) - { - - LOG.info("SLI - unregistering executor for node type "+nodeName); + public void unregisterExecutor(String nodeName) { + LOG.info("SLI - unregistering executor for node type {}", nodeName); nodeExecutors.remove(nodeName); } - - - - public SvcLogicContext execute(SvcLogicGraph graph, SvcLogicContext ctx) - throws SvcLogicException { + public SvcLogicContext execute(SvcLogicGraph graph, SvcLogicContext ctx) throws SvcLogicException { if (nodeExecutors == null) { registerExecutors(); @@ -164,13 +150,11 @@ public class SvcLogicServiceImpl implements SvcLogicService { MDC.put("currentGraph", graph.toString()); SvcLogicNode curNode = graph.getRootNode(); - LOG.info("About to execute graph " + graph.toString()); - - + LOG.info("About to execute graph {}", graph.toString()); while (curNode != null) { MDC.put("nodeId", curNode.getNodeId()+" ("+curNode.getNodeType()+")"); - LOG.info("About to execute node # "+curNode.getNodeId()+" ("+curNode.getNodeType()+")"); + LOG.info("About to execute node # {} ({})", curNode.getNodeId(), curNode.getNodeType()); SvcLogicNode nextNode = executeNode(curNode, ctx); curNode = nextNode; @@ -181,25 +165,24 @@ public class SvcLogicServiceImpl implements SvcLogicService { return (ctx); } - - public SvcLogicNode executeNode(SvcLogicNode node, SvcLogicContext ctx) - throws SvcLogicException { + public SvcLogicNode executeNode(SvcLogicNode node, SvcLogicContext ctx) throws SvcLogicException { if (node == null) { return (null); } if (LOG.isDebugEnabled()) { - LOG.debug("Executing node " + node.getNodeId()); + LOG.debug("Executing node {}", node.getNodeId()); } SvcLogicNodeExecutor executor = nodeExecutors.get(node.getNodeType()); if (executor != null) { - LOG.debug("Executing node executor for node type "+node.getNodeType()+" - "+executor.getClass().getName()); + LOG.debug("Executing node executor for node type {} - {}", + node.getNodeType(), executor.getClass().getName()); return (executor.execute(this, node, ctx)); } else { if (LOG.isDebugEnabled()) { - LOG.debug(node.getNodeType() + " node not implemented"); + LOG.debug("{} node not implemented", node.getNodeType()); } SvcLogicNode nextNode = node.getOutcomeValue("failure"); if (nextNode != null) { @@ -243,23 +226,18 @@ public class SvcLogicServiceImpl implements SvcLogicService { public Properties execute(String module, String rpc, String version, String mode, Properties props, DOMDataBroker domDataBroker) throws SvcLogicException { - // See if there is a service logic defined - // SvcLogicStore store = SvcLogicActivator.getStore(); LOG.info("Fetching service logic from data store"); SvcLogicGraph graph = store.fetch(module, rpc, version, mode); - - 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); @@ -271,8 +249,4 @@ public class SvcLogicServiceImpl implements SvcLogicService { return(ctx.toProperties()); } - - - - } |