layer refactor
This commit is contained in:
parent
4aefb273a5
commit
dc7e4462e5
|
@ -1,106 +1,106 @@
|
|||
package org.bench4q.master.api;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.bench4q.master.api.modelfactory.BusinessModelMapFactory;
|
||||
import org.bench4q.master.entity.Agent;
|
||||
import org.bench4q.master.service.infrastructure.AgentService;
|
||||
import org.bench4q.master.service.infrastructure.AgentStateService;
|
||||
import org.bench4q.master.service.infrastructure.UserService;
|
||||
import org.bench4q.share.models.master.AgentModel;
|
||||
import org.bench4q.share.models.master.AgentResponseModel;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
@Component
|
||||
@RequestMapping("/agentManage")
|
||||
public class AgentController extends BaseController {
|
||||
private AgentService agentPoolService;
|
||||
private AgentStateService agentStateService;
|
||||
|
||||
public AgentStateService getAgentStateService() {
|
||||
return agentStateService;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
public void setAgentStateService(AgentStateService agentStateService) {
|
||||
this.agentStateService = agentStateService;
|
||||
}
|
||||
|
||||
public AgentService getAgentService() {
|
||||
return agentPoolService;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
private void setAgentPoolService(AgentService agentPoolService) {
|
||||
this.agentPoolService = agentPoolService;
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/addAgentToPool", method = RequestMethod.POST)
|
||||
@ResponseBody
|
||||
public AgentResponseModel addAgentToPool(@RequestBody AgentModel agent) {
|
||||
if (!this.checkScope(UserService.SUPER_AUTHENTICATION)) {
|
||||
return setAgentResponseModel(false,
|
||||
"you don't have the power to add agent to pool!",
|
||||
new ArrayList<AgentModel>());
|
||||
}
|
||||
synchronized (this.getAgentService().getAgentLock()) {
|
||||
if (!this.getAgentService().addAgentToPool(
|
||||
BusinessModelMapFactory.toBusiness(agent))) {
|
||||
return setAgentResponseModel(false,
|
||||
"add agent to DB fails in addAgentToPool",
|
||||
new ArrayList<AgentModel>());
|
||||
}
|
||||
this.getAgentService().getAgentLock().notifyAll();
|
||||
return setAgentResponseModel(true, "", new ArrayList<AgentModel>());
|
||||
}
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/removeAgentFromPool", method = RequestMethod.GET)
|
||||
@ResponseBody
|
||||
public AgentResponseModel removeAgentFromPool(@RequestParam int agentId,
|
||||
@RequestParam String hostName) {
|
||||
|
||||
if (!this.checkScope(UserService.SUPER_AUTHENTICATION)) {
|
||||
return setAgentResponseModel(false,
|
||||
"you don't have the power to remove agent from pool!",
|
||||
new ArrayList<AgentModel>());
|
||||
}
|
||||
synchronized (this.getAgentService().getAgentLock()) {
|
||||
if (!this.getAgentService().removeAgentFromPool(agentId)) {
|
||||
return setAgentResponseModel(false,
|
||||
"remove agent from DB fails in removeAgentFromPool",
|
||||
new ArrayList<AgentModel>());
|
||||
}
|
||||
return this.setAgentResponseModel(true, "",
|
||||
new ArrayList<AgentModel>());
|
||||
}
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/queryAgentList", method = { RequestMethod.POST,
|
||||
RequestMethod.GET })
|
||||
@ResponseBody
|
||||
public AgentResponseModel queryAgentList() {
|
||||
List<Agent> list = this.getAgentService().loadAgentPoolFromDB();
|
||||
List<AgentModel> modelList = new ArrayList<AgentModel>();
|
||||
for (Agent agent : list) {
|
||||
modelList.add(BusinessModelMapFactory.toModel(agent));
|
||||
}
|
||||
return setAgentResponseModel(true, "", modelList);
|
||||
}
|
||||
|
||||
private AgentResponseModel setAgentResponseModel(boolean isSuccess,
|
||||
String failCauseString, List<AgentModel> agents) {
|
||||
AgentResponseModel agentResponseModel = new AgentResponseModel();
|
||||
agentResponseModel.setSuccess(isSuccess);
|
||||
agentResponseModel.setFailCauseString(failCauseString);
|
||||
agentResponseModel.setAgents(agents);
|
||||
return agentResponseModel;
|
||||
}
|
||||
package org.bench4q.master.api;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.bench4q.master.api.modelfactory.BusinessModelMapFactory;
|
||||
import org.bench4q.master.domain.entity.Agent;
|
||||
import org.bench4q.master.domain.service.AgentService;
|
||||
import org.bench4q.master.domain.service.UserService;
|
||||
import org.bench4q.master.infrastructure.communication.AgentStateMessenger;
|
||||
import org.bench4q.share.models.master.AgentModel;
|
||||
import org.bench4q.share.models.master.AgentResponseModel;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
@Component
|
||||
@RequestMapping("/agentManage")
|
||||
public class AgentController extends BaseController {
|
||||
private AgentService agentPoolService;
|
||||
private AgentStateMessenger agentStateService;
|
||||
|
||||
public AgentStateMessenger getAgentStateService() {
|
||||
return agentStateService;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
public void setAgentStateService(AgentStateMessenger agentStateService) {
|
||||
this.agentStateService = agentStateService;
|
||||
}
|
||||
|
||||
public AgentService getAgentService() {
|
||||
return agentPoolService;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
private void setAgentPoolService(AgentService agentPoolService) {
|
||||
this.agentPoolService = agentPoolService;
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/addAgentToPool", method = RequestMethod.POST)
|
||||
@ResponseBody
|
||||
public AgentResponseModel addAgentToPool(@RequestBody AgentModel agent) {
|
||||
if (!this.checkScope(UserService.SUPER_AUTHENTICATION)) {
|
||||
return setAgentResponseModel(false,
|
||||
"you don't have the power to add agent to pool!",
|
||||
new ArrayList<AgentModel>());
|
||||
}
|
||||
synchronized (this.getAgentService().getAgentLock()) {
|
||||
if (!this.getAgentService().addAgentToPool(
|
||||
BusinessModelMapFactory.toBusiness(agent))) {
|
||||
return setAgentResponseModel(false,
|
||||
"add agent to DB fails in addAgentToPool",
|
||||
new ArrayList<AgentModel>());
|
||||
}
|
||||
this.getAgentService().getAgentLock().notifyAll();
|
||||
return setAgentResponseModel(true, "", new ArrayList<AgentModel>());
|
||||
}
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/removeAgentFromPool", method = RequestMethod.GET)
|
||||
@ResponseBody
|
||||
public AgentResponseModel removeAgentFromPool(@RequestParam int agentId,
|
||||
@RequestParam String hostName) {
|
||||
|
||||
if (!this.checkScope(UserService.SUPER_AUTHENTICATION)) {
|
||||
return setAgentResponseModel(false,
|
||||
"you don't have the power to remove agent from pool!",
|
||||
new ArrayList<AgentModel>());
|
||||
}
|
||||
synchronized (this.getAgentService().getAgentLock()) {
|
||||
if (!this.getAgentService().removeAgentFromPool(agentId)) {
|
||||
return setAgentResponseModel(false,
|
||||
"remove agent from DB fails in removeAgentFromPool",
|
||||
new ArrayList<AgentModel>());
|
||||
}
|
||||
return this.setAgentResponseModel(true, "",
|
||||
new ArrayList<AgentModel>());
|
||||
}
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/queryAgentList", method = { RequestMethod.POST,
|
||||
RequestMethod.GET })
|
||||
@ResponseBody
|
||||
public AgentResponseModel queryAgentList() {
|
||||
List<Agent> list = this.getAgentService().loadAgentPoolFromDB();
|
||||
List<AgentModel> modelList = new ArrayList<AgentModel>();
|
||||
for (Agent agent : list) {
|
||||
modelList.add(BusinessModelMapFactory.toModel(agent));
|
||||
}
|
||||
return setAgentResponseModel(true, "", modelList);
|
||||
}
|
||||
|
||||
private AgentResponseModel setAgentResponseModel(boolean isSuccess,
|
||||
String failCauseString, List<AgentModel> agents) {
|
||||
AgentResponseModel agentResponseModel = new AgentResponseModel();
|
||||
agentResponseModel.setSuccess(isSuccess);
|
||||
agentResponseModel.setFailCauseString(failCauseString);
|
||||
agentResponseModel.setAgents(agents);
|
||||
return agentResponseModel;
|
||||
}
|
||||
}
|
|
@ -3,10 +3,10 @@ package org.bench4q.master.api;
|
|||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.bench4q.master.auth.AuthenticationManager;
|
||||
import org.bench4q.master.entity.User;
|
||||
import org.bench4q.master.domain.entity.User;
|
||||
import org.bench4q.master.exception.Bench4QException;
|
||||
import org.bench4q.master.exception.ExceptionLog;
|
||||
import org.bench4q.master.helper.auth.AuthenticationManager;
|
||||
import org.bench4q.share.models.ErrorResponseModel;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpStatus;
|
||||
|
|
|
@ -1,24 +1,24 @@
|
|||
package org.bench4q.master.api;
|
||||
|
||||
import org.bench4q.master.entity.User;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
@Controller
|
||||
@RequestMapping("/")
|
||||
public class HomeController extends BaseController {
|
||||
@RequestMapping(value = { "/" }, method = RequestMethod.GET)
|
||||
@ResponseBody
|
||||
public String index() {
|
||||
User principal = this.getPrincipal();
|
||||
String userName;
|
||||
if (principal == null) {
|
||||
userName = "Anonymous User";
|
||||
} else {
|
||||
userName = principal.getUserName();
|
||||
}
|
||||
return "Hello [" + userName + "]";
|
||||
}
|
||||
package org.bench4q.master.api;
|
||||
|
||||
import org.bench4q.master.domain.entity.User;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
@Controller
|
||||
@RequestMapping("/")
|
||||
public class HomeController extends BaseController {
|
||||
@RequestMapping(value = { "/" }, method = RequestMethod.GET)
|
||||
@ResponseBody
|
||||
public String index() {
|
||||
User principal = this.getPrincipal();
|
||||
String userName;
|
||||
if (principal == null) {
|
||||
userName = "Anonymous User";
|
||||
} else {
|
||||
userName = principal.getUserName();
|
||||
}
|
||||
return "Hello [" + userName + "]";
|
||||
}
|
||||
}
|
|
@ -1,98 +1,98 @@
|
|||
package org.bench4q.master.api;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bench4q.master.exception.Bench4QException;
|
||||
import org.bench4q.master.service.infrastructure.MonitorResultService;
|
||||
import org.bench4q.master.service.infrastructure.UserService;
|
||||
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.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
@Controller
|
||||
@RequestMapping(value = "/monitorController")
|
||||
public class MonitorController extends BaseController {
|
||||
private MonitorResultService monitorResultService;
|
||||
|
||||
private MonitorResultService getMonitorResultService() {
|
||||
return monitorResultService;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
private void setMonitorResultService(
|
||||
MonitorResultService monitorResultService) {
|
||||
this.monitorResultService = monitorResultService;
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/logicDiskMonitorSUTInfo/{testPlanRunId}/{hostName}/{port}/{duationBegin}", method = RequestMethod.GET)
|
||||
@ResponseBody
|
||||
public MonitorLogicalDiskResponseModel logicDiskMonitorSUTInfo(
|
||||
@PathVariable UUID testPlanRunId, @PathVariable String hostName,
|
||||
@PathVariable int port, @PathVariable long duationBegin)
|
||||
throws Bench4QException {
|
||||
if (!this.checkScope(UserService.NORAML_AUTHENTICATION)) {
|
||||
throw new Bench4QException(400 + "", "not permitted",
|
||||
"/{testPlanRunId}/script/{scriptId}/{fieldName}");
|
||||
}
|
||||
MonitorLogicalDiskResponseModel ret = this.getMonitorResultService()
|
||||
.loadLogicalDiskResults(testPlanRunId, hostName, port,
|
||||
duationBegin);
|
||||
return ret == null ? new MonitorLogicalDiskResponseModel() : ret;
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/memorySUTInfo", method = { RequestMethod.GET,
|
||||
RequestMethod.POST })
|
||||
@ResponseBody
|
||||
public MonitorMemoryResponseModel memorySUTInfo(
|
||||
@RequestParam UUID testPlanRunId, @RequestParam String hostName,
|
||||
@RequestParam int port, @RequestParam long duationBegin)
|
||||
throws Bench4QException {
|
||||
if (!this.checkScope(UserService.NORAML_AUTHENTICATION)) {
|
||||
throw new Bench4QException(400 + "", "not permitted",
|
||||
"/memorySUTInfo");
|
||||
}
|
||||
MonitorMemoryResponseModel ret = this.getMonitorResultService()
|
||||
.loadMemoryModels(testPlanRunId, hostName, port, duationBegin);
|
||||
return ret == null ? new MonitorMemoryResponseModel() : ret;
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/processorSUTInfo", method = { RequestMethod.GET })
|
||||
@ResponseBody
|
||||
public MonitorProcessorResponseModel processorSUTInfo(
|
||||
@RequestParam UUID testPlanRunId, @RequestParam String hostName,
|
||||
@RequestParam int port, @RequestParam long duationBegin)
|
||||
throws Bench4QException {
|
||||
if (!this.checkScope(UserService.NORAML_AUTHENTICATION)) {
|
||||
throw new Bench4QException(400 + "", "not permitted",
|
||||
"/processorSUTInfo");
|
||||
}
|
||||
MonitorProcessorResponseModel ret = this.getMonitorResultService()
|
||||
.loadProcessorModels(testPlanRunId, hostName, port,
|
||||
duationBegin);
|
||||
return ret == null ? new MonitorProcessorResponseModel() : ret;
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/networkInfo", method = { RequestMethod.GET })
|
||||
@ResponseBody
|
||||
public MonitorNetworkReponseModel networkInfo(
|
||||
@RequestParam UUID testPlanRunId, @RequestParam String hostName,
|
||||
@RequestParam int port, @RequestParam long duationBegin)
|
||||
throws Bench4QException {
|
||||
if (!this.checkScope(UserService.NORAML_AUTHENTICATION)) {
|
||||
throw new Bench4QException(400 + "", "not permitted",
|
||||
"/networkInfo");
|
||||
}
|
||||
MonitorNetworkReponseModel ret = this.getMonitorResultService()
|
||||
.loadNetworkInterfaceModels(testPlanRunId, hostName, port,
|
||||
duationBegin);
|
||||
return ret == null ? new MonitorNetworkReponseModel() : ret;
|
||||
}
|
||||
}
|
||||
package org.bench4q.master.api;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bench4q.master.domain.service.MonitorResultService;
|
||||
import org.bench4q.master.domain.service.UserService;
|
||||
import org.bench4q.master.exception.Bench4QException;
|
||||
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.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
@Controller
|
||||
@RequestMapping(value = "/monitorController")
|
||||
public class MonitorController extends BaseController {
|
||||
private MonitorResultService monitorResultService;
|
||||
|
||||
private MonitorResultService getMonitorResultService() {
|
||||
return monitorResultService;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
private void setMonitorResultService(
|
||||
MonitorResultService monitorResultService) {
|
||||
this.monitorResultService = monitorResultService;
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/logicDiskMonitorSUTInfo/{testPlanRunId}/{hostName}/{port}/{duationBegin}", method = RequestMethod.GET)
|
||||
@ResponseBody
|
||||
public MonitorLogicalDiskResponseModel logicDiskMonitorSUTInfo(
|
||||
@PathVariable UUID testPlanRunId, @PathVariable String hostName,
|
||||
@PathVariable int port, @PathVariable long duationBegin)
|
||||
throws Bench4QException {
|
||||
if (!this.checkScope(UserService.NORAML_AUTHENTICATION)) {
|
||||
throw new Bench4QException(400 + "", "not permitted",
|
||||
"/{testPlanRunId}/script/{scriptId}/{fieldName}");
|
||||
}
|
||||
MonitorLogicalDiskResponseModel ret = this.getMonitorResultService()
|
||||
.loadLogicalDiskResults(testPlanRunId, hostName, port,
|
||||
duationBegin);
|
||||
return ret == null ? new MonitorLogicalDiskResponseModel() : ret;
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/memorySUTInfo", method = { RequestMethod.GET,
|
||||
RequestMethod.POST })
|
||||
@ResponseBody
|
||||
public MonitorMemoryResponseModel memorySUTInfo(
|
||||
@RequestParam UUID testPlanRunId, @RequestParam String hostName,
|
||||
@RequestParam int port, @RequestParam long duationBegin)
|
||||
throws Bench4QException {
|
||||
if (!this.checkScope(UserService.NORAML_AUTHENTICATION)) {
|
||||
throw new Bench4QException(400 + "", "not permitted",
|
||||
"/memorySUTInfo");
|
||||
}
|
||||
MonitorMemoryResponseModel ret = this.getMonitorResultService()
|
||||
.loadMemoryModels(testPlanRunId, hostName, port, duationBegin);
|
||||
return ret == null ? new MonitorMemoryResponseModel() : ret;
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/processorSUTInfo", method = { RequestMethod.GET })
|
||||
@ResponseBody
|
||||
public MonitorProcessorResponseModel processorSUTInfo(
|
||||
@RequestParam UUID testPlanRunId, @RequestParam String hostName,
|
||||
@RequestParam int port, @RequestParam long duationBegin)
|
||||
throws Bench4QException {
|
||||
if (!this.checkScope(UserService.NORAML_AUTHENTICATION)) {
|
||||
throw new Bench4QException(400 + "", "not permitted",
|
||||
"/processorSUTInfo");
|
||||
}
|
||||
MonitorProcessorResponseModel ret = this.getMonitorResultService()
|
||||
.loadProcessorModels(testPlanRunId, hostName, port,
|
||||
duationBegin);
|
||||
return ret == null ? new MonitorProcessorResponseModel() : ret;
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/networkInfo", method = { RequestMethod.GET })
|
||||
@ResponseBody
|
||||
public MonitorNetworkReponseModel networkInfo(
|
||||
@RequestParam UUID testPlanRunId, @RequestParam String hostName,
|
||||
@RequestParam int port, @RequestParam long duationBegin)
|
||||
throws Bench4QException {
|
||||
if (!this.checkScope(UserService.NORAML_AUTHENTICATION)) {
|
||||
throw new Bench4QException(400 + "", "not permitted",
|
||||
"/networkInfo");
|
||||
}
|
||||
MonitorNetworkReponseModel ret = this.getMonitorResultService()
|
||||
.loadNetworkInterfaceModels(testPlanRunId, hostName, port,
|
||||
duationBegin);
|
||||
return ret == null ? new MonitorNetworkReponseModel() : ret;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,116 +1,116 @@
|
|||
package org.bench4q.master.api;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.bench4q.master.api.modelfactory.BusinessModelMapFactory;
|
||||
import org.bench4q.master.entity.Port;
|
||||
import org.bench4q.master.service.infrastructure.PortPoolService;
|
||||
import org.bench4q.master.service.infrastructure.UserService;
|
||||
import org.bench4q.share.models.master.OrganizeRecordPortResponseModel;
|
||||
import org.bench4q.share.models.master.PortModel;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
@Controller
|
||||
@RequestMapping("/RecordPort")
|
||||
public class RecordPortController extends BaseController {
|
||||
|
||||
private PortPoolService portPoolService = new PortPoolService();
|
||||
private static Object syncObject = new Object();
|
||||
|
||||
public PortPoolService getPortPoolService() {
|
||||
return portPoolService;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
private void setPortPoolService(PortPoolService portPoolService) {
|
||||
this.portPoolService = portPoolService;
|
||||
}
|
||||
|
||||
public static Object getSyncObject() {
|
||||
return syncObject;
|
||||
}
|
||||
|
||||
public static void setSyncObject(Object syncObject) {
|
||||
RecordPortController.syncObject = syncObject;
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/addPortToPortPool", method = {
|
||||
RequestMethod.POST, RequestMethod.GET })
|
||||
@ResponseBody
|
||||
public OrganizeRecordPortResponseModel addPortToPortPool(
|
||||
@RequestParam int port) {
|
||||
|
||||
if (!this.checkScope(UserService.SUPER_AUTHENTICATION)) {
|
||||
return _buildResponseModel(false,
|
||||
"you don't hava the power to add port to pool!",
|
||||
new ArrayList<PortModel>());
|
||||
}
|
||||
|
||||
if (!this.getPortPoolService().addPortToDBPool(port)) {
|
||||
return _buildResponseModel(false, "add to DB pool fails",
|
||||
new ArrayList<PortModel>());
|
||||
}
|
||||
return _buildResponseModel(true, "", new ArrayList<PortModel>());
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/removePortFromPool", method = RequestMethod.POST)
|
||||
@ResponseBody
|
||||
public OrganizeRecordPortResponseModel removePortFromPool(
|
||||
@RequestParam int portId) {
|
||||
if (!this.checkScope(UserService.SUPER_AUTHENTICATION)) {
|
||||
return _buildResponseModel(false,
|
||||
"you don't hava the power to remove port from pool!",
|
||||
new ArrayList<PortModel>());
|
||||
}
|
||||
if (!this.getPortPoolService().removePortFromDBPool(portId)) {
|
||||
return _buildResponseModel(false, "remove from local fails",
|
||||
new ArrayList<PortModel>());
|
||||
}
|
||||
return _buildResponseModel(true, "", new ArrayList<PortModel>());
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/loadPortList", method = RequestMethod.POST)
|
||||
@ResponseBody
|
||||
public OrganizeRecordPortResponseModel loadPortList() {
|
||||
if (!this.checkScope(UserService.SUPER_AUTHENTICATION)) {
|
||||
return _buildResponseModel(false,
|
||||
"you don't hava the power to load!",
|
||||
new ArrayList<PortModel>());
|
||||
}
|
||||
List<PortModel> portModels = new ArrayList<PortModel>();
|
||||
for (Port port : this.portPoolService.loadPortList()) {
|
||||
portModels.add(BusinessModelMapFactory.toModel(port));
|
||||
}
|
||||
return this._buildResponseModel(true, "", portModels);
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/editPort", method = { RequestMethod.GET,
|
||||
RequestMethod.POST })
|
||||
@ResponseBody
|
||||
public OrganizeRecordPortResponseModel editPort(@RequestParam PortModel port) {
|
||||
if (!this.checkScope(UserService.SUPER_AUTHENTICATION)) {
|
||||
return _buildResponseModel(false, "you don't have power to edit",
|
||||
new ArrayList<PortModel>());
|
||||
}
|
||||
|
||||
return this._buildResponseModel(
|
||||
this.getPortPoolService().editPort(
|
||||
BusinessModelMapFactory.toBusiness(port)), "",
|
||||
new ArrayList<PortModel>());
|
||||
}
|
||||
|
||||
private OrganizeRecordPortResponseModel _buildResponseModel(
|
||||
boolean success, String failString, List<PortModel> ports) {
|
||||
OrganizeRecordPortResponseModel result = new OrganizeRecordPortResponseModel();
|
||||
result.setSuccess(success);
|
||||
result.setFailCauseString(failString);
|
||||
result.setPortModels(ports);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
package org.bench4q.master.api;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.bench4q.master.api.modelfactory.BusinessModelMapFactory;
|
||||
import org.bench4q.master.domain.entity.Port;
|
||||
import org.bench4q.master.domain.service.PortPoolService;
|
||||
import org.bench4q.master.domain.service.UserService;
|
||||
import org.bench4q.share.models.master.OrganizeRecordPortResponseModel;
|
||||
import org.bench4q.share.models.master.PortModel;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
@Controller
|
||||
@RequestMapping("/RecordPort")
|
||||
public class RecordPortController extends BaseController {
|
||||
|
||||
private PortPoolService portPoolService = new PortPoolService();
|
||||
private static Object syncObject = new Object();
|
||||
|
||||
public PortPoolService getPortPoolService() {
|
||||
return portPoolService;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
private void setPortPoolService(PortPoolService portPoolService) {
|
||||
this.portPoolService = portPoolService;
|
||||
}
|
||||
|
||||
public static Object getSyncObject() {
|
||||
return syncObject;
|
||||
}
|
||||
|
||||
public static void setSyncObject(Object syncObject) {
|
||||
RecordPortController.syncObject = syncObject;
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/addPortToPortPool", method = {
|
||||
RequestMethod.POST, RequestMethod.GET })
|
||||
@ResponseBody
|
||||
public OrganizeRecordPortResponseModel addPortToPortPool(
|
||||
@RequestParam int port) {
|
||||
|
||||
if (!this.checkScope(UserService.SUPER_AUTHENTICATION)) {
|
||||
return _buildResponseModel(false,
|
||||
"you don't hava the power to add port to pool!",
|
||||
new ArrayList<PortModel>());
|
||||
}
|
||||
|
||||
if (!this.getPortPoolService().addPortToDBPool(port)) {
|
||||
return _buildResponseModel(false, "add to DB pool fails",
|
||||
new ArrayList<PortModel>());
|
||||
}
|
||||
return _buildResponseModel(true, "", new ArrayList<PortModel>());
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/removePortFromPool", method = RequestMethod.POST)
|
||||
@ResponseBody
|
||||
public OrganizeRecordPortResponseModel removePortFromPool(
|
||||
@RequestParam int portId) {
|
||||
if (!this.checkScope(UserService.SUPER_AUTHENTICATION)) {
|
||||
return _buildResponseModel(false,
|
||||
"you don't hava the power to remove port from pool!",
|
||||
new ArrayList<PortModel>());
|
||||
}
|
||||
if (!this.getPortPoolService().removePortFromDBPool(portId)) {
|
||||
return _buildResponseModel(false, "remove from local fails",
|
||||
new ArrayList<PortModel>());
|
||||
}
|
||||
return _buildResponseModel(true, "", new ArrayList<PortModel>());
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/loadPortList", method = RequestMethod.POST)
|
||||
@ResponseBody
|
||||
public OrganizeRecordPortResponseModel loadPortList() {
|
||||
if (!this.checkScope(UserService.SUPER_AUTHENTICATION)) {
|
||||
return _buildResponseModel(false,
|
||||
"you don't hava the power to load!",
|
||||
new ArrayList<PortModel>());
|
||||
}
|
||||
List<PortModel> portModels = new ArrayList<PortModel>();
|
||||
for (Port port : this.portPoolService.loadPortList()) {
|
||||
portModels.add(BusinessModelMapFactory.toModel(port));
|
||||
}
|
||||
return this._buildResponseModel(true, "", portModels);
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/editPort", method = { RequestMethod.GET,
|
||||
RequestMethod.POST })
|
||||
@ResponseBody
|
||||
public OrganizeRecordPortResponseModel editPort(@RequestParam PortModel port) {
|
||||
if (!this.checkScope(UserService.SUPER_AUTHENTICATION)) {
|
||||
return _buildResponseModel(false, "you don't have power to edit",
|
||||
new ArrayList<PortModel>());
|
||||
}
|
||||
|
||||
return this._buildResponseModel(
|
||||
this.getPortPoolService().editPort(
|
||||
BusinessModelMapFactory.toBusiness(port)), "",
|
||||
new ArrayList<PortModel>());
|
||||
}
|
||||
|
||||
private OrganizeRecordPortResponseModel _buildResponseModel(
|
||||
boolean success, String failString, List<PortModel> ports) {
|
||||
OrganizeRecordPortResponseModel result = new OrganizeRecordPortResponseModel();
|
||||
result.setSuccess(success);
|
||||
result.setFailCauseString(failString);
|
||||
result.setPortModels(ports);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,14 +13,14 @@ import javax.xml.bind.JAXBException;
|
|||
import org.apache.commons.io.FileUtils;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.bench4q.master.api.modelfactory.BusinessModelMapFactory;
|
||||
import org.bench4q.master.entity.Port;
|
||||
import org.bench4q.master.entity.Script;
|
||||
import org.bench4q.master.domain.entity.Port;
|
||||
import org.bench4q.master.domain.entity.Script;
|
||||
import org.bench4q.master.domain.service.PortPoolService;
|
||||
import org.bench4q.master.domain.service.ScriptService;
|
||||
import org.bench4q.master.domain.service.UserService;
|
||||
import org.bench4q.master.exception.Bench4QException;
|
||||
import org.bench4q.master.exception.ExceptionLog;
|
||||
import org.bench4q.master.scriptrecord.ScriptCapturer;
|
||||
import org.bench4q.master.service.infrastructure.PortPoolService;
|
||||
import org.bench4q.master.service.infrastructure.ScriptService;
|
||||
import org.bench4q.master.service.infrastructure.UserService;
|
||||
import org.bench4q.share.helper.MarshalHelper;
|
||||
import org.bench4q.share.models.agent.RunScenarioModel;
|
||||
import org.bench4q.share.models.master.OperateScriptServerResponseModel;
|
||||
|
|
|
@ -14,12 +14,12 @@ import org.bench4q.master.domain.MonitorInBusiness;
|
|||
import org.bench4q.master.domain.RunningScript;
|
||||
import org.bench4q.master.domain.TestPlanContext;
|
||||
import org.bench4q.master.domain.TestPlanInBusiness;
|
||||
import org.bench4q.master.entity.TestPlanDB;
|
||||
import org.bench4q.master.domain.entity.TestPlanDB;
|
||||
import org.bench4q.master.domain.service.TestPlanScriptResultService;
|
||||
import org.bench4q.master.domain.service.TestPlanService;
|
||||
import org.bench4q.master.domain.service.UserService;
|
||||
import org.bench4q.master.exception.Bench4QException;
|
||||
import org.bench4q.master.report.ReportService;
|
||||
import org.bench4q.master.service.infrastructure.TestPlanScriptResultService;
|
||||
import org.bench4q.master.service.infrastructure.TestPlanService;
|
||||
import org.bench4q.master.service.infrastructure.UserService;
|
||||
import org.bench4q.master.testplan.TestPlanContainer;
|
||||
import org.bench4q.master.testplan.TestPlanEngine;
|
||||
import org.bench4q.share.enums.master.TestPlanStatus;
|
||||
|
|
|
@ -1,58 +1,58 @@
|
|||
package org.bench4q.master.api;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bench4q.master.exception.Bench4QException;
|
||||
import org.bench4q.master.service.infrastructure.TestPlanScriptResultService;
|
||||
import org.bench4q.master.service.infrastructure.UserService;
|
||||
import org.bench4q.share.models.master.ResultLoadModel;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
@Controller
|
||||
@RequestMapping("/testPlanResult")
|
||||
public class TestPlanResulController extends BaseController {
|
||||
private TestPlanScriptResultService testPlanScriptResultService;
|
||||
|
||||
public TestPlanScriptResultService getTestPlanScriptResultService() {
|
||||
return testPlanScriptResultService;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
public void setTestPlanScriptResultService(
|
||||
TestPlanScriptResultService testPlanScriptResultService) {
|
||||
this.testPlanScriptResultService = testPlanScriptResultService;
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/{testPlanRunId}/loadScriptBirefResults/{scriptId}/{fieldName}", method = RequestMethod.GET)
|
||||
@ResponseBody
|
||||
public ResultLoadModel loadScriptBriefResults(
|
||||
@PathVariable UUID testPlanRunId, @PathVariable int scriptId,
|
||||
@PathVariable String fieldName) throws Bench4QException {
|
||||
if (!this.checkScope(UserService.NORAML_AUTHENTICATION)) {
|
||||
throw new Bench4QException(400 + "", "not permitted",
|
||||
"/{testPlanRunId}/script/{scriptId}/{fieldName}");
|
||||
}
|
||||
ResultLoadModel ret = new ResultLoadModel();
|
||||
ret.setValueTimeModels(this.getTestPlanScriptResultService()
|
||||
.loadScriptBriefSpecificField(testPlanRunId, scriptId,
|
||||
fieldName));
|
||||
return ret;
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/{testPlanRunId}/loadBehaviorsBriefResults/{scriptId}/{fieldName}", method = RequestMethod.GET)
|
||||
@ResponseBody
|
||||
public ResultLoadModel loadBehaviorsBriefResults(
|
||||
@PathVariable UUID testPlanRunId, @PathVariable int scriptId,
|
||||
@PathVariable String fieldName) throws Bench4QException {
|
||||
if (!this.checkScope(UserService.NORAML_AUTHENTICATION)) {
|
||||
throw new Bench4QException("400", "not permitted",
|
||||
"/{testPlanRunId}/loadBehaviorsBriefResults/{scriptId}/{fieldName}");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
package org.bench4q.master.api;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bench4q.master.domain.service.TestPlanScriptResultService;
|
||||
import org.bench4q.master.domain.service.UserService;
|
||||
import org.bench4q.master.exception.Bench4QException;
|
||||
import org.bench4q.share.models.master.ResultLoadModel;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
@Controller
|
||||
@RequestMapping("/testPlanResult")
|
||||
public class TestPlanResulController extends BaseController {
|
||||
private TestPlanScriptResultService testPlanScriptResultService;
|
||||
|
||||
public TestPlanScriptResultService getTestPlanScriptResultService() {
|
||||
return testPlanScriptResultService;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
public void setTestPlanScriptResultService(
|
||||
TestPlanScriptResultService testPlanScriptResultService) {
|
||||
this.testPlanScriptResultService = testPlanScriptResultService;
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/{testPlanRunId}/loadScriptBirefResults/{scriptId}/{fieldName}", method = RequestMethod.GET)
|
||||
@ResponseBody
|
||||
public ResultLoadModel loadScriptBriefResults(
|
||||
@PathVariable UUID testPlanRunId, @PathVariable int scriptId,
|
||||
@PathVariable String fieldName) throws Bench4QException {
|
||||
if (!this.checkScope(UserService.NORAML_AUTHENTICATION)) {
|
||||
throw new Bench4QException(400 + "", "not permitted",
|
||||
"/{testPlanRunId}/script/{scriptId}/{fieldName}");
|
||||
}
|
||||
ResultLoadModel ret = new ResultLoadModel();
|
||||
ret.setValueTimeModels(this.getTestPlanScriptResultService()
|
||||
.loadScriptBriefSpecificField(testPlanRunId, scriptId,
|
||||
fieldName));
|
||||
return ret;
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/{testPlanRunId}/loadBehaviorsBriefResults/{scriptId}/{fieldName}", method = RequestMethod.GET)
|
||||
@ResponseBody
|
||||
public ResultLoadModel loadBehaviorsBriefResults(
|
||||
@PathVariable UUID testPlanRunId, @PathVariable int scriptId,
|
||||
@PathVariable String fieldName) throws Bench4QException {
|
||||
if (!this.checkScope(UserService.NORAML_AUTHENTICATION)) {
|
||||
throw new Bench4QException("400", "not permitted",
|
||||
"/{testPlanRunId}/loadBehaviorsBriefResults/{scriptId}/{fieldName}");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,93 +1,93 @@
|
|||
package org.bench4q.master.api;
|
||||
|
||||
import org.bench4q.master.auth.AccessToken;
|
||||
import org.bench4q.master.auth.AuthenticationManager;
|
||||
import org.bench4q.master.entity.User;
|
||||
import org.bench4q.master.service.infrastructure.UserService;
|
||||
import org.bench4q.share.models.master.AuthorizeResponseModel;
|
||||
import org.bench4q.share.models.master.RegisterResponseModel;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
@Controller
|
||||
@RequestMapping("/user")
|
||||
public class UserController {
|
||||
private UserService userService;
|
||||
private AuthenticationManager authenticationManager;
|
||||
|
||||
private UserService getUserService() {
|
||||
return userService;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
private void setUserService(UserService userService) {
|
||||
this.userService = userService;
|
||||
}
|
||||
|
||||
private AuthenticationManager getAuthenticationManager() {
|
||||
return authenticationManager;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
private void setAuthenticationManager(
|
||||
AuthenticationManager authenticationManager) {
|
||||
this.authenticationManager = authenticationManager;
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/register", method = RequestMethod.GET)
|
||||
@ResponseBody
|
||||
public RegisterResponseModel register(@RequestParam String userName,
|
||||
@RequestParam String password) {
|
||||
boolean success = this.getUserService().register(userName, password);
|
||||
RegisterResponseModel registerUserResponseModel = new RegisterResponseModel();
|
||||
registerUserResponseModel.setSuccess(success);
|
||||
return registerUserResponseModel;
|
||||
}
|
||||
|
||||
private AuthorizeResponseModel authorize(String userName, String password,
|
||||
byte requiredScope) {
|
||||
boolean authorized = this.getUserService().validateUser(userName,
|
||||
password);
|
||||
if (!authorized) {
|
||||
return buildAuthorizeResponseModel(null, -1, false);
|
||||
}
|
||||
User user = this.getUserService().getUserByName(userName);
|
||||
if (!this.getAuthenticationManager().isScopeMeet(user.getScope(),
|
||||
requiredScope)) {
|
||||
return buildAuthorizeResponseModel(null, -1, false);
|
||||
}
|
||||
AccessToken accessToken = this.getAuthenticationManager()
|
||||
.generateAccessToken(user);
|
||||
String credential = this.getAuthenticationManager().generateCredential(
|
||||
user);
|
||||
return buildAuthorizeResponseModel(credential,
|
||||
accessToken.getExpiresIn(), true);
|
||||
}
|
||||
|
||||
private AuthorizeResponseModel buildAuthorizeResponseModel(
|
||||
String accessToken, int expiresIn, boolean success) {
|
||||
AuthorizeResponseModel authorizeResponseModel = new AuthorizeResponseModel();
|
||||
authorizeResponseModel.setAccessToken(accessToken);
|
||||
authorizeResponseModel.setExpiresIn(expiresIn);
|
||||
authorizeResponseModel.setSuccess(success);
|
||||
return authorizeResponseModel;
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/adminAuthorize", method = RequestMethod.GET)
|
||||
@ResponseBody
|
||||
public AuthorizeResponseModel adminAuthorize(@RequestParam String userName,
|
||||
@RequestParam String password) {
|
||||
return authorize(userName, password, UserService.SUPER_AUTHENTICATION);
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/normalAuthorize", method = RequestMethod.GET)
|
||||
@ResponseBody
|
||||
public AuthorizeResponseModel normalAuthorize(
|
||||
@RequestParam String userName, @RequestParam String password) {
|
||||
return authorize(userName, password, UserService.NORAML_AUTHENTICATION);
|
||||
}
|
||||
}
|
||||
package org.bench4q.master.api;
|
||||
|
||||
import org.bench4q.master.domain.entity.User;
|
||||
import org.bench4q.master.domain.service.UserService;
|
||||
import org.bench4q.master.helper.auth.AccessToken;
|
||||
import org.bench4q.master.helper.auth.AuthenticationManager;
|
||||
import org.bench4q.share.models.master.AuthorizeResponseModel;
|
||||
import org.bench4q.share.models.master.RegisterResponseModel;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
@Controller
|
||||
@RequestMapping("/user")
|
||||
public class UserController {
|
||||
private UserService userService;
|
||||
private AuthenticationManager authenticationManager;
|
||||
|
||||
private UserService getUserService() {
|
||||
return userService;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
private void setUserService(UserService userService) {
|
||||
this.userService = userService;
|
||||
}
|
||||
|
||||
private AuthenticationManager getAuthenticationManager() {
|
||||
return authenticationManager;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
private void setAuthenticationManager(
|
||||
AuthenticationManager authenticationManager) {
|
||||
this.authenticationManager = authenticationManager;
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/register", method = RequestMethod.GET)
|
||||
@ResponseBody
|
||||
public RegisterResponseModel register(@RequestParam String userName,
|
||||
@RequestParam String password) {
|
||||
boolean success = this.getUserService().register(userName, password);
|
||||
RegisterResponseModel registerUserResponseModel = new RegisterResponseModel();
|
||||
registerUserResponseModel.setSuccess(success);
|
||||
return registerUserResponseModel;
|
||||
}
|
||||
|
||||
private AuthorizeResponseModel authorize(String userName, String password,
|
||||
byte requiredScope) {
|
||||
boolean authorized = this.getUserService().validateUser(userName,
|
||||
password);
|
||||
if (!authorized) {
|
||||
return buildAuthorizeResponseModel(null, -1, false);
|
||||
}
|
||||
User user = this.getUserService().getUserByName(userName);
|
||||
if (!this.getAuthenticationManager().isScopeMeet(user.getScope(),
|
||||
requiredScope)) {
|
||||
return buildAuthorizeResponseModel(null, -1, false);
|
||||
}
|
||||
AccessToken accessToken = this.getAuthenticationManager()
|
||||
.generateAccessToken(user);
|
||||
String credential = this.getAuthenticationManager().generateCredential(
|
||||
user);
|
||||
return buildAuthorizeResponseModel(credential,
|
||||
accessToken.getExpiresIn(), true);
|
||||
}
|
||||
|
||||
private AuthorizeResponseModel buildAuthorizeResponseModel(
|
||||
String accessToken, int expiresIn, boolean success) {
|
||||
AuthorizeResponseModel authorizeResponseModel = new AuthorizeResponseModel();
|
||||
authorizeResponseModel.setAccessToken(accessToken);
|
||||
authorizeResponseModel.setExpiresIn(expiresIn);
|
||||
authorizeResponseModel.setSuccess(success);
|
||||
return authorizeResponseModel;
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/adminAuthorize", method = RequestMethod.GET)
|
||||
@ResponseBody
|
||||
public AuthorizeResponseModel adminAuthorize(@RequestParam String userName,
|
||||
@RequestParam String password) {
|
||||
return authorize(userName, password, UserService.SUPER_AUTHENTICATION);
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/normalAuthorize", method = RequestMethod.GET)
|
||||
@ResponseBody
|
||||
public AuthorizeResponseModel normalAuthorize(
|
||||
@RequestParam String userName, @RequestParam String password) {
|
||||
return authorize(userName, password, UserService.NORAML_AUTHENTICATION);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,12 +7,12 @@ import org.bench4q.master.domain.MonitorInBusiness;
|
|||
import org.bench4q.master.domain.RunningAgent;
|
||||
import org.bench4q.master.domain.RunningScript;
|
||||
import org.bench4q.master.domain.TestPlanInBusiness;
|
||||
import org.bench4q.master.entity.Agent;
|
||||
import org.bench4q.master.entity.Port;
|
||||
import org.bench4q.master.entity.Script;
|
||||
import org.bench4q.master.entity.TestPlanDB;
|
||||
import org.bench4q.master.entity.User;
|
||||
import org.bench4q.master.service.infrastructure.ScriptService;
|
||||
import org.bench4q.master.domain.entity.Agent;
|
||||
import org.bench4q.master.domain.entity.Port;
|
||||
import org.bench4q.master.domain.entity.Script;
|
||||
import org.bench4q.master.domain.entity.TestPlanDB;
|
||||
import org.bench4q.master.domain.entity.User;
|
||||
import org.bench4q.master.domain.service.ScriptService;
|
||||
import org.bench4q.share.models.master.AgentModel;
|
||||
import org.bench4q.share.models.master.MonitorModel;
|
||||
import org.bench4q.share.models.master.PortModel;
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
package org.bench4q.master.domain;
|
||||
|
||||
public interface IAggregate {
|
||||
}
|
|
@ -1,49 +1,49 @@
|
|||
package org.bench4q.master.domain;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bench4q.master.entity.Agent;
|
||||
import org.bench4q.master.service.infrastructure.AgentService;
|
||||
|
||||
public class RunningAgent {
|
||||
private Agent agent;
|
||||
private int loadInUse;
|
||||
private int scriptId;
|
||||
private UUID agentRunId;
|
||||
|
||||
public Agent getAgent() {
|
||||
return agent;
|
||||
}
|
||||
|
||||
public void setAgent(Agent agent) {
|
||||
this.agent = agent;
|
||||
}
|
||||
|
||||
public int getLoadInUse() {
|
||||
return loadInUse;
|
||||
}
|
||||
|
||||
public void setLoadInUse(int loadInUse) {
|
||||
this.loadInUse = loadInUse;
|
||||
}
|
||||
|
||||
public int getScriptId() {
|
||||
return scriptId;
|
||||
}
|
||||
|
||||
public void setScriptId(int scriptId) {
|
||||
this.scriptId = scriptId;
|
||||
}
|
||||
|
||||
public UUID getAgentRunId() {
|
||||
return agentRunId;
|
||||
}
|
||||
|
||||
public void setAgentRunId(UUID agentRunId) {
|
||||
this.agentRunId = agentRunId;
|
||||
}
|
||||
|
||||
public boolean isBreakDown() {
|
||||
return this.getAgent().getCurrentStatus() == AgentService.AGENT_STATUS_BreakDown;
|
||||
}
|
||||
}
|
||||
package org.bench4q.master.domain;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bench4q.master.domain.entity.Agent;
|
||||
import org.bench4q.master.domain.service.AgentService;
|
||||
|
||||
public class RunningAgent {
|
||||
private Agent agent;
|
||||
private int loadInUse;
|
||||
private int scriptId;
|
||||
private UUID agentRunId;
|
||||
|
||||
public Agent getAgent() {
|
||||
return agent;
|
||||
}
|
||||
|
||||
public void setAgent(Agent agent) {
|
||||
this.agent = agent;
|
||||
}
|
||||
|
||||
public int getLoadInUse() {
|
||||
return loadInUse;
|
||||
}
|
||||
|
||||
public void setLoadInUse(int loadInUse) {
|
||||
this.loadInUse = loadInUse;
|
||||
}
|
||||
|
||||
public int getScriptId() {
|
||||
return scriptId;
|
||||
}
|
||||
|
||||
public void setScriptId(int scriptId) {
|
||||
this.scriptId = scriptId;
|
||||
}
|
||||
|
||||
public UUID getAgentRunId() {
|
||||
return agentRunId;
|
||||
}
|
||||
|
||||
public void setAgentRunId(UUID agentRunId) {
|
||||
this.agentRunId = agentRunId;
|
||||
}
|
||||
|
||||
public boolean isBreakDown() {
|
||||
return this.getAgent().getCurrentStatus() == AgentService.AGENT_STATUS_BreakDown;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,358 +1,358 @@
|
|||
package org.bench4q.master.domain;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Observable;
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.bench4q.master.helper.ApplicationContextHelper;
|
||||
import org.bench4q.master.service.infrastructure.AgentService;
|
||||
import org.bench4q.master.service.infrastructure.RunningAgentService;
|
||||
import org.bench4q.master.service.infrastructure.ScriptService;
|
||||
import org.bench4q.master.service.infrastructure.TestPlanService;
|
||||
import org.bench4q.master.testplan.TestPlanEngine;
|
||||
import org.bench4q.master.testplan.datastatistics.BehaviorsBriefStatistics;
|
||||
import org.bench4q.master.testplan.datastatistics.DataStatistics;
|
||||
import org.bench4q.master.testplan.datastatistics.PagesBriefStatistics;
|
||||
import org.bench4q.master.testplan.datastatistics.ScriptBriefStatistics;
|
||||
import org.bench4q.master.testplan.datastatistics.ScriptStatistics;
|
||||
import org.bench4q.master.testplan.highavailable.AgentRunBlotter;
|
||||
import org.bench4q.master.testplan.highavailable.faultolerence.StopAgentFault;
|
||||
import org.bench4q.master.testplan.schedulscript.ExecutionOverTask;
|
||||
import org.bench4q.master.testplan.schedulscript.WarmUpOverTask;
|
||||
import org.bench4q.share.models.agent.RunScenarioModel;
|
||||
import org.bench4q.share.models.agent.StopTestModel;
|
||||
import org.bench4q.share.models.agent.statistics.AgentBriefStatusModel;
|
||||
import org.bench4q.share.models.agent.statistics.DataStatisticsModel;
|
||||
import org.bench4q.share.models.master.TestScriptConfig;
|
||||
import org.bench4q.share.models.master.statistics.ScriptBehaviorsBriefModel;
|
||||
import org.bench4q.share.models.master.statistics.ScriptBriefResultModel;
|
||||
import org.bench4q.share.models.master.statistics.ScriptPagesBriefModel;
|
||||
import org.bench4q.share.models.master.statistics.SampleModel;
|
||||
|
||||
public class RunningScript extends Observable {
|
||||
private int scriptId;
|
||||
private UUID testPlanID;
|
||||
private int requireLoad;
|
||||
private boolean finished;
|
||||
private TestScriptConfig config;
|
||||
private RunScenarioModel scenario;
|
||||
private List<RunningAgent> runningAgents = new ArrayList<RunningAgent>();
|
||||
|
||||
private Timer timer;
|
||||
private List<DataStatistics> dataStatisticsList;
|
||||
private RunningAgentService runningAgentService;
|
||||
private AgentService agentService;
|
||||
private ScriptService scriptService;
|
||||
private static Logger logger = Logger.getLogger(RunningScript.class);
|
||||
private ScriptBriefResultModel latestScriptBriefModel;
|
||||
|
||||
public int getScriptId() {
|
||||
return scriptId;
|
||||
}
|
||||
|
||||
private void setScriptId(int scriptId) {
|
||||
this.scriptId = scriptId;
|
||||
}
|
||||
|
||||
public int getRequireLoad() {
|
||||
return requireLoad;
|
||||
}
|
||||
|
||||
private void setRequireLoad(int requireLoad) {
|
||||
this.requireLoad = requireLoad;
|
||||
}
|
||||
|
||||
public TestScriptConfig getConfig() {
|
||||
return config;
|
||||
}
|
||||
|
||||
private void setConfig(TestScriptConfig config) {
|
||||
this.config = config;
|
||||
}
|
||||
|
||||
public boolean isFinished() {
|
||||
return finished;
|
||||
}
|
||||
|
||||
private void setFinished(boolean finish) {
|
||||
this.finished = finish;
|
||||
}
|
||||
|
||||
public RunScenarioModel getScenario() {
|
||||
return scenario;
|
||||
}
|
||||
|
||||
private void setScenario(RunScenarioModel scenario) {
|
||||
this.scenario = scenario;
|
||||
}
|
||||
|
||||
private List<RunningAgent> getRunningAgents() {
|
||||
return this.runningAgents;
|
||||
}
|
||||
|
||||
private void setRunningAgents(List<RunningAgent> runningAgents) {
|
||||
this.runningAgents = runningAgents;
|
||||
}
|
||||
|
||||
public UUID getTestPlanID() {
|
||||
return testPlanID;
|
||||
}
|
||||
|
||||
public void setTestPlanID(UUID testPlanID) {
|
||||
this.testPlanID = testPlanID;
|
||||
}
|
||||
|
||||
private List<DataStatistics> getDataStatisticsList() {
|
||||
return dataStatisticsList;
|
||||
}
|
||||
|
||||
private void setDataStatisticsList(List<DataStatistics> dataStatisticsList) {
|
||||
this.dataStatisticsList = dataStatisticsList;
|
||||
}
|
||||
|
||||
private RunningAgentService getRunningAgentService() {
|
||||
return runningAgentService;
|
||||
}
|
||||
|
||||
private void setRunningAgentService(RunningAgentService runningAgentService) {
|
||||
this.runningAgentService = runningAgentService;
|
||||
}
|
||||
|
||||
private AgentService getAgentService() {
|
||||
return agentService;
|
||||
}
|
||||
|
||||
private void setAgentService(AgentService agentService) {
|
||||
this.agentService = agentService;
|
||||
}
|
||||
|
||||
private ScriptService getScriptService() {
|
||||
return scriptService;
|
||||
}
|
||||
|
||||
private void setScriptService(ScriptService scriptService) {
|
||||
this.scriptService = scriptService;
|
||||
}
|
||||
|
||||
private Timer getTimer() {
|
||||
return timer;
|
||||
}
|
||||
|
||||
private void setTimer(Timer timer) {
|
||||
this.timer = timer;
|
||||
}
|
||||
|
||||
public ScriptBriefResultModel getLatestScriptBriefModel() {
|
||||
return latestScriptBriefModel;
|
||||
}
|
||||
|
||||
private void setLatestScriptBriefModel(
|
||||
ScriptBriefResultModel latestScriptBriefModel) {
|
||||
this.latestScriptBriefModel = latestScriptBriefModel;
|
||||
}
|
||||
|
||||
private RunningScript() {
|
||||
ScriptBriefResultModel scriptBriefResultModel = new ScriptBriefResultModel();
|
||||
scriptBriefResultModel.setAverageResponseTime(-1);
|
||||
this.setLatestScriptBriefModel(scriptBriefResultModel);
|
||||
|
||||
this.setRunningAgents(new ArrayList<RunningAgent>());
|
||||
this.setDataStatisticsList(new ArrayList<DataStatistics>());
|
||||
this.getDataStatisticsList().add(new ScriptBriefStatistics());
|
||||
this.getDataStatisticsList().add(new BehaviorsBriefStatistics());
|
||||
this.getDataStatisticsList().add(new PagesBriefStatistics());
|
||||
this.setTimer(new Timer());
|
||||
this.setRunningAgentService(ApplicationContextHelper.getContext()
|
||||
.getBean(RunningAgentService.class));
|
||||
this.setAgentService(ApplicationContextHelper.getContext().getBean(
|
||||
AgentService.class));
|
||||
this.setScriptService(ApplicationContextHelper.getContext().getBean(
|
||||
ScriptService.class));
|
||||
}
|
||||
|
||||
public RunningScript(TestScriptConfig config, int requireLoad,
|
||||
int scriptId, UUID testPlanId, List<RunningAgent> runningAgents) {
|
||||
this();
|
||||
this.setConfig(config);
|
||||
this.setFinished(false);
|
||||
this.setRequireLoad(requireLoad);
|
||||
this.setTestPlanID(testPlanId);
|
||||
this.setScriptId(scriptId);
|
||||
this.getRunningAgents().addAll(runningAgents);
|
||||
this.setScenario(this.getScriptService().getRunSceniroModelByScriptId(
|
||||
this.getScriptId()));
|
||||
}
|
||||
|
||||
public static boolean notValidScript(RunningScript input) {
|
||||
return input == null || input.getRunningAgents() == null;
|
||||
}
|
||||
|
||||
public List<RunningAgent> queryRunningAgentsUnModifiable() {
|
||||
return Collections.unmodifiableList(this.runningAgents);
|
||||
}
|
||||
|
||||
private DataStatistics getScriptBriefStatistics() {
|
||||
return getSpecificDataStatistics(ScriptBriefStatistics.class);
|
||||
}
|
||||
|
||||
private DataStatistics getBehaviorsBriefStatistics() {
|
||||
return getSpecificDataStatistics(BehaviorsBriefStatistics.class);
|
||||
}
|
||||
|
||||
public DataStatistics getPagesBriefStatistics() {
|
||||
return getSpecificDataStatistics(PagesBriefStatistics.class);
|
||||
}
|
||||
|
||||
private DataStatistics getSpecificDataStatistics(
|
||||
Class<? extends DataStatistics> dataStatisticsClass) {
|
||||
for (DataStatistics dataStatistics : this.getDataStatisticsList()) {
|
||||
if (dataStatistics.getClass().equals(dataStatisticsClass)) {
|
||||
return dataStatistics;
|
||||
}
|
||||
}
|
||||
return new ScriptStatistics() {
|
||||
public void add(DataStatisticsModel dataUnit) {
|
||||
}
|
||||
|
||||
public Object getStatistics() {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private ScriptBriefResultModel getScriptBrief() {
|
||||
for (RunningAgent runningAgent : getRunningAgents()) {
|
||||
if (runningAgent.isBreakDown()) {
|
||||
continue;
|
||||
}
|
||||
AgentBriefStatusModel briefStatusModel = getRunningAgentService()
|
||||
.brief(runningAgent.getAgent(),
|
||||
runningAgent.getAgentRunId());
|
||||
if (briefStatusModel == null) {
|
||||
continue;
|
||||
}
|
||||
getScriptBriefStatistics().add(briefStatusModel);
|
||||
}
|
||||
ScriptBriefResultModel result = (ScriptBriefResultModel) getScriptBriefStatistics()
|
||||
.getStatistics();
|
||||
result.setFinished(isFinished());
|
||||
this.setLatestScriptBriefModel(result);
|
||||
this.setChanged();
|
||||
this.notifyObservers(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
private ScriptBehaviorsBriefModel getBehaviorsBrief() {
|
||||
for (RunningAgent runningAgent : getRunningAgents()) {
|
||||
getBehaviorsBriefStatistics().add(
|
||||
this.getRunningAgentService().behaviorsBrief(
|
||||
runningAgent.getAgent(),
|
||||
runningAgent.getAgentRunId()));
|
||||
}
|
||||
|
||||
ScriptBehaviorsBriefModel result = (ScriptBehaviorsBriefModel) getBehaviorsBriefStatistics()
|
||||
.getStatistics();
|
||||
result.setFinished(isFinished());
|
||||
notifyObserver(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
private void notifyObserver(SampleModel result) {
|
||||
this.setChanged();
|
||||
this.notifyObservers(result);
|
||||
}
|
||||
|
||||
private ScriptPagesBriefModel getPagesBrief() {
|
||||
for (RunningAgent runningAgent : getRunningAgents()) {
|
||||
this.getPagesBriefStatistics().add(
|
||||
this.getRunningAgentService().pagesBrief(
|
||||
runningAgent.getAgent(),
|
||||
runningAgent.getAgentRunId()));
|
||||
}
|
||||
ScriptPagesBriefModel result = (ScriptPagesBriefModel) this
|
||||
.getPagesBriefStatistics().getStatistics();
|
||||
notifyObserver(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
public boolean scheduleAsConfig(TestPlanEngine testPlanEngine,
|
||||
UUID testPlanId) {
|
||||
TestScriptConfig testScriptConfig = this.getConfig();
|
||||
if (testScriptConfig == null) {
|
||||
return false;
|
||||
}
|
||||
Timer timer = new Timer();
|
||||
timer.schedule(new WarmUpOverTask(), testScriptConfig.getWarmUp()
|
||||
* TestPlanService.TIME_UNIT);
|
||||
|
||||
ExecutionOverTask executionOverTask = new ExecutionOverTask(this);
|
||||
timer.schedule(
|
||||
executionOverTask,
|
||||
(testScriptConfig.getWarmUp() + testScriptConfig
|
||||
.getExecuteRange()) * TestPlanService.TIME_UNIT);
|
||||
|
||||
timer.schedule(
|
||||
new TimerTask() {
|
||||
@Override
|
||||
public void run() {
|
||||
System.out.println("cool down over!");
|
||||
}
|
||||
},
|
||||
(testScriptConfig.getWarmUp()
|
||||
+ testScriptConfig.getExecuteRange() + testScriptConfig
|
||||
.getCoolDown()) * TestPlanService.TIME_UNIT);
|
||||
return true;
|
||||
}
|
||||
|
||||
public void doAfterDistributeLoad(List<RunningAgent> agentsAfterDistribute) {
|
||||
this.getRunningAgents().addAll(agentsAfterDistribute);
|
||||
}
|
||||
|
||||
public void doPeriodicBrief() {
|
||||
this.getTimer().scheduleAtFixedRate(new TimerTask() {
|
||||
@Override
|
||||
public void run() {
|
||||
getScriptBrief();
|
||||
getPagesBrief();
|
||||
getBehaviorsBrief();
|
||||
}
|
||||
}, 0, 10000);
|
||||
}
|
||||
|
||||
public void doForComplete() {
|
||||
for (RunningAgent runningAgent : this.runningAgents) {
|
||||
if (runningAgent == null) {
|
||||
continue;
|
||||
}
|
||||
StopTestModel resultModel = this.getRunningAgentService().stop(
|
||||
runningAgent.getAgent(), runningAgent.getAgentRunId());
|
||||
if (resultModel == null || !resultModel.isSuccess()) {
|
||||
doFaultTolerance(runningAgent);
|
||||
continue;
|
||||
}
|
||||
backLoadAndCleanUp(runningAgent);
|
||||
}
|
||||
this.getTimer().cancel();
|
||||
this.runningAgents.clear();
|
||||
this.setFinished(true);
|
||||
}
|
||||
|
||||
private void doFaultTolerance(RunningAgent runningAgent) {
|
||||
logger.error("when stop agent with hostName "
|
||||
+ runningAgent.getAgent().getHostName() + " returns null!");
|
||||
StopAgentFault stopAgentFault = new StopAgentFault(new AgentRunBlotter(
|
||||
this.getTestPlanID(), runningAgent));
|
||||
stopAgentFault.doTolerance();
|
||||
}
|
||||
|
||||
private void backLoadAndCleanUp(RunningAgent runningAgent) {
|
||||
String hostName = runningAgent.getAgent().getHostName();
|
||||
this.getAgentService().backLoadToAgent(hostName,
|
||||
runningAgent.getLoadInUse());
|
||||
}
|
||||
}
|
||||
package org.bench4q.master.domain;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Observable;
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.bench4q.master.domain.service.AgentService;
|
||||
import org.bench4q.master.domain.service.ScriptService;
|
||||
import org.bench4q.master.domain.service.TestPlanService;
|
||||
import org.bench4q.master.helper.ApplicationContextHelper;
|
||||
import org.bench4q.master.infrastructure.communication.AgentMessenger;
|
||||
import org.bench4q.master.testplan.TestPlanEngine;
|
||||
import org.bench4q.master.testplan.datastatistics.BehaviorsBriefStatistics;
|
||||
import org.bench4q.master.testplan.datastatistics.DataStatistics;
|
||||
import org.bench4q.master.testplan.datastatistics.PagesBriefStatistics;
|
||||
import org.bench4q.master.testplan.datastatistics.ScriptBriefStatistics;
|
||||
import org.bench4q.master.testplan.datastatistics.ScriptStatistics;
|
||||
import org.bench4q.master.testplan.highavailable.AgentRunBlotter;
|
||||
import org.bench4q.master.testplan.highavailable.faultolerence.StopAgentFault;
|
||||
import org.bench4q.master.testplan.schedulscript.ExecutionOverTask;
|
||||
import org.bench4q.master.testplan.schedulscript.WarmUpOverTask;
|
||||
import org.bench4q.share.models.agent.RunScenarioModel;
|
||||
import org.bench4q.share.models.agent.StopTestModel;
|
||||
import org.bench4q.share.models.agent.statistics.AgentBriefStatusModel;
|
||||
import org.bench4q.share.models.agent.statistics.DataStatisticsModel;
|
||||
import org.bench4q.share.models.master.TestScriptConfig;
|
||||
import org.bench4q.share.models.master.statistics.ScriptBehaviorsBriefModel;
|
||||
import org.bench4q.share.models.master.statistics.ScriptBriefResultModel;
|
||||
import org.bench4q.share.models.master.statistics.ScriptPagesBriefModel;
|
||||
import org.bench4q.share.models.master.statistics.SampleModel;
|
||||
|
||||
public class RunningScript extends Observable {
|
||||
private int scriptId;
|
||||
private UUID testPlanID;
|
||||
private int requireLoad;
|
||||
private boolean finished;
|
||||
private TestScriptConfig config;
|
||||
private RunScenarioModel scenario;
|
||||
private List<RunningAgent> runningAgents = new ArrayList<RunningAgent>();
|
||||
|
||||
private Timer timer;
|
||||
private List<DataStatistics> dataStatisticsList;
|
||||
private AgentMessenger runningAgentService;
|
||||
private AgentService agentService;
|
||||
private ScriptService scriptService;
|
||||
private static Logger logger = Logger.getLogger(RunningScript.class);
|
||||
private ScriptBriefResultModel latestScriptBriefModel;
|
||||
|
||||
public int getScriptId() {
|
||||
return scriptId;
|
||||
}
|
||||
|
||||
private void setScriptId(int scriptId) {
|
||||
this.scriptId = scriptId;
|
||||
}
|
||||
|
||||
public int getRequireLoad() {
|
||||
return requireLoad;
|
||||
}
|
||||
|
||||
private void setRequireLoad(int requireLoad) {
|
||||
this.requireLoad = requireLoad;
|
||||
}
|
||||
|
||||
public TestScriptConfig getConfig() {
|
||||
return config;
|
||||
}
|
||||
|
||||
private void setConfig(TestScriptConfig config) {
|
||||
this.config = config;
|
||||
}
|
||||
|
||||
public boolean isFinished() {
|
||||
return finished;
|
||||
}
|
||||
|
||||
private void setFinished(boolean finish) {
|
||||
this.finished = finish;
|
||||
}
|
||||
|
||||
public RunScenarioModel getScenario() {
|
||||
return scenario;
|
||||
}
|
||||
|
||||
private void setScenario(RunScenarioModel scenario) {
|
||||
this.scenario = scenario;
|
||||
}
|
||||
|
||||
private List<RunningAgent> getRunningAgents() {
|
||||
return this.runningAgents;
|
||||
}
|
||||
|
||||
private void setRunningAgents(List<RunningAgent> runningAgents) {
|
||||
this.runningAgents = runningAgents;
|
||||
}
|
||||
|
||||
public UUID getTestPlanID() {
|
||||
return testPlanID;
|
||||
}
|
||||
|
||||
public void setTestPlanID(UUID testPlanID) {
|
||||
this.testPlanID = testPlanID;
|
||||
}
|
||||
|
||||
private List<DataStatistics> getDataStatisticsList() {
|
||||
return dataStatisticsList;
|
||||
}
|
||||
|
||||
private void setDataStatisticsList(List<DataStatistics> dataStatisticsList) {
|
||||
this.dataStatisticsList = dataStatisticsList;
|
||||
}
|
||||
|
||||
private AgentMessenger getRunningAgentService() {
|
||||
return runningAgentService;
|
||||
}
|
||||
|
||||
private void setRunningAgentService(AgentMessenger runningAgentService) {
|
||||
this.runningAgentService = runningAgentService;
|
||||
}
|
||||
|
||||
private AgentService getAgentService() {
|
||||
return agentService;
|
||||
}
|
||||
|
||||
private void setAgentService(AgentService agentService) {
|
||||
this.agentService = agentService;
|
||||
}
|
||||
|
||||
private ScriptService getScriptService() {
|
||||
return scriptService;
|
||||
}
|
||||
|
||||
private void setScriptService(ScriptService scriptService) {
|
||||
this.scriptService = scriptService;
|
||||
}
|
||||
|
||||
private Timer getTimer() {
|
||||
return timer;
|
||||
}
|
||||
|
||||
private void setTimer(Timer timer) {
|
||||
this.timer = timer;
|
||||
}
|
||||
|
||||
public ScriptBriefResultModel getLatestScriptBriefModel() {
|
||||
return latestScriptBriefModel;
|
||||
}
|
||||
|
||||
private void setLatestScriptBriefModel(
|
||||
ScriptBriefResultModel latestScriptBriefModel) {
|
||||
this.latestScriptBriefModel = latestScriptBriefModel;
|
||||
}
|
||||
|
||||
private RunningScript() {
|
||||
ScriptBriefResultModel scriptBriefResultModel = new ScriptBriefResultModel();
|
||||
scriptBriefResultModel.setAverageResponseTime(-1);
|
||||
this.setLatestScriptBriefModel(scriptBriefResultModel);
|
||||
|
||||
this.setRunningAgents(new ArrayList<RunningAgent>());
|
||||
this.setDataStatisticsList(new ArrayList<DataStatistics>());
|
||||
this.getDataStatisticsList().add(new ScriptBriefStatistics());
|
||||
this.getDataStatisticsList().add(new BehaviorsBriefStatistics());
|
||||
this.getDataStatisticsList().add(new PagesBriefStatistics());
|
||||
this.setTimer(new Timer());
|
||||
this.setRunningAgentService(ApplicationContextHelper.getContext()
|
||||
.getBean(AgentMessenger.class));
|
||||
this.setAgentService(ApplicationContextHelper.getContext().getBean(
|
||||
AgentService.class));
|
||||
this.setScriptService(ApplicationContextHelper.getContext().getBean(
|
||||
ScriptService.class));
|
||||
}
|
||||
|
||||
public RunningScript(TestScriptConfig config, int requireLoad,
|
||||
int scriptId, UUID testPlanId, List<RunningAgent> runningAgents) {
|
||||
this();
|
||||
this.setConfig(config);
|
||||
this.setFinished(false);
|
||||
this.setRequireLoad(requireLoad);
|
||||
this.setTestPlanID(testPlanId);
|
||||
this.setScriptId(scriptId);
|
||||
this.getRunningAgents().addAll(runningAgents);
|
||||
this.setScenario(this.getScriptService().getRunSceniroModelByScriptId(
|
||||
this.getScriptId()));
|
||||
}
|
||||
|
||||
public static boolean notValidScript(RunningScript input) {
|
||||
return input == null || input.getRunningAgents() == null;
|
||||
}
|
||||
|
||||
public List<RunningAgent> queryRunningAgentsUnModifiable() {
|
||||
return Collections.unmodifiableList(this.runningAgents);
|
||||
}
|
||||
|
||||
private DataStatistics getScriptBriefStatistics() {
|
||||
return getSpecificDataStatistics(ScriptBriefStatistics.class);
|
||||
}
|
||||
|
||||
private DataStatistics getBehaviorsBriefStatistics() {
|
||||
return getSpecificDataStatistics(BehaviorsBriefStatistics.class);
|
||||
}
|
||||
|
||||
public DataStatistics getPagesBriefStatistics() {
|
||||
return getSpecificDataStatistics(PagesBriefStatistics.class);
|
||||
}
|
||||
|
||||
private DataStatistics getSpecificDataStatistics(
|
||||
Class<? extends DataStatistics> dataStatisticsClass) {
|
||||
for (DataStatistics dataStatistics : this.getDataStatisticsList()) {
|
||||
if (dataStatistics.getClass().equals(dataStatisticsClass)) {
|
||||
return dataStatistics;
|
||||
}
|
||||
}
|
||||
return new ScriptStatistics() {
|
||||
public void add(DataStatisticsModel dataUnit) {
|
||||
}
|
||||
|
||||
public Object getStatistics() {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private ScriptBriefResultModel getScriptBrief() {
|
||||
for (RunningAgent runningAgent : getRunningAgents()) {
|
||||
if (runningAgent.isBreakDown()) {
|
||||
continue;
|
||||
}
|
||||
AgentBriefStatusModel briefStatusModel = getRunningAgentService()
|
||||
.brief(runningAgent.getAgent(),
|
||||
runningAgent.getAgentRunId());
|
||||
if (briefStatusModel == null) {
|
||||
continue;
|
||||
}
|
||||
getScriptBriefStatistics().add(briefStatusModel);
|
||||
}
|
||||
ScriptBriefResultModel result = (ScriptBriefResultModel) getScriptBriefStatistics()
|
||||
.getStatistics();
|
||||
result.setFinished(isFinished());
|
||||
this.setLatestScriptBriefModel(result);
|
||||
this.setChanged();
|
||||
this.notifyObservers(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
private ScriptBehaviorsBriefModel getBehaviorsBrief() {
|
||||
for (RunningAgent runningAgent : getRunningAgents()) {
|
||||
getBehaviorsBriefStatistics().add(
|
||||
this.getRunningAgentService().behaviorsBrief(
|
||||
runningAgent.getAgent(),
|
||||
runningAgent.getAgentRunId()));
|
||||
}
|
||||
|
||||
ScriptBehaviorsBriefModel result = (ScriptBehaviorsBriefModel) getBehaviorsBriefStatistics()
|
||||
.getStatistics();
|
||||
result.setFinished(isFinished());
|
||||
notifyObserver(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
private void notifyObserver(SampleModel result) {
|
||||
this.setChanged();
|
||||
this.notifyObservers(result);
|
||||
}
|
||||
|
||||
private ScriptPagesBriefModel getPagesBrief() {
|
||||
for (RunningAgent runningAgent : getRunningAgents()) {
|
||||
this.getPagesBriefStatistics().add(
|
||||
this.getRunningAgentService().pagesBrief(
|
||||
runningAgent.getAgent(),
|
||||
runningAgent.getAgentRunId()));
|
||||
}
|
||||
ScriptPagesBriefModel result = (ScriptPagesBriefModel) this
|
||||
.getPagesBriefStatistics().getStatistics();
|
||||
notifyObserver(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
public boolean scheduleAsConfig(TestPlanEngine testPlanEngine,
|
||||
UUID testPlanId) {
|
||||
TestScriptConfig testScriptConfig = this.getConfig();
|
||||
if (testScriptConfig == null) {
|
||||
return false;
|
||||
}
|
||||
Timer timer = new Timer();
|
||||
timer.schedule(new WarmUpOverTask(), testScriptConfig.getWarmUp()
|
||||
* TestPlanService.TIME_UNIT);
|
||||
|
||||
ExecutionOverTask executionOverTask = new ExecutionOverTask(this);
|
||||
timer.schedule(
|
||||
executionOverTask,
|
||||
(testScriptConfig.getWarmUp() + testScriptConfig
|
||||
.getExecuteRange()) * TestPlanService.TIME_UNIT);
|
||||
|
||||
timer.schedule(
|
||||
new TimerTask() {
|
||||
@Override
|
||||
public void run() {
|
||||
System.out.println("cool down over!");
|
||||
}
|
||||
},
|
||||
(testScriptConfig.getWarmUp()
|
||||
+ testScriptConfig.getExecuteRange() + testScriptConfig
|
||||
.getCoolDown()) * TestPlanService.TIME_UNIT);
|
||||
return true;
|
||||
}
|
||||
|
||||
public void doAfterDistributeLoad(List<RunningAgent> agentsAfterDistribute) {
|
||||
this.getRunningAgents().addAll(agentsAfterDistribute);
|
||||
}
|
||||
|
||||
public void doPeriodicBrief() {
|
||||
this.getTimer().scheduleAtFixedRate(new TimerTask() {
|
||||
@Override
|
||||
public void run() {
|
||||
getScriptBrief();
|
||||
getPagesBrief();
|
||||
getBehaviorsBrief();
|
||||
}
|
||||
}, 0, 10000);
|
||||
}
|
||||
|
||||
public void doForComplete() {
|
||||
for (RunningAgent runningAgent : this.runningAgents) {
|
||||
if (runningAgent == null) {
|
||||
continue;
|
||||
}
|
||||
StopTestModel resultModel = this.getRunningAgentService().stop(
|
||||
runningAgent.getAgent(), runningAgent.getAgentRunId());
|
||||
if (resultModel == null || !resultModel.isSuccess()) {
|
||||
doFaultTolerance(runningAgent);
|
||||
continue;
|
||||
}
|
||||
backLoadAndCleanUp(runningAgent);
|
||||
}
|
||||
this.getTimer().cancel();
|
||||
this.runningAgents.clear();
|
||||
this.setFinished(true);
|
||||
}
|
||||
|
||||
private void doFaultTolerance(RunningAgent runningAgent) {
|
||||
logger.error("when stop agent with hostName "
|
||||
+ runningAgent.getAgent().getHostName() + " returns null!");
|
||||
StopAgentFault stopAgentFault = new StopAgentFault(new AgentRunBlotter(
|
||||
this.getTestPlanID(), runningAgent));
|
||||
stopAgentFault.doTolerance();
|
||||
}
|
||||
|
||||
private void backLoadAndCleanUp(RunningAgent runningAgent) {
|
||||
String hostName = runningAgent.getAgent().getHostName();
|
||||
this.getAgentService().backLoadToAgent(hostName,
|
||||
runningAgent.getLoadInUse());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,101 +1,101 @@
|
|||
package org.bench4q.master.domain;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bench4q.master.helper.ApplicationContextHelper;
|
||||
import org.bench4q.master.service.infrastructure.TestPlanScriptService;
|
||||
|
||||
public class TestPlanContext {
|
||||
private Map<Integer, RunningScript> runningScriptMap;
|
||||
private TestPlanInBusiness testPlan;
|
||||
private boolean finish;
|
||||
|
||||
public TestPlanInBusiness getTestPlan() {
|
||||
return testPlan;
|
||||
}
|
||||
|
||||
public void setTestPlan(TestPlanInBusiness testPlan) {
|
||||
this.testPlan = testPlan;
|
||||
}
|
||||
|
||||
private Map<Integer, RunningScript> getRunningScriptMap() {
|
||||
return runningScriptMap;
|
||||
}
|
||||
|
||||
private void setRunningScriptMap(
|
||||
Map<Integer, RunningScript> runningScriptMap) {
|
||||
this.runningScriptMap = runningScriptMap;
|
||||
}
|
||||
|
||||
public boolean isFinish() {
|
||||
return finish;
|
||||
}
|
||||
|
||||
public void setFinish(boolean finish) {
|
||||
this.finish = finish;
|
||||
}
|
||||
|
||||
public TestPlanContext(TestPlanInBusiness testPlan, UUID testPlanID) {
|
||||
this.setRunningScriptMap(new HashMap<Integer, RunningScript>());
|
||||
this.fillScriptMapAndAssignTestPlanIdAndScenario(
|
||||
testPlan.getRunningScripts(), testPlanID);
|
||||
this.setTestPlan(testPlan);
|
||||
}
|
||||
|
||||
public void cleanUpFinishedContext() {
|
||||
this.setFinish(true);
|
||||
this.setTestPlan(null);
|
||||
this.setRunningScriptMap(new HashMap<Integer, RunningScript>());
|
||||
System.gc();
|
||||
}
|
||||
|
||||
private void fillScriptMapAndAssignTestPlanIdAndScenario(
|
||||
List<RunningScript> list, UUID testPlanID) {
|
||||
if (this.getRunningScriptMap() == null) {
|
||||
this.setRunningScriptMap(new HashMap<Integer, RunningScript>());
|
||||
}
|
||||
for (RunningScript runningScript : list) {
|
||||
runningScript.setTestPlanID(testPlanID);
|
||||
runningScript.addObserver(ApplicationContextHelper.getContext()
|
||||
.getBean(TestPlanScriptService.class));
|
||||
this.getRunningScriptMap().put(
|
||||
new Integer(runningScript.getScriptId()), runningScript);
|
||||
}
|
||||
}
|
||||
|
||||
public void addToScriptMap(RunningScript runningScript) {
|
||||
this.runningScriptMap.put(new Integer(runningScript.getScriptId()),
|
||||
runningScript);
|
||||
}
|
||||
|
||||
public RunningScript queryRunningScript(int scriptId) {
|
||||
return this.runningScriptMap.get(new Integer(scriptId));
|
||||
}
|
||||
|
||||
public Collection<RunningScript> getAllScript() {
|
||||
return Collections.unmodifiableCollection(this.getRunningScriptMap()
|
||||
.values());
|
||||
}
|
||||
|
||||
public int getScriptCount() {
|
||||
return this.getRunningScriptMap().size();
|
||||
}
|
||||
|
||||
public boolean isContains(int scriptId) {
|
||||
return this.getRunningScriptMap().containsKey(scriptId);
|
||||
}
|
||||
|
||||
public int getTotalLoad() {
|
||||
int result = 0;
|
||||
for (RunningScript runningScript : getAllScript()) {
|
||||
result += runningScript.getRequireLoad();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
package org.bench4q.master.domain;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bench4q.master.domain.service.TestPlanScriptService;
|
||||
import org.bench4q.master.helper.ApplicationContextHelper;
|
||||
|
||||
public class TestPlanContext {
|
||||
private Map<Integer, RunningScript> runningScriptMap;
|
||||
private TestPlanInBusiness testPlan;
|
||||
private boolean finish;
|
||||
|
||||
public TestPlanInBusiness getTestPlan() {
|
||||
return testPlan;
|
||||
}
|
||||
|
||||
public void setTestPlan(TestPlanInBusiness testPlan) {
|
||||
this.testPlan = testPlan;
|
||||
}
|
||||
|
||||
private Map<Integer, RunningScript> getRunningScriptMap() {
|
||||
return runningScriptMap;
|
||||
}
|
||||
|
||||
private void setRunningScriptMap(
|
||||
Map<Integer, RunningScript> runningScriptMap) {
|
||||
this.runningScriptMap = runningScriptMap;
|
||||
}
|
||||
|
||||
public boolean isFinish() {
|
||||
return finish;
|
||||
}
|
||||
|
||||
public void setFinish(boolean finish) {
|
||||
this.finish = finish;
|
||||
}
|
||||
|
||||
public TestPlanContext(TestPlanInBusiness testPlan, UUID testPlanID) {
|
||||
this.setRunningScriptMap(new HashMap<Integer, RunningScript>());
|
||||
this.fillScriptMapAndAssignTestPlanIdAndScenario(
|
||||
testPlan.getRunningScripts(), testPlanID);
|
||||
this.setTestPlan(testPlan);
|
||||
}
|
||||
|
||||
public void cleanUpFinishedContext() {
|
||||
this.setFinish(true);
|
||||
this.setTestPlan(null);
|
||||
this.setRunningScriptMap(new HashMap<Integer, RunningScript>());
|
||||
System.gc();
|
||||
}
|
||||
|
||||
private void fillScriptMapAndAssignTestPlanIdAndScenario(
|
||||
List<RunningScript> list, UUID testPlanID) {
|
||||
if (this.getRunningScriptMap() == null) {
|
||||
this.setRunningScriptMap(new HashMap<Integer, RunningScript>());
|
||||
}
|
||||
for (RunningScript runningScript : list) {
|
||||
runningScript.setTestPlanID(testPlanID);
|
||||
runningScript.addObserver(ApplicationContextHelper.getContext()
|
||||
.getBean(TestPlanScriptService.class));
|
||||
this.getRunningScriptMap().put(
|
||||
new Integer(runningScript.getScriptId()), runningScript);
|
||||
}
|
||||
}
|
||||
|
||||
public void addToScriptMap(RunningScript runningScript) {
|
||||
this.runningScriptMap.put(new Integer(runningScript.getScriptId()),
|
||||
runningScript);
|
||||
}
|
||||
|
||||
public RunningScript queryRunningScript(int scriptId) {
|
||||
return this.runningScriptMap.get(new Integer(scriptId));
|
||||
}
|
||||
|
||||
public Collection<RunningScript> getAllScript() {
|
||||
return Collections.unmodifiableCollection(this.getRunningScriptMap()
|
||||
.values());
|
||||
}
|
||||
|
||||
public int getScriptCount() {
|
||||
return this.getRunningScriptMap().size();
|
||||
}
|
||||
|
||||
public boolean isContains(int scriptId) {
|
||||
return this.getRunningScriptMap().containsKey(scriptId);
|
||||
}
|
||||
|
||||
public int getTotalLoad() {
|
||||
int result = 0;
|
||||
for (RunningScript runningScript : getAllScript()) {
|
||||
result += runningScript.getRequireLoad();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,76 +1,76 @@
|
|||
package org.bench4q.master.entity;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.GenerationType;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Table;
|
||||
|
||||
@Entity
|
||||
@Table(name = "agent")
|
||||
public class Agent {
|
||||
private int id;
|
||||
protected String hostName;
|
||||
protected int port;
|
||||
protected int maxLoad;
|
||||
protected int remainLoad;
|
||||
protected int currentStatus;
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
@Column(name = "id", nullable = false)
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
@Column(name = "hostName", nullable = false)
|
||||
public String getHostName() {
|
||||
return hostName;
|
||||
}
|
||||
|
||||
public void setHostName(String hostName) {
|
||||
this.hostName = hostName;
|
||||
}
|
||||
|
||||
@Column(name = "port", nullable = false)
|
||||
public int getPort() {
|
||||
return port;
|
||||
}
|
||||
|
||||
public void setPort(int port) {
|
||||
this.port = port;
|
||||
}
|
||||
|
||||
@Column(name = "maxLoad", nullable = false)
|
||||
public int getMaxLoad() {
|
||||
return maxLoad;
|
||||
}
|
||||
|
||||
public void setMaxLoad(int maxLoad) {
|
||||
this.maxLoad = maxLoad;
|
||||
}
|
||||
|
||||
@Column(name = "remainLoad", nullable = false)
|
||||
public int getRemainLoad() {
|
||||
return remainLoad;
|
||||
}
|
||||
|
||||
public void setRemainLoad(int remainLoad) {
|
||||
this.remainLoad = remainLoad;
|
||||
}
|
||||
|
||||
@Column(name = "currentStatus", nullable = false)
|
||||
public int getCurrentStatus() {
|
||||
return currentStatus;
|
||||
}
|
||||
|
||||
public void setCurrentStatus(int currentStatus) {
|
||||
this.currentStatus = currentStatus;
|
||||
}
|
||||
|
||||
}
|
||||
package org.bench4q.master.domain.entity;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.GenerationType;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Table;
|
||||
|
||||
@Entity
|
||||
@Table(name = "agent")
|
||||
public class Agent {
|
||||
private int id;
|
||||
protected String hostName;
|
||||
protected int port;
|
||||
protected int maxLoad;
|
||||
protected int remainLoad;
|
||||
protected int currentStatus;
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
@Column(name = "id", nullable = false)
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
@Column(name = "hostName", nullable = false)
|
||||
public String getHostName() {
|
||||
return hostName;
|
||||
}
|
||||
|
||||
public void setHostName(String hostName) {
|
||||
this.hostName = hostName;
|
||||
}
|
||||
|
||||
@Column(name = "port", nullable = false)
|
||||
public int getPort() {
|
||||
return port;
|
||||
}
|
||||
|
||||
public void setPort(int port) {
|
||||
this.port = port;
|
||||
}
|
||||
|
||||
@Column(name = "maxLoad", nullable = false)
|
||||
public int getMaxLoad() {
|
||||
return maxLoad;
|
||||
}
|
||||
|
||||
public void setMaxLoad(int maxLoad) {
|
||||
this.maxLoad = maxLoad;
|
||||
}
|
||||
|
||||
@Column(name = "remainLoad", nullable = false)
|
||||
public int getRemainLoad() {
|
||||
return remainLoad;
|
||||
}
|
||||
|
||||
public void setRemainLoad(int remainLoad) {
|
||||
this.remainLoad = remainLoad;
|
||||
}
|
||||
|
||||
@Column(name = "currentStatus", nullable = false)
|
||||
public int getCurrentStatus() {
|
||||
return currentStatus;
|
||||
}
|
||||
|
||||
public void setCurrentStatus(int currentStatus) {
|
||||
this.currentStatus = currentStatus;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,5 +1,5 @@
|
|||
package org.bench4q.master.entity;
|
||||
|
||||
public interface EntityBase {
|
||||
public Object extractIdentifier();
|
||||
}
|
||||
package org.bench4q.master.domain.entity;
|
||||
|
||||
public interface EntityBase {
|
||||
public Object extractIdentifier();
|
||||
}
|
|
@ -1,81 +1,81 @@
|
|||
package org.bench4q.master.entity;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.GenerationType;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.JoinColumn;
|
||||
import javax.persistence.ManyToOne;
|
||||
import javax.persistence.Table;
|
||||
|
||||
@Entity
|
||||
@Table(name = "MonitorResult")
|
||||
public class MonitorResult {
|
||||
private int id;
|
||||
private TestPlanDB testPlanDB;
|
||||
private String type;
|
||||
private String content;
|
||||
private String hostNameUnderMonitor;
|
||||
private Date createDatetime;
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
@Column(name = "id", nullable = false)
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
@ManyToOne
|
||||
@JoinColumn(name = "testPlanRunId", nullable = false)
|
||||
public TestPlanDB getTestPlanDB() {
|
||||
return testPlanDB;
|
||||
}
|
||||
|
||||
public void setTestPlanDB(TestPlanDB testPlan) {
|
||||
this.testPlanDB = testPlan;
|
||||
}
|
||||
|
||||
@Column(name = "type", nullable = false)
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
@Column(name = "content", columnDefinition = "LONGTEXT", nullable = false)
|
||||
public String getContent() {
|
||||
return content;
|
||||
}
|
||||
|
||||
public void setContent(String content) {
|
||||
this.content = content;
|
||||
}
|
||||
|
||||
@Column(name = "hostNameUnderMonitor", nullable = false)
|
||||
public String getHostNameUnderMonitor() {
|
||||
return hostNameUnderMonitor;
|
||||
}
|
||||
|
||||
public void setHostNameUnderMonitor(String hostNameUnderMonitor) {
|
||||
this.hostNameUnderMonitor = hostNameUnderMonitor;
|
||||
}
|
||||
|
||||
@Column(name = "createDatetime", nullable = false)
|
||||
public Date getCreateDatetime() {
|
||||
return createDatetime;
|
||||
}
|
||||
|
||||
public void setCreateDatetime(Date date) {
|
||||
this.createDatetime = date;
|
||||
}
|
||||
|
||||
}
|
||||
package org.bench4q.master.domain.entity;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.GenerationType;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.JoinColumn;
|
||||
import javax.persistence.ManyToOne;
|
||||
import javax.persistence.Table;
|
||||
|
||||
@Entity
|
||||
@Table(name = "MonitorResult")
|
||||
public class MonitorResult {
|
||||
private int id;
|
||||
private TestPlanDB testPlanDB;
|
||||
private String type;
|
||||
private String content;
|
||||
private String hostNameUnderMonitor;
|
||||
private Date createDatetime;
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
@Column(name = "id", nullable = false)
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
@ManyToOne
|
||||
@JoinColumn(name = "testPlanRunId", nullable = false)
|
||||
public TestPlanDB getTestPlanDB() {
|
||||
return testPlanDB;
|
||||
}
|
||||
|
||||
public void setTestPlanDB(TestPlanDB testPlan) {
|
||||
this.testPlanDB = testPlan;
|
||||
}
|
||||
|
||||
@Column(name = "type", nullable = false)
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
@Column(name = "content", columnDefinition = "LONGTEXT", nullable = false)
|
||||
public String getContent() {
|
||||
return content;
|
||||
}
|
||||
|
||||
public void setContent(String content) {
|
||||
this.content = content;
|
||||
}
|
||||
|
||||
@Column(name = "hostNameUnderMonitor", nullable = false)
|
||||
public String getHostNameUnderMonitor() {
|
||||
return hostNameUnderMonitor;
|
||||
}
|
||||
|
||||
public void setHostNameUnderMonitor(String hostNameUnderMonitor) {
|
||||
this.hostNameUnderMonitor = hostNameUnderMonitor;
|
||||
}
|
||||
|
||||
@Column(name = "createDatetime", nullable = false)
|
||||
public Date getCreateDatetime() {
|
||||
return createDatetime;
|
||||
}
|
||||
|
||||
public void setCreateDatetime(Date date) {
|
||||
this.createDatetime = date;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package org.bench4q.master.entity;
|
||||
package org.bench4q.master.domain.entity;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
|
@ -1,4 +1,4 @@
|
|||
package org.bench4q.master.entity;
|
||||
package org.bench4q.master.domain.entity;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
|
@ -1,82 +1,82 @@
|
|||
package org.bench4q.master.entity;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.GenerationType;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.JoinColumn;
|
||||
import javax.persistence.ManyToOne;
|
||||
import javax.persistence.Table;
|
||||
|
||||
@Entity
|
||||
@Table(name = "Script")
|
||||
public class Script {
|
||||
|
||||
private int id;
|
||||
private String name;
|
||||
private String scriptContent;
|
||||
private int behaviorCount;
|
||||
private Date createDateTime;
|
||||
private User user;
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
@Column(name = "id", nullable = false)
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
@Column(name = "name", nullable = false)
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@Column(name = "createDateTime", nullable = false)
|
||||
public Date getCreateDateTime() {
|
||||
return createDateTime;
|
||||
}
|
||||
|
||||
public void setCreateDateTime(Date createDateTime) {
|
||||
this.createDateTime = createDateTime;
|
||||
}
|
||||
|
||||
@ManyToOne
|
||||
@JoinColumn(name = "userId", nullable = false)
|
||||
public User getUser() {
|
||||
return user;
|
||||
}
|
||||
|
||||
public void setUser(User user) {
|
||||
this.user = user;
|
||||
}
|
||||
|
||||
@Column(name = "scriptContent", columnDefinition = "LONGTEXT", nullable = false)
|
||||
public String getScriptContent() {
|
||||
return scriptContent;
|
||||
}
|
||||
|
||||
public void setScriptContent(String scriptContent) {
|
||||
this.scriptContent = scriptContent;
|
||||
}
|
||||
|
||||
@Column(name = "behaviorCount", nullable = false)
|
||||
public int getBehaviorCount() {
|
||||
return behaviorCount;
|
||||
}
|
||||
|
||||
public void setBehaviorCount(int behaviorCount) {
|
||||
this.behaviorCount = behaviorCount;
|
||||
}
|
||||
|
||||
}
|
||||
package org.bench4q.master.domain.entity;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.GenerationType;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.JoinColumn;
|
||||
import javax.persistence.ManyToOne;
|
||||
import javax.persistence.Table;
|
||||
|
||||
@Entity
|
||||
@Table(name = "Script")
|
||||
public class Script {
|
||||
|
||||
private int id;
|
||||
private String name;
|
||||
private String scriptContent;
|
||||
private int behaviorCount;
|
||||
private Date createDateTime;
|
||||
private User user;
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
@Column(name = "id", nullable = false)
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
@Column(name = "name", nullable = false)
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@Column(name = "createDateTime", nullable = false)
|
||||
public Date getCreateDateTime() {
|
||||
return createDateTime;
|
||||
}
|
||||
|
||||
public void setCreateDateTime(Date createDateTime) {
|
||||
this.createDateTime = createDateTime;
|
||||
}
|
||||
|
||||
@ManyToOne
|
||||
@JoinColumn(name = "userId", nullable = false)
|
||||
public User getUser() {
|
||||
return user;
|
||||
}
|
||||
|
||||
public void setUser(User user) {
|
||||
this.user = user;
|
||||
}
|
||||
|
||||
@Column(name = "scriptContent", columnDefinition = "LONGTEXT", nullable = false)
|
||||
public String getScriptContent() {
|
||||
return scriptContent;
|
||||
}
|
||||
|
||||
public void setScriptContent(String scriptContent) {
|
||||
this.scriptContent = scriptContent;
|
||||
}
|
||||
|
||||
@Column(name = "behaviorCount", nullable = false)
|
||||
public int getBehaviorCount() {
|
||||
return behaviorCount;
|
||||
}
|
||||
|
||||
public void setBehaviorCount(int behaviorCount) {
|
||||
this.behaviorCount = behaviorCount;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package org.bench4q.master.entity;
|
||||
package org.bench4q.master.domain.entity;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.Set;
|
||||
|
@ -15,9 +15,11 @@ import javax.persistence.ManyToOne;
|
|||
import javax.persistence.OneToMany;
|
||||
import javax.persistence.Table;
|
||||
|
||||
import org.bench4q.master.domain.IAggregate;
|
||||
|
||||
@Entity
|
||||
@Table(name = "testplan")
|
||||
public class TestPlanDB {
|
||||
public class TestPlanDB implements IAggregate {
|
||||
private int id;
|
||||
private String name;
|
||||
private Date createDateTime;
|
|
@ -1,4 +1,4 @@
|
|||
package org.bench4q.master.entity;
|
||||
package org.bench4q.master.domain.entity;
|
||||
|
||||
import javax.persistence.CascadeType;
|
||||
import javax.persistence.Column;
|
|
@ -1,83 +1,83 @@
|
|||
package org.bench4q.master.entity;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.GenerationType;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.JoinColumn;
|
||||
import javax.persistence.ManyToOne;
|
||||
import javax.persistence.Table;
|
||||
import javax.xml.bind.JAXBException;
|
||||
|
||||
import org.bench4q.share.helper.MarshalHelper;
|
||||
import org.bench4q.share.models.master.statistics.ScriptBriefResultModel;
|
||||
|
||||
@Entity
|
||||
@Table(name = "TestPlanScriptResult")
|
||||
public class TestPlanScriptResult {
|
||||
private int id;
|
||||
private TestPlanScript testPlanScript;
|
||||
private String resultContent;
|
||||
private String resultType;
|
||||
private Date createDatetime;
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
@Column(name = "id", nullable = false)
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
@ManyToOne
|
||||
@JoinColumn(name = "testPlanScriptId", nullable = false)
|
||||
public TestPlanScript getTestPlanScript() {
|
||||
return testPlanScript;
|
||||
}
|
||||
|
||||
public void setTestPlanScript(TestPlanScript testPlanScript) {
|
||||
this.testPlanScript = testPlanScript;
|
||||
}
|
||||
|
||||
@Column(name = "resultContent", columnDefinition = "LONGTEXT", nullable = false)
|
||||
public String getResultContent() {
|
||||
return resultContent;
|
||||
}
|
||||
|
||||
public void setResultContent(String scriptBriefResultContent) {
|
||||
this.resultContent = scriptBriefResultContent;
|
||||
}
|
||||
|
||||
@Column(name = "resultType", columnDefinition = "TEXT", nullable = false)
|
||||
public String getResultType() {
|
||||
return resultType;
|
||||
}
|
||||
|
||||
public void setResultType(String resultType) {
|
||||
this.resultType = resultType;
|
||||
}
|
||||
|
||||
@Column(name = "createDatetime", nullable = false)
|
||||
public Date getCreateDatetime() {
|
||||
return createDatetime;
|
||||
}
|
||||
|
||||
public void setCreateDatetime(Date createDatetime) {
|
||||
this.createDatetime = createDatetime;
|
||||
}
|
||||
|
||||
public ScriptBriefResultModel extractScriptBriefResultModel() {
|
||||
try {
|
||||
return (ScriptBriefResultModel) MarshalHelper.unmarshal(
|
||||
ScriptBriefResultModel.class, this.getResultContent());
|
||||
} catch (JAXBException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
package org.bench4q.master.domain.entity;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.GenerationType;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.JoinColumn;
|
||||
import javax.persistence.ManyToOne;
|
||||
import javax.persistence.Table;
|
||||
import javax.xml.bind.JAXBException;
|
||||
|
||||
import org.bench4q.share.helper.MarshalHelper;
|
||||
import org.bench4q.share.models.master.statistics.ScriptBriefResultModel;
|
||||
|
||||
@Entity
|
||||
@Table(name = "TestPlanScriptResult")
|
||||
public class TestPlanScriptResult {
|
||||
private int id;
|
||||
private TestPlanScript testPlanScript;
|
||||
private String resultContent;
|
||||
private String resultType;
|
||||
private Date createDatetime;
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
@Column(name = "id", nullable = false)
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
@ManyToOne
|
||||
@JoinColumn(name = "testPlanScriptId", nullable = false)
|
||||
public TestPlanScript getTestPlanScript() {
|
||||
return testPlanScript;
|
||||
}
|
||||
|
||||
public void setTestPlanScript(TestPlanScript testPlanScript) {
|
||||
this.testPlanScript = testPlanScript;
|
||||
}
|
||||
|
||||
@Column(name = "resultContent", columnDefinition = "LONGTEXT", nullable = false)
|
||||
public String getResultContent() {
|
||||
return resultContent;
|
||||
}
|
||||
|
||||
public void setResultContent(String scriptBriefResultContent) {
|
||||
this.resultContent = scriptBriefResultContent;
|
||||
}
|
||||
|
||||
@Column(name = "resultType", columnDefinition = "TEXT", nullable = false)
|
||||
public String getResultType() {
|
||||
return resultType;
|
||||
}
|
||||
|
||||
public void setResultType(String resultType) {
|
||||
this.resultType = resultType;
|
||||
}
|
||||
|
||||
@Column(name = "createDatetime", nullable = false)
|
||||
public Date getCreateDatetime() {
|
||||
return createDatetime;
|
||||
}
|
||||
|
||||
public void setCreateDatetime(Date createDatetime) {
|
||||
this.createDatetime = createDatetime;
|
||||
}
|
||||
|
||||
public ScriptBriefResultModel extractScriptBriefResultModel() {
|
||||
try {
|
||||
return (ScriptBriefResultModel) MarshalHelper.unmarshal(
|
||||
ScriptBriefResultModel.class, this.getResultContent());
|
||||
} catch (JAXBException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,56 +1,56 @@
|
|||
package org.bench4q.master.entity;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.GenerationType;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Table;
|
||||
|
||||
@Entity
|
||||
@Table(name = "user")
|
||||
public class User {
|
||||
private int id;
|
||||
private String userName;
|
||||
private String password;
|
||||
private byte scope;
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
@Column(name = "id", nullable = false)
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
@Column(name = "userName", nullable = false)
|
||||
public String getUserName() {
|
||||
return userName;
|
||||
}
|
||||
|
||||
public void setUserName(String userName) {
|
||||
this.userName = userName;
|
||||
}
|
||||
|
||||
@Column(name = "password", nullable = false)
|
||||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
|
||||
public void setPassword(String password) {
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
@Column(name = "scope", nullable = false)
|
||||
public byte getScope() {
|
||||
return scope;
|
||||
}
|
||||
|
||||
public void setScope(byte scope) {
|
||||
this.scope = scope;
|
||||
}
|
||||
|
||||
}
|
||||
package org.bench4q.master.domain.entity;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.GenerationType;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Table;
|
||||
|
||||
@Entity
|
||||
@Table(name = "user")
|
||||
public class User {
|
||||
private int id;
|
||||
private String userName;
|
||||
private String password;
|
||||
private byte scope;
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
@Column(name = "id", nullable = false)
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
@Column(name = "userName", nullable = false)
|
||||
public String getUserName() {
|
||||
return userName;
|
||||
}
|
||||
|
||||
public void setUserName(String userName) {
|
||||
this.userName = userName;
|
||||
}
|
||||
|
||||
@Column(name = "password", nullable = false)
|
||||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
|
||||
public void setPassword(String password) {
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
@Column(name = "scope", nullable = false)
|
||||
public byte getScope() {
|
||||
return scope;
|
||||
}
|
||||
|
||||
public void setScope(byte scope) {
|
||||
this.scope = scope;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,15 +1,15 @@
|
|||
package org.bench4q.master.factory;
|
||||
package org.bench4q.master.domain.factory;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bench4q.master.entity.PlanedConfig;
|
||||
import org.bench4q.master.entity.TestPlanDB;
|
||||
import org.bench4q.master.entity.TestPlanScript;
|
||||
import org.bench4q.master.entity.User;
|
||||
import org.bench4q.master.service.infrastructure.ScriptService;
|
||||
import org.bench4q.master.domain.entity.PlanedConfig;
|
||||
import org.bench4q.master.domain.entity.TestPlanDB;
|
||||
import org.bench4q.master.domain.entity.TestPlanScript;
|
||||
import org.bench4q.master.domain.entity.User;
|
||||
import org.bench4q.master.domain.service.ScriptService;
|
||||
import org.bench4q.share.enums.master.TestPlanStatus;
|
||||
import org.bench4q.share.models.master.RunningScriptModel;
|
||||
import org.bench4q.share.models.master.TestPlanBusinessModel;
|
|
@ -1,6 +1,6 @@
|
|||
package org.bench4q.master.factory;
|
||||
package org.bench4q.master.domain.factory;
|
||||
|
||||
import org.bench4q.master.entity.User;
|
||||
import org.bench4q.master.domain.entity.User;
|
||||
import org.bench4q.master.helper.HashHelper;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
|
@ -1,4 +1,4 @@
|
|||
package org.bench4q.master.repository;
|
||||
package org.bench4q.master.domain.repository;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.bench4q.master.helper.SessionHelper;
|
|
@ -1,11 +1,11 @@
|
|||
package org.bench4q.master.repository;
|
||||
package org.bench4q.master.domain.repository;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.bench4q.master.entity.TestPlanDB;
|
||||
import org.bench4q.master.entity.User;
|
||||
import org.bench4q.master.domain.entity.TestPlanDB;
|
||||
import org.bench4q.master.domain.entity.User;
|
||||
import org.bench4q.master.exception.ExceptionLog;
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.Transaction;
|
|
@ -1,6 +1,6 @@
|
|||
package org.bench4q.master.repository;
|
||||
package org.bench4q.master.domain.repository;
|
||||
|
||||
import org.bench4q.master.entity.User;
|
||||
import org.bench4q.master.domain.entity.User;
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.Transaction;
|
||||
import org.hibernate.criterion.Restrictions;
|
|
@ -1,244 +1,244 @@
|
|||
package org.bench4q.master.service.infrastructure;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.bench4q.master.entity.Agent;
|
||||
import org.bench4q.master.helper.SessionHelper;
|
||||
import org.bench4q.master.testplan.highavailable.HighAvailablePool;
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.Transaction;
|
||||
import org.hibernate.criterion.Order;
|
||||
import org.hibernate.criterion.Restrictions;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class AgentService {
|
||||
public static int AGENT_STATUS_Idel = 1;
|
||||
public static int AGENT_STATUS_InRun = 2;
|
||||
public static int AGENT_STATUS_BackUp = 3;
|
||||
public static int AGENT_STATUS_BreakDown = 4;
|
||||
private SessionHelper sessionHelper;
|
||||
private Object AGENT_LOCK;
|
||||
private HighAvailablePool highAvailablePool;
|
||||
private static Logger logger = Logger.getLogger(AgentService.class);
|
||||
|
||||
public AgentService() {
|
||||
this.setAgentLock(new Object());
|
||||
}
|
||||
|
||||
private SessionHelper getSessionHelper() {
|
||||
return sessionHelper;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
private void setSessionHelper(SessionHelper sessionHelper) {
|
||||
this.sessionHelper = sessionHelper;
|
||||
}
|
||||
|
||||
private HighAvailablePool getHighAvailablePool() {
|
||||
return highAvailablePool;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
private void setHighAvailablePool(HighAvailablePool highAvailablePool) {
|
||||
this.highAvailablePool = highAvailablePool;
|
||||
}
|
||||
|
||||
public Object getAgentLock() {
|
||||
return AGENT_LOCK;
|
||||
}
|
||||
|
||||
public void setAgentLock(Object object) {
|
||||
this.AGENT_LOCK = object;
|
||||
}
|
||||
|
||||
public boolean addAgentToPool(Agent agentInParam) {
|
||||
Session session = this.getSessionHelper().openSession();
|
||||
Transaction transaction = session.beginTransaction();
|
||||
try {
|
||||
Agent agent = (Agent) session
|
||||
.createCriteria(Agent.class)
|
||||
.add(Restrictions.eq("hostName", agentInParam.getHostName()))
|
||||
.uniqueResult();
|
||||
if (agent != null) {
|
||||
return false;
|
||||
}
|
||||
agent = new Agent();
|
||||
agent.setHostName(agentInParam.getHostName());
|
||||
agent.setMaxLoad(agentInParam.getMaxLoad());
|
||||
agent.setPort(agentInParam.getPort());
|
||||
agent.setRemainLoad(agentInParam.getRemainLoad());
|
||||
agent.setCurrentStatus(AGENT_STATUS_Idel);
|
||||
session.merge(agent);
|
||||
transaction.commit();
|
||||
this.getHighAvailablePool().getPool()
|
||||
.put(agent.getHostName(), agent);
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
transaction.rollback();
|
||||
return false;
|
||||
} finally {
|
||||
if (session != null) {
|
||||
session.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean removeAgentFromPool(int agentId) {
|
||||
Session session = this.getSessionHelper().openSession();
|
||||
Transaction transaction = session.beginTransaction();
|
||||
try {
|
||||
Agent agent = (Agent) session.createCriteria(Agent.class)
|
||||
.add(Restrictions.eq("id", agentId)).uniqueResult();
|
||||
if (agent == null) {
|
||||
return false;
|
||||
}
|
||||
session.delete(agent);
|
||||
transaction.commit();
|
||||
this.getHighAvailablePool().getPool().remove(agent.getHostName());
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
transaction.rollback();
|
||||
return false;
|
||||
} finally {
|
||||
if (session != null) {
|
||||
session.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean recomputeRemainLoadOfAgent(Agent agent) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public List<Agent> loadAgentPoolFromDB() {
|
||||
return this.getAgentList();
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private List<Agent> getAgentList() {
|
||||
List<Agent> agentList = new ArrayList<Agent>();
|
||||
Session session = this.getSessionHelper().openSession();
|
||||
try {
|
||||
agentList = session.createCriteria(Agent.class)
|
||||
.addOrder(Order.desc("remainLoad")).list();
|
||||
return agentList;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return agentList;
|
||||
} finally {
|
||||
if (session != null) {
|
||||
session.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean backLoadToAgent(String hostName, int backLoad) {
|
||||
Session session = this.getSessionHelper().openSession();
|
||||
Transaction transaction = session.beginTransaction();
|
||||
try {
|
||||
Agent agent = (Agent) session.createCriteria(Agent.class)
|
||||
.add(Restrictions.eq("hostName", hostName)).uniqueResult();
|
||||
if (agent == null) {
|
||||
return false;
|
||||
}
|
||||
agent.setRemainLoad(agent.getRemainLoad() + backLoad);
|
||||
session.merge(agent);
|
||||
transaction.commit();
|
||||
logger.info("The agent with hostname " + agent.getHostName()
|
||||
+ " remainload is " + agent.getRemainLoad());
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
transaction.rollback();
|
||||
return false;
|
||||
} finally {
|
||||
if (session != null) {
|
||||
session.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean getLoadFromAgent(String hostName, int requireLoad) {
|
||||
Session session = this.getSessionHelper().openSession();
|
||||
Transaction transaction = session.beginTransaction();
|
||||
try {
|
||||
Agent agent = (Agent) session.createCriteria(Agent.class)
|
||||
.add(Restrictions.eq("hostName", hostName)).uniqueResult();
|
||||
if (agent == null) {
|
||||
return false;
|
||||
}
|
||||
agent.setRemainLoad(agent.getRemainLoad() - requireLoad);
|
||||
session.merge(agent);
|
||||
transaction.commit();
|
||||
logger.info("agent with hostname " + agent.getHostName()
|
||||
+ "remain load is " + agent.getRemainLoad());
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
transaction.rollback();
|
||||
return false;
|
||||
} finally {
|
||||
if (session != null) {
|
||||
session.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean resetAgent(Agent agentInParam) {
|
||||
Session session = this.getSessionHelper().openSession();
|
||||
Transaction transaction = session.beginTransaction();
|
||||
try {
|
||||
Agent agentFromDB = (Agent) session
|
||||
.createCriteria(Agent.class)
|
||||
.add(Restrictions.eq("hostName", agentInParam.getHostName()))
|
||||
.uniqueResult();
|
||||
if (agentFromDB == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
agentFromDB.setRemainLoad(agentFromDB.getMaxLoad());
|
||||
session.merge(agentFromDB);
|
||||
logger.info("agent with hostname " + agentFromDB.getHostName()
|
||||
+ "remain load is " + agentFromDB.getRemainLoad());
|
||||
transaction.commit();
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
transaction.rollback();
|
||||
return false;
|
||||
} finally {
|
||||
if (session != null) {
|
||||
session.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean updateAgentStatus(int currentStatus, String hostName) {
|
||||
Session session = this.getSessionHelper().openSession();
|
||||
Transaction transaction = session.beginTransaction();
|
||||
try {
|
||||
Agent agentFromDB = (Agent) session.createCriteria(Agent.class)
|
||||
.add(Restrictions.eq("hostName", hostName)).uniqueResult();
|
||||
if (agentFromDB == null) {
|
||||
return false;
|
||||
}
|
||||
agentFromDB.setCurrentStatus(currentStatus);
|
||||
session.merge(agentFromDB);
|
||||
transaction.commit();
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
transaction.rollback();
|
||||
return false;
|
||||
} finally {
|
||||
if (session != null) {
|
||||
session.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
package org.bench4q.master.domain.service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.bench4q.master.domain.entity.Agent;
|
||||
import org.bench4q.master.helper.SessionHelper;
|
||||
import org.bench4q.master.testplan.highavailable.HighAvailablePool;
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.Transaction;
|
||||
import org.hibernate.criterion.Order;
|
||||
import org.hibernate.criterion.Restrictions;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class AgentService {
|
||||
public static int AGENT_STATUS_Idel = 1;
|
||||
public static int AGENT_STATUS_InRun = 2;
|
||||
public static int AGENT_STATUS_BackUp = 3;
|
||||
public static int AGENT_STATUS_BreakDown = 4;
|
||||
private SessionHelper sessionHelper;
|
||||
private Object AGENT_LOCK;
|
||||
private HighAvailablePool highAvailablePool;
|
||||
private static Logger logger = Logger.getLogger(AgentService.class);
|
||||
|
||||
public AgentService() {
|
||||
this.setAgentLock(new Object());
|
||||
}
|
||||
|
||||
private SessionHelper getSessionHelper() {
|
||||
return sessionHelper;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
private void setSessionHelper(SessionHelper sessionHelper) {
|
||||
this.sessionHelper = sessionHelper;
|
||||
}
|
||||
|
||||
private HighAvailablePool getHighAvailablePool() {
|
||||
return highAvailablePool;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
private void setHighAvailablePool(HighAvailablePool highAvailablePool) {
|
||||
this.highAvailablePool = highAvailablePool;
|
||||
}
|
||||
|
||||
public Object getAgentLock() {
|
||||
return AGENT_LOCK;
|
||||
}
|
||||
|
||||
public void setAgentLock(Object object) {
|
||||
this.AGENT_LOCK = object;
|
||||
}
|
||||
|
||||
public boolean addAgentToPool(Agent agentInParam) {
|
||||
Session session = this.getSessionHelper().openSession();
|
||||
Transaction transaction = session.beginTransaction();
|
||||
try {
|
||||
Agent agent = (Agent) session
|
||||
.createCriteria(Agent.class)
|
||||
.add(Restrictions.eq("hostName", agentInParam.getHostName()))
|
||||
.uniqueResult();
|
||||
if (agent != null) {
|
||||
return false;
|
||||
}
|
||||
agent = new Agent();
|
||||
agent.setHostName(agentInParam.getHostName());
|
||||
agent.setMaxLoad(agentInParam.getMaxLoad());
|
||||
agent.setPort(agentInParam.getPort());
|
||||
agent.setRemainLoad(agentInParam.getRemainLoad());
|
||||
agent.setCurrentStatus(AGENT_STATUS_Idel);
|
||||
session.merge(agent);
|
||||
transaction.commit();
|
||||
this.getHighAvailablePool().getPool()
|
||||
.put(agent.getHostName(), agent);
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
transaction.rollback();
|
||||
return false;
|
||||
} finally {
|
||||
if (session != null) {
|
||||
session.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean removeAgentFromPool(int agentId) {
|
||||
Session session = this.getSessionHelper().openSession();
|
||||
Transaction transaction = session.beginTransaction();
|
||||
try {
|
||||
Agent agent = (Agent) session.createCriteria(Agent.class)
|
||||
.add(Restrictions.eq("id", agentId)).uniqueResult();
|
||||
if (agent == null) {
|
||||
return false;
|
||||
}
|
||||
session.delete(agent);
|
||||
transaction.commit();
|
||||
this.getHighAvailablePool().getPool().remove(agent.getHostName());
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
transaction.rollback();
|
||||
return false;
|
||||
} finally {
|
||||
if (session != null) {
|
||||
session.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean recomputeRemainLoadOfAgent(Agent agent) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public List<Agent> loadAgentPoolFromDB() {
|
||||
return this.getAgentList();
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private List<Agent> getAgentList() {
|
||||
List<Agent> agentList = new ArrayList<Agent>();
|
||||
Session session = this.getSessionHelper().openSession();
|
||||
try {
|
||||
agentList = session.createCriteria(Agent.class)
|
||||
.addOrder(Order.desc("remainLoad")).list();
|
||||
return agentList;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return agentList;
|
||||
} finally {
|
||||
if (session != null) {
|
||||
session.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean backLoadToAgent(String hostName, int backLoad) {
|
||||
Session session = this.getSessionHelper().openSession();
|
||||
Transaction transaction = session.beginTransaction();
|
||||
try {
|
||||
Agent agent = (Agent) session.createCriteria(Agent.class)
|
||||
.add(Restrictions.eq("hostName", hostName)).uniqueResult();
|
||||
if (agent == null) {
|
||||
return false;
|
||||
}
|
||||
agent.setRemainLoad(agent.getRemainLoad() + backLoad);
|
||||
session.merge(agent);
|
||||
transaction.commit();
|
||||
logger.info("The agent with hostname " + agent.getHostName()
|
||||
+ " remainload is " + agent.getRemainLoad());
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
transaction.rollback();
|
||||
return false;
|
||||
} finally {
|
||||
if (session != null) {
|
||||
session.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean getLoadFromAgent(String hostName, int requireLoad) {
|
||||
Session session = this.getSessionHelper().openSession();
|
||||
Transaction transaction = session.beginTransaction();
|
||||
try {
|
||||
Agent agent = (Agent) session.createCriteria(Agent.class)
|
||||
.add(Restrictions.eq("hostName", hostName)).uniqueResult();
|
||||
if (agent == null) {
|
||||
return false;
|
||||
}
|
||||
agent.setRemainLoad(agent.getRemainLoad() - requireLoad);
|
||||
session.merge(agent);
|
||||
transaction.commit();
|
||||
logger.info("agent with hostname " + agent.getHostName()
|
||||
+ "remain load is " + agent.getRemainLoad());
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
transaction.rollback();
|
||||
return false;
|
||||
} finally {
|
||||
if (session != null) {
|
||||
session.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean resetAgent(Agent agentInParam) {
|
||||
Session session = this.getSessionHelper().openSession();
|
||||
Transaction transaction = session.beginTransaction();
|
||||
try {
|
||||
Agent agentFromDB = (Agent) session
|
||||
.createCriteria(Agent.class)
|
||||
.add(Restrictions.eq("hostName", agentInParam.getHostName()))
|
||||
.uniqueResult();
|
||||
if (agentFromDB == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
agentFromDB.setRemainLoad(agentFromDB.getMaxLoad());
|
||||
session.merge(agentFromDB);
|
||||
logger.info("agent with hostname " + agentFromDB.getHostName()
|
||||
+ "remain load is " + agentFromDB.getRemainLoad());
|
||||
transaction.commit();
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
transaction.rollback();
|
||||
return false;
|
||||
} finally {
|
||||
if (session != null) {
|
||||
session.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean updateAgentStatus(int currentStatus, String hostName) {
|
||||
Session session = this.getSessionHelper().openSession();
|
||||
Transaction transaction = session.beginTransaction();
|
||||
try {
|
||||
Agent agentFromDB = (Agent) session.createCriteria(Agent.class)
|
||||
.add(Restrictions.eq("hostName", hostName)).uniqueResult();
|
||||
if (agentFromDB == null) {
|
||||
return false;
|
||||
}
|
||||
agentFromDB.setCurrentStatus(currentStatus);
|
||||
session.merge(agentFromDB);
|
||||
transaction.commit();
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
transaction.rollback();
|
||||
return false;
|
||||
} finally {
|
||||
if (session != null) {
|
||||
session.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,16 +1,16 @@
|
|||
package org.bench4q.master.service.infrastructure;
|
||||
package org.bench4q.master.domain.service;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.bench4q.master.entity.MonitorResult;
|
||||
import org.bench4q.master.entity.TestPlanDB;
|
||||
import org.bench4q.master.domain.entity.MonitorResult;
|
||||
import org.bench4q.master.domain.entity.TestPlanDB;
|
||||
import org.bench4q.master.domain.repository.TestPlanRepository;
|
||||
import org.bench4q.master.exception.ExceptionLog;
|
||||
import org.bench4q.master.helper.SessionHelper;
|
||||
import org.bench4q.master.repository.TestPlanRepository;
|
||||
import org.bench4q.master.service.communication.MonitorService;
|
||||
import org.bench4q.master.infrastructure.communication.MonitorMessenger;
|
||||
import org.bench4q.share.helper.MarshalHelper;
|
||||
import org.bench4q.share.models.master.MonitorLogicalDiskResponseModel;
|
||||
import org.bench4q.share.models.master.MonitorMemoryResponseModel;
|
||||
|
@ -33,7 +33,7 @@ import org.springframework.stereotype.Component;
|
|||
public class MonitorResultService {
|
||||
private TestPlanService testPlanService;
|
||||
private TestPlanRepository testPlanRepository;
|
||||
private MonitorService monitorService;
|
||||
private MonitorMessenger monitorService;
|
||||
private SessionHelper sessionHelper;
|
||||
private static Logger logger = Logger.getLogger(MonitorResult.class);
|
||||
|
||||
|
@ -64,12 +64,12 @@ public class MonitorResultService {
|
|||
this.sessionHelper = sessionHelper;
|
||||
}
|
||||
|
||||
private MonitorService getMonitorService() {
|
||||
private MonitorMessenger getMonitorService() {
|
||||
return monitorService;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
private void setMonitorService(MonitorService monitorService) {
|
||||
private void setMonitorService(MonitorMessenger monitorService) {
|
||||
this.monitorService = monitorService;
|
||||
}
|
||||
|
|
@ -1,171 +1,171 @@
|
|||
package org.bench4q.master.service.infrastructure;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.bench4q.master.entity.Port;
|
||||
import org.bench4q.master.helper.SessionHelper;
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.Transaction;
|
||||
import org.hibernate.criterion.Restrictions;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class PortPoolService {
|
||||
|
||||
private SessionHelper sessionHelper = new SessionHelper();
|
||||
private Logger logger = Logger.getLogger(PortPoolService.class);
|
||||
|
||||
public SessionHelper getSessionHelper() {
|
||||
return sessionHelper;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
public void setSessionHelper(SessionHelper sessionHelper) {
|
||||
this.sessionHelper = sessionHelper;
|
||||
}
|
||||
|
||||
public boolean addPortToDBPool(int port) {
|
||||
Session session = this.getSessionHelper().openSession();
|
||||
Transaction transaction = session.beginTransaction();
|
||||
try {
|
||||
Port portDB = (Port) session.createCriteria(Port.class)
|
||||
.add(Restrictions.eq("port", port)).uniqueResult();
|
||||
if (portDB != null) {
|
||||
return false;
|
||||
}
|
||||
portDB = new Port();
|
||||
portDB.setPort(port);
|
||||
session.merge(portDB);
|
||||
transaction.commit();
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
transaction.rollback();
|
||||
return false;
|
||||
} finally {
|
||||
if (session != null) {
|
||||
session.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean removePortFromDBPool(int id) {
|
||||
Session session = this.getSessionHelper().openSession();
|
||||
Transaction transaction = session.beginTransaction();
|
||||
try {
|
||||
Port portDB = (Port) session.createCriteria(Port.class)
|
||||
.add(Restrictions.eq("id", id)).uniqueResult();
|
||||
if (portDB == null) {
|
||||
this.logger
|
||||
.error("Port to delete don't exist where the portId is "
|
||||
+ id);
|
||||
return false;
|
||||
}
|
||||
session.delete(portDB);
|
||||
transaction.commit();
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
transaction.rollback();
|
||||
return false;
|
||||
} finally {
|
||||
if (session != null) {
|
||||
session.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public Port getAPortNotInUse() {
|
||||
// If i do the HA in the pool, shall i lock this change for this port
|
||||
Session session = this.getSessionHelper().openSession();
|
||||
Transaction transaction = session.beginTransaction();
|
||||
Port port = null;
|
||||
try {
|
||||
List<Port> portList = (List<Port>) session
|
||||
.createCriteria(Port.class)
|
||||
.add(Restrictions.eq("inUse", false)).list();
|
||||
|
||||
if (portList.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
port = portList.get(0);
|
||||
port.setInUse(true);
|
||||
transaction.commit();
|
||||
return port;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
transaction.rollback();
|
||||
return null;
|
||||
} finally {
|
||||
if (session != null) {
|
||||
session.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean backPort(int port) {
|
||||
Session session = this.getSessionHelper().openSession();
|
||||
Transaction transaction = session.beginTransaction();
|
||||
try {
|
||||
System.out.println("back the port " + port + " to DB!");
|
||||
Port portEntity = (Port) session.createCriteria(Port.class)
|
||||
.add(Restrictions.eq("port", port)).uniqueResult();
|
||||
if (portEntity == null || !portEntity.isInUse()) {
|
||||
return false;
|
||||
}
|
||||
portEntity.setInUse(false);
|
||||
transaction.commit();
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
transaction.rollback();
|
||||
return false;
|
||||
} finally {
|
||||
if (session != null) {
|
||||
session.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public List<Port> loadPortList() {
|
||||
Session session = this.getSessionHelper().openSession();
|
||||
try {
|
||||
List<Port> ports = session.createCriteria(Port.class).list();
|
||||
return ports;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
} finally {
|
||||
if (session != null) {
|
||||
session.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean editPort(Port portInParam) {
|
||||
Session session = this.getSessionHelper().openSession();
|
||||
Transaction transaction = session.beginTransaction();
|
||||
try {
|
||||
Port portInDB = (Port) session.createCriteria(Port.class)
|
||||
.add(Restrictions.eq("port", portInParam.getPort()))
|
||||
.uniqueResult();
|
||||
portInDB.setInUse(portInParam.isInUse());
|
||||
transaction.commit();
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
transaction.rollback();
|
||||
return false;
|
||||
} finally {
|
||||
if (session != null) {
|
||||
session.close();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
package org.bench4q.master.domain.service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.bench4q.master.domain.entity.Port;
|
||||
import org.bench4q.master.helper.SessionHelper;
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.Transaction;
|
||||
import org.hibernate.criterion.Restrictions;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class PortPoolService {
|
||||
|
||||
private SessionHelper sessionHelper = new SessionHelper();
|
||||
private Logger logger = Logger.getLogger(PortPoolService.class);
|
||||
|
||||
public SessionHelper getSessionHelper() {
|
||||
return sessionHelper;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
public void setSessionHelper(SessionHelper sessionHelper) {
|
||||
this.sessionHelper = sessionHelper;
|
||||
}
|
||||
|
||||
public boolean addPortToDBPool(int port) {
|
||||
Session session = this.getSessionHelper().openSession();
|
||||
Transaction transaction = session.beginTransaction();
|
||||
try {
|
||||
Port portDB = (Port) session.createCriteria(Port.class)
|
||||
.add(Restrictions.eq("port", port)).uniqueResult();
|
||||
if (portDB != null) {
|
||||
return false;
|
||||
}
|
||||
portDB = new Port();
|
||||
portDB.setPort(port);
|
||||
session.merge(portDB);
|
||||
transaction.commit();
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
transaction.rollback();
|
||||
return false;
|
||||
} finally {
|
||||
if (session != null) {
|
||||
session.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean removePortFromDBPool(int id) {
|
||||
Session session = this.getSessionHelper().openSession();
|
||||
Transaction transaction = session.beginTransaction();
|
||||
try {
|
||||
Port portDB = (Port) session.createCriteria(Port.class)
|
||||
.add(Restrictions.eq("id", id)).uniqueResult();
|
||||
if (portDB == null) {
|
||||
this.logger
|
||||
.error("Port to delete don't exist where the portId is "
|
||||
+ id);
|
||||
return false;
|
||||
}
|
||||
session.delete(portDB);
|
||||
transaction.commit();
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
transaction.rollback();
|
||||
return false;
|
||||
} finally {
|
||||
if (session != null) {
|
||||
session.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public Port getAPortNotInUse() {
|
||||
// If i do the HA in the pool, shall i lock this change for this port
|
||||
Session session = this.getSessionHelper().openSession();
|
||||
Transaction transaction = session.beginTransaction();
|
||||
Port port = null;
|
||||
try {
|
||||
List<Port> portList = (List<Port>) session
|
||||
.createCriteria(Port.class)
|
||||
.add(Restrictions.eq("inUse", false)).list();
|
||||
|
||||
if (portList.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
port = portList.get(0);
|
||||
port.setInUse(true);
|
||||
transaction.commit();
|
||||
return port;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
transaction.rollback();
|
||||
return null;
|
||||
} finally {
|
||||
if (session != null) {
|
||||
session.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean backPort(int port) {
|
||||
Session session = this.getSessionHelper().openSession();
|
||||
Transaction transaction = session.beginTransaction();
|
||||
try {
|
||||
System.out.println("back the port " + port + " to DB!");
|
||||
Port portEntity = (Port) session.createCriteria(Port.class)
|
||||
.add(Restrictions.eq("port", port)).uniqueResult();
|
||||
if (portEntity == null || !portEntity.isInUse()) {
|
||||
return false;
|
||||
}
|
||||
portEntity.setInUse(false);
|
||||
transaction.commit();
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
transaction.rollback();
|
||||
return false;
|
||||
} finally {
|
||||
if (session != null) {
|
||||
session.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public List<Port> loadPortList() {
|
||||
Session session = this.getSessionHelper().openSession();
|
||||
try {
|
||||
List<Port> ports = session.createCriteria(Port.class).list();
|
||||
return ports;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
} finally {
|
||||
if (session != null) {
|
||||
session.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean editPort(Port portInParam) {
|
||||
Session session = this.getSessionHelper().openSession();
|
||||
Transaction transaction = session.beginTransaction();
|
||||
try {
|
||||
Port portInDB = (Port) session.createCriteria(Port.class)
|
||||
.add(Restrictions.eq("port", portInParam.getPort()))
|
||||
.uniqueResult();
|
||||
portInDB.setInUse(portInParam.isInUse());
|
||||
transaction.commit();
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
transaction.rollback();
|
||||
return false;
|
||||
} finally {
|
||||
if (session != null) {
|
||||
session.close();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -1,244 +1,244 @@
|
|||
package org.bench4q.master.service.infrastructure;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import javax.xml.bind.JAXBException;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.bench4q.master.entity.Script;
|
||||
import org.bench4q.master.entity.User;
|
||||
import org.bench4q.master.exception.ExceptionLog;
|
||||
import org.bench4q.master.helper.SessionHelper;
|
||||
import org.bench4q.share.helper.MarshalHelper;
|
||||
import org.bench4q.share.models.agent.RunScenarioModel;
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.Transaction;
|
||||
import org.hibernate.criterion.Restrictions;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class ScriptService {
|
||||
private SessionHelper sessionHelper = new SessionHelper();
|
||||
private UserService userService;
|
||||
private Logger logger = Logger.getLogger(ScriptService.class);
|
||||
|
||||
private SessionHelper getSessionHelper() {
|
||||
return sessionHelper;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
private void setSessionHelper(SessionHelper sessionHelper) {
|
||||
this.sessionHelper = sessionHelper;
|
||||
}
|
||||
|
||||
private UserService getUserService() {
|
||||
return userService;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
private void setUserService(UserService userService) {
|
||||
this.userService = userService;
|
||||
}
|
||||
|
||||
public Script saveScript(String scriptName, int userId, String scriptContent) {
|
||||
Session session = this.getSessionHelper().openSession();
|
||||
Transaction transaction = session.beginTransaction();
|
||||
try {
|
||||
User user = this.getUserService().getUserById(userId);
|
||||
Script script = new Script();
|
||||
script.setName(scriptName);
|
||||
script.setUser(user);
|
||||
script.setCreateDateTime((new Date()));
|
||||
script.setScriptContent(scriptContent);
|
||||
script.setBehaviorCount(getScriptBehaviorsCount(scriptContent));
|
||||
Script ret = (Script) session.merge(script);
|
||||
transaction.commit();
|
||||
return ret;
|
||||
} catch (Exception e) {
|
||||
logger.info("Exception when save script to DB" + scriptContent
|
||||
+ " : " + ExceptionLog.getStackTrace(e));
|
||||
transaction.rollback();
|
||||
return null;
|
||||
} finally {
|
||||
if (session != null) {
|
||||
session.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Script getScript(int scriptId) {
|
||||
Session session = this.sessionHelper.openSession();
|
||||
try {
|
||||
return doGetScript(scriptId, session);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
logger.error("There is an exception when getScript with id = "
|
||||
+ scriptId);
|
||||
return null;
|
||||
} finally {
|
||||
if (session != null)
|
||||
session.close();
|
||||
}
|
||||
}
|
||||
|
||||
public Script doGetScript(int scriptId, Session session) {
|
||||
return (Script) session.createCriteria(Script.class)
|
||||
.add(Restrictions.eq("id", scriptId)).uniqueResult();
|
||||
}
|
||||
|
||||
private int getScriptBehaviorsCount(String scriptContent)
|
||||
throws JAXBException {
|
||||
int temp = 0;
|
||||
// TODO:restore these lines
|
||||
// List<Object> behaviors = ((RunScenarioModel) MarshalHelper.unmarshal(
|
||||
// RunScenarioModel.class, scriptContent)).getBehaviors();
|
||||
// if (behaviors == null) {
|
||||
// temp = 0;
|
||||
// } else {
|
||||
// temp = behaviors.size();
|
||||
// }
|
||||
return temp;
|
||||
}
|
||||
|
||||
public int getScriptBehaviorCount(int scriptId) {
|
||||
Session session = this.getSessionHelper().openSession();
|
||||
try {
|
||||
Script script = (Script) session.createCriteria(Script.class)
|
||||
.add(Restrictions.eq("scriptId", scriptId)).uniqueResult();
|
||||
if (script == null) {
|
||||
return -1;
|
||||
}
|
||||
return script.getId();
|
||||
} catch (Exception e) {
|
||||
return -1;
|
||||
} finally {
|
||||
if (session != null) {
|
||||
session.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public List<Script> loadScripts(User user) {
|
||||
Session session = this.getSessionHelper().openSession();
|
||||
try {
|
||||
@SuppressWarnings("unchecked")
|
||||
List<Script> scripts = session.createCriteria(Script.class)
|
||||
.add(Restrictions.eq("user", user)).list();
|
||||
if (scripts == null) {
|
||||
return null;
|
||||
}
|
||||
return scripts;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
} finally {
|
||||
if (session != null) {
|
||||
session.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public List<Script> queryScriptsByCreateTime(Date startDate, Date endDate) {
|
||||
Session session = this.getSessionHelper().openSession();
|
||||
try {
|
||||
@SuppressWarnings("unchecked")
|
||||
List<Script> scripts = session
|
||||
.createCriteria(Script.class)
|
||||
.add(Restrictions.between("createDateTime", startDate,
|
||||
endDate)).list();
|
||||
if (scripts == null) {
|
||||
return null;
|
||||
}
|
||||
return scripts;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
} finally {
|
||||
if (session != null) {
|
||||
session.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public RunScenarioModel getRunSceniroModelByScriptId(int scriptId) {
|
||||
String content = this.getScriptContentByScriptId(scriptId);
|
||||
if (content == null) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
return (RunScenarioModel) MarshalHelper.unmarshal(
|
||||
RunScenarioModel.class, content);
|
||||
} catch (JAXBException e) {
|
||||
logger.error(ExceptionLog.getStackTrace(e));
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public String getScriptContentByScriptId(int scriptId) {
|
||||
Session session = this.getSessionHelper().openSession();
|
||||
try {
|
||||
Script script = (Script) session.createCriteria(Script.class)
|
||||
.add(Restrictions.eq("id", scriptId)).uniqueResult();
|
||||
if (script == null) {
|
||||
return null;
|
||||
}
|
||||
return script.getScriptContent();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
} finally {
|
||||
if (session != null) {
|
||||
session.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean deleteScript(int id) {
|
||||
Session session = this.getSessionHelper().openSession();
|
||||
Transaction transaction = session.beginTransaction();
|
||||
try {
|
||||
Script script = (Script) session.createCriteria(Script.class)
|
||||
.add(Restrictions.eq("id", id)).uniqueResult();
|
||||
if (script == null) {
|
||||
return false;
|
||||
}
|
||||
session.delete(script);
|
||||
transaction.commit();
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
transaction.rollback();
|
||||
return false;
|
||||
} finally {
|
||||
if (session != null) {
|
||||
session.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean updateScript(int id, String content) {
|
||||
Session session = this.getSessionHelper().openSession();
|
||||
Transaction transaction = session.beginTransaction();
|
||||
try {
|
||||
Script script = (Script) session.createCriteria(Script.class)
|
||||
.add(Restrictions.eq("id", id)).uniqueResult();
|
||||
if (script == null) {
|
||||
return false;
|
||||
}
|
||||
script.setScriptContent(content);
|
||||
session.merge(script);
|
||||
transaction.commit();
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
transaction.rollback();
|
||||
return false;
|
||||
} finally {
|
||||
if (session != null) {
|
||||
session.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
package org.bench4q.master.domain.service;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import javax.xml.bind.JAXBException;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.bench4q.master.domain.entity.Script;
|
||||
import org.bench4q.master.domain.entity.User;
|
||||
import org.bench4q.master.exception.ExceptionLog;
|
||||
import org.bench4q.master.helper.SessionHelper;
|
||||
import org.bench4q.share.helper.MarshalHelper;
|
||||
import org.bench4q.share.models.agent.RunScenarioModel;
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.Transaction;
|
||||
import org.hibernate.criterion.Restrictions;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class ScriptService {
|
||||
private SessionHelper sessionHelper = new SessionHelper();
|
||||
private UserService userService;
|
||||
private Logger logger = Logger.getLogger(ScriptService.class);
|
||||
|
||||
private SessionHelper getSessionHelper() {
|
||||
return sessionHelper;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
private void setSessionHelper(SessionHelper sessionHelper) {
|
||||
this.sessionHelper = sessionHelper;
|
||||
}
|
||||
|
||||
private UserService getUserService() {
|
||||
return userService;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
private void setUserService(UserService userService) {
|
||||
this.userService = userService;
|
||||
}
|
||||
|
||||
public Script saveScript(String scriptName, int userId, String scriptContent) {
|
||||
Session session = this.getSessionHelper().openSession();
|
||||
Transaction transaction = session.beginTransaction();
|
||||
try {
|
||||
User user = this.getUserService().getUserById(userId);
|
||||
Script script = new Script();
|
||||
script.setName(scriptName);
|
||||
script.setUser(user);
|
||||
script.setCreateDateTime((new Date()));
|
||||
script.setScriptContent(scriptContent);
|
||||
script.setBehaviorCount(getScriptBehaviorsCount(scriptContent));
|
||||
Script ret = (Script) session.merge(script);
|
||||
transaction.commit();
|
||||
return ret;
|
||||
} catch (Exception e) {
|
||||
logger.info("Exception when save script to DB" + scriptContent
|
||||
+ " : " + ExceptionLog.getStackTrace(e));
|
||||
transaction.rollback();
|
||||
return null;
|
||||
} finally {
|
||||
if (session != null) {
|
||||
session.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Script getScript(int scriptId) {
|
||||
Session session = this.sessionHelper.openSession();
|
||||
try {
|
||||
return doGetScript(scriptId, session);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
logger.error("There is an exception when getScript with id = "
|
||||
+ scriptId);
|
||||
return null;
|
||||
} finally {
|
||||
if (session != null)
|
||||
session.close();
|
||||
}
|
||||
}
|
||||
|
||||
public Script doGetScript(int scriptId, Session session) {
|
||||
return (Script) session.createCriteria(Script.class)
|
||||
.add(Restrictions.eq("id", scriptId)).uniqueResult();
|
||||
}
|
||||
|
||||
private int getScriptBehaviorsCount(String scriptContent)
|
||||
throws JAXBException {
|
||||
int temp = 0;
|
||||
// TODO:restore these lines
|
||||
// List<Object> behaviors = ((RunScenarioModel) MarshalHelper.unmarshal(
|
||||
// RunScenarioModel.class, scriptContent)).getBehaviors();
|
||||
// if (behaviors == null) {
|
||||
// temp = 0;
|
||||
// } else {
|
||||
// temp = behaviors.size();
|
||||
// }
|
||||
return temp;
|
||||
}
|
||||
|
||||
public int getScriptBehaviorCount(int scriptId) {
|
||||
Session session = this.getSessionHelper().openSession();
|
||||
try {
|
||||
Script script = (Script) session.createCriteria(Script.class)
|
||||
.add(Restrictions.eq("scriptId", scriptId)).uniqueResult();
|
||||
if (script == null) {
|
||||
return -1;
|
||||
}
|
||||
return script.getId();
|
||||
} catch (Exception e) {
|
||||
return -1;
|
||||
} finally {
|
||||
if (session != null) {
|
||||
session.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public List<Script> loadScripts(User user) {
|
||||
Session session = this.getSessionHelper().openSession();
|
||||
try {
|
||||
@SuppressWarnings("unchecked")
|
||||
List<Script> scripts = session.createCriteria(Script.class)
|
||||
.add(Restrictions.eq("user", user)).list();
|
||||
if (scripts == null) {
|
||||
return null;
|
||||
}
|
||||
return scripts;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
} finally {
|
||||
if (session != null) {
|
||||
session.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public List<Script> queryScriptsByCreateTime(Date startDate, Date endDate) {
|
||||
Session session = this.getSessionHelper().openSession();
|
||||
try {
|
||||
@SuppressWarnings("unchecked")
|
||||
List<Script> scripts = session
|
||||
.createCriteria(Script.class)
|
||||
.add(Restrictions.between("createDateTime", startDate,
|
||||
endDate)).list();
|
||||
if (scripts == null) {
|
||||
return null;
|
||||
}
|
||||
return scripts;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
} finally {
|
||||
if (session != null) {
|
||||
session.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public RunScenarioModel getRunSceniroModelByScriptId(int scriptId) {
|
||||
String content = this.getScriptContentByScriptId(scriptId);
|
||||
if (content == null) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
return (RunScenarioModel) MarshalHelper.unmarshal(
|
||||
RunScenarioModel.class, content);
|
||||
} catch (JAXBException e) {
|
||||
logger.error(ExceptionLog.getStackTrace(e));
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public String getScriptContentByScriptId(int scriptId) {
|
||||
Session session = this.getSessionHelper().openSession();
|
||||
try {
|
||||
Script script = (Script) session.createCriteria(Script.class)
|
||||
.add(Restrictions.eq("id", scriptId)).uniqueResult();
|
||||
if (script == null) {
|
||||
return null;
|
||||
}
|
||||
return script.getScriptContent();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
} finally {
|
||||
if (session != null) {
|
||||
session.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean deleteScript(int id) {
|
||||
Session session = this.getSessionHelper().openSession();
|
||||
Transaction transaction = session.beginTransaction();
|
||||
try {
|
||||
Script script = (Script) session.createCriteria(Script.class)
|
||||
.add(Restrictions.eq("id", id)).uniqueResult();
|
||||
if (script == null) {
|
||||
return false;
|
||||
}
|
||||
session.delete(script);
|
||||
transaction.commit();
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
transaction.rollback();
|
||||
return false;
|
||||
} finally {
|
||||
if (session != null) {
|
||||
session.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean updateScript(int id, String content) {
|
||||
Session session = this.getSessionHelper().openSession();
|
||||
Transaction transaction = session.beginTransaction();
|
||||
try {
|
||||
Script script = (Script) session.createCriteria(Script.class)
|
||||
.add(Restrictions.eq("id", id)).uniqueResult();
|
||||
if (script == null) {
|
||||
return false;
|
||||
}
|
||||
script.setScriptContent(content);
|
||||
session.merge(script);
|
||||
transaction.commit();
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
transaction.rollback();
|
||||
return false;
|
||||
} finally {
|
||||
if (session != null) {
|
||||
session.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package org.bench4q.master.service.infrastructure;
|
||||
package org.bench4q.master.domain.service;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.ArrayList;
|
||||
|
@ -9,11 +9,11 @@ import java.util.UUID;
|
|||
import javax.xml.bind.JAXBException;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.bench4q.master.entity.TestPlanScript;
|
||||
import org.bench4q.master.entity.TestPlanScriptResult;
|
||||
import org.bench4q.master.domain.entity.TestPlanScript;
|
||||
import org.bench4q.master.domain.entity.TestPlanScriptResult;
|
||||
import org.bench4q.master.domain.repository.TestPlanRepository;
|
||||
import org.bench4q.master.exception.ExceptionLog;
|
||||
import org.bench4q.master.helper.SessionHelper;
|
||||
import org.bench4q.master.repository.TestPlanRepository;
|
||||
import org.bench4q.share.helper.MarshalHelper;
|
||||
import org.bench4q.share.models.master.ValueTimeModel;
|
||||
import org.bench4q.share.models.master.statistics.ScriptBehaviorsBriefModel;
|
|
@ -1,4 +1,4 @@
|
|||
package org.bench4q.master.service.infrastructure;
|
||||
package org.bench4q.master.domain.service;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Date;
|
||||
|
@ -11,13 +11,13 @@ import javax.xml.bind.JAXBException;
|
|||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.bench4q.master.domain.RunningScript;
|
||||
import org.bench4q.master.entity.Script;
|
||||
import org.bench4q.master.entity.TestPlanDB;
|
||||
import org.bench4q.master.entity.TestPlanScript;
|
||||
import org.bench4q.master.entity.TestPlanScriptResult;
|
||||
import org.bench4q.master.domain.entity.Script;
|
||||
import org.bench4q.master.domain.entity.TestPlanDB;
|
||||
import org.bench4q.master.domain.entity.TestPlanScript;
|
||||
import org.bench4q.master.domain.entity.TestPlanScriptResult;
|
||||
import org.bench4q.master.domain.repository.TestPlanRepository;
|
||||
import org.bench4q.master.exception.ExceptionLog;
|
||||
import org.bench4q.master.helper.SessionHelper;
|
||||
import org.bench4q.master.repository.TestPlanRepository;
|
||||
import org.bench4q.share.helper.MarshalHelper;
|
||||
import org.bench4q.share.models.master.statistics.ScriptBehaviorsBriefModel;
|
||||
import org.bench4q.share.models.master.statistics.ScriptBriefResultModel;
|
|
@ -1,4 +1,4 @@
|
|||
package org.bench4q.master.service.infrastructure;
|
||||
package org.bench4q.master.domain.service;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
@ -6,12 +6,12 @@ import java.util.UUID;
|
|||
import org.apache.log4j.Logger;
|
||||
import org.bench4q.master.api.modelfactory.BusinessModelMapFactory;
|
||||
import org.bench4q.master.domain.TestPlanInBusiness;
|
||||
import org.bench4q.master.entity.TestPlanDB;
|
||||
import org.bench4q.master.entity.User;
|
||||
import org.bench4q.master.domain.entity.TestPlanDB;
|
||||
import org.bench4q.master.domain.entity.User;
|
||||
import org.bench4q.master.domain.factory.TestPlanFactory;
|
||||
import org.bench4q.master.domain.repository.TestPlanRepository;
|
||||
import org.bench4q.master.exception.ExceptionLog;
|
||||
import org.bench4q.master.factory.TestPlanFactory;
|
||||
import org.bench4q.master.helper.SessionHelper;
|
||||
import org.bench4q.master.repository.TestPlanRepository;
|
||||
import org.bench4q.share.enums.master.TestPlanStatus;
|
||||
import org.bench4q.share.models.master.TestPlanDBModel;
|
||||
import org.hibernate.Session;
|
|
@ -1,8 +1,8 @@
|
|||
package org.bench4q.master.service.infrastructure;
|
||||
package org.bench4q.master.domain.service;
|
||||
|
||||
import org.bench4q.master.entity.User;
|
||||
import org.bench4q.master.factory.UserFactory;
|
||||
import org.bench4q.master.repository.UserRepository;
|
||||
import org.bench4q.master.domain.entity.User;
|
||||
import org.bench4q.master.domain.factory.UserFactory;
|
||||
import org.bench4q.master.domain.repository.UserRepository;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
|
@ -1,36 +0,0 @@
|
|||
package org.bench4q.master.entity;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.GenerationType;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Table;
|
||||
|
||||
@Entity
|
||||
@Table(name = "fortest")
|
||||
public class ForTest {
|
||||
private int id;
|
||||
private String content;
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
@Column(name = "id", nullable = false)
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
@Column(name = "content", columnDefinition = "LONGTEXT", nullable = false)
|
||||
public String getContent() {
|
||||
return content;
|
||||
}
|
||||
|
||||
public void setContent(String content) {
|
||||
this.content = content;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,25 +1,25 @@
|
|||
package org.bench4q.master.helper;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.bench4q.master.entity.EntityBase;
|
||||
|
||||
public class CollectionHelper {
|
||||
/**
|
||||
*
|
||||
* @param container
|
||||
* @param id
|
||||
* @return null if not exists
|
||||
*/
|
||||
public static <T extends EntityBase, ID> T tryGetItemById(
|
||||
List<T> container, ID id) {
|
||||
System.out.println(id.toString());
|
||||
for (T item : container) {
|
||||
if (id.toString().equals(item.extractIdentifier().toString())) {
|
||||
return item;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
package org.bench4q.master.helper;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.bench4q.master.domain.entity.EntityBase;
|
||||
|
||||
public class CollectionHelper {
|
||||
/**
|
||||
*
|
||||
* @param container
|
||||
* @param id
|
||||
* @return null if not exists
|
||||
*/
|
||||
public static <T extends EntityBase, ID> T tryGetItemById(
|
||||
List<T> container, ID id) {
|
||||
System.out.println(id.toString());
|
||||
for (T item : container) {
|
||||
if (id.toString().equals(item.extractIdentifier().toString())) {
|
||||
return item;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,55 +1,55 @@
|
|||
package org.bench4q.master.auth;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
public class AccessToken implements Serializable {
|
||||
private static final long serialVersionUID = 4134631390384650898L;
|
||||
private String userName;
|
||||
private String password;
|
||||
private byte scope;
|
||||
private Date generateTime;
|
||||
private int expiresIn;
|
||||
|
||||
|
||||
public String getUserName() {
|
||||
return userName;
|
||||
}
|
||||
|
||||
public void setUserName(String userName) {
|
||||
this.userName = userName;
|
||||
}
|
||||
|
||||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
|
||||
public void setPassword(String password) {
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
public Date getGenerateTime() {
|
||||
return generateTime;
|
||||
}
|
||||
|
||||
public void setGenerateTime(Date generateTime) {
|
||||
this.generateTime = generateTime;
|
||||
}
|
||||
|
||||
public int getExpiresIn() {
|
||||
return expiresIn;
|
||||
}
|
||||
|
||||
public void setExpiresIn(int expiresIn) {
|
||||
this.expiresIn = expiresIn;
|
||||
}
|
||||
|
||||
public byte getScope() {
|
||||
return scope;
|
||||
}
|
||||
|
||||
public void setScope(byte scope) {
|
||||
this.scope = scope;
|
||||
}
|
||||
|
||||
}
|
||||
package org.bench4q.master.helper.auth;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
public class AccessToken implements Serializable {
|
||||
private static final long serialVersionUID = 4134631390384650898L;
|
||||
private String userName;
|
||||
private String password;
|
||||
private byte scope;
|
||||
private Date generateTime;
|
||||
private int expiresIn;
|
||||
|
||||
|
||||
public String getUserName() {
|
||||
return userName;
|
||||
}
|
||||
|
||||
public void setUserName(String userName) {
|
||||
this.userName = userName;
|
||||
}
|
||||
|
||||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
|
||||
public void setPassword(String password) {
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
public Date getGenerateTime() {
|
||||
return generateTime;
|
||||
}
|
||||
|
||||
public void setGenerateTime(Date generateTime) {
|
||||
this.generateTime = generateTime;
|
||||
}
|
||||
|
||||
public int getExpiresIn() {
|
||||
return expiresIn;
|
||||
}
|
||||
|
||||
public void setExpiresIn(int expiresIn) {
|
||||
this.expiresIn = expiresIn;
|
||||
}
|
||||
|
||||
public byte getScope() {
|
||||
return scope;
|
||||
}
|
||||
|
||||
public void setScope(byte scope) {
|
||||
this.scope = scope;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,139 +1,139 @@
|
|||
package org.bench4q.master.auth;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import org.bench4q.master.entity.User;
|
||||
import org.bench4q.master.helper.StringHelper;
|
||||
import org.bench4q.master.service.infrastructure.UserService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class AuthenticationManager {
|
||||
private final int defaultExpiresTime = 3600;
|
||||
private CryptoManager cryptoManager;
|
||||
private UserService userService;
|
||||
private StringHelper stringHelper;
|
||||
|
||||
private CryptoManager getCryptoManager() {
|
||||
return cryptoManager;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
private void setCryptoManager(CryptoManager cryptoManager) {
|
||||
this.cryptoManager = cryptoManager;
|
||||
}
|
||||
|
||||
private UserService getUserService() {
|
||||
return userService;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
private void setUserService(UserService userService) {
|
||||
this.userService = userService;
|
||||
}
|
||||
|
||||
private StringHelper getStringHelper() {
|
||||
return stringHelper;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
private void setStringHelper(StringHelper stringHelper) {
|
||||
this.stringHelper = stringHelper;
|
||||
}
|
||||
|
||||
public User getPrincipal(HttpServletRequest request) {
|
||||
AccessToken accessToken = this.getAccessToken(request);
|
||||
if (accessToken == null) {
|
||||
return null;
|
||||
}
|
||||
return this.extractUser(accessToken);
|
||||
}
|
||||
|
||||
public boolean checkScope(HttpServletRequest request, byte requiredScope) {
|
||||
AccessToken accessToken = this.getAccessToken(request);
|
||||
if (accessToken == null) {
|
||||
return false;
|
||||
}
|
||||
return isScopeMeet(accessToken.getScope(), requiredScope);
|
||||
}
|
||||
|
||||
public boolean isScopeMeet(byte actualScope, byte requiredScope) {
|
||||
return actualScope >= requiredScope;
|
||||
}
|
||||
|
||||
public String generateCredential(User user) {
|
||||
AccessToken accessToken = this.generateAccessToken(user);
|
||||
return this.generateCredentialFromAccessToken(accessToken);
|
||||
}
|
||||
|
||||
private AccessToken getAccessToken(HttpServletRequest request) {
|
||||
if (request.getHeader("Authorization") == null) {
|
||||
return null;
|
||||
}
|
||||
if (!request.getHeader("Authorization").startsWith("Bearer ")) {
|
||||
return null;
|
||||
}
|
||||
String hex = request.getHeader("Authorization").substring(
|
||||
"Bearer ".length());
|
||||
byte[] bytes = this.getStringHelper().convertToBytes(hex);
|
||||
return this.extractAccessToken(bytes);
|
||||
}
|
||||
|
||||
private User extractUser(AccessToken accessToken) {
|
||||
if (accessToken == null) {
|
||||
return null;
|
||||
}
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
calendar.setTime(accessToken.getGenerateTime());
|
||||
calendar.add(Calendar.SECOND, accessToken.getExpiresIn());
|
||||
Date expireTime = calendar.getTime();
|
||||
if (expireTime.before(new Date(System.currentTimeMillis()))) {
|
||||
return null;
|
||||
}
|
||||
return this.getUserService().getUserByName(accessToken.getUserName());
|
||||
}
|
||||
|
||||
public AccessToken generateAccessToken(User user) {
|
||||
AccessToken accessToken = new AccessToken();
|
||||
accessToken.setExpiresIn(this.defaultExpiresTime);
|
||||
accessToken.setGenerateTime(new Date(System.currentTimeMillis()));
|
||||
accessToken.setPassword(user.getPassword());
|
||||
accessToken.setUserName(user.getUserName());
|
||||
accessToken.setScope(user.getScope());
|
||||
return accessToken;
|
||||
}
|
||||
|
||||
private AccessToken extractAccessToken(byte[] bytes) {
|
||||
try {
|
||||
byte[] decrypted = this.getCryptoManager().decrypt(bytes);
|
||||
ObjectInputStream inputStream = new ObjectInputStream(
|
||||
new ByteArrayInputStream(decrypted));
|
||||
return (AccessToken) inputStream.readObject();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private String generateCredentialFromAccessToken(AccessToken accessToken) {
|
||||
try {
|
||||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||
ObjectOutputStream stream = new ObjectOutputStream(outputStream);
|
||||
stream.writeObject(accessToken);
|
||||
byte[] data = outputStream.toByteArray();
|
||||
byte[] encryptedData = this.getCryptoManager().encrypt(data);
|
||||
return this.getStringHelper().convertToHexString(encryptedData);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
package org.bench4q.master.helper.auth;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import org.bench4q.master.domain.entity.User;
|
||||
import org.bench4q.master.domain.service.UserService;
|
||||
import org.bench4q.master.helper.StringHelper;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class AuthenticationManager {
|
||||
private final int defaultExpiresTime = 3600;
|
||||
private CryptoManager cryptoManager;
|
||||
private UserService userService;
|
||||
private StringHelper stringHelper;
|
||||
|
||||
private CryptoManager getCryptoManager() {
|
||||
return cryptoManager;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
private void setCryptoManager(CryptoManager cryptoManager) {
|
||||
this.cryptoManager = cryptoManager;
|
||||
}
|
||||
|
||||
private UserService getUserService() {
|
||||
return userService;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
private void setUserService(UserService userService) {
|
||||
this.userService = userService;
|
||||
}
|
||||
|
||||
private StringHelper getStringHelper() {
|
||||
return stringHelper;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
private void setStringHelper(StringHelper stringHelper) {
|
||||
this.stringHelper = stringHelper;
|
||||
}
|
||||
|
||||
public User getPrincipal(HttpServletRequest request) {
|
||||
AccessToken accessToken = this.getAccessToken(request);
|
||||
if (accessToken == null) {
|
||||
return null;
|
||||
}
|
||||
return this.extractUser(accessToken);
|
||||
}
|
||||
|
||||
public boolean checkScope(HttpServletRequest request, byte requiredScope) {
|
||||
AccessToken accessToken = this.getAccessToken(request);
|
||||
if (accessToken == null) {
|
||||
return false;
|
||||
}
|
||||
return isScopeMeet(accessToken.getScope(), requiredScope);
|
||||
}
|
||||
|
||||
public boolean isScopeMeet(byte actualScope, byte requiredScope) {
|
||||
return actualScope >= requiredScope;
|
||||
}
|
||||
|
||||
public String generateCredential(User user) {
|
||||
AccessToken accessToken = this.generateAccessToken(user);
|
||||
return this.generateCredentialFromAccessToken(accessToken);
|
||||
}
|
||||
|
||||
private AccessToken getAccessToken(HttpServletRequest request) {
|
||||
if (request.getHeader("Authorization") == null) {
|
||||
return null;
|
||||
}
|
||||
if (!request.getHeader("Authorization").startsWith("Bearer ")) {
|
||||
return null;
|
||||
}
|
||||
String hex = request.getHeader("Authorization").substring(
|
||||
"Bearer ".length());
|
||||
byte[] bytes = this.getStringHelper().convertToBytes(hex);
|
||||
return this.extractAccessToken(bytes);
|
||||
}
|
||||
|
||||
private User extractUser(AccessToken accessToken) {
|
||||
if (accessToken == null) {
|
||||
return null;
|
||||
}
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
calendar.setTime(accessToken.getGenerateTime());
|
||||
calendar.add(Calendar.SECOND, accessToken.getExpiresIn());
|
||||
Date expireTime = calendar.getTime();
|
||||
if (expireTime.before(new Date(System.currentTimeMillis()))) {
|
||||
return null;
|
||||
}
|
||||
return this.getUserService().getUserByName(accessToken.getUserName());
|
||||
}
|
||||
|
||||
public AccessToken generateAccessToken(User user) {
|
||||
AccessToken accessToken = new AccessToken();
|
||||
accessToken.setExpiresIn(this.defaultExpiresTime);
|
||||
accessToken.setGenerateTime(new Date(System.currentTimeMillis()));
|
||||
accessToken.setPassword(user.getPassword());
|
||||
accessToken.setUserName(user.getUserName());
|
||||
accessToken.setScope(user.getScope());
|
||||
return accessToken;
|
||||
}
|
||||
|
||||
private AccessToken extractAccessToken(byte[] bytes) {
|
||||
try {
|
||||
byte[] decrypted = this.getCryptoManager().decrypt(bytes);
|
||||
ObjectInputStream inputStream = new ObjectInputStream(
|
||||
new ByteArrayInputStream(decrypted));
|
||||
return (AccessToken) inputStream.readObject();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private String generateCredentialFromAccessToken(AccessToken accessToken) {
|
||||
try {
|
||||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||
ObjectOutputStream stream = new ObjectOutputStream(outputStream);
|
||||
stream.writeObject(accessToken);
|
||||
byte[] data = outputStream.toByteArray();
|
||||
byte[] encryptedData = this.getCryptoManager().encrypt(data);
|
||||
return this.getStringHelper().convertToHexString(encryptedData);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,120 +1,120 @@
|
|||
package org.bench4q.master.auth;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.InputStream;
|
||||
import java.security.KeyStore.PrivateKeyEntry;
|
||||
import java.security.KeyStore;
|
||||
import java.security.PrivateKey;
|
||||
import java.security.PublicKey;
|
||||
import java.util.Enumeration;
|
||||
|
||||
import javax.crypto.Cipher;
|
||||
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class CryptoManager {
|
||||
private static final int MAX_ENCRYPT_BLOCK = 245;
|
||||
private static final int MAX_DECRYPT_BLOCK = 256;
|
||||
|
||||
private PublicKey publicKey;
|
||||
private PrivateKey privateKey;
|
||||
|
||||
private PublicKey getPublicKey() {
|
||||
return publicKey;
|
||||
}
|
||||
|
||||
private void setPublicKey(PublicKey publicKey) {
|
||||
this.publicKey = publicKey;
|
||||
}
|
||||
|
||||
private PrivateKey getPrivateKey() {
|
||||
return privateKey;
|
||||
}
|
||||
|
||||
private void setPrivateKey(PrivateKey privateKey) {
|
||||
this.privateKey = privateKey;
|
||||
}
|
||||
|
||||
public CryptoManager() {
|
||||
try {
|
||||
InputStream pfxInputStream = Thread.currentThread()
|
||||
.getContextClassLoader()
|
||||
.getResourceAsStream("org/bench4q/master/config/key.pfx");
|
||||
String pfxPassword = "123456";
|
||||
KeyStore keyStore = KeyStore.getInstance("PKCS12");
|
||||
keyStore.load(pfxInputStream, pfxPassword.toCharArray());
|
||||
pfxInputStream.close();
|
||||
Enumeration<String> aliases = keyStore.aliases();
|
||||
if (aliases.hasMoreElements()) {
|
||||
String alias = aliases.nextElement();
|
||||
PrivateKeyEntry privateKeyEntry = (PrivateKeyEntry) keyStore
|
||||
.getEntry(alias, new KeyStore.PasswordProtection(
|
||||
pfxPassword.toCharArray()));
|
||||
this.setPrivateKey(privateKeyEntry.getPrivateKey());
|
||||
this.setPublicKey(privateKeyEntry.getCertificate()
|
||||
.getPublicKey());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public byte[] encrypt(byte[] data) {
|
||||
try {
|
||||
Cipher cipher = Cipher.getInstance("RSA/ECB/PKCS1Padding");
|
||||
cipher.init(Cipher.ENCRYPT_MODE, this.getPublicKey());
|
||||
int inputLen = data.length;
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
int offSet = 0;
|
||||
byte[] cache;
|
||||
int i = 0;
|
||||
while (inputLen - offSet > 0) {
|
||||
if (inputLen - offSet > MAX_ENCRYPT_BLOCK) {
|
||||
cache = cipher.doFinal(data, offSet, MAX_ENCRYPT_BLOCK);
|
||||
} else {
|
||||
cache = cipher.doFinal(data, offSet, inputLen - offSet);
|
||||
}
|
||||
out.write(cache, 0, cache.length);
|
||||
i++;
|
||||
offSet = i * MAX_ENCRYPT_BLOCK;
|
||||
}
|
||||
byte[] encryptedData = out.toByteArray();
|
||||
out.close();
|
||||
return encryptedData;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public byte[] decrypt(byte[] encryptedData) {
|
||||
try {
|
||||
Cipher cipher = Cipher.getInstance("RSA/ECB/PKCS1Padding");
|
||||
cipher.init(Cipher.DECRYPT_MODE, this.getPrivateKey());
|
||||
int inputLen = encryptedData.length;
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
int offSet = 0;
|
||||
byte[] cache;
|
||||
int i = 0;
|
||||
while (inputLen - offSet > 0) {
|
||||
if (inputLen - offSet > MAX_DECRYPT_BLOCK) {
|
||||
cache = cipher.doFinal(encryptedData, offSet,
|
||||
MAX_DECRYPT_BLOCK);
|
||||
} else {
|
||||
cache = cipher.doFinal(encryptedData, offSet, inputLen
|
||||
- offSet);
|
||||
}
|
||||
out.write(cache, 0, cache.length);
|
||||
i++;
|
||||
offSet = i * MAX_DECRYPT_BLOCK;
|
||||
}
|
||||
byte[] decryptedData = out.toByteArray();
|
||||
out.close();
|
||||
return decryptedData;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
package org.bench4q.master.helper.auth;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.InputStream;
|
||||
import java.security.KeyStore.PrivateKeyEntry;
|
||||
import java.security.KeyStore;
|
||||
import java.security.PrivateKey;
|
||||
import java.security.PublicKey;
|
||||
import java.util.Enumeration;
|
||||
|
||||
import javax.crypto.Cipher;
|
||||
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class CryptoManager {
|
||||
private static final int MAX_ENCRYPT_BLOCK = 245;
|
||||
private static final int MAX_DECRYPT_BLOCK = 256;
|
||||
|
||||
private PublicKey publicKey;
|
||||
private PrivateKey privateKey;
|
||||
|
||||
private PublicKey getPublicKey() {
|
||||
return publicKey;
|
||||
}
|
||||
|
||||
private void setPublicKey(PublicKey publicKey) {
|
||||
this.publicKey = publicKey;
|
||||
}
|
||||
|
||||
private PrivateKey getPrivateKey() {
|
||||
return privateKey;
|
||||
}
|
||||
|
||||
private void setPrivateKey(PrivateKey privateKey) {
|
||||
this.privateKey = privateKey;
|
||||
}
|
||||
|
||||
public CryptoManager() {
|
||||
try {
|
||||
InputStream pfxInputStream = Thread.currentThread()
|
||||
.getContextClassLoader()
|
||||
.getResourceAsStream("org/bench4q/master/config/key.pfx");
|
||||
String pfxPassword = "123456";
|
||||
KeyStore keyStore = KeyStore.getInstance("PKCS12");
|
||||
keyStore.load(pfxInputStream, pfxPassword.toCharArray());
|
||||
pfxInputStream.close();
|
||||
Enumeration<String> aliases = keyStore.aliases();
|
||||
if (aliases.hasMoreElements()) {
|
||||
String alias = aliases.nextElement();
|
||||
PrivateKeyEntry privateKeyEntry = (PrivateKeyEntry) keyStore
|
||||
.getEntry(alias, new KeyStore.PasswordProtection(
|
||||
pfxPassword.toCharArray()));
|
||||
this.setPrivateKey(privateKeyEntry.getPrivateKey());
|
||||
this.setPublicKey(privateKeyEntry.getCertificate()
|
||||
.getPublicKey());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public byte[] encrypt(byte[] data) {
|
||||
try {
|
||||
Cipher cipher = Cipher.getInstance("RSA/ECB/PKCS1Padding");
|
||||
cipher.init(Cipher.ENCRYPT_MODE, this.getPublicKey());
|
||||
int inputLen = data.length;
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
int offSet = 0;
|
||||
byte[] cache;
|
||||
int i = 0;
|
||||
while (inputLen - offSet > 0) {
|
||||
if (inputLen - offSet > MAX_ENCRYPT_BLOCK) {
|
||||
cache = cipher.doFinal(data, offSet, MAX_ENCRYPT_BLOCK);
|
||||
} else {
|
||||
cache = cipher.doFinal(data, offSet, inputLen - offSet);
|
||||
}
|
||||
out.write(cache, 0, cache.length);
|
||||
i++;
|
||||
offSet = i * MAX_ENCRYPT_BLOCK;
|
||||
}
|
||||
byte[] encryptedData = out.toByteArray();
|
||||
out.close();
|
||||
return encryptedData;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public byte[] decrypt(byte[] encryptedData) {
|
||||
try {
|
||||
Cipher cipher = Cipher.getInstance("RSA/ECB/PKCS1Padding");
|
||||
cipher.init(Cipher.DECRYPT_MODE, this.getPrivateKey());
|
||||
int inputLen = encryptedData.length;
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
int offSet = 0;
|
||||
byte[] cache;
|
||||
int i = 0;
|
||||
while (inputLen - offSet > 0) {
|
||||
if (inputLen - offSet > MAX_DECRYPT_BLOCK) {
|
||||
cache = cipher.doFinal(encryptedData, offSet,
|
||||
MAX_DECRYPT_BLOCK);
|
||||
} else {
|
||||
cache = cipher.doFinal(encryptedData, offSet, inputLen
|
||||
- offSet);
|
||||
}
|
||||
out.write(cache, 0, cache.length);
|
||||
i++;
|
||||
offSet = i * MAX_DECRYPT_BLOCK;
|
||||
}
|
||||
byte[] decryptedData = out.toByteArray();
|
||||
out.close();
|
||||
return decryptedData;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,162 +1,162 @@
|
|||
package org.bench4q.master.service.infrastructure;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.UUID;
|
||||
|
||||
import javax.xml.bind.JAXBException;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.bench4q.master.entity.Agent;
|
||||
import org.bench4q.master.exception.ExceptionLog;
|
||||
import org.bench4q.master.testplan.highavailable.faultolerence.BriefAgentFault;
|
||||
import org.bench4q.share.communication.HttpRequester;
|
||||
import org.bench4q.share.communication.HttpRequester.HttpResponse;
|
||||
import org.bench4q.share.helper.MarshalHelper;
|
||||
import org.bench4q.share.models.agent.RunScenarioModel;
|
||||
import org.bench4q.share.models.agent.RunScenarioResultModel;
|
||||
import org.bench4q.share.models.agent.StopTestModel;
|
||||
import org.bench4q.share.models.agent.statistics.AgentBriefStatusModel;
|
||||
import org.bench4q.share.models.agent.statistics.AgentBehaviorsBriefModel;
|
||||
import org.bench4q.share.models.agent.statistics.AgentPageBriefModel;
|
||||
import org.bench4q.share.models.agent.statistics.AgentPagesBriefModel;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class RunningAgentService {
|
||||
private HttpRequester httpRequester;
|
||||
private Logger logger = Logger.getLogger(RunningAgentService.class);
|
||||
|
||||
public HttpRequester getHttpRequester() {
|
||||
return httpRequester;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
public void setHttpRequester(HttpRequester httpRequester) {
|
||||
this.httpRequester = httpRequester;
|
||||
}
|
||||
|
||||
public RunScenarioResultModel run(Agent agent,
|
||||
RunScenarioModel runScenarioModel) throws IOException {
|
||||
HttpResponse httpResponse;
|
||||
try {
|
||||
httpResponse = this.httpRequester.sendPostXml(buildBaseUrl(agent)
|
||||
+ "/test/run", MarshalHelper.marshal(
|
||||
RunScenarioModel.class, runScenarioModel), null);
|
||||
if (HttpRequester.isInvalidResponse(httpResponse)) {
|
||||
return null;
|
||||
}
|
||||
return (RunScenarioResultModel) MarshalHelper.unmarshal(
|
||||
RunScenarioResultModel.class, httpResponse.getContent());
|
||||
} catch (JAXBException e) {
|
||||
logger.error(ExceptionLog.getStackTrace(e));
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public AgentBriefStatusModel brief(Agent agent, UUID agentRunId) {
|
||||
HttpResponse httpResponse;
|
||||
try {
|
||||
if (agent == null || agentRunId == null) {
|
||||
return null;
|
||||
}
|
||||
httpResponse = this.httpRequester.sendGet(buildBaseUrl(agent)
|
||||
+ "/test/brief/" + agentRunId, null, null);
|
||||
if (HttpRequester.isInvalidResponse(httpResponse)) {
|
||||
return null;
|
||||
}
|
||||
logger.info(httpResponse.getContent());
|
||||
return (AgentBriefStatusModel) MarshalHelper.unmarshal(
|
||||
AgentBriefStatusModel.class, httpResponse.getContent());
|
||||
} catch (Exception e) {
|
||||
logger.error(e.toString() + " When brief the agent with hostName "
|
||||
+ agent.getHostName());
|
||||
e.printStackTrace();
|
||||
new BriefAgentFault().doTolerance();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public StopTestModel stop(Agent agent, UUID runId) {
|
||||
HttpResponse httpResponse;
|
||||
try {
|
||||
if (agent == null || runId == null) {
|
||||
return null;
|
||||
}
|
||||
httpResponse = this.httpRequester.sendGet(buildBaseUrl(agent)
|
||||
+ "/test/stop/" + runId.toString(), null, null);
|
||||
if (HttpRequester.isInvalidResponse(httpResponse)) {
|
||||
return null;
|
||||
}
|
||||
return (StopTestModel) MarshalHelper.unmarshal(StopTestModel.class,
|
||||
httpResponse.getContent());
|
||||
} catch (Exception e) {
|
||||
logger.error(e.toString() + " when stop the agent with hostName "
|
||||
+ agent.getHostName());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private String buildBaseUrl(Agent agent) {
|
||||
return agent.getHostName() + ":" + agent.getPort();
|
||||
}
|
||||
|
||||
public AgentBehaviorsBriefModel behaviorsBrief(Agent agent, UUID runId) {
|
||||
try {
|
||||
HttpResponse httpResponse = this.getHttpRequester().sendGet(
|
||||
buildBaseUrl(agent) + "/test/behaviorsBrief/"
|
||||
+ runId.toString(), null, null);
|
||||
if (HttpRequester.isInvalidResponse(httpResponse)) {
|
||||
return null;
|
||||
}
|
||||
return (AgentBehaviorsBriefModel) MarshalHelper.unmarshal(
|
||||
AgentBehaviorsBriefModel.class, httpResponse.getContent());
|
||||
} catch (Exception e) {
|
||||
logger.error(ExceptionLog.getStackTrace(e)
|
||||
+ " When behaviorsBrief");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public AgentPageBriefModel pageBrief(Agent agent, UUID runId, int pageId) {
|
||||
try {
|
||||
HttpResponse httpResponse = this.getHttpRequester().sendGet(
|
||||
buildBaseUrl(agent) + "/test/pageBrief/" + runId.toString()
|
||||
+ "/" + pageId, null, null);
|
||||
if (HttpRequester.isInvalidResponse(httpResponse)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (AgentPageBriefModel) MarshalHelper.unmarshal(
|
||||
AgentPageBriefModel.class, httpResponse.getContent());
|
||||
} catch (IOException e) {
|
||||
logger.error(ExceptionLog.getStackTrace(e));
|
||||
return null;
|
||||
} catch (JAXBException e) {
|
||||
logger.error(ExceptionLog.getStackTrace(e));
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public AgentPagesBriefModel pagesBrief(Agent agent, UUID runId) {
|
||||
try {
|
||||
HttpResponse httpResponse = this.getHttpRequester().sendGet(
|
||||
buildBaseUrl(agent) + "/test/pagesBrief/"
|
||||
+ runId.toString(), null, null);
|
||||
if (HttpRequester.isInvalidResponse(httpResponse)) {
|
||||
return null;
|
||||
}
|
||||
logger.info(httpResponse.getContent());
|
||||
return (AgentPagesBriefModel) MarshalHelper.unmarshal(
|
||||
AgentPagesBriefModel.class, httpResponse.getContent());
|
||||
} catch (IOException e) {
|
||||
logger.error(ExceptionLog.getStackTrace(e));
|
||||
return null;
|
||||
} catch (JAXBException e) {
|
||||
logger.error(ExceptionLog.getStackTrace(e));
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
package org.bench4q.master.infrastructure.communication;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.UUID;
|
||||
|
||||
import javax.xml.bind.JAXBException;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.bench4q.master.domain.entity.Agent;
|
||||
import org.bench4q.master.exception.ExceptionLog;
|
||||
import org.bench4q.master.testplan.highavailable.faultolerence.BriefAgentFault;
|
||||
import org.bench4q.share.communication.HttpRequester;
|
||||
import org.bench4q.share.communication.HttpRequester.HttpResponse;
|
||||
import org.bench4q.share.helper.MarshalHelper;
|
||||
import org.bench4q.share.models.agent.RunScenarioModel;
|
||||
import org.bench4q.share.models.agent.RunScenarioResultModel;
|
||||
import org.bench4q.share.models.agent.StopTestModel;
|
||||
import org.bench4q.share.models.agent.statistics.AgentBriefStatusModel;
|
||||
import org.bench4q.share.models.agent.statistics.AgentBehaviorsBriefModel;
|
||||
import org.bench4q.share.models.agent.statistics.AgentPageBriefModel;
|
||||
import org.bench4q.share.models.agent.statistics.AgentPagesBriefModel;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class AgentMessenger {
|
||||
private HttpRequester httpRequester;
|
||||
private Logger logger = Logger.getLogger(AgentMessenger.class);
|
||||
|
||||
public HttpRequester getHttpRequester() {
|
||||
return httpRequester;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
public void setHttpRequester(HttpRequester httpRequester) {
|
||||
this.httpRequester = httpRequester;
|
||||
}
|
||||
|
||||
public RunScenarioResultModel run(Agent agent,
|
||||
RunScenarioModel runScenarioModel) throws IOException {
|
||||
HttpResponse httpResponse;
|
||||
try {
|
||||
httpResponse = this.httpRequester.sendPostXml(buildBaseUrl(agent)
|
||||
+ "/test/run", MarshalHelper.marshal(
|
||||
RunScenarioModel.class, runScenarioModel), null);
|
||||
if (HttpRequester.isInvalidResponse(httpResponse)) {
|
||||
return null;
|
||||
}
|
||||
return (RunScenarioResultModel) MarshalHelper.unmarshal(
|
||||
RunScenarioResultModel.class, httpResponse.getContent());
|
||||
} catch (JAXBException e) {
|
||||
logger.error(ExceptionLog.getStackTrace(e));
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public AgentBriefStatusModel brief(Agent agent, UUID agentRunId) {
|
||||
HttpResponse httpResponse;
|
||||
try {
|
||||
if (agent == null || agentRunId == null) {
|
||||
return null;
|
||||
}
|
||||
httpResponse = this.httpRequester.sendGet(buildBaseUrl(agent)
|
||||
+ "/test/brief/" + agentRunId, null, null);
|
||||
if (HttpRequester.isInvalidResponse(httpResponse)) {
|
||||
return null;
|
||||
}
|
||||
logger.info(httpResponse.getContent());
|
||||
return (AgentBriefStatusModel) MarshalHelper.unmarshal(
|
||||
AgentBriefStatusModel.class, httpResponse.getContent());
|
||||
} catch (Exception e) {
|
||||
logger.error(e.toString() + " When brief the agent with hostName "
|
||||
+ agent.getHostName());
|
||||
e.printStackTrace();
|
||||
new BriefAgentFault().doTolerance();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public StopTestModel stop(Agent agent, UUID runId) {
|
||||
HttpResponse httpResponse;
|
||||
try {
|
||||
if (agent == null || runId == null) {
|
||||
return null;
|
||||
}
|
||||
httpResponse = this.httpRequester.sendGet(buildBaseUrl(agent)
|
||||
+ "/test/stop/" + runId.toString(), null, null);
|
||||
if (HttpRequester.isInvalidResponse(httpResponse)) {
|
||||
return null;
|
||||
}
|
||||
return (StopTestModel) MarshalHelper.unmarshal(StopTestModel.class,
|
||||
httpResponse.getContent());
|
||||
} catch (Exception e) {
|
||||
logger.error(e.toString() + " when stop the agent with hostName "
|
||||
+ agent.getHostName());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private String buildBaseUrl(Agent agent) {
|
||||
return agent.getHostName() + ":" + agent.getPort();
|
||||
}
|
||||
|
||||
public AgentBehaviorsBriefModel behaviorsBrief(Agent agent, UUID runId) {
|
||||
try {
|
||||
HttpResponse httpResponse = this.getHttpRequester().sendGet(
|
||||
buildBaseUrl(agent) + "/test/behaviorsBrief/"
|
||||
+ runId.toString(), null, null);
|
||||
if (HttpRequester.isInvalidResponse(httpResponse)) {
|
||||
return null;
|
||||
}
|
||||
return (AgentBehaviorsBriefModel) MarshalHelper.unmarshal(
|
||||
AgentBehaviorsBriefModel.class, httpResponse.getContent());
|
||||
} catch (Exception e) {
|
||||
logger.error(ExceptionLog.getStackTrace(e)
|
||||
+ " When behaviorsBrief");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public AgentPageBriefModel pageBrief(Agent agent, UUID runId, int pageId) {
|
||||
try {
|
||||
HttpResponse httpResponse = this.getHttpRequester().sendGet(
|
||||
buildBaseUrl(agent) + "/test/pageBrief/" + runId.toString()
|
||||
+ "/" + pageId, null, null);
|
||||
if (HttpRequester.isInvalidResponse(httpResponse)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (AgentPageBriefModel) MarshalHelper.unmarshal(
|
||||
AgentPageBriefModel.class, httpResponse.getContent());
|
||||
} catch (IOException e) {
|
||||
logger.error(ExceptionLog.getStackTrace(e));
|
||||
return null;
|
||||
} catch (JAXBException e) {
|
||||
logger.error(ExceptionLog.getStackTrace(e));
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public AgentPagesBriefModel pagesBrief(Agent agent, UUID runId) {
|
||||
try {
|
||||
HttpResponse httpResponse = this.getHttpRequester().sendGet(
|
||||
buildBaseUrl(agent) + "/test/pagesBrief/"
|
||||
+ runId.toString(), null, null);
|
||||
if (HttpRequester.isInvalidResponse(httpResponse)) {
|
||||
return null;
|
||||
}
|
||||
logger.info(httpResponse.getContent());
|
||||
return (AgentPagesBriefModel) MarshalHelper.unmarshal(
|
||||
AgentPagesBriefModel.class, httpResponse.getContent());
|
||||
} catch (IOException e) {
|
||||
logger.error(ExceptionLog.getStackTrace(e));
|
||||
return null;
|
||||
} catch (JAXBException e) {
|
||||
logger.error(ExceptionLog.getStackTrace(e));
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -1,40 +1,40 @@
|
|||
package org.bench4q.master.service.infrastructure;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.bench4q.share.communication.HttpRequester;
|
||||
import org.bench4q.share.communication.HttpRequester.HttpResponse;
|
||||
import org.bench4q.share.helper.MarshalHelper;
|
||||
import org.bench4q.share.models.agent.ServerStatusModel;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class AgentStateService {
|
||||
private HttpRequester httpRequester = new HttpRequester();
|
||||
private static Logger logger = Logger.getLogger(AgentStateService.class);
|
||||
|
||||
public HttpRequester getHttpRequester() {
|
||||
return httpRequester;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
public void setHttpRequester(HttpRequester httpRequester) {
|
||||
this.httpRequester = httpRequester;
|
||||
}
|
||||
|
||||
public ServerStatusModel askLiving(String hostName, int port) {
|
||||
try {
|
||||
HttpResponse httpResponse = this.getHttpRequester().sendGet(
|
||||
hostName + ":" + port + "/", null, null);
|
||||
if (HttpRequester.isInvalidResponse(httpResponse)) {
|
||||
return null;
|
||||
}
|
||||
return (ServerStatusModel) MarshalHelper.unmarshal(
|
||||
ServerStatusModel.class, httpResponse.getContent());
|
||||
} catch (Exception e) {
|
||||
logger.error("agent :" + hostName + " break down!");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
package org.bench4q.master.infrastructure.communication;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.bench4q.share.communication.HttpRequester;
|
||||
import org.bench4q.share.communication.HttpRequester.HttpResponse;
|
||||
import org.bench4q.share.helper.MarshalHelper;
|
||||
import org.bench4q.share.models.agent.ServerStatusModel;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class AgentStateMessenger {
|
||||
private HttpRequester httpRequester = new HttpRequester();
|
||||
private static Logger logger = Logger.getLogger(AgentStateMessenger.class);
|
||||
|
||||
public HttpRequester getHttpRequester() {
|
||||
return httpRequester;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
public void setHttpRequester(HttpRequester httpRequester) {
|
||||
this.httpRequester = httpRequester;
|
||||
}
|
||||
|
||||
public ServerStatusModel askLiving(String hostName, int port) {
|
||||
try {
|
||||
HttpResponse httpResponse = this.getHttpRequester().sendGet(
|
||||
hostName + ":" + port + "/", null, null);
|
||||
if (HttpRequester.isInvalidResponse(httpResponse)) {
|
||||
return null;
|
||||
}
|
||||
return (ServerStatusModel) MarshalHelper.unmarshal(
|
||||
ServerStatusModel.class, httpResponse.getContent());
|
||||
} catch (Exception e) {
|
||||
logger.error("agent :" + hostName + " break down!");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package org.bench4q.master.service.communication;
|
||||
package org.bench4q.master.infrastructure.communication;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Date;
|
||||
|
@ -9,8 +9,8 @@ import java.util.concurrent.Executors;
|
|||
import javax.xml.bind.JAXBException;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.bench4q.master.domain.service.MonitorResultService;
|
||||
import org.bench4q.master.exception.ExceptionLog;
|
||||
import org.bench4q.master.service.infrastructure.MonitorResultService;
|
||||
import org.bench4q.share.communication.HttpRequester;
|
||||
import org.bench4q.share.communication.HttpRequester.HttpResponse;
|
||||
import org.bench4q.share.helper.MarshalHelper;
|
||||
|
@ -23,10 +23,10 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class MonitorService {
|
||||
public class MonitorMessenger {
|
||||
private HttpRequester httpRequester;
|
||||
private MonitorResultService monitorResultService;
|
||||
private static Logger logger = Logger.getLogger(MonitorService.class);
|
||||
private static Logger logger = Logger.getLogger(MonitorMessenger.class);
|
||||
|
||||
public HttpRequester getHttpRequester() {
|
||||
return httpRequester;
|
|
@ -5,10 +5,10 @@ import java.util.List;
|
|||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bench4q.master.entity.MonitorResult;
|
||||
import org.bench4q.master.service.infrastructure.MonitorResultService;
|
||||
import org.bench4q.master.service.infrastructure.TestPlanScriptService;
|
||||
import org.bench4q.master.service.infrastructure.TestPlanService;
|
||||
import org.bench4q.master.domain.entity.MonitorResult;
|
||||
import org.bench4q.master.domain.service.MonitorResultService;
|
||||
import org.bench4q.master.domain.service.TestPlanScriptService;
|
||||
import org.bench4q.master.domain.service.TestPlanService;
|
||||
import org.bench4q.share.helper.MarshalHelper;
|
||||
import org.bench4q.share.models.master.MonitorResultContainerModel;
|
||||
import org.bench4q.share.models.monitor.LogicalDiskModel;
|
||||
|
|
|
@ -7,12 +7,12 @@ import java.util.Set;
|
|||
import java.util.UUID;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.bench4q.master.entity.TestPlanScript;
|
||||
import org.bench4q.master.entity.TestPlanScriptResult;
|
||||
import org.bench4q.master.repository.TestPlanRepository;
|
||||
import org.bench4q.master.service.infrastructure.MonitorResultService;
|
||||
import org.bench4q.master.service.infrastructure.TestPlanScriptService;
|
||||
import org.bench4q.master.service.infrastructure.TestPlanService;
|
||||
import org.bench4q.master.domain.entity.TestPlanScript;
|
||||
import org.bench4q.master.domain.entity.TestPlanScriptResult;
|
||||
import org.bench4q.master.domain.repository.TestPlanRepository;
|
||||
import org.bench4q.master.domain.service.MonitorResultService;
|
||||
import org.bench4q.master.domain.service.TestPlanScriptService;
|
||||
import org.bench4q.master.domain.service.TestPlanService;
|
||||
import org.bench4q.share.models.master.statistics.ScriptBriefResultModel;
|
||||
import org.jfree.data.time.Second;
|
||||
import org.jfree.data.time.TimeSeries;
|
||||
|
|
|
@ -8,8 +8,8 @@ import org.apache.log4j.Logger;
|
|||
import org.bench4q.master.domain.RunningScript;
|
||||
import org.bench4q.master.domain.TestPlanContext;
|
||||
import org.bench4q.master.domain.TestPlanInBusiness;
|
||||
import org.bench4q.master.entity.User;
|
||||
import org.bench4q.master.service.infrastructure.TestPlanService;
|
||||
import org.bench4q.master.domain.entity.User;
|
||||
import org.bench4q.master.domain.service.TestPlanService;
|
||||
import org.bench4q.master.testplan.highavailable.CurrentLoadObserver;
|
||||
import org.bench4q.master.testplan.highavailable.HighAvailablePool;
|
||||
import org.bench4q.master.testplan.schedulscript.TaskCompleteCallback;
|
||||
|
|
|
@ -1,226 +1,226 @@
|
|||
package org.bench4q.master.testplan.highavailable;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.bench4q.master.domain.RunningAgent;
|
||||
import org.bench4q.master.domain.RunningScript;
|
||||
import org.bench4q.master.domain.TestPlanContext;
|
||||
import org.bench4q.master.entity.Agent;
|
||||
import org.bench4q.master.service.infrastructure.AgentService;
|
||||
import org.bench4q.master.service.infrastructure.AgentStateService;
|
||||
import org.bench4q.master.testplan.TestPlanContainer;
|
||||
import org.bench4q.master.testplan.transaction.script.ScriptLoadBase;
|
||||
import org.bench4q.master.testplan.transaction.script.ScriptLoadSubstitute;
|
||||
import org.bench4q.share.models.agent.ServerStatusModel;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class HighAvailablePool extends CurrentLoadSubject {
|
||||
private AgentService agentService;
|
||||
private AgentStateService agentStateService;
|
||||
private TestPlanContainer testPlanContainer;
|
||||
private Map<String, Agent> pool;
|
||||
private Map<String, ServerStatusModel> agentStatusOfPreviousBeatMap;
|
||||
private Map<UUID, AgentRunBlotter> agentRunBlotters;
|
||||
private long maxAvailableLoad;
|
||||
private long currentAvailableLoad;
|
||||
private static Logger logger = Logger.getLogger(HighAvailablePool.class);
|
||||
|
||||
public Map<String, Agent> getPool() {
|
||||
return this.pool;
|
||||
}
|
||||
|
||||
private void setPool(Map<String, Agent> pool) {
|
||||
this.pool = pool;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
public void setAgentService(AgentService agentService) {
|
||||
this.agentService = agentService;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
public void setAgentStateService(AgentStateService agentStateService) {
|
||||
this.agentStateService = agentStateService;
|
||||
}
|
||||
|
||||
private TestPlanContainer getTestPlanContainer() {
|
||||
return testPlanContainer;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
private void setTestPlanContainer(TestPlanContainer testPlanContainer) {
|
||||
this.testPlanContainer = testPlanContainer;
|
||||
}
|
||||
|
||||
public Long getMaxAvailableLoad() {
|
||||
return maxAvailableLoad;
|
||||
}
|
||||
|
||||
private void setMaxAvailableLoad(Long maxAvailableLoad) {
|
||||
this.maxAvailableLoad = maxAvailableLoad;
|
||||
}
|
||||
|
||||
public long getCurrentAvailableLoad() {
|
||||
return currentAvailableLoad;
|
||||
}
|
||||
|
||||
private void setCurrentAvailableLoad(long currentAvailableLoad) {
|
||||
this.currentAvailableLoad = currentAvailableLoad;
|
||||
}
|
||||
|
||||
private void setAgentStatusOfPreviousBeatMap(
|
||||
Map<String, ServerStatusModel> agentStatusOfPreviousBeatMap) {
|
||||
this.agentStatusOfPreviousBeatMap = agentStatusOfPreviousBeatMap;
|
||||
}
|
||||
|
||||
public Map<UUID, AgentRunBlotter> getAgentRunBlotters() {
|
||||
return agentRunBlotters;
|
||||
}
|
||||
|
||||
public void setAgentRunBlotters(Map<UUID, AgentRunBlotter> agentRunningInfo) {
|
||||
this.agentRunBlotters = agentRunningInfo;
|
||||
}
|
||||
|
||||
public HighAvailablePool() {
|
||||
this.setPool(new HashMap<String, Agent>());
|
||||
this.setAgentRunBlotters(new HashMap<UUID, AgentRunBlotter>());
|
||||
this.setAgentStatusOfPreviousBeatMap(new HashMap<String, ServerStatusModel>());
|
||||
this.setCurrentAvailableLoad((long) 0);
|
||||
}
|
||||
|
||||
@Scheduled(cron = "0,30 */1 * * * *")
|
||||
public void timerTask() {
|
||||
synchronized (this.agentService.getAgentLock()) {
|
||||
synchronized (this.getPool()) {
|
||||
_heartBeatsAndUpdateHAPool();
|
||||
}
|
||||
}
|
||||
logger.info("Rotation Over");
|
||||
}
|
||||
|
||||
private void _heartBeatsAndUpdateHAPool() {
|
||||
this.pool.clear();
|
||||
List<Agent> agents = this.agentService.loadAgentPoolFromDB();
|
||||
ServerStatusModel model = new ServerStatusModel();
|
||||
this.setCurrentAvailableLoad((long) 0);
|
||||
this.setMaxAvailableLoad((long) 0);
|
||||
for (int i = 0; i < agents.size(); i++) {
|
||||
this.getPool().put(agents.get(i).getHostName(), agents.get(i));
|
||||
model = queryAgentStatus(agents.get(i));
|
||||
if (model == null) {
|
||||
_doForBreakDown(model, agents.get(i).getHostName());
|
||||
continue;
|
||||
}
|
||||
_doForHealth(model, agents.get(i));
|
||||
}
|
||||
logger.info("Current Available load in pool is "
|
||||
+ this.getCurrentAvailableLoad());
|
||||
logger.info("Max available load in pool is "
|
||||
+ this.getMaxAvailableLoad());
|
||||
}
|
||||
|
||||
public ServerStatusModel queryAgentStatus(Agent agent) {
|
||||
return this.agentStateService.askLiving(agent.getHostName(),
|
||||
agent.getPort());
|
||||
}
|
||||
|
||||
private void _doForBreakDown(ServerStatusModel statusModel, String hostName) {
|
||||
updateAgentStatus(AgentService.AGENT_STATUS_BreakDown, hostName);
|
||||
List<UUID> runIDs = queryUnfinishedTest(statusModel, hostName);
|
||||
if (runIDs == null) {
|
||||
return;
|
||||
}
|
||||
for (UUID agentRunId : runIDs) {
|
||||
AgentRunBlotter agentRunBlotter = this.getAgentRunBlotters().get(
|
||||
agentRunId);
|
||||
if (agentRunBlotter == null || hasSubstitute(agentRunBlotter)) {
|
||||
continue;
|
||||
}
|
||||
substituteOnBoard(agentRunBlotter, agentRunId);
|
||||
agentRunBlotter.getRunningAgent().getAgent()
|
||||
.setCurrentStatus(AgentService.AGENT_STATUS_BreakDown);
|
||||
// TODO: update the status in Context, but first i want to know if
|
||||
// context and runBlotter are using the same runningAgentModel
|
||||
// TestPlanContext testPlanContext = this.getTestPlanContainer()
|
||||
// .getRunningTestPlans().get(agentRunBlotter.getTestPlanId());
|
||||
}
|
||||
}
|
||||
|
||||
private void updateAgentStatus(int status, String hostName) {
|
||||
this.pool.get(hostName).setCurrentStatus(status);
|
||||
this.agentService.updateAgentStatus(status, hostName);
|
||||
}
|
||||
|
||||
private boolean hasSubstitute(AgentRunBlotter agentRunBlotter) {
|
||||
return agentRunBlotter.getRunningAgent().getAgent().getCurrentStatus() == AgentService.AGENT_STATUS_BreakDown;
|
||||
}
|
||||
|
||||
private void substituteOnBoard(AgentRunBlotter deadAgentBlotter,
|
||||
UUID deadRunId) {
|
||||
logger.info("enter substituteOnBoard");
|
||||
TestPlanContext context = this.getTestPlanContainer()
|
||||
.queryTestPlanContext(deadAgentBlotter.getTestPlanId());
|
||||
if (context == null) {
|
||||
logger.info("The testPlan has finished or not started, so no need to substitute!");
|
||||
return;
|
||||
}
|
||||
RunningScript runningScript = context.queryRunningScript(new Integer(
|
||||
deadAgentBlotter.getRunningAgent().getScriptId()));
|
||||
ScriptLoadBase loadCommand = new ScriptLoadSubstitute(runningScript,
|
||||
deadAgentBlotter);
|
||||
List<RunningAgent> agentsAfterDistribute = loadCommand.execute();
|
||||
runningScript.doAfterDistributeLoad(agentsAfterDistribute);
|
||||
}
|
||||
|
||||
private void _doForHealth(ServerStatusModel newModel, Agent agent) {
|
||||
arrageUnfinishedTest(newModel, agent);
|
||||
this.setCurrentAvailableLoad(this.getCurrentAvailableLoad()
|
||||
+ (long) agent.getRemainLoad());
|
||||
this.setMaxAvailableLoad(this.getMaxAvailableLoad()
|
||||
+ (long) agent.getMaxLoad());
|
||||
this.agentStatusOfPreviousBeatMap.put(agent.getHostName(), newModel);
|
||||
}
|
||||
|
||||
private void arrageUnfinishedTest(ServerStatusModel newModel, Agent agent) {
|
||||
List<UUID> agentUnfinishedRunIds = queryUnfinishedTest(newModel,
|
||||
agent.getHostName());
|
||||
if (agentUnfinishedRunIds == null || agentUnfinishedRunIds.size() == 0) {
|
||||
this.agentService.updateAgentStatus(AgentService.AGENT_STATUS_Idel,
|
||||
agent.getHostName());
|
||||
this.agentService.resetAgent(agent);
|
||||
return;
|
||||
}
|
||||
this.agentService.updateAgentStatus(AgentService.AGENT_STATUS_InRun,
|
||||
agent.getHostName());
|
||||
}
|
||||
|
||||
private List<UUID> queryUnfinishedTest(ServerStatusModel newModel,
|
||||
String hostName) {
|
||||
if (newModel == null) {
|
||||
ServerStatusModel model = this.agentStatusOfPreviousBeatMap
|
||||
.get(hostName);
|
||||
return model == null ? null : model.getRunningTests();
|
||||
}
|
||||
this.agentStatusOfPreviousBeatMap.put(hostName, newModel);
|
||||
return newModel.getRunningTests();
|
||||
}
|
||||
|
||||
public void doForTestPlanComplete(final TestPlanContext context) {
|
||||
|
||||
for (RunningScript runningScript : context.getAllScript()) {
|
||||
for (RunningAgent runningAgent : runningScript.queryRunningAgentsUnModifiable()) {
|
||||
this.getAgentRunBlotters().remove(runningAgent.getAgentRunId());
|
||||
logger.info("see the agentBlotter after run : "
|
||||
+ this.getAgentRunBlotters().get(
|
||||
runningAgent.getAgentRunId()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
package org.bench4q.master.testplan.highavailable;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.bench4q.master.domain.RunningAgent;
|
||||
import org.bench4q.master.domain.RunningScript;
|
||||
import org.bench4q.master.domain.TestPlanContext;
|
||||
import org.bench4q.master.domain.entity.Agent;
|
||||
import org.bench4q.master.domain.service.AgentService;
|
||||
import org.bench4q.master.infrastructure.communication.AgentStateMessenger;
|
||||
import org.bench4q.master.testplan.TestPlanContainer;
|
||||
import org.bench4q.master.testplan.transaction.script.ScriptLoadBase;
|
||||
import org.bench4q.master.testplan.transaction.script.ScriptLoadSubstitute;
|
||||
import org.bench4q.share.models.agent.ServerStatusModel;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class HighAvailablePool extends CurrentLoadSubject {
|
||||
private AgentService agentService;
|
||||
private AgentStateMessenger agentStateService;
|
||||
private TestPlanContainer testPlanContainer;
|
||||
private Map<String, Agent> pool;
|
||||
private Map<String, ServerStatusModel> agentStatusOfPreviousBeatMap;
|
||||
private Map<UUID, AgentRunBlotter> agentRunBlotters;
|
||||
private long maxAvailableLoad;
|
||||
private long currentAvailableLoad;
|
||||
private static Logger logger = Logger.getLogger(HighAvailablePool.class);
|
||||
|
||||
public Map<String, Agent> getPool() {
|
||||
return this.pool;
|
||||
}
|
||||
|
||||
private void setPool(Map<String, Agent> pool) {
|
||||
this.pool = pool;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
public void setAgentService(AgentService agentService) {
|
||||
this.agentService = agentService;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
public void setAgentStateService(AgentStateMessenger agentStateService) {
|
||||
this.agentStateService = agentStateService;
|
||||
}
|
||||
|
||||
private TestPlanContainer getTestPlanContainer() {
|
||||
return testPlanContainer;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
private void setTestPlanContainer(TestPlanContainer testPlanContainer) {
|
||||
this.testPlanContainer = testPlanContainer;
|
||||
}
|
||||
|
||||
public Long getMaxAvailableLoad() {
|
||||
return maxAvailableLoad;
|
||||
}
|
||||
|
||||
private void setMaxAvailableLoad(Long maxAvailableLoad) {
|
||||
this.maxAvailableLoad = maxAvailableLoad;
|
||||
}
|
||||
|
||||
public long getCurrentAvailableLoad() {
|
||||
return currentAvailableLoad;
|
||||
}
|
||||
|
||||
private void setCurrentAvailableLoad(long currentAvailableLoad) {
|
||||
this.currentAvailableLoad = currentAvailableLoad;
|
||||
}
|
||||
|
||||
private void setAgentStatusOfPreviousBeatMap(
|
||||
Map<String, ServerStatusModel> agentStatusOfPreviousBeatMap) {
|
||||
this.agentStatusOfPreviousBeatMap = agentStatusOfPreviousBeatMap;
|
||||
}
|
||||
|
||||
public Map<UUID, AgentRunBlotter> getAgentRunBlotters() {
|
||||
return agentRunBlotters;
|
||||
}
|
||||
|
||||
public void setAgentRunBlotters(Map<UUID, AgentRunBlotter> agentRunningInfo) {
|
||||
this.agentRunBlotters = agentRunningInfo;
|
||||
}
|
||||
|
||||
public HighAvailablePool() {
|
||||
this.setPool(new HashMap<String, Agent>());
|
||||
this.setAgentRunBlotters(new HashMap<UUID, AgentRunBlotter>());
|
||||
this.setAgentStatusOfPreviousBeatMap(new HashMap<String, ServerStatusModel>());
|
||||
this.setCurrentAvailableLoad((long) 0);
|
||||
}
|
||||
|
||||
@Scheduled(cron = "0,30 */1 * * * *")
|
||||
public void timerTask() {
|
||||
synchronized (this.agentService.getAgentLock()) {
|
||||
synchronized (this.getPool()) {
|
||||
_heartBeatsAndUpdateHAPool();
|
||||
}
|
||||
}
|
||||
logger.info("Rotation Over");
|
||||
}
|
||||
|
||||
private void _heartBeatsAndUpdateHAPool() {
|
||||
this.pool.clear();
|
||||
List<Agent> agents = this.agentService.loadAgentPoolFromDB();
|
||||
ServerStatusModel model = new ServerStatusModel();
|
||||
this.setCurrentAvailableLoad((long) 0);
|
||||
this.setMaxAvailableLoad((long) 0);
|
||||
for (int i = 0; i < agents.size(); i++) {
|
||||
this.getPool().put(agents.get(i).getHostName(), agents.get(i));
|
||||
model = queryAgentStatus(agents.get(i));
|
||||
if (model == null) {
|
||||
_doForBreakDown(model, agents.get(i).getHostName());
|
||||
continue;
|
||||
}
|
||||
_doForHealth(model, agents.get(i));
|
||||
}
|
||||
logger.info("Current Available load in pool is "
|
||||
+ this.getCurrentAvailableLoad());
|
||||
logger.info("Max available load in pool is "
|
||||
+ this.getMaxAvailableLoad());
|
||||
}
|
||||
|
||||
public ServerStatusModel queryAgentStatus(Agent agent) {
|
||||
return this.agentStateService.askLiving(agent.getHostName(),
|
||||
agent.getPort());
|
||||
}
|
||||
|
||||
private void _doForBreakDown(ServerStatusModel statusModel, String hostName) {
|
||||
updateAgentStatus(AgentService.AGENT_STATUS_BreakDown, hostName);
|
||||
List<UUID> runIDs = queryUnfinishedTest(statusModel, hostName);
|
||||
if (runIDs == null) {
|
||||
return;
|
||||
}
|
||||
for (UUID agentRunId : runIDs) {
|
||||
AgentRunBlotter agentRunBlotter = this.getAgentRunBlotters().get(
|
||||
agentRunId);
|
||||
if (agentRunBlotter == null || hasSubstitute(agentRunBlotter)) {
|
||||
continue;
|
||||
}
|
||||
substituteOnBoard(agentRunBlotter, agentRunId);
|
||||
agentRunBlotter.getRunningAgent().getAgent()
|
||||
.setCurrentStatus(AgentService.AGENT_STATUS_BreakDown);
|
||||
// TODO: update the status in Context, but first i want to know if
|
||||
// context and runBlotter are using the same runningAgentModel
|
||||
// TestPlanContext testPlanContext = this.getTestPlanContainer()
|
||||
// .getRunningTestPlans().get(agentRunBlotter.getTestPlanId());
|
||||
}
|
||||
}
|
||||
|
||||
private void updateAgentStatus(int status, String hostName) {
|
||||
this.pool.get(hostName).setCurrentStatus(status);
|
||||
this.agentService.updateAgentStatus(status, hostName);
|
||||
}
|
||||
|
||||
private boolean hasSubstitute(AgentRunBlotter agentRunBlotter) {
|
||||
return agentRunBlotter.getRunningAgent().getAgent().getCurrentStatus() == AgentService.AGENT_STATUS_BreakDown;
|
||||
}
|
||||
|
||||
private void substituteOnBoard(AgentRunBlotter deadAgentBlotter,
|
||||
UUID deadRunId) {
|
||||
logger.info("enter substituteOnBoard");
|
||||
TestPlanContext context = this.getTestPlanContainer()
|
||||
.queryTestPlanContext(deadAgentBlotter.getTestPlanId());
|
||||
if (context == null) {
|
||||
logger.info("The testPlan has finished or not started, so no need to substitute!");
|
||||
return;
|
||||
}
|
||||
RunningScript runningScript = context.queryRunningScript(new Integer(
|
||||
deadAgentBlotter.getRunningAgent().getScriptId()));
|
||||
ScriptLoadBase loadCommand = new ScriptLoadSubstitute(runningScript,
|
||||
deadAgentBlotter);
|
||||
List<RunningAgent> agentsAfterDistribute = loadCommand.execute();
|
||||
runningScript.doAfterDistributeLoad(agentsAfterDistribute);
|
||||
}
|
||||
|
||||
private void _doForHealth(ServerStatusModel newModel, Agent agent) {
|
||||
arrageUnfinishedTest(newModel, agent);
|
||||
this.setCurrentAvailableLoad(this.getCurrentAvailableLoad()
|
||||
+ (long) agent.getRemainLoad());
|
||||
this.setMaxAvailableLoad(this.getMaxAvailableLoad()
|
||||
+ (long) agent.getMaxLoad());
|
||||
this.agentStatusOfPreviousBeatMap.put(agent.getHostName(), newModel);
|
||||
}
|
||||
|
||||
private void arrageUnfinishedTest(ServerStatusModel newModel, Agent agent) {
|
||||
List<UUID> agentUnfinishedRunIds = queryUnfinishedTest(newModel,
|
||||
agent.getHostName());
|
||||
if (agentUnfinishedRunIds == null || agentUnfinishedRunIds.size() == 0) {
|
||||
this.agentService.updateAgentStatus(AgentService.AGENT_STATUS_Idel,
|
||||
agent.getHostName());
|
||||
this.agentService.resetAgent(agent);
|
||||
return;
|
||||
}
|
||||
this.agentService.updateAgentStatus(AgentService.AGENT_STATUS_InRun,
|
||||
agent.getHostName());
|
||||
}
|
||||
|
||||
private List<UUID> queryUnfinishedTest(ServerStatusModel newModel,
|
||||
String hostName) {
|
||||
if (newModel == null) {
|
||||
ServerStatusModel model = this.agentStatusOfPreviousBeatMap
|
||||
.get(hostName);
|
||||
return model == null ? null : model.getRunningTests();
|
||||
}
|
||||
this.agentStatusOfPreviousBeatMap.put(hostName, newModel);
|
||||
return newModel.getRunningTests();
|
||||
}
|
||||
|
||||
public void doForTestPlanComplete(final TestPlanContext context) {
|
||||
|
||||
for (RunningScript runningScript : context.getAllScript()) {
|
||||
for (RunningAgent runningAgent : runningScript.queryRunningAgentsUnModifiable()) {
|
||||
this.getAgentRunBlotters().remove(runningAgent.getAgentRunId());
|
||||
logger.info("see the agentBlotter after run : "
|
||||
+ this.getAgentRunBlotters().get(
|
||||
runningAgent.getAgentRunId()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,41 +1,41 @@
|
|||
package org.bench4q.master.testplan.schedulscript;
|
||||
|
||||
import java.util.TimerTask;
|
||||
|
||||
import org.bench4q.master.domain.RunningScript;
|
||||
import org.bench4q.master.helper.ApplicationContextHelper;
|
||||
import org.bench4q.master.service.infrastructure.AgentService;
|
||||
|
||||
public class WarmUpOverTask extends TimerTask {
|
||||
private AgentService agentService;
|
||||
private RunningScript runningScript;
|
||||
|
||||
public AgentService getAgentService() {
|
||||
return agentService;
|
||||
}
|
||||
|
||||
public void setAgentService(AgentService agentService) {
|
||||
this.agentService = agentService;
|
||||
}
|
||||
|
||||
public RunningScript getRunningScript() {
|
||||
return runningScript;
|
||||
}
|
||||
|
||||
public void setRunningScript(RunningScript runningScript) {
|
||||
this.runningScript = runningScript;
|
||||
}
|
||||
|
||||
public WarmUpOverTask() {
|
||||
this.setAgentService(ApplicationContextHelper.getContext().getBean(
|
||||
AgentService.class));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
System.out.println("warm up over and start to execute!");
|
||||
if (this.getRunningScript() == null) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
package org.bench4q.master.testplan.schedulscript;
|
||||
|
||||
import java.util.TimerTask;
|
||||
|
||||
import org.bench4q.master.domain.RunningScript;
|
||||
import org.bench4q.master.domain.service.AgentService;
|
||||
import org.bench4q.master.helper.ApplicationContextHelper;
|
||||
|
||||
public class WarmUpOverTask extends TimerTask {
|
||||
private AgentService agentService;
|
||||
private RunningScript runningScript;
|
||||
|
||||
public AgentService getAgentService() {
|
||||
return agentService;
|
||||
}
|
||||
|
||||
public void setAgentService(AgentService agentService) {
|
||||
this.agentService = agentService;
|
||||
}
|
||||
|
||||
public RunningScript getRunningScript() {
|
||||
return runningScript;
|
||||
}
|
||||
|
||||
public void setRunningScript(RunningScript runningScript) {
|
||||
this.runningScript = runningScript;
|
||||
}
|
||||
|
||||
public WarmUpOverTask() {
|
||||
this.setAgentService(ApplicationContextHelper.getContext().getBean(
|
||||
AgentService.class));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
System.out.println("warm up over and start to execute!");
|
||||
if (this.getRunningScript() == null) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,114 +1,114 @@
|
|||
package org.bench4q.master.testplan.transaction.agent;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.bench4q.master.entity.Agent;
|
||||
import org.bench4q.master.exception.ExceptionLog;
|
||||
import org.bench4q.master.helper.ApplicationContextHelper;
|
||||
import org.bench4q.master.service.infrastructure.AgentService;
|
||||
import org.bench4q.master.service.infrastructure.RunningAgentService;
|
||||
import org.bench4q.master.testplan.transaction.Transaction;
|
||||
import org.bench4q.share.models.agent.RunScenarioModel;
|
||||
import org.bench4q.share.models.agent.RunScenarioResultModel;
|
||||
|
||||
public class AgentTransaction implements Transaction {
|
||||
|
||||
private String agentHostName;
|
||||
private int agentPort;
|
||||
private RunScenarioModel runScenarioModel;
|
||||
private AgentService agentService;
|
||||
private RunningAgentService runningAgentService;
|
||||
private Logger logger = Logger.getLogger(AgentTransaction.class);
|
||||
|
||||
private String getAgentHostName() {
|
||||
return agentHostName;
|
||||
}
|
||||
|
||||
private void setAgentHostName(String agentHostName) {
|
||||
this.agentHostName = agentHostName;
|
||||
}
|
||||
|
||||
private int getAgentPort() {
|
||||
return agentPort;
|
||||
}
|
||||
|
||||
private void setAgentPort(int agentPort) {
|
||||
this.agentPort = agentPort;
|
||||
}
|
||||
|
||||
private RunScenarioModel getRunScenarioModel() {
|
||||
return runScenarioModel;
|
||||
}
|
||||
|
||||
private void setRunScenarioModel(RunScenarioModel runScenarioModel) {
|
||||
this.runScenarioModel = runScenarioModel;
|
||||
}
|
||||
|
||||
private AgentService getAgentService() {
|
||||
return agentService;
|
||||
}
|
||||
|
||||
private void setAgentService(AgentService agentService) {
|
||||
this.agentService = agentService;
|
||||
}
|
||||
|
||||
public RunningAgentService getRunningAgentService() {
|
||||
return runningAgentService;
|
||||
}
|
||||
|
||||
public void setRunningAgentService(RunningAgentService runningAgentService) {
|
||||
this.runningAgentService = runningAgentService;
|
||||
}
|
||||
|
||||
public AgentTransaction(String agentHostName, int port,
|
||||
RunScenarioModel runScenarioModel) {
|
||||
this.setAgentHostName(agentHostName);
|
||||
this.setAgentPort(port);
|
||||
this.setRunScenarioModel(runScenarioModel);
|
||||
this.setAgentService(ApplicationContextHelper.getContext().getBean(
|
||||
AgentService.class));
|
||||
this.setRunningAgentService(ApplicationContextHelper.getContext()
|
||||
.getBean(RunningAgentService.class));
|
||||
}
|
||||
|
||||
public Object execute() throws AgentRunException {
|
||||
try {
|
||||
if (!this.getAgentService().getLoadFromAgent(
|
||||
this.getAgentHostName(),
|
||||
this.getRunScenarioModel().getPoolSize())) {
|
||||
throw new AgentRunException();
|
||||
}
|
||||
if (!isValidRunScenarioModel(runScenarioModel)) {
|
||||
throw new AgentRunException();
|
||||
}
|
||||
RunScenarioResultModel ret = this.getRunningAgentService().run(
|
||||
buildAgent(this.getAgentHostName(), this.getAgentPort()),
|
||||
this.getRunScenarioModel());
|
||||
if (ret == null) {
|
||||
throw new AgentRunException();
|
||||
}
|
||||
return ret;
|
||||
} catch (IOException e) {
|
||||
this.logger
|
||||
.error(ExceptionLog.getStackTrace(e).toString());
|
||||
throw new AgentRunException();
|
||||
}
|
||||
}
|
||||
|
||||
private Agent buildAgent(String hostName, int port) {
|
||||
Agent agent = new Agent();
|
||||
agent.setHostName(hostName);
|
||||
agent.setPort(port);
|
||||
return agent;
|
||||
}
|
||||
|
||||
private boolean isValidRunScenarioModel(RunScenarioModel runScenarioModel) {
|
||||
return runScenarioModel == null ? false : true;
|
||||
}
|
||||
|
||||
public void rollBack() {
|
||||
this.getAgentService().backLoadToAgent(this.getAgentHostName(),
|
||||
this.getRunScenarioModel().getPoolSize());
|
||||
}
|
||||
}
|
||||
package org.bench4q.master.testplan.transaction.agent;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.bench4q.master.domain.entity.Agent;
|
||||
import org.bench4q.master.domain.service.AgentService;
|
||||
import org.bench4q.master.exception.ExceptionLog;
|
||||
import org.bench4q.master.helper.ApplicationContextHelper;
|
||||
import org.bench4q.master.infrastructure.communication.AgentMessenger;
|
||||
import org.bench4q.master.testplan.transaction.Transaction;
|
||||
import org.bench4q.share.models.agent.RunScenarioModel;
|
||||
import org.bench4q.share.models.agent.RunScenarioResultModel;
|
||||
|
||||
public class AgentTransaction implements Transaction {
|
||||
|
||||
private String agentHostName;
|
||||
private int agentPort;
|
||||
private RunScenarioModel runScenarioModel;
|
||||
private AgentService agentService;
|
||||
private AgentMessenger runningAgentService;
|
||||
private Logger logger = Logger.getLogger(AgentTransaction.class);
|
||||
|
||||
private String getAgentHostName() {
|
||||
return agentHostName;
|
||||
}
|
||||
|
||||
private void setAgentHostName(String agentHostName) {
|
||||
this.agentHostName = agentHostName;
|
||||
}
|
||||
|
||||
private int getAgentPort() {
|
||||
return agentPort;
|
||||
}
|
||||
|
||||
private void setAgentPort(int agentPort) {
|
||||
this.agentPort = agentPort;
|
||||
}
|
||||
|
||||
private RunScenarioModel getRunScenarioModel() {
|
||||
return runScenarioModel;
|
||||
}
|
||||
|
||||
private void setRunScenarioModel(RunScenarioModel runScenarioModel) {
|
||||
this.runScenarioModel = runScenarioModel;
|
||||
}
|
||||
|
||||
private AgentService getAgentService() {
|
||||
return agentService;
|
||||
}
|
||||
|
||||
private void setAgentService(AgentService agentService) {
|
||||
this.agentService = agentService;
|
||||
}
|
||||
|
||||
public AgentMessenger getRunningAgentService() {
|
||||
return runningAgentService;
|
||||
}
|
||||
|
||||
public void setRunningAgentService(AgentMessenger runningAgentService) {
|
||||
this.runningAgentService = runningAgentService;
|
||||
}
|
||||
|
||||
public AgentTransaction(String agentHostName, int port,
|
||||
RunScenarioModel runScenarioModel) {
|
||||
this.setAgentHostName(agentHostName);
|
||||
this.setAgentPort(port);
|
||||
this.setRunScenarioModel(runScenarioModel);
|
||||
this.setAgentService(ApplicationContextHelper.getContext().getBean(
|
||||
AgentService.class));
|
||||
this.setRunningAgentService(ApplicationContextHelper.getContext()
|
||||
.getBean(AgentMessenger.class));
|
||||
}
|
||||
|
||||
public Object execute() throws AgentRunException {
|
||||
try {
|
||||
if (!this.getAgentService().getLoadFromAgent(
|
||||
this.getAgentHostName(),
|
||||
this.getRunScenarioModel().getPoolSize())) {
|
||||
throw new AgentRunException();
|
||||
}
|
||||
if (!isValidRunScenarioModel(runScenarioModel)) {
|
||||
throw new AgentRunException();
|
||||
}
|
||||
RunScenarioResultModel ret = this.getRunningAgentService().run(
|
||||
buildAgent(this.getAgentHostName(), this.getAgentPort()),
|
||||
this.getRunScenarioModel());
|
||||
if (ret == null) {
|
||||
throw new AgentRunException();
|
||||
}
|
||||
return ret;
|
||||
} catch (IOException e) {
|
||||
this.logger
|
||||
.error(ExceptionLog.getStackTrace(e).toString());
|
||||
throw new AgentRunException();
|
||||
}
|
||||
}
|
||||
|
||||
private Agent buildAgent(String hostName, int port) {
|
||||
Agent agent = new Agent();
|
||||
agent.setHostName(hostName);
|
||||
agent.setPort(port);
|
||||
return agent;
|
||||
}
|
||||
|
||||
private boolean isValidRunScenarioModel(RunScenarioModel runScenarioModel) {
|
||||
return runScenarioModel == null ? false : true;
|
||||
}
|
||||
|
||||
public void rollBack() {
|
||||
this.getAgentService().backLoadToAgent(this.getAgentHostName(),
|
||||
this.getRunScenarioModel().getPoolSize());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,236 +1,236 @@
|
|||
package org.bench4q.master.testplan.transaction.script;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import javax.xml.bind.JAXBException;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.bench4q.master.domain.RunningAgent;
|
||||
import org.bench4q.master.domain.RunningScript;
|
||||
import org.bench4q.master.entity.Agent;
|
||||
import org.bench4q.master.exception.ExceptionLog;
|
||||
import org.bench4q.master.helper.ApplicationContextHelper;
|
||||
import org.bench4q.master.service.infrastructure.RunningAgentService;
|
||||
import org.bench4q.master.testplan.highavailable.AgentRunBlotter;
|
||||
import org.bench4q.master.testplan.highavailable.HighAvailablePool;
|
||||
import org.bench4q.master.testplan.transaction.Transaction;
|
||||
import org.bench4q.master.testplan.transaction.agent.AgentRunException;
|
||||
import org.bench4q.master.testplan.transaction.agent.AgentTransaction;
|
||||
import org.bench4q.share.models.agent.RunScenarioModel;
|
||||
import org.bench4q.share.models.agent.RunScenarioResultModel;
|
||||
import org.bench4q.share.models.agent.StopTestModel;
|
||||
|
||||
public abstract class ScriptLoadBase implements Transaction {
|
||||
private RunningScript runningScript;
|
||||
private UUID testPlanRunID;
|
||||
private List<RunningAgent> agentListThisTime = new ArrayList<RunningAgent>();
|
||||
private RunningAgentService runningAgentService;
|
||||
private HighAvailablePool highAvailableAgentPool;
|
||||
private static Logger logger = Logger.getLogger(ScriptLoadCommand.class);
|
||||
|
||||
protected RunningScript getRunningScript() {
|
||||
return runningScript;
|
||||
}
|
||||
|
||||
protected void setRunningScript(RunningScript runningScript) {
|
||||
this.runningScript = runningScript;
|
||||
}
|
||||
|
||||
private UUID getTestPlanRunID() {
|
||||
return testPlanRunID;
|
||||
}
|
||||
|
||||
protected void setTestPlanRunID(UUID testPlanRunID) {
|
||||
this.testPlanRunID = testPlanRunID;
|
||||
}
|
||||
|
||||
private List<RunningAgent> getAgentListThisTime() {
|
||||
return agentListThisTime;
|
||||
}
|
||||
|
||||
private void setAgentListThisTime(List<RunningAgent> agentListThisTime) {
|
||||
this.agentListThisTime = agentListThisTime;
|
||||
}
|
||||
|
||||
private RunningAgentService getRunningAgentService() {
|
||||
return runningAgentService;
|
||||
}
|
||||
|
||||
private void setRunningAgentService(RunningAgentService runningAgentService) {
|
||||
this.runningAgentService = runningAgentService;
|
||||
}
|
||||
|
||||
private HighAvailablePool getHighAvailableAgentPool() {
|
||||
return highAvailableAgentPool;
|
||||
}
|
||||
|
||||
private void setHighAvailableAgentPool(
|
||||
HighAvailablePool highAvailableAgentPool) {
|
||||
this.highAvailableAgentPool = highAvailableAgentPool;
|
||||
}
|
||||
|
||||
public static Logger getLogger() {
|
||||
return logger;
|
||||
}
|
||||
|
||||
public static void setLogger(Logger logger) {
|
||||
ScriptLoadBase.logger = logger;
|
||||
}
|
||||
|
||||
public ScriptLoadBase(RunningScript runningScript, UUID testPlanID) {
|
||||
initialize(runningScript, testPlanID);
|
||||
}
|
||||
|
||||
private void initialize(RunningScript runningScript, UUID testPlanID) {
|
||||
this.setRunningScript(runningScript);
|
||||
this.setTestPlanRunID(testPlanID);
|
||||
this.setRunningAgentService(ApplicationContextHelper.getContext()
|
||||
.getBean(RunningAgentService.class));
|
||||
this.setHighAvailableAgentPool(ApplicationContextHelper.getContext()
|
||||
.getBean(HighAvailablePool.class));
|
||||
this.setAgentListThisTime(new ArrayList<RunningAgent>());
|
||||
}
|
||||
|
||||
public List<RunningAgent> execute() {
|
||||
logger.info(this.getRunningScript().getScriptId());
|
||||
// RunScenarioModel runScenarioModel = this.getScriptService()
|
||||
// .getRunSceniroModelByScriptId(
|
||||
// this.getRunningScript().getScriptId());
|
||||
RunScenarioModel runScenarioModel = this.getRunningScript()
|
||||
.getScenario();
|
||||
if (runScenarioModel == null) {
|
||||
logger.error("runScenarioModel is null!");
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
this.runAgentsWithScenario(runScenarioModel, getRequireLoad(), this
|
||||
.getRunningScript().getScriptId(), this.getTestPlanRunID());
|
||||
|
||||
if (this.getAgentListThisTime() == null) {
|
||||
logger.error("runAgentsWithScenario fails where scriptId = "
|
||||
+ this.getRunningScript().getScriptId());
|
||||
return null;
|
||||
}
|
||||
if (RunningScript.notValidScript(this.runningScript)) {
|
||||
logger.error("The running agents of runningScriptModel is null, whose scriptId is"
|
||||
+ this.getRunningScript().getScriptId());
|
||||
return null;
|
||||
}
|
||||
return this.getAgentListThisTime();
|
||||
} catch (Exception e) {
|
||||
logger.error(ExceptionLog.getStackTrace(e).toString()
|
||||
+ " whose scriptID is "
|
||||
+ this.getRunningScript().getScriptId()
|
||||
+ " and TestPlanID is "
|
||||
+ this.getTestPlanRunID().toString());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract int getRequireLoad();
|
||||
|
||||
private void runAgentsWithScenario(RunScenarioModel runScenarioModel,
|
||||
int totalRequireLoad, int scriptId, UUID testPlanId)
|
||||
throws JAXBException, ScriptLoadDistributeException {
|
||||
RunningAgent runningAgent = new RunningAgent();
|
||||
RunScenarioResultModel runScenarioResultModel = new RunScenarioResultModel();
|
||||
int loadForRunCurrent;
|
||||
|
||||
for (Agent agent : this.getHighAvailableAgentPool().getPool().values()) {
|
||||
if (allocationFinish(totalRequireLoad)) {
|
||||
break;
|
||||
}
|
||||
if (this.getHighAvailableAgentPool().queryAgentStatus(agent) == null
|
||||
|| inUse(agent)) {
|
||||
continue;
|
||||
}
|
||||
loadForRunCurrent = getMin(totalRequireLoad, agent.getRemainLoad());
|
||||
runScenarioModel.setPoolSize(loadForRunCurrent);
|
||||
AgentTransaction agentTransaction = new AgentTransaction(
|
||||
agent.getHostName(), agent.getPort(), runScenarioModel);
|
||||
try {
|
||||
runScenarioResultModel = (RunScenarioResultModel) agentTransaction
|
||||
.execute();
|
||||
} catch (AgentRunException e) {
|
||||
agentTransaction.rollBack();
|
||||
continue;
|
||||
}
|
||||
runningAgent = buildRunningAgent(agent, loadForRunCurrent,
|
||||
scriptId, runScenarioResultModel.getRunId());
|
||||
this.getAgentListThisTime().add(runningAgent);
|
||||
updateAgentBlotterInHA(testPlanId, runningAgent);
|
||||
totalRequireLoad -= loadForRunCurrent;
|
||||
}
|
||||
if (!allocationFinish(totalRequireLoad)) {
|
||||
logger.error("allocationUnfinished, remain " + totalRequireLoad
|
||||
+ " unallocated");
|
||||
throw new ScriptLoadDistributeException();
|
||||
}
|
||||
}
|
||||
|
||||
private boolean allocationFinish(int requireLoad) {
|
||||
return requireLoad <= 0;
|
||||
}
|
||||
|
||||
private boolean inUse(Agent agent) {
|
||||
return agent.getRemainLoad() < agent.getMaxLoad();
|
||||
}
|
||||
|
||||
private int getMin(int requireLoad, int remainLoadByStart) {
|
||||
return remainLoadByStart >= requireLoad ? requireLoad
|
||||
: remainLoadByStart;
|
||||
}
|
||||
|
||||
private RunningAgent buildRunningAgent(Agent agent, int loadInUse,
|
||||
int scriptId, UUID agentRunId) {
|
||||
RunningAgent ret = new RunningAgent();
|
||||
ret.setAgent(agent);
|
||||
ret.setAgentRunId(agentRunId);
|
||||
ret.setLoadInUse(loadInUse);
|
||||
ret.setScriptId(scriptId);
|
||||
return ret;
|
||||
}
|
||||
|
||||
private AgentRunBlotter buildAgentRunBlotter(RunningAgent runningAgent,
|
||||
UUID testPlanId) {
|
||||
AgentRunBlotter result = new AgentRunBlotter();
|
||||
result.setRunningAgent(runningAgent);
|
||||
result.setTestPlanId(testPlanId);
|
||||
return result;
|
||||
}
|
||||
|
||||
private void updateAgentBlotterInHA(UUID testPlanId,
|
||||
RunningAgent runningAgent) {
|
||||
this.getHighAvailableAgentPool()
|
||||
.getAgentRunBlotters()
|
||||
.put(runningAgent.getAgentRunId(),
|
||||
buildAgentRunBlotter(runningAgent, testPlanId));
|
||||
}
|
||||
|
||||
public void rollBack() {
|
||||
stopAgentsRunningThisScript();
|
||||
}
|
||||
|
||||
private void stopAgentsRunningThisScript() {
|
||||
if (this.getAgentListThisTime() == null) {
|
||||
return;
|
||||
}
|
||||
for (RunningAgent runningAgent : this.getAgentListThisTime()) {
|
||||
// TODO: there's a problem
|
||||
AgentRunBlotter agentRunBlotter = this.getHighAvailableAgentPool()
|
||||
.getAgentRunBlotters().get(runningAgent.getAgentRunId());
|
||||
if (agentRunBlotter.getRunningAgent().isBreakDown()) {
|
||||
} else if (stopAgentSuccess(runningAgent)) {
|
||||
}
|
||||
this.getAgentListThisTime().remove(runningAgent);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean stopAgentSuccess(RunningAgent runningAgent) {
|
||||
StopTestModel resultModel = this.getRunningAgentService().stop(
|
||||
runningAgent.getAgent(), runningAgent.getAgentRunId());
|
||||
return (resultModel != null) && resultModel.isSuccess();
|
||||
}
|
||||
}
|
||||
package org.bench4q.master.testplan.transaction.script;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import javax.xml.bind.JAXBException;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.bench4q.master.domain.RunningAgent;
|
||||
import org.bench4q.master.domain.RunningScript;
|
||||
import org.bench4q.master.domain.entity.Agent;
|
||||
import org.bench4q.master.exception.ExceptionLog;
|
||||
import org.bench4q.master.helper.ApplicationContextHelper;
|
||||
import org.bench4q.master.infrastructure.communication.AgentMessenger;
|
||||
import org.bench4q.master.testplan.highavailable.AgentRunBlotter;
|
||||
import org.bench4q.master.testplan.highavailable.HighAvailablePool;
|
||||
import org.bench4q.master.testplan.transaction.Transaction;
|
||||
import org.bench4q.master.testplan.transaction.agent.AgentRunException;
|
||||
import org.bench4q.master.testplan.transaction.agent.AgentTransaction;
|
||||
import org.bench4q.share.models.agent.RunScenarioModel;
|
||||
import org.bench4q.share.models.agent.RunScenarioResultModel;
|
||||
import org.bench4q.share.models.agent.StopTestModel;
|
||||
|
||||
public abstract class ScriptLoadBase implements Transaction {
|
||||
private RunningScript runningScript;
|
||||
private UUID testPlanRunID;
|
||||
private List<RunningAgent> agentListThisTime = new ArrayList<RunningAgent>();
|
||||
private AgentMessenger runningAgentService;
|
||||
private HighAvailablePool highAvailableAgentPool;
|
||||
private static Logger logger = Logger.getLogger(ScriptLoadCommand.class);
|
||||
|
||||
protected RunningScript getRunningScript() {
|
||||
return runningScript;
|
||||
}
|
||||
|
||||
protected void setRunningScript(RunningScript runningScript) {
|
||||
this.runningScript = runningScript;
|
||||
}
|
||||
|
||||
private UUID getTestPlanRunID() {
|
||||
return testPlanRunID;
|
||||
}
|
||||
|
||||
protected void setTestPlanRunID(UUID testPlanRunID) {
|
||||
this.testPlanRunID = testPlanRunID;
|
||||
}
|
||||
|
||||
private List<RunningAgent> getAgentListThisTime() {
|
||||
return agentListThisTime;
|
||||
}
|
||||
|
||||
private void setAgentListThisTime(List<RunningAgent> agentListThisTime) {
|
||||
this.agentListThisTime = agentListThisTime;
|
||||
}
|
||||
|
||||
private AgentMessenger getRunningAgentService() {
|
||||
return runningAgentService;
|
||||
}
|
||||
|
||||
private void setRunningAgentService(AgentMessenger runningAgentService) {
|
||||
this.runningAgentService = runningAgentService;
|
||||
}
|
||||
|
||||
private HighAvailablePool getHighAvailableAgentPool() {
|
||||
return highAvailableAgentPool;
|
||||
}
|
||||
|
||||
private void setHighAvailableAgentPool(
|
||||
HighAvailablePool highAvailableAgentPool) {
|
||||
this.highAvailableAgentPool = highAvailableAgentPool;
|
||||
}
|
||||
|
||||
public static Logger getLogger() {
|
||||
return logger;
|
||||
}
|
||||
|
||||
public static void setLogger(Logger logger) {
|
||||
ScriptLoadBase.logger = logger;
|
||||
}
|
||||
|
||||
public ScriptLoadBase(RunningScript runningScript, UUID testPlanID) {
|
||||
initialize(runningScript, testPlanID);
|
||||
}
|
||||
|
||||
private void initialize(RunningScript runningScript, UUID testPlanID) {
|
||||
this.setRunningScript(runningScript);
|
||||
this.setTestPlanRunID(testPlanID);
|
||||
this.setRunningAgentService(ApplicationContextHelper.getContext()
|
||||
.getBean(AgentMessenger.class));
|
||||
this.setHighAvailableAgentPool(ApplicationContextHelper.getContext()
|
||||
.getBean(HighAvailablePool.class));
|
||||
this.setAgentListThisTime(new ArrayList<RunningAgent>());
|
||||
}
|
||||
|
||||
public List<RunningAgent> execute() {
|
||||
logger.info(this.getRunningScript().getScriptId());
|
||||
// RunScenarioModel runScenarioModel = this.getScriptService()
|
||||
// .getRunSceniroModelByScriptId(
|
||||
// this.getRunningScript().getScriptId());
|
||||
RunScenarioModel runScenarioModel = this.getRunningScript()
|
||||
.getScenario();
|
||||
if (runScenarioModel == null) {
|
||||
logger.error("runScenarioModel is null!");
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
this.runAgentsWithScenario(runScenarioModel, getRequireLoad(), this
|
||||
.getRunningScript().getScriptId(), this.getTestPlanRunID());
|
||||
|
||||
if (this.getAgentListThisTime() == null) {
|
||||
logger.error("runAgentsWithScenario fails where scriptId = "
|
||||
+ this.getRunningScript().getScriptId());
|
||||
return null;
|
||||
}
|
||||
if (RunningScript.notValidScript(this.runningScript)) {
|
||||
logger.error("The running agents of runningScriptModel is null, whose scriptId is"
|
||||
+ this.getRunningScript().getScriptId());
|
||||
return null;
|
||||
}
|
||||
return this.getAgentListThisTime();
|
||||
} catch (Exception e) {
|
||||
logger.error(ExceptionLog.getStackTrace(e).toString()
|
||||
+ " whose scriptID is "
|
||||
+ this.getRunningScript().getScriptId()
|
||||
+ " and TestPlanID is "
|
||||
+ this.getTestPlanRunID().toString());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract int getRequireLoad();
|
||||
|
||||
private void runAgentsWithScenario(RunScenarioModel runScenarioModel,
|
||||
int totalRequireLoad, int scriptId, UUID testPlanId)
|
||||
throws JAXBException, ScriptLoadDistributeException {
|
||||
RunningAgent runningAgent = new RunningAgent();
|
||||
RunScenarioResultModel runScenarioResultModel = new RunScenarioResultModel();
|
||||
int loadForRunCurrent;
|
||||
|
||||
for (Agent agent : this.getHighAvailableAgentPool().getPool().values()) {
|
||||
if (allocationFinish(totalRequireLoad)) {
|
||||
break;
|
||||
}
|
||||
if (this.getHighAvailableAgentPool().queryAgentStatus(agent) == null
|
||||
|| inUse(agent)) {
|
||||
continue;
|
||||
}
|
||||
loadForRunCurrent = getMin(totalRequireLoad, agent.getRemainLoad());
|
||||
runScenarioModel.setPoolSize(loadForRunCurrent);
|
||||
AgentTransaction agentTransaction = new AgentTransaction(
|
||||
agent.getHostName(), agent.getPort(), runScenarioModel);
|
||||
try {
|
||||
runScenarioResultModel = (RunScenarioResultModel) agentTransaction
|
||||
.execute();
|
||||
} catch (AgentRunException e) {
|
||||
agentTransaction.rollBack();
|
||||
continue;
|
||||
}
|
||||
runningAgent = buildRunningAgent(agent, loadForRunCurrent,
|
||||
scriptId, runScenarioResultModel.getRunId());
|
||||
this.getAgentListThisTime().add(runningAgent);
|
||||
updateAgentBlotterInHA(testPlanId, runningAgent);
|
||||
totalRequireLoad -= loadForRunCurrent;
|
||||
}
|
||||
if (!allocationFinish(totalRequireLoad)) {
|
||||
logger.error("allocationUnfinished, remain " + totalRequireLoad
|
||||
+ " unallocated");
|
||||
throw new ScriptLoadDistributeException();
|
||||
}
|
||||
}
|
||||
|
||||
private boolean allocationFinish(int requireLoad) {
|
||||
return requireLoad <= 0;
|
||||
}
|
||||
|
||||
private boolean inUse(Agent agent) {
|
||||
return agent.getRemainLoad() < agent.getMaxLoad();
|
||||
}
|
||||
|
||||
private int getMin(int requireLoad, int remainLoadByStart) {
|
||||
return remainLoadByStart >= requireLoad ? requireLoad
|
||||
: remainLoadByStart;
|
||||
}
|
||||
|
||||
private RunningAgent buildRunningAgent(Agent agent, int loadInUse,
|
||||
int scriptId, UUID agentRunId) {
|
||||
RunningAgent ret = new RunningAgent();
|
||||
ret.setAgent(agent);
|
||||
ret.setAgentRunId(agentRunId);
|
||||
ret.setLoadInUse(loadInUse);
|
||||
ret.setScriptId(scriptId);
|
||||
return ret;
|
||||
}
|
||||
|
||||
private AgentRunBlotter buildAgentRunBlotter(RunningAgent runningAgent,
|
||||
UUID testPlanId) {
|
||||
AgentRunBlotter result = new AgentRunBlotter();
|
||||
result.setRunningAgent(runningAgent);
|
||||
result.setTestPlanId(testPlanId);
|
||||
return result;
|
||||
}
|
||||
|
||||
private void updateAgentBlotterInHA(UUID testPlanId,
|
||||
RunningAgent runningAgent) {
|
||||
this.getHighAvailableAgentPool()
|
||||
.getAgentRunBlotters()
|
||||
.put(runningAgent.getAgentRunId(),
|
||||
buildAgentRunBlotter(runningAgent, testPlanId));
|
||||
}
|
||||
|
||||
public void rollBack() {
|
||||
stopAgentsRunningThisScript();
|
||||
}
|
||||
|
||||
private void stopAgentsRunningThisScript() {
|
||||
if (this.getAgentListThisTime() == null) {
|
||||
return;
|
||||
}
|
||||
for (RunningAgent runningAgent : this.getAgentListThisTime()) {
|
||||
// TODO: there's a problem
|
||||
AgentRunBlotter agentRunBlotter = this.getHighAvailableAgentPool()
|
||||
.getAgentRunBlotters().get(runningAgent.getAgentRunId());
|
||||
if (agentRunBlotter.getRunningAgent().isBreakDown()) {
|
||||
} else if (stopAgentSuccess(runningAgent)) {
|
||||
}
|
||||
this.getAgentListThisTime().remove(runningAgent);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean stopAgentSuccess(RunningAgent runningAgent) {
|
||||
StopTestModel resultModel = this.getRunningAgentService().stop(
|
||||
runningAgent.getAgent(), runningAgent.getAgentRunId());
|
||||
return (resultModel != null) && resultModel.isSuccess();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,32 +1,31 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
|
||||
<hibernate-configuration>
|
||||
<session-factory>
|
||||
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver </property>
|
||||
<property name="hibernate.connection.url"> jdbc:mysql://localhost:3306/bench4q_master
|
||||
</property>
|
||||
<property name="hibernate.connection.username">root </property>
|
||||
<property name="hibernate.connection.password">123456 </property>
|
||||
<property name="hibernate.connection.pool.size">20 </property>
|
||||
<property name="hibernate.show_sql">false </property>
|
||||
<property name="format_sql">false</property>
|
||||
<property name="Connection.useUnicode">true </property>
|
||||
<property name="connection.characterEncoding">utf-8 </property>
|
||||
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect </property>
|
||||
<property name="hibernate.hbm2ddl.auto">update</property>
|
||||
<property name="connection.autoReconnect">true</property>
|
||||
<property name="connection.autoReconnectForPools">true</property>
|
||||
<property name="connection.is-connection-validation-required">true</property>
|
||||
|
||||
<mapping class="org.bench4q.master.entity.User" />
|
||||
<mapping class="org.bench4q.master.entity.Script" />
|
||||
<mapping class="org.bench4q.master.entity.PlanedConfig" />
|
||||
<mapping class="org.bench4q.master.entity.Agent" />
|
||||
<mapping class="org.bench4q.master.entity.Port" />
|
||||
<mapping class="org.bench4q.master.entity.TestPlanDB" />
|
||||
<mapping class="org.bench4q.master.entity.TestPlanScript" />
|
||||
<mapping class="org.bench4q.master.entity.TestPlanScriptResult" />
|
||||
<mapping class="org.bench4q.master.entity.MonitorResult" />
|
||||
<mapping class="org.bench4q.master.entity.ForTest" />
|
||||
</session-factory>
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
|
||||
<hibernate-configuration>
|
||||
<session-factory>
|
||||
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver </property>
|
||||
<property name="hibernate.connection.url"> jdbc:mysql://localhost:3306/bench4q_master
|
||||
</property>
|
||||
<property name="hibernate.connection.username">root </property>
|
||||
<property name="hibernate.connection.password">123456 </property>
|
||||
<property name="hibernate.connection.pool.size">20 </property>
|
||||
<property name="hibernate.show_sql">false </property>
|
||||
<property name="format_sql">false</property>
|
||||
<property name="Connection.useUnicode">true </property>
|
||||
<property name="connection.characterEncoding">utf-8 </property>
|
||||
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect </property>
|
||||
<property name="hibernate.hbm2ddl.auto">update</property>
|
||||
<property name="connection.autoReconnect">true</property>
|
||||
<property name="connection.autoReconnectForPools">true</property>
|
||||
<property name="connection.is-connection-validation-required">true</property>
|
||||
|
||||
<mapping class="org.bench4q.master.domain.entity.User" />
|
||||
<mapping class="org.bench4q.master.domain.entity.Script" />
|
||||
<mapping class="org.bench4q.master.domain.entity.PlanedConfig" />
|
||||
<mapping class="org.bench4q.master.domain.entity.Agent" />
|
||||
<mapping class="org.bench4q.master.domain.entity.Port" />
|
||||
<mapping class="org.bench4q.master.domain.entity.TestPlanDB" />
|
||||
<mapping class="org.bench4q.master.domain.entity.TestPlanScript" />
|
||||
<mapping class="org.bench4q.master.domain.entity.TestPlanScriptResult" />
|
||||
<mapping class="org.bench4q.master.domain.entity.MonitorResult" />
|
||||
</session-factory>
|
||||
</hibernate-configuration>
|
|
@ -1,39 +0,0 @@
|
|||
package org.bench4q.master.test;
|
||||
|
||||
import org.bench4q.master.entity.ForTest;
|
||||
import org.bench4q.master.helper.SessionHelper;
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.Transaction;
|
||||
import org.junit.Test;
|
||||
|
||||
public class MysqlTest {
|
||||
|
||||
private SessionHelper sessionHelper;
|
||||
|
||||
public SessionHelper getSessionHelper() {
|
||||
return sessionHelper;
|
||||
}
|
||||
|
||||
public void setSessionHelper(SessionHelper sessionHelper) {
|
||||
this.sessionHelper = sessionHelper;
|
||||
}
|
||||
|
||||
public MysqlTest() {
|
||||
this.setSessionHelper(new SessionHelper());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testForChinese() {
|
||||
Session session = this.getSessionHelper().openSession();
|
||||
Transaction transaction = session.beginTransaction();
|
||||
try {
|
||||
ForTest test = new ForTest();
|
||||
test.setContent("³ÂÌú°´Å¥");
|
||||
session.merge(test);
|
||||
transaction.commit();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
transaction.rollback();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -6,14 +6,14 @@ import java.util.UUID;
|
|||
|
||||
import org.bench4q.master.api.modelfactory.BusinessModelMapFactory;
|
||||
import org.bench4q.master.domain.TestPlanInBusiness;
|
||||
import org.bench4q.master.entity.User;
|
||||
import org.bench4q.master.repository.TestPlanRepository;
|
||||
import org.bench4q.master.repository.UserRepository;
|
||||
import org.bench4q.master.service.infrastructure.ScriptService;
|
||||
import org.bench4q.master.service.infrastructure.TestPlanScriptResultService;
|
||||
import org.bench4q.master.service.infrastructure.TestPlanScriptService;
|
||||
import org.bench4q.master.service.infrastructure.TestPlanService;
|
||||
import org.bench4q.master.service.infrastructure.UserService;
|
||||
import org.bench4q.master.domain.entity.User;
|
||||
import org.bench4q.master.domain.repository.TestPlanRepository;
|
||||
import org.bench4q.master.domain.repository.UserRepository;
|
||||
import org.bench4q.master.domain.service.ScriptService;
|
||||
import org.bench4q.master.domain.service.TestPlanScriptResultService;
|
||||
import org.bench4q.master.domain.service.TestPlanScriptService;
|
||||
import org.bench4q.master.domain.service.TestPlanService;
|
||||
import org.bench4q.master.domain.service.UserService;
|
||||
import org.bench4q.master.test.controller.TestBase;
|
||||
import org.bench4q.master.test.testplan.TestPlanTester;
|
||||
import org.bench4q.share.models.master.MonitorModel;
|
||||
|
|
|
@ -9,7 +9,7 @@ import javax.xml.bind.JAXBException;
|
|||
|
||||
import org.bench4q.master.api.modelfactory.BusinessModelMapFactory;
|
||||
import org.bench4q.master.domain.TestPlanInBusiness;
|
||||
import org.bench4q.master.entity.User;
|
||||
import org.bench4q.master.domain.entity.User;
|
||||
import org.bench4q.master.test.TestBase_MakeUpTestPlan;
|
||||
import org.bench4q.master.test.testplan.TestPlanTester;
|
||||
import org.bench4q.share.communication.HttpRequester.HttpResponse;
|
||||
|
|
|
@ -1,72 +1,72 @@
|
|||
package org.bench4q.master.test.domain;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.bench4q.master.api.modelfactory.BusinessModelMapFactory;
|
||||
import org.bench4q.master.domain.RunningAgent;
|
||||
import org.bench4q.master.domain.RunningScript;
|
||||
import org.bench4q.master.entity.Agent;
|
||||
import org.bench4q.master.test.TestBase_MakeUpTestPlan;
|
||||
import org.bench4q.master.testplan.datastatistics.PagesBriefStatistics;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
|
||||
public class Test_RunningScript extends TestBase_MakeUpTestPlan {
|
||||
|
||||
private RunningScript runningScript;
|
||||
|
||||
private RunningScript getRunningScript() {
|
||||
return runningScript;
|
||||
}
|
||||
|
||||
private void setRunningScript(RunningScript runningScript) {
|
||||
this.runningScript = runningScript;
|
||||
}
|
||||
|
||||
@SuppressWarnings("resource")
|
||||
@BeforeClass
|
||||
public static void beforeClass() {
|
||||
new ClassPathXmlApplicationContext("classpath:service-test-context.xml");
|
||||
}
|
||||
|
||||
public Test_RunningScript() {
|
||||
this.setRunningScript(BusinessModelMapFactory
|
||||
.toBusiness(buildScriptModel(USE_SCRIPT)));
|
||||
List<RunningAgent> runningAgents = new ArrayList<RunningAgent>();
|
||||
RunningAgent runningAgent = new RunningAgent();
|
||||
runningAgent.setLoadInUse(40);
|
||||
runningAgent.setScriptId(this.getScriptId());
|
||||
runningAgent.setAgent(new Agent());
|
||||
runningAgents.add(runningAgent);
|
||||
this.getRunningScript().doAfterDistributeLoad(runningAgents);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDoForComplete() {
|
||||
assertEquals(false, this.getRunningScript().isFinished());
|
||||
assertEquals(1, this.getRunningScript()
|
||||
.queryRunningAgentsUnModifiable().size());
|
||||
this.getRunningScript().doForComplete();
|
||||
assertEquals(0, this.getRunningScript()
|
||||
.queryRunningAgentsUnModifiable().size());
|
||||
assertEquals(true, this.getRunningScript().isFinished());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testForBriefByCycle() throws InterruptedException {
|
||||
this.getRunningScript().doPeriodicBrief();
|
||||
Thread.sleep(20000);
|
||||
assertEquals(0, this.getRunningScript().getLatestScriptBriefModel()
|
||||
.getAverageResponseTime());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testForGetPagesBriefStatistics() {
|
||||
assertNotNull(this.getRunningScript().getPagesBriefStatistics());
|
||||
assertTrue(this.getRunningScript().getPagesBriefStatistics() instanceof PagesBriefStatistics);
|
||||
}
|
||||
}
|
||||
package org.bench4q.master.test.domain;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.bench4q.master.api.modelfactory.BusinessModelMapFactory;
|
||||
import org.bench4q.master.domain.RunningAgent;
|
||||
import org.bench4q.master.domain.RunningScript;
|
||||
import org.bench4q.master.domain.entity.Agent;
|
||||
import org.bench4q.master.test.TestBase_MakeUpTestPlan;
|
||||
import org.bench4q.master.testplan.datastatistics.PagesBriefStatistics;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
|
||||
public class Test_RunningScript extends TestBase_MakeUpTestPlan {
|
||||
|
||||
private RunningScript runningScript;
|
||||
|
||||
private RunningScript getRunningScript() {
|
||||
return runningScript;
|
||||
}
|
||||
|
||||
private void setRunningScript(RunningScript runningScript) {
|
||||
this.runningScript = runningScript;
|
||||
}
|
||||
|
||||
@SuppressWarnings("resource")
|
||||
@BeforeClass
|
||||
public static void beforeClass() {
|
||||
new ClassPathXmlApplicationContext("classpath:service-test-context.xml");
|
||||
}
|
||||
|
||||
public Test_RunningScript() {
|
||||
this.setRunningScript(BusinessModelMapFactory
|
||||
.toBusiness(buildScriptModel(USE_SCRIPT)));
|
||||
List<RunningAgent> runningAgents = new ArrayList<RunningAgent>();
|
||||
RunningAgent runningAgent = new RunningAgent();
|
||||
runningAgent.setLoadInUse(40);
|
||||
runningAgent.setScriptId(this.getScriptId());
|
||||
runningAgent.setAgent(new Agent());
|
||||
runningAgents.add(runningAgent);
|
||||
this.getRunningScript().doAfterDistributeLoad(runningAgents);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDoForComplete() {
|
||||
assertEquals(false, this.getRunningScript().isFinished());
|
||||
assertEquals(1, this.getRunningScript()
|
||||
.queryRunningAgentsUnModifiable().size());
|
||||
this.getRunningScript().doForComplete();
|
||||
assertEquals(0, this.getRunningScript()
|
||||
.queryRunningAgentsUnModifiable().size());
|
||||
assertEquals(true, this.getRunningScript().isFinished());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testForBriefByCycle() throws InterruptedException {
|
||||
this.getRunningScript().doPeriodicBrief();
|
||||
Thread.sleep(20000);
|
||||
assertEquals(0, this.getRunningScript().getLatestScriptBriefModel()
|
||||
.getAverageResponseTime());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testForGetPagesBriefStatistics() {
|
||||
assertNotNull(this.getRunningScript().getPagesBriefStatistics());
|
||||
assertTrue(this.getRunningScript().getPagesBriefStatistics() instanceof PagesBriefStatistics);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,9 +4,9 @@ import static org.junit.Assert.*;
|
|||
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bench4q.master.entity.TestPlanDB;
|
||||
import org.bench4q.master.repository.TestPlanRepository;
|
||||
import org.bench4q.master.repository.UserRepository;
|
||||
import org.bench4q.master.domain.entity.TestPlanDB;
|
||||
import org.bench4q.master.domain.repository.TestPlanRepository;
|
||||
import org.bench4q.master.domain.repository.UserRepository;
|
||||
import org.bench4q.share.enums.master.TestPlanStatus;
|
||||
import org.junit.After;
|
||||
import org.junit.Test;
|
||||
|
|
|
@ -2,9 +2,9 @@ package org.bench4q.master.test.repository;
|
|||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import org.bench4q.master.entity.User;
|
||||
import org.bench4q.master.domain.entity.User;
|
||||
import org.bench4q.master.domain.repository.UserRepository;
|
||||
import org.bench4q.master.helper.HashHelper;
|
||||
import org.bench4q.master.repository.UserRepository;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
|
|
@ -4,9 +4,10 @@ import static org.junit.Assert.*;
|
|||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import javax.xml.bind.JAXBException;
|
||||
|
||||
import org.bench4q.master.service.infrastructure.MonitorResultService;
|
||||
import org.bench4q.master.domain.service.MonitorResultService;
|
||||
import org.bench4q.master.test.TestBase_MakeUpTestPlan;
|
||||
import org.bench4q.share.helper.MarshalHelper;
|
||||
import org.bench4q.share.models.monitor.LogicalDiskModel;
|
||||
|
|
|
@ -4,7 +4,7 @@ import static org.junit.Assert.*;
|
|||
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bench4q.master.service.communication.MonitorService;
|
||||
import org.bench4q.master.infrastructure.communication.MonitorMessenger;
|
||||
import org.bench4q.share.models.monitor.LogicalDiskModel;
|
||||
import org.bench4q.share.models.monitor.MemoryModel;
|
||||
import org.bench4q.share.models.monitor.NetworkInterfaceModel;
|
||||
|
@ -20,14 +20,14 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
|||
public class Test_MonitorService {
|
||||
private static final int PORT = 5556;
|
||||
private static final String SUT_HOST_NAME = "133.133.12.3";
|
||||
private MonitorService monitorService;
|
||||
private MonitorMessenger monitorService;
|
||||
|
||||
private MonitorService getMonitorService() {
|
||||
private MonitorMessenger getMonitorService() {
|
||||
return monitorService;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
private void setMonitorService(MonitorService monitorService) {
|
||||
private void setMonitorService(MonitorMessenger monitorService) {
|
||||
this.monitorService = monitorService;
|
||||
}
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@ import java.io.IOException;
|
|||
import javax.xml.bind.JAXBException;
|
||||
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.bench4q.master.service.infrastructure.ScriptService;
|
||||
import org.bench4q.master.domain.service.ScriptService;
|
||||
import org.bench4q.share.helper.MarshalHelper;
|
||||
import org.bench4q.share.models.agent.RunScenarioModel;
|
||||
import org.junit.Test;
|
||||
|
|
|
@ -7,8 +7,8 @@ import java.util.UUID;
|
|||
|
||||
import org.bench4q.master.api.modelfactory.BusinessModelMapFactory;
|
||||
import org.bench4q.master.domain.TestPlanInBusiness;
|
||||
import org.bench4q.master.entity.User;
|
||||
import org.bench4q.master.service.infrastructure.TestPlanScriptResultService;
|
||||
import org.bench4q.master.domain.entity.User;
|
||||
import org.bench4q.master.domain.service.TestPlanScriptResultService;
|
||||
import org.bench4q.master.test.TestBase_MakeUpTestPlan;
|
||||
import org.bench4q.master.test.testplan.TestPlanTester;
|
||||
import org.bench4q.share.helper.TestHelper;
|
||||
|
|
|
@ -5,8 +5,8 @@ import static org.junit.Assert.*;
|
|||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bench4q.master.entity.TestPlanScript;
|
||||
import org.bench4q.master.entity.TestPlanScriptResult;
|
||||
import org.bench4q.master.domain.entity.TestPlanScript;
|
||||
import org.bench4q.master.domain.entity.TestPlanScriptResult;
|
||||
import org.bench4q.master.test.TestBase_MakeUpTestPlan;
|
||||
import org.bench4q.share.models.master.statistics.ScriptBriefResultModel;
|
||||
import org.junit.After;
|
||||
|
|
|
@ -11,8 +11,8 @@ import org.bench4q.master.api.modelfactory.BusinessModelMapFactory;
|
|||
import org.bench4q.master.domain.MonitorInBusiness;
|
||||
import org.bench4q.master.domain.RunningScript;
|
||||
import org.bench4q.master.domain.TestPlanInBusiness;
|
||||
import org.bench4q.master.entity.TestPlanScript;
|
||||
import org.bench4q.master.entity.User;
|
||||
import org.bench4q.master.domain.entity.TestPlanScript;
|
||||
import org.bench4q.master.domain.entity.User;
|
||||
import org.bench4q.master.test.TestBase_MakeUpTestPlan;
|
||||
import org.bench4q.share.enums.master.TestPlanStatus;
|
||||
import org.bench4q.share.models.master.RunningAgentModel;
|
||||
|
|
|
@ -2,7 +2,7 @@ package org.bench4q.master.test.service;
|
|||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import org.bench4q.master.service.infrastructure.UserService;
|
||||
import org.bench4q.master.domain.service.UserService;
|
||||
import org.junit.After;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.0.xsd">
|
||||
|
||||
<context:component-scan
|
||||
base-package="org.bench4q.master.helper, org.bench4q.master.repository, org.bench4q.master.entity" />
|
||||
base-package="org.bench4q.master.helper, org.bench4q.master.domain.repository, org.bench4q.master.domain.entity" />
|
||||
<mvc:annotation-driven />
|
||||
<task:annotation-driven />
|
||||
</beans>
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.0.xsd">
|
||||
|
||||
<context:component-scan
|
||||
base-package="org.bench4q.master.service,org.bench4q.master.report, org.bench4q.master.helper, org.bench4q.master.testplan, org.bench4q.share, org.bench4q.master.api.modelfactory, org.bench4q.master.factory, org.bench4q.master.repository" />
|
||||
base-package="org.bench4q.master.domain.service,org.bench4q.master.infrastructure.communication,org.bench4q.master.report, org.bench4q.master.helper, org.bench4q.master.testplan, org.bench4q.share, org.bench4q.master.api.modelfactory, org.bench4q.master.domain.factory, org.bench4q.master.domain.repository" />
|
||||
<mvc:annotation-driven />
|
||||
<task:annotation-driven />
|
||||
</beans>
|
||||
|
|
Loading…
Reference in New Issue