Skip to content

Commit 2ebacce

Browse files
author
Ajay Kannan
committed
---
yaml --- r: 4705 b: refs/heads/logging-alpha c: 4d2fe25 h: refs/heads/master i: 4703: 2365d93
1 parent b4a7d01 commit 2ebacce

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
@@ -12,7 +12,7 @@ refs/heads/compute-alpha: 969cba2627f1d53d352cc4a5ffe0879dacf65e6c
1212
refs/heads/dns-alpha: 2f90e7e338349287ace33375896907af0f032ca1
1313
refs/heads/dns-alpha-batch: 17442b07867021b85d0452f5f3eda29a3413288f
1414
refs/heads/gcs-nio: 283aeaf15efdcf3621eb6859f05e55ad7764375d
15-
refs/heads/logging-alpha: 9463c5592e230e7384960664119781e642a87c45
15+
refs/heads/logging-alpha: 4d2fe25b88f32abb9cc4c3d4bc01fbfde1221a79
1616
refs/tags/v0.1.0: a615317f7424ed58621b1f65d5c4d8cbbe8a6ed8
1717
refs/tags/v0.1.1: 7a7f6985fe465e9dd6a075af55493f42b4933be0
1818
refs/tags/v0.1.2: 3eb3fe866ba22487686048f45d927b8c8638ea3f

branches/logging-alpha/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/logging-alpha/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)