mirror of
https://github.com/ctripcorp/zeus.git
synced 2024-11-10 09:02:49 +08:00
support slb-ids migration by 3 modes
This commit is contained in:
parent
578eebd5f9
commit
932226f42d
1 changed files with 42 additions and 26 deletions
|
@ -4,8 +4,8 @@ import com.ctrip.zeus.model.entity.*;
|
|||
import com.ctrip.zeus.tag.entity.Property;
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import com.fasterxml.jackson.annotation.JsonView;
|
||||
import com.netflix.config.DynamicBooleanProperty;
|
||||
import com.netflix.config.DynamicPropertyFactory;
|
||||
import com.netflix.config.DynamicStringProperty;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
@ -123,7 +123,7 @@ public interface ExtendedView<T> {
|
|||
}
|
||||
|
||||
class ExtendedVs extends VsView implements ExtendedView<VirtualServer> {
|
||||
private static DynamicBooleanProperty n2nViewEnabled = DynamicPropertyFactory.getInstance().getBooleanProperty("slb.slb-vs-n2n.view.enabled", false);
|
||||
private static DynamicStringProperty n2nViewMode = DynamicPropertyFactory.getInstance().getStringProperty("slb.slb-vs-n2n.view.mode", "singular");
|
||||
|
||||
private List<String> tags;
|
||||
private List<Property> properties;
|
||||
|
@ -154,25 +154,31 @@ public interface ExtendedView<T> {
|
|||
|
||||
@Override
|
||||
Long getSlbId() {
|
||||
if (n2nViewEnabled.get()) {
|
||||
return null;
|
||||
} else {
|
||||
if (instance.getSlbId() == null && instance.getSlbIds().size() > 0) {
|
||||
instance.setSlbId(instance.getSlbIds().get(0));
|
||||
}
|
||||
return instance.getSlbId();
|
||||
switch (n2nViewMode.get()) {
|
||||
case "plural":
|
||||
return null;
|
||||
case "singular":
|
||||
case "redundant":
|
||||
default:
|
||||
if (instance.getSlbId() == null && instance.getSlbIds().size() > 0) {
|
||||
instance.setSlbId(instance.getSlbIds().get(0));
|
||||
}
|
||||
return instance.getSlbId();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
List<Long> getSlbIds() {
|
||||
if (n2nViewEnabled.get()) {
|
||||
if (instance.getSlbIds().size() == 0 && instance.getSlbId() != null) {
|
||||
instance.getSlbIds().add(instance.getSlbId());
|
||||
}
|
||||
return instance.getSlbIds();
|
||||
} else {
|
||||
return null;
|
||||
switch (n2nViewMode.get()) {
|
||||
case "plural":
|
||||
case "redundant":
|
||||
if (instance.getSlbIds().size() == 0 && instance.getSlbId() != null) {
|
||||
instance.getSlbIds().add(instance.getSlbId());
|
||||
}
|
||||
return instance.getSlbIds();
|
||||
case "singular":
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -217,16 +223,26 @@ public interface ExtendedView<T> {
|
|||
}
|
||||
|
||||
public static void renderVirtualServer(VirtualServer vs) {
|
||||
if (n2nViewEnabled.get()) {
|
||||
if (vs.getSlbIds().size() == 0 && vs.getSlbId() != null) {
|
||||
vs.getSlbIds().add(vs.getSlbId());
|
||||
}
|
||||
vs.setSlbId(null);
|
||||
} else {
|
||||
if (vs.getSlbId() == null && vs.getSlbIds().size() > 0) {
|
||||
vs.setSlbId(vs.getSlbIds().get(0));
|
||||
}
|
||||
vs.getSlbIds().clear();
|
||||
switch (n2nViewMode.get()) {
|
||||
case "plural":
|
||||
if (vs.getSlbIds().size() == 0 && vs.getSlbId() != null) {
|
||||
vs.getSlbIds().add(vs.getSlbId());
|
||||
}
|
||||
vs.setSlbId(null);
|
||||
break;
|
||||
case "redundant":
|
||||
if (vs.getSlbIds().size() == 0 && vs.getSlbId() != null) {
|
||||
vs.getSlbIds().add(vs.getSlbId());
|
||||
} else if (vs.getSlbId() == null && vs.getSlbIds().size() > 0) {
|
||||
vs.setSlbId(vs.getSlbIds().get(0));
|
||||
}
|
||||
break;
|
||||
case "singular":
|
||||
default:
|
||||
if (vs.getSlbId() == null && vs.getSlbIds().size() > 0) {
|
||||
vs.setSlbId(vs.getSlbIds().get(0));
|
||||
}
|
||||
vs.getSlbIds().clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue