Fix KubernetesPod tests
Project: http://git-wip-us.apache.org/repos/asf/brooklyn-server/repo Commit: http://git-wip-us.apache.org/repos/asf/brooklyn-server/commit/5656c432 Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-server/tree/5656c432 Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-server/diff/5656c432 Branch: refs/heads/master Commit: 5656c432d83e96a9f9f548a4277abe7a0261726b Parents: e05fbb6 Author: Andrew Donald Kennedy <[email protected]> Authored: Tue Jan 31 17:20:22 2017 +0000 Committer: Andrew Donald Kennedy <[email protected]> Committed: Fri May 19 14:01:20 2017 +0100 ---------------------------------------------------------------------- .../kubernetes/entity/KubernetesPod.java | 5 ----- .../kubernetes/location/KubernetesLocation.java | 13 ++----------- .../location/KubernetesLocationYamlLiveTest.java | 17 +++++++---------- .../openshift/location/OpenShiftLocation.java | 9 +-------- 4 files changed, 10 insertions(+), 34 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/5656c432/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 6ac2b89..4c334ec 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 @@ -25,11 +25,6 @@ public interface KubernetesPod extends DockerContainer { ConfigKey<Boolean> PRIVILEGED = KubernetesLocationConfig.PRIVILEGED; - ConfigKey<String> POD = ConfigKeys.builder(String.class) - .name("pod") - .description("The name of the pod") - .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/5656c432/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 0b2c41f..fa0250d 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 @@ -49,7 +49,6 @@ import org.slf4j.LoggerFactory; import com.google.common.base.Functions; import com.google.common.base.Joiner; -import com.google.common.base.MoreObjects; import com.google.common.base.Optional; import com.google.common.base.Predicate; import com.google.common.base.Predicates; @@ -190,7 +189,6 @@ public class KubernetesLocation extends AbstractLocation implements MachineProvi if (isKubernetesPod(entity) && entity.config().get(DockerContainer.IMAGE_NAME) == null && entity.config().get(DockerContainer.INBOUND_TCP_PORTS) == null && - entity.config().get(KubernetesPod.POD) == null && entity.getChildren().size() > 0) { return null; } @@ -653,19 +651,12 @@ public class KubernetesLocation extends AbstractLocation implements MachineProvi protected void deploy(final String namespace, Entity entity, Map<String, String> metadata, final String deploymentName, Container container, final Integer replicas, Map<String, String> secrets) { PodTemplateSpecBuilder podTemplateSpecBuilder = new PodTemplateSpecBuilder() .withNewMetadata() + .addToLabels("name", deploymentName) .addToLabels(metadata) .endMetadata() .withNewSpec() .addToContainers(container) .endSpec(); - if (isKubernetesPod(entity)) { - String podName = entity.config().get(KubernetesPod.POD); - if (Strings.isNonBlank(podName)) { - podTemplateSpecBuilder.editOrNewMetadata().withName(podName).endMetadata(); - } - } else { - podTemplateSpecBuilder.editOrNewMetadata().withName(deploymentName).endMetadata(); - } if (secrets != null) { for (String secretName : secrets.keySet()) { podTemplateSpecBuilder.withNewSpec() @@ -956,7 +947,7 @@ public class KubernetesLocation extends AbstractLocation implements MachineProvi } public boolean implementsInterface(Entity entity, Class<?> type) { - return Iterables.tryFind(Arrays.asList(entity.getClass().getInterfaces()), Predicates.instanceOf(type)).isPresent(); + return Iterables.tryFind(Arrays.asList(entity.getClass().getInterfaces()), Predicates.assignableFrom(type)).isPresent(); } @Override http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/5656c432/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 f392673..853fbe5 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 @@ -21,6 +21,7 @@ import java.util.Map; import org.apache.brooklyn.api.entity.Entity; import org.apache.brooklyn.api.location.MachineLocation; +import org.apache.brooklyn.api.location.MachineProvisioningLocation; import org.apache.brooklyn.camp.brooklyn.AbstractYamlTest; import org.apache.brooklyn.core.entity.Attributes; import org.apache.brooklyn.core.entity.Entities; @@ -33,7 +34,6 @@ import org.apache.brooklyn.entity.software.base.SoftwareProcess; import org.apache.brooklyn.entity.software.base.VanillaSoftwareProcess; import org.apache.brooklyn.location.ssh.SshMachineLocation; import org.apache.brooklyn.util.core.config.ConfigBag; -import org.apache.brooklyn.util.guava.Maybe; import org.apache.brooklyn.util.net.Networking; import org.apache.brooklyn.util.text.Identifiers; import org.apache.logging.log4j.util.Strings; @@ -214,16 +214,15 @@ public class KubernetesLocationYamlLiveTest extends AbstractYamlTest { " brooklyn.config:", " docker.container.imageName: tomcat", " docker.container.inboundPorts: [ \"8080\" ]", - " pod: tomcat-pod", " metadata:", " extra: test"); DockerContainer entity = runTomcat(yaml); - assertAttributeEqualsEventually(entity, KubernetesPod.KUBERNETES_POD, "tomcat-pod"); String namespace = entity.sensors().get(KubernetesPod.KUBERNETES_NAMESPACE); + String podName = entity.sensors().get(KubernetesPod.KUBERNETES_POD); KubernetesClient client = getClient(entity); - Pod pod = client.pods().inNamespace(namespace).withName("tomcat-pod").get(); + Pod pod = client.pods().inNamespace(namespace).withName(podName).get(); Map<String, String> labels = pod.getMetadata().getLabels(); assertTrue(labels.containsKey("extra")); assertEquals(labels.get("extra"), "test"); @@ -299,7 +298,7 @@ public class KubernetesLocationYamlLiveTest extends AbstractYamlTest { @Test(groups={"Live"}) public void testWordpressInPods() throws Exception { // TODO docker.container.inboundPorts doesn't accept list of ints - need to use quotes - String randomId = Identifiers.makeRandomId(4); + String randomId = Identifiers.makeRandomLowercaseId(4); String yaml = Joiner.on("\n").join( locationYaml, "services:", @@ -313,7 +312,6 @@ public class KubernetesLocationYamlLiveTest extends AbstractYamlTest { " docker.container.environment:", " MYSQL_ROOT_PASSWORD: \"password\"", " deployment: wordpress-mysql-" + randomId, - " pod: wordpress-mysql-pod-" + randomId, " - type: " + KubernetesPod.class.getName(), " id: wordpress", " name: wordpress", @@ -343,7 +341,6 @@ public class KubernetesLocationYamlLiveTest extends AbstractYamlTest { String mysqlPublicPort = assertAttributeEventuallyNonNull(mysql, Sensors.newStringSensor("docker.port.3306.mapped.public")); assertReachableEventually(HostAndPort.fromString(mysqlPublicPort)); - assertAttributeEqualsEventually(mysql, KubernetesPod.KUBERNETES_POD, "wordpress-mysql-pod-" + randomId); assertAttributeEqualsEventually(mysql, KubernetesPod.KUBERNETES_NAMESPACE, "amp"); assertAttributeEqualsEventually(mysql, KubernetesPod.KUBERNETES_SERVICE, "wordpress-mysql-" + randomId); @@ -443,9 +440,9 @@ public class KubernetesLocationYamlLiveTest extends AbstractYamlTest { } public KubernetesClient getClient(Entity entity) { - Maybe<KubernetesLocation> location = Machines.findUniqueElement(entity.getLocations(), KubernetesLocation.class); - if (location.isPresentAndNonNull()) { - KubernetesLocation kubernetes = location.get(); + MachineProvisioningLocation location = entity.sensors().get(SoftwareProcess.PROVISIONING_LOCATION); + if (location instanceof KubernetesLocation) { + KubernetesLocation kubernetes = (KubernetesLocation) location; ConfigBag config = kubernetes.config().getBag(); KubernetesClientRegistry registry = kubernetes.config().get(KubernetesLocationConfig.KUBERNETES_CLIENT_REGISTRY); KubernetesClient client = registry.getKubernetesClient(config); http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/5656c432/openshift-location/src/main/java/io/cloudsoft/amp/containerservice/openshift/location/OpenShiftLocation.java ---------------------------------------------------------------------- diff --git a/openshift-location/src/main/java/io/cloudsoft/amp/containerservice/openshift/location/OpenShiftLocation.java b/openshift-location/src/main/java/io/cloudsoft/amp/containerservice/openshift/location/OpenShiftLocation.java index c857ee2..84bc0a8 100644 --- a/openshift-location/src/main/java/io/cloudsoft/amp/containerservice/openshift/location/OpenShiftLocation.java +++ b/openshift-location/src/main/java/io/cloudsoft/amp/containerservice/openshift/location/OpenShiftLocation.java @@ -166,19 +166,12 @@ public class OpenShiftLocation extends KubernetesLocation implements OpenShiftLo protected void deploy(final String namespace, Entity entity, Map<String, String> metadata, final String deploymentName, Container container, final Integer replicas, Map<String, String> secrets) { PodTemplateSpecBuilder podTemplateSpecBuilder = new PodTemplateSpecBuilder() .withNewMetadata() + .addToLabels("name", deploymentName) .addToLabels(metadata) .endMetadata() .withNewSpec() .addToContainers(container) .endSpec(); - if (isKubernetesPod(entity)) { - String podName = entity.config().get(KubernetesPod.POD); - if (Strings.isNonBlank(podName)) { - podTemplateSpecBuilder.editOrNewMetadata().withName(podName).endMetadata(); - } - } else { - podTemplateSpecBuilder.editOrNewMetadata().withName(deploymentName).endMetadata(); - } if (secrets != null) { for (String secretName : secrets.keySet()) { podTemplateSpecBuilder.withNewSpec()
