Skip to content

Commit c27b2ed

Browse files
author
Ajay Kannan
committed
---
yaml --- r: 1327 b: refs/heads/update-datastore c: 4d2fe25 h: refs/heads/master i: 1325: 2b9cb27 1323: 9bc3c6c 1319: 617a9e4 1311: bec9816 v: v3
1 parent 0346a26 commit c27b2ed

3 files changed

Lines changed: 20 additions & 9 deletions

File tree

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ refs/heads/gh-pages: d1b373c30c176edc08692348167bec3a244bb823
55
refs/heads/bigquery: 762fa5830e6c398c0396177e3e7fd243bd62cfc3
66
refs/heads/pubsub-alpha: dea33f5d017ff85c14573b4a06c6b1f2c4bbe2b0
77
refs/heads/resource-manager: ebf4adc5ee835cd2086c4ac5b4e78d01a5a005a7
8-
refs/heads/update-datastore: 9463c5592e230e7384960664119781e642a87c45
8+
refs/heads/update-datastore: 4d2fe25b88f32abb9cc4c3d4bc01fbfde1221a79

branches/update-datastore/gcloud-java-datastore/src/main/java/com/google/gcloud/spi/DefaultDatastoreRpc.java

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package com.google.gcloud.spi;
1818

19+
import com.google.common.base.Strings;
1920
import com.google.common.collect.ImmutableMap;
2021
import com.google.gcloud.datastore.DatastoreOptions;
2122
import com.google.gcloud.spi.DatastoreRpc.DatastoreRpcException.Reason;
@@ -51,14 +52,16 @@ public DefaultDatastoreRpc(DatastoreOptions options) {
5152
.projectId(options.projectId())
5253
.initializer(options.httpRequestInitializer());
5354
if (isLocalHost(options.host())) {
54-
clientBuilder = clientBuilder.localHost(options.host());
55-
} else if (!options.host()
56-
.equals(com.google.datastore.v1beta3.client.DatastoreFactory.DEFAULT_HOST)) {
55+
clientBuilder = clientBuilder.localHost(removeScheme(options.host()));
56+
} else if (!com.google.datastore.v1beta3.client.DatastoreFactory.DEFAULT_HOST
57+
.equals(options.host()) && !Strings.isNullOrEmpty(options.host())) {
5758
String fullURL = options.host();
5859
if (fullURL.charAt(fullURL.length() - 1) != '/') {
5960
fullURL = fullURL + '/';
6061
}
61-
fullURL = fullURL + "datastore/v1beta3/projects/" + options.projectId();
62+
fullURL = fullURL + "datastore/"
63+
+ com.google.datastore.v1beta3.client.DatastoreFactory.VERSION + "/projects/"
64+
+ options.projectId();
6265
clientBuilder = clientBuilder.projectId(null).projectEndpoint(fullURL);
6366
}
6467
client = com.google.datastore.v1beta3.client.DatastoreFactory.get()
@@ -73,9 +76,7 @@ private static boolean isLocalHost(String host) {
7376
normalizedHost = "http://" + normalizedHost;
7477
}
7578
InetAddress hostAddr = InetAddress.getByName(new URL(normalizedHost).getHost());
76-
if (hostAddr.isAnyLocalAddress() || hostAddr.isLoopbackAddress()) {
77-
return true;
78-
}
79+
return hostAddr.isAnyLocalAddress() || hostAddr.isLoopbackAddress();
7980
} catch (UnknownHostException | MalformedURLException e) {
8081
// ignore
8182
}
@@ -87,6 +88,15 @@ private static boolean includesScheme(String url) {
8788
return url.startsWith("http://") || url.startsWith("https://");
8889
}
8990

91+
private static String removeScheme(String url) {
92+
if (url.startsWith("https://")) {
93+
return url.substring("https://".length());
94+
} else if (url.startsWith("http://")) {
95+
return url.substring("http://".length());
96+
}
97+
return url;
98+
}
99+
90100
private static DatastoreRpcException translate(
91101
com.google.datastore.v1beta3.client.DatastoreException exception) {
92102
String reasonStr = "";

branches/update-datastore/gcloud-java-datastore/src/test/java/com/google/gcloud/datastore/LocalGcdHelper.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,8 @@ public static void main(String... args) throws IOException, InterruptedException
309309
public static boolean isActive(String projectId) {
310310
try {
311311
StringBuilder urlBuilder = new StringBuilder("http://localhost:").append(PORT);
312-
urlBuilder.append("/datastore/v1beta3/projects/").append(projectId).append(":lookup");
312+
urlBuilder.append("/datastore/" + com.google.datastore.v1beta3.client.DatastoreFactory.VERSION
313+
+ "/projects/").append(projectId).append(":lookup");
313314
URL url = new URL(urlBuilder.toString());
314315
try (BufferedReader reader =
315316
new BufferedReader(new InputStreamReader(url.openStream(), UTF_8))) {

0 commit comments

Comments
 (0)