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 --- .../wt/dataprovider/http/ReadyHttpServlet.java | 59 +++++++++++++++++++--- 1 file changed, 52 insertions(+), 7 deletions(-) (limited to 'sdnr/wt/data-provider/provider/src/main/java/org/onap') 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; } } -- cgit 1.2.3-korg