mirror of
https://github.com/ctripcorp/zeus.git
synced 2024-09-22 00:26:05 +08:00
report misses gs/gvs update
This commit is contained in:
parent
b6bf354fd7
commit
e258d1c30a
|
@ -60,7 +60,7 @@ public class GroupMemberResource {
|
|||
for (GroupServer groupServer : gsl.getGroupServers()) {
|
||||
groupMemberRepository.addGroupServer(gsl.getGroupId(), groupServer);
|
||||
}
|
||||
groupRepository.updateVersion(gsl.getGroupId());
|
||||
groupRepository.updateVersion(new Long[] {gsl.getGroupId()});
|
||||
return responseHandler.handle("Successfully added group servers to group with id " + gsl.getGroupId() + ".", hh.getMediaType());
|
||||
}
|
||||
|
||||
|
@ -75,7 +75,7 @@ public class GroupMemberResource {
|
|||
for (GroupServer groupServer : gsl.getGroupServers()) {
|
||||
groupMemberRepository.updateGroupServer(gsl.getGroupId(), groupServer);
|
||||
}
|
||||
groupRepository.updateVersion(gsl.getGroupId());
|
||||
groupRepository.updateVersion(new Long[] {gsl.getGroupId()});
|
||||
return responseHandler.handle("Successfully updated group servers to group with id " + gsl.getGroupId() + ".", hh.getMediaType());
|
||||
}
|
||||
|
||||
|
@ -90,7 +90,7 @@ public class GroupMemberResource {
|
|||
for (String ip : ips) {
|
||||
groupMemberRepository.removeGroupServer(groupId, ip);
|
||||
}
|
||||
groupRepository.updateVersion(groupId);
|
||||
groupRepository.updateVersion(new Long[] {groupId});
|
||||
return responseHandler.handle("Successfully removed " + Joiner.on(",").join(ips) + " from group with id " + groupId + ".", hh.getMediaType());
|
||||
}
|
||||
|
||||
|
|
|
@ -12,6 +12,7 @@ import com.ctrip.zeus.restful.message.TrimmedQueryParam;
|
|||
import com.ctrip.zeus.service.model.GroupRepository;
|
||||
import com.ctrip.zeus.service.model.SlbRepository;
|
||||
import com.ctrip.zeus.service.model.VirtualServerRepository;
|
||||
import com.ctrip.zeus.service.query.GroupCriteriaQuery;
|
||||
import com.ctrip.zeus.service.query.VirtualServerCriteriaQuery;
|
||||
import com.ctrip.zeus.tag.PropertyService;
|
||||
import com.ctrip.zeus.tag.TagService;
|
||||
|
@ -42,6 +43,8 @@ public class VirtualServerResource {
|
|||
@Resource
|
||||
private VirtualServerCriteriaQuery virtualServerCriteriaQuery;
|
||||
@Resource
|
||||
private GroupCriteriaQuery groupCriteriaQuery;
|
||||
@Resource
|
||||
private TagService tagService;
|
||||
@Resource
|
||||
private PropertyService propertyService;
|
||||
|
@ -119,7 +122,8 @@ public class VirtualServerResource {
|
|||
throw new ValidationException("Slb id is not provided.");
|
||||
virtualServerRepository.updateVirtualServer(virtualServer);
|
||||
slbRepository.updateVersion(virtualServer.getSlbId());
|
||||
groupRepository.updateVersionByVirtualServer(virtualServer.getId());
|
||||
Set<Long> groupIds = groupCriteriaQuery.queryByVsIds(new Long[] {virtualServer.getId()});
|
||||
groupRepository.updateVersion(groupIds.toArray(new Long[groupIds.size()]));
|
||||
return responseHandler.handle(virtualServer, hh.getMediaType());
|
||||
}
|
||||
|
||||
|
|
|
@ -11,6 +11,7 @@ import org.springframework.core.Ordered;
|
|||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by zhoumy on 2015/7/9.
|
||||
|
@ -39,6 +40,18 @@ public class ReportAspect implements Ordered {
|
|||
}
|
||||
return obj;
|
||||
}
|
||||
case "updateVersion": {
|
||||
Object obj = point.proceed();
|
||||
try {
|
||||
List<Group> groups = (List<Group>) obj;
|
||||
for (Group group : groups) {
|
||||
reportService.reportGroup(group);
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
logger.error("Fail to report group to queue.", ex);
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
case "delete": {
|
||||
Object obj = point.proceed();
|
||||
try {
|
||||
|
|
|
@ -27,9 +27,7 @@ public interface GroupRepository extends Repository {
|
|||
|
||||
Group update(Group group) throws Exception;
|
||||
|
||||
void updateVersion(Long groupId) throws Exception;
|
||||
|
||||
void updateVersionByVirtualServer(Long vsId) throws Exception;
|
||||
List<Group> updateVersion(Long[] groupIds) throws Exception;
|
||||
|
||||
int delete(Long groupId) throws Exception;
|
||||
|
||||
|
|
|
@ -31,5 +31,5 @@ public interface SlbRepository extends Repository {
|
|||
|
||||
int delete(Long slbId) throws Exception;
|
||||
|
||||
void updateVersion(Long slbId) throws Exception;
|
||||
Slb updateVersion(Long slbId) throws Exception;
|
||||
}
|
||||
|
|
|
@ -12,6 +12,7 @@ import com.ctrip.zeus.service.query.GroupCriteriaQuery;
|
|||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
@ -79,9 +80,7 @@ public class GroupRepositoryImpl implements GroupRepository {
|
|||
Long groupId = groupSync.add(group);
|
||||
group.setId(groupId);
|
||||
syncVsAndGs(group);
|
||||
archive(groupId);
|
||||
return getById(groupId);
|
||||
|
||||
return archive(groupId);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -90,23 +89,18 @@ public class GroupRepositoryImpl implements GroupRepository {
|
|||
Long groupId = groupSync.update(group);
|
||||
group.setId(groupId);
|
||||
syncVsAndGs(group);
|
||||
archive(groupId);
|
||||
return getById(groupId);
|
||||
return archive(groupId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateVersion(Long groupId) throws Exception {
|
||||
groupSync.updateVersion(new Long[]{groupId});
|
||||
archive(groupId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateVersionByVirtualServer(Long vsId) throws Exception {
|
||||
Set<Long> groupIds = groupCriteriaQuery.queryByVsIds(new Long[] {vsId});
|
||||
groupSync.updateVersion(groupIds.toArray(new Long[groupIds.size()]));
|
||||
public List<Group> updateVersion(Long[] groupIds) throws Exception {
|
||||
List<Group> result = new ArrayList<>();
|
||||
groupSync.updateVersion(groupIds);
|
||||
for (Long groupId : groupIds) {
|
||||
archive(groupId);
|
||||
Group group = archive(groupId);
|
||||
result.add(group);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -123,7 +117,7 @@ public class GroupRepositoryImpl implements GroupRepository {
|
|||
return list(groupIds);
|
||||
}
|
||||
|
||||
private void archive(Long groupId) throws Exception {
|
||||
private Group archive(Long groupId) throws Exception {
|
||||
Group group = groupQuery.getById(groupId);
|
||||
for (GroupVirtualServer groupVirtualServer : virtualServerRepository.listGroupVsByGroups(new Long[]{group.getId()})) {
|
||||
group.addGroupVirtualServer(groupVirtualServer);
|
||||
|
@ -132,6 +126,7 @@ public class GroupRepositoryImpl implements GroupRepository {
|
|||
group.addGroupServer(server);
|
||||
}
|
||||
archiveService.archiveGroup(group);
|
||||
return group;
|
||||
}
|
||||
|
||||
private void syncVsAndGs(Group group) throws Exception {
|
||||
|
|
|
@ -93,8 +93,7 @@ public class SlbRepositoryImpl implements SlbRepository {
|
|||
Long slbId = slbSync.add(slb);
|
||||
slb.setId(slbId);
|
||||
addVs(slb);
|
||||
archive(slbId);
|
||||
Slb result = getById(slbId);
|
||||
Slb result = archive(slbId);
|
||||
|
||||
for (SlbServer slbServer : result.getSlbServers()) {
|
||||
nginxServerDao.insert(new NginxServerDo()
|
||||
|
@ -110,8 +109,7 @@ public class SlbRepositoryImpl implements SlbRepository {
|
|||
public Slb update(Slb slb) throws Exception {
|
||||
slbModelValidator.validate(slb);
|
||||
Long slbId = slbSync.update(slb);
|
||||
archive(slbId);
|
||||
Slb result = getById(slbId);
|
||||
Slb result = archive(slbId);
|
||||
|
||||
for (SlbServer slbServer : result.getSlbServers()) {
|
||||
nginxServerDao.insert(new NginxServerDo()
|
||||
|
@ -132,17 +130,18 @@ public class SlbRepositoryImpl implements SlbRepository {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void updateVersion(Long slbId) throws Exception {
|
||||
public Slb updateVersion(Long slbId) throws Exception {
|
||||
slbSync.updateVersion(slbId);
|
||||
archive(slbId);
|
||||
return archive(slbId);
|
||||
}
|
||||
|
||||
private void archive(Long slbId) throws Exception {
|
||||
private Slb archive(Long slbId) throws Exception {
|
||||
Slb slb = slbQuery.getById(slbId);
|
||||
for (VirtualServer virtualServer : virtualServerRepository.listVirtualServerBySlb(slb.getId())) {
|
||||
slb.addVirtualServer(virtualServer);
|
||||
}
|
||||
archiveService.archiveSlb(slb);
|
||||
return slb;
|
||||
}
|
||||
|
||||
private List<Slb> batchGet(Long[] slbIds) throws Exception {
|
||||
|
|
|
@ -3,6 +3,7 @@ package com.ctrip.zeus.service;
|
|||
import com.ctrip.zeus.exceptions.ValidationException;
|
||||
import com.ctrip.zeus.model.entity.*;
|
||||
import com.ctrip.zeus.service.model.*;
|
||||
import com.ctrip.zeus.service.query.GroupCriteriaQuery;
|
||||
import com.ctrip.zeus.util.ModelAssert;
|
||||
import com.ctrip.zeus.util.S;
|
||||
import org.codehaus.plexus.component.repository.exception.ComponentLifecycleException;
|
||||
|
@ -18,6 +19,7 @@ import javax.annotation.Resource;
|
|||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Created by zhoumy on 2015/3/24.
|
||||
|
@ -29,6 +31,8 @@ public class ModelServiceTest extends AbstractSpringTest {
|
|||
@Resource
|
||||
private GroupRepository groupRepository;
|
||||
@Resource
|
||||
private GroupCriteriaQuery groupCriteriaQuery;
|
||||
@Resource
|
||||
private SlbRepository slbRepository;
|
||||
@Resource
|
||||
private VirtualServerRepository virtualServerRepository;
|
||||
|
@ -90,7 +94,7 @@ public class ModelServiceTest extends AbstractSpringTest {
|
|||
|
||||
@Test
|
||||
public void testListSlbsByGroups() throws Exception {
|
||||
List<Slb> slbs = slbRepository.listByGroups(new Long[]{testGroup.getId(), testGroup.getId() + 1});
|
||||
List<Slb> slbs = slbRepository.listByGroups(new Long[]{testGroup.getId(), testGroup.getId() + 1 });
|
||||
Assert.assertEquals(1, slbs.size());
|
||||
}
|
||||
|
||||
|
@ -294,7 +298,7 @@ public class ModelServiceTest extends AbstractSpringTest {
|
|||
|
||||
gvs.add(new GroupVirtualServer().setPath("/testUpdateGroupVsNew").setVirtualServer(new VirtualServer().setId(defaultSlb.getVirtualServers().get(0).getId())));
|
||||
virtualServerRepository.updateGroupVirtualServers(testGroup.getId(), gvs);
|
||||
groupRepository.updateVersion(testGroup.getId());
|
||||
groupRepository.updateVersion(new Long[] {testGroup.getId()});
|
||||
Assert.assertEquals(gvs.size(), groupRepository.get(testGroup.getName()).getGroupVirtualServers().size());
|
||||
Assert.assertEquals(gvs.size(), virtualServerRepository.listGroupVsByGroups(new Long[]{testGroup.getId()}).size());
|
||||
|
||||
|
@ -305,14 +309,14 @@ public class ModelServiceTest extends AbstractSpringTest {
|
|||
gvs.get(0).setVirtualServer(new VirtualServer().setId(defaultSlb.getVirtualServers().get(1).getId()));
|
||||
try {
|
||||
virtualServerRepository.updateGroupVirtualServers(testGroup.getId(), gvs);
|
||||
groupRepository.updateVersion(testGroup.getId());
|
||||
groupRepository.updateVersion(new Long[] {testGroup.getId()});
|
||||
Assert.assertTrue(false);
|
||||
} catch (Exception ex) {
|
||||
Assert.assertTrue(ex instanceof ValidationException);
|
||||
}
|
||||
gvs.remove(gvs.get(1));
|
||||
virtualServerRepository.updateGroupVirtualServers(testGroup.getId(), gvs);
|
||||
groupRepository.updateVersion(testGroup.getId());
|
||||
groupRepository.updateVersion(new Long[] {testGroup.getId()});
|
||||
gvs = virtualServerRepository.listGroupVsByGroups(new Long[]{testGroup.getId()});
|
||||
|
||||
Assert.assertEquals(1, gvs.size());
|
||||
|
@ -348,7 +352,8 @@ public class ModelServiceTest extends AbstractSpringTest {
|
|||
virtualServers.get(1).setName("www.hello.com.cn");
|
||||
for (VirtualServer virtualServer : virtualServers) {
|
||||
virtualServerRepository.updateVirtualServer(virtualServer);
|
||||
groupRepository.updateVersionByVirtualServer(virtualServer.getId());
|
||||
Set<Long> groupIds = groupCriteriaQuery.queryByVsIds(new Long[] {virtualServer.getId()});
|
||||
groupRepository.updateVersion(groupIds.toArray(new Long[groupIds.size()]));
|
||||
}
|
||||
slbRepository.updateVersion(created.getId());
|
||||
|
||||
|
|
Loading…
Reference in a new issue