use of org.apache.catalina.DistributedManager in project tomcat by apache.
the class HostConfig method checkUndeploy.
/**
* Check for old versions of applications using parallel deployment that are
* now unused (have no active sessions) and undeploy any that are found.
*/
public synchronized void checkUndeploy() {
// Need ordered set of names
SortedSet<String> sortedAppNames = new TreeSet<>();
sortedAppNames.addAll(deployed.keySet());
if (sortedAppNames.size() < 2) {
return;
}
Iterator<String> iter = sortedAppNames.iterator();
ContextName previous = new ContextName(iter.next(), false);
do {
ContextName current = new ContextName(iter.next(), false);
if (current.getPath().equals(previous.getPath())) {
// Current and previous are same path - current will always
// be a later version
Context previousContext = (Context) host.findChild(previous.getName());
Context currentContext = (Context) host.findChild(current.getName());
if (previousContext != null && currentContext != null && currentContext.getState().isAvailable() && !isServiced(previous.getName())) {
Manager manager = previousContext.getManager();
if (manager != null) {
int sessionCount;
if (manager instanceof DistributedManager) {
sessionCount = ((DistributedManager) manager).getActiveSessionsFull();
} else {
sessionCount = manager.getActiveSessions();
}
if (sessionCount == 0) {
if (log.isInfoEnabled()) {
log.info(sm.getString("hostConfig.undeployVersion", previous.getName()));
}
DeployedApplication app = deployed.get(previous.getName());
String[] resources = app.redeployResources.keySet().toArray(new String[0]);
// Version is unused - undeploy it completely
// The -1 is a 'trick' to ensure all redeploy
// resources are removed
undeploy(app);
deleteRedeployResources(app, resources, -1, true);
}
}
}
}
previous = current;
} while (iter.hasNext());
}
use of org.apache.catalina.DistributedManager in project tomcat by apache.
the class HTMLManagerServlet method list.
/**
* Render a HTML list of the currently active Contexts in our virtual host,
* and memory and server status information.
*
* @param request The request
* @param response The response
* @param message a message to display
* @param smClient internationalized strings
* @throws IOException an IO error occurred
*/
protected void list(HttpServletRequest request, HttpServletResponse response, String message, StringManager smClient) throws IOException {
if (debug >= 1)
log("list: Listing contexts for virtual host '" + host.getName() + "'");
PrintWriter writer = response.getWriter();
// HTML Header Section
writer.print(Constants.HTML_HEADER_SECTION);
// Body Header Section
Object[] args = new Object[2];
args[0] = request.getContextPath();
args[1] = smClient.getString("htmlManagerServlet.title");
writer.print(MessageFormat.format(Constants.BODY_HEADER_SECTION, args));
// Message Section
args = new Object[3];
args[0] = smClient.getString("htmlManagerServlet.messageLabel");
if (message == null || message.length() == 0) {
args[1] = "OK";
} else {
args[1] = RequestUtil.filter(message);
}
writer.print(MessageFormat.format(Constants.MESSAGE_SECTION, args));
// Manager Section
args = new Object[9];
args[0] = smClient.getString("htmlManagerServlet.manager");
args[1] = response.encodeURL(request.getContextPath() + "/html/list");
args[2] = smClient.getString("htmlManagerServlet.list");
args[3] = response.encodeURL(request.getContextPath() + "/" + smClient.getString("htmlManagerServlet.helpHtmlManagerFile"));
args[4] = smClient.getString("htmlManagerServlet.helpHtmlManager");
args[5] = response.encodeURL(request.getContextPath() + "/" + smClient.getString("htmlManagerServlet.helpManagerFile"));
args[6] = smClient.getString("htmlManagerServlet.helpManager");
args[7] = response.encodeURL(request.getContextPath() + "/status");
args[8] = smClient.getString("statusServlet.title");
writer.print(MessageFormat.format(Constants.MANAGER_SECTION, args));
// Apps Header Section
args = new Object[7];
args[0] = smClient.getString("htmlManagerServlet.appsTitle");
args[1] = smClient.getString("htmlManagerServlet.appsPath");
args[2] = smClient.getString("htmlManagerServlet.appsVersion");
args[3] = smClient.getString("htmlManagerServlet.appsName");
args[4] = smClient.getString("htmlManagerServlet.appsAvailable");
args[5] = smClient.getString("htmlManagerServlet.appsSessions");
args[6] = smClient.getString("htmlManagerServlet.appsTasks");
writer.print(MessageFormat.format(APPS_HEADER_SECTION, args));
// Apps Row Section
// Create sorted map of deployed applications by context name.
Container[] children = host.findChildren();
String[] contextNames = new String[children.length];
for (int i = 0; i < children.length; i++) contextNames[i] = children[i].getName();
Arrays.sort(contextNames);
String appsStart = smClient.getString("htmlManagerServlet.appsStart");
String appsStop = smClient.getString("htmlManagerServlet.appsStop");
String appsReload = smClient.getString("htmlManagerServlet.appsReload");
String appsUndeploy = smClient.getString("htmlManagerServlet.appsUndeploy");
String appsExpire = smClient.getString("htmlManagerServlet.appsExpire");
String noVersion = "<i>" + smClient.getString("htmlManagerServlet.noVersion") + "</i>";
boolean isHighlighted = true;
boolean isDeployed = true;
String highlightColor = null;
for (String contextName : contextNames) {
Context ctxt = (Context) host.findChild(contextName);
if (ctxt != null) {
// Bugzilla 34818, alternating row colors
isHighlighted = !isHighlighted;
if (isHighlighted) {
highlightColor = "#C3F3C3";
} else {
highlightColor = "#FFFFFF";
}
String contextPath = ctxt.getPath();
String displayPath = contextPath;
if (displayPath.equals("")) {
displayPath = "/";
}
StringBuilder tmp = new StringBuilder();
tmp.append("path=");
tmp.append(URL_ENCODER.encode(displayPath, "UTF-8"));
if (ctxt.getWebappVersion().length() > 0) {
tmp.append("&version=");
tmp.append(URL_ENCODER.encode(ctxt.getWebappVersion(), "UTF-8"));
}
String pathVersion = tmp.toString();
try {
isDeployed = isDeployed(contextName);
} catch (Exception e) {
// Assume false on failure for safety
isDeployed = false;
}
args = new Object[7];
args[0] = "<a href=\"" + URL_ENCODER.encode(contextPath + "/", "UTF-8") + "\">" + RequestUtil.filter(displayPath) + "</a>";
if ("".equals(ctxt.getWebappVersion())) {
args[1] = noVersion;
} else {
args[1] = RequestUtil.filter(ctxt.getWebappVersion());
}
if (ctxt.getDisplayName() == null) {
args[2] = " ";
} else {
args[2] = RequestUtil.filter(ctxt.getDisplayName());
}
args[3] = Boolean.valueOf(ctxt.getState().isAvailable());
args[4] = RequestUtil.filter(response.encodeURL(request.getContextPath() + "/html/sessions?" + pathVersion));
Manager manager = ctxt.getManager();
if (manager instanceof DistributedManager && showProxySessions) {
args[5] = Integer.valueOf(((DistributedManager) manager).getActiveSessionsFull());
} else if (manager != null) {
args[5] = Integer.valueOf(manager.getActiveSessions());
} else {
args[5] = Integer.valueOf(0);
}
args[6] = highlightColor;
writer.print(MessageFormat.format(APPS_ROW_DETAILS_SECTION, args));
args = new Object[14];
args[0] = RequestUtil.filter(response.encodeURL(request.getContextPath() + "/html/start?" + pathVersion));
args[1] = appsStart;
args[2] = RequestUtil.filter(response.encodeURL(request.getContextPath() + "/html/stop?" + pathVersion));
args[3] = appsStop;
args[4] = RequestUtil.filter(response.encodeURL(request.getContextPath() + "/html/reload?" + pathVersion));
args[5] = appsReload;
args[6] = RequestUtil.filter(response.encodeURL(request.getContextPath() + "/html/undeploy?" + pathVersion));
args[7] = appsUndeploy;
args[8] = RequestUtil.filter(response.encodeURL(request.getContextPath() + "/html/expire?" + pathVersion));
args[9] = appsExpire;
args[10] = smClient.getString("htmlManagerServlet.expire.explain");
if (manager == null) {
args[11] = smClient.getString("htmlManagerServlet.noManager");
} else {
args[11] = Integer.valueOf(ctxt.getSessionTimeout());
}
args[12] = smClient.getString("htmlManagerServlet.expire.unit");
args[13] = highlightColor;
if (ctxt.getName().equals(this.context.getName())) {
writer.print(MessageFormat.format(MANAGER_APP_ROW_BUTTON_SECTION, args));
} else if (ctxt.getState().isAvailable() && isDeployed) {
writer.print(MessageFormat.format(STARTED_DEPLOYED_APPS_ROW_BUTTON_SECTION, args));
} else if (ctxt.getState().isAvailable() && !isDeployed) {
writer.print(MessageFormat.format(STARTED_NONDEPLOYED_APPS_ROW_BUTTON_SECTION, args));
} else if (!ctxt.getState().isAvailable() && isDeployed) {
writer.print(MessageFormat.format(STOPPED_DEPLOYED_APPS_ROW_BUTTON_SECTION, args));
} else {
writer.print(MessageFormat.format(STOPPED_NONDEPLOYED_APPS_ROW_BUTTON_SECTION, args));
}
}
}
// Deploy Section
args = new Object[7];
args[0] = smClient.getString("htmlManagerServlet.deployTitle");
args[1] = smClient.getString("htmlManagerServlet.deployServer");
args[2] = response.encodeURL(request.getContextPath() + "/html/deploy");
args[3] = smClient.getString("htmlManagerServlet.deployPath");
args[4] = smClient.getString("htmlManagerServlet.deployConfig");
args[5] = smClient.getString("htmlManagerServlet.deployWar");
args[6] = smClient.getString("htmlManagerServlet.deployButton");
writer.print(MessageFormat.format(DEPLOY_SECTION, args));
args = new Object[4];
args[0] = smClient.getString("htmlManagerServlet.deployUpload");
args[1] = response.encodeURL(request.getContextPath() + "/html/upload");
args[2] = smClient.getString("htmlManagerServlet.deployUploadFile");
args[3] = smClient.getString("htmlManagerServlet.deployButton");
writer.print(MessageFormat.format(UPLOAD_SECTION, args));
// Diagnostics section
args = new Object[9];
args[0] = smClient.getString("htmlManagerServlet.diagnosticsTitle");
args[1] = smClient.getString("htmlManagerServlet.diagnosticsLeak");
args[2] = response.encodeURL(request.getContextPath() + "/html/findleaks");
args[3] = smClient.getString("htmlManagerServlet.diagnosticsLeakWarning");
args[4] = smClient.getString("htmlManagerServlet.diagnosticsLeakButton");
args[5] = smClient.getString("htmlManagerServlet.diagnosticsSsl");
args[6] = response.encodeURL(request.getContextPath() + "/html/sslConnectorCiphers");
args[7] = smClient.getString("htmlManagerServlet.diagnosticsSslConnectorCipherButton");
args[8] = smClient.getString("htmlManagerServlet.diagnosticsSslConnectorCipherText");
writer.print(MessageFormat.format(DIAGNOSTICS_SECTION, args));
// Server Header Section
args = new Object[9];
args[0] = smClient.getString("htmlManagerServlet.serverTitle");
args[1] = smClient.getString("htmlManagerServlet.serverVersion");
args[2] = smClient.getString("htmlManagerServlet.serverJVMVersion");
args[3] = smClient.getString("htmlManagerServlet.serverJVMVendor");
args[4] = smClient.getString("htmlManagerServlet.serverOSName");
args[5] = smClient.getString("htmlManagerServlet.serverOSVersion");
args[6] = smClient.getString("htmlManagerServlet.serverOSArch");
args[7] = smClient.getString("htmlManagerServlet.serverHostname");
args[8] = smClient.getString("htmlManagerServlet.serverIPAddress");
writer.print(MessageFormat.format(Constants.SERVER_HEADER_SECTION, args));
// Server Row Section
args = new Object[8];
args[0] = ServerInfo.getServerInfo();
args[1] = System.getProperty("java.runtime.version");
args[2] = System.getProperty("java.vm.vendor");
args[3] = System.getProperty("os.name");
args[4] = System.getProperty("os.version");
args[5] = System.getProperty("os.arch");
try {
InetAddress address = InetAddress.getLocalHost();
args[6] = address.getHostName();
args[7] = address.getHostAddress();
} catch (UnknownHostException e) {
args[6] = "-";
args[7] = "-";
}
writer.print(MessageFormat.format(Constants.SERVER_ROW_SECTION, args));
// HTML Tail Section
writer.print(Constants.HTML_TAIL_SECTION);
// Finish up the response
writer.flush();
writer.close();
}
use of org.apache.catalina.DistributedManager in project tomcat by apache.
the class HTMLManagerServlet method getSessionsForName.
protected List<Session> getSessionsForName(ContextName cn, StringManager smClient) {
if ((cn == null) || !(cn.getPath().startsWith("/") || cn.getPath().equals(""))) {
String path = null;
if (cn != null) {
path = cn.getPath();
}
throw new IllegalArgumentException(smClient.getString("managerServlet.invalidPath", RequestUtil.filter(path)));
}
Context ctxt = (Context) host.findChild(cn.getName());
if (null == ctxt) {
throw new IllegalArgumentException(smClient.getString("managerServlet.noContext", RequestUtil.filter(cn.getDisplayName())));
}
Manager manager = ctxt.getManager();
List<Session> sessions = new ArrayList<>();
sessions.addAll(Arrays.asList(manager.findSessions()));
if (manager instanceof DistributedManager && showProxySessions) {
// Add dummy proxy sessions
Set<String> sessionIds = ((DistributedManager) manager).getSessionIdsFull();
// Remove active (primary and backup) session IDs from full list
for (Session session : sessions) {
sessionIds.remove(session.getId());
}
// Left with just proxy sessions - add them
for (String sessionId : sessionIds) {
sessions.add(new DummyProxySession(sessionId));
}
}
return sessions;
}
Aggregations