From 8e4396ed1c759633740d755f6cbc3da228529a0a Mon Sep 17 00:00:00 2001 From: Michael Dürre Date: Mon, 31 Aug 2020 10:44:26 +0200 Subject: add devmgr infos in about MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit extend about infos to devmgr bundle states Issue-ID: SDNC-1114 Signed-off-by: Michael Dürre Change-Id: I804332282543ad3b10020031b2efd3c5aa8d65ec --- .../wt/dataprovider/http/ReadyHttpServlet.java | 37 ++++++++++-- .../dataprovider/http/about/AboutHttpServlet.java | 68 ++++++++++++++-------- .../wt/dataprovider/http/about/ODLVersionLUT.java | 39 +++++++------ .../wt/dataprovider/http/about/SystemInfo.java | 9 ++- 4 files changed, 107 insertions(+), 46 deletions(-) (limited to 'sdnr') 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 e20f453a1..cb74911ff 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 @@ -22,19 +22,21 @@ package org.onap.ccsdk.features.sdnr.wt.dataprovider.http; import java.io.IOException; - import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; - +import org.onap.ccsdk.features.sdnr.wt.dataprovider.http.about.MarkdownTable; +import org.osgi.framework.Bundle; +import org.osgi.framework.BundleContext; +import org.osgi.framework.FrameworkUtil; import org.slf4j.Logger; import org.slf4j.LoggerFactory; public class ReadyHttpServlet extends HttpServlet { /** - * + * */ private static final long serialVersionUID = 1L; private static final Logger LOG = LoggerFactory.getLogger(ReadyHttpServlet.class); @@ -43,7 +45,7 @@ public class ReadyHttpServlet extends HttpServlet { @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { - if (isReady()) { + if (isReady() && this.getBundleStatesNotActiveCount()==0) { resp.setStatus(HttpServletResponse.SC_OK); } else { @@ -63,4 +65,31 @@ public class ReadyHttpServlet extends HttpServlet { status = s; LOG.info("status is set to ready: {}", status); } + + private int getBundleStatesNotActiveCount() { + Bundle thisbundle = FrameworkUtil.getBundle(this.getClass()); + BundleContext context = thisbundle ==null?null:thisbundle.getBundleContext(); + if (context == null) { + LOG.debug("no bundle context available"); + return 0; + } + Bundle[] bundles = context.getBundles(); + if (bundles == null || bundles.length <= 0) { + LOG.debug("no bundles found"); + return 0; + } + 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(bundle.getState()!=Bundle.ACTIVE) { + cntNotActive++; + } + + } + return cntNotActive; + } + } diff --git a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/http/about/AboutHttpServlet.java b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/http/about/AboutHttpServlet.java index 9ac0cc0c3..81b9645fe 100644 --- a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/http/about/AboutHttpServlet.java +++ b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/http/about/AboutHttpServlet.java @@ -38,6 +38,9 @@ import javax.servlet.http.HttpServletResponse; import org.onap.ccsdk.features.sdnr.wt.common.Resources; import org.onap.ccsdk.features.sdnr.wt.common.file.PomFile; import org.onap.ccsdk.features.sdnr.wt.common.file.PomPropertiesFile; +import org.osgi.framework.Bundle; +import org.osgi.framework.BundleContext; +import org.osgi.framework.FrameworkUtil; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -59,7 +62,6 @@ public class AboutHttpServlet extends HttpServlet { private static final String PLACEHOLDER_ONAP_RELEASEVERSION = "{release-version}"; private static final String PLACEHOLDER_ODL_RELEASENAME = "{odl-version}"; private static final String PLACEHOLDER_BUILD_TIMESTAMP = "{build-time}"; - private static final String PLACEHOLDER_ODLUX_REVISION = "{odlux-revision}"; private static final String PLACEHOLDER_PACKAGE_GITHASH = "{package-githash}"; private static final String PLACEHOLDER_PACAKGE_VERSION = "{package-version}"; private static final String PLACEHOLDER_CCSDK_VERSION = "{ccsdk-version}"; @@ -69,10 +71,12 @@ public class AboutHttpServlet extends HttpServlet { private static final String PLACEHOLDER_KARAF_INFO = "{karaf-info}"; private static final String PLACEHOLDER_DEVICEMANAGER_TABLE = "{devicemanagers}"; private static final String README_FILE = "README.md"; + private static final String NO_DEVICEMANAGERS_RUNNING_MESSAGE = null; private final String groupId = "org.onap.ccsdk.features.sdnr.wt"; private final String artifactId = "sdnr-wt-data-provider-provider"; + private final Map BUNDLESTATE_LUT; private final Map data; private final String readmeContent; // private BundleService bundleService; @@ -83,7 +87,13 @@ public class AboutHttpServlet extends HttpServlet { this.data = new HashMap<>(); this.collectStaticData(); this.readmeContent = this.render(this.getResourceFileContent(README_FILE)); - //BundleContext context = FrameworkUtil.getBundle(this.getClass()).getBundleContext(); + this.BUNDLESTATE_LUT = new HashMap<>(); + this.BUNDLESTATE_LUT.put(Bundle.UNINSTALLED, "uninstalled"); + this.BUNDLESTATE_LUT.put(Bundle.INSTALLED, "installed"); + this.BUNDLESTATE_LUT.put(Bundle.RESOLVED, "resolved"); + this.BUNDLESTATE_LUT.put(Bundle.STARTING, "starting"); + this.BUNDLESTATE_LUT.put(Bundle.STOPPING, "stopping"); + this.BUNDLESTATE_LUT.put(Bundle.ACTIVE, "active"); } @@ -97,13 +107,14 @@ public class AboutHttpServlet extends HttpServlet { private void collectStaticData() { PomPropertiesFile props = this.getPomProperties(); final String ccsdkVersion = this.getPomParentVersion(); + final String mdsalVersion = SystemInfo.getMdSalVersion(UNKNOWN); this.data.put(PLACEHOLDER_ONAP_RELEASENAME, ODLVersionLUT.getONAPReleaseName(ccsdkVersion, UNKNOWN)); - this.data.put(PLACEHOLDER_ODL_RELEASENAME, ODLVersionLUT.getOdlVersion(ccsdkVersion, UNKNOWN)); + this.data.put(PLACEHOLDER_ODL_RELEASENAME, ODLVersionLUT.getOdlVersion(mdsalVersion, UNKNOWN)); this.data.put(PLACEHOLDER_BUILD_TIMESTAMP, props != null ? props.getBuildDate().toString() : ""); this.data.put(PLACEHOLDER_PACAKGE_VERSION, this.getManifestValue("Bundle-Version")); this.data.put(PLACEHOLDER_CCSDK_VERSION, ccsdkVersion); - this.data.put(PLACEHOLDER_ONAP_RELEASEVERSION, "2.0.0-SNAPSHOT"); - this.data.put(PLACEHOLDER_MDSAL_VERSION, SystemInfo.getMdSalVersion(UNKNOWN)); + this.data.put(PLACEHOLDER_ONAP_RELEASEVERSION, SystemInfo.getOnapVersion(UNKNOWN)); + this.data.put(PLACEHOLDER_MDSAL_VERSION, mdsalVersion); this.data.put(PLACEHOLDER_YANGTOOLS_VERSION, SystemInfo.getYangToolsVersion(UNKNOWN)); this.data.put(PLACEHOLDER_PACKAGE_GITHASH, this.getGitHash(UNKNOWN)); } @@ -272,25 +283,34 @@ public class AboutHttpServlet extends HttpServlet { } private String getDevicemanagerBundles() { - // if(this.bundleService==null) { - // LOG.debug("no bundle service available"); - // return ""; - // } - // - // List ids = new ArrayList(); - // List bundles = bundleService.selectBundles("0", ids , true); - // if(bundles==null || bundles.size()<=0) { - // LOG.debug("no bundles found"); - // return ""; - // } - // LOG.debug("found {} bundles",bundles.size()); - // MarkdownTable table = new MarkdownTable(); - // for(Bundle bundle:bundles) { - // BundleInfo info = this.bundleService.getInfo(bundle); - // table.addRow(new String[] {String.valueOf(info.getBundleId()),info.getVersion(),info.getName(),info.getState().toString()}); - // } - // return table.toMarkDown(); - return ""; + Bundle thisbundle = FrameworkUtil.getBundle(this.getClass()); + BundleContext context = thisbundle ==null?null:thisbundle.getBundleContext(); + if (context == null) { + LOG.debug("no bundle context available"); + return ""; + } + Bundle[] bundles = context.getBundles(); + if (bundles == null || bundles.length <= 0) { + LOG.debug("no bundles found"); + return NO_DEVICEMANAGERS_RUNNING_MESSAGE; + } + LOG.debug("found {} bundles", bundles.length); + MarkdownTable table = new MarkdownTable(); + table.setHeader(new String[] {"Bundle-Id","Version","Symbolic-Name","Status"}); + String name; + for (Bundle bundle : bundles) { + name = bundle.getSymbolicName(); + if(!(name.contains("devicemanager") && name.contains("provider"))) { + continue; + } + if(name.equals("org.onap.ccsdk.features.sdnr.wt.sdnr-wt-devicemanager-provider")) { + continue; + } + table.addRow(new String[] {String.valueOf(bundle.getBundleId()), bundle.getVersion().toString(), name, + BUNDLESTATE_LUT.getOrDefault(bundle.getState(),"unknown")}); + + } + return table.toMarkDown(); } /** diff --git a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/http/about/ODLVersionLUT.java b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/http/about/ODLVersionLUT.java index bd8fae6a0..991231f87 100644 --- a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/http/about/ODLVersionLUT.java +++ b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/http/about/ODLVersionLUT.java @@ -21,8 +21,13 @@ */ package org.onap.ccsdk.features.sdnr.wt.dataprovider.http.about; +import java.util.HashMap; +import java.util.Map; + public class ODLVersionLUT { + private static Map odlMdsalVersionLUT=null; + public static String getONAPReleaseName(String onapCCSDKVersion, String def) { if (onapCCSDKVersion == null) { return def; @@ -45,26 +50,26 @@ public class ODLVersionLUT { return def; } - public static String getOdlVersion(String onapCCSDKVersion, String def) { + public static String getOdlVersion(String mdsalVersion, String def) { - if (onapCCSDKVersion == null) { + if (mdsalVersion == null) { return def; } - if (onapCCSDKVersion.startsWith("2.")) { - return "sodium-SR3 (0.11.3)"; - } - if (onapCCSDKVersion.startsWith("1.5.")) { - return "neon-SR1 (0.10.1)"; - } - if (onapCCSDKVersion.startsWith("1.4.")) { - return "neon-SR1 (0.10.1)"; + if(odlMdsalVersionLUT==null) { + odlMdsalVersionLUT = new HashMap<>(); + odlMdsalVersionLUT.put("5.0.14","magnesium-SR2 (0.12.2)"); + odlMdsalVersionLUT.put("5.0.10","magnesium-SR1 (0.12.1)"); + odlMdsalVersionLUT.put("5.0.9","magnesium-SR0 (0.12.0)"); + odlMdsalVersionLUT.put("4.0.14","sodium-SR3 (0.11.3)"); + odlMdsalVersionLUT.put("4.0.11","sodium-SR2 (0.11.2)"); + odlMdsalVersionLUT.put("4.0.6","sodium-SR1 (0.11.1)"); + odlMdsalVersionLUT.put("4.0.4","sodium-SR0 (0.11.0)"); + odlMdsalVersionLUT.put("3.0.13","neon-SR3 (0.10.3)"); + odlMdsalVersionLUT.put("3.0.10","neon-SR2 (0.10.2)"); + odlMdsalVersionLUT.put("3.0.8","neon-SR1 (0.10.1)"); + odlMdsalVersionLUT.put("3.0.6","neon-SR0 (0.10.0)"); } - if (onapCCSDKVersion.startsWith("1.3.")) { - return "fluorine-SR2 (0.9.2)"; - } - if (onapCCSDKVersion.startsWith("1.2.")) { - return "sodium-SR3 (0.11.3)"; - } - return def; + + return odlMdsalVersionLUT.getOrDefault(mdsalVersion, def); } } diff --git a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/http/about/SystemInfo.java b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/http/about/SystemInfo.java index 1497362a6..134e3d37b 100644 --- a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/http/about/SystemInfo.java +++ b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/http/about/SystemInfo.java @@ -42,7 +42,6 @@ import java.util.concurrent.Callable; import java.util.regex.Matcher; import java.util.regex.Pattern; import java.util.stream.Stream; - import org.osgi.framework.Bundle; import org.osgi.framework.BundleContext; import org.osgi.framework.FrameworkUtil; @@ -54,6 +53,10 @@ public class SystemInfo { private static OperatingSystemMXBean os = ManagementFactory.getOperatingSystemMXBean(); protected static boolean showMemoryPools = false; + public static String getOnapVersion(String def) { + return getOnapVersion("", def); + } + public static String getMdSalVersion(String def) { return getMdSalVersion("", def); } @@ -62,6 +65,10 @@ public class SystemInfo { return getYangToolsVersion("", def); } + public static String getOnapVersion(String baseOdlDirectory, String def) { + return getFeatureVersionByFolder(baseOdlDirectory, "system/org/onap/sdnc/northbound/sdnc-northbound-all/", def); + } + public static String getMdSalVersion(String baseOdlDirectory, String def) { return getFeatureVersionByFolder(baseOdlDirectory, "system/org/opendaylight/mdsal/mdsal-binding-api/", def); } -- cgit 1.2.3-korg