diff options
author | Michael Dürre <michael.duerre@highstreet-technologies.com> | 2020-09-03 11:05:35 +0200 |
---|---|---|
committer | Michael Dürre <michael.duerre@highstreet-technologies.com> | 2020-09-03 11:05:48 +0200 |
commit | eab8409c6094d6fd842bb15c803883f9064036e4 (patch) | |
tree | 76820c083317b7cb96bdc62c9afdb6b8a6882a8b | |
parent | 4756715c82c0d71f934d47620031893bc92a1344 (diff) |
fixed ready state
changed bundle state detect to bundleservice
Issue-ID: CCSDK-2726
Signed-off-by: Michael Dürre <michael.duerre@highstreet-technologies.com>
Change-Id: I74b2e7d91a2be1a6d25b74ae8ecb8a4c9d76865b
3 files changed, 60 insertions, 9 deletions
diff --git a/sdnr/wt/data-provider/provider/pom.xml b/sdnr/wt/data-provider/provider/pom.xml index 2a7b68632..85b8f308d 100644 --- a/sdnr/wt/data-provider/provider/pom.xml +++ b/sdnr/wt/data-provider/provider/pom.xml @@ -58,6 +58,10 @@ <scope>test</scope> </dependency> <dependency> + <groupId>org.apache.karaf.bundle</groupId> + <artifactId>org.apache.karaf.bundle.core</artifactId> + </dependency> + <dependency> <groupId>${project.groupId}</groupId> <artifactId>sdnr-wt-data-provider-setup</artifactId> <version>${project.version}</version> @@ -82,6 +86,7 @@ <artifactId>org.osgi.core</artifactId> <scope>provided</scope> </dependency> + <dependency> <groupId>org.apache.karaf.shell</groupId> <artifactId>org.apache.karaf.shell.core</artifactId> diff --git a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/http/ReadyHttpServlet.java b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/http/ReadyHttpServlet.java index cb74911ff..284365021 100644 --- a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/http/ReadyHttpServlet.java +++ b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/http/ReadyHttpServlet.java @@ -26,6 +26,9 @@ import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import org.apache.karaf.bundle.core.BundleInfo; +import org.apache.karaf.bundle.core.BundleService; +import org.apache.karaf.bundle.core.BundleState; import org.onap.ccsdk.features.sdnr.wt.dataprovider.http.about.MarkdownTable; import org.osgi.framework.Bundle; import org.osgi.framework.BundleContext; @@ -42,10 +45,16 @@ public class ReadyHttpServlet extends HttpServlet { private static final Logger LOG = LoggerFactory.getLogger(ReadyHttpServlet.class); private static boolean status; + + private BundleService bundleService = null; + + public void setBundleService(BundleService bundleService) { + this.bundleService = bundleService; + } @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { - if (isReady() && this.getBundleStatesNotActiveCount()==0) { + if (isReady() && this.getBundleStatesReady()) { resp.setStatus(HttpServletResponse.SC_OK); } else { @@ -66,30 +75,66 @@ public class ReadyHttpServlet extends HttpServlet { LOG.info("status is set to ready: {}", status); } - private int getBundleStatesNotActiveCount() { + private boolean getBundleStatesReady() { Bundle thisbundle = FrameworkUtil.getBundle(this.getClass()); BundleContext context = thisbundle ==null?null:thisbundle.getBundleContext(); if (context == null) { LOG.debug("no bundle context available"); - return 0; + return true; } Bundle[] bundles = context.getBundles(); if (bundles == null || bundles.length <= 0) { LOG.debug("no bundles found"); - return 0; + return true; } LOG.debug("found {} bundles", bundles.length); MarkdownTable table = new MarkdownTable(); table.setHeader(new String[] {"Bundle-Id","Version","Symbolic-Name","Status"}); int cntNotActive=0; + for (Bundle bundle : bundles) { + if(this.bundleService!=null) { + BundleInfo info = this.bundleService.getInfo(bundle); + if(info.getState()==BundleState.Active ) { + continue; + } + if(info.getState()==BundleState.Resolved ) { + if(!this.isBundleImportant(bundle.getSymbolicName())) { + LOG.trace("ignore not important bundle {} with state {}",bundle.getSymbolicName(),info.getState()); + continue; + } + } - if(bundle.getState()!=Bundle.ACTIVE) { - cntNotActive++; + LOG.trace("bundle {} is in state {}",bundle.getSymbolicName(),info.getState()); } + else { + LOG.warn("bundle service is null"); + } + cntNotActive++; + } + return cntNotActive==0; + } + + private boolean isBundleImportant(String symbolicName) { + symbolicName = symbolicName.toLowerCase(); + if(symbolicName.contains("mdsal")) { + return true; + } + if(symbolicName.contains("netconf")) { + return true; + } + if(symbolicName.contains("ccsdk")) { + return true; } - return cntNotActive; + if(symbolicName.contains("devicemanager")) { + return true; + } + if(symbolicName.contains("restconf")) { + return true; + } + + return false; } } diff --git a/sdnr/wt/data-provider/provider/src/main/resources/org/opendaylight/blueprint/impl-blueprint.xml b/sdnr/wt/data-provider/provider/src/main/resources/org/opendaylight/blueprint/impl-blueprint.xml index ad9661f66..1be114612 100644 --- a/sdnr/wt/data-provider/provider/src/main/resources/org/opendaylight/blueprint/impl-blueprint.xml +++ b/sdnr/wt/data-provider/provider/src/main/resources/org/opendaylight/blueprint/impl-blueprint.xml @@ -29,11 +29,12 @@ <reference id="rpcProviderService" interface="org.opendaylight.mdsal.binding.api.RpcProviderService" odl:type="default"/> - -<!-- <reference id="bundleService" interface="org.apache.karaf.bundle.core.BundleService" odl:type="default"/> --> + <reference id="bundleService" + interface="org.apache.karaf.bundle.core.BundleService" /> <bean id="readyServlet" class="org.onap.ccsdk.features.sdnr.wt.dataprovider.http.ReadyHttpServlet"> + <property name="bundleService" ref="bundleService"/> </bean> <service interface="javax.servlet.http.HttpServlet" ref="readyServlet"> |