Search in sources :

Example 1 with HasPorts

use of org.platformlayer.ops.networks.HasPorts in project platformlayer by platformlayer.

the class NetworkConnectionController method addChildren.

@Override
protected void addChildren() throws OpsException {
    NetworkConnection model = ops.getInstance(NetworkConnection.class);
    Protocol protocol = null;
    if (model.protocol != null) {
        protocol = EnumUtils.valueOfCaseInsensitive(Protocol.class, model.protocol);
    }
    Transport transport = null;
    // if (model.transport != null) {
    // protocol = EnumUtils.valueOfCaseInsensitive(Transport.class, model.transport);
    // }
    List<Integer> ports = Lists.newArrayList();
    if (model.port != 0) {
        ports.add(model.port);
        if (model.protocol == null) {
            protocol = Protocol.Tcp;
        }
    } else {
        ItemBase destItem = platformLayer.getItem(model.destItem);
        HasPorts hasPorts = providers.toInterface(destItem, HasPorts.class);
        ports.addAll(hasPorts.getPorts());
        if (model.protocol == null) {
            // TODO: Support UDP?
            protocol = Protocol.Tcp;
        }
    }
    UUID uniqueId = platformLayer.getOrCreateUuid(model);
    for (int port : ports) {
        PlatformLayerFirewallEntry net = injected(PlatformLayerFirewallEntry.class);
        net.destItem = model.destItem;
        net.port = port;
        net.sourceItemKey = model.sourceItem;
        net.sourceCidr = model.sourceCidr;
        net.protocol = protocol;
        net.transport = transport;
        net.uniqueId = port + "-" + uniqueId.toString();
        addChild(net);
    }
}
Also used : HasPorts(org.platformlayer.ops.networks.HasPorts) ItemBase(org.platformlayer.core.model.ItemBase) NetworkConnection(org.platformlayer.service.network.model.NetworkConnection) Protocol(org.platformlayer.ops.firewall.Protocol) Transport(org.platformlayer.ops.firewall.Transport) UUID(java.util.UUID)

Aggregations

UUID (java.util.UUID)1 ItemBase (org.platformlayer.core.model.ItemBase)1 Protocol (org.platformlayer.ops.firewall.Protocol)1 Transport (org.platformlayer.ops.firewall.Transport)1 HasPorts (org.platformlayer.ops.networks.HasPorts)1 NetworkConnection (org.platformlayer.service.network.model.NetworkConnection)1