Skip to content

Commit 5772968

Browse files
committed
---
yaml --- r: 1995 b: refs/heads/pubsub-alpha c: a25e504 h: refs/heads/master i: 1993: e2008d1 1991: 3fb9b3a
1 parent 76bfd53 commit 5772968

9 files changed

Lines changed: 75 additions & 125 deletions

File tree

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ refs/heads/master: 689bbb466df4b2d5d2483d6edb8ac5c7c7f7c6fa
33
refs/heads/travis: e21ee7b88a5edc3f3d8c71f90c3fc32abf7e8dd6
44
refs/heads/gh-pages: 4e0561bb4504bf647db669a14417b2b2c87ba45d
55
refs/heads/bigquery: 762fa5830e6c398c0396177e3e7fd243bd62cfc3
6-
refs/heads/pubsub-alpha: 1a6dcde82e01bc4432e14675b39bffddae97c8b6
6+
refs/heads/pubsub-alpha: a25e50430b55b93816be392e363638e67f67a500
77
refs/heads/resource-manager: ebf4adc5ee835cd2086c4ac5b4e78d01a5a005a7
88
refs/heads/update-datastore: 482954f2c5055231e5b3122ea91d2ba00ce8187c
99
refs/tags/0.0.9: 22f1839238f66c39e67ed4dfdcd273b1ae2e8444

branches/pubsub-alpha/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ Most `gcloud-java` libraries require a project ID. There are multiple ways to s
6969
1. Project ID supplied when building the service options
7070
2. Project ID specified by the environment variable `GCLOUD_PROJECT`
7171
3. App Engine project ID
72-
4. Compute Engine project ID
73-
5. Google Cloud SDK project ID
72+
4. Google Cloud SDK project ID
73+
5. Compute Engine project ID
7474

7575
Authentication
7676
--------------

branches/pubsub-alpha/gcloud-java-core/pom.xml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,18 @@
2020
<dependency>
2121
<groupId>com.google.auth</groupId>
2222
<artifactId>google-auth-library-credentials</artifactId>
23-
<version>0.1.0</version>
23+
<version>0.3.1</version>
2424
</dependency>
2525
<dependency>
2626
<groupId>com.google.auth</groupId>
2727
<artifactId>google-auth-library-oauth2-http</artifactId>
28-
<version>0.1.0</version>
28+
<version>0.3.1</version>
29+
<exclusions>
30+
<exclusion>
31+
<groupId>com.google.guava</groupId>
32+
<artifactId>guava-jdk5</artifactId>
33+
</exclusion>
34+
</exclusions>
2935
</dependency>
3036
<dependency>
3137
<groupId>com.google.http-client</groupId>

branches/pubsub-alpha/gcloud-java-core/src/main/java/com/google/gcloud/AuthCredentials.java

Lines changed: 0 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,9 @@
1919
import static com.google.common.base.Preconditions.checkNotNull;
2020

2121
import com.google.api.client.googleapis.auth.oauth2.GoogleCredential;
22-
import com.google.api.client.googleapis.compute.ComputeCredential;
2322
import com.google.api.client.googleapis.extensions.appengine.auth.oauth2.AppIdentityCredential;
24-
import com.google.api.client.googleapis.javanet.GoogleNetHttpTransport;
2523
import com.google.api.client.http.HttpRequestInitializer;
2624
import com.google.api.client.http.HttpTransport;
27-
import com.google.api.client.http.javanet.NetHttpTransport;
2825
import com.google.api.client.json.jackson.JacksonFactory;
2926
import com.google.auth.http.HttpCredentialsAdapter;
3027
import com.google.auth.oauth2.GoogleCredentials;
@@ -33,7 +30,6 @@
3330
import java.io.IOException;
3431
import java.io.InputStream;
3532
import java.io.Serializable;
36-
import java.security.GeneralSecurityException;
3733
import java.security.PrivateKey;
3834
import java.util.Objects;
3935
import java.util.Set;
@@ -164,55 +160,6 @@ public RestorableState<AuthCredentials> capture() {
164160
}
165161
}
166162

167-
private static class ComputeEngineAuthCredentials extends AuthCredentials {
168-
169-
private ComputeCredential computeCredential;
170-
171-
private static final ComputeEngineAuthCredentialsState STATE =
172-
new ComputeEngineAuthCredentialsState();
173-
174-
private static class ComputeEngineAuthCredentialsState
175-
implements RestorableState<AuthCredentials>, Serializable {
176-
177-
private static final long serialVersionUID = -6168594072854417404L;
178-
179-
@Override
180-
public AuthCredentials restore() {
181-
try {
182-
return new ComputeEngineAuthCredentials();
183-
} catch (IOException | GeneralSecurityException e) {
184-
throw new IllegalStateException(
185-
"Could not restore " + ComputeEngineAuthCredentials.class.getSimpleName(), e);
186-
}
187-
}
188-
189-
@Override
190-
public int hashCode() {
191-
return getClass().getName().hashCode();
192-
}
193-
194-
@Override
195-
public boolean equals(Object obj) {
196-
return obj instanceof ComputeEngineAuthCredentialsState;
197-
}
198-
}
199-
200-
ComputeEngineAuthCredentials() throws IOException, GeneralSecurityException {
201-
computeCredential = getComputeCredential();
202-
}
203-
204-
@Override
205-
protected HttpRequestInitializer httpRequestInitializer(HttpTransport transport,
206-
Set<String> scopes) {
207-
return computeCredential;
208-
}
209-
210-
@Override
211-
public RestorableState<AuthCredentials> capture() {
212-
return STATE;
213-
}
214-
}
215-
216163
public static class ApplicationDefaultAuthCredentials extends AuthCredentials {
217164

218165
private GoogleCredentials googleCredentials;
@@ -278,11 +225,6 @@ public static AuthCredentials createForAppEngine() {
278225
return AppEngineAuthCredentials.INSTANCE;
279226
}
280227

281-
public static AuthCredentials createForComputeEngine()
282-
throws IOException, GeneralSecurityException {
283-
return new ComputeEngineAuthCredentials();
284-
}
285-
286228
/**
287229
* Returns the Application Default Credentials.
288230
*
@@ -337,13 +279,4 @@ public static ServiceAccountAuthCredentials createForJson(InputStream jsonCreden
337279
public static AuthCredentials noCredentials() {
338280
return ServiceAccountAuthCredentials.NO_CREDENTIALS;
339281
}
340-
341-
static ComputeCredential getComputeCredential() throws IOException, GeneralSecurityException {
342-
NetHttpTransport transport = GoogleNetHttpTransport.newTrustedTransport();
343-
// Try to connect using Google Compute Engine service account credentials.
344-
ComputeCredential credential = new ComputeCredential(transport, new JacksonFactory());
345-
// Force token refresh to detect if we are running on Google Compute Engine.
346-
credential.refreshToken();
347-
return credential;
348-
}
349282
}

branches/pubsub-alpha/gcloud-java-core/src/main/java/com/google/gcloud/ServiceOptions.java

Lines changed: 36 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -109,12 +109,6 @@ public HttpTransport create() {
109109
// Maybe not on App Engine
110110
}
111111
}
112-
// Consider Compute
113-
try {
114-
return AuthCredentials.getComputeCredential().getTransport();
115-
} catch (Exception e) {
116-
// Maybe not on GCE
117-
}
118112
return new NetHttpTransport();
119113
}
120114
}
@@ -342,7 +336,7 @@ protected boolean projectIdRequired() {
342336
}
343337

344338
private static AuthCredentials defaultAuthCredentials() {
345-
// Consider App Engine. This will not be needed once issue #21 is fixed.
339+
// Consider App Engine.
346340
if (appEngineAppId() != null) {
347341
try {
348342
return AuthCredentials.createForAppEngine();
@@ -354,16 +348,8 @@ private static AuthCredentials defaultAuthCredentials() {
354348
try {
355349
return AuthCredentials.createApplicationDefaults();
356350
} catch (Exception ex) {
357-
// fallback to old-style
351+
return AuthCredentials.noCredentials();
358352
}
359-
360-
// Consider old-style Compute. This will not be needed once issue #21 is fixed.
361-
try {
362-
return AuthCredentials.createForComputeEngine();
363-
} catch (Exception ignore) {
364-
// Maybe not on GCE
365-
}
366-
return AuthCredentials.noCredentials();
367353
}
368354

369355
protected static String appEngineAppId() {
@@ -383,19 +369,6 @@ protected String defaultProject() {
383369
}
384370

385371
protected static String googleCloudProjectId() {
386-
try {
387-
URL url = new URL("http://metadata/computeMetadata/v1/project/project-id");
388-
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
389-
connection.setRequestProperty("X-Google-Metadata-Request", "True");
390-
InputStream input = connection.getInputStream();
391-
if (connection.getResponseCode() == 200) {
392-
try (BufferedReader reader = new BufferedReader(new InputStreamReader(input, UTF_8))) {
393-
return reader.readLine();
394-
}
395-
}
396-
} catch (IOException ignore) {
397-
// ignore
398-
}
399372
File configDir;
400373
if (System.getenv().containsKey("CLOUDSDK_CONFIG")) {
401374
configDir = new File(System.getenv("CLOUDSDK_CONFIG"));
@@ -404,38 +377,52 @@ protected static String googleCloudProjectId() {
404377
} else {
405378
configDir = new File(System.getProperty("user.home"), ".config/gcloud");
406379
}
407-
FileReader fileReader;
380+
FileReader fileReader = null;
408381
try {
409382
fileReader = new FileReader(new File(configDir, "configurations/config_default"));
410383
} catch (FileNotFoundException newConfigFileNotFoundEx) {
411384
try {
412385
fileReader = new FileReader(new File(configDir, "properties"));
413386
} catch (FileNotFoundException oldConfigFileNotFoundEx) {
414-
// return null if we can't find config file
415-
return null;
387+
// ignore
416388
}
417389
}
418-
try (BufferedReader reader = new BufferedReader(fileReader)) {
419-
String line;
420-
String section = null;
421-
Pattern projectPattern = Pattern.compile("^project\\s*=\\s*(.*)$");
422-
Pattern sectionPattern = Pattern.compile("^\\[(.*)\\]$");
423-
while ((line = reader.readLine()) != null) {
424-
if (line.isEmpty() || line.startsWith(";")) {
425-
continue;
426-
}
427-
line = line.trim();
428-
Matcher matcher = sectionPattern.matcher(line);
429-
if (matcher.matches()) {
430-
section = matcher.group(1);
431-
} else if (section == null || section.equals("core")) {
432-
matcher = projectPattern.matcher(line);
390+
if (fileReader != null) {
391+
try (BufferedReader reader = new BufferedReader(fileReader)) {
392+
String line;
393+
String section = null;
394+
Pattern projectPattern = Pattern.compile("^project\\s*=\\s*(.*)$");
395+
Pattern sectionPattern = Pattern.compile("^\\[(.*)\\]$");
396+
while ((line = reader.readLine()) != null) {
397+
if (line.isEmpty() || line.startsWith(";")) {
398+
continue;
399+
}
400+
line = line.trim();
401+
Matcher matcher = sectionPattern.matcher(line);
433402
if (matcher.matches()) {
434-
return matcher.group(1);
403+
section = matcher.group(1);
404+
} else if (section == null || section.equals("core")) {
405+
matcher = projectPattern.matcher(line);
406+
if (matcher.matches()) {
407+
return matcher.group(1);
408+
}
435409
}
436410
}
411+
} catch (IOException ex) {
412+
// ignore
413+
}
414+
}
415+
try {
416+
URL url = new URL("http://metadata/computeMetadata/v1/project/project-id");
417+
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
418+
connection.setRequestProperty("X-Google-Metadata-Request", "True");
419+
InputStream input = connection.getInputStream();
420+
if (connection.getResponseCode() == 200) {
421+
try (BufferedReader reader = new BufferedReader(new InputStreamReader(input, UTF_8))) {
422+
return reader.readLine();
423+
}
437424
}
438-
} catch (IOException ex) {
425+
} catch (IOException ignore) {
439426
// ignore
440427
}
441428
// return null if can't determine

branches/pubsub-alpha/gcloud-java-datastore/pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,12 @@
2727
<artifactId>google-api-services-datastore-protobuf</artifactId>
2828
<version>v1beta2-rev1-2.1.2</version>
2929
<scope>compile</scope>
30+
<exclusions>
31+
<exclusion>
32+
<groupId>com.google.api-client</groupId>
33+
<artifactId>google-api-client</artifactId>
34+
</exclusion>
35+
</exclusions>
3036
</dependency>
3137
<dependency>
3238
<groupId>junit</groupId>

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

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
import org.json.JSONTokener;
4343

4444
import java.net.InetAddress;
45+
import java.net.SocketTimeoutException;
4546
import java.net.URL;
4647
import java.util.HashMap;
4748
import java.util.Map;
@@ -121,9 +122,17 @@ private static DatastoreRpcException translate(DatastoreException exception) {
121122
if (reason == null) {
122123
reason = HTTP_STATUS_TO_REASON.get(exception.getCode());
123124
}
124-
return reason != null
125-
? new DatastoreRpcException(reason)
126-
: new DatastoreRpcException("Unknown", exception.getCode(), false, message);
125+
if (reason != null) {
126+
return new DatastoreRpcException(reason);
127+
} else {
128+
boolean retryable = false;
129+
reasonStr = "Unknown";
130+
if (exception.getCause() instanceof SocketTimeoutException) {
131+
retryable = true;
132+
reasonStr = "Request timeout";
133+
}
134+
return new DatastoreRpcException(reasonStr, exception.getCode(), retryable, message);
135+
}
127136
}
128137

129138
@Override

branches/pubsub-alpha/gcloud-java-storage/pom.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@
3232
<groupId>com.google.guava</groupId>
3333
<artifactId>guava-jdk5</artifactId>
3434
</exclusion>
35+
<exclusion>
36+
<groupId>com.google.api-client</groupId>
37+
<artifactId>google-api-client</artifactId>
38+
</exclusion>
3539
</exclusions>
3640
</dependency>
3741
<dependency>

branches/pubsub-alpha/gcloud-java-storage/src/main/java/com/google/gcloud/spi/DefaultStorageRpc.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868
import java.io.ByteArrayOutputStream;
6969
import java.io.IOException;
7070
import java.io.InputStream;
71+
import java.net.SocketTimeoutException;
7172
import java.util.ArrayList;
7273
import java.util.Iterator;
7374
import java.util.List;
@@ -101,7 +102,11 @@ private static StorageException translate(IOException exception) {
101102
&& ((GoogleJsonResponseException) exception).getDetails() != null) {
102103
translated = translate(((GoogleJsonResponseException) exception).getDetails());
103104
} else {
104-
translated = new StorageException(0, exception.getMessage(), false);
105+
boolean retryable = false;
106+
if (exception instanceof SocketTimeoutException) {
107+
retryable = true;
108+
}
109+
translated = new StorageException(0, exception.getMessage(), retryable);
105110
}
106111
translated.initCause(exception);
107112
return translated;

0 commit comments

Comments
 (0)