remove vs/slb from group status and remove hc module

This commit is contained in:
Mengyi Zhou 2016-09-26 14:16:22 +08:00
parent 322d7cf4ec
commit a79bf4a55a
5 changed files with 59 additions and 248 deletions

View file

@ -12,7 +12,6 @@ import com.ctrip.zeus.service.model.SelectionMode;
import com.ctrip.zeus.service.query.CriteriaQueryFactory;
import com.ctrip.zeus.service.query.GroupCriteriaQuery;
import com.ctrip.zeus.service.query.QueryEngine;
import com.ctrip.zeus.service.query.SlbCriteriaQuery;
import com.ctrip.zeus.service.status.GroupStatusService;
import com.ctrip.zeus.status.entity.GroupStatus;
import com.ctrip.zeus.status.entity.GroupStatusList;
@ -42,8 +41,6 @@ public class StatusResource {
@Resource
private GroupCriteriaQuery groupCriteriaQuery;
@Resource
private SlbCriteriaQuery slbCriteriaQuery;
@Resource
private ResponseHandler responseHandler;
@Resource
private GlobalJobDao globalJobDao;
@ -57,15 +54,14 @@ public class StatusResource {
public Response allGroupStatusInSlb(@Context HttpServletRequest request, @Context HttpHeaders hh,
@TrimmedQueryParam("mode") final String mode,
@Context UriInfo uriInfo) throws Exception {
List<GroupStatus> statusList = null;
QueryEngine queryRender = new QueryEngine(QueryParamRender.extractRawQueryParam(uriInfo), "group", SelectionMode.getMode(mode));
queryRender.init(true);
IdVersion[] searchKeys = queryRender.run(criteriaQueryFactory);
Set<Long> groupIds = new HashSet<>();
for (IdVersion idv : searchKeys){
for (IdVersion idv : searchKeys) {
groupIds.add(idv.getId());
}
statusList = groupStatusService.getOfflineGroupsStatus(groupIds);
List<GroupStatus> statusList = groupStatusService.getOfflineGroupsStatus(groupIds);
GroupStatusList result = new GroupStatusList();
for (GroupStatus groupStatus : statusList) {
result.addGroupStatus(groupStatus);
@ -79,41 +75,25 @@ public class StatusResource {
@Authorize(name = "getGroupStatus", uriGroupHint = -1)
public Response groupStatus(@Context HttpServletRequest request, @Context HttpHeaders hh,
@QueryParam("groupId") Long groupId,
@QueryParam("groupName") String groupName,
@QueryParam("slbId") Long slbId,
@QueryParam("slbName") String slbName) throws Exception {
GroupStatus statusResult = null;
@QueryParam("groupName") String groupName) throws Exception {
if (groupId == null) {
if (groupName != null) {
groupId = groupCriteriaQuery.queryByName(groupName);
}
}
if (null == groupId) {
throw new ValidationException("Group Id or Name not found!");
}
if (slbId == null) {
if (slbName != null) {
slbId = slbCriteriaQuery.queryByName(slbName);
}
}
if (null == slbId) {
GroupStatus status = groupStatusService.getOfflineGroupStatus(groupId);
if (status != null) {
statusResult = status;
} else {
throw new ValidationException("Not Found Group Status In Slb!");
}
} else {
GroupStatus res = groupStatusService.getOfflineGroupStatus(groupId, slbId);
if (res != null) {
statusResult = res;
} else {
throw new ValidationException("Not Found Group Status!");
if (groupId == null) {
throw new ValidationException("Cannot find group by groupName " + groupName + ".");
}
IdVersion[] check = groupCriteriaQuery.queryByIdAndMode(groupId, SelectionMode.REDUNDANT);
if (check.length == 0) {
throw new ValidationException("Cannot find group by groupId " + groupId + ".");
}
return responseHandler.handle(statusResult, hh.getMediaType());
GroupStatus status = groupStatusService.getOfflineGroupStatus(groupId);
if (status == null) {
throw new ValidationException("Not Found Group Status In Slb!");
}
return responseHandler.handle(status, hh.getMediaType());
}
@GET

View file

@ -1,94 +0,0 @@
package com.ctrip.zeus.service.build.conf;
import com.ctrip.zeus.model.entity.Group;
import com.ctrip.zeus.model.entity.HealthCheck;
import com.ctrip.zeus.model.entity.VirtualServer;
import com.ctrip.zeus.service.build.ConfigHandler;
import com.ctrip.zeus.util.AssertUtils;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
/**
* @author:xingchaowang
* @date: 3/8/2015.
*/
@Component("healthCheckConf")
public class HealthCheckConf {
@Resource
ConfigHandler configHandler;
public String generate(VirtualServer vs, Group group) throws Exception {
Long vsId = vs.getId();
Long groupId = group.getId();
Long slbId = vs.getSlbId();
if (!configHandler.getEnable("upstream.healthCheck", slbId, vsId, groupId, true)) {
return "";
}
HealthCheck h = group.getHealthCheck();
if (h == null) {
return "";
}
AssertUtils.assertNotNull(h.getIntervals(), "Group HealthCheck Intervals config is null!");
AssertUtils.assertNotNull(h.getFails(), "Group HealthCheck Fails config is null!");
AssertUtils.assertNotNull(h.getPasses(), "Group HealthCheck Passes config is null!");
AssertUtils.assertNotNull(h.getUri(), "Group HealthCheck Uri config is null!");
StringBuilder b = new StringBuilder(128);
String healthCheckTimeout = configHandler.getStringValue("upstream.healthCheck.timeOut", null, vsId, groupId, "2000");
String sslAspx = configHandler.getStringValue("upstream.healthCheck.ssl.aspx", null, vsId, groupId, "/SlbHealthCheck.aspx");
if (group.getSsl() && configHandler.getEnable("upstream.healthCheck.sslHello", null, vsId, groupId, false)) {
b.append(" check interval=").append(h.getIntervals())
.append(" rise=").append(h.getPasses())
.append(" fall=").append(h.getFails())
.append(" timeout=").append(h.getTimeout() == null ? healthCheckTimeout : h.getTimeout())
.append(" type=ssl_hello").append(";\n");
} else if (group.getSsl() && h.getUri().equalsIgnoreCase(sslAspx)) {
b.append(" check interval=").append(h.getIntervals())
.append(" rise=").append(h.getPasses())
.append(" fall=").append(h.getFails())
.append(" timeout=").append(h.getTimeout() == null ? healthCheckTimeout : h.getTimeout());
b.append(" port=").append(80);
b.append(" type=http default_down=false").append(";\n")
.append(" check_keepalive_requests 100").append(";\n")
.append(" check_http_send \"")
.append("GET ").append(h.getUri()).append(" HTTP/1.0\\r\\n")
.append("Connection:keep-alive\\r\\n");
b.append("UserAgent:SLB_HealthCheck").append("\\r\\n\\r\\n\"").append(";\n")
.append(" check_http_expect_alive http_2xx http_3xx").append(";\n");
} else if (group.getSsl()) {
b.append(" check interval=").append(h.getIntervals())
.append(" rise=").append(h.getPasses())
.append(" fall=").append(h.getFails())
.append(" timeout=").append(h.getTimeout() == null ? healthCheckTimeout : h.getTimeout());
b.append(" port=").append(80);
b.append(" type=http default_down=false").append(";\n")
.append(" check_keepalive_requests 100").append(";\n")
.append(" check_http_send \"")
.append("GET ").append(h.getUri()).append(" HTTP/1.1\\r\\n")
.append("Connection:keep-alive\\r\\n")
.append("Host:").append(vs.getDomains().get(0).getName().trim()).append("\\r\\n");
b.append("UserAgent:SLB_HealthCheck").append("\\r\\n\\r\\n\"").append(";\n")
.append(" check_http_expect_alive http_2xx http_3xx").append(";\n");
}else {
b.append(" check interval=").append(h.getIntervals())
.append(" rise=").append(h.getPasses())
.append(" fall=").append(h.getFails())
.append(" timeout=").append(h.getTimeout() == null ? healthCheckTimeout : h.getTimeout());
b.append(" type=http default_down=false").append(";\n")
.append(" check_keepalive_requests 100").append(";\n")
.append(" check_http_send \"")
.append("GET ").append(h.getUri()).append(" HTTP/1.1\\r\\n")
.append("Connection:keep-alive\\r\\n")
.append("Host:").append(vs.getDomains().get(0).getName().trim()).append("\\r\\n");
b.append("User-Agent:SLB_HealthCheck").append("\\r\\n\\r\\n\"").append(";\n")
.append(" check_http_expect_alive http_2xx http_3xx").append(";\n");
}
return b.toString();
}
}

View file

@ -20,8 +20,6 @@ import java.util.*;
public class UpstreamsConf {
@Resource
ConfigHandler configHandler;
@Resource
HealthCheckConf healthCheckConf;
public static final String UpstreamPrefix = "backend_";
@ -113,8 +111,6 @@ public class UpstreamsConf {
confWriter.writeCommand("keepalive_timeout", configHandler.getStringValue("upstream.keepAlive.timeout", slbId, vsId, groupId, "110") + "s");
}
// This module is to be abandoned.
confWriter.getStringBuilder().append(healthCheckConf.generate(vs, group));
confWriter.writeUpstreamEnd();
}

View file

@ -18,6 +18,7 @@ import java.util.Set;
public interface GroupStatusService {
/**
* Find all online groups status
*
* @return status list
* @throws Exception
*/
@ -25,6 +26,7 @@ public interface GroupStatusService {
/**
* Find all online group status in the specific slb cluster
*
* @param slbId
* @return status list
* @throws Exception
@ -33,15 +35,16 @@ public interface GroupStatusService {
/**
* Find online group status by groupId
*
* @param groups groupId
* @param slbId slbId
* @return status list
* @throws Exception
*/
List<GroupStatus> getOnlineGroupsStatus(Map<Long,Group> groups , Long slbId) throws Exception;
List<GroupStatus> getOnlineGroupsStatus(Map<Long, Group> groups) throws Exception;
/**
* Find all online group status by groupIds and slb id
*
* @param groupId groupId
* @return status list
* @throws Exception
@ -50,6 +53,7 @@ public interface GroupStatusService {
/**
* Find all online groups status
*
* @return status list
* @throws Exception
*/
@ -57,6 +61,7 @@ public interface GroupStatusService {
/**
* Find all online group status in the specific slb cluster
*
* @param slbId
* @return status list
* @throws Exception
@ -65,6 +70,7 @@ public interface GroupStatusService {
/**
* Find online group status by groupId
*
* @param groupId groupId
* @return status list
* @throws Exception
@ -73,25 +79,18 @@ public interface GroupStatusService {
/**
* Find online group status by groupId
*
* @param groupIds groupIds
* @return status list
* @throws Exception
*/
List<GroupStatus> getOfflineGroupsStatus(Set<Long> groupIds) throws Exception;
/**
* Find online group status by groupId
* @param groupId groupId
* @return status list
* @throws Exception
*/
GroupStatus getOfflineGroupStatus(Long groupId,Long slbId) throws Exception;
/**
* Find all online group status by groupIds and slb id
* @param slbId slbId
*
* @return status list
* @throws Exception
*/
List<GroupStatus> getOfflineGroupsStatus(Map<Long,Group> groups ,Map<Long,Group> onlineGroups , Long slbId) throws Exception;
List<GroupStatus> getOfflineGroupsStatus(Map<Long, Group> groups, Map<Long, Group> onlineGroups) throws Exception;
}

View file

@ -1,18 +1,13 @@
package com.ctrip.zeus.service.status.impl;
import com.ctrip.zeus.dal.core.ConfSlbActiveDao;
import com.ctrip.zeus.exceptions.ValidationException;
import com.ctrip.zeus.model.entity.Group;
import com.ctrip.zeus.model.entity.GroupServer;
import com.ctrip.zeus.model.entity.GroupVirtualServer;
import com.ctrip.zeus.model.entity.VirtualServer;
import com.ctrip.zeus.service.build.ConfigHandler;
import com.ctrip.zeus.service.model.*;
import com.ctrip.zeus.service.query.GroupCriteriaQuery;
import com.ctrip.zeus.service.query.SlbCriteriaQuery;
import com.ctrip.zeus.service.query.VirtualServerCriteriaQuery;
import com.ctrip.zeus.service.status.GroupStatusService;
import com.ctrip.zeus.service.status.HealthCheckStatusService;
import com.ctrip.zeus.service.status.StatusOffset;
import com.ctrip.zeus.service.status.StatusService;
import com.ctrip.zeus.status.entity.GroupServerStatus;
@ -51,10 +46,6 @@ public class GroupStatusServiceImpl implements GroupStatusService {
ConfSlbActiveDao confSlbActiveDao;
@Resource
EntityFactory entityFactory;
@Resource
private HealthCheckStatusService healthCheckStatusService;
@Resource
private ConfigHandler configHandler;
private Logger LOGGER = LoggerFactory.getLogger(GroupStatusServiceImpl.class);
@ -87,7 +78,7 @@ public class GroupStatusServiceImpl implements GroupStatusService {
if (groups.getOnlineMapping() == null || groups.getOnlineMapping().size() == 0) {
return result;
}
result = getOnlineGroupsStatus(groups.getOnlineMapping(), slbId);
result = getOnlineGroupsStatus(groups.getOnlineMapping());
return result;
}
@ -99,39 +90,18 @@ public class GroupStatusServiceImpl implements GroupStatusService {
if (groups.getOfflineMapping() == null || groups.getOfflineMapping().size() == 0) {
return result;
}
result = getOfflineGroupsStatus(groups.getOfflineMapping(), groups.getOnlineMapping(), slbId);
result = getOfflineGroupsStatus(groups.getOfflineMapping(), groups.getOnlineMapping());
return result;
}
@Override
public GroupStatus getOnlineGroupStatus(Long groupId) throws Exception {
GroupStatus result = null;
ModelStatusMapping<Group> map = entityFactory.getGroupsByIds(new Long[]{groupId});
if (map.getOnlineMapping() == null || map.getOnlineMapping().size() == 0) {
ModelStatusMapping<Group> groupMap = entityFactory.getGroupsByIds(new Long[]{groupId});
if (groupMap.getOnlineMapping().size() == 0) {
return result;
}
List<Long> vsId = new ArrayList<>();
for (GroupVirtualServer gvs : map.getOnlineMapping().get(groupId).getGroupVirtualServers()) {
vsId.add(gvs.getVirtualServer().getId());
}
ModelStatusMapping<VirtualServer> vsMap = entityFactory.getVsesByIds(vsId.toArray(new Long[]{}));
if (vsMap.getOnlineMapping() == null || vsMap.getOnlineMapping().size() == 0) {
return result;
}
Long slbId = null;
for (Long vid : vsMap.getOnlineMapping().keySet()) {
Long tmp = vsMap.getOnlineMapping().get(vid).getSlbId();
if (tmp != null) {
slbId = tmp;
if (configHandler.getEnable("healthy.operation.active", slbId, null, null, false)) {
break;
}
}
if (slbId == null) {
throw new ValidationException("Not found slbId for Group Id:" + groupId);
}
}
List<GroupStatus> list = getOnlineGroupsStatus(map.getOnlineMapping(), slbId);
List<GroupStatus> list = getOnlineGroupsStatus(groupMap.getOnlineMapping());
if (list.size() > 0) {
result = list.get(0);
}
@ -141,32 +111,12 @@ public class GroupStatusServiceImpl implements GroupStatusService {
@Override
public GroupStatus getOfflineGroupStatus(Long groupId) throws Exception {
GroupStatus result = null;
ModelStatusMapping<Group> map = entityFactory.getGroupsByIds(new Long[]{groupId});
if (map.getOfflineMapping() == null || map.getOfflineMapping().size() == 0) {
ModelStatusMapping<Group> groupMap = entityFactory.getGroupsByIds(new Long[]{groupId});
if (groupMap.getOfflineMapping().size() == 0) {
return result;
}
List<Long> vsId = new ArrayList<>();
for (GroupVirtualServer gvs : map.getOfflineMapping().get(groupId).getGroupVirtualServers()) {
vsId.add(gvs.getVirtualServer().getId());
}
ModelStatusMapping<VirtualServer> vsMap = entityFactory.getVsesByIds(vsId.toArray(new Long[]{}));
if (vsMap.getOfflineMapping() == null || vsMap.getOfflineMapping().size() == 0) {
return result;
}
Long slbId = null;
for (Long vid : vsMap.getOfflineMapping().keySet()) {
Long tmp = vsMap.getOfflineMapping().get(vid).getSlbId();
if (tmp != null) {
slbId = tmp;
if (configHandler.getEnable("healthy.operation.active", slbId, null, null, false)) {
break;
}
}
}
if (slbId == null) {
throw new ValidationException("Not found slbId for Group Id:" + groupId);
}
List<GroupStatus> list = getOfflineGroupsStatus(map.getOfflineMapping(), map.getOnlineMapping(), slbId);
List<GroupStatus> list = getOfflineGroupsStatus(groupMap.getOfflineMapping(), groupMap.getOnlineMapping());
if (list.size() > 0) {
result = list.get(0);
}
@ -180,41 +130,24 @@ public class GroupStatusServiceImpl implements GroupStatusService {
if (map.getOfflineMapping() == null || map.getOfflineMapping().size() == 0) {
return result;
}
result = getOfflineGroupsStatus(map.getOfflineMapping(), map.getOnlineMapping(), -1L);
result = getOfflineGroupsStatus(map.getOfflineMapping(), map.getOnlineMapping());
return result;
}
@Override
public GroupStatus getOfflineGroupStatus(Long groupId, Long slbId) throws Exception {
GroupStatus result = null;
ModelStatusMapping<Group> map = entityFactory.getGroupsByIds(new Long[]{groupId});
if (map.getOfflineMapping() == null || map.getOfflineMapping().size() == 0) {
return result;
}
List<GroupStatus> list = getOfflineGroupsStatus(map.getOfflineMapping(), map.getOnlineMapping(), slbId);
if (list.size() > 0) {
result = list.get(0);
}
return result;
}
@Override
public List<GroupStatus> getOnlineGroupsStatus(Map<Long, Group> groups, Long slbId) throws Exception {
public List<GroupStatus> getOnlineGroupsStatus(Map<Long, Group> groups) throws Exception {
List<GroupStatus> res = new ArrayList<>();
GroupStatus status = null;
boolean healthyActivateFlag = healthyOpsActivate.get() && configHandler.getEnable("healthy.operation.active", slbId, null, null, false);
GroupStatus status = new GroupStatus();
Map<String, List<Boolean>> memberStatus = statusService.fetchGroupServerStatus(groups.keySet().toArray(new Long[]{}));
Set<String> allDownServers = statusService.findAllDownServers();
for (Group group : groups.values()) {
Long groupId = group.getId();
status = new GroupStatus();
status.setGroupId(groupId);
status.setSlbId(slbId);
status.setGroupName(group.getName());
status.setActivated(true);
List<GroupServer> groupServerList = group.getGroupServers();//groupRepository.listGroupServersByGroup(groupId);
List<GroupServer> groupServerList = group.getGroupServers();
for (GroupServer gs : groupServerList) {
GroupServerStatus groupServerStatus = new GroupServerStatus();
groupServerStatus.setIp(gs.getIp());
@ -229,7 +162,7 @@ public class GroupStatusServiceImpl implements GroupStatusService {
boolean pullIn = memberStatus.get(key).get(StatusOffset.PULL_OPS);
boolean raise = memberStatus.get(key).get(StatusOffset.HEALTHY);
boolean up = false;
if (healthyActivateFlag) {
if (healthyOpsActivate.get()) {
up = memberUp && serverUp && pullIn && raise;
} else {
if (memberUp && serverUp && pullIn) {
@ -253,19 +186,16 @@ public class GroupStatusServiceImpl implements GroupStatusService {
}
@Override
public List<GroupStatus> getOfflineGroupsStatus(Map<Long, Group> groups, Map<Long, Group> onlineGroups, Long slbId) throws Exception {
public List<GroupStatus> getOfflineGroupsStatus(Map<Long, Group> groups, Map<Long, Group> onlineGroups) throws Exception {
List<GroupStatus> res = new ArrayList<>();
GroupStatus status = null;
boolean healthyActivateFlag = healthyOpsActivate.get() && configHandler.getEnable("healthy.operation.active", slbId, null, null, false);
Map<String, List<Boolean>> memberStatus = statusService.fetchGroupServerStatus(groups.keySet().toArray(new Long[]{}));
Set<String> allDownServers = statusService.findAllDownServers();
for (Group group : groups.values()) {
GroupStatus status = new GroupStatus();
Long groupId = group.getId();
status = new GroupStatus();
status.setGroupId(groupId);
status.setSlbId(slbId);
status.setGroupName(group.getName());
status.setActivated(onlineGroups.containsKey(groupId));
@ -299,7 +229,7 @@ public class GroupStatusServiceImpl implements GroupStatusService {
boolean raise = memberStatus.get(key).get(StatusOffset.HEALTHY);
boolean up = false;
NextStatus nextStatus = NextStatus.Online;
if (healthyActivateFlag) {
if (healthyOpsActivate.get()) {
up = memberUp && serverUp && pullIn && raise;
} else {
if (memberUp && serverUp && pullIn) {