From 457284e76472031187af81cab488031a18065b5d Mon Sep 17 00:00:00 2001 From: Jonathan Cobb Date: Thu, 10 Dec 2020 10:17:16 -0500 Subject: [PATCH] update null location handling --- .../src/main/java/bubble/ApiConstants.java | 2 ++ .../cloud/compute/docker/DockerComputeDriver.java | 13 ++++++------- .../bubble/model/cloud/RegionalServiceDriver.java | 6 ++++-- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/bubble-server/src/main/java/bubble/ApiConstants.java b/bubble-server/src/main/java/bubble/ApiConstants.java index 5b296dd4..20d24817 100644 --- a/bubble-server/src/main/java/bubble/ApiConstants.java +++ b/bubble-server/src/main/java/bubble/ApiConstants.java @@ -131,6 +131,8 @@ public class ApiConstants { public static final File CACERTS_DIR = new File(HOME_DIR, "cacerts"); public static final File MITMPROXY_CERT_DIR = new File(HOME_DIR, "mitm_certs"); + public static final String LOCAL = "local"; + public static final String META_PROP_BUBBLE_VERSION = "bubble.version"; public static final String SESSION_HEADER = "X-Bubble-Session"; diff --git a/bubble-server/src/main/java/bubble/cloud/compute/docker/DockerComputeDriver.java b/bubble-server/src/main/java/bubble/cloud/compute/docker/DockerComputeDriver.java index 2ed69bfb..25a44b63 100644 --- a/bubble-server/src/main/java/bubble/cloud/compute/docker/DockerComputeDriver.java +++ b/bubble-server/src/main/java/bubble/cloud/compute/docker/DockerComputeDriver.java @@ -1,5 +1,6 @@ package bubble.cloud.compute.docker; +import bubble.ApiConstants; import bubble.cloud.CloudRegion; import bubble.cloud.compute.*; import bubble.cloud.geoLocation.GeoLocation; @@ -46,16 +47,14 @@ import static org.cobbzilla.util.system.Sleep.sleep; @Slf4j public class DockerComputeDriver extends ComputeServiceDriverBase { - public static final String LOCAL = "local"; - public static final CloudRegion[] CLOUD_REGIONS_ARRAY = new CloudRegion[]{ - new CloudRegion().setName(LOCAL).setInternalName(LOCAL).setLocation(GeoLocation.NULL_LOCATION) + new CloudRegion().setName(ApiConstants.LOCAL).setInternalName(ApiConstants.LOCAL).setLocation(GeoLocation.NULL_LOCATION) }; public static final List CLOUD_REGIONS = Arrays.asList(CLOUD_REGIONS_ARRAY); - public static final ComputeNodeSize LOCAL_SIZE = new ComputeNodeSize().setName(LOCAL).setInternalName(LOCAL).setType(ComputeNodeSizeType.local); + public static final ComputeNodeSize LOCAL_SIZE = new ComputeNodeSize().setName(ApiConstants.LOCAL).setInternalName(ApiConstants.LOCAL).setType(ComputeNodeSizeType.local); public static final List CLOUD_SIZES = singletonList(LOCAL_SIZE); - public static final Map NODE_SIZE_MAP = MapBuilder.build(LOCAL, LOCAL_SIZE); + public static final Map NODE_SIZE_MAP = MapBuilder.build(ApiConstants.LOCAL, LOCAL_SIZE); public static final ExposedPort[] SAGE_EXPOSED_PORTS = {new ExposedPort(22), new ExposedPort(8090)}; @@ -66,7 +65,7 @@ public class DockerComputeDriver extends ComputeServiceDriverBase { public static final String BASE_IMAGE = "phusion/baseimage:focal-1.0.0alpha1-amd64"; public static final List CLOUD_OS_IMAGES = singletonList( - new OsImage().setName(BASE_IMAGE).setId(BASE_IMAGE).setRegion(LOCAL) + new OsImage().setName(BASE_IMAGE).setId(BASE_IMAGE).setRegion(ApiConstants.LOCAL) ); public static final long START_TIMEOUT = SECONDS.toMillis(120); @@ -289,7 +288,7 @@ public class DockerComputeDriver extends ComputeServiceDriverBase { } @Override public List getPackerImagesForRegion(String region) { - return region == null || region.equals(LOCAL) ? getAllPackerImages() : emptyList(); + return region == null || region.equals(ApiConstants.LOCAL) ? getAllPackerImages() : emptyList(); } @Override public List listNodes() throws IOException { diff --git a/bubble-server/src/main/java/bubble/model/cloud/RegionalServiceDriver.java b/bubble-server/src/main/java/bubble/model/cloud/RegionalServiceDriver.java index 3e86b75a..617cba72 100644 --- a/bubble-server/src/main/java/bubble/model/cloud/RegionalServiceDriver.java +++ b/bubble-server/src/main/java/bubble/model/cloud/RegionalServiceDriver.java @@ -16,8 +16,10 @@ import java.util.Collection; import java.util.List; import java.util.stream.Collectors; +import static bubble.ApiConstants.LOCAL; import static bubble.cloud.CloudRegionRelative.SORT_DISTANCE_THEN_NAME; -import static bubble.cloud.geoLocation.GeoLocation.*; +import static bubble.cloud.geoLocation.GeoLocation.DEFAULT_GEO_LOCATION; +import static bubble.cloud.geoLocation.GeoLocation.NULL_LOCATION; import static org.cobbzilla.util.daemon.ZillaRuntime.shortError; public interface RegionalServiceDriver { @@ -87,7 +89,7 @@ public interface RegionalServiceDriver { CloudService c, CloudRegion region) { final CloudRegionRelative r = new CloudRegionRelative(region); - r.setDistance(null); + r.setDistance(LOCAL.equals(region.getInternalName()) ? 0.0 : null); r.setCloud(c.getUuid()); allRegions.add(r); }