fix softDeactivateGroup and add api

This commit is contained in:
fanqq 2016-03-08 11:42:27 +08:00
parent 1b3401b3a3
commit 7de084eead
2 changed files with 38 additions and 8 deletions

View file

@ -153,19 +153,15 @@ public class TaskExecutorImpl implements TaskExecutor {
//1.4 offline data check //1.4 offline data check
List<IdVersion> toFetch = new ArrayList<>(); List<IdVersion> toFetch = new ArrayList<>();
for (OpsTask task : activateGroupOps.values()) { for (OpsTask task : activateGroupOps.values()) {
if (softDeactivateGroupOps.containsKey(task.getGroupId())){ if (softDeactivateGroupOps.containsKey(task.getGroupId())) {
setTaskFail(task,"Activating Group while soft deactivating group ,groupId[" + task.getGroupId() + "]"); setTaskFail(task, "Activating Group while soft deactivating group ,groupId[" + task.getGroupId() + "]");
activateGroupOps.remove(task.getGroupId());
continue; continue;
} }
if (!offlineGroups.get(task.getGroupId()).getVersion().equals(task.getVersion())) { if (!offlineGroups.get(task.getGroupId()).getVersion().equals(task.getVersion())) {
toFetch.add(new IdVersion(task.getId(), task.getVersion())); toFetch.add(new IdVersion(task.getId(), task.getVersion()));
} }
} }
for (OpsTask task : softDeactivateGroupOps.values()){
if (!offlineGroups.get(task.getGroupId()).getVersion().equals(task.getVersion())) {
toFetch.add(new IdVersion(task.getId(), task.getVersion()));
}
}
List<Group> groups = groupRepository.list(toFetch.toArray(new IdVersion[]{})); List<Group> groups = groupRepository.list(toFetch.toArray(new IdVersion[]{}));
for (Group group : groups) { for (Group group : groups) {
offlineGroups.put(group.getId(), group); offlineGroups.put(group.getId(), group);
@ -194,6 +190,11 @@ public class TaskExecutorImpl implements TaskExecutor {
for (Long gid : activateGroupOps.keySet()) { for (Long gid : activateGroupOps.keySet()) {
onlineGroups.put(gid, offlineGroups.get(gid)); onlineGroups.put(gid, offlineGroups.get(gid));
} }
for (Long gid : softDeactivateGroupOps.keySet()) {
if (onlineGroups.containsKey(gid)) {
onlineGroups.remove(gid);
}
}
//2.2 merge on/offline vses //2.2 merge on/offline vses
for (Long sid : activateVsOps.keySet()) { for (Long sid : activateVsOps.keySet()) {
onlineVses.put(sid, offlineVses.get(sid)); onlineVses.put(sid, offlineVses.get(sid));
@ -225,7 +226,7 @@ public class TaskExecutorImpl implements TaskExecutor {
if (task.getSlbVirtualServerId() != null && onlineVses.containsKey(task.getSlbVirtualServerId())) { if (task.getSlbVirtualServerId() != null && onlineVses.containsKey(task.getSlbVirtualServerId())) {
needBuildVses.add(task.getSlbVirtualServerId()); needBuildVses.add(task.getSlbVirtualServerId());
} else { } else {
setTaskFail(task,"Not found online vs for soft deactivate group ops. vs="+task.getSlbVirtualServerId()); setTaskFail(task, "Not found online vs for soft deactivate group ops. vs=" + task.getSlbVirtualServerId());
} }
} }
} }

View file

@ -150,6 +150,35 @@ public class DeactivateResource {
return responseHandler.handle(results, hh.getMediaType()); return responseHandler.handle(results, hh.getMediaType());
} }
@GET
@Path("/soft/group")
@Authorize(name = "activate")
public Response softDeactivateGroup(@Context HttpServletRequest request,
@Context HttpHeaders hh,
@QueryParam("vsId") Long vsId,
@QueryParam("groupId") Long groupId) throws Exception {
ModelStatusMapping<Group> groupMap = entityFactory.getGroupsByIds(new Long[]{groupId});
if (groupMap.getOfflineMapping() != null && groupMap.getOfflineMapping().size() > 0) {
throw new ValidationException("Not found group.");
}
ModelStatusMapping<VirtualServer> vsMap = entityFactory.getVsesByIds(new Long[]{vsId});
if (vsMap.getOnlineMapping() == null || vsMap.getOnlineMapping().get(vsId) == null) {
throw new ValidationException("Vs is not activated.VsId:" + vsId);
}
VirtualServer vs = vsMap.getOnlineMapping().get(vsId);
OpsTask sofDeactivateTask = new OpsTask();
sofDeactivateTask.setSlbVirtualServerId(vsId);
sofDeactivateTask.setCreateTime(new Date());
sofDeactivateTask.setOpsType(TaskOpsType.SOFT_DEACTIVATE_GROUP);
sofDeactivateTask.setTargetSlbId(vs.getSlbId());
sofDeactivateTask.setGroupId(groupId);
sofDeactivateTask.setVersion(groupMap.getOfflineMapping().get(groupId).getVersion());
Long taskId = taskManager.addTask(sofDeactivateTask);
TaskResult results = taskManager.getResult(taskId, apiTimeout.get());
return responseHandler.handle(results, hh.getMediaType());
}
@GET @GET
@Path("/slb") @Path("/slb")
@Authorize(name = "activate") @Authorize(name = "activate")