From eab8409c6094d6fd842bb15c803883f9064036e4 Mon Sep 17 00:00:00 2001 From: Michael Dürre Date: Thu, 3 Sep 2020 11:05:35 +0200 Subject: fixed ready state MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit changed bundle state detect to bundleservice Issue-ID: CCSDK-2726 Signed-off-by: Michael Dürre Change-Id: I74b2e7d91a2be1a6d25b74ae8ecb8a4c9d76865b --- sdnr/wt/data-provider/provider/pom.xml | 5 ++ .../wt/dataprovider/http/ReadyHttpServlet.java | 59 +++++++++++++++++++--- .../org/opendaylight/blueprint/impl-blueprint.xml | 5 +- 3 files changed, 60 insertions(+), 9 deletions(-) (limited to 'sdnr/wt/data-provider/provider') 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 @@ -57,6 +57,10 @@ mockito-core test + + org.apache.karaf.bundle + org.apache.karaf.bundle.core + ${project.groupId} sdnr-wt-data-provider-setup @@ -82,6 +86,7 @@ org.osgi.core provided + org.apache.karaf.shell org.apache.karaf.shell.core 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 @@ - - + + -- cgit 1.2.3-korg