refactor and try to log to front end
refactor and try to log to front end
This commit is contained in:
parent
a04a075ffe
commit
0ec2f364f7
|
@ -98,8 +98,8 @@ public class TestPlanController extends BaseController {
|
|||
this.testPlanScriptResultService = testPlanScriptResultService;
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/run", method = {
|
||||
RequestMethod.POST, RequestMethod.GET })
|
||||
@RequestMapping(value = "/run", method = { RequestMethod.POST,
|
||||
RequestMethod.GET })
|
||||
@ResponseStatus(value = HttpStatus.OK)
|
||||
@ResponseBody
|
||||
public TestPlanResultModel runTestPlanWithTestPlanModel(
|
||||
|
@ -107,15 +107,14 @@ public class TestPlanController extends BaseController {
|
|||
throws Bench4QException {
|
||||
if (!this.checkScope(UserService.NORAML_AUTHENTICATION)) {
|
||||
throw new Bench4QException(HAVE_NO_POWER,
|
||||
"You don't have enough power to run a test plan!",
|
||||
"/run");
|
||||
"You don't have enough power to run a test plan!", "/run");
|
||||
}
|
||||
UUID testPlanRunID = this.getTestPlanRunner().runWith(
|
||||
testPlanBusinessModel, this.getPrincipal());
|
||||
if (testPlanRunID == null) {
|
||||
throw new Bench4QException("TestPlan_Commit_Error",
|
||||
"There is an exception when commit the test plan",
|
||||
"/run");
|
||||
UUID testPlanRunID = null;
|
||||
try {
|
||||
testPlanRunID = this.getTestPlanRunner().runWith(
|
||||
testPlanBusinessModel, this.getPrincipal());
|
||||
} catch (Exception e) {
|
||||
throw new Bench4QException(e, "/run");
|
||||
}
|
||||
return buildResponseModel(this.getTestPlanService()
|
||||
.queryTestPlanStatus(testPlanRunID), testPlanRunID, null,
|
||||
|
@ -206,13 +205,13 @@ public class TestPlanController extends BaseController {
|
|||
@ResponseBody
|
||||
public TestPlanResponseModel loadTestPlans() {
|
||||
if (!this.checkScope(UserService.NORAML_AUTHENTICATION)) {
|
||||
return buildTestPlanResponseModel(false, "no scope", null,null);
|
||||
return buildTestPlanResponseModel(false, "no scope", null, null);
|
||||
}
|
||||
List<TestPlan> testPlanDBs = this.testPlanService.loadTestPlans(this
|
||||
.getPrincipal());
|
||||
return testPlanDBs == null ? buildTestPlanResponseModel(false,
|
||||
"exception", null,null) : buildTestPlanResponseModel(true, null,
|
||||
testPlanDBs,null);
|
||||
"exception", null, null) : buildTestPlanResponseModel(true,
|
||||
null, testPlanDBs, null);
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/queryTestPlan/{runId}", method = RequestMethod.GET)
|
||||
|
@ -233,14 +232,16 @@ public class TestPlanController extends BaseController {
|
|||
@ResponseBody
|
||||
public TestPlanResponseModel removeTestPlanFromPool(int testPlanId) {
|
||||
if (!this.checkScope(UserService.NORAML_AUTHENTICATION)) {
|
||||
return buildTestPlanResponseModel(false, "no scope", null,null);
|
||||
return buildTestPlanResponseModel(false, "no scope", null, null);
|
||||
}
|
||||
return buildTestPlanResponseModel(
|
||||
this.testPlanService.removeTestPlanInDB(testPlanId), null, null,null);
|
||||
this.testPlanService.removeTestPlanInDB(testPlanId), null,
|
||||
null, null);
|
||||
}
|
||||
|
||||
private TestPlanResponseModel buildTestPlanResponseModel(boolean success,
|
||||
String failCause, List<TestPlan> testPlanDBs,String[] filterTypeList) {
|
||||
String failCause, List<TestPlan> testPlanDBs,
|
||||
String[] filterTypeList) {
|
||||
TestPlanResponseModel result = new TestPlanResponseModel();
|
||||
result.setSuccess(success);
|
||||
result.setFailCause(failCause);
|
||||
|
@ -313,7 +314,7 @@ public class TestPlanController extends BaseController {
|
|||
guardIsTheOwner(testPlanId);
|
||||
return buildTestPlanResponseModel(
|
||||
this.getTestPlanRunner().stop(testPlanId), "",
|
||||
Collections.<TestPlan> emptyList(),null);
|
||||
Collections.<TestPlan> emptyList(), null);
|
||||
}
|
||||
|
||||
private void guardIsTheOwner(UUID testPlanId) {
|
||||
|
@ -323,9 +324,9 @@ public class TestPlanController extends BaseController {
|
|||
throw new Bench4QRunTimeException("You are not the owner");
|
||||
}
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/loadFilterTypeList", method = { RequestMethod.POST,
|
||||
RequestMethod.GET })
|
||||
|
||||
@RequestMapping(value = "/loadFilterTypeList", method = {
|
||||
RequestMethod.POST, RequestMethod.GET })
|
||||
@ResponseStatus(value = HttpStatus.OK)
|
||||
@ResponseBody
|
||||
public TestPlanResponseModel loadFilterTypeList() throws Bench4QException {
|
||||
|
@ -334,7 +335,9 @@ public class TestPlanController extends BaseController {
|
|||
"You don't have enough power to get filter type list!",
|
||||
"/loadFilterTypeList");
|
||||
}
|
||||
String[] filterTypeList = this.getTestPlanService().loadFilterTypeList();
|
||||
return this.buildTestPlanResponseModel(true, null, null,filterTypeList);
|
||||
String[] filterTypeList = this.getTestPlanService()
|
||||
.loadFilterTypeList();
|
||||
return this
|
||||
.buildTestPlanResponseModel(true, null, null, filterTypeList);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -103,8 +103,7 @@ public class TestPlanFactory {
|
|||
|
||||
public TestPlan createATestPlanWithoutId(TestPlanModel testPlanModel,
|
||||
User user, UUID runId) throws IllegalParameterException {
|
||||
Logger.getLogger(TestPlanFactory.class).info(
|
||||
"testPlanName:" + testPlanModel.getName());
|
||||
this.logger.info("testPlanName:" + testPlanModel.getName());
|
||||
TestPlan result = new TestPlan();
|
||||
result.setCreateDateTime(new Date());
|
||||
result.setCurrentStatus(TestPlanStatus.NotStart.name());
|
||||
|
@ -115,22 +114,24 @@ public class TestPlanFactory {
|
|||
result.setTestPlanRunId(runId.toString());
|
||||
result.setUser(user);
|
||||
Set<TestPlanScript> testPlanScripts = new HashSet<TestPlanScript>();
|
||||
int requiredLoad = 0;
|
||||
int totalRequiredLoad = 0;
|
||||
for (RunningScriptModel runningScriptModel : testPlanModel
|
||||
.getRunningScriptModels()) {
|
||||
if (runningScriptModel.getRequireLoad() <= 0) {
|
||||
this.logger.info(MarshalHelper.tryMarshal(runningScriptModel
|
||||
.getScheduleModel()));
|
||||
int scriptLoad = runningScriptModel.getScheduleModel().getMaxLoad();
|
||||
if (scriptLoad <= 0) {
|
||||
throw new IllegalParameterException(
|
||||
"runningScriptModel's requireLoad is L.T. zero where scriptId is "
|
||||
+ runningScriptModel.getScriptId());
|
||||
}
|
||||
requiredLoad += runningScriptModel.getRequireLoad();
|
||||
testPlanScripts.add(createATestPlanScriptWithoutId(
|
||||
runningScriptModel.getRequireLoad(),
|
||||
totalRequiredLoad += scriptLoad;
|
||||
testPlanScripts.add(createATestPlanScriptWithoutId(scriptLoad,
|
||||
runningScriptModel.getScriptId(),
|
||||
runningScriptModel.getScheduleModel(), result,
|
||||
runningScriptModel.getScriptFilterOptionsModel()));
|
||||
}
|
||||
result.setRequiredLoad(requiredLoad);
|
||||
result.setRequiredLoad(totalRequiredLoad);
|
||||
result.setTestPlanScripts(testPlanScripts);
|
||||
|
||||
Set<Monitor> monitors = new HashSet<Monitor>();
|
||||
|
|
|
@ -17,7 +17,6 @@ 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.domain.valueobject.schedulscript.TaskCompleteCallback;
|
||||
import org.bench4q.master.exception.ExceptionLog;
|
||||
import org.bench4q.master.exception.ExceptionUtils.IllegalParameterException;
|
||||
import org.bench4q.master.infrastructure.highavailable.CurrentLoadObserver;
|
||||
import org.bench4q.master.infrastructure.highavailable.HighAvailablePool;
|
||||
|
@ -94,14 +93,13 @@ public class TestPlanEngine implements TaskCompleteCallback,
|
|||
}, 0, Main.PICK_CYCLE_IN_SECONDS, TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
public UUID runWith(final TestPlanModel testPlanModel, User user) {
|
||||
public UUID runWith(final TestPlanModel testPlanModel, User user)
|
||||
throws IllegalParameterException {
|
||||
ExecutorService executorService = Executors.newCachedThreadPool();
|
||||
final UUID testPlanId = UUID.randomUUID();
|
||||
logger.info("name:" + testPlanModel.getName() + " start to run");
|
||||
logger.info(testPlanId + " start to run");
|
||||
if (!submitTestPlan(testPlanModel, user, testPlanId)) {
|
||||
return null;
|
||||
}
|
||||
submitTestPlan(testPlanModel, user, testPlanId);
|
||||
Runnable runnable = new Runnable() {
|
||||
public void run() {
|
||||
doRunTestPlan(testPlanId);
|
||||
|
@ -125,20 +123,13 @@ public class TestPlanEngine implements TaskCompleteCallback,
|
|||
}
|
||||
|
||||
public boolean submitTestPlan(final TestPlanModel testPlanBusinessModel,
|
||||
final User user, final UUID testPlanRunId) {
|
||||
try {
|
||||
TestPlan testPlan = this.getTestPlanFactory()
|
||||
.createATestPlanWithoutId(testPlanBusinessModel, user,
|
||||
testPlanRunId);
|
||||
Logger.getLogger(TestPlanService.class).info(
|
||||
"test plan name:" + testPlan.getName());
|
||||
return this.getTestPlanRepository().attach(testPlan);
|
||||
} catch (IllegalParameterException e) {
|
||||
// TODO: give back the message
|
||||
Logger.getLogger(TestPlanService.class).error(
|
||||
ExceptionLog.getStackTrace(e) + e.getMessage());
|
||||
return false;
|
||||
}
|
||||
final User user, final UUID testPlanRunId)
|
||||
throws IllegalParameterException {
|
||||
TestPlan testPlan = this.getTestPlanFactory().createATestPlanWithoutId(
|
||||
testPlanBusinessModel, user, testPlanRunId);
|
||||
Logger.getLogger(TestPlanService.class).info(
|
||||
"test plan name:" + testPlan.getName());
|
||||
return this.getTestPlanRepository().attach(testPlan);
|
||||
}
|
||||
|
||||
public void doRunTestPlan(final UUID testPlanId) {
|
||||
|
|
|
@ -44,4 +44,8 @@ public class Bench4QException extends Exception {
|
|||
this.setMessage(message);
|
||||
this.setResource(resource);
|
||||
}
|
||||
|
||||
public Bench4QException(Exception e, String resource) {
|
||||
this("404", e.getMessage(), resource);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,6 +23,7 @@ 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.exception.ExceptionUtils.IllegalParameterException;
|
||||
import org.bench4q.master.helper.SessionHelper;
|
||||
import org.bench4q.master.infrastructure.communication.AgentMessenger;
|
||||
import org.bench4q.master.infrastructure.highavailable.HighAvailablePool;
|
||||
|
@ -317,7 +318,11 @@ public class TestBase_MakeUpTestPlan extends TestBase {
|
|||
TestPlanModel model = null;
|
||||
|
||||
model = createAtestPlanWithOneScriptAndName(load);
|
||||
this.getTestPlanEngine().submitTestPlan(model, user, testPlanRunId);
|
||||
try {
|
||||
this.getTestPlanEngine().submitTestPlan(model, user, testPlanRunId);
|
||||
} catch (IllegalParameterException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
this.setTestPlanRunIdUuid(testPlanRunId);
|
||||
return testPlanRunId;
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@ import java.util.UUID;
|
|||
import javax.xml.bind.JAXBException;
|
||||
|
||||
import org.bench4q.master.domain.entity.User;
|
||||
import org.bench4q.master.exception.ExceptionUtils.IllegalParameterException;
|
||||
import org.bench4q.master.unitTest.TestBase_MakeUpTestPlan;
|
||||
import org.bench4q.share.communication.HttpRequester.HttpResponse;
|
||||
import org.bench4q.share.helper.MarshalHelper;
|
||||
|
@ -51,7 +52,12 @@ public class TestPlanScriptResultControllerTest extends TestBase_MakeUpTestPlan
|
|||
EACH_SCRIPT_LOAD_SMALLSCALE);
|
||||
// TestPlanInBusiness testPlan =
|
||||
// BusinessModelMapFactory.toBusiness(model);
|
||||
this.getTestPlanEngine().submitTestPlan(model, user, testPlanRunId);
|
||||
try {
|
||||
this.getTestPlanEngine().submitTestPlan(model, user, testPlanRunId);
|
||||
} catch (IllegalParameterException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
this.setTestPlanRunIdUuid(testPlanRunId);
|
||||
for (int i = 0; i < 3; i++) {
|
||||
/*
|
||||
|
|
|
@ -14,6 +14,7 @@ import org.bench4q.master.domain.repository.TestPlanRepository;
|
|||
import org.bench4q.master.domain.service.AgentService;
|
||||
import org.bench4q.master.domain.service.MonitorResultService;
|
||||
import org.bench4q.master.exception.Bench4QException;
|
||||
import org.bench4q.master.exception.ExceptionUtils.IllegalParameterException;
|
||||
import org.bench4q.master.unitTest.TestBase_MakeUpTestPlan;
|
||||
import org.bench4q.share.enums.master.TestPlanStatus;
|
||||
import org.bench4q.share.models.monitor.MemoryModel;
|
||||
|
@ -96,9 +97,13 @@ public class Test_MonitorResultService extends TestBase_MakeUpTestPlan {
|
|||
User user = this.getUserRepository().getUser("admin");
|
||||
int scriptId = getUserFirstScript(user);
|
||||
this.getHaPool().checkAllHeartBeat();
|
||||
this.setTestPlanRunIdUuid(this.getTestPlanEngine().runWith(
|
||||
createATestPlanWithOneScript(scriptId,
|
||||
EACH_SCRIPT_LOAD_SMALLSCALE), user));
|
||||
try {
|
||||
this.setTestPlanRunIdUuid(this.getTestPlanEngine().runWith(
|
||||
createATestPlanWithOneScript(scriptId,
|
||||
EACH_SCRIPT_LOAD_SMALLSCALE), user));
|
||||
} catch (IllegalParameterException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
Thread.sleep(500);
|
||||
TestPlan testPlanInDomain = this.getTestPlanFactory().convertToDomain(
|
||||
this.getTestPlanRepository().getTestPlanInDomainBy(
|
||||
|
|
|
@ -15,6 +15,7 @@ import org.bench4q.master.domain.entity.TestPlanScript;
|
|||
import org.bench4q.master.domain.entity.User;
|
||||
import org.bench4q.master.domain.repository.ScriptRepositoty;
|
||||
import org.bench4q.master.domain.service.AgentService;
|
||||
import org.bench4q.master.exception.ExceptionUtils.IllegalParameterException;
|
||||
import org.bench4q.master.unitTest.TestBase_MakeUpTestPlan;
|
||||
import org.bench4q.share.enums.master.TestPlanStatus;
|
||||
import org.bench4q.share.helper.TestHelper;
|
||||
|
@ -90,9 +91,13 @@ public class Test_TestPlanEngine extends TestBase_MakeUpTestPlan {
|
|||
this.getHaPool().checkAllHeartBeat();
|
||||
Date dateBeforeRun = new Date();
|
||||
Thread.sleep(1000);
|
||||
this.setTestPlanRunIdUuid(this.getTestPlanEngine().runWith(
|
||||
createATestPlanWithOneScript(scriptId,
|
||||
EACH_SCRIPT_LOAD_SMALLSCALE), user));
|
||||
try {
|
||||
this.setTestPlanRunIdUuid(this.getTestPlanEngine().runWith(
|
||||
createATestPlanWithOneScript(scriptId,
|
||||
EACH_SCRIPT_LOAD_SMALLSCALE), user));
|
||||
} catch (IllegalParameterException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
assertNotNull(getTestPlanRunIdUuid());
|
||||
Thread.sleep(10000);
|
||||
TestPlan testPlan = this.getTestPlanRepository().getTestPlanInDomainBy(
|
||||
|
|
|
@ -9,6 +9,7 @@ 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.domain.service.TestResultSave;
|
||||
import org.bench4q.master.exception.ExceptionUtils.IllegalParameterException;
|
||||
import org.bench4q.master.unitTest.TestBase_MakeUpTestPlan;
|
||||
import org.bench4q.share.models.master.TestPlanModel;
|
||||
import org.bench4q.share.models.master.statistics.ScriptBehaviorsBriefModel;
|
||||
|
@ -65,7 +66,11 @@ public class Test_TestPlanScriptResultService extends TestBase_MakeUpTestPlan {
|
|||
this.setScriptId(this.getUserFirstScript(user));
|
||||
TestPlanModel model = createATestPlanWithOneScript(this.getScriptId(),
|
||||
EACH_SCRIPT_LOAD_SMALLSCALE);
|
||||
this.getTestPlanEngine().submitTestPlan(model, user, testPlanRunId);
|
||||
try {
|
||||
this.getTestPlanEngine().submitTestPlan(model, user, testPlanRunId);
|
||||
} catch (IllegalParameterException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
this.setTestPlanRunIdUuid(testPlanRunId);
|
||||
this.testPlanRepository.getTestPlanInDomainBy(getTestPlanRunIdUuid());
|
||||
|
||||
|
|
|
@ -8,6 +8,7 @@ import java.util.UUID;
|
|||
import org.bench4q.master.domain.entity.TestPlan;
|
||||
import org.bench4q.master.domain.entity.TestPlanScript;
|
||||
import org.bench4q.master.domain.entity.User;
|
||||
import org.bench4q.master.exception.ExceptionUtils.IllegalParameterException;
|
||||
import org.bench4q.master.unitTest.TestBase_MakeUpTestPlan;
|
||||
import org.bench4q.share.enums.master.TestPlanStatus;
|
||||
import org.bench4q.share.models.master.TestPlanResultModel;
|
||||
|
@ -52,9 +53,14 @@ public class Test_TestPlanService extends TestBase_MakeUpTestPlan {
|
|||
.loadEntities(user).size();
|
||||
System.out.println(planCountBeforeSubmit);
|
||||
UUID randomUUID = UUID.randomUUID();
|
||||
assertTrue(this.getTestPlanEngine().submitTestPlan(
|
||||
createATestPlanWithOneScript(getUserFirstScript(user),
|
||||
EACH_SCRIPT_LOAD_SMALLSCALE), user, randomUUID));
|
||||
try {
|
||||
assertTrue(this.getTestPlanEngine().submitTestPlan(
|
||||
createATestPlanWithOneScript(getUserFirstScript(user),
|
||||
EACH_SCRIPT_LOAD_SMALLSCALE), user, randomUUID));
|
||||
} catch (IllegalParameterException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
int planCountAfterSubmit = this.getTestPlanRepository()
|
||||
.loadEntities(user).size();
|
||||
assertEquals(planCountBeforeSubmit + 1, planCountAfterSubmit);
|
||||
|
|
|
@ -1 +1 @@
|
|||
masterAddress=133.133.2.100:8901
|
||||
masterAddress=localhost:8901
|
Loading…
Reference in New Issue