refa
This commit is contained in:
parent
90940286d4
commit
bc7e701ada
|
@ -7,7 +7,20 @@ import java.util.UUID;
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
import org.bench4q.master.entity.MonitorResult;
|
import org.bench4q.master.entity.MonitorResult;
|
||||||
import org.bench4q.master.entity.TestPlanDB;
|
import org.bench4q.master.entity.TestPlanDB;
|
||||||
|
import org.bench4q.master.exception.ExceptionLog;
|
||||||
import org.bench4q.master.helper.SessionHelper;
|
import org.bench4q.master.helper.SessionHelper;
|
||||||
|
import org.bench4q.master.service.communication.MonitorService;
|
||||||
|
import org.bench4q.share.helper.MarshalHelper;
|
||||||
|
import org.bench4q.share.models.master.MonitorLogicalDiskResponseModel;
|
||||||
|
import org.bench4q.share.models.master.MonitorMemoryResponseModel;
|
||||||
|
import org.bench4q.share.models.master.MonitorNetworkReponseModel;
|
||||||
|
import org.bench4q.share.models.master.MonitorProcessorResponseModel;
|
||||||
|
import org.bench4q.share.models.master.MonitorResultBase;
|
||||||
|
import org.bench4q.share.models.master.statistics.SampleModel;
|
||||||
|
import org.bench4q.share.models.monitor.LogicalDiskModel;
|
||||||
|
import org.bench4q.share.models.monitor.MemoryModel;
|
||||||
|
import org.bench4q.share.models.monitor.NetworkInterfaceModel;
|
||||||
|
import org.bench4q.share.models.monitor.ProcessorModel;
|
||||||
import org.hibernate.Session;
|
import org.hibernate.Session;
|
||||||
import org.hibernate.Transaction;
|
import org.hibernate.Transaction;
|
||||||
import org.hibernate.criterion.Order;
|
import org.hibernate.criterion.Order;
|
||||||
|
@ -18,6 +31,7 @@ import org.springframework.stereotype.Component;
|
||||||
@Component
|
@Component
|
||||||
public class MonitorResultService {
|
public class MonitorResultService {
|
||||||
private TestPlanService testPlanService;
|
private TestPlanService testPlanService;
|
||||||
|
private MonitorService monitorService;
|
||||||
private SessionHelper sessionHelper;
|
private SessionHelper sessionHelper;
|
||||||
private static Logger logger = Logger.getLogger(MonitorResult.class);
|
private static Logger logger = Logger.getLogger(MonitorResult.class);
|
||||||
|
|
||||||
|
@ -39,6 +53,15 @@ public class MonitorResultService {
|
||||||
this.sessionHelper = sessionHelper;
|
this.sessionHelper = sessionHelper;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private MonitorService getMonitorService() {
|
||||||
|
return monitorService;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private void setMonitorService(MonitorService monitorService) {
|
||||||
|
this.monitorService = monitorService;
|
||||||
|
}
|
||||||
|
|
||||||
public boolean saveMonitorResult(UUID testPlanRunId, String type,
|
public boolean saveMonitorResult(UUID testPlanRunId, String type,
|
||||||
String content, Date createDatetime, String hostNameUnderMonitor) {
|
String content, Date createDatetime, String hostNameUnderMonitor) {
|
||||||
Session session = this.getSessionHelper().openSession();
|
Session session = this.getSessionHelper().openSession();
|
||||||
|
@ -91,4 +114,72 @@ public class MonitorResultService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public MonitorLogicalDiskResponseModel loadLogicalDiskResults(
|
||||||
|
UUID testPlanRunId, String hostName, int port, long beginTime) {
|
||||||
|
this.getMonitorService().logicDisk(testPlanRunId, hostName, port);
|
||||||
|
return loadMonitorResultModel(testPlanRunId, hostName, beginTime,
|
||||||
|
LogicalDiskModel.class, MonitorLogicalDiskResponseModel.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
private List<MonitorResult> doGetMonitorResultsByeTypeAndBeginDate(
|
||||||
|
UUID testPlanRunId, String hostName, long beginTime,
|
||||||
|
Session session, Class<?> resultClass) {
|
||||||
|
return session
|
||||||
|
.createCriteria(MonitorResult.class)
|
||||||
|
.add(Restrictions.eq("testPlanDB", this.getTestPlanService()
|
||||||
|
.getTestPlan(testPlanRunId)))
|
||||||
|
.add(Restrictions.eq("hostNameUnderMonitor", hostName))
|
||||||
|
.add(Restrictions.eq("type", resultClass.getName()))
|
||||||
|
.add(Restrictions.ge("createDatetime", new Date(beginTime)))
|
||||||
|
.addOrder(Order.asc("createDatetime")).list();
|
||||||
|
}
|
||||||
|
|
||||||
|
public MonitorMemoryResponseModel loadMemoryModels(UUID testPlanRunId,
|
||||||
|
String hostName, int port, long beginTime) {
|
||||||
|
this.getMonitorService().memory(testPlanRunId, hostName, port);
|
||||||
|
return loadMonitorResultModel(testPlanRunId, hostName, beginTime,
|
||||||
|
MemoryModel.class, MonitorMemoryResponseModel.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public MonitorProcessorResponseModel loadProcessorModels(
|
||||||
|
UUID testPlanRunId, String hostName, int port, long beginTime) {
|
||||||
|
this.getMonitorService().processor(testPlanRunId, hostName, port);
|
||||||
|
return loadMonitorResultModel(testPlanRunId, hostName, beginTime,
|
||||||
|
ProcessorModel.class, MonitorProcessorResponseModel.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
private <T1 extends SampleModel, T2 extends MonitorResultBase> T2 loadMonitorResultModel(
|
||||||
|
UUID testPlanRunId, String hostName, long beginTime,
|
||||||
|
Class<T1> fromMonitorClass, Class<T2> resultClass) {
|
||||||
|
Session session = this.getSessionHelper().openSession();
|
||||||
|
try {
|
||||||
|
T2 ret = resultClass.newInstance();
|
||||||
|
List<MonitorResult> monitorResults = doGetMonitorResultsByeTypeAndBeginDate(
|
||||||
|
testPlanRunId, hostName, beginTime, session,
|
||||||
|
fromMonitorClass);
|
||||||
|
for (MonitorResult monitorResult : monitorResults) {
|
||||||
|
assert (fromMonitorClass.getName().equals(monitorResult
|
||||||
|
.getType()));
|
||||||
|
T1 result = (T1) MarshalHelper.unmarshal(fromMonitorClass,
|
||||||
|
monitorResult.getContent());
|
||||||
|
result.setSamplingTime(monitorResult.getCreateDatetime());
|
||||||
|
ret.add(result);
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.error(ExceptionLog.getStackTrace(e));
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public MonitorNetworkReponseModel loadNetworkInterfaceModels(
|
||||||
|
UUID testPlanRunId, String hostName, int port, long beginTime) {
|
||||||
|
this.getMonitorService()
|
||||||
|
.networkInterface(testPlanRunId, hostName, port);
|
||||||
|
return loadMonitorResultModel(testPlanRunId, hostName, beginTime,
|
||||||
|
NetworkInterfaceModel.class, MonitorNetworkReponseModel.class);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue