diff options
Diffstat (limited to 'sli')
6 files changed, 51 insertions, 112 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()) { |