diff options
author | Kevin Smokowski <ks6305@att.com> | 2017-05-26 18:23:42 +0000 |
---|---|---|
committer | Kevin Smokowski <ks6305@att.com> | 2017-05-26 18:23:42 +0000 |
commit | ae1e918820b3b4e70b7844b3c1d6c45dcde3b22d (patch) | |
tree | fd24d5677940db51a67ba893b7241e2d8d77abe0 /sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/SvcLogicActivator.java | |
parent | dda3edb6257146ab6599bfd44658a9791037511d (diff) |
SDNC-12 refactoring to support easy mocking
Change-Id: I5788e5b728c12bbefe83f1702f508a6a1daf22f0
Signed-off-by: Kevin Smokowski <ks6305@att.com>
Diffstat (limited to 'sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/SvcLogicActivator.java')
-rw-r--r-- | sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/SvcLogicActivator.java | 437 |
1 files changed, 218 insertions, 219 deletions
diff --git a/sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/SvcLogicActivator.java b/sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/SvcLogicActivator.java index 8996095..ae42e2c 100644 --- a/sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/SvcLogicActivator.java +++ b/sli/provider/src/main/java/org/openecomp/sdnc/sli/provider/SvcLogicActivator.java @@ -1,226 +1,225 @@ -/*-
+/*- * ============LICENSE_START======================================================= * openECOMP : SDN-C * ================================================================================ * Copyright (C) 2017 AT&T Intellectual Property. All rights * reserved. * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
+ * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and * limitations under the License. - * ============LICENSE_END=========================================================
- */
-
-package org.openecomp.sdnc.sli.provider;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.net.URL;
-import java.util.HashMap;
-import java.util.Hashtable;
-import java.util.LinkedList;
-import java.util.Map;
-import java.util.Properties;
-
-import org.openecomp.sdnc.sli.ConfigurationException;
-import org.openecomp.sdnc.sli.SvcLogicAdaptor;
-import org.openecomp.sdnc.sli.SvcLogicException;
-import org.openecomp.sdnc.sli.SvcLogicStore;
-import org.openecomp.sdnc.sli.SvcLogicStoreFactory;
-import org.osgi.framework.BundleActivator;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.ServiceReference;
-import org.osgi.framework.ServiceRegistration;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import com.mysql.jdbc.Driver;
-
-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());
- put("break", new BreakNodeExecutor());
- put("while", new WhileNodeExecutor());
- }
- };
-
- 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);
-
- }
-
-
- if (registrations == null) {
-
- registrations = new LinkedList<ServiceRegistration>();
- }
-
- // Advertise SvcLogicService
- svcLogicServiceImpl = new SvcLogicServiceImpl();
-
- LOG.info("SLI: Registering service " + SvcLogicService.NAME
- + " in bundle " + ctx.getBundle().getSymbolicName());
- ServiceRegistration reg = ctx.registerService(SvcLogicService.NAME,
- svcLogicServiceImpl, null);
- registrations.add(reg);
-
- // Initialize SvcLogicStore
- try {
- SvcLogicStore store = getStore();
- registerNodeTypes(store);
- } catch (ConfigurationException e) {
- LOG.warn("Could not initialize SvcLogicScore", e);
- }
-
- LOG.info("SLI - done registering services");
- }
-
- @Override
- public void stop(BundleContext ctx) throws Exception {
-
- 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;
- }
- }
-
- public static SvcLogicStore getStore() throws SvcLogicException {
- // Create and initialize SvcLogicStore object - used to access
- // saved service logic.
-
- SvcLogicStore store = null;
-
- try {
- Driver dvr = new Driver();
- 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));
-
- }
-
- }
-
-}
+ * ============LICENSE_END========================================================= + */ + +package org.openecomp.sdnc.sli.provider; + +import java.io.File; +import java.io.FileInputStream; +import java.util.HashMap; +import java.util.Hashtable; +import java.util.LinkedList; +import java.util.Map; +import java.util.Properties; + +import org.openecomp.sdnc.sli.ConfigurationException; +import org.openecomp.sdnc.sli.SvcLogicAdaptor; +import org.openecomp.sdnc.sli.SvcLogicException; +import org.openecomp.sdnc.sli.SvcLogicStore; +import org.openecomp.sdnc.sli.SvcLogicStoreFactory; +import org.osgi.framework.BundleActivator; +import org.osgi.framework.BundleContext; +import org.osgi.framework.ServiceReference; +import org.osgi.framework.ServiceRegistration; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.mysql.jdbc.Driver; + +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()); + 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); + + } + + + if (registrations == null) { + + registrations = new LinkedList<ServiceRegistration>(); + } + + // Advertise SvcLogicService + svcLogicServiceImpl = new SvcLogicServiceImpl(); + + LOG.info("SLI: Registering service " + SvcLogicService.NAME + + " in bundle " + ctx.getBundle().getSymbolicName()); + ServiceRegistration reg = ctx.registerService(SvcLogicService.NAME, + svcLogicServiceImpl, null); + registrations.add(reg); + + // Initialize SvcLogicStore + try { + SvcLogicStore store = getStore(); + registerNodeTypes(store); + } catch (ConfigurationException e) { + LOG.warn("Could not initialize SvcLogicScore", e); + } + + LOG.info("SLI - done registering services"); + } + + @Override + public void stop(BundleContext ctx) throws Exception { + + 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; + } + } + + public static SvcLogicStore getStore() throws SvcLogicException { + // Create and initialize SvcLogicStore object - used to access + // saved service logic. + + SvcLogicStore store = null; + + try { + Driver dvr = new Driver(); + 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)); + + } + + } + +} |