diff options
author | Gaurav Agrawal <gaurav.agrawal@huawei.com> | 2017-09-25 12:58:52 +0530 |
---|---|---|
committer | Gaurav Agrawal <gaurav.agrawal@huawei.com> | 2017-09-25 12:58:52 +0530 |
commit | 0923423a42c94993d79d342c6679905e80346b29 (patch) | |
tree | 3108f02eb2db1e688d7aeb274374bc765a699d9c | |
parent | bac4dbe402cc81409d210a2dabd25847a12b6a36 (diff) |
Fixes for SvcLogicActivator
1. Convert tabs to 4 spaces.
2. Break lines to be less than 120 characters
3. Remove extraneous spaces/parenthesis & redundant assignments.
4. Use logger built-in string format.
5. Fix critical sonar issues.
https://sonar.onap.org/component_issues/index?id=org.onap.ccsdk.sli.core%3Accsdk-sli-core#resolved=false|severities=CRITICAL
Change-Id: Idb348f125e92f0e9be30847c41b385411220fd96
Issue-Id: CCSDK-67
Signed-off-by: Gaurav Agrawal <gaurav.agrawal@huawei.com>
-rw-r--r-- | sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/SvcLogicActivator.java | 291 |
1 files changed, 141 insertions, 150 deletions
diff --git a/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/SvcLogicActivator.java b/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/SvcLogicActivator.java index a578dc6a..7c1fa8e4 100644 --- a/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/SvcLogicActivator.java +++ b/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/SvcLogicActivator.java @@ -3,7 +3,7 @@ * ONAP : CCSDK * ================================================================================ * Copyright (C) 2017 AT&T Intellectual Property. All rights - * reserved. + * reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -28,7 +28,6 @@ import java.util.Hashtable; import java.util.LinkedList; import java.util.Map; import java.util.Properties; - import org.onap.ccsdk.sli.core.sli.ConfigurationException; import org.onap.ccsdk.sli.core.sli.SvcLogicAdaptor; import org.onap.ccsdk.sli.core.sli.SvcLogicException; @@ -44,180 +43,172 @@ import org.slf4j.LoggerFactory; public class SvcLogicActivator implements BundleActivator { - private static final String SVCLOGIC_PROP_VAR = "SDNC_SLI_PROPERTIES"; - private static final String SDNC_CONFIG_DIR = "SDNC_CONFIG_DIR"; - - private static final Map<String, SvcLogicNodeExecutor> BUILTIN_NODES = new HashMap<String, SvcLogicNodeExecutor>() { - { - put("block", new BlockNodeExecutor()); - put("call", new CallNodeExecutor()); - put("configure", new ConfigureNodeExecutor()); - put("delete", new DeleteNodeExecutor()); - put("execute", new ExecuteNodeExecutor()); - put("exists", new ExistsNodeExecutor()); - put("for", new ForNodeExecutor()); - put("get-resource", new GetResourceNodeExecutor()); - put("is-available", new IsAvailableNodeExecutor()); - put("notify", new NotifyNodeExecutor()); - put("record", new RecordNodeExecutor()); - put("release", new ReleaseNodeExecutor()); - put("reserve", new ReserveNodeExecutor()); - put("return", new ReturnNodeExecutor()); - put("save", new SaveNodeExecutor()); - put("set", new SetNodeExecutor()); - put("switch", new SwitchNodeExecutor()); - put("update", new UpdateNodeExecutor()); + private static final String SVCLOGIC_PROP_VAR = "SDNC_SLI_PROPERTIES"; + private static final String SDNC_CONFIG_DIR = "SDNC_CONFIG_DIR"; + + private static final Map<String, SvcLogicNodeExecutor> BUILTIN_NODES = new HashMap<String, SvcLogicNodeExecutor>() { + { + put("block", new BlockNodeExecutor()); + put("call", new CallNodeExecutor()); + put("configure", new ConfigureNodeExecutor()); + put("delete", new DeleteNodeExecutor()); + put("execute", new ExecuteNodeExecutor()); + put("exists", new ExistsNodeExecutor()); + put("for", new ForNodeExecutor()); + put("get-resource", new GetResourceNodeExecutor()); + put("is-available", new IsAvailableNodeExecutor()); + put("notify", new NotifyNodeExecutor()); + put("record", new RecordNodeExecutor()); + put("release", new ReleaseNodeExecutor()); + put("reserve", new ReserveNodeExecutor()); + put("return", new ReturnNodeExecutor()); + put("save", new SaveNodeExecutor()); + put("set", new SetNodeExecutor()); + put("switch", new SwitchNodeExecutor()); + put("update", new UpdateNodeExecutor()); put("break", new BreakNodeExecutor()); - } - }; - - private static LinkedList<ServiceRegistration> registrations = new LinkedList<ServiceRegistration>(); - - private static HashMap<String, SvcLogicAdaptor> adaptorMap = null; - - private static final Logger LOG = LoggerFactory - .getLogger(SvcLogicActivator.class); - - private static Properties props = null; - - private static BundleContext bundleCtx = null; - - private static SvcLogicService svcLogicServiceImpl = null; - - @Override - public void start(BundleContext ctx) throws Exception { - - LOG.info("Activating SLI"); - - bundleCtx = ctx; - - // Read properties - props = new Properties(); - String propPath = System.getenv(SVCLOGIC_PROP_VAR); - - if (propPath == null) { - String propDir = System.getenv(SDNC_CONFIG_DIR); - if (propDir == null) { - - propDir = "/opt/sdnc/data/properties"; - } - propPath = propDir + "/svclogic.properties"; - LOG.warn("Environment variable "+SVCLOGIC_PROP_VAR+" unset - defaulting to "+propPath); - } - - File propFile = new File(propPath); - - if (!propFile.exists()) { - - throw new ConfigurationException( - "Missing configuration properties file : " - + propFile); - } - try { - - props.load(new FileInputStream(propFile)); - } catch (Exception e) { - throw new ConfigurationException( - "Could not load properties file " + propPath, e); + } + }; - } + private static final Logger LOG = LoggerFactory.getLogger(SvcLogicActivator.class); + private static LinkedList<ServiceRegistration> registrations = new LinkedList<>(); - if (registrations == null) { + private static HashMap<String, SvcLogicAdaptor> adaptorMap; - registrations = new LinkedList<ServiceRegistration>(); - } + private static Properties props; - // Advertise SvcLogicService - svcLogicServiceImpl = new SvcLogicServiceImpl(); + private static BundleContext bundleCtx; - LOG.info("SLI: Registering service " + SvcLogicService.NAME - + " in bundle " + ctx.getBundle().getSymbolicName()); - ServiceRegistration reg = ctx.registerService(SvcLogicService.NAME, - svcLogicServiceImpl, null); - registrations.add(reg); + private static SvcLogicService svcLogicServiceImpl; - // Initialize SvcLogicStore - try { - SvcLogicStore store = getStore(); - registerNodeTypes(store); - } catch (ConfigurationException e) { - LOG.warn("Could not initialize SvcLogicScore", e); - } + @Override + public void start(BundleContext ctx) throws Exception { - LOG.info("SLI - done registering services"); - } + LOG.info("Activating SLI"); - @Override - public void stop(BundleContext ctx) throws Exception { + synchronized (SvcLogicActivator.class) { + bundleCtx = ctx; + props = new Properties(); + } - if (registrations != null) { - for (ServiceRegistration reg : registrations) { - ServiceReference regRef = reg.getReference(); - /* Don't bother to remove node types from table - String nodeType = (String) regRef.getProperty("nodeType"); - if (nodeType != null) { - LOG.info("SLI - unregistering node type " + nodeType); - store.unregisterNodeType(nodeType); - } - */ - reg.unregister(); - } - registrations = null; - } - } + // Read properties + String propPath = System.getenv(SVCLOGIC_PROP_VAR); - public static SvcLogicStore getStore() throws SvcLogicException { - // Create and initialize SvcLogicStore object - used to access - // saved service logic. + if (propPath == null) { + String propDir = System.getenv(SDNC_CONFIG_DIR); + if (propDir == null) { - SvcLogicStore store = null; + propDir = "/opt/sdnc/data/properties"; + } + propPath = propDir + "/svclogic.properties"; + LOG.warn("Environment variable {} unset - defaulting to {}", SVCLOGIC_PROP_VAR, propPath); + } - try { - store = SvcLogicStoreFactory.getSvcLogicStore(props); - } catch (Exception e) { - throw new ConfigurationException( - "Could not get service logic store", e); + File propFile = new File(propPath); - } + if (!propFile.exists()) { + throw new ConfigurationException("Missing configuration properties file : " + propFile); + } - try { - store.init(props); - } catch (Exception e) { - throw new ConfigurationException( - "Could not get service logic store", e); - } + try { + props.load(new FileInputStream(propFile)); + } catch (Exception e) { + throw new ConfigurationException("Could not load properties file " + propPath, e); - return(store); - } + } - private static void registerNodeTypes(SvcLogicStore store) throws SvcLogicException { + synchronized (SvcLogicActivator.class) { + if (registrations == null) { + registrations = new LinkedList<>(); + } + // Advertise SvcLogicService + svcLogicServiceImpl = new SvcLogicServiceImpl(); + } - if (store == null) { - return; - } - // Advertise built-in node executors - LOG.info("SLI : Registering built-in node executors"); - Hashtable propTable = new Hashtable(); + LOG.info("SLI: Registering service {} in bundle {}", SvcLogicService.NAME, ctx.getBundle().getSymbolicName()); + ServiceRegistration reg = ctx.registerService(SvcLogicService.NAME, svcLogicServiceImpl, null); + registrations.add(reg); - for (String nodeType : BUILTIN_NODES.keySet()) { - LOG.info("SLI - registering node type " + nodeType); - propTable.clear(); - propTable.put("nodeType", nodeType); + // Initialize SvcLogicStore + try { + SvcLogicStore store = getStore(); + registerNodeTypes(store); + } catch (ConfigurationException e) { + LOG.warn("Could not initialize SvcLogicScore", e); + } - ServiceRegistration reg = bundleCtx.registerService(SvcLogicNodeExecutor.class.getName(), - BUILTIN_NODES.get(nodeType), propTable); - registrations.add(reg); + LOG.info("SLI - done registering services"); + } - store.registerNodeType(nodeType); + @Override + public void stop(BundleContext ctx) throws Exception { - LOG.info("SLI - registering node executor"); + if (registrations != null) { + for (ServiceRegistration reg : registrations) { + ServiceReference regRef = reg.getReference(); + /* Don't bother to remove node types from table + String nodeType = (String) regRef.getProperty("nodeType"); + if (nodeType != null) { + LOG.info("SLI - unregistering node type " + nodeType); + store.unregisterNodeType(nodeType); + } + */ + reg.unregister(); + } + synchronized (SvcLogicActivator.class) { + registrations = null; + } + } + } - ((SvcLogicServiceImpl)svcLogicServiceImpl).registerExecutor(nodeType, BUILTIN_NODES.get(nodeType)); + public static SvcLogicStore getStore() throws SvcLogicException { + // Create and initialize SvcLogicStore object - used to access + // saved service logic. - } + SvcLogicStore store; - } + try { + store = SvcLogicStoreFactory.getSvcLogicStore(props); + } catch (Exception e) { + throw new ConfigurationException("Could not get service logic store", e); + } + + try { + store.init(props); + } catch (Exception e) { + throw new ConfigurationException("Could not get service logic store", e); + } + + return(store); + } + + private static void registerNodeTypes(SvcLogicStore store) throws SvcLogicException { + + if (store == null) { + return; + } + // Advertise built-in node executors + LOG.info("SLI : Registering built-in node executors"); + Hashtable propTable = new Hashtable(); + + for (String nodeType : BUILTIN_NODES.keySet()) { + LOG.info("SLI - registering node type {}", nodeType); + propTable.clear(); + propTable.put("nodeType", nodeType); + + ServiceRegistration reg = bundleCtx.registerService(SvcLogicNodeExecutor.class.getName(), + BUILTIN_NODES.get(nodeType), propTable); + registrations.add(reg); + + store.registerNodeType(nodeType); + + LOG.info("SLI - registering node executor"); + + ((SvcLogicServiceImpl)svcLogicServiceImpl).registerExecutor(nodeType, BUILTIN_NODES.get(nodeType)); + + } + } } |