mirror of https://github.com/apache/cloudstack.git
Add JMX support to async job management, active job details will be checked in jConsole
This commit is contained in:
parent
47882e9809
commit
33b3333d65
|
|
@ -0,0 +1,21 @@
|
|||
package com.cloud.async;
|
||||
|
||||
public interface AsyncJobMBean {
|
||||
public long getAccountId();
|
||||
public long getUserId();
|
||||
public String getCmd();
|
||||
public String getCmdInfo();
|
||||
public String getStatus();
|
||||
public int getProcessStatus();
|
||||
public int getResultCode();
|
||||
public String getResult();
|
||||
public String getInstanceType();
|
||||
public String getInstanceId();
|
||||
public String getInitMsid();
|
||||
public String getCreateTime();
|
||||
public String getLastUpdateTime();
|
||||
public String getLastPollTime();
|
||||
public String getSyncQueueId();
|
||||
public String getSyncQueueContentType();
|
||||
public String getSyncQueueContentId();
|
||||
}
|
||||
|
|
@ -0,0 +1,128 @@
|
|||
package com.cloud.async;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.TimeZone;
|
||||
|
||||
import javax.management.StandardMBean;
|
||||
|
||||
import com.cloud.utils.DateUtil;
|
||||
|
||||
public class AsyncJobMBeanImpl extends StandardMBean implements AsyncJobMBean {
|
||||
private AsyncJobVO _jobVo;
|
||||
|
||||
public AsyncJobMBeanImpl(AsyncJobVO jobVo) {
|
||||
super(AsyncJobMBean.class, false);
|
||||
|
||||
_jobVo = jobVo;
|
||||
}
|
||||
|
||||
public long getAccountId() {
|
||||
return _jobVo.getAccountId();
|
||||
}
|
||||
|
||||
public long getUserId() {
|
||||
return _jobVo.getUserId();
|
||||
}
|
||||
|
||||
public String getCmd() {
|
||||
return _jobVo.getCmd();
|
||||
}
|
||||
|
||||
public String getCmdInfo() {
|
||||
return _jobVo.getCmdInfo();
|
||||
}
|
||||
|
||||
public String getStatus() {
|
||||
int jobStatus = _jobVo.getStatus();
|
||||
switch(jobStatus) {
|
||||
case AsyncJobResult.STATUS_SUCCEEDED :
|
||||
return "Completed";
|
||||
|
||||
case AsyncJobResult.STATUS_IN_PROGRESS:
|
||||
return "In preogress";
|
||||
|
||||
case AsyncJobResult.STATUS_FAILED:
|
||||
return "failed";
|
||||
}
|
||||
|
||||
return "Unknow";
|
||||
}
|
||||
|
||||
public int getProcessStatus() {
|
||||
return _jobVo.getProcessStatus();
|
||||
}
|
||||
|
||||
public int getResultCode() {
|
||||
return _jobVo.getResultCode();
|
||||
}
|
||||
|
||||
public String getResult() {
|
||||
return _jobVo.getResult();
|
||||
}
|
||||
|
||||
public String getInstanceType() {
|
||||
if(_jobVo.getInstanceType() != null)
|
||||
return _jobVo.getInstanceType().toString();
|
||||
return "N/A";
|
||||
}
|
||||
|
||||
public String getInstanceId() {
|
||||
if(_jobVo.getInstanceId() != null)
|
||||
return String.valueOf(_jobVo.getInstanceId());
|
||||
return "N/A";
|
||||
}
|
||||
|
||||
public String getInitMsid() {
|
||||
if(_jobVo.getInitMsid() != null) {
|
||||
return String.valueOf(_jobVo.getInitMsid());
|
||||
}
|
||||
return "N/A";
|
||||
}
|
||||
|
||||
public String getCreateTime() {
|
||||
Date time = _jobVo.getCreated();
|
||||
if(time != null)
|
||||
return DateUtil.getDateDisplayString(TimeZone.getDefault(), time);
|
||||
return "N/A";
|
||||
}
|
||||
|
||||
public String getLastUpdateTime() {
|
||||
Date time = _jobVo.getLastUpdated();
|
||||
if(time != null)
|
||||
return DateUtil.getDateDisplayString(TimeZone.getDefault(), time);
|
||||
return "N/A";
|
||||
}
|
||||
|
||||
public String getLastPollTime() {
|
||||
Date time = _jobVo.getLastPolled();
|
||||
|
||||
if(time != null)
|
||||
return DateUtil.getDateDisplayString(TimeZone.getDefault(), time);
|
||||
return "N/A";
|
||||
}
|
||||
|
||||
public String getSyncQueueId() {
|
||||
SyncQueueItemVO item = _jobVo.getSyncSource();
|
||||
if(item != null && item.getQueueId() != null) {
|
||||
return String.valueOf(item.getQueueId());
|
||||
}
|
||||
return "N/A";
|
||||
}
|
||||
|
||||
public String getSyncQueueContentType() {
|
||||
SyncQueueItemVO item = _jobVo.getSyncSource();
|
||||
if(item != null) {
|
||||
return item.getContentType();
|
||||
}
|
||||
return "N/A";
|
||||
}
|
||||
|
||||
public String getSyncQueueContentId() {
|
||||
SyncQueueItemVO item = _jobVo.getSyncSource();
|
||||
if(item != null && item.getContentId() != null) {
|
||||
return String.valueOf(item.getContentId());
|
||||
}
|
||||
return "N/A";
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -62,6 +62,7 @@ import com.cloud.utils.db.DB;
|
|||
import com.cloud.utils.db.GlobalLock;
|
||||
import com.cloud.utils.db.Transaction;
|
||||
import com.cloud.utils.exception.CloudRuntimeException;
|
||||
import com.cloud.utils.mgmt.JmxUtil;
|
||||
import com.cloud.utils.net.MacAddress;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
|
|
@ -346,6 +347,12 @@ public class AsyncJobManagerImpl implements AsyncJobManager, ClusterManagerListe
|
|||
@Override
|
||||
public void run() {
|
||||
long jobId = 0;
|
||||
|
||||
try {
|
||||
JmxUtil.registerMBean("AsyncJobManager", "Active Job " + job.getId(), new AsyncJobMBeanImpl(job));
|
||||
} catch(Exception e) {
|
||||
s_logger.warn("Unable to register active job " + job.getId() + " to JMX minotoring");
|
||||
}
|
||||
|
||||
BaseAsyncCmd cmdObj = null;
|
||||
Transaction txn = Transaction.open(Transaction.CLOUD_DB);
|
||||
|
|
@ -437,6 +444,13 @@ public class AsyncJobManagerImpl implements AsyncJobManager, ClusterManagerListe
|
|||
}
|
||||
}
|
||||
} finally {
|
||||
|
||||
try {
|
||||
JmxUtil.unregisterMBean("AsyncJobManager", "Active Job " + job.getId());
|
||||
} catch(Exception e) {
|
||||
s_logger.warn("Unable to unregister active job " + job.getId() + " from JMX minotoring");
|
||||
}
|
||||
|
||||
StackMaid.current().exitCleanup();
|
||||
txn.close();
|
||||
NDC.pop();
|
||||
|
|
|
|||
|
|
@ -586,7 +586,7 @@ public class ClusterManagerImpl implements ClusterManager {
|
|||
newNodeList.add(mshost);
|
||||
|
||||
try {
|
||||
JmxUtil.registerMBean("ClusterManager", "Node " + mshost.getId(), new ClusterManagerMBeanImpl(mshost));
|
||||
JmxUtil.registerMBean("ClusterManager", "Node " + mshost.getId(), new ClusterManagerMBeanImpl(this, mshost));
|
||||
} catch(Exception e) {
|
||||
s_logger.warn("Unable to regiester cluster node into JMX monitoring due to exception " + e.toString());
|
||||
}
|
||||
|
|
@ -809,4 +809,12 @@ public class ClusterManagerImpl implements ClusterManager {
|
|||
public int getHeartbeatThreshold() {
|
||||
return this.heartbeatThreshold;
|
||||
}
|
||||
|
||||
public int getHeartbeatInterval() {
|
||||
return this.heartbeatInterval;
|
||||
}
|
||||
|
||||
public void setHeartbeatThreshold(int threshold) {
|
||||
heartbeatThreshold = threshold;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,4 +5,7 @@ public interface ClusterManagerMBean {
|
|||
public String getLastUpdateTime();
|
||||
public String getClusterNodeIP();
|
||||
public String getVersion();
|
||||
public int getHeartbeatInterval();
|
||||
public int getHeartbeatThreshold();
|
||||
public void setHeartbeatThreshold(int threshold);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,11 +8,13 @@ import javax.management.StandardMBean;
|
|||
import com.cloud.utils.DateUtil;
|
||||
|
||||
public class ClusterManagerMBeanImpl extends StandardMBean implements ClusterManagerMBean {
|
||||
private ClusterManagerImpl _clusterMgr;
|
||||
private ManagementServerHostVO _mshostVo;
|
||||
|
||||
public ClusterManagerMBeanImpl(ManagementServerHostVO mshostVo) {
|
||||
public ClusterManagerMBeanImpl(ClusterManagerImpl clusterMgr, ManagementServerHostVO mshostVo) {
|
||||
super(ClusterManagerMBean.class, false);
|
||||
|
||||
_clusterMgr = clusterMgr;
|
||||
_mshostVo = mshostVo;
|
||||
}
|
||||
|
||||
|
|
@ -32,4 +34,18 @@ public class ClusterManagerMBeanImpl extends StandardMBean implements ClusterMan
|
|||
public String getVersion() {
|
||||
return _mshostVo.getVersion();
|
||||
}
|
||||
|
||||
public int getHeartbeatInterval() {
|
||||
return _clusterMgr.getHeartbeatInterval();
|
||||
}
|
||||
|
||||
public int getHeartbeatThreshold() {
|
||||
return _clusterMgr.getHeartbeatThreshold();
|
||||
}
|
||||
|
||||
public void setHeartbeatThreshold(int threshold) {
|
||||
// to avoid accidentally screwing up cluster manager, we put some guarding logic here
|
||||
if(threshold >= ClusterManager.DEFAULT_HEARTBEAT_THRESHOLD)
|
||||
_clusterMgr.setHeartbeatThreshold(threshold);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue