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);
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
- if (isReady()) {
+ if (isReady() && this.getBundleStatesNotActiveCount()==0) {
resp.setStatus(HttpServletResponse.SC_OK);
} else {
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;
+ }
+
}
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;
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}";
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<Integer,String> BUNDLESTATE_LUT;
private final Map<String, String> data;
private final String readmeContent;
// private BundleService bundleService;
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");
}
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));
}
}
private String getDevicemanagerBundles() {
- // if(this.bundleService==null) {
- // LOG.debug("no bundle service available");
- // return "";
- // }
- //
- // List<String> ids = new ArrayList<String>();
- // List<Bundle> 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();
}
/**
*/
package org.onap.ccsdk.features.sdnr.wt.dataprovider.http.about;
+import java.util.HashMap;
+import java.util.Map;
+
public class ODLVersionLUT {
+ private static Map<String,String> odlMdsalVersionLUT=null;
+
public static String getONAPReleaseName(String onapCCSDKVersion, String def) {
if (onapCCSDKVersion == null) {
return def;
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);
}
}