mirror of
https://github.com/ctripcorp/zeus.git
synced 2024-09-20 07:36:02 +08:00
update
This commit is contained in:
parent
9d4dc719d2
commit
a530f36956
|
@ -70,6 +70,9 @@ public class TrafficPolicyResource {
|
|||
queryRender.readToCommand(cmd);
|
||||
|
||||
IdVersion[] searchKeys = trafficPolicyQuery.queryByCommand(cmd, SelectionMode.getMode(mode));
|
||||
if (searchKeys == null) {
|
||||
searchKeys = trafficPolicyQuery.queryAll(SelectionMode.getMode(mode)).toArray(new IdVersion[]{});
|
||||
}
|
||||
List<TrafficPolicy> result = trafficPolicyRepository.list(searchKeys);
|
||||
|
||||
List<ExtendedView.ExtendedTrafficPolicy> viewArray = new ArrayList<>(result.size());
|
||||
|
@ -132,6 +135,13 @@ public class TrafficPolicyResource {
|
|||
if (extendedView.getTags() != null) {
|
||||
addTag(p.getId(), extendedView.getTags());
|
||||
}
|
||||
try {
|
||||
if (trafficPolicyQuery.queryByIdAndMode(p.getId(), SelectionMode.ONLINE_EXCLUSIVE).length == 1) {
|
||||
propertyBox.set("status", "toBeActivated", "policy", p.getId());
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
}
|
||||
|
||||
return responseHandler.handle(p, hh.getMediaType());
|
||||
}
|
||||
|
||||
|
|
|
@ -11,6 +11,8 @@ public interface ModelValidator<T> {
|
|||
|
||||
void validateForActivate(T[] toBeActivatedItems, boolean escapedPathValidation) throws Exception;
|
||||
|
||||
void validateForDeactivate(Long[] toBeDeactivatedItems) throws Exception;
|
||||
|
||||
void checkVersionForUpdate(T target) throws Exception;
|
||||
|
||||
void removable(Long targetId) throws Exception;
|
||||
|
|
|
@ -121,11 +121,18 @@ public class DefaultGroupValidator implements GroupValidator {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void validateForDeactivate(Long[] toBeDeactivatedItems) throws Exception {
|
||||
for (RTrafficPolicyGroupDo e : rTrafficPolicyGroupDao.findByGroupsAndPolicyActiveVersion(toBeDeactivatedItems, RTrafficPolicyGroupEntity.READSET_FULL)) {
|
||||
throw new ValidationException("Group that you try to deactivate is hold by an online traffic policy " + e.getPolicyId() + ".");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void checkVersionForUpdate(Group target) throws Exception {
|
||||
RelGroupStatusDo check = rGroupStatusDao.findByGroup(target.getId(), RGroupStatusEntity.READSET_FULL);
|
||||
if (check == null) {
|
||||
throw new ValidationException("Group that you tries to update does not exist.");
|
||||
throw new ValidationException("Group that you try to update does not exist.");
|
||||
}
|
||||
if (check.getOfflineVersion() > target.getVersion()) {
|
||||
throw new ValidationException("Newer version is detected.");
|
||||
|
@ -306,7 +313,7 @@ public class DefaultGroupValidator implements GroupValidator {
|
|||
} else {
|
||||
// check priority and reformat
|
||||
if (!e.getPriority().equals(insertEntry.getPriority())) {
|
||||
throw new ValidationException("Group that you tries to create/modify may cause path prefix-overlap problem with other entries on virtual-server " + vsId + ". Recommend priority will be " + insertEntry.getPriority() + ".");
|
||||
throw new ValidationException("Group that you try to create/modify may cause path prefix-overlap problem with other entries on virtual-server " + vsId + ". Recommend priority will be " + insertEntry.getPriority() + ".");
|
||||
}
|
||||
e.setPath(insertEntry.getPath());
|
||||
}
|
||||
|
|
|
@ -85,6 +85,11 @@ public class DefaultSlbValidator implements SlbValidator {
|
|||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void validateForDeactivate(Long[] toBeDeactivatedItems) throws Exception {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void checkVersionForUpdate(Slb target) throws Exception {
|
||||
SlbDo check = slbDao.findById(target.getId(), SlbEntity.READSET_FULL);
|
||||
|
|
|
@ -29,6 +29,8 @@ public class DefaultTrafficPolicyValidator implements TrafficPolicyValidator {
|
|||
private RGroupVsDao rGroupVsDao;
|
||||
@Resource
|
||||
private PathValidator pathValidator;
|
||||
@Resource
|
||||
private RGroupStatusDao rGroupStatusDao;
|
||||
|
||||
@Override
|
||||
public boolean exists(Long targetId) throws Exception {
|
||||
|
@ -73,6 +75,7 @@ public class DefaultTrafficPolicyValidator implements TrafficPolicyValidator {
|
|||
for (RelGroupVsDo e : rGroupVsDao.findByVsesAndGroupOfflineVersion(vsIds, RGroupVsEntity.READSET_FULL)) {
|
||||
putArrayEntryValue(gvsListByVsId, e.getVsId(), e);
|
||||
}
|
||||
validatePolicyControls(target, groupIds, vsIds, gvsListByVsId);
|
||||
|
||||
Map<Long, List<RTrafficPolicyVsDo>> pvsListByVsId = new HashMap<>();
|
||||
for (RTrafficPolicyVsDo e : rTrafficPolicyVsDao.findByVsesAndPolicyVersion(vsIds, RTrafficPolicyVsEntity.READSET_FULL)) {
|
||||
|
@ -84,8 +87,6 @@ public class DefaultTrafficPolicyValidator implements TrafficPolicyValidator {
|
|||
putArrayEntryValue(policyListByGroupId, e.getGroupId(), e);
|
||||
}
|
||||
|
||||
validatePolicyControls(target, groupIds, vsIds, gvsListByVsId);
|
||||
|
||||
Map<Long, List<PathValidator.LocationEntry>> currentLocationEntriesByVs = new HashMap<>();
|
||||
compareAndBuildCurrentLocationEntries(target, groupIds, vsIds, policyListByGroupId, pvsListByVsId, gvsListByVsId,
|
||||
escapePathValidation ? null : currentLocationEntriesByVs);
|
||||
|
@ -199,6 +200,13 @@ public class DefaultTrafficPolicyValidator implements TrafficPolicyValidator {
|
|||
policies[i] = e.getId();
|
||||
hashes[i] = VersionUtils.getHash(e.getId(), e.getVersion());
|
||||
}
|
||||
Long[] groupIds = groupLookup.toArray(new Long[groupLookup.size()]);
|
||||
for (RelGroupStatusDo e : rGroupStatusDao.findByGroups(groupIds, RGroupStatusEntity.READSET_FULL)) {
|
||||
if (e.getOnlineVersion() < 0) {
|
||||
throw new ValidationException("Group " + e.getGroupId() + " has not been activated.");
|
||||
}
|
||||
}
|
||||
|
||||
Long[] vsIds = vsLookup.toArray(new Long[vsLookup.size()]);
|
||||
|
||||
Map<Long, List<RelGroupVsDo>> gvsListByVsId = new HashMap<>();
|
||||
|
@ -219,7 +227,7 @@ public class DefaultTrafficPolicyValidator implements TrafficPolicyValidator {
|
|||
}
|
||||
|
||||
Map<Long, List<RTrafficPolicyGroupDo>> policyListByGroupId = new HashMap<>();
|
||||
for (RTrafficPolicyGroupDo e : rTrafficPolicyGroupDao.findByGroupsAndPolicyActiveVersion(groupLookup.toArray(new Long[groupLookup.size()]), RTrafficPolicyGroupEntity.READSET_FULL)) {
|
||||
for (RTrafficPolicyGroupDo e : rTrafficPolicyGroupDao.findByGroupsAndPolicyActiveVersion(groupIds, RTrafficPolicyGroupEntity.READSET_FULL)) {
|
||||
if (Arrays.binarySearch(policies, e.getPolicyId()) >= 0) continue;
|
||||
putArrayEntryValue(policyListByGroupId, e.getGroupId(), e);
|
||||
}
|
||||
|
@ -252,6 +260,11 @@ public class DefaultTrafficPolicyValidator implements TrafficPolicyValidator {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void validateForDeactivate(Long[] toBeDeactivatedItems) throws Exception {
|
||||
|
||||
}
|
||||
|
||||
private <T> void putArrayEntryValue(Map<Long, List<T>> map, Long key, T e) {
|
||||
List<T> v = map.get(key);
|
||||
if (v == null) {
|
||||
|
@ -265,12 +278,15 @@ public class DefaultTrafficPolicyValidator implements TrafficPolicyValidator {
|
|||
Long prev = groupIds[0];
|
||||
for (int i = 1; i < groupIds.length; i++) {
|
||||
if (prev.equals(groupIds[i])) {
|
||||
throw new ValidationException("Traffic policy that you tries to create/modify declares the same group " + prev + " more than once.");
|
||||
throw new ValidationException("Traffic policy that you try to create/modify declares the same group " + prev + " more than once.");
|
||||
}
|
||||
prev = groupIds[i];
|
||||
}
|
||||
if (groupIds.length <= 1) {
|
||||
throw new ValidationException("Traffic policy that you tries to create/modify does not have enough traffic-controls.");
|
||||
throw new ValidationException("Traffic policy that you try to create/modify does not have enough traffic-controls.");
|
||||
}
|
||||
if (rGroupStatusDao.findByGroups(groupIds, RGroupStatusEntity.READSET_FULL).size() != groupIds.length) {
|
||||
throw new ValidationException("Traffic policy that you try to create/modify contains group that does not exist.");
|
||||
}
|
||||
|
||||
int[] versions = new int[groupIds.length];
|
||||
|
@ -355,7 +371,7 @@ public class DefaultTrafficPolicyValidator implements TrafficPolicyValidator {
|
|||
public void checkVersionForUpdate(TrafficPolicy target) throws Exception {
|
||||
TrafficPolicyDo d = trafficPolicyDao.findById(target.getId(), TrafficPolicyEntity.READSET_FULL);
|
||||
if (d == null) {
|
||||
throw new ValidationException("Traffic policy that you tries to update does not exist.");
|
||||
throw new ValidationException("Traffic policy that you try to update does not exist.");
|
||||
}
|
||||
if (d.getVersion() > target.getVersion()) {
|
||||
throw new ValidationException("Newer version is detected.");
|
||||
|
@ -369,7 +385,7 @@ public class DefaultTrafficPolicyValidator implements TrafficPolicyValidator {
|
|||
public void removable(Long targetId) throws Exception {
|
||||
TrafficPolicyDo d = trafficPolicyDao.findById(targetId, TrafficPolicyEntity.READSET_FULL);
|
||||
if (d != null && d.getActiveVersion() > 0) {
|
||||
throw new ValidationException("Traffic policy that you tried to delete is still active.");
|
||||
throw new ValidationException("Traffic policy that you try to delete is still active.");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -43,6 +43,11 @@ public class DefaultVGroupValidator implements VGroupValidator {
|
|||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void validateForDeactivate(Long[] toBeDeactivatedItems) throws Exception {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void checkVersionForUpdate(Group target) throws Exception {
|
||||
groupModelValidator.checkVersionForUpdate(target);
|
||||
|
|
|
@ -112,6 +112,11 @@ public class DefaultVirtualServerValidator implements VirtualServerValidator {
|
|||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void validateForDeactivate(Long[] toBeDeactivatedItems) throws Exception {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void checkVersionForUpdate(VirtualServer target) throws Exception {
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package com.ctrip.zeus.service.query.impl;
|
||||
|
||||
import com.ctrip.zeus.dal.core.*;
|
||||
import com.ctrip.zeus.executor.impl.ResultHandler;
|
||||
import com.ctrip.zeus.model.entity.TrafficPolicy;
|
||||
import com.ctrip.zeus.service.model.IdVersion;
|
||||
import com.ctrip.zeus.service.model.SelectionMode;
|
||||
|
@ -130,7 +131,19 @@ public class DefaultTrafficPolicyCriteriaQuery implements TrafficPolicyQuery {
|
|||
}
|
||||
return result;
|
||||
}
|
||||
}).build(IdVersion.class).run();
|
||||
}).build(IdVersion.class).run(new ResultHandler<IdVersion, IdVersion>() {
|
||||
@Override
|
||||
public IdVersion[] handle(Set<IdVersion> result) throws Exception {
|
||||
if (result == null) return null;
|
||||
if (result.size() == 0) return new IdVersion[0];
|
||||
Set<Long> ids = new HashSet<>();
|
||||
for (IdVersion e : result) {
|
||||
ids.add(e.getId());
|
||||
}
|
||||
result.retainAll(queryByIdsAndMode(ids.toArray(new Long[ids.size()]), mode));
|
||||
return result.toArray(new IdVersion[result.size()]);
|
||||
}
|
||||
});
|
||||
|
||||
return result;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue