mirror of
https://github.com/ctripcorp/zeus.git
synced 2024-11-11 01:24:27 +08:00
Merge branch 'github_dev' into task_rebuild
Conflicts: src/main/java/com/ctrip/zeus/service/model/GroupRepository.java src/main/java/com/ctrip/zeus/service/model/impl/GroupRepositoryImpl.java src/main/resources/META-INF/wizard/jdbc/wizard.xml
This commit is contained in:
commit
a86d30f971
20 changed files with 408 additions and 28 deletions
|
@ -131,6 +131,72 @@ public class GroupResource {
|
|||
return input;
|
||||
}
|
||||
})
|
||||
.addFilterId(new FilterSet<Long>() {
|
||||
@Override
|
||||
public Set<Long> filter(Set<Long> input) throws Exception {
|
||||
input.removeAll(groupCriteriaQuery.queryAllVGroups());
|
||||
return input;
|
||||
}
|
||||
})
|
||||
.build();
|
||||
for (Group group : groupRepository.list(executer.run())) {
|
||||
groupList.addGroup(getGroupByType(group, type));
|
||||
}
|
||||
groupList.setTotal(groupList.getGroups().size());
|
||||
return responseHandler.handle(groupList, hh.getMediaType());
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("/vgroups")
|
||||
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
|
||||
@Authorize(name = "getAllGroups")
|
||||
public Response listVGroups(@Context HttpHeaders hh,
|
||||
@Context HttpServletRequest request,
|
||||
@QueryParam("slbId") final Long slbId,
|
||||
@TrimmedQueryParam("domain") final String domain,
|
||||
@TrimmedQueryParam("type") String type,
|
||||
@TrimmedQueryParam("tag") final String tag,
|
||||
@TrimmedQueryParam("pname") final String pname,
|
||||
@TrimmedQueryParam("pvalue") final String pvalue) throws Exception {
|
||||
GroupList groupList = new GroupList();
|
||||
QueryExecuter executer = new QueryExecuter.Builder()
|
||||
.addFilterId(new FilterSet<Long>() {
|
||||
@Override
|
||||
public Set<Long> filter(Set<Long> input) throws Exception {
|
||||
return groupCriteriaQuery.queryAllVGroups();
|
||||
}
|
||||
})
|
||||
.addFilterId(new FilterSet<Long>() {
|
||||
@Override
|
||||
public Set<Long> filter(Set<Long> input) throws Exception {
|
||||
if (tag != null) {
|
||||
input.retainAll(tagService.query(tag, "group"));
|
||||
}
|
||||
return input;
|
||||
}
|
||||
})
|
||||
.addFilterId(new FilterSet<Long>() {
|
||||
@Override
|
||||
public Set<Long> filter(Set<Long> input) throws Exception {
|
||||
if (pname != null) {
|
||||
if (pvalue != null)
|
||||
input.retainAll(propertyService.query(pname, pvalue, "group"));
|
||||
else
|
||||
input.retainAll(propertyService.query(pname, "group"));
|
||||
}
|
||||
return input;
|
||||
}
|
||||
})
|
||||
.addFilterId(new FilterSet<Long>() {
|
||||
@Override
|
||||
public Set<Long> filter(Set<Long> input) throws Exception {
|
||||
if (domain != null) {
|
||||
Set<Long> vsIds = virtualServerCriteriaQuery.queryByDomain(domain);
|
||||
input.retainAll(groupCriteriaQuery.queryByVsIds(vsIds.toArray(new Long[vsIds.size()])));
|
||||
}
|
||||
return input;
|
||||
}
|
||||
})
|
||||
.build();
|
||||
for (Group group : groupRepository.list(executer.run())) {
|
||||
groupList.addGroup(getGroupByType(group, type));
|
||||
|
@ -172,6 +238,15 @@ public class GroupResource {
|
|||
return responseHandler.handle(g, hh.getMediaType());
|
||||
}
|
||||
|
||||
@POST
|
||||
@Path("/vgroup/new")
|
||||
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, "*/*"})
|
||||
@Authorize(name = "addGroup")
|
||||
public Response addVGroup(@Context HttpHeaders hh, @Context HttpServletRequest request, String group) throws Exception {
|
||||
Group g = groupRepository.addVGroup(parseGroup(hh.getMediaType(), group));
|
||||
return responseHandler.handle(g, hh.getMediaType());
|
||||
}
|
||||
|
||||
@POST
|
||||
@Path("/group/update")
|
||||
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, "*/*"})
|
||||
|
@ -188,6 +263,22 @@ public class GroupResource {
|
|||
return responseHandler.handle(g, hh.getMediaType());
|
||||
}
|
||||
|
||||
@POST
|
||||
@Path("/vgroup/update")
|
||||
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, "*/*"})
|
||||
@Authorize(name = "updateGroup")
|
||||
public Response updateVGroup(@Context HttpHeaders hh, @Context HttpServletRequest request, String group) throws Exception {
|
||||
Group g = parseGroup(hh.getMediaType(), group);
|
||||
DistLock lock = dbLockFactory.newLock(g.getName() + "_updateGroup");
|
||||
try {
|
||||
lock.lock();
|
||||
g = groupRepository.updateVGroup(g);
|
||||
} finally {
|
||||
lock.unlock();
|
||||
}
|
||||
return responseHandler.handle(g, hh.getMediaType());
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("/group/delete")
|
||||
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
|
||||
|
@ -199,6 +290,17 @@ public class GroupResource {
|
|||
return Response.ok().build();
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("/vgroup/delete")
|
||||
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
|
||||
@Authorize(name = "deleteGroup")
|
||||
public Response deleteVGroup(@Context HttpHeaders hh, @Context HttpServletRequest request, @QueryParam("groupId") Long groupId) throws Exception {
|
||||
if (groupId == null)
|
||||
throw new Exception("Missing parameter.");
|
||||
groupRepository.deleteVGroup(groupId);
|
||||
return Response.ok().build();
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("/group/upgradeAll")
|
||||
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
|
||||
|
@ -234,18 +336,23 @@ public class GroupResource {
|
|||
throw new Exception("Group cannot be parsed.");
|
||||
}
|
||||
}
|
||||
g.setAppId(g.getAppId().trim());
|
||||
g.setName(g.getName().trim());
|
||||
g.setAppId(trimIfNotNull(g.getAppId()));
|
||||
g.setName(trimIfNotNull(g.getName()));
|
||||
if (g.getHealthCheck() != null)
|
||||
g.getHealthCheck().setUri(g.getHealthCheck().getUri().trim());
|
||||
g.getHealthCheck().setUri(trimIfNotNull(g.getHealthCheck().getUri()));
|
||||
for (GroupServer groupServer : g.getGroupServers()) {
|
||||
groupServer.setIp(groupServer.getIp().trim());
|
||||
groupServer.setHostName(groupServer.getHostName().trim());
|
||||
groupServer.setIp(trimIfNotNull(groupServer.getIp()));
|
||||
groupServer.setHostName(trimIfNotNull(groupServer.getHostName()));
|
||||
}
|
||||
g.getLoadBalancingMethod().setValue(g.getLoadBalancingMethod().getValue());
|
||||
if (g.getLoadBalancingMethod() != null)
|
||||
g.getLoadBalancingMethod().setValue(trimIfNotNull(g.getLoadBalancingMethod().getValue()));
|
||||
return g;
|
||||
}
|
||||
|
||||
private String trimIfNotNull(String value) {
|
||||
return value != null ? value.trim() : value;
|
||||
}
|
||||
|
||||
private Group getGroupByType(Group group, String type) {
|
||||
if ("INFO".equalsIgnoreCase(type)) {
|
||||
return new Group().setId(group.getId())
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package com.ctrip.zeus.service.build.conf;
|
||||
|
||||
import com.ctrip.zeus.exceptions.ValidationException;
|
||||
import com.ctrip.zeus.model.entity.Group;
|
||||
import com.ctrip.zeus.model.entity.GroupVirtualServer;
|
||||
import com.ctrip.zeus.model.entity.Slb;
|
||||
|
@ -28,11 +29,23 @@ public class LocationConf {
|
|||
private static DynamicStringProperty errorPage_500 = DynamicPropertyFactory.getInstance().getStringProperty("errorPage.500.url", null);//"http://slberrorpages.ctripcorp.com/slberrorpages/500.htm");
|
||||
private static DynamicBooleanProperty errorPageEnable = DynamicPropertyFactory.getInstance().getBooleanProperty("errorPage.enable", false);//"http://slberrorpages.ctripcorp.com/slberrorpages/500.htm");
|
||||
private static DynamicBooleanProperty errorPageEnableAll = DynamicPropertyFactory.getInstance().getBooleanProperty("errorPage.enable-all", false);//"http://slberrorpages.ctripcorp.com/slberrorpages/500.htm");
|
||||
private static DynamicStringProperty upstreamKeepAlive = DynamicPropertyFactory.getInstance().getStringProperty("upstream.keep-alive", null);//"http://slberrorpages.ctripcorp.com/slberrorpages/500.htm");
|
||||
|
||||
public static String generate(Slb slb, VirtualServer vs, Group group, String upstreamName)throws Exception {
|
||||
StringBuilder b = new StringBuilder(1024);
|
||||
|
||||
if (group.isVirtual()){
|
||||
b.append("location ").append(getPath(slb, vs, group)).append(" {\n");
|
||||
if (group.getGroupVirtualServers().size()==1)
|
||||
{
|
||||
b.append("rewrite ").append(group.getGroupVirtualServers().get(0).getRedirect()).append(" redirect;\n");
|
||||
}else {
|
||||
throw new ValidationException("Virtual Group has Multiple Group VirtualServers Redirect");
|
||||
}
|
||||
b.append("}\n");
|
||||
return b.toString();
|
||||
}
|
||||
b.append("location ").append(getPath(slb, vs, group)).append(" {\n");
|
||||
|
||||
if (clientMaxSizeList.get() !=null)
|
||||
{
|
||||
String []sizeList = clientMaxSizeList.get().split(";");
|
||||
|
@ -53,6 +66,7 @@ public class LocationConf {
|
|||
b.append("proxy_set_header Host $host").append(";\n");
|
||||
|
||||
b.append("proxy_set_header X-Real-IP $remote_addr;\n");
|
||||
addKeepAliveSettings(b,group.getId());
|
||||
|
||||
addProxyReadTimeout(group.getId(),b);
|
||||
|
||||
|
@ -101,6 +115,23 @@ public class LocationConf {
|
|||
return b.toString();
|
||||
}
|
||||
|
||||
private static void addKeepAliveSettings(StringBuilder b,Long groupId) {
|
||||
String tmp = upstreamKeepAlive.get();
|
||||
if (tmp==null||tmp.trim().equals("")){
|
||||
return;
|
||||
}else if (tmp.equals("All")){
|
||||
b.append("proxy_set_header Connection \"\";\n");
|
||||
}else {
|
||||
String[] pairs = tmp.split(";");
|
||||
for (String pair : pairs){
|
||||
String[] t = pair.split("=");
|
||||
if (t.length==2&&t[0].trim().equals(String.valueOf(groupId))){
|
||||
b.append("proxy_set_header Connection \"\";\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void addProxyReadTimeout(Long gid , StringBuilder sb) {
|
||||
String defaultConfig = proxyTimeoutDefault.get();
|
||||
String config = proxyTimeoutList.get();
|
||||
|
|
|
@ -24,7 +24,7 @@ public class NginxConf {
|
|||
"'\"$query_string\" $server_port $remote_user $remote_addr $http_x_forwarded_for '\n" +
|
||||
"'$server_protocol \"$http_user_agent\" \"$cookie_COOKIE\" \"$http_referer\" '\n" +
|
||||
"'$host $status $body_bytes_sent $request_time $upstream_response_time '\n" +
|
||||
"'$upstream_addr $upstream_status';\n"
|
||||
"'$upstream_addr $upstream_status $proxy_host';\n"
|
||||
);
|
||||
|
||||
|
||||
|
|
|
@ -6,6 +6,9 @@ import com.ctrip.zeus.model.entity.Slb;
|
|||
import com.ctrip.zeus.model.entity.VirtualServer;
|
||||
import com.ctrip.zeus.util.AssertUtils;
|
||||
import com.ctrip.zeus.util.StringFormat;
|
||||
import com.netflix.config.DynamicIntProperty;
|
||||
import com.netflix.config.DynamicPropertyFactory;
|
||||
import com.netflix.config.DynamicStringProperty;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
@ -16,6 +19,9 @@ import java.util.Set;
|
|||
* @date: 3/10/2015.
|
||||
*/
|
||||
public class UpstreamsConf {
|
||||
private static DynamicStringProperty upstreamKeepAlive = DynamicPropertyFactory.getInstance().getStringProperty("upstream.keep-alive", null);//"http://slberrorpages.ctripcorp.com/slberrorpages/500.htm");
|
||||
private static DynamicIntProperty upstreamKeepAliveDefault = DynamicPropertyFactory.getInstance().getIntProperty("upstream.keep-alive.default", 100);//"http://slberrorpages.ctripcorp.com/slberrorpages/500.htm");
|
||||
|
||||
public static String generate(Slb slb, VirtualServer vs, List<Group> groups, Set<String> allDownServers, Set<String> allUpGroupServers)throws Exception {
|
||||
StringBuilder b = new StringBuilder(10240);
|
||||
|
||||
|
@ -34,6 +40,9 @@ public class UpstreamsConf {
|
|||
}
|
||||
|
||||
public static String buildUpstreamConf(Slb slb, VirtualServer vs, Group group, String upstreamName, Set<String> allDownServers, Set<String> allUpGroupServers) throws Exception {
|
||||
if (group.isVirtual()){
|
||||
return "";
|
||||
}
|
||||
StringBuilder b = new StringBuilder(1024);
|
||||
String body = buildUpstreamConfBody(slb,vs,group,allDownServers,allUpGroupServers);
|
||||
if (null == body){
|
||||
|
@ -79,11 +88,28 @@ public class UpstreamsConf {
|
|||
.append(isDown?" down":"")
|
||||
.append(";\n");
|
||||
}
|
||||
|
||||
addKeepAliveSetting(b,group.getId());
|
||||
//HealthCheck
|
||||
b.append(HealthCheckConf.generate(slb, vs, group));
|
||||
|
||||
return b.toString();
|
||||
}
|
||||
|
||||
private static void addKeepAliveSetting(StringBuilder b, Long gid) {
|
||||
String tmp = upstreamKeepAlive.get();
|
||||
if (tmp==null||tmp.trim().equals("")){
|
||||
return;
|
||||
}else if (tmp.equals("All")){
|
||||
b.append("keepalive ").append(upstreamKeepAliveDefault.get()).append(";\n");
|
||||
}else {
|
||||
String[] pairs = tmp.split(";");
|
||||
for (String pair : pairs){
|
||||
String[] t = pair.split("=");
|
||||
if (t.length==2&&t[0].trim().equals(String.valueOf(gid))){
|
||||
b.append("keepalive ").append(t[1]).append(";\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -12,6 +12,7 @@ import javax.annotation.Resource;
|
|||
public class AutoFiller {
|
||||
@Resource
|
||||
private VirtualServerRepository virtualServerRepository;
|
||||
private static final String RegexRootPath = " /";
|
||||
|
||||
public void autofill(Group group) throws Exception {
|
||||
for (GroupVirtualServer gvs : group.getGroupVirtualServers()) {
|
||||
|
@ -23,7 +24,10 @@ public class AutoFiller {
|
|||
tvs.getDomains().add(domain);
|
||||
}
|
||||
if (gvs.getPriority() == null) {
|
||||
gvs.setPriority(gvs.getRewrite() == null ? 1000 : -1000);
|
||||
if (gvs.getPath().endsWith(RegexRootPath))
|
||||
gvs.setPriority(Integer.MIN_VALUE);
|
||||
else
|
||||
gvs.setPriority(gvs.getRewrite() == null ? 1000 : -1000);
|
||||
}
|
||||
}
|
||||
HealthCheck hc = group.getHealthCheck();
|
||||
|
@ -44,6 +48,27 @@ public class AutoFiller {
|
|||
}
|
||||
}
|
||||
|
||||
public void autofillVGroup(Group group) throws Exception {
|
||||
for (GroupVirtualServer gvs : group.getGroupVirtualServers()) {
|
||||
VirtualServer tvs = gvs.getVirtualServer();
|
||||
VirtualServer vs = virtualServerRepository.getById(gvs.getVirtualServer().getId());
|
||||
tvs.setName(vs.getName()).setSlbId(vs.getSlbId()).setPort(vs.getPort()).setSsl(vs.getSsl());
|
||||
tvs.getDomains().clear();
|
||||
for (Domain domain : vs.getDomains()) {
|
||||
tvs.getDomains().add(domain);
|
||||
}
|
||||
if (gvs.getPriority() == null) {
|
||||
if (gvs.getPath().endsWith(RegexRootPath))
|
||||
gvs.setPriority(Integer.MIN_VALUE);
|
||||
else
|
||||
gvs.setPriority(gvs.getRewrite() == null ? 1000 : -1000);
|
||||
}
|
||||
}
|
||||
group.setHealthCheck(null);
|
||||
group.setLoadBalancingMethod(null);
|
||||
group.getGroupServers().clear();
|
||||
}
|
||||
|
||||
public void autofill(Slb slb) throws Exception {
|
||||
slb.setNginxBin("/opt/app/nginx/sbin").setNginxConf("/opt/app/nginx/conf").setNginxWorkerProcesses(9)
|
||||
.setStatus(slb.getStatus() == null ? "Default" : slb.getStatus());
|
||||
|
|
|
@ -17,10 +17,16 @@ public interface GroupRepository extends Repository {
|
|||
|
||||
Group add(Group group) throws Exception;
|
||||
|
||||
Group addVGroup(Group group) throws Exception;
|
||||
|
||||
Group update(Group group) throws Exception;
|
||||
|
||||
Group updateVGroup(Group group) throws Exception;
|
||||
|
||||
int delete(Long groupId) throws Exception;
|
||||
|
||||
int deleteVGroup(Long groupId) throws Exception;
|
||||
|
||||
@Deprecated
|
||||
List<Group> listGroupsByGroupServer(String groupServerIp) throws Exception;
|
||||
|
||||
|
|
|
@ -12,6 +12,8 @@ public interface GroupSync {
|
|||
|
||||
void add(Group group) throws Exception;
|
||||
|
||||
void add(Group group, boolean isVirtual) throws Exception;
|
||||
|
||||
void update(Group group) throws Exception;
|
||||
|
||||
void updateVersion(Long[] groupIds) throws Exception;
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
package com.ctrip.zeus.service.model.handler;
|
||||
|
||||
import com.ctrip.zeus.model.entity.Group;
|
||||
|
||||
/**
|
||||
* Created by zhoumy on 2015/11/23.
|
||||
*/
|
||||
public interface VGroupValidator extends ModelValidator<Group> {
|
||||
}
|
|
@ -33,11 +33,14 @@ public class DefaultGroupValidator implements GroupValidator {
|
|||
@Resource
|
||||
private RGroupVsDao rGroupVsDao;
|
||||
@Resource
|
||||
private RGroupVgDao rGroupVgDao;
|
||||
@Resource
|
||||
private GroupDao groupDao;
|
||||
|
||||
@Override
|
||||
public boolean exists(Long targetId) throws Exception {
|
||||
return groupDao.findById(targetId, GroupEntity.READSET_FULL) != null;
|
||||
return groupDao.findById(targetId, GroupEntity.READSET_FULL) != null
|
||||
&& rGroupVgDao.findByGroup(targetId, RGroupVgEntity.READSET_FULL) == null;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -0,0 +1,55 @@
|
|||
package com.ctrip.zeus.service.model.handler.impl;
|
||||
|
||||
import com.ctrip.zeus.dal.core.GroupDao;
|
||||
import com.ctrip.zeus.dal.core.GroupEntity;
|
||||
import com.ctrip.zeus.dal.core.RGroupVgDao;
|
||||
import com.ctrip.zeus.dal.core.RGroupVgEntity;
|
||||
import com.ctrip.zeus.exceptions.ValidationException;
|
||||
import com.ctrip.zeus.model.entity.Group;
|
||||
import com.ctrip.zeus.model.entity.GroupVirtualServer;
|
||||
import com.ctrip.zeus.service.model.handler.GroupValidator;
|
||||
import com.ctrip.zeus.service.model.handler.VGroupValidator;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
/**
|
||||
* Created by zhoumy on 2015/11/23.
|
||||
*/
|
||||
@Component("vGroupValidator")
|
||||
public class DefaultVGroupValidator implements VGroupValidator {
|
||||
@Resource
|
||||
private RGroupVgDao rGroupVgDao;
|
||||
@Resource
|
||||
private GroupDao groupDao;
|
||||
@Resource
|
||||
private GroupValidator groupModelValidator;
|
||||
|
||||
@Override
|
||||
public boolean exists(Long targetId) throws Exception {
|
||||
return groupDao.findById(targetId, GroupEntity.READSET_FULL) != null
|
||||
&& rGroupVgDao.findByGroup(targetId, RGroupVgEntity.READSET_FULL) != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void validate(Group target) throws Exception {
|
||||
if (target.getName() == null || target.getName().isEmpty()) {
|
||||
throw new ValidationException("Group name is required.");
|
||||
}
|
||||
groupModelValidator.validateGroupVirtualServers(target.getId(), target.getGroupVirtualServers());
|
||||
for (GroupVirtualServer groupVirtualServer : target.getGroupVirtualServers()) {
|
||||
if (groupVirtualServer.getRedirect() == null)
|
||||
throw new ValidationException("Redirect value is required.");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void checkVersion(Group target) throws Exception {
|
||||
groupModelValidator.checkVersion(target);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removable(Long targetId) throws Exception {
|
||||
groupModelValidator.removable(targetId);
|
||||
}
|
||||
}
|
|
@ -29,11 +29,16 @@ public class GroupEntityManager implements GroupSync {
|
|||
private RGroupVsDao rGroupVsDao;
|
||||
@Resource
|
||||
private RGroupGsDao rGroupGsDao;
|
||||
@Resource
|
||||
private RGroupVgDao rGroupVgDao;
|
||||
|
||||
@Override
|
||||
public void add(Group group) throws Exception {
|
||||
group.setVersion(1);
|
||||
GroupDo d = C.toGroupDo(0L, group);
|
||||
if (d.getAppId() == null)
|
||||
// if app id is null, it must be virtual group
|
||||
d.setAppId("VirtualGroup");
|
||||
groupDao.insert(d);
|
||||
group.setId(d.getId());
|
||||
archiveGroupDao.insert(new ArchiveGroupDo().setGroupId(group.getId()).setVersion(group.getVersion()).setContent(ContentWriters.writeGroupContent(group)));
|
||||
|
@ -41,6 +46,13 @@ public class GroupEntityManager implements GroupSync {
|
|||
relSyncGs(group, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void add(Group group, boolean isVirtual) throws Exception {
|
||||
add(group);
|
||||
if (isVirtual)
|
||||
relSyncVg(group);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(Group group) throws Exception {
|
||||
GroupDo check = groupDao.findById(group.getId(), GroupEntity.READSET_FULL);
|
||||
|
@ -48,7 +60,7 @@ public class GroupEntityManager implements GroupSync {
|
|||
throw new ValidationException("Newer Group version is detected.");
|
||||
group.setVersion(group.getVersion() + 1);
|
||||
|
||||
GroupDo d = C.toGroupDo(group.getId(), group);
|
||||
GroupDo d = C.toGroupDo(group.getId(), group).setAppId("VirtualGroup");
|
||||
groupDao.updateById(d, GroupEntity.UPDATESET_FULL);
|
||||
archiveGroupDao.insert(new ArchiveGroupDo().setGroupId(group.getId()).setVersion(group.getVersion()).setContent(ContentWriters.writeGroupContent(group)));
|
||||
relSyncVs(group, false);
|
||||
|
@ -64,6 +76,7 @@ public class GroupEntityManager implements GroupSync {
|
|||
public int delete(Long groupId) throws Exception {
|
||||
rGroupVsDao.deleteAllByGroup(new RelGroupVsDo().setGroupId(groupId));
|
||||
rGroupGsDao.deleteAllByGroup(new RelGroupGsDo().setGroupId(groupId));
|
||||
rGroupVgDao.deleteByPK(new RelGroupVgDo().setGroupId(groupId));
|
||||
int count = groupDao.deleteById(new GroupDo().setId(groupId));
|
||||
archiveGroupDao.deleteByGroup(new ArchiveGroupDo().setGroupId(groupId));
|
||||
return count;
|
||||
|
@ -129,6 +142,10 @@ public class GroupEntityManager implements GroupSync {
|
|||
rGroupGsDao.insert(dos);
|
||||
}
|
||||
|
||||
private void relSyncVg(Group group) throws DalException {
|
||||
rGroupVgDao.insert(new RelGroupVgDo().setGroupId(group.getId()));
|
||||
}
|
||||
|
||||
private void relSyncVs(Group group, boolean isnew) throws DalException {
|
||||
if (isnew) {
|
||||
for (GroupVirtualServer groupVirtualServer : group.getGroupVirtualServers()) {
|
||||
|
|
|
@ -38,6 +38,11 @@ public class GroupSyncImpl implements GroupSync {
|
|||
cascadeSync(group);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void add(Group group, boolean isVirtual) throws Exception {
|
||||
add(group);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(Group group) throws Exception {
|
||||
GroupDo check = groupDao.findById(group.getId(), GroupEntity.READSET_FULL);
|
||||
|
|
|
@ -5,6 +5,7 @@ import com.ctrip.zeus.model.entity.*;
|
|||
import com.ctrip.zeus.service.model.*;
|
||||
import com.ctrip.zeus.service.model.handler.GroupSync;
|
||||
import com.ctrip.zeus.service.model.handler.GroupValidator;
|
||||
import com.ctrip.zeus.service.model.handler.VGroupValidator;
|
||||
import com.ctrip.zeus.service.query.GroupCriteriaQuery;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
|
@ -29,12 +30,8 @@ public class GroupRepositoryImpl implements GroupRepository {
|
|||
private VirtualServerRepository virtualServerRepository;
|
||||
@Resource
|
||||
private GroupValidator groupModelValidator;
|
||||
|
||||
@Override
|
||||
public List<Group> list(Long slbId) throws Exception {
|
||||
Set<Long> groupIds = groupCriteriaQuery.queryBySlbId(slbId);
|
||||
return list(groupIds.toArray(new Long[groupIds.size()]));
|
||||
}
|
||||
@Resource
|
||||
private VGroupValidator vGroupValidator;
|
||||
|
||||
@Override
|
||||
public List<Group> list(Long[] ids) throws Exception {
|
||||
|
@ -44,52 +41,81 @@ public class GroupRepositoryImpl implements GroupRepository {
|
|||
groupVirtualServer.setVirtualServer(
|
||||
virtualServerRepository.getById(groupVirtualServer.getVirtualServer().getId()));
|
||||
}
|
||||
autoFiller.autofill(group);
|
||||
hideVirtualValue(group);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Group getById(Long id) throws Exception {
|
||||
if (groupModelValidator.exists(id)) {
|
||||
if (groupModelValidator.exists(id) || vGroupValidator.exists(id)) {
|
||||
Group result = archiveService.getLatestGroup(id);
|
||||
for (GroupVirtualServer groupVirtualServer : result.getGroupVirtualServers()) {
|
||||
groupVirtualServer.setVirtualServer(
|
||||
virtualServerRepository.getById(groupVirtualServer.getVirtualServer().getId()));
|
||||
}
|
||||
autoFiller.autofill(result);
|
||||
hideVirtualValue(result);
|
||||
return result;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Group get(String groupName) throws Exception {
|
||||
return getById(groupCriteriaQuery.queryByName(groupName));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Group add(Group group) throws Exception {
|
||||
groupModelValidator.validate(group);
|
||||
autoFiller.autofill(group);
|
||||
groupEntityManager.add(group);
|
||||
hideVirtualValue(group);
|
||||
groupEntityManager.add(group, false);
|
||||
return group;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Group addVGroup(Group group) throws Exception {
|
||||
vGroupValidator.validate(group);
|
||||
autoFiller.autofillVGroup(group);
|
||||
group.setVirtual(true);
|
||||
groupEntityManager.add(group, true);
|
||||
hideVirtualValue(group);
|
||||
return group;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Group update(Group group) throws Exception {
|
||||
if (!groupModelValidator.exists(group.getId()))
|
||||
throw new ValidationException("Group with id " + group.getId() + "does not exist.");
|
||||
throw new ValidationException("Group with id " + group.getId() + " does not exist.");
|
||||
groupModelValidator.validate(group);
|
||||
autoFiller.autofill(group);
|
||||
hideVirtualValue(group);
|
||||
groupEntityManager.update(group);
|
||||
return group;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Group updateVGroup(Group group) throws Exception {
|
||||
if (!vGroupValidator.exists(group.getId()))
|
||||
throw new ValidationException("Group with id " + group.getId() + " does not exist.");
|
||||
vGroupValidator.validate(group);
|
||||
autoFiller.autofillVGroup(group);
|
||||
group.setVirtual(true);
|
||||
groupEntityManager.update(group);
|
||||
hideVirtualValue(group);
|
||||
return group;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int delete(Long groupId) throws Exception {
|
||||
groupModelValidator.removable(groupId);
|
||||
return groupEntityManager.delete(groupId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int deleteVGroup(Long groupId) throws Exception {
|
||||
vGroupValidator.removable(groupId);
|
||||
return delete(groupId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Group> listGroupsByGroupServer(String groupServerIp) throws Exception {
|
||||
Set<Long> groupIds = groupCriteriaQuery.queryByGroupServerIp(groupServerIp);
|
||||
|
@ -109,4 +135,19 @@ public class GroupRepositoryImpl implements GroupRepository {
|
|||
Group group = getById(groupId);
|
||||
groupEntityManager.port(group);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Group get(String groupName) throws Exception {
|
||||
return getById(groupCriteriaQuery.queryByName(groupName));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Group> list(Long slbId) throws Exception {
|
||||
Set<Long> groupIds = groupCriteriaQuery.queryBySlbId(slbId);
|
||||
return list(groupIds.toArray(new Long[groupIds.size()]));
|
||||
}
|
||||
|
||||
private void hideVirtualValue(Group group) {
|
||||
group.setVirtual(null);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,4 +20,6 @@ public interface GroupCriteriaQuery {
|
|||
Set<Long> queryByVsIds(Long[] vsIds) throws Exception;
|
||||
|
||||
Set<Long> queryByGroupServerIp(String ip) throws Exception;
|
||||
|
||||
Set<Long> queryAllVGroups() throws Exception;
|
||||
}
|
||||
|
|
|
@ -23,6 +23,8 @@ public class DefaultGroupCriteriaQuery implements GroupCriteriaQuery {
|
|||
private RGroupGsDao rGroupGsDao;
|
||||
@Resource
|
||||
private RVsSlbDao rVsSlbDao;
|
||||
@Resource
|
||||
private RGroupVgDao rGroupVgDao;
|
||||
|
||||
@Override
|
||||
public Long queryByName(String name) throws Exception {
|
||||
|
@ -83,4 +85,13 @@ public class DefaultGroupCriteriaQuery implements GroupCriteriaQuery {
|
|||
}
|
||||
return groupIds;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<Long> queryAllVGroups() throws Exception {
|
||||
Set<Long> groupIds = new HashSet<>();
|
||||
for (RelGroupVgDo relGroupVgDo : rGroupVgDao.findAll(RGroupVgEntity.READSET_FULL)) {
|
||||
groupIds.add(relGroupVgDo.getGroupId());
|
||||
}
|
||||
return groupIds;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,28 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<entities do-package="com.ctrip.zeus.dal.core" gen="true" do-class-suffix="Do">
|
||||
<entity name="r-group-vs" table="r_group_vs" alias="rgv" do-class="RelGroupVsDo">
|
||||
<entity name="r-group-vg" table="r_group_vg" alias="rgv" do-class="RelGroupVgDo">
|
||||
<query-defs>
|
||||
<query name="find-all" type="SELECT" multiple="true">
|
||||
<statement>
|
||||
<![CDATA[
|
||||
SELECT <FIELDS/>
|
||||
FROM <TABLE/>
|
||||
]]>
|
||||
</statement>
|
||||
</query>
|
||||
<query name="find-by-group" type="SELECT">
|
||||
<param name="group-id"/>
|
||||
<statement>
|
||||
<![CDATA[
|
||||
SELECT <FIELDS/>
|
||||
FROM <TABLE/>
|
||||
WHERE <FIELD name='group-id'/> = ${group-id}
|
||||
]]>
|
||||
</statement>
|
||||
</query>
|
||||
</query-defs>
|
||||
</entity>
|
||||
<entity name="r-group-vs" table="r_group_vs" alias="rgv2" do-class="RelGroupVsDo">
|
||||
<var name="ids" value-type="Long[]"/>
|
||||
<query-defs>
|
||||
<query name="find-all-groups-by-vs" type="SELECT" multiple="true">
|
||||
|
|
|
@ -63,6 +63,7 @@
|
|||
<attribute name="priority" value-type="int" />
|
||||
<element name="path" value-type="String" />
|
||||
<element name="rewrite" value-type="String" />
|
||||
<element name="redirect" value-type="String" />
|
||||
<entity-ref name="virtual-server" />
|
||||
</entity>
|
||||
<entity name="group-server">
|
||||
|
@ -83,6 +84,7 @@
|
|||
<attribute name="app-id" value-type="String" />
|
||||
<attribute name="version" value-type="int" />
|
||||
<attribute name="ssl" value-type="boolean" />
|
||||
<attribute name="virtual" value-type="boolean" />
|
||||
<entity-ref name="group-virtual-server" type="list" names="group-virtual-servers" xml-indent="true" />
|
||||
<entity-ref name="health-check" />
|
||||
<entity-ref name="load-balancing-method" />
|
||||
|
|
|
@ -56,6 +56,7 @@
|
|||
<table name="r_slb_slb_server"/>
|
||||
<table name="certificate"/>
|
||||
<table name="r_certificate_slb_server"/>
|
||||
<table name="r_group_vg"/>
|
||||
<table name="archive_vs"/>
|
||||
</group>
|
||||
</jdbc>
|
||||
|
|
|
@ -558,6 +558,20 @@ CREATE TABLE IF NOT EXISTS `r_group_gs` (
|
|||
-- Data exporting was unselected.
|
||||
|
||||
|
||||
-- Dumping structure for table r_group_vg
|
||||
DROP TABLE IF EXISTS `r_group_vg`;
|
||||
CREATE TABLE IF NOT EXISTS `r_group_vg` (
|
||||
`id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT 'primary key',
|
||||
`group_id` bigint(20) NOT NULL DEFAULT '0' COMMENT 'group id',
|
||||
`DataChange_LastTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT 'last time modified',
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `group_id` (`group_id`),
|
||||
KEY `DataChange_LastTime` (`DataChange_LastTime`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
||||
|
||||
-- Data exporting was unselected.
|
||||
|
||||
|
||||
-- Dumping structure for table r_group_vs
|
||||
DROP TABLE IF EXISTS `r_group_vs`;
|
||||
CREATE TABLE IF NOT EXISTS `r_group_vs` (
|
||||
|
|
|
@ -41,6 +41,7 @@
|
|||
<group-virtual-server priority="0">
|
||||
<path>/hotel</path>
|
||||
<rewrite>^/regex</rewrite>
|
||||
<redirect>/fullurl</redirect>
|
||||
<virtual-server/>
|
||||
</group-virtual-server>
|
||||
<group-server port="80" weight="5" max-fails="5" fail-timeout="30">
|
||||
|
@ -54,7 +55,7 @@
|
|||
<group-server/>
|
||||
</group-servers>
|
||||
</group-server-list>
|
||||
<group id="123456789012" name="gateway" app-id="app921822" version="1" ssl="false">
|
||||
<group id="123456789012" name="gateway" app-id="app921822" version="1" ssl="false" virtual="true">
|
||||
<group-virtual-servers>
|
||||
<group-virtual-server/>
|
||||
<group-virtual-server/>
|
||||
|
|
Loading…
Reference in a new issue