소스 검색

improvements when geo services are not available

tags/v1.4.5
Jonathan Cobb 4 년 전
부모
커밋
8712d0498a
7개의 변경된 파일17개의 추가작업 그리고 19개의 파일을 삭제
  1. +2
    -0
      bubble-server/src/main/java/bubble/cloud/geoLocation/GeoLocation.java
  2. +2
    -0
      bubble-server/src/main/java/bubble/cloud/geoTime/GeoTimeZone.java
  3. +1
    -7
      bubble-server/src/main/java/bubble/model/cloud/RegionalServiceDriver.java
  4. +2
    -2
      bubble-server/src/main/java/bubble/resources/DetectResource.java
  5. +1
    -1
      bubble-server/src/main/java/bubble/resources/cloud/CloudServiceRegionsResource.java
  6. +8
    -8
      bubble-server/src/main/java/bubble/service/cloud/GeoService.java
  7. +1
    -1
      bubble-web

+ 2
- 0
bubble-server/src/main/java/bubble/cloud/geoLocation/GeoLocation.java 파일 보기

@@ -20,6 +20,8 @@ import static org.cobbzilla.util.daemon.ZillaRuntime.*;
@NoArgsConstructor @Accessors(chain=true) @ToString(of={"lat", "lon"})
public class GeoLocation {

public static final GeoLocation NULL_LOCATION = new GeoLocation().setLat("-1.0").setLon("-1.0");

@Getter @Setter private String country;
public boolean hasCountry() { return !empty(country); }



+ 2
- 0
bubble-server/src/main/java/bubble/cloud/geoTime/GeoTimeZone.java 파일 보기

@@ -13,6 +13,8 @@ import lombok.experimental.Accessors;
@NoArgsConstructor @AllArgsConstructor @Accessors(chain=true)
public class GeoTimeZone {

public static final GeoTimeZone UTC = new GeoTimeZone("Etc/UTC", "UTC", 0L);

@Getter @Setter private String timeZoneId;
@Getter @Setter private String standardName;
@Getter @Setter private Long currentOffsetMs;


+ 1
- 7
bubble-server/src/main/java/bubble/model/cloud/RegionalServiceDriver.java 파일 보기

@@ -62,7 +62,7 @@ public interface RegionalServiceDriver {
if (latLonIsValid) {
r.setDistance(latitude, longitude);
} else {
r.setDistance(0);
r.setDistance(-1);
}
allRegions.add(r);
}
@@ -74,12 +74,6 @@ public interface RegionalServiceDriver {

List<CloudRegion> getRegions();

default List<CloudRegion> getRegionsExcluding(Collection<String> exclude) {
ArrayList<CloudRegion> filtered = new ArrayList<>(getRegions());
filtered.removeIf(r -> exclude.contains(r.getInternalName()) || exclude.contains(r.getName()));
return filtered;
}

default List<CloudRegion> getRegions(BubbleFootprint footprint) {
return getRegions().stream()
.filter(r -> footprint == null || footprint.isAllowedCountry(r.getLocation().getCountry()))


+ 2
- 2
bubble-server/src/main/java/bubble/resources/DetectResource.java 파일 보기

@@ -4,6 +4,7 @@
*/
package bubble.resources;

import bubble.cloud.CloudServiceType;
import bubble.service.cloud.GeoService;
import lombok.extern.slf4j.Slf4j;
import org.glassfish.grizzly.http.server.Request;
@@ -20,8 +21,7 @@ import javax.ws.rs.core.Response;

import static bubble.ApiConstants.*;
import static org.cobbzilla.util.http.HttpContentTypes.APPLICATION_JSON;
import static org.cobbzilla.wizard.resources.ResourceUtil.ok;
import static org.cobbzilla.wizard.resources.ResourceUtil.optionalUserPrincipal;
import static org.cobbzilla.wizard.resources.ResourceUtil.*;

@Consumes(APPLICATION_JSON)
@Produces(APPLICATION_JSON)


+ 1
- 1
bubble-server/src/main/java/bubble/resources/cloud/CloudServiceRegionsResource.java 파일 보기

@@ -82,7 +82,7 @@ public class CloudServiceRegionsResource {
if (footprint == null) return notFound(footprintId);
}

return ok(findClosestRegions(configuration, computeClouds(), footprint, loc.getLatitude(), loc.getLongitude()));
return ok(findClosestRegions(configuration, computeClouds(), footprint, loc.getLatitude(), loc.getLongitude(), null, geoService.supportsGeoLocation()));
}

public List<CloudRegion> findRegions(List<CloudService> clouds, BubbleFootprint footprint) {


+ 8
- 8
bubble-server/src/main/java/bubble/service/cloud/GeoService.java 파일 보기

@@ -80,7 +80,8 @@ public class GeoService {

public GeoLocation locate (String accountUuid, String ip, boolean cacheOnly) {
if (!supportsGeoLocation()) {
throw invalidEx("err.geoLocateService.notFound");
log.warn("locate: no geoLocation cloud services defined, returning null location");
return GeoLocation.NULL_LOCATION;
}
final String cacheKey = hashOf(accountUuid, ip);
return locateCache.computeIfAbsent(cacheKey, k -> {
@@ -103,8 +104,9 @@ public class GeoService {
}

private GeoLocation getLocation(String accountUuid, String ip, String cacheKey) {
if (!supportsGeoCode()) {
throw invalidEx("err.geoCodeService.notFound");
if (!supportsGeoLocation()) {
log.warn("getLocation: no geoLocation cloud services defined, returning null location");
return GeoLocation.NULL_LOCATION;
}
List<CloudService> geoLocationServices = null;
if (accountUuid != null) {
@@ -128,7 +130,7 @@ public class GeoService {
try {
final GeoLocation result = geo.getGeoLocateDriver(configuration).geolocate(ip);
if (result != null) {
if (!result.hasLatLon()) {
if (!result.hasLatLon() && supportsGeoCode()) {
if (geoCodeDriver == null) {
List<CloudService> geoCodeServices = null;
if (accountUuid != null) {
@@ -211,7 +213,8 @@ public class GeoService {

public GeoTimeZone getTimeZone (final Account account, String ip) {
if (!supportsGeoTime()) {
throw invalidEx("err.geoTimeService.notFound");
log.warn("getTimeZone: no geoTime clouds configured, returning UTC time zone");
return GeoTimeZone.UTC;
}
final AtomicReference<Account> acct = new AtomicReference<>(account);
return timezoneCache.computeIfAbsent(ip, k -> {
@@ -289,9 +292,6 @@ public class GeoService {
public CloudAndRegion selectCloudAndRegion(BubbleNetwork network,
NetLocation netLocation,
Collection<CloudAndRegion> exclude) {
if (!supportsGeoLocation()) {
throw invalidEx("err.geoLocateService.notFound");
}
final CloudRegion closest;
final String cloudUuid;
if (netLocation.hasIp()) {


+ 1
- 1
bubble-web

@@ -1 +1 @@
Subproject commit 6b016bdd3e0640cb31154ac39d33ac26f10e49ba
Subproject commit 9cfcf6620419200505c9105c74cb256af80d1ce8

불러오는 중...
취소
저장