Search in sources :

Example 1 with Context

use of de.widdix.awscftemplates.Context in project aws-cf-templates by widdix.

the class TestECSService method testWaf.

@Test
public void testWaf() {
    final Context context = new Context();
    final String vpcStackName = "vpc-2azs-" + this.random8String();
    final String wafStackName = "waf-" + this.random8String();
    final String clusterStackName = "ecs-cluster-" + this.random8String();
    final String stackName = "ecs-service-" + this.random8String();
    final String classB = "10";
    final String keyName = "key-" + this.random8String();
    try {
        this.createKey(keyName);
        try {
            this.createStack(context, vpcStackName, "vpc/vpc-2azs.yaml", new Parameter().withParameterKey("ClassB").withParameterValue(classB));
            try {
                this.createStack(context, wafStackName, "security/waf.yaml");
                try {
                    this.createStack(context, clusterStackName, "ecs/cluster.yaml", new Parameter().withParameterKey("ParentVPCStack").withParameterValue(vpcStackName), new Parameter().withParameterKey("ParentWAFStack").withParameterValue(wafStackName), new Parameter().withParameterKey("KeyName").withParameterValue(keyName));
                    try {
                        this.createStack(context, stackName, "ecs/service-dedicated-alb.yaml", new Parameter().withParameterKey("ParentVPCStack").withParameterValue(vpcStackName), new Parameter().withParameterKey("ParentWAFStack").withParameterValue(wafStackName), new Parameter().withParameterKey("ParentClusterStack").withParameterValue(clusterStackName), new Parameter().withParameterKey("Image").withParameterValue("nginx:1.11.5"));
                        final String url = this.getStackOutputValue(stackName, "URL");
                        final Callable<String> callable = () -> {
                            final HttpResponse response = WS.url(url).timeout(10000).get();
                            // check HTTP response code
                            if (WS.getStatus(response) != 200) {
                                throw new RuntimeException("200 expected, but saw " + WS.getStatus(response));
                            }
                            return WS.getResponseAsString(response);
                        };
                        final String response = this.retry(context, callable);
                        // check if nginx page appears
                        Assert.assertTrue("http response body contains \"Welcome to nginx!\"", response.contains("Welcome to nginx!"));
                    } finally {
                        this.deleteStack(context, stackName);
                    }
                } finally {
                    this.deleteStack(context, clusterStackName);
                }
            } finally {
                this.deleteStack(context, wafStackName);
            }
        } finally {
            this.deleteStack(context, vpcStackName);
        }
    } finally {
        this.deleteKey(context, keyName);
    }
}
Also used : Context(de.widdix.awscftemplates.Context) Parameter(com.amazonaws.services.cloudformation.model.Parameter) HttpResponse(org.apache.http.HttpResponse) ACloudFormationTest(de.widdix.awscftemplates.ACloudFormationTest) Test(org.junit.Test)

Example 2 with Context

use of de.widdix.awscftemplates.Context in project aws-cf-templates by widdix.

the class TestECSService method testClusterAlbHostPattern.

@Test
public void testClusterAlbHostPattern() {
    final Context context = new Context();
    final String zoneStackName = "zone-" + this.random8String();
    final String vpcStackName = "vpc-2azs-" + this.random8String();
    final String clusterStackName = "ecs-cluster-" + this.random8String();
    final String stackName = "ecs-service-" + this.random8String();
    final String classB = "10";
    final String keyName = "key-" + this.random8String();
    final String subDomainName = stackName;
    try {
        this.createKey(keyName);
        try {
            this.createStack(context, zoneStackName, "vpc/zone-legacy.yaml", new Parameter().withParameterKey("HostedZoneName").withParameterValue(Config.get(Config.Key.DOMAIN_SUFFIX)), new Parameter().withParameterKey("HostedZoneId").withParameterValue(Config.get(Config.Key.HOSTED_ZONE_ID)));
            try {
                this.createStack(context, vpcStackName, "vpc/vpc-2azs.yaml", new Parameter().withParameterKey("ClassB").withParameterValue(classB));
                try {
                    this.createStack(context, clusterStackName, "ecs/cluster.yaml", new Parameter().withParameterKey("ParentVPCStack").withParameterValue(vpcStackName), new Parameter().withParameterKey("KeyName").withParameterValue(keyName));
                    try {
                        final String domain = subDomainName + "." + Config.get(Config.Key.DOMAIN_SUFFIX);
                        this.createStack(context, stackName, "ecs/service-cluster-alb.yaml", new Parameter().withParameterKey("ParentClusterStack").withParameterValue(clusterStackName), new Parameter().withParameterKey("ParentZoneStack").withParameterValue(zoneStackName), new Parameter().withParameterKey("SubDomainNameWithDot").withParameterValue(subDomainName + "."), new Parameter().withParameterKey("Image").withParameterValue("nginx:1.11.5"), new Parameter().withParameterKey("LoadBalancerPath").withParameterValue(""), new Parameter().withParameterKey("LoadBalancerHostPattern").withParameterValue(domain));
                        final String url = "http://" + domain;
                        final Callable<String> callable = () -> {
                            final HttpResponse response = WS.url(url).timeout(10000).get();
                            // check HTTP response code
                            if (WS.getStatus(response) != 200) {
                                throw new RuntimeException("200 expected, but saw " + WS.getStatus(response));
                            }
                            return WS.getResponseAsString(response);
                        };
                        final String response = this.retry(context, callable);
                        // check if nginx page appears
                        Assert.assertTrue("http response body contains \"Welcome to nginx!\"", response.contains("Welcome to nginx!"));
                    } finally {
                        this.deleteStack(context, stackName);
                    }
                } finally {
                    this.deleteStack(context, clusterStackName);
                }
            } finally {
                this.deleteStack(context, vpcStackName);
            }
        } finally {
            this.deleteStack(context, zoneStackName);
        }
    } finally {
        this.deleteKey(context, keyName);
    }
}
Also used : Context(de.widdix.awscftemplates.Context) Parameter(com.amazonaws.services.cloudformation.model.Parameter) HttpResponse(org.apache.http.HttpResponse) ACloudFormationTest(de.widdix.awscftemplates.ACloudFormationTest) Test(org.junit.Test)

Example 3 with Context

use of de.widdix.awscftemplates.Context in project aws-cf-templates by widdix.

the class TestECSService method testDedicatedAlb.

@Test
public void testDedicatedAlb() {
    final Context context = new Context();
    final String vpcStackName = "vpc-2azs-" + this.random8String();
    final String clusterStackName = "ecs-cluster-" + this.random8String();
    final String stackName = "ecs-service-" + this.random8String();
    final String classB = "10";
    final String keyName = "key-" + this.random8String();
    try {
        this.createKey(keyName);
        try {
            this.createStack(context, vpcStackName, "vpc/vpc-2azs.yaml", new Parameter().withParameterKey("ClassB").withParameterValue(classB));
            try {
                this.createStack(context, clusterStackName, "ecs/cluster.yaml", new Parameter().withParameterKey("ParentVPCStack").withParameterValue(vpcStackName), new Parameter().withParameterKey("KeyName").withParameterValue(keyName));
                try {
                    this.createStack(context, stackName, "ecs/service-dedicated-alb.yaml", new Parameter().withParameterKey("ParentVPCStack").withParameterValue(vpcStackName), new Parameter().withParameterKey("ParentClusterStack").withParameterValue(clusterStackName), new Parameter().withParameterKey("Image").withParameterValue("nginx:1.11.5"));
                    final String url = this.getStackOutputValue(stackName, "URL");
                    final Callable<String> callable = () -> {
                        final HttpResponse response = WS.url(url).timeout(10000).get();
                        // check HTTP response code
                        if (WS.getStatus(response) != 200) {
                            throw new RuntimeException("200 expected, but saw " + WS.getStatus(response));
                        }
                        return WS.getResponseAsString(response);
                    };
                    final String response = this.retry(context, callable);
                    // check if nginx page appears
                    Assert.assertTrue("http response body contains \"Welcome to nginx!\"", response.contains("Welcome to nginx!"));
                } finally {
                    this.deleteStack(context, stackName);
                }
            } finally {
                this.deleteStack(context, clusterStackName);
            }
        } finally {
            this.deleteStack(context, vpcStackName);
        }
    } finally {
        this.deleteKey(context, keyName);
    }
}
Also used : Context(de.widdix.awscftemplates.Context) Parameter(com.amazonaws.services.cloudformation.model.Parameter) HttpResponse(org.apache.http.HttpResponse) ACloudFormationTest(de.widdix.awscftemplates.ACloudFormationTest) Test(org.junit.Test)

Example 4 with Context

use of de.widdix.awscftemplates.Context in project aws-cf-templates by widdix.

the class TestFargateService method testDedicatedAlb.

@Test
public void testDedicatedAlb() {
    final Context context = new Context();
    final String vpcStackName = "vpc-2azs-" + this.random8String();
    final String clusterStackName = "fargate-cluster-" + this.random8String();
    final String stackName = "fargate-service-" + this.random8String();
    final String classB = "10";
    try {
        this.createStack(context, vpcStackName, "vpc/vpc-2azs.yaml", new Parameter().withParameterKey("ClassB").withParameterValue(classB));
        try {
            this.createStack(context, clusterStackName, "fargate/cluster.yaml", new Parameter().withParameterKey("ParentVPCStack").withParameterValue(vpcStackName));
            try {
                this.createStack(context, stackName, "fargate/service-dedicated-alb.yaml", new Parameter().withParameterKey("ParentVPCStack").withParameterValue(vpcStackName), new Parameter().withParameterKey("ParentClusterStack").withParameterValue(clusterStackName), new Parameter().withParameterKey("AppImage").withParameterValue("nginx:1.11.5"));
                final String url = this.getStackOutputValue(stackName, "URL");
                final Callable<String> callable = () -> {
                    final HttpResponse response = WS.url(url).timeout(10000).get();
                    // check HTTP response code
                    if (WS.getStatus(response) != 200) {
                        throw new RuntimeException("200 expected, but saw " + WS.getStatus(response));
                    }
                    return WS.getResponseAsString(response);
                };
                final String response = this.retry(context, callable);
                // check if nginx page appears
                Assert.assertTrue("http response body contains \"Welcome to nginx!\"", response.contains("Welcome to nginx!"));
            } finally {
                this.deleteStack(context, stackName);
            }
        } finally {
            this.deleteStack(context, clusterStackName);
        }
    } finally {
        this.deleteStack(context, vpcStackName);
    }
}
Also used : Context(de.widdix.awscftemplates.Context) Parameter(com.amazonaws.services.cloudformation.model.Parameter) HttpResponse(org.apache.http.HttpResponse) ACloudFormationTest(de.widdix.awscftemplates.ACloudFormationTest) Test(org.junit.Test)

Example 5 with Context

use of de.widdix.awscftemplates.Context in project aws-cf-templates by widdix.

the class TestFargateService method testClusterAlbPathPattern.

@Test
public void testClusterAlbPathPattern() {
    final Context context = new Context();
    final String vpcStackName = "vpc-2azs-" + this.random8String();
    final String clusterStackName = "fargate-cluster-" + this.random8String();
    final String stackName = "fargate-service-" + this.random8String();
    final String classB = "10";
    final String keyName = "key-" + this.random8String();
    try {
        this.createKey(keyName);
        try {
            this.createStack(context, vpcStackName, "vpc/vpc-2azs.yaml", new Parameter().withParameterKey("ClassB").withParameterValue(classB));
            try {
                this.createStack(context, clusterStackName, "fargate/cluster.yaml", new Parameter().withParameterKey("ParentVPCStack").withParameterValue(vpcStackName));
                final String url = this.getStackOutputValue(clusterStackName, "URL");
                try {
                    this.createStack(context, stackName, "fargate/service-cluster-alb.yaml", new Parameter().withParameterKey("ParentVPCStack").withParameterValue(vpcStackName), new Parameter().withParameterKey("ParentClusterStack").withParameterValue(clusterStackName), new Parameter().withParameterKey("AppImage").withParameterValue("nginx:1.11.5"), new Parameter().withParameterKey("Spot").withParameterValue("true"));
                    final Callable<String> callable = () -> {
                        final HttpResponse response = WS.url(url).timeout(10000).get();
                        // check HTTP response code
                        if (WS.getStatus(response) != 200) {
                            throw new RuntimeException("200 expected, but saw " + WS.getStatus(response));
                        }
                        return WS.getResponseAsString(response);
                    };
                    final String response = this.retry(context, callable);
                    // check if nginx page appears
                    Assert.assertTrue("http response body contains \"Welcome to nginx!\"", response.contains("Welcome to nginx!"));
                } finally {
                    this.deleteStack(context, stackName);
                }
            } finally {
                this.deleteStack(context, clusterStackName);
            }
        } finally {
            this.deleteStack(context, vpcStackName);
        }
    } finally {
        this.deleteKey(context, keyName);
    }
}
Also used : Context(de.widdix.awscftemplates.Context) Parameter(com.amazonaws.services.cloudformation.model.Parameter) HttpResponse(org.apache.http.HttpResponse) ACloudFormationTest(de.widdix.awscftemplates.ACloudFormationTest) Test(org.junit.Test)

Aggregations

Context (de.widdix.awscftemplates.Context)70 Test (org.junit.Test)70 Parameter (com.amazonaws.services.cloudformation.model.Parameter)66 ACloudFormationTest (de.widdix.awscftemplates.ACloudFormationTest)62 HttpResponse (org.apache.http.HttpResponse)19 KeyPair (com.amazonaws.services.ec2.model.KeyPair)4 DescribeContainerInstancesRequest (com.amazonaws.services.ecs.model.DescribeContainerInstancesRequest)2 DescribeContainerInstancesResult (com.amazonaws.services.ecs.model.DescribeContainerInstancesResult)2 ListContainerInstancesRequest (com.amazonaws.services.ecs.model.ListContainerInstancesRequest)2 ListContainerInstancesResult (com.amazonaws.services.ecs.model.ListContainerInstancesResult)2 Session (com.jcraft.jsch.Session)1 Ignore (org.junit.Ignore)1