summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSamuel Kontris <samuel.kontris@pantheon.tech>2019-09-04 15:31:48 +0200
committerDan Timoney <dtimoney@att.com>2019-10-15 18:19:47 +0000
commit574363f5a29ac9237a377c4c0923b414a38fddec (patch)
tree7f74f7e8acfc05055bd3ff281e57d6b0c37cb982
parent4999c933f01789a4f71eb34cc32c7377c62ee2dd (diff)
Refactor class/instance loading and resolving in the SLI module
Code from the static class SvcLogicAdaptorFactory is moved to the SvcLogicClassResolver class. Class SvcLogicClassResolver is created as a bean in the blueprint xml file, not as singleton directly in the code. Then is injected via blueprint into the SvcLogicServiceImpl. Methods registerExecutor and unregisterExecutor from the SvcLogicServiceImpl class are removed - are not used anywhere. This change causes compilation error in the northbound repository. Fix for this error is here: https://gerrit.onap.org/r/#/c/ccsdk/sli/northbound/+/95053/ Issue-ID: CCSDK-1688 Change-Id: I26ce01b761ab5d17f1cc19e39af581b1963658a5 Signed-off-by: Samuel Kontris <samuel.kontris@pantheon.tech>
-rw-r--r--sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/SvcLogicAdaptorFactory.java65
-rw-r--r--sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/SvcLogicClassResolver.java36
-rwxr-xr-xsli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/SvcLogicServiceImpl.java38
-rw-r--r--sli/provider/src/main/resources/OSGI-INF/blueprint/sli-blueprint.xml7
-rw-r--r--sli/provider/src/main/resources/org/opendaylight/blueprint/sli-blueprint.xml7
-rw-r--r--sli/provider/src/test/java/org/onap/ccsdk/sli/core/sli/provider/ITCaseSvcLogicGraphExecutor.java10
-rw-r--r--sliapi/provider/src/test/java/org/onap/ccsdk/sli/core/sliapi/TestSliapiProvider.java5
7 files changed, 54 insertions, 114 deletions
diff --git a/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/SvcLogicAdaptorFactory.java b/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/SvcLogicAdaptorFactory.java
deleted file mode 100644
index 540c04ef..00000000
--- a/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/SvcLogicAdaptorFactory.java
+++ /dev/null
@@ -1,65 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * ONAP : CCSDK
- * ================================================================================
- * 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
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.ccsdk.sli.core.sli.provider;
-
-import java.util.HashMap;
-
-import org.onap.ccsdk.sli.core.sli.SvcLogicAdaptor;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public class SvcLogicAdaptorFactory {
-
- private static final Logger LOG = LoggerFactory
- .getLogger(SvcLogicAdaptorFactory.class);
-
- private static HashMap<String, SvcLogicAdaptor> adaptorMap = new HashMap<>();
-
- public static void registerAdaptor(SvcLogicAdaptor adaptor) {
- String name = adaptor.getClass().getName();
- LOG.info("Registering adaptor " + name);
- adaptorMap.put(name, adaptor);
-
- }
-
- public static void unregisterAdaptor(String name) {
- if (adaptorMap.containsKey(name)) {
- LOG.info("Unregistering " + name);
- adaptorMap.remove(name);
- }
- }
-
- public static SvcLogicAdaptor getInstance(String name) {
- if (adaptorMap.containsKey(name)) {
- return adaptorMap.get(name);
- } else {
-
- SvcLogicAdaptor adaptor = (SvcLogicAdaptor) SvcLogicClassResolver.getInstance().resolve(name);
-
- if (adaptor != null) {
- registerAdaptor(adaptor);
- }
-
- return adaptor;
- }
- }
-}
diff --git a/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/SvcLogicClassResolver.java b/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/SvcLogicClassResolver.java
index f10976a5..08e957f1 100644
--- a/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/SvcLogicClassResolver.java
+++ b/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/SvcLogicClassResolver.java
@@ -1,5 +1,6 @@
package org.onap.ccsdk.sli.core.sli.provider;
+import java.util.HashMap;
import org.onap.ccsdk.sli.core.sli.SvcLogicAdaptor;
import org.onap.ccsdk.sli.core.sli.SvcLogicJavaPlugin;
import org.onap.ccsdk.sli.core.sli.SvcLogicRecorder;
@@ -13,17 +14,40 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class SvcLogicClassResolver implements SvcLogicResolver {
+
private static final Logger LOG = LoggerFactory.getLogger(SvcLogicClassResolver.class);
- private static SvcLogicClassResolver instance = new SvcLogicClassResolver();
+ private static HashMap<String, SvcLogicAdaptor> adaptorMap = new HashMap<>();
+
+ public void registerAdaptor(SvcLogicAdaptor adaptor) {
+ String name = adaptor.getClass().getName();
+ LOG.info("Registering adaptor " + name);
+ adaptorMap.put(name, adaptor);
+
+ }
- private SvcLogicClassResolver() {
+ public void unregisterAdaptor(String name) {
+ if (adaptorMap.containsKey(name)) {
+ LOG.info("Unregistering " + name);
+ adaptorMap.remove(name);
+ }
}
- public static SvcLogicClassResolver getInstance() {
- return instance;
+ private SvcLogicAdaptor getAdaptorInstance(String name) {
+ if (adaptorMap.containsKey(name)) {
+ return adaptorMap.get(name);
+ } else {
+
+ SvcLogicAdaptor adaptor = (SvcLogicAdaptor) resolve(name);
+
+ if (adaptor != null) {
+ registerAdaptor(adaptor);
+ }
+
+ return adaptor;
+ }
}
- public Object resolve(String className) {
+ private Object resolve(String className) {
Bundle bundle = FrameworkUtil.getBundle(SvcLogicClassResolver.class);
@@ -68,7 +92,7 @@ public class SvcLogicClassResolver implements SvcLogicResolver {
@Override
public SvcLogicAdaptor getSvcLogicAdaptor(String adaptorName) {
- return SvcLogicAdaptorFactory.getInstance(adaptorName);
+ return getAdaptorInstance(adaptorName);
}
}
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 0d49366f..9e91b751 100755
--- 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
@@ -32,13 +32,11 @@ import org.onap.ccsdk.sli.core.sli.SvcLogicException;
import org.onap.ccsdk.sli.core.sli.SvcLogicGraph;
import org.onap.ccsdk.sli.core.sli.SvcLogicStore;
import org.onap.ccsdk.sli.core.sli.SvcLogicStoreFactory;
-import org.onap.ccsdk.sli.core.sli.provider.base.AbstractSvcLogicNodeExecutor;
import org.onap.ccsdk.sli.core.sli.provider.base.SvcLogicPropertiesProvider;
+import org.onap.ccsdk.sli.core.sli.provider.base.SvcLogicResolver;
import org.onap.ccsdk.sli.core.sli.provider.base.SvcLogicServiceImplBase;
import org.onap.logging.ref.slf4j.ONAPLogConstants;
import org.opendaylight.controller.md.sal.dom.api.DOMDataBroker;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.ServiceReference;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.MDC;
@@ -46,45 +44,23 @@ import org.slf4j.MDC;
public class SvcLogicServiceImpl extends SvcLogicServiceImplBase implements SvcLogicService {
private static final Logger LOG = LoggerFactory.getLogger(SvcLogicServiceImpl.class);
- protected BundleContext bctx = null;
- public SvcLogicServiceImpl(SvcLogicPropertiesProvider resourceProvider) throws SvcLogicException {
+ public SvcLogicServiceImpl(SvcLogicPropertiesProvider resourceProvider, SvcLogicResolver resolver)
+ throws SvcLogicException {
super(null);
- this.resolver = SvcLogicClassResolver.getInstance();
+ this.resolver = resolver;
properties = resourceProvider.getProperties();
this.store = getStore();
}
- public SvcLogicServiceImpl(SvcLogicPropertiesProvider resourceProvider, DbLibService dbSvc)
- throws SvcLogicException {
+ public SvcLogicServiceImpl(SvcLogicPropertiesProvider resourceProvider, DbLibService dbSvc,
+ SvcLogicResolver resolver) throws SvcLogicException {
super(null);
- this.resolver = SvcLogicClassResolver.getInstance();
+ this.resolver = resolver;
properties = resourceProvider.getProperties();
this.store = new SvcLogicDblibStore(dbSvc);
}
- public void registerExecutor(ServiceReference sr) {
- String nodeName = (String) sr.getProperty("nodeType");
- if (nodeName != null) {
- AbstractSvcLogicNodeExecutor executor;
- try {
- executor = (AbstractSvcLogicNodeExecutor) bctx.getService(sr);
- } catch (Exception e) {
- LOG.error("Cannot get service executor for {}", nodeName, e);
- return;
- }
- registerExecutor(nodeName, executor);
- }
- }
-
- public void unregisterExecutor(ServiceReference sr) {
- String nodeName = (String) sr.getProperty("nodeType");
-
- if (nodeName != null) {
- unregisterExecutor(nodeName);
- }
- }
-
@Override
public Properties execute(String module, String rpc, String version, String mode, Properties props)
throws SvcLogicException {
diff --git a/sli/provider/src/main/resources/OSGI-INF/blueprint/sli-blueprint.xml b/sli/provider/src/main/resources/OSGI-INF/blueprint/sli-blueprint.xml
index bb14477e..d88cf331 100644
--- a/sli/provider/src/main/resources/OSGI-INF/blueprint/sli-blueprint.xml
+++ b/sli/provider/src/main/resources/OSGI-INF/blueprint/sli-blueprint.xml
@@ -5,17 +5,18 @@
<bean id="propProvider" class="org.onap.ccsdk.sli.core.sli.provider.SvcLogicPropertiesProviderImpl" />
<reference id="dblibService" interface="org.onap.ccsdk.sli.core.dblib.DbLibService" />
+ <bean id="svcLogicClassResolver" class="org.onap.ccsdk.sli.core.sli.provider.SvcLogicClassResolver" />
<bean id="svcLogicService" class="org.onap.ccsdk.sli.core.sli.provider.SvcLogicServiceImpl">
<argument ref="propProvider" />
- <argument ref="dblibService"/>
+ <argument ref="dblibService" />
+ <argument ref="svcLogicClassResolver" />
</bean>
-
<service ref="svcLogicService">
<interfaces>
<value>org.onap.ccsdk.sli.core.sli.provider.SvcLogicService</value>
</interfaces>
</service>
-</blueprint> \ No newline at end of file
+</blueprint>
diff --git a/sli/provider/src/main/resources/org/opendaylight/blueprint/sli-blueprint.xml b/sli/provider/src/main/resources/org/opendaylight/blueprint/sli-blueprint.xml
index bb14477e..d88cf331 100644
--- a/sli/provider/src/main/resources/org/opendaylight/blueprint/sli-blueprint.xml
+++ b/sli/provider/src/main/resources/org/opendaylight/blueprint/sli-blueprint.xml
@@ -5,17 +5,18 @@
<bean id="propProvider" class="org.onap.ccsdk.sli.core.sli.provider.SvcLogicPropertiesProviderImpl" />
<reference id="dblibService" interface="org.onap.ccsdk.sli.core.dblib.DbLibService" />
+ <bean id="svcLogicClassResolver" class="org.onap.ccsdk.sli.core.sli.provider.SvcLogicClassResolver" />
<bean id="svcLogicService" class="org.onap.ccsdk.sli.core.sli.provider.SvcLogicServiceImpl">
<argument ref="propProvider" />
- <argument ref="dblibService"/>
+ <argument ref="dblibService" />
+ <argument ref="svcLogicClassResolver" />
</bean>
-
<service ref="svcLogicService">
<interfaces>
<value>org.onap.ccsdk.sli.core.sli.provider.SvcLogicService</value>
</interfaces>
</service>
-</blueprint> \ No newline at end of file
+</blueprint>
diff --git a/sli/provider/src/test/java/org/onap/ccsdk/sli/core/sli/provider/ITCaseSvcLogicGraphExecutor.java b/sli/provider/src/test/java/org/onap/ccsdk/sli/core/sli/provider/ITCaseSvcLogicGraphExecutor.java
index 6092d1fb..ad439cdb 100644
--- a/sli/provider/src/test/java/org/onap/ccsdk/sli/core/sli/provider/ITCaseSvcLogicGraphExecutor.java
+++ b/sli/provider/src/test/java/org/onap/ccsdk/sli/core/sli/provider/ITCaseSvcLogicGraphExecutor.java
@@ -33,7 +33,6 @@ import java.util.HashMap;
import java.util.LinkedList;
import java.util.Map;
import java.util.Properties;
-
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
@@ -44,6 +43,7 @@ import org.onap.ccsdk.sli.core.sli.SvcLogicGraph;
import org.onap.ccsdk.sli.core.sli.SvcLogicParser;
import org.onap.ccsdk.sli.core.sli.SvcLogicStore;
import org.onap.ccsdk.sli.core.sli.SvcLogicStoreFactory;
+import org.onap.ccsdk.sli.core.sli.provider.base.AbstractSvcLogicNodeExecutor;
import org.onap.ccsdk.sli.core.sli.provider.base.BlockNodeExecutor;
import org.onap.ccsdk.sli.core.sli.provider.base.BreakNodeExecutor;
import org.onap.ccsdk.sli.core.sli.provider.base.CallNodeExecutor;
@@ -61,7 +61,6 @@ import org.onap.ccsdk.sli.core.sli.provider.base.ReserveNodeExecutor;
import org.onap.ccsdk.sli.core.sli.provider.base.ReturnNodeExecutor;
import org.onap.ccsdk.sli.core.sli.provider.base.SaveNodeExecutor;
import org.onap.ccsdk.sli.core.sli.provider.base.SetNodeExecutor;
-import org.onap.ccsdk.sli.core.sli.provider.base.AbstractSvcLogicNodeExecutor;
import org.onap.ccsdk.sli.core.sli.provider.base.SvcLogicPropertiesProvider;
import org.onap.ccsdk.sli.core.sli.provider.base.SwitchNodeExecutor;
import org.onap.ccsdk.sli.core.sli.provider.base.UpdateNodeExecutor;
@@ -98,6 +97,8 @@ public class ITCaseSvcLogicGraphExecutor {
}
};
+ private static SvcLogicClassResolver svcLogicClassResolver;
+
@BeforeClass
public static void setUpBeforeClass() throws Exception {
@@ -115,7 +116,8 @@ public class ITCaseSvcLogicGraphExecutor {
SvcLogicParser parser = new SvcLogicParser();
SvcLogicPropertiesProvider resourceProvider = new SvcLogicPropertiesProviderImpl();
- SvcLogicServiceImpl svc = new SvcLogicServiceImpl(resourceProvider);
+ svcLogicClassResolver = new SvcLogicClassResolver();
+ SvcLogicServiceImpl svc = new SvcLogicServiceImpl(resourceProvider, svcLogicClassResolver);
for (String nodeType : BUILTIN_NODES.keySet()) {
svc.registerExecutor(nodeType, BUILTIN_NODES.get(nodeType));
@@ -165,7 +167,7 @@ public class ITCaseSvcLogicGraphExecutor {
return svcprops;
}
};
- SvcLogicServiceImpl svc = new SvcLogicServiceImpl(resourceProvider);
+ SvcLogicServiceImpl svc = new SvcLogicServiceImpl(resourceProvider, svcLogicClassResolver);
SvcLogicStore store = svc.getStore();
assertNotNull(store);
for (String nodeType : BUILTIN_NODES.keySet()) {
diff --git a/sliapi/provider/src/test/java/org/onap/ccsdk/sli/core/sliapi/TestSliapiProvider.java b/sliapi/provider/src/test/java/org/onap/ccsdk/sli/core/sliapi/TestSliapiProvider.java
index c898ffff..f48cf783 100644
--- a/sliapi/provider/src/test/java/org/onap/ccsdk/sli/core/sliapi/TestSliapiProvider.java
+++ b/sliapi/provider/src/test/java/org/onap/ccsdk/sli/core/sliapi/TestSliapiProvider.java
@@ -18,13 +18,13 @@ import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.concurrent.Future;
-
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.onap.ccsdk.sli.core.sli.SvcLogicParser;
import org.onap.ccsdk.sli.core.sli.SvcLogicStore;
import org.onap.ccsdk.sli.core.sli.SvcLogicStoreFactory;
+import org.onap.ccsdk.sli.core.sli.provider.SvcLogicClassResolver;
import org.onap.ccsdk.sli.core.sli.provider.SvcLogicPropertiesProviderImpl;
import org.onap.ccsdk.sli.core.sli.provider.SvcLogicServiceImpl;
import org.onap.ccsdk.sli.core.sli.provider.base.AbstractSvcLogicNodeExecutor;
@@ -124,7 +124,8 @@ public class TestSliapiProvider {
SvcLogicParser.activate("sli", "healthcheck", "1.0.0", "sync", store);
// Create a ServiceLogicService and initialize it
- SvcLogicServiceImpl svc = new SvcLogicServiceImpl(new SvcLogicPropertiesProviderImpl());
+ SvcLogicServiceImpl svc = new SvcLogicServiceImpl(new SvcLogicPropertiesProviderImpl(),
+ new SvcLogicClassResolver());
for (String nodeType : BUILTIN_NODES.keySet()) {
svc.registerExecutor(nodeType, BUILTIN_NODES.get(nodeType));
}