/** Set the rotations the given cluster should be member of */ public static Set<RotationName> from(Element rotationsElement) { Set<RotationName> rotations = new TreeSet<>(); List<Element> children = XML.getChildren(rotationsElement, "rotation"); for (Element el : children) { String name = el.getAttribute("id"); if (name == null || name.length() > maxLength || !pattern.matcher(name).matches()) { throw new IllegalArgumentException("Rotation ID '" + name + "' is missing or has invalid format"); } RotationName rotation = RotationName.from(name); if (rotations.contains(rotation)) { throw new IllegalArgumentException("Rotation ID '" + name + "' is duplicated"); } rotations.add(rotation); } return Collections.unmodifiableSet(rotations); }
public static RotationName from(String name) { return new RotationName(name); }
private RotationName(String name) { this.name = requireNonBlank(name, "name must be non-empty"); }
public static byte[] toJson(LoadBalancer loadBalancer) { Slime slime = new Slime(); Cursor root = slime.setObject(); root.setString(idField, loadBalancer.id().serializedForm()); root.setString(hostnameField, loadBalancer.hostname().toString()); loadBalancer.dnsZone().ifPresent(dnsZone -> root.setString(dnsZoneField, dnsZone.id())); Cursor portArray = root.setArray(portsField); loadBalancer.ports().forEach(portArray::addLong); Cursor networkArray = root.setArray(networksField); loadBalancer.networks().forEach(networkArray::addString); Cursor realArray = root.setArray(realsField); loadBalancer.reals().forEach(real -> { Cursor realObject = realArray.addObject(); realObject.setString(hostnameField, real.hostname().value()); realObject.setString(ipAddressField, real.ipAddress()); realObject.setLong(portField, real.port()); }); Cursor rotationArray = root.setArray(rotationsField); loadBalancer.rotations().forEach(rotation -> { Cursor rotationObject = rotationArray.addObject(); rotationObject.setString(nameField, rotation.value()); }); root.setBool(inactiveField, loadBalancer.inactive()); try { return SlimeUtils.toJsonBytes(slime); } catch (IOException e) { throw new UncheckedIOException(e); } }
lb.rotations().forEach(rotation -> { Cursor rotationObject = rotationArray.addObject(); rotationObject.setString("name", rotation.value()); });
Version.fromString("6.42"), false, Set.of(RotationName.from("us-cluster"))); activate(provisioner.prepare(zoneApp, zoneCluster, Capacity.fromRequiredNodeType(NodeType.host), 1, null), zoneApp, provisioner);
public static LoadBalancer fromJson(byte[] data) { Cursor object = SlimeUtils.jsonToSlime(data).get(); Set<Real> reals = new LinkedHashSet<>(); object.field(realsField).traverse((ArrayTraverser) (i, realObject) -> { reals.add(new Real(HostName.from(realObject.field(hostnameField).asString()), realObject.field(ipAddressField).asString(), (int) realObject.field(portField).asLong())); }); Set<Integer> ports = new LinkedHashSet<>(); object.field(portsField).traverse((ArrayTraverser) (i, port) -> ports.add((int) port.asLong())); Set<String> networks = new LinkedHashSet<>(); object.field(networksField).traverse((ArrayTraverser) (i, network) -> networks.add(network.asString())); Set<RotationName> rotations = new LinkedHashSet<>(); object.field(rotationsField).traverse((ArrayTraverser) (i, rotation) -> { rotations.add(RotationName.from(rotation.field(nameField).asString())); }); return new LoadBalancer(LoadBalancerId.fromSerializedForm(object.field(idField).asString()), HostName.from(object.field(hostnameField).asString()), optionalField(object.field(dnsZoneField), DnsZone::new), ports, networks, reals, rotations, object.field(inactiveField).asBool()); }