fixed ready state 89/112089/1
authorMichael Dürre <michael.duerre@highstreet-technologies.com>
Thu, 3 Sep 2020 09:05:35 +0000 (11:05 +0200)
committerMichael Dürre <michael.duerre@highstreet-technologies.com>
Thu, 3 Sep 2020 09:05:48 +0000 (11:05 +0200)
changed bundle state detect to bundleservice

Issue-ID: CCSDK-2726
Signed-off-by: Michael Dürre <michael.duerre@highstreet-technologies.com>
Change-Id: I74b2e7d91a2be1a6d25b74ae8ecb8a4c9d76865b

sdnr/wt/data-provider/provider/pom.xml
sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/http/ReadyHttpServlet.java
sdnr/wt/data-provider/provider/src/main/resources/org/opendaylight/blueprint/impl-blueprint.xml

index 2a7b686..85b8f30 100644 (file)
             <artifactId>mockito-core</artifactId>
             <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>
@@ -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>
index cb74911..2843650 100644 (file)
@@ -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;
     }
 
 }
index ad9661f..1be1146 100644 (file)
     <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">