use of org.ops4j.pax.web.service.spi.WebEvent in project karaf by apache.
the class WebContainerServiceImpl method stop.
public void stop(List<Long> bundleIds) throws Exception {
if (bundleIds != null && !bundleIds.isEmpty()) {
for (long bundleId : bundleIds) {
if (webEventHandler.getBundleEvents().containsKey(bundleId)) {
WebEvent webEvent = webEventHandler.getBundleEvents().get(bundleId);
Bundle bundle = webEvent.getBundle();
if (bundle != null) {
// deploy
warManager.stop(bundleId);
} else {
System.out.println("Bundle ID " + bundleId + " is invalid");
LOGGER.warn("Bundle ID {} is invalid", bundleId);
}
}
}
}
}
use of org.ops4j.pax.web.service.spi.WebEvent in project karaf by apache.
the class WebContainerServiceImpl method list.
public List<WebBundle> list() throws Exception {
Bundle[] bundles = bundleContext.getBundles();
Map<Long, WebEvent> bundleEvents = webEventHandler.getBundleEvents();
List<WebBundle> webBundles = new ArrayList<>();
if (bundles != null) {
for (Bundle bundle : bundles) {
// first check if the bundle is a web bundle
String contextPath = bundle.getHeaders().get("Web-ContextPath");
if (contextPath == null) {
// this one used by pax-web but is deprecated
contextPath = bundle.getHeaders().get("Webapp-Context");
}
if (contextPath == null) {
// the bundle is not a web bundle
continue;
}
WebBundle webBundle = new WebBundle();
contextPath = contextPath.trim();
// get the bundle name
String name = bundle.getHeaders().get(Constants.BUNDLE_NAME);
// if there is no name, then default to symbolic name
name = (name == null) ? bundle.getSymbolicName() : name;
// if there is no symbolic name, resort to location
name = (name == null) ? bundle.getLocation() : name;
// get the bundle version
String version = bundle.getHeaders().get(Constants.BUNDLE_VERSION);
name = ((version != null)) ? name + " (" + version + ")" : name;
long bundleId = bundle.getBundleId();
int level = bundle.adapt(BundleStartLevel.class).getStartLevel();
if (!contextPath.startsWith("/")) {
contextPath = "/" + contextPath;
}
webBundle.setBundleId(bundleId);
webBundle.setName(name);
webBundle.setContextPath(contextPath);
webBundle.setLevel(level);
webBundle.setState(getStateString(bundle));
webBundle.setWebState(state(bundle.getBundleId()));
webBundles.add(webBundle);
}
}
return webBundles;
}
use of org.ops4j.pax.web.service.spi.WebEvent in project karaf by apache.
the class WebContainerServiceImpl method getWebContextPath.
@Override
public String getWebContextPath(Long id) {
Map<Long, WebEvent> bundleEvents = webEventHandler.getBundleEvents();
WebEvent webEvent = bundleEvents.get(id);
return webEvent.getContextPath();
}
use of org.ops4j.pax.web.service.spi.WebEvent in project karaf by apache.
the class WebContainerServiceImpl method state.
public String state(long bundleId) {
Map<Long, WebEvent> bundleEvents = webEventHandler.getBundleEvents();
String topic = "Unknown ";
if (bundleEvents.containsKey(bundleId)) {
WebEvent webEvent = bundleEvents.get(bundleId);
switch(webEvent.getType()) {
case WebEvent.DEPLOYING:
topic = "Deploying ";
break;
case WebEvent.DEPLOYED:
topic = "Deployed ";
break;
case WebEvent.UNDEPLOYING:
topic = "Undeploying";
break;
case WebEvent.UNDEPLOYED:
topic = "Undeployed ";
break;
case WebEvent.FAILED:
topic = "Failed ";
break;
case WebEvent.WAITING:
topic = "Waiting ";
break;
default:
topic = "Failed ";
}
}
while (topic.length() < 11) {
topic += " ";
}
return topic;
}
use of org.ops4j.pax.web.service.spi.WebEvent in project karaf by apache.
the class HttpPlugin method getWebDetails.
protected List<WebDetail> getWebDetails() {
Map<Long, WebEvent> bundleEvents = webEventHandler.getBundleEvents();
List<WebDetail> result = new ArrayList<>();
for (WebEvent event : bundleEvents.values()) {
WebDetail webDetail = new WebDetail();
webDetail.setBundleId(event.getBundle().getBundleId());
webDetail.setContextPath(event.getContextPath().trim().concat("/"));
int state = bundleContext.getBundle(event.getBundle().getBundleId()).getState();
String stateStr;
if (state == Bundle.ACTIVE) {
stateStr = "Active";
} else if (state == Bundle.INSTALLED) {
stateStr = "Installed";
} else if (state == Bundle.RESOLVED) {
stateStr = "Resolved";
} else if (state == Bundle.STARTING) {
stateStr = "Starting";
} else if (state == Bundle.STOPPING) {
stateStr = "Stopping";
} else {
stateStr = "Unknown";
}
webDetail.setState(stateStr);
webDetail.setWebState(getStateString(event.getType()));
result.add(webDetail);
}
return result;
}
Aggregations