add pull in/out member

This commit is contained in:
fanqq 2015-10-12 16:46:42 +08:00
parent 1b2825a2c5
commit ca09eb0753
13 changed files with 366 additions and 58 deletions

View file

@ -14,6 +14,7 @@ import com.ctrip.zeus.service.model.ArchiveService;
import com.ctrip.zeus.service.model.GroupRepository;
import com.ctrip.zeus.service.model.SlbRepository;
import com.ctrip.zeus.service.nginx.NginxService;
import com.ctrip.zeus.service.status.StatusOffset;
import com.ctrip.zeus.service.status.StatusService;
import com.ctrip.zeus.service.task.TaskService;
import com.ctrip.zeus.service.task.constant.TaskOpsType;
@ -62,6 +63,7 @@ public class TaskExecutorImpl implements TaskExecutor {
private HashMap<Long , OpsTask> deactivateGroupOps = new HashMap<>();
private HashMap<Long , OpsTask> activateSlbOps = new HashMap<>();
private HashMap<Long , List<OpsTask>> memberOps = new HashMap<>();
private HashMap<Long , List<OpsTask>> pullMemberOps = new HashMap<>();
private List<OpsTask> tasks = null;
@ -235,11 +237,17 @@ public class TaskExecutorImpl implements TaskExecutor {
}
String [] ips = task.getIpList().split(";");
List<String>ipList = Arrays.asList(ips);
if (task.getUp()){
statusService.upMember(slbId,task.getGroupId(), ipList);
}else {
statusService.downMember(slbId,task.getGroupId(), ipList);
statusService.updateStatus(slbId,task.getGroupId(),ipList,StatusOffset.MEMBER_OPS,task.getUp());
}
}
for (List<OpsTask> taskList :pullMemberOps.values()){
for (OpsTask task : taskList){
if (!task.getStatus().equals(TaskStatus.DOING)){
continue;
}
String [] ips = task.getIpList().split(";");
List<String>ipList = Arrays.asList(ips);
statusService.updateStatus(slbId,task.getGroupId(),ipList,StatusOffset.PULL_OPS,task.getUp());
}
}
}catch (Exception e){
@ -269,7 +277,8 @@ public class TaskExecutorImpl implements TaskExecutor {
}
private Set<String> getAllUpGroupServers(Long slbId,Map<Long, Group> groups, HashMap<Long, Group> activatingGroups) throws Exception {
Set<String> allUpGroupServers = statusService.findAllUpGroupServersBySlbId(slbId);
// Set<String> allUpGroupServers = statusService.findAllUpGroupServersBySlbId(slbId);
Set<String> memberOpsUpGroupServers = statusService.findAllGroupServersBySlbIdAndStatusOffset(slbId, StatusOffset.MEMBER_OPS);
Set<Long> tmpid = memberOps.keySet();
for (Long gid : tmpid){
Group groupTmp = activatingGroups.get(gid);
@ -287,18 +296,48 @@ public class TaskExecutorImpl implements TaskExecutor {
}
if (opsTask.getUp()){
for (String ip : ips){
allUpGroupServers.add(slbId+"_"+gvs.getVirtualServer().getId()+"_"+gid+"_"+ip);
memberOpsUpGroupServers.add(slbId+"_"+gvs.getVirtualServer().getId()+"_"+gid+"_"+ip);
}
}else {
for (String ip : ips){
allUpGroupServers.remove(slbId + "_" + gvs.getVirtualServer().getId() + "_" + gid + "_" + ip);
memberOpsUpGroupServers.remove(slbId + "_" + gvs.getVirtualServer().getId() + "_" + gid + "_" + ip);
}
}
}
}
}
return allUpGroupServers;
Set<String> pullMemberOpsUpGroupServers = statusService.findAllGroupServersBySlbIdAndStatusOffset(slbId,StatusOffset.PULL_OPS);
tmpid = pullMemberOps.keySet();
for (Long gid : tmpid){
Group groupTmp = activatingGroups.get(gid);
if (groupTmp==null){
groupTmp = groups.get(gid);
}
List<OpsTask> taskList = pullMemberOps.get(gid);
for (OpsTask opsTask : taskList)
{
String ipList =opsTask.getIpList();
String[]ips = ipList.split(";");
for (GroupVirtualServer gvs : groupTmp.getGroupVirtualServers()){
if (!gvs.getVirtualServer().getSlbId().equals(slbId)){
continue;
}
if (opsTask.getUp()){
for (String ip : ips){
pullMemberOpsUpGroupServers.add(slbId+"_"+gvs.getVirtualServer().getId()+"_"+gid+"_"+ip);
}
}else {
for (String ip : ips){
pullMemberOpsUpGroupServers.remove(slbId + "_" + gvs.getVirtualServer().getId() + "_" + gid + "_" + ip);
}
}
}
}
}
Set<String> result = new HashSet<>();
result.addAll(memberOpsUpGroupServers);
result.retainAll(pullMemberOpsUpGroupServers);
return result;
}
private Set<String> getAllDownServer() throws Exception{
@ -322,6 +361,11 @@ public class TaskExecutorImpl implements TaskExecutor {
result.add(gid);
}
}
for (Long gid : pullMemberOps.keySet()){
if (pullMemberOps.get(gid).get(0).getStatus().equals(TaskStatus.DOING)){
result.add(gid);
}
}
for (String ip : serverOps.keySet()){
List<Long>groupIds = serverGroupService.findAllByIp(ip);
result.addAll(groupIds);
@ -340,16 +384,25 @@ public class TaskExecutorImpl implements TaskExecutor {
for(OpsTask opsTask : tasksList){
String ips = opsTask.getIpList();
String[]iplist = ips.split(";");
if (opsTask.getUp()){
statusService.upMember(slbId , groupId, Arrays.asList(iplist));
}else {
statusService.downMember(slbId ,groupId, Arrays.asList(iplist));
}
statusService.updateStatus(slbId , groupId, Arrays.asList(iplist),StatusOffset.MEMBER_OPS,opsTask.getUp());
opsTask.setStatus(TaskStatus.SUCCESS);
}
memberOps.remove(groupId);
}
}
Set<Long> pullMemberGroups = pullMemberOps.keySet();
for (Long groupId : pullMemberGroups){
if (!activateService.isGroupActivated(groupId,slbId)){
List<OpsTask> tasksList = pullMemberOps.get(groupId);
for(OpsTask opsTask : tasksList){
String ips = opsTask.getIpList();
String[]iplist = ips.split(";");
statusService.updateStatus(slbId , groupId, Arrays.asList(iplist),StatusOffset.PULL_OPS,opsTask.getUp());
opsTask.setStatus(TaskStatus.SUCCESS);
}
pullMemberOps.remove(groupId);
}
}
}catch (Exception e){
logger.error("PreMemberOperation Fail!",e);
}
@ -402,6 +455,7 @@ public class TaskExecutorImpl implements TaskExecutor {
serverOps.clear();
memberOps.clear();
deactivateGroupOps.clear();
pullMemberOps.clear();
for (OpsTask task : tasks){
task.setStatus(TaskStatus.DOING);
//Activate group
@ -425,6 +479,16 @@ public class TaskExecutorImpl implements TaskExecutor {
}
taskList.add(task);
}
//tars member ops
if (task.getOpsType().equals(TaskOpsType.PULL_MEMBER_OPS)){
List<OpsTask> taskList = pullMemberOps.get(task.getGroupId());
if (taskList==null){
taskList = new ArrayList<>();
pullMemberOps.put(task.getGroupId(),taskList);
}
taskList.add(task);
}
//deactivate
if (task.getOpsType().equals(TaskOpsType.DEACTIVATE_GROUP)){
deactivateGroupOps.put(task.getGroupId(),task);
}

View file

@ -1,6 +1,8 @@
package com.ctrip.zeus.restful.resource;
import com.ctrip.zeus.auth.Authorize;
import com.ctrip.zeus.dal.core.StatusGroupServerDao;
import com.ctrip.zeus.dal.core.StatusGroupServerDo;
import com.ctrip.zeus.exceptions.ValidationException;
import com.ctrip.zeus.executor.TaskManager;
import com.ctrip.zeus.lock.DbLockFactory;
@ -14,6 +16,8 @@ import com.ctrip.zeus.service.build.NginxConfService;
import com.ctrip.zeus.service.model.GroupRepository;
import com.ctrip.zeus.service.model.SlbRepository;
import com.ctrip.zeus.service.nginx.NginxService;
import com.ctrip.zeus.service.query.GroupCriteriaQuery;
import com.ctrip.zeus.service.query.SlbCriteriaQuery;
import com.ctrip.zeus.service.status.GroupStatusService;
import com.ctrip.zeus.service.status.StatusService;
import com.ctrip.zeus.service.task.TaskService;
@ -76,10 +80,21 @@ public class ServerResource {
private TaskManager taskManager;
@Resource
private ActiveConfService activeConfService;
@Resource
private SlbCriteriaQuery slbCriteriaQuery;
@Resource
private GroupCriteriaQuery groupCriteriaQuery;
@Resource
private StatusGroupServerDao statusGroupServerDao;
private static DynamicIntProperty lockTimeout = DynamicPropertyFactory.getInstance().getIntProperty("lock.timeout", 5000);
@GET
@Path("/clean")
public Response clean(@Context HttpServletRequest request,@Context HttpHeaders hh, @QueryParam("ip") String ip) throws Exception{
statusGroupServerDao.deleteByUp(new StatusGroupServerDo().setUp(false));
return Response.status(200).entity("Suc").type(MediaType.APPLICATION_JSON).build();
}
@GET
@Path("/upServer")
@ -156,7 +171,7 @@ public class ServerResource {
{
_groupId = groupId;
}else if (groupName != null){
_groupId = groupRepository.get(groupName).getId();
_groupId = groupCriteriaQuery.queryByName(groupName);
}
if (null == _groupId)
{
@ -174,7 +189,7 @@ public class ServerResource {
{
_ips.addAll(ips);
}
return memberOps(hh, _groupId, _ips , true);
return memberOps(hh, _groupId, _ips , true,TaskOpsType.MEMBER_OPS);
}
@GET
@ -194,7 +209,7 @@ public class ServerResource {
{
_groupId = groupId;
}else if (groupName != null){
_groupId = groupRepository.get(groupName).getId();
_groupId = groupCriteriaQuery.queryByName(groupName);
}
if (null == _groupId)
{
@ -213,26 +228,102 @@ public class ServerResource {
_ips.addAll(ips);
}
return memberOps(hh, _groupId, _ips,false);
return memberOps(hh, _groupId, _ips,false,TaskOpsType.MEMBER_OPS);
}
private Response memberOps(HttpHeaders hh,Long groupId,List<String> ips,boolean up)throws Exception{
@GET
@Path("/pullIn")
@Authorize(name="upDownMember")
public Response pullIn(@Context HttpServletRequest request,
@Context HttpHeaders hh,
@QueryParam("groupId") Long groupId,
@QueryParam("groupName") String groupName,
@QueryParam("ip") List<String> ips,
@QueryParam("batch") Boolean batch)throws Exception
{
Long _groupId = null;
List<String> _ips = new ArrayList<>();
if (groupId != null)
{
_groupId = groupId;
}else if (groupName != null){
_groupId = groupCriteriaQuery.queryByName(groupName);
}
if (null == _groupId)
{
throw new ValidationException("Group Id or Name not found!");
}
if (null != batch && batch.equals(true))
{
Group gp = groupRepository.getById(_groupId);
List<GroupServer> servers = gp.getGroupServers();
for (GroupServer gs : servers)
{
_ips.add(gs.getIp());
}
}else if (ips != null)
{
_ips.addAll(ips);
}
return memberOps(hh, _groupId, _ips , true,TaskOpsType.PULL_MEMBER_OPS);
}
@GET
@Path("/pullOut")
@Authorize(name="upDownMember")
public Response pullOut(@Context HttpServletRequest request,
@Context HttpHeaders hh,
@QueryParam("groupId") Long groupId,
@QueryParam("groupName") String groupName,
@QueryParam("ip") List<String> ips,
@QueryParam("batch") Boolean batch)throws Exception
{
Long _groupId = null;
List<String> _ips = new ArrayList<>();
if (groupId != null)
{
_groupId = groupId;
}else if (groupName != null){
_groupId = groupCriteriaQuery.queryByName(groupName);
}
if (null == _groupId)
{
throw new ValidationException("Group Id or Name not found!");
}
if (null != batch && batch.equals(true))
{
Group gp = groupRepository.getById(_groupId);
List<GroupServer> servers = gp.getGroupServers();
for (GroupServer gs : servers)
{
_ips.add(gs.getIp());
}
}else if (ips != null)
{
_ips.addAll(ips);
}
return memberOps(hh, _groupId, _ips,false,TaskOpsType.PULL_MEMBER_OPS);
}
private Response memberOps(HttpHeaders hh,Long groupId,List<String> ips,boolean up,String type)throws Exception{
StringBuilder sb = new StringBuilder();
for (String ip : ips){
sb.append(ip).append(";");
}
Set<Long> slbIds = activeConfService.getSlbIdsByGroupId(groupId);
List<Slb> slbs = slbRepository.listByGroups(new Long[]{groupId});
for (Slb slb : slbs){
slbIds.add(slb.getId());
}
Set<Long> slbs = slbCriteriaQuery.queryByGroups(new Long[]{groupId});
slbIds.addAll(slbs);
List<OpsTask>tasks = new ArrayList<>();
for (Long slbId : slbIds){
OpsTask task = new OpsTask();
task.setTargetSlbId(slbId);
task.setOpsType(TaskOpsType.MEMBER_OPS);
task.setOpsType(type);
task.setUp(up);
task.setGroupId(groupId);
task.setIpList(sb.toString());

View file

@ -75,7 +75,8 @@ public class BuildServiceImpl implements BuildService {
List<String> l = activeConfService.getConfGroupActiveContentByGroupIds(groupList.toArray(new Long[]{}));
for (String content : l ){
Group tmpGroup = DefaultSaxParser.parseEntity(Group.class, content);
if (tmpGroup!=null&&!activatingGroups.containsKey(tmpGroup.getId())) {
// if (tmpGroup!=null&&!activatingGroups.containsKey(tmpGroup.getId())) {
if (tmpGroup!=null) {
groups.add(tmpGroup);
}
}

View file

@ -37,6 +37,6 @@ public interface GroupStatusService {
GroupStatusList getLocalGroupStatus(List<Long> groupId , Long slbId) throws Exception;
GroupServerStatus getGroupServerStatus(Long groupId, Long slbId, String ip, Integer port , Set<String> allDownServers,Set<String> allUpGroupServerInSlb,Group group) throws Exception;
GroupServerStatus getGroupServerStatus(Long groupId, Long slbId, String ip, Integer port , Set<String> allDownServers,Set<String> allUpGroupServerInSlb,Set<String> allPullInGroupServerInSlb,Group group) throws Exception;
}

View file

@ -0,0 +1,10 @@
package com.ctrip.zeus.service.status;
/**
* Created by fanqq on 2015/10/10.
*/
public class StatusOffset {
public static final int MEMBER_OPS = 0 ;
public static final int PULL_OPS = 1 ;
}

View file

@ -19,14 +19,6 @@ public interface StatusService extends Repository {
*/
Set<String> findAllDownServers() throws Exception;
/**
* get all down app servers by slbname
* @param slbId the slb id
* @return app server ip list
* @throws Exception
*/
Set<String> findAllDownGroupServersBySlbId(Long slbId) throws Exception;
/**
* get all up app servers by slbId
* @param slbId the slb id
@ -34,6 +26,13 @@ public interface StatusService extends Repository {
* @throws Exception
*/
Set<String> findAllUpGroupServersBySlbId(Long slbId) throws Exception;
/**
* get group servers by slbId and status offset
* @param slbId the slb id
* @return app server ip list
* @throws Exception
*/
Set<String> findAllGroupServersBySlbIdAndStatusOffset(Long slbId , int offset) throws Exception;
/**
* up server by app server ip
@ -67,6 +66,16 @@ public interface StatusService extends Repository {
* @throws Exception
*/
void downMember(Long slbId ,Long groupId, List<String> ips)throws Exception;
/**
* update status by group server ip and slbId and group id
* @param ips the group server ips
* @param groupId group id
* @param offset offset [0-30]
* @param status status enable = true , disable = false
* @return
* @throws Exception
*/
void updateStatus(Long slbId ,Long groupId, List<String> ips , int offset , boolean status)throws Exception;
/**
* get App server status by app name and slbname and virtual server ip

View file

@ -10,6 +10,7 @@ import com.ctrip.zeus.service.activate.ActiveConfService;
import com.ctrip.zeus.service.model.GroupRepository;
import com.ctrip.zeus.service.model.SlbRepository;
import com.ctrip.zeus.service.status.GroupStatusService;
import com.ctrip.zeus.service.status.StatusOffset;
import com.ctrip.zeus.service.status.StatusService;
import com.ctrip.zeus.status.entity.GroupServerStatus;
import com.ctrip.zeus.status.entity.GroupStatus;
@ -104,8 +105,9 @@ public class GroupStatusServiceImpl implements GroupStatusService {
Slb slb = slbRepository.getById(slbId);
AssertUtils.assertNotNull(slb, "slb Id not found!");
List<Group> groups = groupRepository.list(groupIds.toArray(new Long[]{}));
HashMap<Long,Boolean> isActivated = activateService.isGroupsActivated(groupIds.toArray(new Long[]{}),slbId);
Set<String> allUpGroupServerInSlb = statusService.findAllUpGroupServersBySlbId(slbId);
HashMap<Long,Boolean> isActivated = activateService.isGroupsActivated(groupIds.toArray(new Long[]{}), slbId);
Set<String> allUpGroupServerInSlb = statusService.findAllGroupServersBySlbIdAndStatusOffset(slbId, StatusOffset.MEMBER_OPS);
Set<String> allPullInGroupServerInSlb = statusService.findAllGroupServersBySlbIdAndStatusOffset(slbId, StatusOffset.PULL_OPS);
Set<String> allDownServers = statusService.findAllDownServers();
for (Group group : groups)
@ -140,7 +142,7 @@ public class GroupStatusServiceImpl implements GroupStatusService {
ips.add(gs.getIp());
}
for (String ip : ipPort.keySet()) {
GroupServerStatus serverStatus = getGroupServerStatus(groupId, slbId, ip, ipPort.get(ip),allDownServers,allUpGroupServerInSlb,group);
GroupServerStatus serverStatus = getGroupServerStatus(groupId, slbId, ip, ipPort.get(ip),allDownServers,allUpGroupServerInSlb,allPullInGroupServerInSlb,group);
if (activatedIps.contains(ip)&&ips.contains(ip)){
serverStatus.setDiscription("Activated");
}else if (!activatedIps.contains(ip)&&ips.contains(ip)){
@ -180,7 +182,7 @@ public class GroupStatusServiceImpl implements GroupStatusService {
@Override
public GroupServerStatus getGroupServerStatus(Long groupId, Long slbId, String ip, Integer port , Set<String> allDownServers,Set<String> allUpGroupServerInSlb,Group group) throws Exception {
public GroupServerStatus getGroupServerStatus(Long groupId, Long slbId, String ip, Integer port , Set<String> allDownServers,Set<String> allUpGroupServerInSlb,Set<String> allPullInGroupServerInSlb ,Group group) throws Exception {
GroupServerStatus groupServerStatus = new GroupServerStatus();
groupServerStatus.setIp(ip);
@ -189,11 +191,13 @@ public class GroupStatusServiceImpl implements GroupStatusService {
sb.append(slbId).append("_").append(group.getGroupVirtualServers().get(0).getVirtualServer().getId()).append("_").append(groupId).append("_").append(ip);
boolean memberUp = allUpGroupServerInSlb.contains(sb.toString());
boolean pullIn = allPullInGroupServerInSlb.contains(sb.toString());
boolean serverUp = !allDownServers.contains(ip);
boolean backendUp = getUpstreamStatus(groupId,ip,memberUp,serverUp);
boolean backendUp = getUpstreamStatus(groupId,ip,memberUp,serverUp,pullIn);
groupServerStatus.setServer(serverUp);
groupServerStatus.setMember(memberUp);
groupServerStatus.setPull(pullIn);
groupServerStatus.setUp(backendUp);
return groupServerStatus;
@ -201,7 +205,7 @@ public class GroupStatusServiceImpl implements GroupStatusService {
//TODO: should include port to get accurate upstream
private boolean getUpstreamStatus(Long groupId, String ip , boolean memberUp , boolean serverUp) throws Exception {
private boolean getUpstreamStatus(Long groupId, String ip , boolean memberUp , boolean serverUp ,boolean pullIn) throws Exception {
UpstreamStatus upstreamStatus = LocalClient.getInstance().getUpstreamStatus();
List<S> servers = upstreamStatus.getServers().getServer();
String upstreamNameEndWith = "_"+groupId;
@ -215,9 +219,9 @@ public class GroupStatusServiceImpl implements GroupStatusService {
if (ipPorts.length == 2){
if (ipPorts[0].equals(ip)){
boolean flag = "up".equalsIgnoreCase(server.getStatus());
if (!(memberUp&&serverUp)&&flag)
if (!(memberUp&&serverUp&&pullIn)&&flag)
{
LOGGER.error("nginx status api return status while memberUp or serverUp is down! ip:"+ip+" groupId:"+groupId);
LOGGER.error("nginx status api return status while memberUp or serverUp or pull is down! ip:"+ip+" groupId:"+groupId);
}
return flag;
}
@ -225,6 +229,6 @@ public class GroupStatusServiceImpl implements GroupStatusService {
}
//Not found status from nginx , ip is mark down or health check is disable
// return memberUp&&serverUp
return memberUp&&serverUp;
return memberUp&&serverUp&&pullIn;
}
}

View file

@ -35,6 +35,8 @@ public class StatusServiceImpl implements StatusService {
private ActivateService activateService;
@Resource
private GroupRepository groupRepository;
@Resource
private StatusGroupServerDao statusGroupServerDao;
private Logger logger = LoggerFactory.getLogger(StatusServiceImpl.class);
@ -49,26 +51,34 @@ public class StatusServiceImpl implements StatusService {
return allDownIps;
}
@Override
public Set<String> findAllDownGroupServersBySlbId(Long slbId) throws Exception {
Set<String> allDownAppServers = new HashSet<>();
List<StatusGroupServerDo> allDownAppServerList = statusGroupServerService.listAllDownBySlbId(slbId);
for (StatusGroupServerDo d : allDownAppServerList) {
allDownAppServers.add(d.getSlbId() + "_" + d.getSlbVirtualServerId() + "_" + d.getGroupId() + "_" + d.getIp());
}
return allDownAppServers;
}
/*
* group server is up while status is 0 .
* */
@Override
public Set<String> findAllUpGroupServersBySlbId(Long slbId) throws Exception {
Set<String> allUpAppServers = new HashSet<>();
List<StatusGroupServerDo> allUpAppServerList = statusGroupServerService.listAllUpBySlbId(slbId);
List<StatusGroupServerDo> allUpAppServerList = statusGroupServerDao.findAllBySlbIdAndStatus( slbId , 0 , StatusGroupServerEntity.READSET_FULL);
for (StatusGroupServerDo d : allUpAppServerList) {
allUpAppServers.add(d.getSlbId() + "_" + d.getSlbVirtualServerId() + "_" + d.getGroupId() + "_" + d.getIp());
}
return allUpAppServers;
}
@Override
public Set<String> findAllGroupServersBySlbIdAndStatusOffset(Long slbId, int offset) throws Exception {
Set<String> allUpAppServers = new HashSet<>();
List<StatusGroupServerDo> allUpAppServerList = statusGroupServerDao.findAllBySlbId(slbId,StatusGroupServerEntity.READSET_FULL);
int tmp = ~(1 << offset);
for (StatusGroupServerDo statusGroupServerDo : allUpAppServerList){
int status = statusGroupServerDo.getStatus();
if (tmp == (status|tmp)){
allUpAppServers.add(statusGroupServerDo.getSlbId() + "_" + statusGroupServerDo.getSlbVirtualServerId() + "_" + statusGroupServerDo.getGroupId() + "_" + statusGroupServerDo.getIp());
}
}
return allUpAppServers;
}
@Override
public void upServer(String ip) throws Exception {
@ -151,6 +161,58 @@ public class StatusServiceImpl implements StatusService {
}
}
@Override
public void updateStatus(Long slbId, Long groupId, List<String> ips, int offset, boolean status) throws Exception {
if (offset > 30 || offset < 0){
throw new Exception("offset of status should be [0-30]");
}
Group group;
if(activateService.isGroupActivated(groupId,slbId)){
group = activateService.getActivatedGroup(groupId,slbId);
}else {
group = groupRepository.getById(groupId);
}
if (group == null){
return;
}
List<GroupVirtualServer> groupVirtualServers = group.getGroupVirtualServers();
List<Long> vsIds = new ArrayList<>();
for (GroupVirtualServer groupVirtualServer : groupVirtualServers) {
if (!groupVirtualServer.getVirtualServer().getSlbId().equals(slbId)) {
continue;
}
vsIds.add(groupVirtualServer.getVirtualServer().getId());
}
for (GroupVirtualServer groupVirtualServer : groupVirtualServers){
if (!groupVirtualServer.getVirtualServer().getSlbId().equals(slbId)){
continue;
}
for (String ip : ips) {
if (ip==null||ip.isEmpty())
{
continue;
}
statusGroupServerDao.deleteByGroupIdAndSlbIdAndIpAndExSlbVirtualServerIds(new StatusGroupServerDo()
.setSlbId(slbId)
.setGroupId(groupId)
.setIp(ip).setExVirtualServerIds(vsIds.toArray(new Long[]{})));
StatusGroupServerDo data = new StatusGroupServerDo();
data.setSlbId(slbId)
.setSlbVirtualServerId(groupVirtualServer.getVirtualServer().getId())
.setGroupId(groupId)
.setIp(ip);
int reset = ~(1 << offset);
int updatestatus = (status?0:1)<<offset;
data.setReset(reset).setStatus(updatestatus);
statusGroupServerDao.updateStatus(data);
}
logger.info("[update status]: VirtualServer:"+groupVirtualServer.toString()+"ips:"+ips.toString());
}
}
@Override
public boolean getGroupServerStatus(Long slbId, Long groupId, String vsip) throws Exception {

View file

@ -9,4 +9,5 @@ public class TaskOpsType {
public static final String ACTIVATE_SLB= "Activate_SLB";
public static final String SERVER_OPS= "Server_Ops";
public static final String MEMBER_OPS= "Member_Ops";
public static final String PULL_MEMBER_OPS= "Pull_Member_Ops";
}

View file

@ -88,6 +88,7 @@
<var name="key-private-key" value-type="String" key-member="private-key" />
<primary-key name="PRIMARY" members="private_key" />
<index name="time idx" members="DataChange_LastTime ASC" />
<index name="idx_DataChange_LastTime" members="DataChange_LastTime ASC" />
<readsets>
<readset name="FULL" all="true" />
</readsets>
@ -128,6 +129,7 @@
<var name="key-id" value-type="int" key-member="id" />
<primary-key name="PRIMARY" members="id" />
<index name="time_idx" members="DataChange_LastTime ASC" />
<index name="idx_DataChange_LastTime" members="DataChange_LastTime ASC" />
<readsets>
<readset name="FULL" all="true" />
</readsets>
@ -169,6 +171,7 @@
<index name="role_idx" members="role_name ASC" />
<index name="res_idx" members="resource_name ASC" />
<index name="time_idx" members="DataChange_LastTime ASC" />
<index name="idx_DataChange_LastTime" members="DataChange_LastTime ASC" />
<readsets>
<readset name="FULL" all="true" />
</readsets>
@ -209,6 +212,7 @@
<primary-key name="PRIMARY" members="id" />
<index name="role_idx" unique="true" members="role_name ASC" />
<index name="time_idx" members="DataChange_LastTime ASC" />
<index name="idx_DataChange_LastTime" members="DataChange_LastTime ASC" />
<readsets>
<readset name="FULL" all="true" />
</readsets>
@ -249,6 +253,7 @@
<primary-key name="PRIMARY" members="id" />
<index name="usr_name_idx" unique="true" members="user_name ASC" />
<index name="time_idx" members="DataChange_LastTime ASC" />
<index name="idx_DataChange_LastTime" members="DataChange_LastTime ASC" />
<readsets>
<readset name="FULL" all="true" />
</readsets>
@ -290,6 +295,7 @@
<primary-key name="PRIMARY" members="id" />
<index name="usr_idx" members="user_name ASC" />
<index name="time_idx" members="DataChange_LastTime ASC" />
<index name="idx_DataChange_LastTime" members="DataChange_LastTime ASC" />
<readsets>
<readset name="FULL" all="true" />
</readsets>
@ -829,7 +835,6 @@
<primary-key name="PRIMARY" members="id" />
<index name="slb_virtual_server_id_version" unique="true" members="slb_virtual_server_id ASC, version ASC" />
<index name="idx_DataChange_LastTime" members="DataChange_LastTime ASC" />
<index name="idx_slb_id_virtual_server_id_version" members="slb_id ASC, slb_virtual_server_id ASC, version ASC" />
<readsets>
<readset name="FULL" all="true" />
</readsets>
@ -872,7 +877,6 @@
<primary-key name="PRIMARY" members="id" />
<index name="slb_virtual_server_id_version" unique="true" members="slb_virtual_server_id ASC, version ASC" />
<index name="idx_DataChange_LastTime" members="DataChange_LastTime ASC" />
<index name="idx_slb_id_virtual_server_id_version" members="slb_id ASC, slb_virtual_server_id ASC, version ASC" />
<readsets>
<readset name="FULL" all="true" />
</readsets>
@ -959,7 +963,6 @@
<var name="key-id" value-type="long" key-member="id" />
<primary-key name="PRIMARY" members="id" />
<index name="DataChange_LastTime" members="DataChange_LastTime ASC" />
<index name="idx_datetime" members="datetime ASC" />
<readsets>
<readset name="FULL" all="true" />
</readsets>
@ -1636,6 +1639,7 @@
<member name="up" field="up" value-type="boolean" nullable="false" />
<member name="created-time" field="created_time" value-type="Date" />
<member name="data-change-last-time" field="DataChange_LastTime" value-type="Date" nullable="false" />
<member name="status" field="status" value-type="int" length="10" nullable="false" />
<var name="key-id" value-type="long" key-member="id" />
<primary-key name="PRIMARY" members="id" />
<index name="slb_virtual_server_id_group_id_ip" unique="true" members="slb_virtual_server_id ASC, group_id ASC, ip ASC" />

View file

@ -1,6 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<entities do-package="com.ctrip.zeus.dal.core" gen="true" do-class-suffix="Do">
<entity name="status-group-server" table="status_group_server" alias="sas" do-class="StatusGroupServerDo">
<var name="reset" value-type="Integer"/>
<var name="ex-virtual-server-ids" value-type="Long[]"/>
<query-defs>
<query name="insert" type="INSERT">
<statement>
@ -13,6 +15,18 @@
]]>
</statement>
</query>
<query name="update-status" type="INSERT">
<param name="reset"/>
<statement>
<![CDATA[
INSERT INTO <TABLE/>(<FIELDS/>)
VALUES(<VALUES/>)
ON DUPLICATE KEY UPDATE
status = status & ${reset} | values(status),
<FIELD name="data-change-last-time"/> = NOW()
]]>
</statement>
</query>
<query name="find-all" type="SELECT" multiple="true">
<statement>
<![CDATA[
@ -31,6 +45,16 @@
]]>
</statement>
</query>
<query name="find-all-by-slb-id" type="SELECT" multiple="true">
<param name="slb-id"/>
<statement>
<![CDATA[
SELECT <FIELDS/>
FROM <TABLE/>
WHERE <FIELD name='slb-id'/> = ${slb-id}
]]>
</statement>
</query>
<query name="find-all-by-ip" type="SELECT" multiple="true">
<param name="ip"/>
<statement>
@ -53,6 +77,18 @@
]]>
</statement>
</query>
<query name="find-all-by-slb-id-and-status" type="SELECT" multiple="true">
<param name="slb-id"/>
<param name="status"/>
<statement>
<![CDATA[
SELECT <FIELDS/>
FROM <TABLE/>
WHERE <FIELD name='slb-id'/> = ${slb-id}
AND <FIELD name='status'/> = ${status}
]]>
</statement>
</query>
<query name="find-all-by-slb-id-and-group-id-and-ip" type="SELECT" multiple="true">
<param name="slb-id"/>
<param name="group-id"/>
@ -105,6 +141,29 @@
]]>
</statement>
</query>
<query name="delete-by-up" type="DELETE">
<param name="up"/>
<statement>
<![CDATA[
DELETE FROM <TABLE/>
WHERE <FIELD name='up'/> = ${up}
]]>
</statement>
</query>
<query name="delete-by-group-id-and-slb-id-and-ip-and-ex-slb-virtual-server-ids" type="DELETE">
<param name="group-id"/>
<param name="slb-id"/>
<param name="ex-virtual-server-ids"/>
<statement>
<![CDATA[
DELETE FROM <TABLE/>
WHERE <FIELD name='group-id'/> = ${group-id}
AND <FIELD name='slb-id'/> = ${slb-id}
AND <FIELD name='ip'/> = ${ip}
AND <FIELD name='slb-virtual-server-id'/> not in <IN> ${ex-virtual-server-ids} </IN>
]]>
</statement>
</query>
</query-defs>
</entity>
<entity name="status-server" table="status_server" alias="ss" do-class="StatusServerDo">

View file

@ -20,6 +20,7 @@
<element name="port" value-type="int" />
<element name="member" value-type="boolean" />
<element name="server" value-type="boolean" />
<element name="pull" value-type="boolean" />
<element name="up" value-type="boolean" />
<element name="discription" value-type="String" />
</entity>

View file

@ -10,6 +10,7 @@
<port>11</port>
<member>true</member>
<server>true</server>
<pull>true</pull>
<up>true</up>
<discription>status</discription>
</group-server-status>
@ -18,6 +19,7 @@
<port>11</port>
<member>true</member>
<server>true</server>
<pull>true</pull>
<up>true</up>
<discription>status</discription>
</group-server-status>