Search in sources :

Example 1 with AptCacheService

use of org.platformlayer.service.aptcache.model.AptCacheService in project platformlayer by platformlayer.

the class AptCacheServiceController method getUrl.

@Override
public String getUrl(Object modelObject, NetworkPoint forNetworkPoint, URI uri) throws OpsException {
    AptCacheService model = (AptCacheService) modelObject;
    if (model.getState() != ManagedItemState.ACTIVE) {
        log.info("Cache not active; returning null URL");
        return null;
    }
    // {
    // // By DNS
    // String dnsName = aptCacheService.getDnsName();
    // String address = "http://" + dnsName + ":3128/";
    // proxies.add(address);
    // }
    //
    // {
    // By IP
    NetworkPoint networkPoint = network.findNetworkPoint(model);
    if (networkPoint == null) {
        log.info("Machine not found for cache; returning null URL");
        return null;
    }
    String address = "http://" + networkPoint.getBestAddress(forNetworkPoint) + ":3128/";
    return address;
}
Also used : AptCacheService(org.platformlayer.service.aptcache.model.AptCacheService) NetworkPoint(org.platformlayer.ops.networks.NetworkPoint)

Example 2 with AptCacheService

use of org.platformlayer.service.aptcache.model.AptCacheService in project platformlayer by platformlayer.

the class AptCacheServiceController method addChildren.

@Override
protected void addChildren() throws OpsException {
    AptCacheService model = OpsContext.get().getInstance(AptCacheService.class);
    // TODO: Create endpoint with default port; maybe default to closed?
    // model.dnsName
    InstanceBuilder instance = InstanceBuilder.build(model.dnsName, this, model.getTags());
    instance.hostPolicy.allowRunInContainer = true;
    addChild(instance);
    instance.addChild(PackageDependency.build("squid3"));
    instance.addChild(SimpleFile.build(getClass(), new File("/etc/squid3/squid.conf")));
    instance.addChild(ManagedService.build("squid3"));
    // instance.addChild(CollectdCollector.build());
    {
        PublicEndpoint endpoint = injected(PublicEndpoint.class);
        endpoint.publicPort = PORT;
        endpoint.backendPort = PORT;
        endpoint.dnsName = model.dnsName;
        endpoint.tagItem = model.getKey();
        endpoint.parentItem = model.getKey();
        instance.addChild(endpoint);
    }
}
Also used : AptCacheService(org.platformlayer.service.aptcache.model.AptCacheService) PublicEndpoint(org.platformlayer.ops.networks.PublicEndpoint) File(java.io.File) SimpleFile(org.platformlayer.ops.filesystem.SimpleFile) InstanceBuilder(org.platformlayer.ops.instances.InstanceBuilder)

Example 3 with AptCacheService

use of org.platformlayer.service.aptcache.model.AptCacheService in project platformlayer by platformlayer.

the class ITAptCacheService method testCreateAndDeleteItem.

@Test
public void testCreateAndDeleteItem() throws Exception {
    String id = random.randomAlphanumericString(8);
    AptCacheService aptCache = new AptCacheService();
    aptCache.dnsName = id + ".test.platformlayer.org";
    aptCache = putItem(id, aptCache);
    aptCache = waitForHealthy(aptCache);
    InetSocketAddress socketAddress = getUniqueEndpoint(aptCache);
    Assert.assertFalse(isPortOpen(socketAddress));
    openFirewall(aptCache, AptCacheServiceController.PORT);
    Assert.assertTrue(isPortOpen(socketAddress));
    // TODO: Make endpoint http://<ip>:<port>/ ???
    // String httpUrl = "http://" + socketAddress.getAddress().getHostAddress() + ":" + socketAddress.getPort();
    String html = testProxy(socketAddress, "http://www.google.com/");
    Assert.assertTrue(html.contains("Search the world"));
    deleteItem(aptCache);
}
Also used : AptCacheService(org.platformlayer.service.aptcache.model.AptCacheService) InetSocketAddress(java.net.InetSocketAddress) Test(org.testng.annotations.Test) PlatformLayerApiTest(org.platformlayer.tests.PlatformLayerApiTest)

Aggregations

AptCacheService (org.platformlayer.service.aptcache.model.AptCacheService)3 File (java.io.File)1 InetSocketAddress (java.net.InetSocketAddress)1 SimpleFile (org.platformlayer.ops.filesystem.SimpleFile)1 InstanceBuilder (org.platformlayer.ops.instances.InstanceBuilder)1 NetworkPoint (org.platformlayer.ops.networks.NetworkPoint)1 PublicEndpoint (org.platformlayer.ops.networks.PublicEndpoint)1 PlatformLayerApiTest (org.platformlayer.tests.PlatformLayerApiTest)1 Test (org.testng.annotations.Test)1