Use KubernetesPod as entity for container deployment
Project: http://git-wip-us.apache.org/repos/asf/brooklyn-server/repo Commit: http://git-wip-us.apache.org/repos/asf/brooklyn-server/commit/eb94f08a Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-server/tree/eb94f08a Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-server/diff/eb94f08a Branch: refs/heads/master Commit: eb94f08aa791c8cbab53c462a44fe8d3dbdf3522 Parents: b78362c Author: Andrew Donald Kennedy <[email protected]> Authored: Sat Jan 28 00:55:22 2017 +0000 Committer: Andrew Donald Kennedy <[email protected]> Committed: Fri May 19 14:01:20 2017 +0100 ---------------------------------------------------------------------- .../kubernetes/entity/KubernetesPod.java | 6 +- .../kubernetes/entity/KubernetesPodImpl.java | 4 +- .../kubernetes/location/KubernetesLocation.java | 2 +- .../location/KubernetesLocationConfig.java | 17 ++-- .../KubernetesLocationYamlLiveTest.java | 100 ++++++++++--------- .../location/SimpleBlueprintsLiveTest.java | 37 ------- 6 files changed, 66 insertions(+), 100 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/eb94f08a/kubernetes-location/src/main/java/io/cloudsoft/amp/containerservice/kubernetes/entity/KubernetesPod.java ---------------------------------------------------------------------- diff --git a/kubernetes-location/src/main/java/io/cloudsoft/amp/containerservice/kubernetes/entity/KubernetesPod.java b/kubernetes-location/src/main/java/io/cloudsoft/amp/containerservice/kubernetes/entity/KubernetesPod.java index 9f23037..ae9bdb3 100644 --- a/kubernetes-location/src/main/java/io/cloudsoft/amp/containerservice/kubernetes/entity/KubernetesPod.java +++ b/kubernetes-location/src/main/java/io/cloudsoft/amp/containerservice/kubernetes/entity/KubernetesPod.java @@ -1,8 +1,10 @@ package io.cloudsoft.amp.containerservice.kubernetes.entity; import org.apache.brooklyn.api.entity.ImplementedBy; -import org.apache.brooklyn.entity.stock.BasicStartable; + +import io.cloudsoft.amp.containerservice.dockercontainer.DockerContainer; +import io.cloudsoft.amp.containerservice.kubernetes.location.KubernetesLocationConfig; @ImplementedBy(KubernetesPodImpl.class) -public interface KubernetesPod extends BasicStartable { +public interface KubernetesPod extends DockerContainer, KubernetesLocationConfig { } http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/eb94f08a/kubernetes-location/src/main/java/io/cloudsoft/amp/containerservice/kubernetes/entity/KubernetesPodImpl.java ---------------------------------------------------------------------- diff --git a/kubernetes-location/src/main/java/io/cloudsoft/amp/containerservice/kubernetes/entity/KubernetesPodImpl.java b/kubernetes-location/src/main/java/io/cloudsoft/amp/containerservice/kubernetes/entity/KubernetesPodImpl.java index 774a276..2acf734 100644 --- a/kubernetes-location/src/main/java/io/cloudsoft/amp/containerservice/kubernetes/entity/KubernetesPodImpl.java +++ b/kubernetes-location/src/main/java/io/cloudsoft/amp/containerservice/kubernetes/entity/KubernetesPodImpl.java @@ -1,7 +1,7 @@ package io.cloudsoft.amp.containerservice.kubernetes.entity; -import org.apache.brooklyn.entity.stock.BasicStartableImpl; +import io.cloudsoft.amp.containerservice.dockercontainer.DockerContainerImpl; -public class KubernetesPodImpl extends BasicStartableImpl implements KubernetesPod { +public class KubernetesPodImpl extends DockerContainerImpl implements KubernetesPod { } http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/eb94f08a/kubernetes-location/src/main/java/io/cloudsoft/amp/containerservice/kubernetes/location/KubernetesLocation.java ---------------------------------------------------------------------- diff --git a/kubernetes-location/src/main/java/io/cloudsoft/amp/containerservice/kubernetes/location/KubernetesLocation.java b/kubernetes-location/src/main/java/io/cloudsoft/amp/containerservice/kubernetes/location/KubernetesLocation.java index 4543b4d..1cf9545 100644 --- a/kubernetes-location/src/main/java/io/cloudsoft/amp/containerservice/kubernetes/location/KubernetesLocation.java +++ b/kubernetes-location/src/main/java/io/cloudsoft/amp/containerservice/kubernetes/location/KubernetesLocation.java @@ -98,7 +98,7 @@ import io.fabric8.kubernetes.api.model.extensions.DeploymentStatus; import io.fabric8.kubernetes.client.KubernetesClient; import io.fabric8.kubernetes.client.KubernetesClientException; -public class KubernetesLocation extends AbstractLocation implements MachineProvisioningLocation<MachineLocation>, KubernetesLocationConfig { +public class KubernetesLocation extends AbstractLocation implements MachineProvisioningLocation<MachineLocation>, CloudLocationConfig, KubernetesLocationConfig { /* * TODO http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/eb94f08a/kubernetes-location/src/main/java/io/cloudsoft/amp/containerservice/kubernetes/location/KubernetesLocationConfig.java ---------------------------------------------------------------------- diff --git a/kubernetes-location/src/main/java/io/cloudsoft/amp/containerservice/kubernetes/location/KubernetesLocationConfig.java b/kubernetes-location/src/main/java/io/cloudsoft/amp/containerservice/kubernetes/location/KubernetesLocationConfig.java index 0b90cac..c2e9d89 100644 --- a/kubernetes-location/src/main/java/io/cloudsoft/amp/containerservice/kubernetes/location/KubernetesLocationConfig.java +++ b/kubernetes-location/src/main/java/io/cloudsoft/amp/containerservice/kubernetes/location/KubernetesLocationConfig.java @@ -7,7 +7,6 @@ import org.apache.brooklyn.api.sensor.AttributeSensor; import org.apache.brooklyn.config.ConfigKey; import org.apache.brooklyn.core.config.ConfigKeys; import org.apache.brooklyn.core.location.LocationConfigKeys; -import org.apache.brooklyn.core.location.cloud.CloudLocationConfig; import org.apache.brooklyn.core.sensor.Sensors; import org.apache.brooklyn.util.core.flags.SetFromFlag; import org.apache.brooklyn.util.time.Duration; @@ -16,7 +15,7 @@ import com.google.common.base.Predicates; import com.google.common.collect.ImmutableMap; import com.google.common.reflect.TypeToken; -public interface KubernetesLocationConfig extends CloudLocationConfig { +public interface KubernetesLocationConfig { @SetFromFlag("endpoint") ConfigKey<String> MASTER_URL = LocationConfigKeys.CLOUD_ENDPOINT; @@ -89,13 +88,6 @@ public interface KubernetesLocationConfig extends CloudLocationConfig { .constraint(Predicates.<Duration>notNull()) .build(); - ConfigKey<String> NAMESPACE = ConfigKeys.builder(String.class) - .name("namespace") - .description("Namespace where resources will live; the default is 'amp'") - .defaultValue("amp") - .constraint(Predicates.<String>notNull()) - .build(); - ConfigKey<Boolean> CREATE_NAMESPACE = ConfigKeys.builder(Boolean.class) .name("namespace.create") .description("Whether to create the namespace if it does not exist") @@ -110,6 +102,13 @@ public interface KubernetesLocationConfig extends CloudLocationConfig { .constraint(Predicates.<Boolean>notNull()) .build(); + ConfigKey<String> NAMESPACE = ConfigKeys.builder(String.class) + .name("namespace") + .description("Namespace where resources will live; the default is 'amp'") + .defaultValue("amp") + .constraint(Predicates.<String>notNull()) + .build(); + @SuppressWarnings("serial") ConfigKey<List<String>> PERSISTENT_VOLUMES = ConfigKeys.builder(new TypeToken<List<String>>() {}) .name("persistentVolumes") http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/eb94f08a/kubernetes-location/src/test/java/io/cloudsoft/amp/containerservice/kubernetes/location/KubernetesLocationYamlLiveTest.java ---------------------------------------------------------------------- diff --git a/kubernetes-location/src/test/java/io/cloudsoft/amp/containerservice/kubernetes/location/KubernetesLocationYamlLiveTest.java b/kubernetes-location/src/test/java/io/cloudsoft/amp/containerservice/kubernetes/location/KubernetesLocationYamlLiveTest.java index 11c78ef..962be36 100644 --- a/kubernetes-location/src/test/java/io/cloudsoft/amp/containerservice/kubernetes/location/KubernetesLocationYamlLiveTest.java +++ b/kubernetes-location/src/test/java/io/cloudsoft/amp/containerservice/kubernetes/location/KubernetesLocationYamlLiveTest.java @@ -30,6 +30,7 @@ import org.apache.brooklyn.core.sensor.Sensors; import org.apache.brooklyn.entity.software.base.EmptySoftwareProcess; import org.apache.brooklyn.entity.software.base.SoftwareProcess; import org.apache.brooklyn.entity.software.base.VanillaSoftwareProcess; +import org.apache.brooklyn.entity.stock.BasicStartable; import org.apache.brooklyn.location.ssh.SshMachineLocation; import org.apache.brooklyn.util.net.Networking; import org.apache.brooklyn.util.text.Identifiers; @@ -42,7 +43,6 @@ import com.google.common.collect.ImmutableList; import com.google.common.collect.Iterables; import com.google.common.net.HostAndPort; -import io.cloudsoft.amp.containerservice.dockercontainer.DockerContainer; import io.cloudsoft.amp.containerservice.kubernetes.entity.KubernetesPod; import io.cloudsoft.amp.containerservice.kubernetes.entity.KubernetesResource; @@ -70,7 +70,7 @@ public class KubernetesLocationYamlLiveTest extends AbstractYamlTest { locationYaml = Joiner.on("\n").join( "location:", " kubernetes:", - " " + KubernetesLocationConfig.CLOUD_ENDPOINT.getName() + ": \"" + KUBERNETES_ENDPOINT + "\"", + " " + KubernetesLocationConfig.MASTER_URL.getName() + ": \"" + KUBERNETES_ENDPOINT + "\"", " " + (Strings.isBlank(IDENTITY) ? "" : "identity: "+IDENTITY), " " + (Strings.isBlank(CREDENTIAL) ? "" : "credential: "+CREDENTIAL)); } @@ -195,12 +195,12 @@ public class KubernetesLocationYamlLiveTest extends AbstractYamlTest { String yaml = Joiner.on("\n").join( locationYaml, "services:", - "- type: " + DockerContainer.class.getName(), + "- type: " + KubernetesPod.class.getName(), " brooklyn.config:", " docker.container.imageName: tomcat", " docker.container.inboundPorts: [ \"8080\" ]"); Entity app = createStartWaitAndLogApplication(yaml); - DockerContainer entity = Iterables.getOnlyElement(Entities.descendantsAndSelf(app, DockerContainer.class)); + KubernetesPod entity = Iterables.getOnlyElement(Entities.descendantsAndSelf(app, KubernetesPod.class)); Entities.dumpInfo(app); String publicMapped = assertAttributeEventuallyNonNull(entity, Sensors.newStringSensor("docker.port.8080.mapped.public")); @@ -212,32 +212,64 @@ public class KubernetesLocationYamlLiveTest extends AbstractYamlTest { @Test(groups={"Live"}) - public void testWordpressInPod() throws Exception { + public void testWordpressInContainers() throws Exception { // TODO docker.container.inboundPorts doesn't accept list of ints - need to use quotes String randomId = Identifiers.makeRandomLowercaseId(4); String yaml = Joiner.on("\n").join( locationYaml, "services:", - "- type: " + KubernetesPod.class.getName(), - " brooklyn.children:", - " - type: " + DockerContainer.class.getName(), + " - type: " + KubernetesPod.class.getName(), + " brooklyn.children:", + " - type: " + KubernetesPod.class.getName(), + " id: wordpress-mysql", + " name: mysql", + " brooklyn.config:", + " docker.container.imageName: mysql:5.6", + " docker.container.inboundPorts:", + " - \"3306\"", + " docker.container.environment:", + " MYSQL_ROOT_PASSWORD: \"password\"", + " provisioning.properties:", + " deployment: wordpress-mysql-" + randomId, + " - type: " + KubernetesPod.class.getName(), + " id: wordpress", + " name: wordpress", + " brooklyn.config:", + " docker.container.imageName: wordpress:4.4-apache", + " docker.container.inboundPorts:", + " - \"80\"", + " docker.container.environment:", + " WORDPRESS_DB_HOST: \"wordpress-mysql\"", + " WORDPRESS_DB_PASSWORD: \"password\"", + " provisioning.properties:", + " deployment: wordpress-" + randomId); + + runWordpress(yaml); + } + + @Test(groups={"Live"}) + public void testWordpressInSeperatePods() throws Exception { + // TODO docker.container.inboundPorts doesn't accept list of ints - need to use quotes + String randomId = Identifiers.makeRandomId(4); + String yaml = Joiner.on("\n").join( + locationYaml, + "services:", + " - type: " + KubernetesPod.class.getName(), " id: wordpress-mysql", " name: mysql", " brooklyn.config:", " docker.container.imageName: mysql:5.6", " docker.container.inboundPorts:", - " - \"3306\"", + " - \"3306\"", " docker.container.environment:", " MYSQL_ROOT_PASSWORD: \"password\"", - " provisioning.properties:", - " deployment: wordpress-mysql-" + randomId, - " - type: " + DockerContainer.class.getName(), + " - type: " + KubernetesPod.class.getName(), " id: wordpress", " name: wordpress", " brooklyn.config:", " docker.container.imageName: wordpress:4-apache", " docker.container.inboundPorts:", - " - \"80\"", + " - \"80\"", " docker.container.environment:", " WORDPRESS_DB_HOST: \"wordpress-mysql\"", " WORDPRESS_DB_PASSWORD: \"password\"", @@ -247,45 +279,17 @@ public class KubernetesLocationYamlLiveTest extends AbstractYamlTest { runWordpress(yaml); } - @Test(groups={"Live"}) - public void testWordpressInSeperatePods() throws Exception { - // TODO docker.container.inboundPorts doesn't accept list of ints - need to use quotes - String yaml = Joiner.on("\n").join( - locationYaml, - "services:", - "- type: " + DockerContainer.class.getName(), - " id: wordpress-mysql", - " name: mysql", - " brooklyn.config:", - " docker.container.imageName: mysql:5.6", - " docker.container.inboundPorts:", - " - \"3306\"", - " docker.container.environment:", - " MYSQL_ROOT_PASSWORD: \"password\"", - "- type: " + DockerContainer.class.getName(), - " id: wordpress", - " name: wordpress", - " brooklyn.config:", - " docker.container.imageName: wordpress:4-apache", - " docker.container.inboundPorts:", - " - \"80\"", - " docker.container.environment:", - " WORDPRESS_DB_HOST: \"wordpress-mysql\"", - " WORDPRESS_DB_PASSWORD: \"password\""); - runWordpress(yaml); - } - /** - * Assumes that the {@link DockerContainer} entities have display names of "mysql" and "wordpress", + * Assumes that the {@link KubernetesPod} entities have display names of "mysql" and "wordpress", * and that they use ports 3306 and 80 respectively. */ protected void runWordpress(String yaml) throws Exception { Entity app = createStartWaitAndLogApplication(yaml); Entities.dumpInfo(app); - Iterable<DockerContainer> containers = Entities.descendantsAndSelf(app, DockerContainer.class); - DockerContainer mysql = Iterables.find(containers, EntityPredicates.displayNameEqualTo("mysql")); - DockerContainer wordpress = Iterables.find(containers, EntityPredicates.displayNameEqualTo("wordpress")); + Iterable<KubernetesPod> containers = Entities.descendantsAndSelf(app, KubernetesPod.class); + KubernetesPod mysql = Iterables.find(containers, EntityPredicates.displayNameEqualTo("mysql")); + KubernetesPod wordpress = Iterables.find(containers, EntityPredicates.displayNameEqualTo("wordpress")); String mysqlPublicPort = assertAttributeEventuallyNonNull(mysql, Sensors.newStringSensor("docker.port.3306.mapped.public")); assertReachableEventually(HostAndPort.fromString(mysqlPublicPort)); @@ -301,9 +305,7 @@ public class KubernetesLocationYamlLiveTest extends AbstractYamlTest { String yaml = Joiner.on("\n").join( locationYaml, "services:", - "- type: " + KubernetesPod.class.getName(), - " brooklyn.children:", - " - type: " + DockerContainer.class.getName(), + " - type: " + KubernetesPod.class.getName(), " brooklyn.config:", " docker.container.imageName: tomcat", " docker.container.inboundPorts:", @@ -312,7 +314,7 @@ public class KubernetesLocationYamlLiveTest extends AbstractYamlTest { " CLUSTER_ID: \"id\"", " CLUSTER_TOKEN: \"token\""); Entity app = createStartWaitAndLogApplication(yaml); - DockerContainer container = Iterables.getOnlyElement(Entities.descendantsAndSelf(app, DockerContainer.class)); + KubernetesPod container = Iterables.getOnlyElement(Entities.descendantsAndSelf(app, KubernetesPod.class)); Entities.dumpInfo(app); http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/eb94f08a/kubernetes-location/src/test/java/io/cloudsoft/amp/containerservice/kubernetes/location/SimpleBlueprintsLiveTest.java ---------------------------------------------------------------------- diff --git a/kubernetes-location/src/test/java/io/cloudsoft/amp/containerservice/kubernetes/location/SimpleBlueprintsLiveTest.java b/kubernetes-location/src/test/java/io/cloudsoft/amp/containerservice/kubernetes/location/SimpleBlueprintsLiveTest.java deleted file mode 100644 index 34e57e6..0000000 --- a/kubernetes-location/src/test/java/io/cloudsoft/amp/containerservice/kubernetes/location/SimpleBlueprintsLiveTest.java +++ /dev/null @@ -1,37 +0,0 @@ -package io.cloudsoft.amp.containerservice.kubernetes.location; - -import org.apache.brooklyn.launcher.blueprints.AbstractBlueprintTest; -import org.testng.annotations.Test; - -public class SimpleBlueprintsLiveTest extends AbstractBlueprintTest { - - // TODO The yaml hard-codes a k8s endpoint URL that is no longer running - @Test(groups={"Live", "Broken"}, enabled=false) - public void testSimpleServer() throws Exception { - runTest("blueprints/simple-server-on-kubernetes.yaml"); - } - - // TODO The yaml hard-codes a k8s endpoint URL that is no longer running - @Test(groups={"Live", "Broken"}, enabled=false) - public void testVanillaSoftwareProcess() throws Exception { - runTest("blueprints/vanilla-software-process-on-kubernetes.yaml"); - } - - // TODO The yaml hard-codes a k8s endpoint URL that is no longer running - @Test(groups={"Live", "Broken"}, enabled=false) - public void testTomcatDockerImage() throws Exception { - runTest("blueprints/tomcat-docker-image-on-kubernetes.yaml"); - } - - // TODO The yaml hard-codes a k8s endpoint URL that is no longer running - @Test(groups={"Live", "Broken"}, enabled=false) - public void testWordpressDockerImage() throws Exception { - runTest("blueprints/mysql_wordpress-docker-images-on-kubernetes.yaml"); - } - - // TODO The yaml hard-codes a k8s endpoint URL that is no longer running - @Test(groups={"Live", "Broken"}, enabled=false) - public void testIronRunnerDockerImage() throws Exception { - runTest("blueprints/iron_runner-docker-image-on-kubernetes.yaml"); - } -}
