📄 jkstatustask.java
字号:
/*
* Copyright 2002,2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.jk.status;
import java.util.Iterator;
import java.util.List;
import org.apache.catalina.ant.BaseRedirectorHelperTask;
import org.apache.tomcat.util.IntrospectionUtils;
import org.apache.tools.ant.BuildException;
/**
* Ant task that implements the show <code>/jkstatus</code> command, supported
* by the mod_jk status (1.2.13) application.
*
* @author Peter Rossbach
* @version $Revision:$
* @since 5.5.10
*/
public class JkStatusTask extends BaseRedirectorHelperTask {
/**
* Store status as <code>resultProperty</code> prefix.
*/
protected String resultproperty;
/**
* Echo status at ant console
*/
protected boolean echo = false;
/**
* The login password for the <code>mod_jk status</code> page.
*/
protected String password = null;
/**
* The URL of the <code>mod_jk status</code> page to be used.
*/
protected String url = "http://localhost:80/jkstatus";
/**
* The login username for the <code>mod_jk status</code> page.
*/
protected String username = null;
private String errorProperty;
private String worker;
private String loadbalancer;
public String getPassword() {
return (this.password);
}
public void setPassword(String password) {
this.password = password;
}
public String getUrl() {
return (this.url);
}
public void setUrl(String url) {
this.url = url;
}
public String getUsername() {
return (this.username);
}
public void setUsername(String username) {
this.username = username;
}
/**
* @return Returns the echo.
*/
public boolean isEcho() {
return echo;
}
/**
* @param echo
* The echo to set.
*/
public void setEcho(boolean echo) {
this.echo = echo;
}
/**
* @return Returns the resultproperty.
*/
public String getResultproperty() {
return resultproperty;
}
/**
* @param resultproperty
* The resultproperty to set.
*/
public void setResultproperty(String resultproperty) {
this.resultproperty = resultproperty;
}
/**
* @return Returns the loadbalancer.
*/
public String getLoadbalancer() {
return loadbalancer;
}
/**
* @param loadbalancer The loadbalancer to set.
*/
public void setLoadbalancer(String loadbalancer) {
this.loadbalancer = loadbalancer;
}
/**
* @return Returns the worker.
*/
public String getWorker() {
return worker;
}
/**
* @param worker The worker to set.
*/
public void setWorker(String worker) {
this.worker = worker;
}
// --------------------------------------------------------- Public Methods
/**
* Get jkstatus from server.
*
* @exception BuildException
* if a validation error occurs
*/
public void execute() throws BuildException {
if (url == null) {
throw new BuildException("Must specify an 'url'");
}
boolean isWorkerOnly = worker != null && !"".equals(worker);
boolean isLoadbalancerOnly = loadbalancer != null
&& !"".equals(loadbalancer);
StringBuffer error = new StringBuffer();
try {
JkStatusAccessor accessor = new JkStatusAccessor();
JkStatus status = accessor.status(url, username, password);
if (!isWorkerOnly && !isLoadbalancerOnly) {
JkServer server = status.getServer();
if (resultproperty != null) {
createProperty(server, "name");
createProperty(server, "port");
createProperty(server, "version");
createProperty(server, "software");
}
if (isEcho()) {
handleOutput("server name=" + server.getName() + "."
+ server.getPort() + " - " + server.getSoftware());
}
}
List balancers = status.getBalancers();
for (Iterator iter = balancers.iterator(); iter.hasNext();) {
JkBalancer balancer = (JkBalancer) iter.next();
String balancerIndex = null;
if (isLoadbalancerOnly) {
if (loadbalancer.equals(balancer.getName())) {
if (resultproperty != null) {
setPropertyBalancerOnly(balancer);
}
echoBalancer(balancer);
return;
}
} else {
if (!isWorkerOnly) {
if (resultproperty != null) {
balancerIndex = Integer.toString(balancer.getId());
setPropertyBalancer(balancer,balancerIndex);
}
echoBalancer(balancer);
}
List members = balancer.getBalancerMembers();
for (Iterator iterator = members.iterator(); iterator
.hasNext();) {
JkBalancerMember member = (JkBalancerMember) iterator
.next();
if (isWorkerOnly) {
if (worker.equals(member.getName())) {
if (resultproperty != null) {
setPropertyWorkerOnly(balancer, member);
}
echoWorker(member);
return;
}
} else {
if (resultproperty != null) {
setPropertyWorker(balancerIndex, member);
}
echoWorker(member);
if (!"OK".equals(member.getStatus())) {
error.append(" worker name=" + member.getName()
+ " status=" + member.getStatus()
+ " host=" + member.getAddress());
}
}
}
if (!isWorkerOnly) {
if (resultproperty != null && members.size() > 0) {
getProject().setNewProperty(
resultproperty + ".balancer."
+ balancerIndex + ".member.length",
Integer.toString(members.size()));
}
List mappings = balancer.getBalancerMappings();
int j = 0;
for (Iterator iterator = mappings.iterator(); iterator
.hasNext(); j++) {
JkBalancerMapping mapping = (JkBalancerMapping) iterator
.next();
if (resultproperty != null) {
String stringIndex2 = Integer.toString(j);
createProperty(mapping, balancerIndex,
stringIndex2, "type");
createProperty(mapping, balancerIndex,
stringIndex2, "uri");
createProperty(mapping, balancerIndex,
stringIndex2, "context");
}
if (isEcho()) {
handleOutput("balancer name="
+ balancer.getName() + " mappingtype="
+ mapping.getType() + " uri="
+ mapping.getUri() + " context="
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -