2 * ============LICENSE_START=======================================================
3 * ONAP : ccsdk features
4 * ================================================================================
5 * Copyright (C) 2019 highstreet technologies GmbH Intellectual Property.
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
22 package org.onap.ccsdk.features.sdnr.wt.dataprovider.http;
24 import java.io.IOException;
25 import javax.servlet.ServletException;
26 import javax.servlet.http.HttpServlet;
27 import javax.servlet.http.HttpServletRequest;
28 import javax.servlet.http.HttpServletResponse;
29 import org.onap.ccsdk.features.sdnr.wt.dataprovider.http.about.MarkdownTable;
30 import org.osgi.framework.Bundle;
31 import org.osgi.framework.BundleContext;
32 import org.osgi.framework.FrameworkUtil;
33 import org.slf4j.Logger;
34 import org.slf4j.LoggerFactory;
36 public class ReadyHttpServlet extends HttpServlet {
41 private static final long serialVersionUID = 1L;
42 private static final Logger LOG = LoggerFactory.getLogger(ReadyHttpServlet.class);
43 private static boolean status;
46 protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
48 if (isReady() && this.getBundleStatesNotActiveCount()==0) {
49 resp.setStatus(HttpServletResponse.SC_OK);
53 resp.sendError(HttpServletResponse.SC_NOT_FOUND);
54 } catch (IOException | IllegalStateException e) {
55 LOG.warn("unable to write out 404 res not found: {}", e);
60 private static boolean isReady() {
64 public static void setStatus(boolean s) {
66 LOG.info("status is set to ready: {}", status);
69 private int getBundleStatesNotActiveCount() {
70 Bundle thisbundle = FrameworkUtil.getBundle(this.getClass());
71 BundleContext context = thisbundle ==null?null:thisbundle.getBundleContext();
72 if (context == null) {
73 LOG.debug("no bundle context available");
76 Bundle[] bundles = context.getBundles();
77 if (bundles == null || bundles.length <= 0) {
78 LOG.debug("no bundles found");
81 LOG.debug("found {} bundles", bundles.length);
82 MarkdownTable table = new MarkdownTable();
83 table.setHeader(new String[] {"Bundle-Id","Version","Symbolic-Name","Status"});
85 for (Bundle bundle : bundles) {
87 if(bundle.getState()!=Bundle.ACTIVE) {