Search in sources :

Example 1 with ResourcePool

use of org.platformlayer.ops.pool.ResourcePool in project platformlayer by platformlayer.

the class DirectCloudUtils method getPublicAddressPool4.

public OpsProvider<ResourcePool<InetSocketAddress>> getPublicAddressPool4(final int publicPort, final List<Integer> publicPortGroup) {
    OpsProvider<ResourcePool<InetSocketAddress>> pool = new OpsProvider<ResourcePool<InetSocketAddress>>() {

        @Override
        public ResourcePool<InetSocketAddress> get() throws OpsException {
            DirectHost host = OpsContext.get().getInstance(DirectHost.class);
            OpsTarget target = OpsContext.get().getInstance(OpsTarget.class);
            PlatformLayerKey sharedNetworkKey = getSharedNetworkKey();
            // We don't skip here, at the moment.
            // We may just need a comma separated list in future...
            int skipCount = 0;
            if (sharedNetworkKey == null) {
                File poolPath = getPoolPath("sockets-ipv4-public");
                File resourceDir = new File(poolPath, "all");
                File assignedBase = new File(poolPath, "assigned");
                File perPortDir = new File(assignedBase, "port" + publicPort);
                PoolBuilder<AddressModel> poolBuilder = null;
                String ipv4Public = host.ipv4Public;
                if (ipv4Public != null) {
                    poolBuilder = new NetworkPoolBuilder(ipv4Public, skipCount);
                }
                StaticFilesystemBackedPool<AddressModel> addressPool = new StaticFilesystemBackedPool<AddressModel>(AddressModel.class, poolBuilder, target, resourceDir, perPortDir);
                return new AssignPortToAddressPool(addressPool, publicPort);
            } else {
                throw new UnsupportedOperationException();
            // DirectNetwork network = platformLayer.getItem(sharedNetworkKey, DirectNetwork.class);
            // 
            // for (AddressModel net : network.getNetworks()) {
            // if (Strings.isNullOrEmpty(net.cidr)) {
            // continue;
            // }
            // 
            // IpRange cidr = IpRange.parse(net.cidr);
            // if (!cidr.isIpv4()) {
            // continue;
            // }
            // 
            // NetworkPoolBuilder poolBuilder = new NetworkPoolBuilder(net.cidr, skipCount, net);
            // PlatformlayerBackedPool<AddressModel> addressPool = new PlatformlayerBackedPool<AddressModel>(
            // platformLayer, sharedNetworkKey, AddressModel.class, poolBuilder);
            // return new AssignPortToAddressPool(addressPool, publicPort);
            // }
            // 
            // log.warn("Unable to find an IPV4 network configured on " + sharedNetworkKey);
            // return null;
            }
        }
    };
    return pool;
}
Also used : InetSocketAddress(java.net.InetSocketAddress) StaticFilesystemBackedPool(org.platformlayer.ops.pool.StaticFilesystemBackedPool) ResourcePool(org.platformlayer.ops.pool.ResourcePool) PlatformLayerKey(org.platformlayer.core.model.PlatformLayerKey) NetworkPoint(org.platformlayer.ops.networks.NetworkPoint) DirectHost(org.platformlayer.service.cloud.direct.model.DirectHost) OpsTarget(org.platformlayer.ops.OpsTarget) OpsProvider(org.platformlayer.ops.OpsProvider) NetworkPoolBuilder(org.platformlayer.ops.pool.NetworkPoolBuilder) AddressModel(org.platformlayer.core.model.AddressModel) File(java.io.File)

Aggregations

File (java.io.File)1 InetSocketAddress (java.net.InetSocketAddress)1 AddressModel (org.platformlayer.core.model.AddressModel)1 PlatformLayerKey (org.platformlayer.core.model.PlatformLayerKey)1 OpsProvider (org.platformlayer.ops.OpsProvider)1 OpsTarget (org.platformlayer.ops.OpsTarget)1 NetworkPoint (org.platformlayer.ops.networks.NetworkPoint)1 NetworkPoolBuilder (org.platformlayer.ops.pool.NetworkPoolBuilder)1 ResourcePool (org.platformlayer.ops.pool.ResourcePool)1 StaticFilesystemBackedPool (org.platformlayer.ops.pool.StaticFilesystemBackedPool)1 DirectHost (org.platformlayer.service.cloud.direct.model.DirectHost)1