Add static fields for constants
Project: http://git-wip-us.apache.org/repos/asf/brooklyn-server/repo Commit: http://git-wip-us.apache.org/repos/asf/brooklyn-server/commit/6c4386ba Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-server/tree/6c4386ba Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-server/diff/6c4386ba Branch: refs/heads/master Commit: 6c4386ba07360b10c99ed23da34a2d7321291772 Parents: 3d00095 Author: Andrew Donald Kennedy <[email protected]> Authored: Tue Jan 31 05:16:48 2017 +0000 Committer: Andrew Donald Kennedy <[email protected]> Committed: Fri May 19 14:01:20 2017 +0100 ---------------------------------------------------------------------- .../kubernetes/location/KubernetesLocation.java | 36 ++++++++++++-------- .../openshift/entity/OpenShiftPodImpl.java | 2 +- .../openshift/location/OpenShiftLocation.java | 4 +-- 3 files changed, 25 insertions(+), 17 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/6c4386ba/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 cd44f37..62285dc 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 @@ -120,19 +120,27 @@ public class KubernetesLocation extends AbstractLocation implements MachineProvi private static final Logger LOG = LoggerFactory.getLogger(KubernetesLocation.class); - public static final String SERVER_TYPE = "NodePort"; + public static final String NODE_PORT = "NodePort"; + public static final String IMMUTABLE_CONTAINER_KEY = "immutable-container"; public static final String SSHABLE_CONTAINER = "sshable-container"; public static final String CLOUDSOFT_ENTITY_ID = "cloudsoft.io/entity-id"; public static final String CLOUDSOFT_APPLICATION_ID = "cloudsoft.io/application-id"; + public static final String KUBERNETES_DOCKERCFG = "kubernetes.io/dockercfg"; + + public static final String PHASE_TERMINATING = "Terminating"; + public static final String PHASE_ACTIVE = "Active"; /** * The regex for the image descriptions that support us injecting login credentials. */ - private static final List<String> IMAGE_DESCRIPTION_REGEXES_REQUIRING_INJECTED_LOGIN_CREDS = ImmutableList.of( + public static final List<String> IMAGE_DESCRIPTION_REGEXES_REQUIRING_INJECTED_LOGIN_CREDS = ImmutableList.of( "cloudsoft/centos.*", "cloudsoft/ubuntu.*"); + /** The environment variable for injecting login credentials. */ + public static final String CLOUDSOFT_ROOT_PASSWORD = "CLOUDSOFT_ROOT_PASSWORD"; + private KubernetesClient client; public KubernetesLocation() { @@ -280,7 +288,7 @@ public class KubernetesLocation extends AbstractLocation implements MachineProvi protected synchronized void deleteEmptyNamespace(final String name) { if (!name.equals("default") && isNamespaceEmpty(name)) { if (client.namespaces().withName(name).get() != null && - !client.namespaces().withName(name).get().getStatus().getPhase().equals("Terminating")) { + !client.namespaces().withName(name).get().getStatus().getPhase().equals(PHASE_TERMINATING)) { client.namespaces().withName(name).delete(); ExitCondition exitCondition = new ExitCondition() { @Override @@ -515,7 +523,7 @@ public class KubernetesLocation extends AbstractLocation implements MachineProvi @Override public Boolean call() { Namespace actualNamespace = client.namespaces().withName(name).get(); - return actualNamespace != null && actualNamespace.getStatus().getPhase().equals("Active"); + return actualNamespace != null && actualNamespace.getStatus().getPhase().equals(PHASE_ACTIVE); } @Override public String getFailureMessage() { @@ -585,7 +593,7 @@ public class KubernetesLocation extends AbstractLocation implements MachineProvi .withNewMetadata() .withName(secretName) .endMetadata() - .withType("kubernetes.io/dockercfg") + .withType(KUBERNETES_DOCKERCFG) .withData(ImmutableMap.of(".dockercfg", base64encoded)) .build(); try { @@ -706,7 +714,7 @@ public class KubernetesLocation extends AbstractLocation implements MachineProvi .withNewSpec() .addToSelector(metadata) .addToPorts(Iterables.toArray(servicePorts, ServicePort.class)) - .withType(SERVER_TYPE) + .withType(NODE_PORT) .endSpec() .build(); client.services().inNamespace(namespace).create(service); @@ -878,7 +886,7 @@ public class KubernetesLocation extends AbstractLocation implements MachineProvi setup.configure(LOGIN_USER_PASSWORD, loginPassword); } - injections.put("CLOUDSOFT_ROOT_PASSWORD", loginPassword); + injections.put(CLOUDSOFT_ROOT_PASSWORD, loginPassword); } } @@ -910,7 +918,7 @@ public class KubernetesLocation extends AbstractLocation implements MachineProvi } } - public static List<Integer> toIntPortList(Object v) { + protected List<Integer> toIntPortList(Object v) { if (v == null) return ImmutableList.of(); PortRange portRange = PortRanges.fromIterable(ImmutableList.of(v)); return ImmutableList.copyOf(portRange); @@ -944,7 +952,7 @@ public class KubernetesLocation extends AbstractLocation implements MachineProvi return implementsInterface(entity, KubernetesResource.class); } - protected boolean implementsInterface(Entity entity, Class<?> type) { + public boolean implementsInterface(Entity entity, Class<?> type) { return Iterables.tryFind(Arrays.asList(entity.getClass().getInterfaces()), Predicates.instanceOf(type)).isPresent(); } @@ -954,7 +962,7 @@ public class KubernetesLocation extends AbstractLocation implements MachineProvi } /** @see {@link #lookup(ConfigKey, Entity, ConfigBag, Object)} */ - protected <T> T lookup(ConfigKey<T> config, Entity entity, ConfigBag setup) { + public <T> T lookup(ConfigKey<T> config, Entity entity, ConfigBag setup) { return lookup(config, entity, setup, null); } @@ -962,20 +970,20 @@ public class KubernetesLocation extends AbstractLocation implements MachineProvi * Looks up {@link ConfigKey configuration} with the entity value taking precedence over the * location, and returning a default value (normally {@literal null}) if neither is present. */ - protected <T> T lookup(ConfigKey<T> config, Entity entity, ConfigBag setup, T defaultValue) { + public <T> T lookup(ConfigKey<T> config, Entity entity, ConfigBag setup, T defaultValue) { Optional<T> entityValue = Optional.fromNullable(entity.config().get(config)); Optional<T> locationValue = Optional.fromNullable(setup.get(config)); return entityValue.or(locationValue).or(defaultValue); } - protected void waitForExitCondition(ExitCondition exitCondition) { + public void waitForExitCondition(ExitCondition exitCondition) { waitForExitCondition(exitCondition, Duration.ONE_SECOND, Duration.FIVE_MINUTES); } - protected void waitForExitCondition(ExitCondition exitCondition, Duration finalDelay, Duration duration) { + public void waitForExitCondition(ExitCondition exitCondition, Duration initial, Duration duration) { ReferenceWithError<Boolean> result = Repeater.create() - .backoffTo(finalDelay) + .backoff(initial, 1.2, duration) .limitTimeTo(duration) .until(exitCondition) .runKeepingError(); http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/6c4386ba/openshift-location/src/main/java/io/cloudsoft/amp/containerservice/openshift/entity/OpenShiftPodImpl.java ---------------------------------------------------------------------- diff --git a/openshift-location/src/main/java/io/cloudsoft/amp/containerservice/openshift/entity/OpenShiftPodImpl.java b/openshift-location/src/main/java/io/cloudsoft/amp/containerservice/openshift/entity/OpenShiftPodImpl.java index 7e95533..49ffa4d 100644 --- a/openshift-location/src/main/java/io/cloudsoft/amp/containerservice/openshift/entity/OpenShiftPodImpl.java +++ b/openshift-location/src/main/java/io/cloudsoft/amp/containerservice/openshift/entity/OpenShiftPodImpl.java @@ -1,6 +1,6 @@ package io.cloudsoft.amp.containerservice.openshift.entity; -mport io.cloudsoft.amp.containerservice.kubernetes.entity.KubernetesPodImpl; +import io.cloudsoft.amp.containerservice.kubernetes.entity.KubernetesPodImpl; public class OpenShiftPodImpl extends KubernetesPodImpl implements OpenShiftPod { http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/6c4386ba/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 c6f0190..f3d1180 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 @@ -112,7 +112,7 @@ public class OpenShiftLocation extends KubernetesLocation implements OpenShiftLo @Override public Boolean call() { Project actualProject = client.projects().withName(name).get(); - return actualProject != null && actualProject.getStatus().getPhase().equals("Active"); + return actualProject != null && actualProject.getStatus().getPhase().equals(PHASE_ACTIVE); } @Override public String getFailureMessage() { @@ -136,7 +136,7 @@ public class OpenShiftLocation extends KubernetesLocation implements OpenShiftLo protected synchronized void deleteEmptyNamespace(final String name) { if (!name.equals("default") && isNamespaceEmpty(name)) { if (client.projects().withName(name).get() != null && - !client.projects().withName(name).get().getStatus().getPhase().equals("Terminating")) { + !client.projects().withName(name).get().getStatus().getPhase().equals(PHASE_TERMINATING)) { client.projects().withName(name).delete(); ExitCondition exitCondition = new ExitCondition() { @Override
