diff options
author | Arne Juul <arnej@yahoo-inc.com> | 2019-02-06 14:37:43 +0000 |
---|---|---|
committer | Arne Juul <arnej@yahoo-inc.com> | 2019-02-20 10:30:08 +0000 |
commit | 92599c56d62226a32e1e4df4321123c9691db73d (patch) | |
tree | 7e981d971920da1536443289d511198af265b432 /config-provisioning/src/main/java/com/yahoo/config/provision/NetworkPorts.java | |
parent | 85e394563c8b711a1a0307c8ac5953c1817f5629 (diff) |
add list of network port allocations
* add port suffixes to identify individual ports for a service
* stash port reservations from current config model
Diffstat (limited to 'config-provisioning/src/main/java/com/yahoo/config/provision/NetworkPorts.java')
-rw-r--r-- | config-provisioning/src/main/java/com/yahoo/config/provision/NetworkPorts.java | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/config-provisioning/src/main/java/com/yahoo/config/provision/NetworkPorts.java b/config-provisioning/src/main/java/com/yahoo/config/provision/NetworkPorts.java new file mode 100644 index 00000000000..1c83c4314d9 --- /dev/null +++ b/config-provisioning/src/main/java/com/yahoo/config/provision/NetworkPorts.java @@ -0,0 +1,57 @@ +// Copyright 2019 Oath Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. + +package com.yahoo.config.provision; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.List; +import java.util.Optional; + +/** + * Models an immutable list of network port allocations + * @author arnej + */ +public class NetworkPorts { + + public static class Allocation { + public final int port; + public final String serviceType; + public final String configId; + public final String portSuffix; + + public Allocation(int port, String serviceType, String configId, String portSuffix) { + this.port = port; + this.serviceType = serviceType; + this.configId = configId; + this.portSuffix = portSuffix; + } + public String key() { + StringBuilder buf = new StringBuilder(); + buf.append("t=").append(serviceType); + buf.append(" cfg=").append(configId); + buf.append(" suf=").append(portSuffix); + return buf.toString(); + } + public String toString() { + StringBuilder buf = new StringBuilder(); + buf.append("[port=").append(port); + buf.append(" serviceType=").append(serviceType); + buf.append(" configId=").append(configId); + buf.append(" suffix=").append(portSuffix); + buf.append("]"); + return buf.toString(); + } + } + + private final List<Allocation> allocations; + + public NetworkPorts(Collection<Allocation> allocations) { + this.allocations = new ArrayList<>(allocations.size()); + this.allocations.addAll(allocations); + } + + public Collection<Allocation> allocations() { + return Collections.unmodifiableList(this.allocations); + } +} |