refactor removeAgent(hostName) to removeAgent(id)

This commit is contained in:
Tienan Chen 2013-09-12 13:29:03 +08:00
parent b9fb1c0aa4
commit daa8992d0a
2 changed files with 4 additions and 5 deletions

View File

@ -58,14 +58,14 @@ public class AgentController extends BaseController {
@RequestMapping(value = "/removeAgentFromPool", method = RequestMethod.GET)
@ResponseBody
public AgentResponseModel removeAgentFromPool(@RequestParam String hostName) {
public AgentResponseModel removeAgentFromPool(@RequestParam int agentId) {
if (!this.checkScope(UserService.SUPER_AUTHENTICATION)) {
return _setAgentResponseModel(false,
"you don't have the power to remove agent from pool!", null);
}
synchronized (this.getAgentService().getAgentLock()) {
if (!this.getAgentService().removeAgentFromPool(hostName)) {
if (!this.getAgentService().removeAgentFromPool(agentId)) {
return _setAgentResponseModel(false,
"remove agent from DB fails in removeAgentFromPool",
null);

View File

@ -96,13 +96,12 @@ public class AgentService {
}
}
public boolean removeAgentFromPool(String hostNameString) {
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("hostName", hostNameString))
.uniqueResult();
.add(Restrictions.eq("id", agentId)).uniqueResult();
if (agent == null) {
return false;
}