diff --git a/src/main/java/com/ctrip/zeus/restful/resource/GroupResource.java b/src/main/java/com/ctrip/zeus/restful/resource/GroupResource.java index 3d83c401..bb025905 100644 --- a/src/main/java/com/ctrip/zeus/restful/resource/GroupResource.java +++ b/src/main/java/com/ctrip/zeus/restful/resource/GroupResource.java @@ -322,7 +322,7 @@ public class GroupResource { failedIds.add(group.getId()); } } - if (groupIds.size() == 0) + if (failedIds.size() == 0) return responseHandler.handle("Successfully synced all group statuses.", hh.getMediaType()); else return responseHandler.handle("Error occurs when syncing group statuses on id " + Joiner.on(',').join(groupIds) + ".", hh.getMediaType()); diff --git a/src/main/java/com/ctrip/zeus/restful/resource/OperationResource.java b/src/main/java/com/ctrip/zeus/restful/resource/OperationResource.java index 5729aadc..7b09575b 100644 --- a/src/main/java/com/ctrip/zeus/restful/resource/OperationResource.java +++ b/src/main/java/com/ctrip/zeus/restful/resource/OperationResource.java @@ -7,6 +7,7 @@ import com.ctrip.zeus.exceptions.ValidationException; import com.ctrip.zeus.executor.TaskManager; import com.ctrip.zeus.model.entity.*; import com.ctrip.zeus.restful.message.ResponseHandler; +import com.ctrip.zeus.service.activate.ActivateService; import com.ctrip.zeus.service.activate.ActiveConfService; import com.ctrip.zeus.service.model.GroupRepository; import com.ctrip.zeus.service.model.SlbRepository; @@ -37,10 +38,7 @@ import javax.ws.rs.core.HttpHeaders; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; import java.io.InputStream; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.Set; +import java.util.*; /** * @author:xingchaowang @@ -76,6 +74,8 @@ public class OperationResource { private CertificateService certificateService; @Resource private CertificateInstaller certificateInstaller; + @Resource + private ActivateService activateService; @GET @@ -94,14 +94,19 @@ public class OperationResource { private Response serverOps(HttpHeaders hh, String serverip, boolean up) throws Exception { //get slb by serverip - List slblist = slbRepository.listByGroupServer(serverip); - AssertUtils.assertNotNull(slblist, "[UpServer/DownServer] Can not find slb by server ip :[" + serverip + "],Please check the configuration and server ip!"); + Set groupIds = statusService.findGroupIdByIp(serverip); + Set slbIds = activeConfService.getSlbIdsByGroupIds(groupIds.toArray(new Long[]{})); + Set slbIdsOffLine = slbCriteriaQuery.queryByGroups(groupIds.toArray(new Long[]{})); + slbIds.addAll(slbIdsOffLine); + if (slbIds == null || slbIds.size() == 0 ){ + throw new ValidationException("Not found Server Ip."); + } List tasks = new ArrayList<>(); - for (Slb slb : slblist) { + for (Long slbId : slbIds) { OpsTask task = new OpsTask(); task.setIpList(serverip); task.setOpsType(TaskOpsType.SERVER_OPS); - task.setTargetSlbId(slb.getId()); + task.setTargetSlbId(slbId); task.setUp(up); tasks.add(task); } @@ -119,7 +124,7 @@ public class OperationResource { throw new Exception(failCause); } ServerStatus ss = new ServerStatus().setIp(serverip).setUp(statusService.getServerStatus(serverip)); - List groupList = groupRepository.listGroupsByGroupServer(serverip); + List groupList = groupRepository.list(groupIds.toArray(new Long[]{})); if (groupList != null) { for (Group group : groupList) { diff --git a/src/main/java/com/ctrip/zeus/service/activate/ActiveConfService.java b/src/main/java/com/ctrip/zeus/service/activate/ActiveConfService.java index 36ff9968..b083b11f 100644 --- a/src/main/java/com/ctrip/zeus/service/activate/ActiveConfService.java +++ b/src/main/java/com/ctrip/zeus/service/activate/ActiveConfService.java @@ -11,6 +11,7 @@ import java.util.Set; public interface ActiveConfService extends Repository { public Set getSlbIdsByGroupId(Long groupId)throws Exception; + public Set getSlbIdsByGroupIds(Long[] groupId)throws Exception; public Set getGroupIdsBySlbId(Long slbId) throws Exception; public Set getVsIdsBySlbId(Long slbId) throws Exception; } diff --git a/src/main/java/com/ctrip/zeus/service/activate/impl/ActiveConfServiceImpl.java b/src/main/java/com/ctrip/zeus/service/activate/impl/ActiveConfServiceImpl.java index 6805ba99..d9d88e63 100644 --- a/src/main/java/com/ctrip/zeus/service/activate/impl/ActiveConfServiceImpl.java +++ b/src/main/java/com/ctrip/zeus/service/activate/impl/ActiveConfServiceImpl.java @@ -43,6 +43,21 @@ public class ActiveConfServiceImpl implements ActiveConfService { return slbIds; } @Override + public Set getSlbIdsByGroupIds(Long[] groupId) throws Exception { + Set slbIds = new HashSet<>(); + + List groupActiveDos = confGroupActiveDao.findAllByGroupIds(groupId,ConfGroupActiveEntity.READSET_FULL); + List vsIds = new ArrayList<>(); + for (ConfGroupActiveDo c : groupActiveDos){ + vsIds.add(c.getSlbVirtualServerId()); + } + List vsActiveDos = confSlbVirtualServerActiveDao.findBySlbVirtualServerIds(vsIds.toArray(new Long[]{}),ConfSlbVirtualServerActiveEntity.READSET_FULL); + for (ConfSlbVirtualServerActiveDo c : vsActiveDos){ + slbIds.add(c.getSlbId()); + } + return slbIds; + } + @Override public Set getGroupIdsBySlbId(Long slbId) throws Exception { Set groupIds = new HashSet<>(); List vsActiveDos = confSlbVirtualServerActiveDao.findBySlbId(slbId,ConfSlbVirtualServerActiveEntity.READSET_FULL);